blob: ed4f972be59e82af72a00269dea52e0730a1ce8f [file] [log] [blame]
Matt Fleming3565a062010-08-16 18:57:57 +00001//===- lib/MC/ELFObjectWriter.cpp - ELF File Writer -------------------===//
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// This file implements ELF object file writer information.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/MC/ELFObjectWriter.h"
15#include "llvm/ADT/STLExtras.h"
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/Twine.h"
18#include "llvm/MC/MCAssembler.h"
19#include "llvm/MC/MCAsmLayout.h"
20#include "llvm/MC/MCContext.h"
21#include "llvm/MC/MCELFSymbolFlags.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCObjectWriter.h"
24#include "llvm/MC/MCSectionELF.h"
25#include "llvm/MC/MCSymbol.h"
26#include "llvm/MC/MCValue.h"
27#include "llvm/Support/Debug.h"
28#include "llvm/Support/ErrorHandling.h"
29#include "llvm/Support/ELF.h"
30#include "llvm/Target/TargetAsmBackend.h"
31
32#include "../Target/X86/X86FixupKinds.h"
33
34#include <vector>
35using namespace llvm;
36
37namespace {
38
39 class ELFObjectWriterImpl {
40 static bool isFixupKindX86PCRel(unsigned Kind) {
41 switch (Kind) {
42 default:
43 return false;
44 case X86::reloc_pcrel_1byte:
45 case X86::reloc_pcrel_4byte:
46 case X86::reloc_riprel_4byte:
47 case X86::reloc_riprel_4byte_movq_load:
48 return true;
49 }
50 }
51
Chris Lattnerb188a372010-08-28 03:21:03 +000052 /*static bool isFixupKindX86RIPRel(unsigned Kind) {
Matt Fleming3565a062010-08-16 18:57:57 +000053 return Kind == X86::reloc_riprel_4byte ||
54 Kind == X86::reloc_riprel_4byte_movq_load;
Chris Lattnerb188a372010-08-28 03:21:03 +000055 }*/
Matt Fleming3565a062010-08-16 18:57:57 +000056
57
58 /// ELFSymbolData - Helper struct for containing some precomputed information
59 /// on symbols.
60 struct ELFSymbolData {
61 MCSymbolData *SymbolData;
62 uint64_t StringIndex;
63 uint32_t SectionIndex;
64
65 // Support lexicographic sorting.
66 bool operator<(const ELFSymbolData &RHS) const {
Benjamin Kramer36c6dc22010-08-23 21:23:52 +000067 return SymbolData->getSymbol().getName() <
68 RHS.SymbolData->getSymbol().getName();
Matt Fleming3565a062010-08-16 18:57:57 +000069 }
70 };
71
72 /// @name Relocation Data
73 /// @{
74
75 struct ELFRelocationEntry {
76 // Make these big enough for both 32-bit and 64-bit
77 uint64_t r_offset;
78 uint64_t r_info;
79 uint64_t r_addend;
80
81 // Support lexicographic sorting.
82 bool operator<(const ELFRelocationEntry &RE) const {
83 return RE.r_offset < r_offset;
84 }
85 };
86
87 llvm::DenseMap<const MCSectionData*,
88 std::vector<ELFRelocationEntry> > Relocations;
89 DenseMap<const MCSection*, uint64_t> SectionStringTableIndex;
90
91 /// @}
92 /// @name Symbol Table Data
93 /// @{
94
95 SmallString<256> StringTable;
96 std::vector<ELFSymbolData> LocalSymbolData;
97 std::vector<ELFSymbolData> ExternalSymbolData;
98 std::vector<ELFSymbolData> UndefinedSymbolData;
99
100 /// @}
101
102 ELFObjectWriter *Writer;
103
104 raw_ostream &OS;
105
Matt Fleming3565a062010-08-16 18:57:57 +0000106 unsigned Is64Bit : 1;
107
108 bool HasRelocationAddend;
109
110 // This holds the symbol table index of the last local symbol.
111 unsigned LastLocalSymbolIndex;
112 // This holds the .strtab section index.
113 unsigned StringTableIndex;
114
115 unsigned ShstrtabIndex;
116
117 public:
118 ELFObjectWriterImpl(ELFObjectWriter *_Writer, bool _Is64Bit,
119 bool _HasRelAddend)
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000120 : Writer(_Writer), OS(Writer->getStream()),
Matt Fleming3565a062010-08-16 18:57:57 +0000121 Is64Bit(_Is64Bit), HasRelocationAddend(_HasRelAddend) {
122 }
123
124 void Write8(uint8_t Value) { Writer->Write8(Value); }
125 void Write16(uint16_t Value) { Writer->Write16(Value); }
126 void Write32(uint32_t Value) { Writer->Write32(Value); }
Chris Lattnerb188a372010-08-28 03:21:03 +0000127 //void Write64(uint64_t Value) { Writer->Write64(Value); }
Matt Fleming3565a062010-08-16 18:57:57 +0000128 void WriteZeros(unsigned N) { Writer->WriteZeros(N); }
Chris Lattnerb188a372010-08-28 03:21:03 +0000129 //void WriteBytes(StringRef Str, unsigned ZeroFillSize = 0) {
130 // Writer->WriteBytes(Str, ZeroFillSize);
131 //}
Matt Fleming3565a062010-08-16 18:57:57 +0000132
133 void WriteWord(uint64_t W) {
Chris Lattnerb188a372010-08-28 03:21:03 +0000134 if (Is64Bit)
Matt Fleming3565a062010-08-16 18:57:57 +0000135 Writer->Write64(W);
Chris Lattnerb188a372010-08-28 03:21:03 +0000136 else
Matt Fleming3565a062010-08-16 18:57:57 +0000137 Writer->Write32(W);
Matt Fleming3565a062010-08-16 18:57:57 +0000138 }
139
140 void String8(char *buf, uint8_t Value) {
141 buf[0] = Value;
142 }
143
144 void StringLE16(char *buf, uint16_t Value) {
145 buf[0] = char(Value >> 0);
146 buf[1] = char(Value >> 8);
147 }
148
149 void StringLE32(char *buf, uint32_t Value) {
Benjamin Kramer36c6dc22010-08-23 21:23:52 +0000150 StringLE16(buf, uint16_t(Value >> 0));
Benjamin Kramerc522f6e2010-08-23 21:32:00 +0000151 StringLE16(buf + 2, uint16_t(Value >> 16));
Matt Fleming3565a062010-08-16 18:57:57 +0000152 }
153
154 void StringLE64(char *buf, uint64_t Value) {
Benjamin Kramer36c6dc22010-08-23 21:23:52 +0000155 StringLE32(buf, uint32_t(Value >> 0));
Benjamin Kramerc522f6e2010-08-23 21:32:00 +0000156 StringLE32(buf + 4, uint32_t(Value >> 32));
Matt Fleming3565a062010-08-16 18:57:57 +0000157 }
158
159 void StringBE16(char *buf ,uint16_t Value) {
160 buf[0] = char(Value >> 8);
161 buf[1] = char(Value >> 0);
162 }
163
164 void StringBE32(char *buf, uint32_t Value) {
Benjamin Kramer36c6dc22010-08-23 21:23:52 +0000165 StringBE16(buf, uint16_t(Value >> 16));
Benjamin Kramerc522f6e2010-08-23 21:32:00 +0000166 StringBE16(buf + 2, uint16_t(Value >> 0));
Matt Fleming3565a062010-08-16 18:57:57 +0000167 }
168
169 void StringBE64(char *buf, uint64_t Value) {
Benjamin Kramer36c6dc22010-08-23 21:23:52 +0000170 StringBE32(buf, uint32_t(Value >> 32));
Benjamin Kramerc522f6e2010-08-23 21:32:00 +0000171 StringBE32(buf + 4, uint32_t(Value >> 0));
Matt Fleming3565a062010-08-16 18:57:57 +0000172 }
173
174 void String16(char *buf, uint16_t Value) {
175 if (Writer->isLittleEndian())
Eli Friedmanf8020a32010-08-16 19:15:06 +0000176 StringLE16(buf, Value);
Matt Fleming3565a062010-08-16 18:57:57 +0000177 else
Eli Friedmanf8020a32010-08-16 19:15:06 +0000178 StringBE16(buf, Value);
Matt Fleming3565a062010-08-16 18:57:57 +0000179 }
180
181 void String32(char *buf, uint32_t Value) {
182 if (Writer->isLittleEndian())
Eli Friedmanf8020a32010-08-16 19:15:06 +0000183 StringLE32(buf, Value);
Matt Fleming3565a062010-08-16 18:57:57 +0000184 else
Eli Friedmanf8020a32010-08-16 19:15:06 +0000185 StringBE32(buf, Value);
Matt Fleming3565a062010-08-16 18:57:57 +0000186 }
187
188 void String64(char *buf, uint64_t Value) {
189 if (Writer->isLittleEndian())
Eli Friedmanf8020a32010-08-16 19:15:06 +0000190 StringLE64(buf, Value);
Matt Fleming3565a062010-08-16 18:57:57 +0000191 else
Eli Friedmanf8020a32010-08-16 19:15:06 +0000192 StringBE64(buf, Value);
Matt Fleming3565a062010-08-16 18:57:57 +0000193 }
194
195 void WriteHeader(uint64_t SectionDataSize, unsigned NumberOfSections);
196
197 void WriteSymbolEntry(MCDataFragment *F, uint64_t name, uint8_t info,
198 uint64_t value, uint64_t size,
199 uint8_t other, uint16_t shndx);
200
201 void WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD,
202 const MCAsmLayout &Layout);
203
204 void WriteSymbolTable(MCDataFragment *F, const MCAssembler &Asm,
205 const MCAsmLayout &Layout);
206
207 void RecordRelocation(const MCAssembler &Asm, const MCAsmLayout &Layout,
208 const MCFragment *Fragment, const MCFixup &Fixup,
209 MCValue Target, uint64_t &FixedValue);
210
Benjamin Kramer0b6cbfe2010-08-23 21:19:37 +0000211 uint64_t getSymbolIndexInSymbolTable(const MCAssembler &Asm,
212 const MCSymbol *S);
Matt Fleming3565a062010-08-16 18:57:57 +0000213
214 /// ComputeSymbolTable - Compute the symbol table data
215 ///
216 /// \param StringTable [out] - The string table data.
217 /// \param StringIndexMap [out] - Map from symbol names to offsets in the
218 /// string table.
219 void ComputeSymbolTable(MCAssembler &Asm);
220
221 void WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
222 const MCSectionData &SD);
223
224 void WriteRelocations(MCAssembler &Asm, MCAsmLayout &Layout) {
225 for (MCAssembler::const_iterator it = Asm.begin(),
226 ie = Asm.end(); it != ie; ++it) {
227 WriteRelocation(Asm, Layout, *it);
228 }
229 }
230
231 void CreateMetadataSections(MCAssembler &Asm, MCAsmLayout &Layout);
232
Benjamin Kramer0b6cbfe2010-08-23 21:19:37 +0000233 void ExecutePostLayoutBinding(MCAssembler &Asm) {
234 // Compute symbol table information.
235 ComputeSymbolTable(Asm);
236 }
Matt Fleming3565a062010-08-16 18:57:57 +0000237
238 void WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
239 uint64_t Address, uint64_t Offset,
240 uint64_t Size, uint32_t Link, uint32_t Info,
241 uint64_t Alignment, uint64_t EntrySize);
242
243 void WriteRelocationsFragment(const MCAssembler &Asm, MCDataFragment *F,
244 const MCSectionData *SD);
245
246 void WriteObject(const MCAssembler &Asm, const MCAsmLayout &Layout);
247 };
248
249}
250
251// Emit the ELF header.
252void ELFObjectWriterImpl::WriteHeader(uint64_t SectionDataSize,
253 unsigned NumberOfSections) {
254 // ELF Header
255 // ----------
256 //
257 // Note
258 // ----
259 // emitWord method behaves differently for ELF32 and ELF64, writing
260 // 4 bytes in the former and 8 in the latter.
261
262 Write8(0x7f); // e_ident[EI_MAG0]
263 Write8('E'); // e_ident[EI_MAG1]
264 Write8('L'); // e_ident[EI_MAG2]
265 Write8('F'); // e_ident[EI_MAG3]
266
267 Write8(Is64Bit ? ELF::ELFCLASS64 : ELF::ELFCLASS32); // e_ident[EI_CLASS]
268
269 // e_ident[EI_DATA]
270 Write8(Writer->isLittleEndian() ? ELF::ELFDATA2LSB : ELF::ELFDATA2MSB);
271
272 Write8(ELF::EV_CURRENT); // e_ident[EI_VERSION]
273 Write8(ELF::ELFOSABI_LINUX); // e_ident[EI_OSABI]
274 Write8(0); // e_ident[EI_ABIVERSION]
275
276 WriteZeros(ELF::EI_NIDENT - ELF::EI_PAD);
277
278 Write16(ELF::ET_REL); // e_type
279
280 // FIXME: Make this configurable
Benjamin Kramereb976772010-08-17 17:02:29 +0000281 Write16(Is64Bit ? ELF::EM_X86_64 : ELF::EM_386); // e_machine = target
Matt Fleming3565a062010-08-16 18:57:57 +0000282
283 Write32(ELF::EV_CURRENT); // e_version
284 WriteWord(0); // e_entry, no entry point in .o file
285 WriteWord(0); // e_phoff, no program header for .o
Benjamin Kramereb976772010-08-17 17:02:29 +0000286 WriteWord(SectionDataSize + (Is64Bit ? sizeof(ELF::Elf64_Ehdr) :
287 sizeof(ELF::Elf32_Ehdr))); // e_shoff = sec hdr table off in bytes
Matt Fleming3565a062010-08-16 18:57:57 +0000288
289 // FIXME: Make this configurable.
290 Write32(0); // e_flags = whatever the target wants
291
292 // e_ehsize = ELF header size
293 Write16(Is64Bit ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr));
294
295 Write16(0); // e_phentsize = prog header entry size
296 Write16(0); // e_phnum = # prog header entries = 0
297
298 // e_shentsize = Section header entry size
299 Write16(Is64Bit ? sizeof(ELF::Elf64_Shdr) : sizeof(ELF::Elf32_Shdr));
300
301 // e_shnum = # of section header ents
302 Write16(NumberOfSections);
303
304 // e_shstrndx = Section # of '.shstrtab'
305 Write16(ShstrtabIndex);
306}
307
308void ELFObjectWriterImpl::WriteSymbolEntry(MCDataFragment *F, uint64_t name,
309 uint8_t info, uint64_t value,
310 uint64_t size, uint8_t other,
311 uint16_t shndx) {
312 if (Is64Bit) {
313 char buf[8];
314
315 String32(buf, name);
316 F->getContents() += StringRef(buf, 4); // st_name
317
318 String8(buf, info);
319 F->getContents() += StringRef(buf, 1); // st_info
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000320
Matt Fleming3565a062010-08-16 18:57:57 +0000321 String8(buf, other);
322 F->getContents() += StringRef(buf, 1); // st_other
323
324 String16(buf, shndx);
325 F->getContents() += StringRef(buf, 2); // st_shndx
326
327 String64(buf, value);
328 F->getContents() += StringRef(buf, 8); // st_value
329
330 String64(buf, size);
331 F->getContents() += StringRef(buf, 8); // st_size
332 } else {
333 char buf[4];
334
335 String32(buf, name);
336 F->getContents() += StringRef(buf, 4); // st_name
337
338 String32(buf, value);
339 F->getContents() += StringRef(buf, 4); // st_value
340
341 String32(buf, size);
342 F->getContents() += StringRef(buf, 4); // st_size
343
344 String8(buf, info);
345 F->getContents() += StringRef(buf, 1); // st_info
346
347 String8(buf, other);
348 F->getContents() += StringRef(buf, 1); // st_other
349
350 String16(buf, shndx);
351 F->getContents() += StringRef(buf, 2); // st_shndx
352 }
353}
354
355void ELFObjectWriterImpl::WriteSymbol(MCDataFragment *F, ELFSymbolData &MSD,
356 const MCAsmLayout &Layout) {
357 MCSymbolData &Data = *MSD.SymbolData;
Matt Fleming3565a062010-08-16 18:57:57 +0000358 uint8_t Info = (Data.getFlags() & 0xff);
359 uint8_t Other = ((Data.getFlags() & 0xf00) >> ELF_STV_Shift);
360 uint64_t Value = 0;
361 uint64_t Size = 0;
362 const MCExpr *ESize;
363
364 if (Data.isCommon() && Data.isExternal())
365 Value = Data.getCommonAlignment();
366
Roman Divacky563b38a2010-09-08 14:29:45 +0000367 if (!Data.isCommon() && !(Data.getFlags() & ELF_STB_Weak))
Benjamin Kramer6cc53be2010-08-30 17:20:17 +0000368 if (MCFragment *FF = Data.getFragment())
369 Value = Layout.getSymbolAddress(&Data) -
370 Layout.getSectionAddress(FF->getParent());
371
Matt Fleming3565a062010-08-16 18:57:57 +0000372 ESize = Data.getSize();
373 if (Data.getSize()) {
374 MCValue Res;
375 if (ESize->getKind() == MCExpr::Binary) {
376 const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(ESize);
377
378 if (BE->EvaluateAsRelocatable(Res, &Layout)) {
379 MCSymbolData &A =
380 Layout.getAssembler().getSymbolData(Res.getSymA()->getSymbol());
381 MCSymbolData &B =
382 Layout.getAssembler().getSymbolData(Res.getSymB()->getSymbol());
383
384 Size = Layout.getSymbolAddress(&A) - Layout.getSymbolAddress(&B);
Matt Fleming3565a062010-08-16 18:57:57 +0000385 }
386 } else if (ESize->getKind() == MCExpr::Constant) {
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000387 Size = static_cast<const MCConstantExpr *>(ESize)->getValue();
Matt Fleming3565a062010-08-16 18:57:57 +0000388 } else {
389 assert(0 && "Unsupported size expression");
390 }
391 }
392
393 // Write out the symbol table entry
394 WriteSymbolEntry(F, MSD.StringIndex, Info, Value,
395 Size, Other, MSD.SectionIndex);
396}
397
398void ELFObjectWriterImpl::WriteSymbolTable(MCDataFragment *F,
399 const MCAssembler &Asm,
400 const MCAsmLayout &Layout) {
401 // The string table must be emitted first because we need the index
402 // into the string table for all the symbol names.
403 assert(StringTable.size() && "Missing string table");
404
405 // FIXME: Make sure the start of the symbol table is aligned.
406
407 // The first entry is the undefined symbol entry.
408 unsigned EntrySize = Is64Bit ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000409 F->getContents().append(EntrySize, '\x00');
Matt Fleming3565a062010-08-16 18:57:57 +0000410
411 // Write the symbol table entries.
412 LastLocalSymbolIndex = LocalSymbolData.size() + 1;
413 for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i) {
414 ELFSymbolData &MSD = LocalSymbolData[i];
415 WriteSymbol(F, MSD, Layout);
416 }
417
418 // Write out a symbol table entry for each section.
Eli Friedmana44fa242010-08-16 21:17:09 +0000419 // leaving out the just added .symtab which is at
420 // the very end
421 unsigned Index = 1;
422 for (MCAssembler::const_iterator it = Asm.begin(),
423 ie = Asm.end(); it != ie; ++it, ++Index) {
Eli Friedmana44fa242010-08-16 21:17:09 +0000424 const MCSectionELF &Section =
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000425 static_cast<const MCSectionELF&>(it->getSection());
Eli Friedmana44fa242010-08-16 21:17:09 +0000426 // Leave out relocations so we don't have indexes within
427 // the relocations messed up
Benjamin Kramer377a5722010-08-17 17:30:07 +0000428 if (Section.getType() == ELF::SHT_RELA || Section.getType() == ELF::SHT_REL)
Eli Friedmana44fa242010-08-16 21:17:09 +0000429 continue;
430 if (Index == Asm.size())
431 continue;
Matt Fleming3565a062010-08-16 18:57:57 +0000432 WriteSymbolEntry(F, 0, ELF::STT_SECTION, 0, 0, ELF::STV_DEFAULT, Index);
Eli Friedmana44fa242010-08-16 21:17:09 +0000433 LastLocalSymbolIndex++;
434 }
Matt Fleming3565a062010-08-16 18:57:57 +0000435
436 for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i) {
437 ELFSymbolData &MSD = ExternalSymbolData[i];
438 MCSymbolData &Data = *MSD.SymbolData;
439 assert((Data.getFlags() & ELF_STB_Global) &&
440 "External symbol requires STB_GLOBAL flag");
441 WriteSymbol(F, MSD, Layout);
442 if (Data.getFlags() & ELF_STB_Local)
443 LastLocalSymbolIndex++;
444 }
445
446 for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i) {
447 ELFSymbolData &MSD = UndefinedSymbolData[i];
448 MCSymbolData &Data = *MSD.SymbolData;
449 Data.setFlags(Data.getFlags() | ELF_STB_Global);
450 WriteSymbol(F, MSD, Layout);
451 if (Data.getFlags() & ELF_STB_Local)
452 LastLocalSymbolIndex++;
453 }
454}
455
Benjamin Kramere5b57342010-08-17 18:20:28 +0000456// FIXME: this is currently X86/X86_64 only
Matt Fleming3565a062010-08-16 18:57:57 +0000457void ELFObjectWriterImpl::RecordRelocation(const MCAssembler &Asm,
458 const MCAsmLayout &Layout,
459 const MCFragment *Fragment,
460 const MCFixup &Fixup,
461 MCValue Target,
462 uint64_t &FixedValue) {
Matt Fleming3565a062010-08-16 18:57:57 +0000463 int64_t Addend = 0;
464 unsigned Index = 0;
Benjamin Kramer95c602a2010-08-27 10:38:39 +0000465 int64_t Value = Target.getConstant();
Matt Fleming3565a062010-08-16 18:57:57 +0000466
Benjamin Kramer81cfb852010-08-17 19:45:05 +0000467 if (!Target.isAbsolute()) {
Matt Fleming3565a062010-08-16 18:57:57 +0000468 const MCSymbol *Symbol = &Target.getSymA()->getSymbol();
469 MCSymbolData &SD = Asm.getSymbolData(*Symbol);
470 const MCSymbolData *Base = Asm.getAtom(Layout, &SD);
Benjamin Kramer63d37b92010-08-26 17:23:02 +0000471 MCFragment *F = SD.getFragment();
Matt Fleming3565a062010-08-16 18:57:57 +0000472
473 if (Base) {
Benjamin Kramer679d2362010-08-30 11:59:29 +0000474 if (F && (!Symbol->isInSection() || SD.isCommon()) && !SD.isExternal()) {
Benjamin Kramer0b6cbfe2010-08-23 21:19:37 +0000475 Index = F->getParent()->getOrdinal() + LocalSymbolData.size() + 1;
Benjamin Kramerbcf2db62010-08-23 19:05:46 +0000476 Value += Layout.getSymbolAddress(&SD);
477 } else
Benjamin Kramer0b6cbfe2010-08-23 21:19:37 +0000478 Index = getSymbolIndexInSymbolTable(Asm, Symbol);
Matt Fleming3565a062010-08-16 18:57:57 +0000479 if (Base != &SD)
480 Value += Layout.getSymbolAddress(&SD) - Layout.getSymbolAddress(Base);
481 Addend = Value;
Benjamin Kramer63d37b92010-08-26 17:23:02 +0000482 // Compensate for the addend on i386.
Benjamin Kramer4ba1b302010-08-26 18:12:04 +0000483 if (Is64Bit)
484 Value = 0;
Matt Fleming3565a062010-08-16 18:57:57 +0000485 } else {
Matt Fleming3565a062010-08-16 18:57:57 +0000486 if (F) {
487 // Index of the section in .symtab against this symbol
488 // is being relocated + 2 (empty section + abs. symbols).
Benjamin Kramer0b6cbfe2010-08-23 21:19:37 +0000489 Index = F->getParent()->getOrdinal() + LocalSymbolData.size() + 1;
Matt Fleming3565a062010-08-16 18:57:57 +0000490
491 MCSectionData *FSD = F->getParent();
492 // Offset of the symbol in the section
493 Addend = Layout.getSymbolAddress(&SD) - Layout.getSectionAddress(FSD);
494 } else {
495 FixedValue = Value;
496 return;
497 }
498 }
499 }
500
Benjamin Kramer95c602a2010-08-27 10:38:39 +0000501 FixedValue = Value;
502
Matt Fleming3565a062010-08-16 18:57:57 +0000503 // determine the type of the relocation
Benjamin Kramer63d37b92010-08-26 17:23:02 +0000504 bool IsPCRel = isFixupKindX86PCRel(Fixup.getKind());
505 unsigned Type;
Benjamin Kramere5b57342010-08-17 18:20:28 +0000506 if (Is64Bit) {
507 if (IsPCRel) {
508 Type = ELF::R_X86_64_PC32;
509 } else {
510 switch ((unsigned)Fixup.getKind()) {
511 default: llvm_unreachable("invalid fixup kind!");
512 case FK_Data_8: Type = ELF::R_X86_64_64; break;
513 case X86::reloc_pcrel_4byte:
514 case FK_Data_4:
515 // check that the offset fits within a signed long
516 if (isInt<32>(Target.getConstant()))
517 Type = ELF::R_X86_64_32S;
518 else
519 Type = ELF::R_X86_64_32;
520 break;
521 case FK_Data_2: Type = ELF::R_X86_64_16; break;
522 case X86::reloc_pcrel_1byte:
523 case FK_Data_1: Type = ELF::R_X86_64_8; break;
524 }
525 }
Matt Fleming3565a062010-08-16 18:57:57 +0000526 } else {
Benjamin Kramere5b57342010-08-17 18:20:28 +0000527 if (IsPCRel) {
528 Type = ELF::R_386_PC32;
529 } else {
530 switch ((unsigned)Fixup.getKind()) {
531 default: llvm_unreachable("invalid fixup kind!");
532 case X86::reloc_pcrel_4byte:
533 case FK_Data_4: Type = ELF::R_386_32; break;
534 case FK_Data_2: Type = ELF::R_386_16; break;
535 case X86::reloc_pcrel_1byte:
536 case FK_Data_1: Type = ELF::R_386_8; break;
537 }
Matt Fleming3565a062010-08-16 18:57:57 +0000538 }
539 }
540
Benjamin Kramere5b57342010-08-17 18:20:28 +0000541 ELFRelocationEntry ERE;
542
543 if (Is64Bit) {
544 struct ELF::Elf64_Rela ERE64;
545 ERE64.setSymbolAndType(Index, Type);
546 ERE.r_info = ERE64.r_info;
547 } else {
548 struct ELF::Elf32_Rela ERE32;
549 ERE32.setSymbolAndType(Index, Type);
550 ERE.r_info = ERE32.r_info;
551 }
Matt Fleming3565a062010-08-16 18:57:57 +0000552
Benjamin Kramer63d37b92010-08-26 17:23:02 +0000553 ERE.r_offset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
Benjamin Kramere5b57342010-08-17 18:20:28 +0000554
Matt Fleming3565a062010-08-16 18:57:57 +0000555 if (HasRelocationAddend)
556 ERE.r_addend = Addend;
Benjamin Kramer172d7d62010-08-17 00:33:24 +0000557 else
558 ERE.r_addend = 0; // Silence compiler warning.
Matt Fleming3565a062010-08-16 18:57:57 +0000559
560 Relocations[Fragment->getParent()].push_back(ERE);
561}
562
Benjamin Kramer0b6cbfe2010-08-23 21:19:37 +0000563uint64_t
564ELFObjectWriterImpl::getSymbolIndexInSymbolTable(const MCAssembler &Asm,
565 const MCSymbol *S) {
Benjamin Kramer7b83c262010-08-25 20:09:43 +0000566 MCSymbolData &SD = Asm.getSymbolData(*S);
Eli Friedmanf8020a32010-08-16 19:15:06 +0000567
Benjamin Kramer7b83c262010-08-25 20:09:43 +0000568 // Local symbol.
569 if (!SD.isExternal() && !S->isUndefined())
570 return SD.getIndex() + /* empty symbol */ 1;
571
572 // External or undefined symbol.
573 return SD.getIndex() + Asm.size() + /* empty symbol */ 1;
Matt Fleming3565a062010-08-16 18:57:57 +0000574}
575
576void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
577 // Build section lookup table.
578 DenseMap<const MCSection*, uint8_t> SectionIndexMap;
579 unsigned Index = 1;
580 for (MCAssembler::iterator it = Asm.begin(),
581 ie = Asm.end(); it != ie; ++it, ++Index)
582 SectionIndexMap[&it->getSection()] = Index;
583
584 // Index 0 is always the empty string.
585 StringMap<uint64_t> StringIndexMap;
586 StringTable += '\x00';
587
588 // Add the data for local symbols.
589 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
590 ie = Asm.symbol_end(); it != ie; ++it) {
591 const MCSymbol &Symbol = it->getSymbol();
592
593 // Ignore non-linker visible symbols.
594 if (!Asm.isSymbolLinkerVisible(Symbol))
595 continue;
596
597 if (it->isExternal() || Symbol.isUndefined())
598 continue;
599
600 uint64_t &Entry = StringIndexMap[Symbol.getName()];
601 if (!Entry) {
602 Entry = StringTable.size();
603 StringTable += Symbol.getName();
604 StringTable += '\x00';
605 }
606
607 ELFSymbolData MSD;
608 MSD.SymbolData = it;
609 MSD.StringIndex = Entry;
610
611 if (Symbol.isAbsolute()) {
612 MSD.SectionIndex = ELF::SHN_ABS;
613 LocalSymbolData.push_back(MSD);
614 } else {
615 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
616 assert(MSD.SectionIndex && "Invalid section index!");
617 LocalSymbolData.push_back(MSD);
618 }
619 }
620
621 // Now add non-local symbols.
622 for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
623 ie = Asm.symbol_end(); it != ie; ++it) {
624 const MCSymbol &Symbol = it->getSymbol();
625
626 // Ignore non-linker visible symbols.
627 if (!Asm.isSymbolLinkerVisible(Symbol))
628 continue;
629
630 if (!it->isExternal() && !Symbol.isUndefined())
631 continue;
632
633 uint64_t &Entry = StringIndexMap[Symbol.getName()];
634 if (!Entry) {
635 Entry = StringTable.size();
636 StringTable += Symbol.getName();
637 StringTable += '\x00';
638 }
639
640 ELFSymbolData MSD;
641 MSD.SymbolData = it;
642 MSD.StringIndex = Entry;
643
644 if (Symbol.isUndefined()) {
645 MSD.SectionIndex = ELF::SHN_UNDEF;
646 // XXX: for some reason we dont Emit* this
647 it->setFlags(it->getFlags() | ELF_STB_Global);
648 UndefinedSymbolData.push_back(MSD);
649 } else if (Symbol.isAbsolute()) {
650 MSD.SectionIndex = ELF::SHN_ABS;
651 ExternalSymbolData.push_back(MSD);
652 } else if (it->isCommon()) {
653 MSD.SectionIndex = ELF::SHN_COMMON;
654 ExternalSymbolData.push_back(MSD);
655 } else {
656 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
657 assert(MSD.SectionIndex && "Invalid section index!");
658 ExternalSymbolData.push_back(MSD);
659 }
660 }
661
662 // Symbols are required to be in lexicographic order.
663 array_pod_sort(LocalSymbolData.begin(), LocalSymbolData.end());
664 array_pod_sort(ExternalSymbolData.begin(), ExternalSymbolData.end());
665 array_pod_sort(UndefinedSymbolData.begin(), UndefinedSymbolData.end());
666
667 // Set the symbol indices. Local symbols must come before all other
668 // symbols with non-local bindings.
669 Index = 0;
670 for (unsigned i = 0, e = LocalSymbolData.size(); i != e; ++i)
671 LocalSymbolData[i].SymbolData->setIndex(Index++);
672 for (unsigned i = 0, e = ExternalSymbolData.size(); i != e; ++i)
673 ExternalSymbolData[i].SymbolData->setIndex(Index++);
674 for (unsigned i = 0, e = UndefinedSymbolData.size(); i != e; ++i)
675 UndefinedSymbolData[i].SymbolData->setIndex(Index++);
676}
677
678void ELFObjectWriterImpl::WriteRelocation(MCAssembler &Asm, MCAsmLayout &Layout,
679 const MCSectionData &SD) {
680 if (!Relocations[&SD].empty()) {
681 MCContext &Ctx = Asm.getContext();
682 const MCSection *RelaSection;
683 const MCSectionELF &Section =
684 static_cast<const MCSectionELF&>(SD.getSection());
685
686 const StringRef SectionName = Section.getSectionName();
Benjamin Kramer377a5722010-08-17 17:30:07 +0000687 std::string RelaSectionName = HasRelocationAddend ? ".rela" : ".rel";
Matt Fleming3565a062010-08-16 18:57:57 +0000688 RelaSectionName += SectionName;
Benjamin Kramer299fbe32010-08-17 17:56:13 +0000689
690 unsigned EntrySize;
691 if (HasRelocationAddend)
692 EntrySize = Is64Bit ? sizeof(ELF::Elf64_Rela) : sizeof(ELF::Elf32_Rela);
693 else
694 EntrySize = Is64Bit ? sizeof(ELF::Elf64_Rel) : sizeof(ELF::Elf32_Rel);
Matt Fleming3565a062010-08-16 18:57:57 +0000695
Benjamin Kramer377a5722010-08-17 17:30:07 +0000696 RelaSection = Ctx.getELFSection(RelaSectionName, HasRelocationAddend ?
697 ELF::SHT_RELA : ELF::SHT_REL, 0,
Matt Fleming3565a062010-08-16 18:57:57 +0000698 SectionKind::getReadOnly(),
699 false, EntrySize);
700
701 MCSectionData &RelaSD = Asm.getOrCreateSectionData(*RelaSection);
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000702 RelaSD.setAlignment(Is64Bit ? 8 : 4);
Matt Fleming3565a062010-08-16 18:57:57 +0000703
704 MCDataFragment *F = new MCDataFragment(&RelaSD);
705
706 WriteRelocationsFragment(Asm, F, &SD);
707
708 Asm.AddSectionToTheEnd(RelaSD, Layout);
709 }
710}
711
712void ELFObjectWriterImpl::WriteSecHdrEntry(uint32_t Name, uint32_t Type,
713 uint64_t Flags, uint64_t Address,
714 uint64_t Offset, uint64_t Size,
715 uint32_t Link, uint32_t Info,
716 uint64_t Alignment,
717 uint64_t EntrySize) {
718 Write32(Name); // sh_name: index into string table
719 Write32(Type); // sh_type
720 WriteWord(Flags); // sh_flags
721 WriteWord(Address); // sh_addr
722 WriteWord(Offset); // sh_offset
723 WriteWord(Size); // sh_size
724 Write32(Link); // sh_link
725 Write32(Info); // sh_info
726 WriteWord(Alignment); // sh_addralign
727 WriteWord(EntrySize); // sh_entsize
728}
729
730void ELFObjectWriterImpl::WriteRelocationsFragment(const MCAssembler &Asm,
731 MCDataFragment *F,
732 const MCSectionData *SD) {
733 std::vector<ELFRelocationEntry> &Relocs = Relocations[SD];
734 // sort by the r_offset just like gnu as does
735 array_pod_sort(Relocs.begin(), Relocs.end());
736
737 for (unsigned i = 0, e = Relocs.size(); i != e; ++i) {
738 ELFRelocationEntry entry = Relocs[e - i - 1];
739
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000740 unsigned WordSize = Is64Bit ? 8 : 4;
741 F->getContents() += StringRef((const char *)&entry.r_offset, WordSize);
742 F->getContents() += StringRef((const char *)&entry.r_info, WordSize);
Matt Fleming3565a062010-08-16 18:57:57 +0000743
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000744 if (HasRelocationAddend)
745 F->getContents() += StringRef((const char *)&entry.r_addend, WordSize);
Matt Fleming3565a062010-08-16 18:57:57 +0000746 }
747}
748
749void ELFObjectWriterImpl::CreateMetadataSections(MCAssembler &Asm,
750 MCAsmLayout &Layout) {
751 MCContext &Ctx = Asm.getContext();
752 MCDataFragment *F;
753
754 WriteRelocations(Asm, Layout);
755
756 const MCSection *SymtabSection;
757 unsigned EntrySize = Is64Bit ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
758
759 SymtabSection = Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
760 SectionKind::getReadOnly(),
761 false, EntrySize);
762
763 MCSectionData &SymtabSD = Asm.getOrCreateSectionData(*SymtabSection);
764
765 SymtabSD.setAlignment(Is64Bit ? 8 : 4);
766
767 F = new MCDataFragment(&SymtabSD);
768
769 // Symbol table
770 WriteSymbolTable(F, Asm, Layout);
771 Asm.AddSectionToTheEnd(SymtabSD, Layout);
772
773 const MCSection *StrtabSection;
774 StrtabSection = Ctx.getELFSection(".strtab", ELF::SHT_STRTAB, 0,
775 SectionKind::getReadOnly(), false);
776
777 MCSectionData &StrtabSD = Asm.getOrCreateSectionData(*StrtabSection);
778 StrtabSD.setAlignment(1);
779
780 // FIXME: This isn't right. If the sections get rearranged this will
781 // be wrong. We need a proper lookup.
782 StringTableIndex = Asm.size();
783
784 F = new MCDataFragment(&StrtabSD);
785 F->getContents().append(StringTable.begin(), StringTable.end());
786 Asm.AddSectionToTheEnd(StrtabSD, Layout);
787
788 const MCSection *ShstrtabSection;
789 ShstrtabSection = Ctx.getELFSection(".shstrtab", ELF::SHT_STRTAB, 0,
790 SectionKind::getReadOnly(), false);
791
792 MCSectionData &ShstrtabSD = Asm.getOrCreateSectionData(*ShstrtabSection);
793 ShstrtabSD.setAlignment(1);
794
795 F = new MCDataFragment(&ShstrtabSD);
796
797 // FIXME: This isn't right. If the sections get rearranged this will
798 // be wrong. We need a proper lookup.
799 ShstrtabIndex = Asm.size();
800
801 // Section header string table.
802 //
803 // The first entry of a string table holds a null character so skip
804 // section 0.
805 uint64_t Index = 1;
806 F->getContents() += '\x00';
807
808 for (MCAssembler::const_iterator it = Asm.begin(),
809 ie = Asm.end(); it != ie; ++it) {
Matt Fleming3565a062010-08-16 18:57:57 +0000810 const MCSectionELF &Section =
Benjamin Kramer368ae7e2010-08-17 00:00:46 +0000811 static_cast<const MCSectionELF&>(it->getSection());
Matt Fleming3565a062010-08-16 18:57:57 +0000812
813 // Remember the index into the string table so we can write it
814 // into the sh_name field of the section header table.
815 SectionStringTableIndex[&it->getSection()] = Index;
816
817 Index += Section.getSectionName().size() + 1;
818 F->getContents() += Section.getSectionName();
819 F->getContents() += '\x00';
820 }
821
822 Asm.AddSectionToTheEnd(ShstrtabSD, Layout);
823}
824
825void ELFObjectWriterImpl::WriteObject(const MCAssembler &Asm,
826 const MCAsmLayout &Layout) {
Matt Fleming3565a062010-08-16 18:57:57 +0000827 CreateMetadataSections(const_cast<MCAssembler&>(Asm),
828 const_cast<MCAsmLayout&>(Layout));
829
830 // Add 1 for the null section.
831 unsigned NumSections = Asm.size() + 1;
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000832 uint64_t NaturalAlignment = Is64Bit ? 8 : 4;
833 uint64_t HeaderSize = Is64Bit ? sizeof(ELF::Elf64_Ehdr) : sizeof(ELF::Elf32_Ehdr);
834 uint64_t FileOff = HeaderSize;
Matt Fleming3565a062010-08-16 18:57:57 +0000835
836 for (MCAssembler::const_iterator it = Asm.begin(),
837 ie = Asm.end(); it != ie; ++it) {
838 const MCSectionData &SD = *it;
Matt Fleming3565a062010-08-16 18:57:57 +0000839
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000840 FileOff = RoundUpToAlignment(FileOff, SD.getAlignment());
841
Matt Fleming3565a062010-08-16 18:57:57 +0000842 // Get the size of the section in the output file (including padding).
843 uint64_t Size = Layout.getSectionFileSize(&SD);
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000844
845 FileOff += Size;
Matt Fleming3565a062010-08-16 18:57:57 +0000846 }
847
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000848 FileOff = RoundUpToAlignment(FileOff, NaturalAlignment);
849
Matt Fleming3565a062010-08-16 18:57:57 +0000850 // Write out the ELF header ...
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000851 WriteHeader(FileOff - HeaderSize, NumSections);
852
853 FileOff = HeaderSize;
Matt Fleming3565a062010-08-16 18:57:57 +0000854
855 // ... then all of the sections ...
856 DenseMap<const MCSection*, uint64_t> SectionOffsetMap;
857
Benjamin Kramer44cbde82010-08-19 13:44:49 +0000858 DenseMap<const MCSection*, uint8_t> SectionIndexMap;
859
860 unsigned Index = 1;
Matt Fleming3565a062010-08-16 18:57:57 +0000861 for (MCAssembler::const_iterator it = Asm.begin(),
862 ie = Asm.end(); it != ie; ++it) {
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000863 const MCSectionData &SD = *it;
864
865 uint64_t Padding = OffsetToAlignment(FileOff, SD.getAlignment());
866 WriteZeros(Padding);
867 FileOff += Padding;
868
Matt Fleming3565a062010-08-16 18:57:57 +0000869 // Remember the offset into the file for this section.
870 SectionOffsetMap[&it->getSection()] = FileOff;
Benjamin Kramer44cbde82010-08-19 13:44:49 +0000871 SectionIndexMap[&it->getSection()] = Index++;
872
Matt Fleming3565a062010-08-16 18:57:57 +0000873 FileOff += Layout.getSectionFileSize(&SD);
874
875 Asm.WriteSectionData(it, Layout, Writer);
876 }
877
Benjamin Kramera9eadca2010-09-06 16:11:52 +0000878 uint64_t Padding = OffsetToAlignment(FileOff, NaturalAlignment);
879 WriteZeros(Padding);
880 FileOff += Padding;
881
Matt Fleming3565a062010-08-16 18:57:57 +0000882 // ... and then the section header table.
883 // Should we align the section header table?
884 //
885 // Null section first.
886 WriteSecHdrEntry(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
887
888 for (MCAssembler::const_iterator it = Asm.begin(),
889 ie = Asm.end(); it != ie; ++it) {
890 const MCSectionData &SD = *it;
891 const MCSectionELF &Section =
892 static_cast<const MCSectionELF&>(SD.getSection());
893
894 uint64_t sh_link = 0;
895 uint64_t sh_info = 0;
896
897 switch(Section.getType()) {
898 case ELF::SHT_DYNAMIC:
899 sh_link = SectionStringTableIndex[&it->getSection()];
900 sh_info = 0;
901 break;
902
903 case ELF::SHT_REL:
Eli Friedmanf8020a32010-08-16 19:15:06 +0000904 case ELF::SHT_RELA: {
Matt Fleming3565a062010-08-16 18:57:57 +0000905 const MCSection *SymtabSection;
906 const MCSection *InfoSection;
Matt Fleming3565a062010-08-16 18:57:57 +0000907
908 SymtabSection = Asm.getContext().getELFSection(".symtab", ELF::SHT_SYMTAB, 0,
909 SectionKind::getReadOnly(),
Eli Friedmanf8020a32010-08-16 19:15:06 +0000910 false);
Benjamin Kramer44cbde82010-08-19 13:44:49 +0000911 sh_link = SectionIndexMap[SymtabSection];
Matt Fleming3565a062010-08-16 18:57:57 +0000912
Benjamin Kramer377a5722010-08-17 17:30:07 +0000913 // Remove ".rel" and ".rela" prefixes.
914 unsigned SecNameLen = (Section.getType() == ELF::SHT_REL) ? 4 : 5;
915 StringRef SectionName = Section.getSectionName().substr(SecNameLen);
916
Eli Friedmanf8020a32010-08-16 19:15:06 +0000917 InfoSection = Asm.getContext().getELFSection(SectionName,
Matt Fleming3565a062010-08-16 18:57:57 +0000918 ELF::SHT_PROGBITS, 0,
Eli Friedmanf8020a32010-08-16 19:15:06 +0000919 SectionKind::getReadOnly(),
920 false);
Benjamin Kramer44cbde82010-08-19 13:44:49 +0000921 sh_info = SectionIndexMap[InfoSection];
Matt Fleming3565a062010-08-16 18:57:57 +0000922 break;
Eli Friedmanf8020a32010-08-16 19:15:06 +0000923 }
Matt Fleming3565a062010-08-16 18:57:57 +0000924
925 case ELF::SHT_SYMTAB:
926 case ELF::SHT_DYNSYM:
927 sh_link = StringTableIndex;
928 sh_info = LastLocalSymbolIndex;
929 break;
930
931 case ELF::SHT_PROGBITS:
932 case ELF::SHT_STRTAB:
933 case ELF::SHT_NOBITS:
Benjamin Kramer19dc7fa2010-08-31 17:03:33 +0000934 case ELF::SHT_NULL:
Matt Fleming3565a062010-08-16 18:57:57 +0000935 // Nothing to do.
936 break;
937
938 case ELF::SHT_HASH:
939 case ELF::SHT_GROUP:
940 case ELF::SHT_SYMTAB_SHNDX:
941 default:
942 assert(0 && "FIXME: sh_type value not supported!");
943 break;
944 }
945
946 WriteSecHdrEntry(SectionStringTableIndex[&it->getSection()],
947 Section.getType(), Section.getFlags(),
948 Layout.getSectionAddress(&SD),
949 SectionOffsetMap.lookup(&SD.getSection()),
950 Layout.getSectionSize(&SD), sh_link,
951 sh_info, SD.getAlignment(),
952 Section.getEntrySize());
953 }
954}
955
956ELFObjectWriter::ELFObjectWriter(raw_ostream &OS,
957 bool Is64Bit,
958 bool IsLittleEndian,
959 bool HasRelocationAddend)
960 : MCObjectWriter(OS, IsLittleEndian)
961{
962 Impl = new ELFObjectWriterImpl(this, Is64Bit, HasRelocationAddend);
963}
964
965ELFObjectWriter::~ELFObjectWriter() {
966 delete (ELFObjectWriterImpl*) Impl;
967}
968
969void ELFObjectWriter::ExecutePostLayoutBinding(MCAssembler &Asm) {
970 ((ELFObjectWriterImpl*) Impl)->ExecutePostLayoutBinding(Asm);
971}
972
973void ELFObjectWriter::RecordRelocation(const MCAssembler &Asm,
974 const MCAsmLayout &Layout,
975 const MCFragment *Fragment,
976 const MCFixup &Fixup, MCValue Target,
977 uint64_t &FixedValue) {
978 ((ELFObjectWriterImpl*) Impl)->RecordRelocation(Asm, Layout, Fragment, Fixup,
979 Target, FixedValue);
980}
981
982void ELFObjectWriter::WriteObject(const MCAssembler &Asm,
983 const MCAsmLayout &Layout) {
984 ((ELFObjectWriterImpl*) Impl)->WriteObject(Asm, Layout);
985}