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_Unknown;
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: Correctly set SF_FormatSpecific, SF_ThreadLocal, SF_Common
169 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
170 symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED)
171 Result |= SymbolRef::SF_Undefined;
173 // TODO: This are certainly too restrictive.
174 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
175 Result |= SymbolRef::SF_Global;
177 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL)
178 Result |= SymbolRef::SF_Weak;
180 if (symb->SectionNumber == COFF::IMAGE_SYM_ABSOLUTE)
181 Result |= SymbolRef::SF_Absolute;
183 return object_error::success;
186 error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb,
187 uint64_t &Result) const {
188 // FIXME: Return the correct size. This requires looking at all the symbols
189 // in the same section as this symbol, and looking for either the next
190 // symbol, or the end of the section.
191 const coff_symbol *symb = toSymb(Symb);
192 const coff_section *Section = NULL;
193 if (error_code ec = getSection(symb->SectionNumber, Section))
196 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
198 if (Type == 'U' || Type == 'w')
199 Result = UnknownAddressOrSize;
201 Result = Section->SizeOfRawData - symb->Value;
204 return object_error::success;
207 error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb,
208 char &Result) const {
209 const coff_symbol *symb = toSymb(Symb);
211 if (error_code ec = getSymbolName(Symb, name))
213 char ret = StringSwitch<char>(name)
214 .StartsWith(".debug", 'N')
215 .StartsWith(".sxdata", 'N')
220 return object_error::success;
223 uint32_t Characteristics = 0;
224 if (symb->SectionNumber > 0) {
225 const coff_section *Section = NULL;
226 if (error_code ec = getSection(symb->SectionNumber, Section))
228 Characteristics = Section->Characteristics;
231 switch (symb->SectionNumber) {
232 case COFF::IMAGE_SYM_UNDEFINED:
233 // Check storage classes.
234 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) {
236 return object_error::success; // Don't do ::toupper.
237 } else if (symb->Value != 0) // Check for common symbols.
242 case COFF::IMAGE_SYM_ABSOLUTE:
245 case COFF::IMAGE_SYM_DEBUG:
249 // Check section type.
250 if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
252 else if ( Characteristics & COFF::IMAGE_SCN_MEM_READ
253 && ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
255 else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
257 else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
259 else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO)
262 // Check for section symbol.
263 else if ( symb->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC
268 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
269 ret = ::toupper(ret);
272 return object_error::success;
275 error_code COFFObjectFile::getSymbolSection(DataRefImpl Symb,
276 section_iterator &Result) const {
277 const coff_symbol *symb = toSymb(Symb);
278 if (symb->SectionNumber <= COFF::IMAGE_SYM_UNDEFINED)
279 Result = end_sections();
281 const coff_section *sec = 0;
282 if (error_code ec = getSection(symb->SectionNumber, sec)) return ec;
284 std::memset(&Sec, 0, sizeof(Sec));
285 Sec.p = reinterpret_cast<uintptr_t>(sec);
286 Result = section_iterator(SectionRef(Sec, this));
288 return object_error::success;
291 error_code COFFObjectFile::getSectionNext(DataRefImpl Sec,
292 SectionRef &Result) const {
293 const coff_section *sec = toSec(Sec);
295 Sec.p = reinterpret_cast<uintptr_t>(sec);
296 Result = SectionRef(Sec, this);
297 return object_error::success;
300 error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
301 StringRef &Result) const {
302 const coff_section *sec = toSec(Sec);
303 return getSectionName(sec, Result);
306 error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
307 uint64_t &Result) const {
308 const coff_section *sec = toSec(Sec);
309 Result = sec->VirtualAddress;
310 return object_error::success;
313 error_code COFFObjectFile::getSectionSize(DataRefImpl Sec,
314 uint64_t &Result) const {
315 const coff_section *sec = toSec(Sec);
316 Result = sec->SizeOfRawData;
317 return object_error::success;
320 error_code COFFObjectFile::getSectionContents(DataRefImpl Sec,
321 StringRef &Result) const {
322 const coff_section *sec = toSec(Sec);
323 // The only thing that we need to verify is that the contents is contained
324 // within the file bounds. We don't need to make sure it doesn't cover other
325 // data, as there's nothing that says that is not allowed.
326 uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData;
327 uintptr_t con_end = con_start + sec->SizeOfRawData;
328 if (con_end > uintptr_t(Data->getBufferEnd()))
329 return object_error::parse_failed;
330 Result = StringRef(reinterpret_cast<const char*>(con_start),
332 return object_error::success;
335 error_code COFFObjectFile::getSectionAlignment(DataRefImpl Sec,
336 uint64_t &Res) const {
337 const coff_section *sec = toSec(Sec);
339 return object_error::parse_failed;
340 Res = uint64_t(1) << (((sec->Characteristics & 0x00F00000) >> 20) - 1);
341 return object_error::success;
344 error_code COFFObjectFile::isSectionText(DataRefImpl Sec,
345 bool &Result) const {
346 const coff_section *sec = toSec(Sec);
347 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE;
348 return object_error::success;
351 error_code COFFObjectFile::isSectionData(DataRefImpl Sec,
352 bool &Result) const {
353 const coff_section *sec = toSec(Sec);
354 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
355 return object_error::success;
358 error_code COFFObjectFile::isSectionBSS(DataRefImpl Sec,
359 bool &Result) const {
360 const coff_section *sec = toSec(Sec);
361 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
362 return object_error::success;
365 error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
367 bool &Result) const {
368 const coff_section *sec = toSec(Sec);
369 const coff_symbol *symb = toSymb(Symb);
370 const coff_section *symb_sec = 0;
371 if (error_code ec = getSection(symb->SectionNumber, symb_sec)) return ec;
376 return object_error::success;
379 relocation_iterator COFFObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
380 const coff_section *sec = toSec(Sec);
382 std::memset(&ret, 0, sizeof(ret));
383 if (sec->NumberOfRelocations == 0)
386 ret.p = reinterpret_cast<uintptr_t>(base() + sec->PointerToRelocations);
388 return relocation_iterator(RelocationRef(ret, this));
391 relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
392 const coff_section *sec = toSec(Sec);
394 std::memset(&ret, 0, sizeof(ret));
395 if (sec->NumberOfRelocations == 0)
398 ret.p = reinterpret_cast<uintptr_t>(
399 reinterpret_cast<const coff_relocation*>(
400 base() + sec->PointerToRelocations)
401 + sec->NumberOfRelocations);
403 return relocation_iterator(RelocationRef(ret, this));
406 COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
407 : ObjectFile(Binary::ID_COFF, Object, ec)
412 , StringTableSize(0) {
413 // Check that we at least have enough room for a header.
414 if (!checkSize(Data, ec, sizeof(coff_file_header))) return;
416 // The actual starting location of the COFF header in the file. This can be
417 // non-zero in PE/COFF files.
418 uint64_t HeaderStart = 0;
420 // Check if this is a PE/COFF file.
421 if (base()[0] == 0x4d && base()[1] == 0x5a) {
422 // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
423 // PE signature to find 'normal' COFF header.
424 if (!checkSize(Data, ec, 0x3c + 8)) return;
425 HeaderStart = *reinterpret_cast<const ulittle16_t *>(base() + 0x3c);
426 // Check the PE header. ("PE\0\0")
427 if (std::memcmp(base() + HeaderStart, "PE\0\0", 4) != 0) {
428 ec = object_error::parse_failed;
431 HeaderStart += 4; // Skip the PE Header.
434 Header = reinterpret_cast<const coff_file_header *>(base() + HeaderStart);
435 if (!checkAddr(Data, ec, uintptr_t(Header), sizeof(coff_file_header)))
439 reinterpret_cast<const coff_section *>( base()
441 + sizeof(coff_file_header)
442 + Header->SizeOfOptionalHeader);
443 if (!checkAddr(Data, ec, uintptr_t(SectionTable),
444 Header->NumberOfSections * sizeof(coff_section)))
447 if (Header->PointerToSymbolTable != 0) {
449 reinterpret_cast<const coff_symbol *>(base()
450 + Header->PointerToSymbolTable);
451 if (!checkAddr(Data, ec, uintptr_t(SymbolTable),
452 Header->NumberOfSymbols * sizeof(coff_symbol)))
455 // Find string table.
456 StringTable = reinterpret_cast<const char *>(base())
457 + Header->PointerToSymbolTable
458 + Header->NumberOfSymbols * sizeof(coff_symbol);
459 if (!checkAddr(Data, ec, uintptr_t(StringTable), sizeof(ulittle32_t)))
462 StringTableSize = *reinterpret_cast<const ulittle32_t *>(StringTable);
463 if (!checkAddr(Data, ec, uintptr_t(StringTable), StringTableSize))
465 // Check that the string table is null terminated if has any in it.
466 if (StringTableSize < 4
467 || (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) {
468 ec = object_error::parse_failed;
473 ec = object_error::success;
476 symbol_iterator COFFObjectFile::begin_symbols() const {
478 std::memset(&ret, 0, sizeof(DataRefImpl));
479 ret.p = reinterpret_cast<intptr_t>(SymbolTable);
480 return symbol_iterator(SymbolRef(ret, this));
483 symbol_iterator COFFObjectFile::end_symbols() const {
484 // The symbol table ends where the string table begins.
486 std::memset(&ret, 0, sizeof(DataRefImpl));
487 ret.p = reinterpret_cast<intptr_t>(StringTable);
488 return symbol_iterator(SymbolRef(ret, this));
491 symbol_iterator COFFObjectFile::begin_dynamic_symbols() const {
493 report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
496 symbol_iterator COFFObjectFile::end_dynamic_symbols() const {
498 report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
501 library_iterator COFFObjectFile::begin_libraries_needed() const {
503 report_fatal_error("Libraries needed unimplemented in COFFObjectFile");
506 library_iterator COFFObjectFile::end_libraries_needed() const {
508 report_fatal_error("Libraries needed unimplemented in COFFObjectFile");
511 StringRef COFFObjectFile::getLoadName() const {
512 // COFF does not have this field.
517 section_iterator COFFObjectFile::begin_sections() const {
519 std::memset(&ret, 0, sizeof(DataRefImpl));
520 ret.p = reinterpret_cast<intptr_t>(SectionTable);
521 return section_iterator(SectionRef(ret, this));
524 section_iterator COFFObjectFile::end_sections() const {
526 std::memset(&ret, 0, sizeof(DataRefImpl));
527 ret.p = reinterpret_cast<intptr_t>(SectionTable + Header->NumberOfSections);
528 return section_iterator(SectionRef(ret, this));
531 uint8_t COFFObjectFile::getBytesInAddress() const {
532 return getArch() == Triple::x86_64 ? 8 : 4;
535 StringRef COFFObjectFile::getFileFormatName() const {
536 switch(Header->Machine) {
537 case COFF::IMAGE_FILE_MACHINE_I386:
539 case COFF::IMAGE_FILE_MACHINE_AMD64:
540 return "COFF-x86-64";
542 return "COFF-<unknown arch>";
546 unsigned COFFObjectFile::getArch() const {
547 switch(Header->Machine) {
548 case COFF::IMAGE_FILE_MACHINE_I386:
550 case COFF::IMAGE_FILE_MACHINE_AMD64:
551 return Triple::x86_64;
553 return Triple::UnknownArch;
557 error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const {
559 return object_error::success;
562 error_code COFFObjectFile::getSection(int32_t index,
563 const coff_section *&Result) const {
564 // Check for special index values.
565 if (index == COFF::IMAGE_SYM_UNDEFINED ||
566 index == COFF::IMAGE_SYM_ABSOLUTE ||
567 index == COFF::IMAGE_SYM_DEBUG)
569 else if (index > 0 && index <= Header->NumberOfSections)
570 // We already verified the section table data, so no need to check again.
571 Result = SectionTable + (index - 1);
573 return object_error::parse_failed;
574 return object_error::success;
577 error_code COFFObjectFile::getString(uint32_t offset,
578 StringRef &Result) const {
579 if (StringTableSize <= 4)
580 // Tried to get a string from an empty string table.
581 return object_error::parse_failed;
582 if (offset >= StringTableSize)
583 return object_error::unexpected_eof;
584 Result = StringRef(StringTable + offset);
585 return object_error::success;
588 error_code COFFObjectFile::getSymbol(uint32_t index,
589 const coff_symbol *&Result) const {
590 if (index < Header->NumberOfSymbols)
591 Result = SymbolTable + index;
593 return object_error::parse_failed;
594 return object_error::success;
597 error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
598 StringRef &Res) const {
599 // Check for string table entry. First 4 bytes are 0.
600 if (symbol->Name.Offset.Zeroes == 0) {
601 uint32_t Offset = symbol->Name.Offset.Offset;
602 if (error_code ec = getString(Offset, Res))
604 return object_error::success;
607 if (symbol->Name.ShortName[7] == 0)
608 // Null terminated, let ::strlen figure out the length.
609 Res = StringRef(symbol->Name.ShortName);
611 // Not null terminated, use all 8 bytes.
612 Res = StringRef(symbol->Name.ShortName, 8);
613 return object_error::success;
616 error_code COFFObjectFile::getSectionName(const coff_section *Sec,
617 StringRef &Res) const {
619 if (Sec->Name[7] == 0)
620 // Null terminated, let ::strlen figure out the length.
623 // Not null terminated, use all 8 bytes.
624 Name = StringRef(Sec->Name, 8);
626 // Check for string table entry. First byte is '/'.
627 if (Name[0] == '/') {
629 if (Name.substr(1).getAsInteger(10, Offset))
630 return object_error::parse_failed;
631 if (error_code ec = getString(Offset, Name))
636 return object_error::success;
639 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
640 return reinterpret_cast<const coff_relocation*>(Rel.p);
642 error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
643 RelocationRef &Res) const {
644 Rel.p = reinterpret_cast<uintptr_t>(
645 reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
646 Res = RelocationRef(Rel, this);
647 return object_error::success;
649 error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
650 uint64_t &Res) const {
651 Res = toRel(Rel)->VirtualAddress;
652 return object_error::success;
654 error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel,
655 uint64_t &Res) const {
656 Res = toRel(Rel)->VirtualAddress;
657 return object_error::success;
659 error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel,
660 SymbolRef &Res) const {
661 const coff_relocation* R = toRel(Rel);
663 std::memset(&Symb, 0, sizeof(Symb));
664 Symb.p = reinterpret_cast<uintptr_t>(SymbolTable + R->SymbolTableIndex);
665 Res = SymbolRef(Symb, this);
666 return object_error::success;
668 error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
669 uint64_t &Res) const {
670 const coff_relocation* R = toRel(Rel);
672 return object_error::success;
675 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
676 case COFF::enum: res = #enum; break;
678 error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
679 SmallVectorImpl<char> &Result) const {
680 const coff_relocation *reloc = toRel(Rel);
682 switch (Header->Machine) {
683 case COFF::IMAGE_FILE_MACHINE_AMD64:
684 switch (reloc->Type) {
685 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ABSOLUTE);
686 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR64);
687 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32);
688 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32NB);
689 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32);
690 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_1);
691 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_2);
692 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_3);
693 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_4);
694 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_5);
695 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECTION);
696 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL);
697 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL7);
698 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_TOKEN);
699 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SREL32);
700 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_PAIR);
701 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SSPAN32);
706 case COFF::IMAGE_FILE_MACHINE_I386:
707 switch (reloc->Type) {
708 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_ABSOLUTE);
709 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR16);
710 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL16);
711 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32);
712 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32NB);
713 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SEG12);
714 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECTION);
715 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL);
716 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_TOKEN);
717 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL7);
718 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL32);
726 Result.append(res.begin(), res.end());
727 return object_error::success;
730 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
732 error_code COFFObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
733 int64_t &Res) const {
735 return object_error::success;
737 error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel,
738 SmallVectorImpl<char> &Result) const {
739 const coff_relocation *reloc = toRel(Rel);
740 const coff_symbol *symb = 0;
741 if (error_code ec = getSymbol(reloc->SymbolTableIndex, symb)) return ec;
743 ::memset(&sym, 0, sizeof(sym));
744 sym.p = reinterpret_cast<uintptr_t>(symb);
746 if (error_code ec = getSymbolName(sym, symname)) return ec;
747 Result.append(symname.begin(), symname.end());
748 return object_error::success;
751 error_code COFFObjectFile::getLibraryNext(DataRefImpl LibData,
752 LibraryRef &Result) const {
753 report_fatal_error("getLibraryNext not implemented in COFFObjectFile");
756 error_code COFFObjectFile::getLibraryPath(DataRefImpl LibData,
757 StringRef &Result) const {
758 report_fatal_error("getLibraryPath not implemented in COFFObjectFile");
763 ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
765 return new COFFObjectFile(Object, ec);
768 } // end namespace llvm