Tim Northover | 53d3251 | 2014-03-29 07:34:53 +0000 | [diff] [blame] | 1 | //===-- llvm/MC/MCLinkerOptimizationHint.cpp ----- LOH handling -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/MC/MCLinkerOptimizationHint.h" |
| 11 | #include "llvm/MC/MCAsmLayout.h" |
| 12 | #include "llvm/Support/LEB128.h" |
| 13 | #include "llvm/MC/MCStreamer.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | |
Quentin Colombet | 3c2b13b | 2014-04-02 01:02:28 +0000 | [diff] [blame] | 17 | // Each LOH is composed by, in this order (each field is encoded using ULEB128): |
| 18 | // - Its kind. |
| 19 | // - Its number of arguments (let say N). |
| 20 | // - Its arg1. |
| 21 | // - ... |
| 22 | // - Its argN. |
| 23 | // <arg1> to <argN> are absolute addresses in the object file, i.e., |
| 24 | // relative addresses from the beginning of the object file. |
Tim Northover | 53d3251 | 2014-03-29 07:34:53 +0000 | [diff] [blame] | 25 | void MCLOHDirective::Emit_impl(raw_ostream &OutStream, |
| 26 | const MachObjectWriter &ObjWriter, |
| 27 | const MCAsmLayout &Layout) const { |
| 28 | const MCAssembler &Asm = Layout.getAssembler(); |
| 29 | encodeULEB128(Kind, OutStream); |
| 30 | encodeULEB128(Args.size(), OutStream); |
| 31 | for (LOHArgs::const_iterator It = Args.begin(), EndIt = Args.end(); |
| 32 | It != EndIt; ++It) |
| 33 | encodeULEB128(ObjWriter.getSymbolAddress(&Asm.getSymbolData(**It), Layout), |
| 34 | OutStream); |
| 35 | } |