LLVM  8.0.1
MCLinkerOptimizationHint.cpp
Go to the documentation of this file.
1 //===- llvm/MC/MCLinkerOptimizationHint.cpp ----- LOH handling ------------===//
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 
11 #include "llvm/MC/MCAsmLayout.h"
13 #include "llvm/Support/LEB128.h"
15 #include <cstddef>
16 #include <cstdint>
17 
18 using namespace llvm;
19 
20 // Each LOH is composed by, in this order (each field is encoded using ULEB128):
21 // - Its kind.
22 // - Its number of arguments (let say N).
23 // - Its arg1.
24 // - ...
25 // - Its argN.
26 // <arg1> to <argN> are absolute addresses in the object file, i.e.,
27 // relative addresses from the beginning of the object file.
28 void MCLOHDirective::emit_impl(raw_ostream &OutStream,
29  const MachObjectWriter &ObjWriter,
30  const MCAsmLayout &Layout) const {
31  encodeULEB128(Kind, OutStream);
32  encodeULEB128(Args.size(), OutStream);
33  for (const MCSymbol *Arg : Args)
34  encodeULEB128(ObjWriter.getSymbolAddress(*Arg, Layout), OutStream);
35 }
36 
38  const MCAsmLayout &Layout) const {
39  raw_ostream &OutStream = ObjWriter.W.OS;
40  emit_impl(OutStream, ObjWriter, Layout);
41 }
42 
44  const MCAsmLayout &Layout) const {
45  class raw_counting_ostream : public raw_ostream {
46  uint64_t Count = 0;
47 
48  void write_impl(const char *, size_t size) override { Count += size; }
49 
50  uint64_t current_pos() const override { return Count; }
51 
52  public:
53  raw_counting_ostream() = default;
54  ~raw_counting_ostream() override { flush(); }
55  };
56 
57  raw_counting_ostream OutStream;
58  emit_impl(OutStream, ObjWriter, Layout);
59  return OutStream.tell();
60 }
uint64_t getSymbolAddress(const MCSymbol &S, const MCAsmLayout &Layout) const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
void emit(MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const
Emit this directive as: <kind, numArgs, addr1, ..., addrN>
support::endian::Writer W
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
uint64_t getEmitSize(const MachObjectWriter &ObjWriter, const MCAsmLayout &Layout) const
Get the size in bytes of this directive if emitted in ObjWriter with the given Layout.
auto size(R &&Range, typename std::enable_if< std::is_same< typename std::iterator_traits< decltype(Range.begin())>::iterator_category, std::random_access_iterator_tag >::value, void >::type *=nullptr) -> decltype(std::distance(Range.begin(), Range.end()))
Get the size of a range.
Definition: STLExtras.h:1167
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:81
amdgpu Simplify well known AMD library false Value Value * Arg
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46