1 //===- lib/MC/ELFObjectWriter.cpp - ELF File Writer -----------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements ELF object file writer information.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/BinaryFormat/ELF.h"
22 #include "llvm/MC/MCAsmBackend.h"
23 #include "llvm/MC/MCAsmInfo.h"
24 #include "llvm/MC/MCAsmLayout.h"
25 #include "llvm/MC/MCAssembler.h"
26 #include "llvm/MC/MCContext.h"
27 #include "llvm/MC/MCELFObjectWriter.h"
28 #include "llvm/MC/MCExpr.h"
29 #include "llvm/MC/MCFixup.h"
30 #include "llvm/MC/MCFixupKindInfo.h"
31 #include "llvm/MC/MCFragment.h"
32 #include "llvm/MC/MCObjectWriter.h"
33 #include "llvm/MC/MCSection.h"
34 #include "llvm/MC/MCSectionELF.h"
35 #include "llvm/MC/MCSymbol.h"
36 #include "llvm/MC/MCSymbolELF.h"
37 #include "llvm/MC/MCValue.h"
38 #include "llvm/MC/StringTableBuilder.h"
39 #include "llvm/Support/Allocator.h"
40 #include "llvm/Support/Casting.h"
41 #include "llvm/Support/Compression.h"
42 #include "llvm/Support/Endian.h"
43 #include "llvm/Support/Error.h"
44 #include "llvm/Support/ErrorHandling.h"
45 #include "llvm/Support/Host.h"
46 #include "llvm/Support/MathExtras.h"
47 #include "llvm/Support/SMLoc.h"
48 #include "llvm/Support/StringSaver.h"
49 #include "llvm/Support/SwapByteOrder.h"
50 #include "llvm/Support/raw_ostream.h"
64 #define DEBUG_TYPE "reloc-info"
68 using SectionIndexMapTy = DenseMap<const MCSectionELF *, uint32_t>;
70 class ELFObjectWriter;
72 class SymbolTableWriter {
73 ELFObjectWriter &EWriter;
76 // indexes we are going to write to .symtab_shndx.
77 std::vector<uint32_t> ShndxIndexes;
79 // The numbel of symbols written so far.
82 void createSymtabShndx();
84 template <typename T> void write(T Value);
87 SymbolTableWriter(ELFObjectWriter &EWriter, bool Is64Bit);
89 void writeSymbol(uint32_t name, uint8_t info, uint64_t value, uint64_t size,
90 uint8_t other, uint32_t shndx, bool Reserved);
92 ArrayRef<uint32_t> getShndxIndexes() const { return ShndxIndexes; }
95 class ELFObjectWriter : public MCObjectWriter {
96 static uint64_t SymbolValue(const MCSymbol &Sym, const MCAsmLayout &Layout);
97 static bool isInSymtab(const MCAsmLayout &Layout, const MCSymbolELF &Symbol,
98 bool Used, bool Renamed);
100 /// Helper struct for containing some precomputed information on symbols.
101 struct ELFSymbolData {
102 const MCSymbolELF *Symbol;
103 uint32_t SectionIndex;
106 // Support lexicographic sorting.
107 bool operator<(const ELFSymbolData &RHS) const {
108 unsigned LHSType = Symbol->getType();
109 unsigned RHSType = RHS.Symbol->getType();
110 if (LHSType == ELF::STT_SECTION && RHSType != ELF::STT_SECTION)
112 if (LHSType != ELF::STT_SECTION && RHSType == ELF::STT_SECTION)
114 if (LHSType == ELF::STT_SECTION && RHSType == ELF::STT_SECTION)
115 return SectionIndex < RHS.SectionIndex;
116 return Name < RHS.Name;
120 /// The target specific ELF writer instance.
121 std::unique_ptr<MCELFObjectTargetWriter> TargetObjectWriter;
123 DenseMap<const MCSymbolELF *, const MCSymbolELF *> Renames;
125 DenseMap<const MCSectionELF *, std::vector<ELFRelocationEntry>> Relocations;
128 /// @name Symbol Table Data
131 StringTableBuilder StrTabBuilder{StringTableBuilder::ELF};
135 // This holds the symbol table index of the last local symbol.
136 unsigned LastLocalSymbolIndex;
137 // This holds the .strtab section index.
138 unsigned StringTableIndex;
139 // This holds the .symtab section index.
140 unsigned SymbolTableIndex;
142 // Sections in the order they are to be output in the section table.
143 std::vector<const MCSectionELF *> SectionTable;
144 unsigned addToSectionTable(const MCSectionELF *Sec);
146 // TargetObjectWriter wrappers.
147 bool is64Bit() const { return TargetObjectWriter->is64Bit(); }
148 bool hasRelocationAddend() const {
149 return TargetObjectWriter->hasRelocationAddend();
151 unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
152 const MCFixup &Fixup, bool IsPCRel) const {
153 return TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
156 void align(unsigned Alignment);
158 bool maybeWriteCompression(uint64_t Size,
159 SmallVectorImpl<char> &CompressedContents,
160 bool ZLibStyle, unsigned Alignment);
163 ELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
164 raw_pwrite_stream &OS, bool IsLittleEndian)
165 : MCObjectWriter(OS, IsLittleEndian),
166 TargetObjectWriter(std::move(MOTW)) {}
168 ~ELFObjectWriter() override = default;
170 void reset() override {
173 StrTabBuilder.clear();
174 SectionTable.clear();
175 MCObjectWriter::reset();
178 void WriteWord(uint64_t W) {
185 template <typename T> void write(T Val) {
187 support::endian::Writer<support::little>(getStream()).write(Val);
189 support::endian::Writer<support::big>(getStream()).write(Val);
192 void writeHeader(const MCAssembler &Asm);
194 void writeSymbol(SymbolTableWriter &Writer, uint32_t StringIndex,
195 ELFSymbolData &MSD, const MCAsmLayout &Layout);
197 // Start and end offset of each section
198 using SectionOffsetsTy =
199 std::map<const MCSectionELF *, std::pair<uint64_t, uint64_t>>;
201 bool shouldRelocateWithSymbol(const MCAssembler &Asm,
202 const MCSymbolRefExpr *RefA,
203 const MCSymbol *Sym, uint64_t C,
204 unsigned Type) const;
206 void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
207 const MCFragment *Fragment, const MCFixup &Fixup,
208 MCValue Target, uint64_t &FixedValue) override;
210 // Map from a signature symbol to the group section index
211 using RevGroupMapTy = DenseMap<const MCSymbol *, unsigned>;
213 /// Compute the symbol table data
215 /// \param Asm - The assembler.
216 /// \param SectionIndexMap - Maps a section to its index.
217 /// \param RevGroupMap - Maps a signature symbol to the group section.
218 void computeSymbolTable(MCAssembler &Asm, const MCAsmLayout &Layout,
219 const SectionIndexMapTy &SectionIndexMap,
220 const RevGroupMapTy &RevGroupMap,
221 SectionOffsetsTy &SectionOffsets);
223 MCSectionELF *createRelocationSection(MCContext &Ctx,
224 const MCSectionELF &Sec);
226 const MCSectionELF *createStringTable(MCContext &Ctx);
228 void executePostLayoutBinding(MCAssembler &Asm,
229 const MCAsmLayout &Layout) override;
231 void writeSectionHeader(const MCAsmLayout &Layout,
232 const SectionIndexMapTy &SectionIndexMap,
233 const SectionOffsetsTy &SectionOffsets);
235 void writeSectionData(const MCAssembler &Asm, MCSection &Sec,
236 const MCAsmLayout &Layout);
238 void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
239 uint64_t Address, uint64_t Offset, uint64_t Size,
240 uint32_t Link, uint32_t Info, uint64_t Alignment,
243 void writeRelocations(const MCAssembler &Asm, const MCSectionELF &Sec);
245 using MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl;
246 bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
247 const MCSymbol &SymA,
248 const MCFragment &FB, bool InSet,
249 bool IsPCRel) const override;
251 void writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) override;
252 void writeSection(const SectionIndexMapTy &SectionIndexMap,
253 uint32_t GroupSymbolIndex, uint64_t Offset, uint64_t Size,
254 const MCSectionELF &Section);
257 } // end anonymous namespace
259 void ELFObjectWriter::align(unsigned Alignment) {
260 uint64_t Padding = OffsetToAlignment(getStream().tell(), Alignment);
264 unsigned ELFObjectWriter::addToSectionTable(const MCSectionELF *Sec) {
265 SectionTable.push_back(Sec);
266 StrTabBuilder.add(Sec->getSectionName());
267 return SectionTable.size();
270 void SymbolTableWriter::createSymtabShndx() {
271 if (!ShndxIndexes.empty())
274 ShndxIndexes.resize(NumWritten);
277 template <typename T> void SymbolTableWriter::write(T Value) {
278 EWriter.write(Value);
281 SymbolTableWriter::SymbolTableWriter(ELFObjectWriter &EWriter, bool Is64Bit)
282 : EWriter(EWriter), Is64Bit(Is64Bit), NumWritten(0) {}
284 void SymbolTableWriter::writeSymbol(uint32_t name, uint8_t info, uint64_t value,
285 uint64_t size, uint8_t other,
286 uint32_t shndx, bool Reserved) {
287 bool LargeIndex = shndx >= ELF::SHN_LORESERVE && !Reserved;
292 if (!ShndxIndexes.empty()) {
294 ShndxIndexes.push_back(shndx);
296 ShndxIndexes.push_back(0);
299 uint16_t Index = LargeIndex ? uint16_t(ELF::SHN_XINDEX) : shndx;
302 write(name); // st_name
303 write(info); // st_info
304 write(other); // st_other
305 write(Index); // st_shndx
306 write(value); // st_value
307 write(size); // st_size
309 write(name); // st_name
310 write(uint32_t(value)); // st_value
311 write(uint32_t(size)); // st_size
312 write(info); // st_info
313 write(other); // st_other
314 write(Index); // st_shndx
320 // Emit the ELF header.
321 void ELFObjectWriter::writeHeader(const MCAssembler &Asm) {
327 // emitWord method behaves differently for ELF32 and ELF64, writing
328 // 4 bytes in the former and 8 in the latter.
330 writeBytes(ELF::ElfMagic); // e_ident[EI_MAG0] to e_ident[EI_MAG3]
332 write8(is64Bit() ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]
335 write8(isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
337 write8(ELF::EV_CURRENT); // e_ident[EI_VERSION]
339 write8(TargetObjectWriter->getOSABI());
340 write8(0); // e_ident[EI_ABIVERSION]
342 WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD);
344 write16(ELF::ET_REL); // e_type
346 write16(TargetObjectWriter->getEMachine()); // e_machine = target
348 write32(ELF::EV_CURRENT); // e_version
349 WriteWord(0); // e_entry, no entry point in .o file
350 WriteWord(0); // e_phoff, no program header for .o
351 WriteWord(0); // e_shoff = sec hdr table off in bytes
353 // e_flags = whatever the target wants
354 write32(Asm.getELFHeaderEFlags());
356 // e_ehsize = ELF header size
357 write16(is64Bit() ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr));
359 write16(0); // e_phentsize = prog header entry size
360 write16(0); // e_phnum = # prog header entries = 0
362 // e_shentsize = Section header entry size
363 write16(is64Bit() ? sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr));
365 // e_shnum = # of section header ents
368 // e_shstrndx = Section # of '.shstrtab'
369 assert(StringTableIndex < ELF::SHN_LORESERVE);
370 write16(StringTableIndex);
373 uint64_t ELFObjectWriter::SymbolValue(const MCSymbol &Sym,
374 const MCAsmLayout &Layout) {
375 if (Sym.isCommon() && Sym.isExternal())
376 return Sym.getCommonAlignment();
379 if (!Layout.getSymbolOffset(Sym, Res))
382 if (Layout.getAssembler().isThumbFunc(&Sym))
388 void ELFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
389 const MCAsmLayout &Layout) {
390 // The presence of symbol versions causes undefined symbols and
391 // versions declared with @@@ to be renamed.
392 for (const std::pair<StringRef, const MCSymbol *> &P : Asm.Symvers) {
393 StringRef AliasName = P.first;
394 const auto &Symbol = cast<MCSymbolELF>(*P.second);
395 size_t Pos = AliasName.find('@');
396 assert(Pos != StringRef::npos);
398 StringRef Prefix = AliasName.substr(0, Pos);
399 StringRef Rest = AliasName.substr(Pos);
400 StringRef Tail = Rest;
401 if (Rest.startswith("@@@"))
402 Tail = Rest.substr(Symbol.isUndefined() ? 2 : 1);
405 cast<MCSymbolELF>(Asm.getContext().getOrCreateSymbol(Prefix + Tail));
406 Asm.registerSymbol(*Alias);
407 const MCExpr *Value = MCSymbolRefExpr::create(&Symbol, Asm.getContext());
408 Alias->setVariableValue(Value);
410 // Aliases defined with .symvar copy the binding from the symbol they alias.
411 // This is the first place we are able to copy this information.
412 Alias->setExternal(Symbol.isExternal());
413 Alias->setBinding(Symbol.getBinding());
415 if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
418 // FIXME: produce a better error message.
419 if (Symbol.isUndefined() && Rest.startswith("@@") &&
420 !Rest.startswith("@@@"))
421 report_fatal_error("A @@ version cannot be undefined");
423 Renames.insert(std::make_pair(&Symbol, Alias));
427 static uint8_t mergeTypeForSet(uint8_t origType, uint8_t newType) {
428 uint8_t Type = newType;
430 // Propagation rules:
431 // IFUNC > FUNC > OBJECT > NOTYPE
432 // TLS_OBJECT > OBJECT > NOTYPE
434 // dont let the new type degrade the old type
438 case ELF::STT_GNU_IFUNC:
439 if (Type == ELF::STT_FUNC || Type == ELF::STT_OBJECT ||
440 Type == ELF::STT_NOTYPE || Type == ELF::STT_TLS)
441 Type = ELF::STT_GNU_IFUNC;
444 if (Type == ELF::STT_OBJECT || Type == ELF::STT_NOTYPE ||
445 Type == ELF::STT_TLS)
446 Type = ELF::STT_FUNC;
448 case ELF::STT_OBJECT:
449 if (Type == ELF::STT_NOTYPE)
450 Type = ELF::STT_OBJECT;
453 if (Type == ELF::STT_OBJECT || Type == ELF::STT_NOTYPE ||
454 Type == ELF::STT_GNU_IFUNC || Type == ELF::STT_FUNC)
462 void ELFObjectWriter::writeSymbol(SymbolTableWriter &Writer,
463 uint32_t StringIndex, ELFSymbolData &MSD,
464 const MCAsmLayout &Layout) {
465 const auto &Symbol = cast<MCSymbolELF>(*MSD.Symbol);
466 const MCSymbolELF *Base =
467 cast_or_null<MCSymbolELF>(Layout.getBaseSymbol(Symbol));
469 // This has to be in sync with when computeSymbolTable uses SHN_ABS or
471 bool IsReserved = !Base || Symbol.isCommon();
473 // Binding and Type share the same byte as upper and lower nibbles
474 uint8_t Binding = Symbol.getBinding();
475 uint8_t Type = Symbol.getType();
477 Type = mergeTypeForSet(Type, Base->getType());
479 uint8_t Info = (Binding << 4) | Type;
481 // Other and Visibility share the same byte with Visibility using the lower
483 uint8_t Visibility = Symbol.getVisibility();
484 uint8_t Other = Symbol.getOther() | Visibility;
486 uint64_t Value = SymbolValue(*MSD.Symbol, Layout);
489 const MCExpr *ESize = MSD.Symbol->getSize();
491 ESize = Base->getSize();
495 if (!ESize->evaluateKnownAbsolute(Res, Layout))
496 report_fatal_error("Size expression must be absolute.");
500 // Write out the symbol table entry
501 Writer.writeSymbol(StringIndex, Info, Value, Size, Other, MSD.SectionIndex,
505 // It is always valid to create a relocation with a symbol. It is preferable
506 // to use a relocation with a section if that is possible. Using the section
507 // allows us to omit some local symbols from the symbol table.
508 bool ELFObjectWriter::shouldRelocateWithSymbol(const MCAssembler &Asm,
509 const MCSymbolRefExpr *RefA,
510 const MCSymbol *S, uint64_t C,
511 unsigned Type) const {
512 const auto *Sym = cast_or_null<MCSymbolELF>(S);
513 // A PCRel relocation to an absolute value has no symbol (or section). We
514 // represent that with a relocation to a null section.
518 MCSymbolRefExpr::VariantKind Kind = RefA->getKind();
522 // The .odp creation emits a relocation against the symbol ".TOC." which
523 // create a R_PPC64_TOC relocation. However the relocation symbol name
524 // in final object creation should be NULL, since the symbol does not
525 // really exist, it is just the reference to TOC base for the current
526 // object file. Since the symbol is undefined, returning false results
527 // in a relocation with a null section which is the desired result.
528 case MCSymbolRefExpr::VK_PPC_TOCBASE:
531 // These VariantKind cause the relocation to refer to something other than
532 // the symbol itself, like a linker generated table. Since the address of
533 // symbol is not relevant, we cannot replace the symbol with the
534 // section and patch the difference in the addend.
535 case MCSymbolRefExpr::VK_GOT:
536 case MCSymbolRefExpr::VK_PLT:
537 case MCSymbolRefExpr::VK_GOTPCREL:
538 case MCSymbolRefExpr::VK_PPC_GOT_LO:
539 case MCSymbolRefExpr::VK_PPC_GOT_HI:
540 case MCSymbolRefExpr::VK_PPC_GOT_HA:
544 // An undefined symbol is not in any section, so the relocation has to point
545 // to the symbol itself.
546 assert(Sym && "Expected a symbol");
547 if (Sym->isUndefined())
550 unsigned Binding = Sym->getBinding();
553 llvm_unreachable("Invalid Binding");
557 // If the symbol is weak, it might be overridden by a symbol in another
558 // file. The relocation has to point to the symbol so that the linker
561 case ELF::STB_GLOBAL:
562 // Global ELF symbols can be preempted by the dynamic linker. The relocation
563 // has to point to the symbol for a reason analogous to the STB_WEAK case.
567 // If a relocation points to a mergeable section, we have to be careful.
568 // If the offset is zero, a relocation with the section will encode the
569 // same information. With a non-zero offset, the situation is different.
570 // For example, a relocation can point 42 bytes past the end of a string.
571 // If we change such a relocation to use the section, the linker would think
572 // that it pointed to another string and subtracting 42 at runtime will
573 // produce the wrong value.
574 if (Sym->isInSection()) {
575 auto &Sec = cast<MCSectionELF>(Sym->getSection());
576 unsigned Flags = Sec.getFlags();
577 if (Flags & ELF::SHF_MERGE) {
581 // It looks like gold has a bug (http://sourceware.org/PR16794) and can
582 // only handle section relocations to mergeable sections if using RELA.
583 if (!hasRelocationAddend())
587 // Most TLS relocations use a got, so they need the symbol. Even those that
588 // are just an offset (@tpoff), require a symbol in gold versions before
589 // 5efeedf61e4fe720fd3e9a08e6c91c10abb66d42 (2014-09-26) which fixed
590 // http://sourceware.org/PR16773.
591 if (Flags & ELF::SHF_TLS)
595 // If the symbol is a thumb function the final relocation must set the lowest
596 // bit. With a symbol that is done by just having the symbol have that bit
597 // set, so we would lose the bit if we relocated with the section.
598 // FIXME: We could use the section but add the bit to the relocation value.
599 if (Asm.isThumbFunc(Sym))
602 if (TargetObjectWriter->needsRelocateWithSymbol(*Sym, Type))
607 // True if the assembler knows nothing about the final value of the symbol.
608 // This doesn't cover the comdat issues, since in those cases the assembler
609 // can at least know that all symbols in the section will move together.
610 static bool isWeak(const MCSymbolELF &Sym) {
611 if (Sym.getType() == ELF::STT_GNU_IFUNC)
614 switch (Sym.getBinding()) {
616 llvm_unreachable("Unknown binding");
619 case ELF::STB_GLOBAL:
622 case ELF::STB_GNU_UNIQUE:
627 void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
628 const MCAsmLayout &Layout,
629 const MCFragment *Fragment,
630 const MCFixup &Fixup, MCValue Target,
631 uint64_t &FixedValue) {
632 MCAsmBackend &Backend = Asm.getBackend();
633 bool IsPCRel = Backend.getFixupKindInfo(Fixup.getKind()).Flags &
634 MCFixupKindInfo::FKF_IsPCRel;
635 const MCSectionELF &FixupSection = cast<MCSectionELF>(*Fragment->getParent());
636 uint64_t C = Target.getConstant();
637 uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
638 MCContext &Ctx = Asm.getContext();
640 if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
641 // Let A, B and C being the components of Target and R be the location of
642 // the fixup. If the fixup is not pcrel, we want to compute (A - B + C).
643 // If it is pcrel, we want to compute (A - B + C - R).
645 // In general, ELF has no relocations for -B. It can only represent (A + C)
646 // or (A + C - R). If B = R + K and the relocation is not pcrel, we can
647 // replace B to implement it: (A - R - K + C)
651 "No relocation available to represent this relative expression");
655 const auto &SymB = cast<MCSymbolELF>(RefB->getSymbol());
657 if (SymB.isUndefined()) {
658 Ctx.reportError(Fixup.getLoc(),
659 Twine("symbol '") + SymB.getName() +
660 "' can not be undefined in a subtraction expression");
664 assert(!SymB.isAbsolute() && "Should have been folded");
665 const MCSection &SecB = SymB.getSection();
666 if (&SecB != &FixupSection) {
667 Ctx.reportError(Fixup.getLoc(),
668 "Cannot represent a difference across sections");
672 uint64_t SymBOffset = Layout.getSymbolOffset(SymB);
673 uint64_t K = SymBOffset - FixupOffset;
678 // We either rejected the fixup or folded B into C at this point.
679 const MCSymbolRefExpr *RefA = Target.getSymA();
680 const auto *SymA = RefA ? cast<MCSymbolELF>(&RefA->getSymbol()) : nullptr;
682 bool ViaWeakRef = false;
683 if (SymA && SymA->isVariable()) {
684 const MCExpr *Expr = SymA->getVariableValue();
685 if (const auto *Inner = dyn_cast<MCSymbolRefExpr>(Expr)) {
686 if (Inner->getKind() == MCSymbolRefExpr::VK_WEAKREF) {
687 SymA = cast<MCSymbolELF>(&Inner->getSymbol());
693 unsigned Type = getRelocType(Ctx, Target, Fixup, IsPCRel);
694 uint64_t OriginalC = C;
695 bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
696 if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
697 C += Layout.getSymbolOffset(*SymA);
700 if (hasRelocationAddend()) {
707 if (!RelocateWithSymbol) {
708 const MCSection *SecA =
709 (SymA && !SymA->isUndefined()) ? &SymA->getSection() : nullptr;
710 auto *ELFSec = cast_or_null<MCSectionELF>(SecA);
711 const auto *SectionSymbol =
712 ELFSec ? cast<MCSymbolELF>(ELFSec->getBeginSymbol()) : nullptr;
714 SectionSymbol->setUsedInReloc();
715 ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend, SymA,
717 Relocations[&FixupSection].push_back(Rec);
721 const auto *RenamedSymA = SymA;
723 if (const MCSymbolELF *R = Renames.lookup(SymA))
727 RenamedSymA->setIsWeakrefUsedInReloc();
729 RenamedSymA->setUsedInReloc();
731 ELFRelocationEntry Rec(FixupOffset, RenamedSymA, Type, Addend, SymA,
733 Relocations[&FixupSection].push_back(Rec);
736 bool ELFObjectWriter::isInSymtab(const MCAsmLayout &Layout,
737 const MCSymbolELF &Symbol, bool Used,
739 if (Symbol.isVariable()) {
740 const MCExpr *Expr = Symbol.getVariableValue();
741 if (const MCSymbolRefExpr *Ref = dyn_cast<MCSymbolRefExpr>(Expr)) {
742 if (Ref->getKind() == MCSymbolRefExpr::VK_WEAKREF)
753 if (Symbol.isVariable() && Symbol.isUndefined()) {
754 // FIXME: this is here just to diagnose the case of a var = commmon_sym.
755 Layout.getBaseSymbol(Symbol);
759 if (Symbol.isUndefined() && !Symbol.isBindingSet())
762 if (Symbol.isTemporary())
765 if (Symbol.getType() == ELF::STT_SECTION)
771 void ELFObjectWriter::computeSymbolTable(
772 MCAssembler &Asm, const MCAsmLayout &Layout,
773 const SectionIndexMapTy &SectionIndexMap, const RevGroupMapTy &RevGroupMap,
774 SectionOffsetsTy &SectionOffsets) {
775 MCContext &Ctx = Asm.getContext();
776 SymbolTableWriter Writer(*this, is64Bit());
779 unsigned EntrySize = is64Bit() ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
780 MCSectionELF *SymtabSection =
781 Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, EntrySize, "");
782 SymtabSection->setAlignment(is64Bit() ? 8 : 4);
783 SymbolTableIndex = addToSectionTable(SymtabSection);
785 align(SymtabSection->getAlignment());
786 uint64_t SecStart = getStream().tell();
788 // The first entry is the undefined symbol entry.
789 Writer.writeSymbol(0, 0, 0, 0, 0, 0, false);
791 std::vector<ELFSymbolData> LocalSymbolData;
792 std::vector<ELFSymbolData> ExternalSymbolData;
794 // Add the data for the symbols.
795 bool HasLargeSectionIndex = false;
796 for (const MCSymbol &S : Asm.symbols()) {
797 const auto &Symbol = cast<MCSymbolELF>(S);
798 bool Used = Symbol.isUsedInReloc();
799 bool WeakrefUsed = Symbol.isWeakrefUsedInReloc();
800 bool isSignature = Symbol.isSignature();
802 if (!isInSymtab(Layout, Symbol, Used || WeakrefUsed || isSignature,
803 Renames.count(&Symbol)))
806 if (Symbol.isTemporary() && Symbol.isUndefined()) {
807 Ctx.reportError(SMLoc(), "Undefined temporary symbol");
812 MSD.Symbol = cast<MCSymbolELF>(&Symbol);
814 bool Local = Symbol.getBinding() == ELF::STB_LOCAL;
815 assert(Local || !Symbol.isTemporary());
817 if (Symbol.isAbsolute()) {
818 MSD.SectionIndex = ELF::SHN_ABS;
819 } else if (Symbol.isCommon()) {
821 MSD.SectionIndex = ELF::SHN_COMMON;
822 } else if (Symbol.isUndefined()) {
823 if (isSignature && !Used) {
824 MSD.SectionIndex = RevGroupMap.lookup(&Symbol);
825 if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
826 HasLargeSectionIndex = true;
828 MSD.SectionIndex = ELF::SHN_UNDEF;
831 const MCSectionELF &Section =
832 static_cast<const MCSectionELF &>(Symbol.getSection());
833 MSD.SectionIndex = SectionIndexMap.lookup(&Section);
834 assert(MSD.SectionIndex && "Invalid section index!");
835 if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
836 HasLargeSectionIndex = true;
839 StringRef Name = Symbol.getName();
841 // Sections have their own string table
842 if (Symbol.getType() != ELF::STT_SECTION) {
844 StrTabBuilder.add(Name);
848 LocalSymbolData.push_back(MSD);
850 ExternalSymbolData.push_back(MSD);
853 // This holds the .symtab_shndx section index.
854 unsigned SymtabShndxSectionIndex = 0;
856 if (HasLargeSectionIndex) {
857 MCSectionELF *SymtabShndxSection =
858 Ctx.getELFSection(".symtab_shndxr", ELF::SHT_SYMTAB_SHNDX, 0, 4, "");
859 SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
860 SymtabShndxSection->setAlignment(4);
863 ArrayRef<std::string> FileNames = Asm.getFileNames();
864 for (const std::string &Name : FileNames)
865 StrTabBuilder.add(Name);
867 StrTabBuilder.finalize();
869 // File symbols are emitted first and handled separately from normal symbols,
870 // i.e. a non-STT_FILE symbol with the same name may appear.
871 for (const std::string &Name : FileNames)
872 Writer.writeSymbol(StrTabBuilder.getOffset(Name),
873 ELF::STT_FILE | ELF::STB_LOCAL, 0, 0, ELF::STV_DEFAULT,
876 // Symbols are required to be in lexicographic order.
877 array_pod_sort(LocalSymbolData.begin(), LocalSymbolData.end());
878 array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
880 // Set the symbol indices. Local symbols must come before all other
881 // symbols with non-local bindings.
882 unsigned Index = FileNames.size() + 1;
884 for (ELFSymbolData &MSD : LocalSymbolData) {
885 unsigned StringIndex = MSD.Symbol->getType() == ELF::STT_SECTION
887 : StrTabBuilder.getOffset(MSD.Name);
888 MSD.Symbol->setIndex(Index++);
889 writeSymbol(Writer, StringIndex, MSD, Layout);
892 // Write the symbol table entries.
893 LastLocalSymbolIndex = Index;
895 for (ELFSymbolData &MSD : ExternalSymbolData) {
896 unsigned StringIndex = StrTabBuilder.getOffset(MSD.Name);
897 MSD.Symbol->setIndex(Index++);
898 writeSymbol(Writer, StringIndex, MSD, Layout);
899 assert(MSD.Symbol->getBinding() != ELF::STB_LOCAL);
902 uint64_t SecEnd = getStream().tell();
903 SectionOffsets[SymtabSection] = std::make_pair(SecStart, SecEnd);
905 ArrayRef<uint32_t> ShndxIndexes = Writer.getShndxIndexes();
906 if (ShndxIndexes.empty()) {
907 assert(SymtabShndxSectionIndex == 0);
910 assert(SymtabShndxSectionIndex != 0);
912 SecStart = getStream().tell();
913 const MCSectionELF *SymtabShndxSection =
914 SectionTable[SymtabShndxSectionIndex - 1];
915 for (uint32_t Index : ShndxIndexes)
917 SecEnd = getStream().tell();
918 SectionOffsets[SymtabShndxSection] = std::make_pair(SecStart, SecEnd);
922 ELFObjectWriter::createRelocationSection(MCContext &Ctx,
923 const MCSectionELF &Sec) {
924 if (Relocations[&Sec].empty())
927 const StringRef SectionName = Sec.getSectionName();
928 std::string RelaSectionName = hasRelocationAddend() ? ".rela" : ".rel";
929 RelaSectionName += SectionName;
932 if (hasRelocationAddend())
933 EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
935 EntrySize = is64Bit() ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
938 if (Sec.getFlags() & ELF::SHF_GROUP)
939 Flags = ELF::SHF_GROUP;
941 MCSectionELF *RelaSection = Ctx.createELFRelSection(
942 RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
943 Flags, EntrySize, Sec.getGroup(), &Sec);
944 RelaSection->setAlignment(is64Bit() ? 8 : 4);
948 // Include the debug info compression header.
949 bool ELFObjectWriter::maybeWriteCompression(
950 uint64_t Size, SmallVectorImpl<char> &CompressedContents, bool ZLibStyle,
951 unsigned Alignment) {
954 is64Bit() ? sizeof(ELF::Elf32_Chdr) : sizeof(ELF::Elf64_Chdr);
955 if (Size <= HdrSize + CompressedContents.size())
957 // Platform specific header is followed by compressed data.
959 // Write Elf64_Chdr header.
960 write(static_cast<ELF::Elf64_Word>(ELF::ELFCOMPRESS_ZLIB));
961 write(static_cast<ELF::Elf64_Word>(0)); // ch_reserved field.
962 write(static_cast<ELF::Elf64_Xword>(Size));
963 write(static_cast<ELF::Elf64_Xword>(Alignment));
965 // Write Elf32_Chdr header otherwise.
966 write(static_cast<ELF::Elf32_Word>(ELF::ELFCOMPRESS_ZLIB));
967 write(static_cast<ELF::Elf32_Word>(Size));
968 write(static_cast<ELF::Elf32_Word>(Alignment));
973 // "ZLIB" followed by 8 bytes representing the uncompressed size of the section,
974 // useful for consumers to preallocate a buffer to decompress into.
975 const StringRef Magic = "ZLIB";
976 if (Size <= Magic.size() + sizeof(Size) + CompressedContents.size())
978 write(ArrayRef<char>(Magic.begin(), Magic.size()));
983 void ELFObjectWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
984 const MCAsmLayout &Layout) {
985 MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
986 StringRef SectionName = Section.getSectionName();
988 auto &MC = Asm.getContext();
989 const auto &MAI = MC.getAsmInfo();
991 // Compressing debug_frame requires handling alignment fragments which is
992 // more work (possibly generalizing MCAssembler.cpp:writeFragment to allow
993 // for writing to arbitrary buffers) for little benefit.
994 bool CompressionEnabled =
995 MAI->compressDebugSections() != DebugCompressionType::None;
996 if (!CompressionEnabled || !SectionName.startswith(".debug_") ||
997 SectionName == ".debug_frame") {
998 Asm.writeSectionData(&Section, Layout);
1002 assert((MAI->compressDebugSections() == DebugCompressionType::Z ||
1003 MAI->compressDebugSections() == DebugCompressionType::GNU) &&
1004 "expected zlib or zlib-gnu style compression");
1006 SmallVector<char, 128> UncompressedData;
1007 raw_svector_ostream VecOS(UncompressedData);
1008 raw_pwrite_stream &OldStream = getStream();
1010 Asm.writeSectionData(&Section, Layout);
1011 setStream(OldStream);
1013 SmallVector<char, 128> CompressedContents;
1014 if (Error E = zlib::compress(
1015 StringRef(UncompressedData.data(), UncompressedData.size()),
1016 CompressedContents)) {
1017 consumeError(std::move(E));
1018 getStream() << UncompressedData;
1022 bool ZlibStyle = MAI->compressDebugSections() == DebugCompressionType::Z;
1023 if (!maybeWriteCompression(UncompressedData.size(), CompressedContents,
1024 ZlibStyle, Sec.getAlignment())) {
1025 getStream() << UncompressedData;
1030 // Set the compressed flag. That is zlib style.
1031 Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);
1033 // Add "z" prefix to section name. This is zlib-gnu style.
1034 MC.renameELFSection(&Section, (".z" + SectionName.drop_front(1)).str());
1035 getStream() << CompressedContents;
1038 void ELFObjectWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
1039 uint64_t Flags, uint64_t Address,
1040 uint64_t Offset, uint64_t Size,
1041 uint32_t Link, uint32_t Info,
1043 uint64_t EntrySize) {
1044 write32(Name); // sh_name: index into string table
1045 write32(Type); // sh_type
1046 WriteWord(Flags); // sh_flags
1047 WriteWord(Address); // sh_addr
1048 WriteWord(Offset); // sh_offset
1049 WriteWord(Size); // sh_size
1050 write32(Link); // sh_link
1051 write32(Info); // sh_info
1052 WriteWord(Alignment); // sh_addralign
1053 WriteWord(EntrySize); // sh_entsize
1056 void ELFObjectWriter::writeRelocations(const MCAssembler &Asm,
1057 const MCSectionELF &Sec) {
1058 std::vector<ELFRelocationEntry> &Relocs = Relocations[&Sec];
1060 // We record relocations by pushing to the end of a vector. Reverse the vector
1061 // to get the relocations in the order they were created.
1062 // In most cases that is not important, but it can be for special sections
1063 // (.eh_frame) or specific relocations (TLS optimizations on SystemZ).
1064 std::reverse(Relocs.begin(), Relocs.end());
1066 // Sort the relocation entries. MIPS needs this.
1067 TargetObjectWriter->sortRelocs(Asm, Relocs);
1069 for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
1070 const ELFRelocationEntry &Entry = Relocs[e - i - 1];
1071 unsigned Index = Entry.Symbol ? Entry.Symbol->getIndex() : 0;
1074 write(Entry.Offset);
1075 if (TargetObjectWriter->getEMachine() == ELF::EM_MIPS) {
1076 write(uint32_t(Index));
1078 write(TargetObjectWriter->getRSsym(Entry.Type));
1079 write(TargetObjectWriter->getRType3(Entry.Type));
1080 write(TargetObjectWriter->getRType2(Entry.Type));
1081 write(TargetObjectWriter->getRType(Entry.Type));
1083 struct ELF::Elf64_Rela ERE64;
1084 ERE64.setSymbolAndType(Index, Entry.Type);
1085 write(ERE64.r_info);
1087 if (hasRelocationAddend())
1088 write(Entry.Addend);
1090 write(uint32_t(Entry.Offset));
1092 struct ELF::Elf32_Rela ERE32;
1093 ERE32.setSymbolAndType(Index, Entry.Type);
1094 write(ERE32.r_info);
1096 if (hasRelocationAddend())
1097 write(uint32_t(Entry.Addend));
1099 if (TargetObjectWriter->getEMachine() == ELF::EM_MIPS) {
1100 if (uint32_t RType = TargetObjectWriter->getRType2(Entry.Type)) {
1101 write(uint32_t(Entry.Offset));
1103 ERE32.setSymbolAndType(0, RType);
1104 write(ERE32.r_info);
1107 if (uint32_t RType = TargetObjectWriter->getRType3(Entry.Type)) {
1108 write(uint32_t(Entry.Offset));
1110 ERE32.setSymbolAndType(0, RType);
1111 write(ERE32.r_info);
1119 const MCSectionELF *ELFObjectWriter::createStringTable(MCContext &Ctx) {
1120 const MCSectionELF *StrtabSection = SectionTable[StringTableIndex - 1];
1121 StrTabBuilder.write(getStream());
1122 return StrtabSection;
1125 void ELFObjectWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
1126 uint32_t GroupSymbolIndex, uint64_t Offset,
1127 uint64_t Size, const MCSectionELF &Section) {
1128 uint64_t sh_link = 0;
1129 uint64_t sh_info = 0;
1131 switch(Section.getType()) {
1136 case ELF::SHT_DYNAMIC:
1137 llvm_unreachable("SHT_DYNAMIC in a relocatable object");
1140 case ELF::SHT_RELA: {
1141 sh_link = SymbolTableIndex;
1142 assert(sh_link && ".symtab not found");
1143 const MCSection *InfoSection = Section.getAssociatedSection();
1144 sh_info = SectionIndexMap.lookup(cast<MCSectionELF>(InfoSection));
1148 case ELF::SHT_SYMTAB:
1149 case ELF::SHT_DYNSYM:
1150 sh_link = StringTableIndex;
1151 sh_info = LastLocalSymbolIndex;
1154 case ELF::SHT_SYMTAB_SHNDX:
1155 sh_link = SymbolTableIndex;
1158 case ELF::SHT_GROUP:
1159 sh_link = SymbolTableIndex;
1160 sh_info = GroupSymbolIndex;
1164 if (Section.getFlags() & ELF::SHF_LINK_ORDER) {
1165 const MCSymbol *Sym = Section.getAssociatedSymbol();
1166 const MCSectionELF *Sec = cast<MCSectionELF>(&Sym->getSection());
1167 sh_link = SectionIndexMap.lookup(Sec);
1170 WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getSectionName()),
1171 Section.getType(), Section.getFlags(), 0, Offset, Size,
1172 sh_link, sh_info, Section.getAlignment(),
1173 Section.getEntrySize());
1176 void ELFObjectWriter::writeSectionHeader(
1177 const MCAsmLayout &Layout, const SectionIndexMapTy &SectionIndexMap,
1178 const SectionOffsetsTy &SectionOffsets) {
1179 const unsigned NumSections = SectionTable.size();
1181 // Null section first.
1182 uint64_t FirstSectionSize =
1183 (NumSections + 1) >= ELF::SHN_LORESERVE ? NumSections + 1 : 0;
1184 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, 0, 0, 0, 0);
1186 for (const MCSectionELF *Section : SectionTable) {
1187 uint32_t GroupSymbolIndex;
1188 unsigned Type = Section->getType();
1189 if (Type != ELF::SHT_GROUP)
1190 GroupSymbolIndex = 0;
1192 GroupSymbolIndex = Section->getGroup()->getIndex();
1194 const std::pair<uint64_t, uint64_t> &Offsets =
1195 SectionOffsets.find(Section)->second;
1197 if (Type == ELF::SHT_NOBITS)
1198 Size = Layout.getSectionAddressSize(Section);
1200 Size = Offsets.second - Offsets.first;
1202 writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
1207 void ELFObjectWriter::writeObject(MCAssembler &Asm,
1208 const MCAsmLayout &Layout) {
1209 MCContext &Ctx = Asm.getContext();
1210 MCSectionELF *StrtabSection =
1211 Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0);
1212 StringTableIndex = addToSectionTable(StrtabSection);
1214 RevGroupMapTy RevGroupMap;
1215 SectionIndexMapTy SectionIndexMap;
1217 std::map<const MCSymbol *, std::vector<const MCSectionELF *>> GroupMembers;
1219 // Write out the ELF header ...
1222 // ... then the sections ...
1223 SectionOffsetsTy SectionOffsets;
1224 std::vector<MCSectionELF *> Groups;
1225 std::vector<MCSectionELF *> Relocations;
1226 for (MCSection &Sec : Asm) {
1227 MCSectionELF &Section = static_cast<MCSectionELF &>(Sec);
1229 align(Section.getAlignment());
1231 // Remember the offset into the file for this section.
1232 uint64_t SecStart = getStream().tell();
1234 const MCSymbolELF *SignatureSymbol = Section.getGroup();
1235 writeSectionData(Asm, Section, Layout);
1237 uint64_t SecEnd = getStream().tell();
1238 SectionOffsets[&Section] = std::make_pair(SecStart, SecEnd);
1240 MCSectionELF *RelSection = createRelocationSection(Ctx, Section);
1242 if (SignatureSymbol) {
1243 Asm.registerSymbol(*SignatureSymbol);
1244 unsigned &GroupIdx = RevGroupMap[SignatureSymbol];
1246 MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
1247 GroupIdx = addToSectionTable(Group);
1248 Group->setAlignment(4);
1249 Groups.push_back(Group);
1251 std::vector<const MCSectionELF *> &Members =
1252 GroupMembers[SignatureSymbol];
1253 Members.push_back(&Section);
1255 Members.push_back(RelSection);
1258 SectionIndexMap[&Section] = addToSectionTable(&Section);
1260 SectionIndexMap[RelSection] = addToSectionTable(RelSection);
1261 Relocations.push_back(RelSection);
1265 for (MCSectionELF *Group : Groups) {
1266 align(Group->getAlignment());
1268 // Remember the offset into the file for this section.
1269 uint64_t SecStart = getStream().tell();
1271 const MCSymbol *SignatureSymbol = Group->getGroup();
1272 assert(SignatureSymbol);
1273 write(uint32_t(ELF::GRP_COMDAT));
1274 for (const MCSectionELF *Member : GroupMembers[SignatureSymbol]) {
1275 uint32_t SecIndex = SectionIndexMap.lookup(Member);
1279 uint64_t SecEnd = getStream().tell();
1280 SectionOffsets[Group] = std::make_pair(SecStart, SecEnd);
1283 // Compute symbol table information.
1284 computeSymbolTable(Asm, Layout, SectionIndexMap, RevGroupMap, SectionOffsets);
1286 for (MCSectionELF *RelSection : Relocations) {
1287 align(RelSection->getAlignment());
1289 // Remember the offset into the file for this section.
1290 uint64_t SecStart = getStream().tell();
1292 writeRelocations(Asm,
1293 cast<MCSectionELF>(*RelSection->getAssociatedSection()));
1295 uint64_t SecEnd = getStream().tell();
1296 SectionOffsets[RelSection] = std::make_pair(SecStart, SecEnd);
1300 uint64_t SecStart = getStream().tell();
1301 const MCSectionELF *Sec = createStringTable(Ctx);
1302 uint64_t SecEnd = getStream().tell();
1303 SectionOffsets[Sec] = std::make_pair(SecStart, SecEnd);
1306 uint64_t NaturalAlignment = is64Bit() ? 8 : 4;
1307 align(NaturalAlignment);
1309 const uint64_t SectionHeaderOffset = getStream().tell();
1311 // ... then the section header table ...
1312 writeSectionHeader(Layout, SectionIndexMap, SectionOffsets);
1314 uint16_t NumSections = (SectionTable.size() + 1 >= ELF::SHN_LORESERVE)
1315 ? (uint16_t)ELF::SHN_UNDEF
1316 : SectionTable.size() + 1;
1317 if (sys::IsLittleEndianHost != IsLittleEndian)
1318 sys::swapByteOrder(NumSections);
1319 unsigned NumSectionsOffset;
1322 uint64_t Val = SectionHeaderOffset;
1323 if (sys::IsLittleEndianHost != IsLittleEndian)
1324 sys::swapByteOrder(Val);
1325 getStream().pwrite(reinterpret_cast<char *>(&Val), sizeof(Val),
1326 offsetof(ELF::Elf64_Ehdr, e_shoff));
1327 NumSectionsOffset = offsetof(ELF::Elf64_Ehdr, e_shnum);
1329 uint32_t Val = SectionHeaderOffset;
1330 if (sys::IsLittleEndianHost != IsLittleEndian)
1331 sys::swapByteOrder(Val);
1332 getStream().pwrite(reinterpret_cast<char *>(&Val), sizeof(Val),
1333 offsetof(ELF::Elf32_Ehdr, e_shoff));
1334 NumSectionsOffset = offsetof(ELF::Elf32_Ehdr, e_shnum);
1336 getStream().pwrite(reinterpret_cast<char *>(&NumSections),
1337 sizeof(NumSections), NumSectionsOffset);
1340 bool ELFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
1341 const MCAssembler &Asm, const MCSymbol &SA, const MCFragment &FB,
1342 bool InSet, bool IsPCRel) const {
1343 const auto &SymA = cast<MCSymbolELF>(SA);
1349 return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
1353 std::unique_ptr<MCObjectWriter>
1354 llvm::createELFObjectWriter(std::unique_ptr<MCELFObjectTargetWriter> MOTW,
1355 raw_pwrite_stream &OS, bool IsLittleEndian) {
1356 return llvm::make_unique<ELFObjectWriter>(std::move(MOTW), OS,