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/MC/ELFObjectWriter.h"
15 #include "llvm/ADT/SmallPtrSet.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/Twine.h"
19 #include "llvm/MC/MCAssembler.h"
20 #include "llvm/MC/MCAsmLayout.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCELFSymbolFlags.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCObjectWriter.h"
25 #include "llvm/MC/MCSectionELF.h"
26 #include "llvm/MC/MCSymbol.h"
27 #include "llvm/MC/MCValue.h"
28 #include "llvm/Support/Debug.h"
29 #include "llvm/Support/ErrorHandling.h"
30 #include "llvm/Support/ELF.h"
31 #include "llvm/Target/TargetAsmBackend.h"
33 #include "../Target/X86/X86FixupKinds.h"
38 static unsigned GetType(const MCSymbolData &SD) {
39 uint32_t Type = (SD.getFlags() & (0xf << ELF_STT_Shift)) >> ELF_STT_Shift;
40 assert(Type == ELF::STT_NOTYPE || Type == ELF::STT_OBJECT ||
41 Type == ELF::STT_FUNC || Type == ELF::STT_SECTION ||
42 Type == ELF::STT_FILE || Type == ELF::STT_COMMON ||
43 Type == ELF::STT_TLS);
47 static unsigned GetBinding(const MCSymbolData &SD) {
48 uint32_t Binding = (SD.getFlags() & (0xf << ELF_STB_Shift)) >> ELF_STB_Shift;
49 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
50 Binding == ELF::STB_WEAK);
54 static void SetBinding(MCSymbolData &SD, unsigned Binding) {
55 assert(Binding == ELF::STB_LOCAL || Binding == ELF::STB_GLOBAL ||
56 Binding == ELF::STB_WEAK);
57 uint32_t OtherFlags = SD.getFlags() & ~(0xf << ELF_STB_Shift);
58 SD.setFlags(OtherFlags | (Binding << ELF_STB_Shift));
61 static unsigned GetVisibility(MCSymbolData &SD) {
63 (SD.getFlags() & (0xf << ELF_STV_Shift)) >> ELF_STV_Shift;
64 assert(Visibility == ELF::STV_DEFAULT || Visibility == ELF::STV_INTERNAL ||
65 Visibility == ELF::STV_HIDDEN || Visibility == ELF::STV_PROTECTED);
69 static bool isFixupKindX86PCRel(unsigned Kind) {
73 case X86::reloc_pcrel_1byte:
74 case X86::reloc_pcrel_4byte:
75 case X86::reloc_riprel_4byte:
76 case X86::reloc_riprel_4byte_movq_load:
81 static bool RelocNeedsGOT(MCSymbolRefExpr::VariantKind Variant) {
85 case MCSymbolRefExpr::VK_GOT:
86 case MCSymbolRefExpr::VK_PLT:
87 case MCSymbolRefExpr::VK_GOTPCREL:
88 case MCSymbolRefExpr::VK_TPOFF:
89 case MCSymbolRefExpr::VK_TLSGD:
90 case MCSymbolRefExpr::VK_GOTTPOFF:
91 case MCSymbolRefExpr::VK_INDNTPOFF:
92 case MCSymbolRefExpr::VK_NTPOFF:
93 case MCSymbolRefExpr::VK_GOTNTPOFF:
94 case MCSymbolRefExpr::VK_TLSLDM:
95 case MCSymbolRefExpr::VK_DTPOFF:
96 case MCSymbolRefExpr::VK_TLSLD:
103 class ELFObjectWriterImpl {
104 /*static bool isFixupKindX86RIPRel(unsigned Kind) {
105 return Kind == X86::reloc_riprel_4byte ||
106 Kind == X86::reloc_riprel_4byte_movq_load;
110 /// ELFSymbolData - Helper struct for containing some precomputed information
112 struct ELFSymbolData {
113 MCSymbolData *SymbolData;
114 uint64_t StringIndex;
115 uint32_t SectionIndex;
117 // Support lexicographic sorting.
118 bool operator<(const ELFSymbolData &RHS) const {
119 if (GetType(*SymbolData) == ELF::STT_FILE)
121 if (GetType(*RHS.SymbolData) == ELF::STT_FILE)
123 return SymbolData->getSymbol().getName() <
124 RHS.SymbolData->getSymbol().getName();
128 /// @name Relocation Data
131 struct ELFRelocationEntry {
132 // Make these big enough for both 32-bit and 64-bit
136 const MCSymbol *Symbol;
139 // Support lexicographic sorting.
140 bool operator<(const ELFRelocationEntry &RE) const {
141 return RE.r_offset < r_offset;
145 SmallPtrSet<const MCSymbol *, 16> UsedInReloc;
146 SmallPtrSet<const MCSymbol *, 16> WeakrefUsedInReloc;
147 DenseMap<const MCSymbol *, const MCSymbol *> Renames;
149 llvm::DenseMap<const MCSectionData*,
150 std::vector<ELFRelocationEntry> > Relocations;
151 DenseMap<const MCSection*, uint64_t> SectionStringTableIndex;
154 /// @name Symbol Table Data
157 SmallString<256> StringTable;
158 std::vector<ELFSymbolData> LocalSymbolData;
159 std::vector<ELFSymbolData> ExternalSymbolData;
160 std::vector<ELFSymbolData> UndefinedSymbolData;
164 int NumRegularSections;
168 bool NeedsSymtabShndx;
170 ELFObjectWriter *Writer;
174 unsigned Is64Bit : 1;
176 bool HasRelocationAddend;
178 Triple::OSType OSType;
182 // This holds the symbol table index of the last local symbol.
183 unsigned LastLocalSymbolIndex;
184 // This holds the .strtab section index.
185 unsigned StringTableIndex;
186 // This holds the .symtab section index.
187 unsigned SymbolTableIndex;
189 unsigned ShstrtabIndex;
192 ELFObjectWriterImpl(ELFObjectWriter *_Writer, bool _Is64Bit,
193 uint16_t _EMachine, bool _HasRelAddend,
194 Triple::OSType _OSType)
195 : NeedsGOT(false), NeedsSymtabShndx(false), Writer(_Writer),
196 OS(Writer->getStream()),
197 Is64Bit(_Is64Bit), HasRelocationAddend(_HasRelAddend),
198 OSType(_OSType), EMachine(_EMachine) {
201 void Write8(uint8_t Value) { Writer->Write8(Value); }
202 void Write16(uint16_t Value) { Writer->Write16(Value); }
203 void Write32(uint32_t Value) { Writer->Write32(Value); }
204 //void Write64(uint64_t Value) { Writer->Write64(Value); }
205 void WriteZeros(unsigned N) { Writer->WriteZeros(N); }
206 //void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) {
207 // Writer->WriteBytes(Str, ZeroFillSize);
210 void WriteWord(uint64_t W) {
217 void StringLE16(char *buf, uint16_t Value) {
218 buf[0] = char(Value >> 0);
219 buf[1] = char(Value >> 8);
222 void StringLE32(char *buf, uint32_t Value) {
223 StringLE16(buf, uint16_t(Value >> 0));
224 StringLE16(buf + 2, uint16_t(Value >> 16));
227 void StringLE64(char *buf, uint64_t Value) {
228 StringLE32(buf, uint32_t(Value >> 0));
229 StringLE32(buf + 4, uint32_t(Value >> 32));
232 void StringBE16(char *buf ,uint16_t Value) {
233 buf[0] = char(Value >> 8);
234 buf[1] = char(Value >> 0);
237 void StringBE32(char *buf, uint32_t Value) {
238 StringBE16(buf, uint16_t(Value >> 16));
239 StringBE16(buf + 2, uint16_t(Value >> 0));
242 void StringBE64(char *buf, uint64_t Value) {
243 StringBE32(buf, uint32_t(Value >> 32));
244 StringBE32(buf + 4, uint32_t(Value >> 0));
247 void String8(MCDataFragment &F, uint8_t Value) {
250 F.getContents() += StringRef(buf, 1);
253 void String16(MCDataFragment &F, uint16_t Value) {
255 if (Writer->isLittleEndian())
256 StringLE16(buf, Value);
258 StringBE16(buf, Value);
259 F.getContents() += StringRef(buf, 2);
262 void String32(MCDataFragment &F, uint32_t Value) {
264 if (Writer->isLittleEndian())
265 StringLE32(buf, Value);
267 StringBE32(buf, Value);
268 F.getContents() += StringRef(buf, 4);
271 void String64(MCDataFragment &F, uint64_t Value) {
273 if (Writer->isLittleEndian())
274 StringLE64(buf, Value);
276 StringBE64(buf, Value);
277 F.getContents() += StringRef(buf, 8);
280 void WriteHeader(uint64_t SectionDataSize, unsigned NumberOfSections);
282 void WriteSymbolEntry(MCDataFragment *SymtabF, MCDataFragment *ShndxF,
283 uint64_t name, uint8_t info,
284 uint64_t value, uint64_t size,
285 uint8_t other, uint32_t shndx,
288 void WriteSymbol(MCDataFragment *SymtabF, MCDataFragment *ShndxF,
290 const MCAsmLayout &Layout);
292 void WriteSymbolTable(MCDataFragment *SymtabF, MCDataFragment *ShndxF,
293 const MCAssembler &Asm,
294 const MCAsmLayout &Layout,
295 unsigned NumRegularSections);
297 void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout,
298 const MCFragment *Fragment, const MCFixup &Fixup,
299 MCValue Target, uint64_t &FixedValue);
301 uint64_t getSymbolIndexInSymbolTable(const MCAssembler &Asm,
304 /// ComputeSymbolTable - Compute the symbol table data
306 /// \param StringTable [out] - The string table data.
307 /// \param StringIndexMap [out] - Map from symbol names to offsets in the
309 void ComputeSymbolTable(MCAssembler &Asm);
311 void WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
312 const MCSectionData &SD);
314 void WriteRelocations(MCAssembler &Asm, MCAsmLayout &Layout) {
315 for (MCAssembler::const_iterator it = Asm.begin(),
316 ie = Asm.end(); it != ie; ++it) {
317 WriteRelocation(Asm, Layout, *it);
321 void CreateMetadataSections(MCAssembler &Asm, MCAsmLayout &Layout);
323 void ExecutePostLayoutBinding(MCAssembler &Asm);
325 void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
326 uint64_t Address, uint64_t Offset,
327 uint64_t Size, uint32_t Link, uint32_t Info,
328 uint64_t Alignment, uint64_t EntrySize);
330 void WriteRelocationsFragment(const MCAssembler &Asm, MCDataFragment *F,
331 const MCSectionData *SD);
333 bool IsFixupFullyResolved(const MCAssembler &Asm,
334 const MCValue Target,
336 const MCFragment *DF) const;
338 void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
343 // Emit the ELF header.
344 void ELFObjectWriterImpl::WriteHeader(uint64_t SectionDataSize,
345 unsigned NumberOfSections) {
351 // emitWord method behaves differently for ELF32 and ELF64, writing
352 // 4 bytes in the former and 8 in the latter.
354 Write8(0x7f); // e_ident[EI_MAG0]
355 Write8('E'); // e_ident[EI_MAG1]
356 Write8('L'); // e_ident[EI_MAG2]
357 Write8('F'); // e_ident[EI_MAG3]
359 Write8(Is64Bit ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]
362 Write8(Writer->isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
364 Write8(ELF::EV_CURRENT); // e_ident[EI_VERSION]
367 case Triple::FreeBSD: Write8(ELF::ELFOSABI_FREEBSD); break;
368 case Triple::Linux: Write8(ELF::ELFOSABI_LINUX); break;
369 default: Write8(ELF::ELFOSABI_NONE); break;
371 Write8(0); // e_ident[EI_ABIVERSION]
373 WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD);
375 Write16(ELF::ET_REL); // e_type
377 Write16(EMachine); // e_machine = target
379 Write32(ELF::EV_CURRENT); // e_version
380 WriteWord(0); // e_entry, no entry point in .o file
381 WriteWord(0); // e_phoff, no program header for .o
382 WriteWord(SectionDataSize + (Is64Bit ? sizeof(ELF::Elf64_Ehdr) :
383 sizeof(ELF::Elf32_Ehdr))); // e_shoff = sec hdr table off in bytes
385 // FIXME: Make this configurable.
386 Write32(0); // e_flags = whatever the target wants
388 // e_ehsize = ELF header size
389 Write16(Is64Bit ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr));
391 Write16(0); // e_phentsize = prog header entry size
392 Write16(0); // e_phnum = # prog header entries = 0
394 // e_shentsize = Section header entry size
395 Write16(Is64Bit ? sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr));
397 // e_shnum = # of section header ents
398 if (NumberOfSections >= ELF::SHN_LORESERVE)
401 Write16(NumberOfSections);
403 // e_shstrndx = Section # of '.shstrtab'
404 if (NumberOfSections >= ELF::SHN_LORESERVE)
405 Write16(ELF::SHN_XINDEX);
407 Write16(ShstrtabIndex);
410 void ELFObjectWriterImpl::WriteSymbolEntry(MCDataFragment *SymtabF,
411 MCDataFragment *ShndxF,
413 uint8_t info, uint64_t value,
414 uint64_t size, uint8_t other,
418 if (shndx >= ELF::SHN_LORESERVE && !Reserved)
419 String32(*ShndxF, shndx);
421 String32(*ShndxF, 0);
424 uint16_t Index = (shndx >= ELF::SHN_LORESERVE && !Reserved) ?
425 uint16_t(ELF::SHN_XINDEX) : shndx;
428 String32(*SymtabF, name); // st_name
429 String8(*SymtabF, info); // st_info
430 String8(*SymtabF, other); // st_other
431 String16(*SymtabF, Index); // st_shndx
432 String64(*SymtabF, value); // st_value
433 String64(*SymtabF, size); // st_size
435 String32(*SymtabF, name); // st_name
436 String32(*SymtabF, value); // st_value
437 String32(*SymtabF, size); // st_size
438 String8(*SymtabF, info); // st_info
439 String8(*SymtabF, other); // st_other
440 String16(*SymtabF, Index); // st_shndx
444 static uint64_t SymbolValue(MCSymbolData &Data, const MCAsmLayout &Layout) {
445 if (Data.isCommon() && Data.isExternal())
446 return Data.getCommonAlignment();
448 const MCSymbol &Symbol = Data.getSymbol();
449 if (!Symbol.isInSection())
452 if (MCFragment *FF = Data.getFragment())
453 return Layout.getSymbolAddress(&Data) -
454 Layout.getSectionAddress(FF->getParent());
459 static const MCSymbol &AliasedSymbol(const MCSymbol &Symbol) {
460 const MCSymbol *S = &Symbol;
461 while (S->isVariable()) {
462 const MCExpr *Value = S->getVariableValue();
463 if (Value->getKind() != MCExpr::SymbolRef)
465 const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Value);
466 S = &Ref->getSymbol();
471 void ELFObjectWriterImpl::ExecutePostLayoutBinding(MCAssembler &Asm) {
472 // The presence of symbol versions causes undefined symbols and
473 // versions declared with @@@ to be renamed.
475 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
476 ie = Asm.symbol_end(); it != ie; ++it) {
477 const MCSymbol &Alias = it->getSymbol();
478 const MCSymbol &Symbol = AliasedSymbol(Alias);
479 MCSymbolData &SD = Asm.getSymbolData(Symbol);
481 // Undefined symbols are global, but this is the first place we
482 // are able to set it.
483 if (Symbol.isUndefined() && !Symbol.isVariable()) {
484 if (GetBinding(SD) == ELF::STB_LOCAL) {
485 SetBinding(SD, ELF::STB_GLOBAL);
486 SetBinding(*it, ELF::STB_GLOBAL);
491 if (&Symbol == &Alias)
494 StringRef AliasName = Alias.getName();
495 size_t Pos = AliasName.find('@');
496 if (Pos == StringRef::npos)
499 // Aliases defined with .symvar copy the binding from the symbol they alias.
500 // This is the first place we are able to copy this information.
501 it->setExternal(SD.isExternal());
502 SetBinding(*it, GetBinding(SD));
504 StringRef Rest = AliasName.substr(Pos);
505 if (!Symbol.isUndefined() && !Rest.startswith("@@@"))
508 // FIXME: produce a better error message.
509 if (Symbol.isUndefined() && Rest.startswith("@@") &&
510 !Rest.startswith("@@@"))
511 report_fatal_error("A @@ version cannot be undefined");
513 Renames.insert(std::make_pair(&Symbol, &Alias));
517 void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *SymtabF,
518 MCDataFragment *ShndxF,
520 const MCAsmLayout &Layout) {
521 MCSymbolData &OrigData = *MSD.SymbolData;
523 Layout.getAssembler().getSymbolData(AliasedSymbol(OrigData.getSymbol()));
525 bool IsReserved = Data.isCommon() || Data.getSymbol().isAbsolute() ||
526 Data.getSymbol().isVariable();
528 uint8_t Binding = GetBinding(OrigData);
529 uint8_t Visibility = GetVisibility(OrigData);
530 uint8_t Type = GetType(Data);
532 uint8_t Info = (Binding << ELF_STB_Shift) | (Type << ELF_STT_Shift);
533 uint8_t Other = Visibility;
535 uint64_t Value = SymbolValue(Data, Layout);
539 assert(!(Data.isCommon() && !Data.isExternal()));
541 ESize = Data.getSize();
542 if (Data.getSize()) {
544 if (ESize->getKind() == MCExpr::Binary) {
545 const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(ESize);
547 if (BE->EvaluateAsRelocatable(Res, &Layout)) {
548 assert(!Res.getSymA() || !Res.getSymA()->getSymbol().isDefined());
549 assert(!Res.getSymB() || !Res.getSymB()->getSymbol().isDefined());
550 Size = Res.getConstant();
552 } else if (ESize->getKind() == MCExpr::Constant) {
553 Size = static_cast<const MCConstantExpr *>(ESize)->getValue();
555 assert(0 && "Unsupported size expression");
559 // Write out the symbol table entry
560 WriteSymbolEntry(SymtabF, ShndxF, MSD.StringIndex, Info, Value,
561 Size, Other, MSD.SectionIndex, IsReserved);
564 void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *SymtabF,
565 MCDataFragment *ShndxF,
566 const MCAssembler &Asm,
567 const MCAsmLayout &Layout,
568 unsigned NumRegularSections) {
569 // The string table must be emitted first because we need the index
570 // into the string table for all the symbol names.
571 assert(StringTable.size() && "Missing string table");
573 // FIXME: Make sure the start of the symbol table is aligned.
575 // The first entry is the undefined symbol entry.
576 WriteSymbolEntry(SymtabF, ShndxF, 0, 0, 0, 0, 0, 0, false);
578 // Write the symbol table entries.
579 LastLocalSymbolIndex = LocalSymbolData.size() + 1;
580 for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) {
581 ELFSymbolData &MSD = LocalSymbolData[i];
582 WriteSymbol(SymtabF, ShndxF, MSD, Layout);
585 // Write out a symbol table entry for each regular section.
587 for (MCAssembler::const_iterator it = Asm.begin();
588 Index <= NumRegularSections; ++it, ++Index) {
589 const MCSectionELF &Section =
590 static_cast<const MCSectionELF&>(it->getSection());
591 // Leave out relocations so we don't have indexes within
592 // the relocations messed up
593 if (Section.getType() == ELF::SHT_RELA || Section.getType() == ELF::SHT_REL)
595 WriteSymbolEntry(SymtabF, ShndxF, 0, ELF::STT_SECTION, 0, 0,
596 ELF::STV_DEFAULT, Index, false);
597 LastLocalSymbolIndex++;
600 for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) {
601 ELFSymbolData &MSD = ExternalSymbolData[i];
602 MCSymbolData &Data = *MSD.SymbolData;
603 assert(((Data.getFlags() & ELF_STB_Global) ||
604 (Data.getFlags() & ELF_STB_Weak)) &&
605 "External symbol requires STB_GLOBAL or STB_WEAK flag");
606 WriteSymbol(SymtabF, ShndxF, MSD, Layout);
607 if (GetBinding(Data) == ELF::STB_LOCAL)
608 LastLocalSymbolIndex++;
611 for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) {
612 ELFSymbolData &MSD = UndefinedSymbolData[i];
613 MCSymbolData &Data = *MSD.SymbolData;
614 WriteSymbol(SymtabF, ShndxF, MSD, Layout);
615 if (GetBinding(Data) == ELF::STB_LOCAL)
616 LastLocalSymbolIndex++;
620 static bool ShouldRelocOnSymbol(const MCSymbolData &SD,
621 const MCValue &Target,
622 const MCFragment &F) {
623 const MCSymbol &Symbol = SD.getSymbol();
624 if (Symbol.isUndefined())
627 const MCSectionELF &Section =
628 static_cast<const MCSectionELF&>(Symbol.getSection());
633 MCSymbolRefExpr::VariantKind Kind = Target.getSymA()->getKind();
634 const MCSectionELF &Sec2 =
635 static_cast<const MCSectionELF&>(F.getParent()->getSection());
637 if (Section.getKind().isBSS())
640 if (&Sec2 != &Section &&
641 (Kind == MCSymbolRefExpr::VK_PLT ||
642 Kind == MCSymbolRefExpr::VK_GOTPCREL ||
643 Kind == MCSymbolRefExpr::VK_GOTOFF))
646 if (Section.getFlags() & MCSectionELF::SHF_MERGE)
647 return Target.getConstant() != 0;
652 // FIXME: this is currently X86/X86_64 only
653 void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
654 const MCAsmLayout &Layout,
655 const MCFragment *Fragment,
656 const MCFixup &Fixup,
658 uint64_t &FixedValue) {
661 int64_t Value = Target.getConstant();
662 const MCSymbol *Symbol = 0;
663 const MCSymbol *Renamed = 0;
665 bool IsPCRel = isFixupKindX86PCRel(Fixup.getKind());
666 if (!Target.isAbsolute()) {
667 Symbol = &AliasedSymbol(Target.getSymA()->getSymbol());
668 Renamed = Renames.lookup(Symbol);
670 Renamed = &Target.getSymA()->getSymbol();
671 MCSymbolData &SD = Asm.getSymbolData(*Symbol);
672 MCFragment *F = SD.getFragment();
674 if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
675 const MCSymbol &SymbolB = RefB->getSymbol();
676 MCSymbolData &SDB = Asm.getSymbolData(SymbolB);
678 MCSectionData *Sec = Fragment->getParent();
680 // Offset of the symbol in the section
681 int64_t a = Layout.getSymbolAddress(&SDB) - Layout.getSectionAddress(Sec);
683 // Ofeset of the relocation in the section
684 int64_t b = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
688 // Check that this case has already been fully resolved before we get
690 if (Symbol->isDefined() && !SD.isExternal() &&
692 &Fragment->getParent()->getSection() == &Symbol->getSection()) {
693 llvm_unreachable("We don't need a relocation in this case.");
697 bool RelocOnSymbol = ShouldRelocOnSymbol(SD, Target, *Fragment);
698 if (!RelocOnSymbol) {
699 Index = F->getParent()->getOrdinal();
701 MCSectionData *FSD = F->getParent();
702 // Offset of the symbol in the section
703 Value += Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
705 UsedInReloc.insert(Renamed);
706 MCSymbolData &RenamedSD = Asm.getSymbolData(*Renamed);
707 if (RenamedSD.getFlags() & ELF_Other_Weakref) {
708 WeakrefUsedInReloc.insert(Symbol);
713 // Compensate for the addend on i386.
720 // determine the type of the relocation
722 MCSymbolRefExpr::VariantKind Modifier = Target.getSymA()->getKind();
728 llvm_unreachable("Unimplemented");
729 case MCSymbolRefExpr::VK_None:
730 Type = ELF::R_X86_64_PC32;
732 case MCSymbolRefExpr::VK_PLT:
733 Type = ELF::R_X86_64_PLT32;
735 case MCSymbolRefExpr::VK_GOTPCREL:
736 Type = ELF::R_X86_64_GOTPCREL;
738 case MCSymbolRefExpr::VK_GOTTPOFF:
739 Type = ELF::R_X86_64_GOTTPOFF;
741 case MCSymbolRefExpr::VK_TLSGD:
742 Type = ELF::R_X86_64_TLSGD;
744 case MCSymbolRefExpr::VK_TLSLD:
745 Type = ELF::R_X86_64_TLSLD;
749 switch ((unsigned)Fixup.getKind()) {
750 default: llvm_unreachable("invalid fixup kind!");
751 case FK_Data_8: Type = ELF::R_X86_64_64; break;
752 case X86::reloc_signed_4byte:
753 case X86::reloc_pcrel_4byte:
754 assert(isInt<32>(Target.getConstant()));
757 llvm_unreachable("Unimplemented");
758 case MCSymbolRefExpr::VK_None:
759 Type = ELF::R_X86_64_32S;
761 case MCSymbolRefExpr::VK_GOT:
762 Type = ELF::R_X86_64_GOT32;
764 case MCSymbolRefExpr::VK_GOTPCREL:
765 Type = ELF::R_X86_64_GOTPCREL;
767 case MCSymbolRefExpr::VK_TPOFF:
768 Type = ELF::R_X86_64_TPOFF32;
770 case MCSymbolRefExpr::VK_DTPOFF:
771 Type = ELF::R_X86_64_DTPOFF32;
776 Type = ELF::R_X86_64_32;
778 case FK_Data_2: Type = ELF::R_X86_64_16; break;
779 case X86::reloc_pcrel_1byte:
780 case FK_Data_1: Type = ELF::R_X86_64_8; break;
787 llvm_unreachable("Unimplemented");
788 case MCSymbolRefExpr::VK_None:
789 Type = ELF::R_386_PC32;
791 case MCSymbolRefExpr::VK_PLT:
792 Type = ELF::R_386_PLT32;
796 switch ((unsigned)Fixup.getKind()) {
797 default: llvm_unreachable("invalid fixup kind!");
799 case X86::reloc_global_offset_table:
800 Type = ELF::R_386_GOTPC;
803 // FIXME: Should we avoid selecting reloc_signed_4byte in 32 bit mode
805 case X86::reloc_signed_4byte:
806 case X86::reloc_pcrel_4byte:
810 llvm_unreachable("Unimplemented");
811 case MCSymbolRefExpr::VK_None:
812 Type = ELF::R_386_32;
814 case MCSymbolRefExpr::VK_GOT:
815 Type = ELF::R_386_GOT32;
817 case MCSymbolRefExpr::VK_GOTOFF:
818 Type = ELF::R_386_GOTOFF;
820 case MCSymbolRefExpr::VK_TLSGD:
821 Type = ELF::R_386_TLS_GD;
823 case MCSymbolRefExpr::VK_TPOFF:
824 Type = ELF::R_386_TLS_LE_32;
826 case MCSymbolRefExpr::VK_INDNTPOFF:
827 Type = ELF::R_386_TLS_IE;
829 case MCSymbolRefExpr::VK_NTPOFF:
830 Type = ELF::R_386_TLS_LE;
832 case MCSymbolRefExpr::VK_GOTNTPOFF:
833 Type = ELF::R_386_TLS_GOTIE;
835 case MCSymbolRefExpr::VK_TLSLDM:
836 Type = ELF::R_386_TLS_LDM;
838 case MCSymbolRefExpr::VK_DTPOFF:
839 Type = ELF::R_386_TLS_LDO_32;
843 case FK_Data_2: Type = ELF::R_386_16; break;
844 case X86::reloc_pcrel_1byte:
845 case FK_Data_1: Type = ELF::R_386_8; break;
850 if (RelocNeedsGOT(Modifier))
853 ELFRelocationEntry ERE;
857 ERE.Symbol = Renamed;
859 ERE.r_offset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
861 if (HasRelocationAddend)
862 ERE.r_addend = Addend;
864 ERE.r_addend = 0; // Silence compiler warning.
866 Relocations[Fragment->getParent()].push_back(ERE);
870 ELFObjectWriterImpl::getSymbolIndexInSymbolTable(const MCAssembler &Asm,
872 MCSymbolData &SD = Asm.getSymbolData(*S);
875 if (!SD.isExternal() && !S->isUndefined())
876 return SD.getIndex() + /* empty symbol */ 1;
878 // External or undefined symbol.
879 return SD.getIndex() + NumRegularSections + /* empty symbol */ 1;
882 static bool isInSymtab(const MCAssembler &Asm, const MCSymbolData &Data,
883 bool Used, bool Renamed) {
884 if (Data.getFlags() & ELF_Other_Weakref)
893 const MCSymbol &Symbol = Data.getSymbol();
895 if (Symbol.getName() == "_GLOBAL_OFFSET_TABLE_")
898 const MCSymbol &A = AliasedSymbol(Symbol);
899 if (!A.isVariable() && A.isUndefined() && !Data.isCommon())
902 if (!Asm.isSymbolLinkerVisible(Symbol) && !Symbol.isUndefined())
905 if (Symbol.isTemporary())
911 static bool isLocal(const MCSymbolData &Data) {
912 if (Data.isExternal())
915 const MCSymbol &Symbol = Data.getSymbol();
916 if (Symbol.isUndefined() && !Symbol.isVariable())
922 void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
923 // FIXME: Is this the correct place to do this?
925 llvm::StringRef Name = "_GLOBAL_OFFSET_TABLE_";
926 MCSymbol *Sym = Asm.getContext().GetOrCreateSymbol(Name);
927 MCSymbolData &Data = Asm.getOrCreateSymbolData(*Sym);
928 Data.setExternal(true);
929 SetBinding(Data, ELF::STB_GLOBAL);
932 // Build section lookup table.
933 NumRegularSections = Asm.size();
934 DenseMap<const MCSection*, uint32_t> SectionIndexMap;
936 for (MCAssembler::iterator it = Asm.begin(),
937 ie = Asm.end(); it != ie; ++it, ++Index)
938 SectionIndexMap[&it->getSection()] = Index;
940 // Index 0 is always the empty string.
941 StringMap<uint64_t> StringIndexMap;
942 StringTable += '\x00';
944 // Add the data for the symbols.
945 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
946 ie = Asm.symbol_end(); it != ie; ++it) {
947 const MCSymbol &Symbol = it->getSymbol();
949 bool Used = UsedInReloc.count(&Symbol);
950 bool WeakrefUsed = WeakrefUsedInReloc.count(&Symbol);
951 if (!isInSymtab(Asm, *it, Used || WeakrefUsed,
952 Renames.count(&Symbol)))
957 bool Local = isLocal(*it);
958 const MCSymbol &RefSymbol = AliasedSymbol(Symbol);
960 if (RefSymbol.isUndefined() && !Used && WeakrefUsed)
961 SetBinding(*it, ELF::STB_WEAK);
963 if (it->isCommon()) {
965 MSD.SectionIndex = ELF::SHN_COMMON;
966 } else if (Symbol.isAbsolute() || RefSymbol.isVariable()) {
967 MSD.SectionIndex = ELF::SHN_ABS;
968 } else if (RefSymbol.isUndefined()) {
969 MSD.SectionIndex = ELF::SHN_UNDEF;
971 MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection());
972 if (MSD.SectionIndex >= ELF::SHN_LORESERVE)
973 NeedsSymtabShndx = true;
974 assert(MSD.SectionIndex && "Invalid section index!");
977 // The @@@ in symbol version is replaced with @ in undefined symbols and
978 // @@ in defined ones.
979 StringRef Name = Symbol.getName();
980 size_t Pos = Name.find("@@@");
981 std::string FinalName;
982 if (Pos != StringRef::npos) {
983 StringRef Prefix = Name.substr(0, Pos);
984 unsigned n = MSD.SectionIndex == ELF::SHN_UNDEF ? 2 : 1;
985 StringRef Suffix = Name.substr(Pos + n);
986 FinalName = Prefix.str() + Suffix.str();
988 FinalName = Name.str();
991 uint64_t &Entry = StringIndexMap[FinalName];
993 Entry = StringTable.size();
994 StringTable += FinalName;
995 StringTable += '\x00';
997 MSD.StringIndex = Entry;
998 if (MSD.SectionIndex == ELF::SHN_UNDEF)
999 UndefinedSymbolData.push_back(MSD);
1001 LocalSymbolData.push_back(MSD);
1003 ExternalSymbolData.push_back(MSD);
1006 // Symbols are required to be in lexicographic order.
1007 array_pod_sort(LocalSymbolData.begin(), LocalSymbolData.end());
1008 array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
1009 array_pod_sort(UndefinedSymbolData.begin(), UndefinedSymbolData.end());
1011 // Set the symbol indices. Local symbols must come before all other
1012 // symbols with non-local bindings.
1014 for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
1015 LocalSymbolData[i].SymbolData->setIndex(Index++);
1016 for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
1017 ExternalSymbolData[i].SymbolData->setIndex(Index++);
1018 for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
1019 UndefinedSymbolData[i].SymbolData->setIndex(Index++);
1022 void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
1023 const MCSectionData &SD) {
1024 if (!Relocations[&SD].empty()) {
1025 MCContext &Ctx = Asm.getContext();
1026 const MCSectionELF *RelaSection;
1027 const MCSectionELF &Section =
1028 static_cast<const MCSectionELF&>(SD.getSection());
1030 const StringRef SectionName = Section.getSectionName();
1031 std::string RelaSectionName = HasRelocationAddend ? ".rela" : ".rel";
1032 RelaSectionName += SectionName;
1035 if (HasRelocationAddend)
1036 EntrySize = Is64Bit ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
1038 EntrySize = Is64Bit ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
1040 RelaSection = Ctx.getELFSection(RelaSectionName, HasRelocationAddend ?
1041 ELF::SHT_RELA : ELF::SHT_REL, 0,
1042 SectionKind::getReadOnly(),
1045 MCSectionData &RelaSD = Asm.getOrCreateSectionData(*RelaSection);
1046 RelaSD.setAlignment(Is64Bit ? 8 : 4);
1048 MCDataFragment *F = new MCDataFragment(&RelaSD);
1050 WriteRelocationsFragment(Asm, F, &SD);
1052 Asm.AddSectionToTheEnd(*Writer, RelaSD, Layout);
1056 void ELFObjectWriterImpl::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
1057 uint64_t Flags, uint64_t Address,
1058 uint64_t Offset, uint64_t Size,
1059 uint32_t Link, uint32_t Info,
1061 uint64_t EntrySize) {
1062 Write32(Name); // sh_name: index into string table
1063 Write32(Type); // sh_type
1064 WriteWord(Flags); // sh_flags
1065 WriteWord(Address); // sh_addr
1066 WriteWord(Offset); // sh_offset
1067 WriteWord(Size); // sh_size
1068 Write32(Link); // sh_link
1069 Write32(Info); // sh_info
1070 WriteWord(Alignment); // sh_addralign
1071 WriteWord(EntrySize); // sh_entsize
1074 void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm,
1076 const MCSectionData *SD) {
1077 std::vector<ELFRelocationEntry> &Relocs = Relocations[SD];
1078 // sort by the r_offset just like gnu as does
1079 array_pod_sort(Relocs.begin(), Relocs.end());
1081 for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
1082 ELFRelocationEntry entry = Relocs[e - i - 1];
1084 if (entry.Index < 0)
1085 entry.Index = getSymbolIndexInSymbolTable(Asm, entry.Symbol);
1087 entry.Index += LocalSymbolData.size() + 1;
1089 String64(*F, entry.r_offset);
1091 struct ELF::Elf64_Rela ERE64;
1092 ERE64.setSymbolAndType(entry.Index, entry.Type);
1093 String64(*F, ERE64.r_info);
1095 if (HasRelocationAddend)
1096 String64(*F, entry.r_addend);
1098 String32(*F, entry.r_offset);
1100 struct ELF::Elf32_Rela ERE32;
1101 ERE32.setSymbolAndType(entry.Index, entry.Type);
1102 String32(*F, ERE32.r_info);
1104 if (HasRelocationAddend)
1105 String32(*F, entry.r_addend);
1110 void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,
1111 MCAsmLayout &Layout) {
1112 MCContext &Ctx = Asm.getContext();
1115 unsigned EntrySize = Is64Bit ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
1117 unsigned NumRegularSections = Asm.size();
1119 // We construct .shstrtab, .symtab and .strtab in this order to match gnu as.
1120 const MCSectionELF *ShstrtabSection =
1121 Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0,
1122 SectionKind::getReadOnly(), false);
1123 MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection);
1124 ShstrtabSD.setAlignment(1);
1125 ShstrtabIndex = Asm.size();
1127 const MCSectionELF *SymtabSection =
1128 Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
1129 SectionKind::getReadOnly(),
1131 MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection);
1132 SymtabSD.setAlignment(Is64Bit ? 8 : 4);
1133 SymbolTableIndex = Asm.size();
1135 MCSectionData *SymtabShndxSD = NULL;
1137 if (NeedsSymtabShndx) {
1138 const MCSectionELF *SymtabShndxSection =
1139 Ctx.getELFSection(".symtab_shndx", ELF::SHT_SYMTAB_SHNDX, 0,
1140 SectionKind::getReadOnly(), 4);
1141 SymtabShndxSD = &Asm.getOrCreateSectionData(*SymtabShndxSection);
1142 SymtabShndxSD->setAlignment(4);
1145 const MCSection *StrtabSection;
1146 StrtabSection = Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0,
1147 SectionKind::getReadOnly(), false);
1148 MCSectionData &StrtabSD = Asm.getOrCreateSectionData(*StrtabSection);
1149 StrtabSD.setAlignment(1);
1150 StringTableIndex = Asm.size();
1152 WriteRelocations(Asm, Layout);
1155 F = new MCDataFragment(&SymtabSD);
1156 MCDataFragment *ShndxF = NULL;
1157 if (NeedsSymtabShndx) {
1158 ShndxF = new MCDataFragment(SymtabShndxSD);
1159 Asm.AddSectionToTheEnd(*Writer, *SymtabShndxSD, Layout);
1161 WriteSymbolTable(F, ShndxF, Asm, Layout, NumRegularSections);
1162 Asm.AddSectionToTheEnd(*Writer, SymtabSD, Layout);
1164 F = new MCDataFragment(&StrtabSD);
1165 F->getContents().append(StringTable.begin(), StringTable.end());
1166 Asm.AddSectionToTheEnd(*Writer, StrtabSD, Layout);
1168 F = new MCDataFragment(&ShstrtabSD);
1170 // Section header string table.
1172 // The first entry of a string table holds a null character so skip
1175 F->getContents() += '\x00';
1177 for (MCAssembler::const_iterator it = Asm.begin(),
1178 ie = Asm.end(); it != ie; ++it) {
1179 const MCSectionELF &Section =
1180 static_cast<const MCSectionELF&>(it->getSection());
1181 // FIXME: We could merge suffixes like in .text and .rela.text.
1183 // Remember the index into the string table so we can write it
1184 // into the sh_name field of the section header table.
1185 SectionStringTableIndex[&it->getSection()] = Index;
1187 Index += Section.getSectionName().size() + 1;
1188 F->getContents() += Section.getSectionName();
1189 F->getContents() += '\x00';
1192 Asm.AddSectionToTheEnd(*Writer, ShstrtabSD, Layout);
1195 bool ELFObjectWriterImpl::IsFixupFullyResolved(const MCAssembler &Asm,
1196 const MCValue Target,
1198 const MCFragment *DF) const {
1199 // If this is a PCrel relocation, find the section this fixup value is
1201 const MCSection *BaseSection = 0;
1203 BaseSection = &DF->getParent()->getSection();
1204 assert(BaseSection);
1207 const MCSection *SectionA = 0;
1208 const MCSymbol *SymbolA = 0;
1209 if (const MCSymbolRefExpr *A = Target.getSymA()) {
1210 SymbolA = &A->getSymbol();
1211 SectionA = &SymbolA->getSection();
1214 const MCSection *SectionB = 0;
1215 if (const MCSymbolRefExpr *B = Target.getSymB()) {
1216 SectionB = &B->getSymbol().getSection();
1220 return SectionA == SectionB;
1222 const MCSymbolData &DataA = Asm.getSymbolData(*SymbolA);
1223 if (DataA.isExternal())
1226 return !SectionB && BaseSection == SectionA;
1229 void ELFObjectWriterImpl::WriteObject(MCAssembler &Asm,
1230 const MCAsmLayout &Layout) {
1231 // Compute symbol table information.
1232 ComputeSymbolTable(Asm);
1234 CreateMetadataSections(const_cast<MCAssembler&>(Asm),
1235 const_cast<MCAsmLayout&>(Layout));
1237 // Add 1 for the null section.
1238 unsigned NumSections = Asm.size() + 1;
1239 uint64_t NaturalAlignment = Is64Bit ? 8 : 4;
1240 uint64_t HeaderSize = Is64Bit ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr);
1241 uint64_t FileOff = HeaderSize;
1243 for (MCAssembler::const_iterator it = Asm.begin(),
1244 ie = Asm.end(); it != ie; ++it) {
1245 const MCSectionData &SD = *it;
1247 FileOff = RoundUpToAlignment(FileOff, SD.getAlignment());
1249 // Get the size of the section in the output file (including padding).
1250 uint64_t Size = Layout.getSectionFileSize(&SD);
1255 FileOff = RoundUpToAlignment(FileOff, NaturalAlignment);
1257 // Write out the ELF header ...
1258 WriteHeader(FileOff - HeaderSize, NumSections);
1260 FileOff = HeaderSize;
1262 // ... then all of the sections ...
1263 DenseMap<const MCSection*, uint64_t> SectionOffsetMap;
1265 DenseMap<const MCSection*, uint32_t> SectionIndexMap;
1268 for (MCAssembler::const_iterator it = Asm.begin(),
1269 ie = Asm.end(); it != ie; ++it) {
1270 const MCSectionData &SD = *it;
1272 uint64_t Padding = OffsetToAlignment(FileOff, SD.getAlignment());
1273 WriteZeros(Padding);
1276 // Remember the offset into the file for this section.
1277 SectionOffsetMap[&it->getSection()] = FileOff;
1278 SectionIndexMap[&it->getSection()] = Index++;
1280 FileOff += Layout.getSectionFileSize(&SD);
1282 Asm.WriteSectionData(it, Layout, Writer);
1285 uint64_t Padding = OffsetToAlignment(FileOff, NaturalAlignment);
1286 WriteZeros(Padding);
1289 // ... and then the section header table.
1290 // Should we align the section header table?
1292 // Null section first.
1293 uint64_t FirstSectionSize =
1294 NumSections >= ELF::SHN_LORESERVE ? NumSections : 0;
1295 uint32_t FirstSectionLink =
1296 ShstrtabIndex >= ELF::SHN_LORESERVE ? ShstrtabIndex : 0;
1297 WriteSecHdrEntry(0, 0, 0, 0, 0, FirstSectionSize, FirstSectionLink, 0, 0, 0);
1299 for (MCAssembler::const_iterator it = Asm.begin(),
1300 ie = Asm.end(); it != ie; ++it) {
1301 const MCSectionData &SD = *it;
1302 const MCSectionELF &Section =
1303 static_cast<const MCSectionELF&>(SD.getSection());
1305 uint64_t sh_link = 0;
1306 uint64_t sh_info = 0;
1308 switch(Section.getType()) {
1309 case ELF::SHT_DYNAMIC:
1310 sh_link = SectionStringTableIndex[&it->getSection()];
1315 case ELF::SHT_RELA: {
1316 const MCSectionELF *SymtabSection;
1317 const MCSectionELF *InfoSection;
1319 SymtabSection = Asm.getContext().getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
1320 SectionKind::getReadOnly(),
1322 sh_link = SectionIndexMap[SymtabSection];
1324 // Remove ".rel" and ".rela" prefixes.
1325 unsigned SecNameLen = (Section.getType() == ELF::SHT_REL) ? 4 : 5;
1326 StringRef SectionName = Section.getSectionName().substr(SecNameLen);
1328 InfoSection = Asm.getContext().getELFSection(SectionName,
1329 ELF::SHT_PROGBITS, 0,
1330 SectionKind::getReadOnly(),
1332 sh_info = SectionIndexMap[InfoSection];
1336 case ELF::SHT_SYMTAB:
1337 case ELF::SHT_DYNSYM:
1338 sh_link = StringTableIndex;
1339 sh_info = LastLocalSymbolIndex;
1342 case ELF::SHT_SYMTAB_SHNDX:
1343 sh_link = SymbolTableIndex;
1346 case ELF::SHT_PROGBITS:
1347 case ELF::SHT_STRTAB:
1348 case ELF::SHT_NOBITS:
1350 case ELF::SHT_ARM_ATTRIBUTES:
1355 assert(0 && "FIXME: sh_type value not supported!");
1359 WriteSecHdrEntry(SectionStringTableIndex[&it->getSection()],
1360 Section.getType(), Section.getFlags(),
1362 SectionOffsetMap.lookup(&SD.getSection()),
1363 Layout.getSectionSize(&SD), sh_link,
1364 sh_info, SD.getAlignment(),
1365 Section.getEntrySize());
1369 ELFObjectWriter::ELFObjectWriter(raw_ostream &OS,
1371 Triple::OSType OSType,
1373 bool IsLittleEndian,
1374 bool HasRelocationAddend)
1375 : MCObjectWriter(OS, IsLittleEndian)
1377 Impl = new ELFObjectWriterImpl(this, Is64Bit, EMachine,
1378 HasRelocationAddend, OSType);
1381 ELFObjectWriter::~ELFObjectWriter() {
1382 delete (ELFObjectWriterImpl*) Impl;
1385 void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {
1386 ((ELFObjectWriterImpl*) Impl)->ExecutePostLayoutBinding(Asm);
1389 void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
1390 const MCAsmLayout &Layout,
1391 const MCFragment *Fragment,
1392 const MCFixup &Fixup, MCValue Target,
1393 uint64_t &FixedValue) {
1394 ((ELFObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup,
1395 Target, FixedValue);
1398 bool ELFObjectWriter::IsFixupFullyResolved(const MCAssembler &Asm,
1399 const MCValue Target,
1401 const MCFragment *DF) const {
1402 return ((ELFObjectWriterImpl*) Impl)->IsFixupFullyResolved(Asm, Target,
1406 void ELFObjectWriter::WriteObject(MCAssembler &Asm,
1407 const MCAsmLayout &Layout) {
1408 ((ELFObjectWriterImpl*) Impl)->WriteObject(Asm, Layout);