1 //===- COFFObjectFile.cpp - COFF object file implementation -----*- C++ -*-===//
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 declares the COFFObjectFile class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Object/COFF.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/ADT/Triple.h"
20 using namespace object;
23 using support::ulittle8_t;
24 using support::ulittle16_t;
25 using support::ulittle32_t;
26 using support::little16_t;
30 // Returns false if size is greater than the buffer size. And sets ec.
31 bool checkSize(const MemoryBuffer *m, error_code &ec, uint64_t size) {
32 if (m->getBufferSize() < size) {
33 ec = object_error::unexpected_eof;
39 // Returns false if any bytes in [addr, addr + size) fall outsize of m.
40 bool checkAddr(const MemoryBuffer *m,
44 if (addr + size < addr ||
46 addr + size > uintptr_t(m->getBufferEnd())) {
47 ec = object_error::unexpected_eof;
54 const coff_symbol *COFFObjectFile::toSymb(DataRefImpl Symb) const {
55 const coff_symbol *addr = reinterpret_cast<const coff_symbol*>(Symb.p);
58 // Verify that the symbol points to a valid entry in the symbol table.
59 uintptr_t offset = uintptr_t(addr) - uintptr_t(base());
60 if (offset < Header->PointerToSymbolTable
61 || offset >= Header->PointerToSymbolTable
62 + (Header->NumberOfSymbols * sizeof(coff_symbol)))
63 report_fatal_error("Symbol was outside of symbol table.");
65 assert((offset - Header->PointerToSymbolTable) % sizeof(coff_symbol)
66 == 0 && "Symbol did not point to the beginning of a symbol");
72 const coff_section *COFFObjectFile::toSec(DataRefImpl Sec) const {
73 const coff_section *addr = reinterpret_cast<const coff_section*>(Sec.p);
76 // Verify that the section points to a valid entry in the section table.
77 if (addr < SectionTable
78 || addr >= (SectionTable + Header->NumberOfSections))
79 report_fatal_error("Section was outside of section table.");
81 uintptr_t offset = uintptr_t(addr) - uintptr_t(SectionTable);
82 assert(offset % sizeof(coff_section) == 0 &&
83 "Section did not point to the beginning of a section");
89 error_code COFFObjectFile::getSymbolNext(DataRefImpl Symb,
90 SymbolRef &Result) const {
91 const coff_symbol *symb = toSymb(Symb);
92 symb += 1 + symb->NumberOfAuxSymbols;
93 Symb.p = reinterpret_cast<uintptr_t>(symb);
94 Result = SymbolRef(Symb, this);
95 return object_error::success;
98 error_code COFFObjectFile::getSymbolName(DataRefImpl Symb,
99 StringRef &Result) const {
100 const coff_symbol *symb = toSymb(Symb);
101 return getSymbolName(symb, Result);
104 error_code COFFObjectFile::getSymbolFileOffset(DataRefImpl Symb,
105 uint64_t &Result) const {
106 const coff_symbol *symb = toSymb(Symb);
107 const coff_section *Section = NULL;
108 if (error_code ec = getSection(symb->SectionNumber, Section))
111 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
113 if (Type == 'U' || Type == 'w')
114 Result = UnknownAddressOrSize;
116 Result = Section->PointerToRawData + symb->Value;
118 Result = symb->Value;
119 return object_error::success;
122 error_code COFFObjectFile::getSymbolAddress(DataRefImpl Symb,
123 uint64_t &Result) const {
124 const coff_symbol *symb = toSymb(Symb);
125 const coff_section *Section = NULL;
126 if (error_code ec = getSection(symb->SectionNumber, Section))
129 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
131 if (Type == 'U' || Type == 'w')
132 Result = UnknownAddressOrSize;
134 Result = Section->VirtualAddress + symb->Value;
136 Result = symb->Value;
137 return object_error::success;
140 error_code COFFObjectFile::getSymbolType(DataRefImpl Symb,
141 SymbolRef::Type &Result) const {
142 const coff_symbol *symb = toSymb(Symb);
143 Result = SymbolRef::ST_Other;
144 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
145 symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) {
146 Result = SymbolRef::ST_External;
148 if (symb->getComplexType() == COFF::IMAGE_SYM_DTYPE_FUNCTION) {
149 Result = SymbolRef::ST_Function;
152 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
154 if (Type == 'r' || Type == 'R') {
155 Result = SymbolRef::ST_Data;
159 return object_error::success;
162 error_code COFFObjectFile::getSymbolFlags(DataRefImpl Symb,
163 uint32_t &Result) const {
164 const coff_symbol *symb = toSymb(Symb);
165 Result = SymbolRef::SF_None;
167 // TODO: Set SF_FormatSpecific.
169 // TODO: This are certainly too restrictive.
170 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
171 Result |= SymbolRef::SF_Global;
173 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL)
174 Result |= SymbolRef::SF_Weak;
176 if (symb->SectionNumber == COFF::IMAGE_SYM_ABSOLUTE)
177 Result |= SymbolRef::SF_Absolute;
179 return object_error::success;
182 error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb,
183 uint64_t &Result) const {
184 // FIXME: Return the correct size. This requires looking at all the symbols
185 // in the same section as this symbol, and looking for either the next
186 // symbol, or the end of the section.
187 const coff_symbol *symb = toSymb(Symb);
188 const coff_section *Section = NULL;
189 if (error_code ec = getSection(symb->SectionNumber, Section))
192 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
194 if (Type == 'U' || Type == 'w')
195 Result = UnknownAddressOrSize;
197 Result = Section->SizeOfRawData - symb->Value;
200 return object_error::success;
203 error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb,
204 char &Result) const {
205 const coff_symbol *symb = toSymb(Symb);
207 if (error_code ec = getSymbolName(Symb, name))
209 char ret = StringSwitch<char>(name)
210 .StartsWith(".debug", 'N')
211 .StartsWith(".sxdata", 'N')
216 return object_error::success;
219 uint32_t Characteristics = 0;
220 if (symb->SectionNumber > 0) {
221 const coff_section *Section = NULL;
222 if (error_code ec = getSection(symb->SectionNumber, Section))
224 Characteristics = Section->Characteristics;
227 switch (symb->SectionNumber) {
228 case COFF::IMAGE_SYM_UNDEFINED:
229 // Check storage classes.
230 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) {
232 return object_error::success; // Don't do ::toupper.
233 } else if (symb->Value != 0) // Check for common symbols.
238 case COFF::IMAGE_SYM_ABSOLUTE:
241 case COFF::IMAGE_SYM_DEBUG:
245 // Check section type.
246 if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
248 else if ( Characteristics & COFF::IMAGE_SCN_MEM_READ
249 && ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
251 else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
253 else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
255 else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO)
258 // Check for section symbol.
259 else if ( symb->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC
264 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
265 ret = ::toupper(ret);
268 return object_error::success;
271 error_code COFFObjectFile::getSymbolSection(DataRefImpl Symb,
272 section_iterator &Result) const {
273 const coff_symbol *symb = toSymb(Symb);
274 if (symb->SectionNumber <= COFF::IMAGE_SYM_UNDEFINED)
275 Result = end_sections();
277 const coff_section *sec = 0;
278 if (error_code ec = getSection(symb->SectionNumber, sec)) return ec;
280 std::memset(&Sec, 0, sizeof(Sec));
281 Sec.p = reinterpret_cast<uintptr_t>(sec);
282 Result = section_iterator(SectionRef(Sec, this));
284 return object_error::success;
287 error_code COFFObjectFile::getSectionNext(DataRefImpl Sec,
288 SectionRef &Result) const {
289 const coff_section *sec = toSec(Sec);
291 Sec.p = reinterpret_cast<uintptr_t>(sec);
292 Result = SectionRef(Sec, this);
293 return object_error::success;
296 error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
297 StringRef &Result) const {
298 const coff_section *sec = toSec(Sec);
300 if (sec->Name[7] == 0)
301 // Null terminated, let ::strlen figure out the length.
304 // Not null terminated, use all 8 bytes.
305 name = StringRef(sec->Name, 8);
307 // Check for string table entry. First byte is '/'.
308 if (name[0] == '/') {
310 name.substr(1).getAsInteger(10, Offset);
311 if (error_code ec = getString(Offset, name))
316 return object_error::success;
319 error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
320 uint64_t &Result) const {
321 const coff_section *sec = toSec(Sec);
322 Result = sec->VirtualAddress;
323 return object_error::success;
326 error_code COFFObjectFile::getSectionSize(DataRefImpl Sec,
327 uint64_t &Result) const {
328 const coff_section *sec = toSec(Sec);
329 Result = sec->SizeOfRawData;
330 return object_error::success;
333 error_code COFFObjectFile::getSectionContents(DataRefImpl Sec,
334 StringRef &Result) const {
335 const coff_section *sec = toSec(Sec);
336 // The only thing that we need to verify is that the contents is contained
337 // within the file bounds. We don't need to make sure it doesn't cover other
338 // data, as there's nothing that says that is not allowed.
339 uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData;
340 uintptr_t con_end = con_start + sec->SizeOfRawData;
341 if (con_end > uintptr_t(Data->getBufferEnd()))
342 return object_error::parse_failed;
343 Result = StringRef(reinterpret_cast<const char*>(con_start),
345 return object_error::success;
348 error_code COFFObjectFile::getSectionAlignment(DataRefImpl Sec,
349 uint64_t &Res) const {
350 const coff_section *sec = toSec(Sec);
352 return object_error::parse_failed;
353 Res = uint64_t(1) << (((sec->Characteristics & 0x00F00000) >> 20) - 1);
354 return object_error::success;
357 error_code COFFObjectFile::isSectionText(DataRefImpl Sec,
358 bool &Result) const {
359 const coff_section *sec = toSec(Sec);
360 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE;
361 return object_error::success;
364 error_code COFFObjectFile::isSectionData(DataRefImpl Sec,
365 bool &Result) const {
366 const coff_section *sec = toSec(Sec);
367 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
368 return object_error::success;
371 error_code COFFObjectFile::isSectionBSS(DataRefImpl Sec,
372 bool &Result) const {
373 const coff_section *sec = toSec(Sec);
374 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
375 return object_error::success;
378 error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
380 bool &Result) const {
381 const coff_section *sec = toSec(Sec);
382 const coff_symbol *symb = toSymb(Symb);
383 const coff_section *symb_sec = 0;
384 if (error_code ec = getSection(symb->SectionNumber, symb_sec)) return ec;
389 return object_error::success;
392 relocation_iterator COFFObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
393 const coff_section *sec = toSec(Sec);
395 std::memset(&ret, 0, sizeof(ret));
396 if (sec->NumberOfRelocations == 0)
399 ret.p = reinterpret_cast<uintptr_t>(base() + sec->PointerToRelocations);
401 return relocation_iterator(RelocationRef(ret, this));
404 relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
405 const coff_section *sec = toSec(Sec);
407 std::memset(&ret, 0, sizeof(ret));
408 if (sec->NumberOfRelocations == 0)
411 ret.p = reinterpret_cast<uintptr_t>(
412 reinterpret_cast<const coff_relocation*>(
413 base() + sec->PointerToRelocations)
414 + sec->NumberOfRelocations);
416 return relocation_iterator(RelocationRef(ret, this));
419 COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
420 : ObjectFile(Binary::isCOFF, Object, ec)
425 , StringTableSize(0) {
426 // Check that we at least have enough room for a header.
427 if (!checkSize(Data, ec, sizeof(coff_file_header))) return;
429 // The actual starting location of the COFF header in the file. This can be
430 // non-zero in PE/COFF files.
431 uint64_t HeaderStart = 0;
433 // Check if this is a PE/COFF file.
434 if (base()[0] == 0x4d && base()[1] == 0x5a) {
435 // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
436 // PE signature to find 'normal' COFF header.
437 if (!checkSize(Data, ec, 0x3c + 8)) return;
438 HeaderStart = *reinterpret_cast<const ulittle16_t *>(base() + 0x3c);
439 // Check the PE header. ("PE\0\0")
440 if (std::memcmp(base() + HeaderStart, "PE\0\0", 4) != 0) {
441 ec = object_error::parse_failed;
444 HeaderStart += 4; // Skip the PE Header.
447 Header = reinterpret_cast<const coff_file_header *>(base() + HeaderStart);
448 if (!checkAddr(Data, ec, uintptr_t(Header), sizeof(coff_file_header)))
452 reinterpret_cast<const coff_section *>( base()
454 + sizeof(coff_file_header)
455 + Header->SizeOfOptionalHeader);
456 if (!checkAddr(Data, ec, uintptr_t(SectionTable),
457 Header->NumberOfSections * sizeof(coff_section)))
460 if (Header->PointerToSymbolTable != 0) {
462 reinterpret_cast<const coff_symbol *>(base()
463 + Header->PointerToSymbolTable);
464 if (!checkAddr(Data, ec, uintptr_t(SymbolTable),
465 Header->NumberOfSymbols * sizeof(coff_symbol)))
468 // Find string table.
469 StringTable = reinterpret_cast<const char *>(base())
470 + Header->PointerToSymbolTable
471 + Header->NumberOfSymbols * sizeof(coff_symbol);
472 if (!checkAddr(Data, ec, uintptr_t(StringTable), sizeof(ulittle32_t)))
475 StringTableSize = *reinterpret_cast<const ulittle32_t *>(StringTable);
476 if (!checkAddr(Data, ec, uintptr_t(StringTable), StringTableSize))
478 // Check that the string table is null terminated if has any in it.
479 if (StringTableSize < 4
480 || (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) {
481 ec = object_error::parse_failed;
486 ec = object_error::success;
489 symbol_iterator COFFObjectFile::begin_symbols() const {
491 std::memset(&ret, 0, sizeof(DataRefImpl));
492 ret.p = reinterpret_cast<intptr_t>(SymbolTable);
493 return symbol_iterator(SymbolRef(ret, this));
496 symbol_iterator COFFObjectFile::end_symbols() const {
497 // The symbol table ends where the string table begins.
499 std::memset(&ret, 0, sizeof(DataRefImpl));
500 ret.p = reinterpret_cast<intptr_t>(StringTable);
501 return symbol_iterator(SymbolRef(ret, this));
504 symbol_iterator COFFObjectFile::begin_dynamic_symbols() const {
506 report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
509 symbol_iterator COFFObjectFile::end_dynamic_symbols() const {
511 report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
514 section_iterator COFFObjectFile::begin_sections() const {
516 std::memset(&ret, 0, sizeof(DataRefImpl));
517 ret.p = reinterpret_cast<intptr_t>(SectionTable);
518 return section_iterator(SectionRef(ret, this));
521 section_iterator COFFObjectFile::end_sections() const {
523 std::memset(&ret, 0, sizeof(DataRefImpl));
524 ret.p = reinterpret_cast<intptr_t>(SectionTable + Header->NumberOfSections);
525 return section_iterator(SectionRef(ret, this));
528 uint8_t COFFObjectFile::getBytesInAddress() const {
529 return getArch() == Triple::x86_64 ? 8 : 4;
532 StringRef COFFObjectFile::getFileFormatName() const {
533 switch(Header->Machine) {
534 case COFF::IMAGE_FILE_MACHINE_I386:
536 case COFF::IMAGE_FILE_MACHINE_AMD64:
537 return "COFF-x86-64";
539 return "COFF-<unknown arch>";
543 unsigned COFFObjectFile::getArch() const {
544 switch(Header->Machine) {
545 case COFF::IMAGE_FILE_MACHINE_I386:
547 case COFF::IMAGE_FILE_MACHINE_AMD64:
548 return Triple::x86_64;
550 return Triple::UnknownArch;
554 error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const {
556 return object_error::success;
559 error_code COFFObjectFile::getSection(int32_t index,
560 const coff_section *&Result) const {
561 // Check for special index values.
562 if (index == COFF::IMAGE_SYM_UNDEFINED ||
563 index == COFF::IMAGE_SYM_ABSOLUTE ||
564 index == COFF::IMAGE_SYM_DEBUG)
566 else if (index > 0 && index <= Header->NumberOfSections)
567 // We already verified the section table data, so no need to check again.
568 Result = SectionTable + (index - 1);
570 return object_error::parse_failed;
571 return object_error::success;
574 error_code COFFObjectFile::getString(uint32_t offset,
575 StringRef &Result) const {
576 if (StringTableSize <= 4)
577 // Tried to get a string from an empty string table.
578 return object_error::parse_failed;
579 if (offset >= StringTableSize)
580 return object_error::unexpected_eof;
581 Result = StringRef(StringTable + offset);
582 return object_error::success;
585 error_code COFFObjectFile::getSymbol(uint32_t index,
586 const coff_symbol *&Result) const {
587 if (index < Header->NumberOfSymbols)
588 Result = SymbolTable + index;
590 return object_error::parse_failed;
591 return object_error::success;
594 error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
595 StringRef &Res) const {
596 // Check for string table entry. First 4 bytes are 0.
597 if (symbol->Name.Offset.Zeroes == 0) {
598 uint32_t Offset = symbol->Name.Offset.Offset;
599 if (error_code ec = getString(Offset, Res))
601 return object_error::success;
604 if (symbol->Name.ShortName[7] == 0)
605 // Null terminated, let ::strlen figure out the length.
606 Res = StringRef(symbol->Name.ShortName);
608 // Not null terminated, use all 8 bytes.
609 Res = StringRef(symbol->Name.ShortName, 8);
610 return object_error::success;
613 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
614 return reinterpret_cast<const coff_relocation*>(Rel.p);
616 error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
617 RelocationRef &Res) const {
618 Rel.p = reinterpret_cast<uintptr_t>(
619 reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
620 Res = RelocationRef(Rel, this);
621 return object_error::success;
623 error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
624 uint64_t &Res) const {
625 Res = toRel(Rel)->VirtualAddress;
626 return object_error::success;
628 error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel,
629 uint64_t &Res) const {
630 Res = toRel(Rel)->VirtualAddress;
631 return object_error::success;
633 error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel,
634 SymbolRef &Res) const {
635 const coff_relocation* R = toRel(Rel);
637 std::memset(&Symb, 0, sizeof(Symb));
638 Symb.p = reinterpret_cast<uintptr_t>(SymbolTable + R->SymbolTableIndex);
639 Res = SymbolRef(Symb, this);
640 return object_error::success;
642 error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
643 uint64_t &Res) const {
644 const coff_relocation* R = toRel(Rel);
646 return object_error::success;
649 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
650 case COFF::enum: res = #enum; break;
652 error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
653 SmallVectorImpl<char> &Result) const {
654 const coff_relocation *reloc = toRel(Rel);
656 switch (Header->Machine) {
657 case COFF::IMAGE_FILE_MACHINE_AMD64:
658 switch (reloc->Type) {
659 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ABSOLUTE);
660 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR64);
661 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32);
662 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32NB);
663 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32);
664 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_1);
665 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_2);
666 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_3);
667 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_4);
668 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_5);
669 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECTION);
670 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL);
671 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL7);
672 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_TOKEN);
673 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SREL32);
674 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_PAIR);
675 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SSPAN32);
680 case COFF::IMAGE_FILE_MACHINE_I386:
681 switch (reloc->Type) {
682 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_ABSOLUTE);
683 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR16);
684 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL16);
685 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32);
686 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32NB);
687 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SEG12);
688 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECTION);
689 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL);
690 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_TOKEN);
691 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL7);
692 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL32);
700 Result.append(res.begin(), res.end());
701 return object_error::success;
704 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
706 error_code COFFObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
707 int64_t &Res) const {
709 return object_error::success;
711 error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel,
712 SmallVectorImpl<char> &Result) const {
713 const coff_relocation *reloc = toRel(Rel);
714 const coff_symbol *symb = 0;
715 if (error_code ec = getSymbol(reloc->SymbolTableIndex, symb)) return ec;
717 ::memset(&sym, 0, sizeof(sym));
718 sym.p = reinterpret_cast<uintptr_t>(symb);
720 if (error_code ec = getSymbolName(sym, symname)) return ec;
721 Result.append(symname.begin(), symname.end());
722 return object_error::success;
727 ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
729 return new COFFObjectFile(Object, ec);
732 } // end namespace llvm