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::isSymbolGlobal(DataRefImpl Symb,
163 bool &Result) const {
164 const coff_symbol *symb = toSymb(Symb);
165 Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL);
166 return object_error::success;
169 error_code COFFObjectFile::isSymbolWeak(DataRefImpl Symb,
170 bool &Result) const {
171 const coff_symbol *symb = toSymb(Symb);
172 Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL);
173 return object_error::success;
176 error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb,
177 uint64_t &Result) const {
178 // FIXME: Return the correct size. This requires looking at all the symbols
179 // in the same section as this symbol, and looking for either the next
180 // symbol, or the end of the section.
181 const coff_symbol *symb = toSymb(Symb);
182 const coff_section *Section = NULL;
183 if (error_code ec = getSection(symb->SectionNumber, Section))
186 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
188 if (Type == 'U' || Type == 'w')
189 Result = UnknownAddressOrSize;
191 Result = Section->SizeOfRawData - symb->Value;
194 return object_error::success;
197 error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb,
198 char &Result) const {
199 const coff_symbol *symb = toSymb(Symb);
201 if (error_code ec = getSymbolName(Symb, name))
203 char ret = StringSwitch<char>(name)
204 .StartsWith(".debug", 'N')
205 .StartsWith(".sxdata", 'N')
210 return object_error::success;
213 uint32_t Characteristics = 0;
214 if (symb->SectionNumber > 0) {
215 const coff_section *Section = NULL;
216 if (error_code ec = getSection(symb->SectionNumber, Section))
218 Characteristics = Section->Characteristics;
221 switch (symb->SectionNumber) {
222 case COFF::IMAGE_SYM_UNDEFINED:
223 // Check storage classes.
224 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) {
226 return object_error::success; // Don't do ::toupper.
227 } else if (symb->Value != 0) // Check for common symbols.
232 case COFF::IMAGE_SYM_ABSOLUTE:
235 case COFF::IMAGE_SYM_DEBUG:
239 // Check section type.
240 if (Characteristics & COFF::IMAGE_SCN_CNT_CODE)
242 else if ( Characteristics & COFF::IMAGE_SCN_MEM_READ
243 && ~Characteristics & COFF::IMAGE_SCN_MEM_WRITE) // Read only.
245 else if (Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
247 else if (Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
249 else if (Characteristics & COFF::IMAGE_SCN_LNK_INFO)
252 // Check for section symbol.
253 else if ( symb->StorageClass == COFF::IMAGE_SYM_CLASS_STATIC
258 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
259 ret = ::toupper(ret);
262 return object_error::success;
265 error_code COFFObjectFile::isSymbolInternal(DataRefImpl Symb,
266 bool &Result) const {
268 return object_error::success;
271 error_code COFFObjectFile::isSymbolAbsolute(DataRefImpl Symb,
272 bool &Result) const {
273 const coff_symbol *symb = toSymb(Symb);
274 Result = symb->SectionNumber == COFF::IMAGE_SYM_ABSOLUTE;
275 return object_error::success;
278 error_code COFFObjectFile::getSymbolSection(DataRefImpl Symb,
279 section_iterator &Result) const {
280 const coff_symbol *symb = toSymb(Symb);
281 if (symb->SectionNumber <= COFF::IMAGE_SYM_UNDEFINED)
282 Result = end_sections();
284 const coff_section *sec = 0;
285 if (error_code ec = getSection(symb->SectionNumber, sec)) return ec;
287 std::memset(&Sec, 0, sizeof(Sec));
288 Sec.p = reinterpret_cast<uintptr_t>(sec);
289 Result = section_iterator(SectionRef(Sec, this));
291 return object_error::success;
294 error_code COFFObjectFile::getSectionNext(DataRefImpl Sec,
295 SectionRef &Result) const {
296 const coff_section *sec = toSec(Sec);
298 Sec.p = reinterpret_cast<uintptr_t>(sec);
299 Result = SectionRef(Sec, this);
300 return object_error::success;
303 error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
304 StringRef &Result) const {
305 const coff_section *sec = toSec(Sec);
307 if (sec->Name[7] == 0)
308 // Null terminated, let ::strlen figure out the length.
311 // Not null terminated, use all 8 bytes.
312 name = StringRef(sec->Name, 8);
314 // Check for string table entry. First byte is '/'.
315 if (name[0] == '/') {
317 name.substr(1).getAsInteger(10, Offset);
318 if (error_code ec = getString(Offset, name))
323 return object_error::success;
326 error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
327 uint64_t &Result) const {
328 const coff_section *sec = toSec(Sec);
329 Result = sec->VirtualAddress;
330 return object_error::success;
333 error_code COFFObjectFile::getSectionSize(DataRefImpl Sec,
334 uint64_t &Result) const {
335 const coff_section *sec = toSec(Sec);
336 Result = sec->SizeOfRawData;
337 return object_error::success;
340 error_code COFFObjectFile::getSectionContents(DataRefImpl Sec,
341 StringRef &Result) const {
342 const coff_section *sec = toSec(Sec);
343 // The only thing that we need to verify is that the contents is contained
344 // within the file bounds. We don't need to make sure it doesn't cover other
345 // data, as there's nothing that says that is not allowed.
346 uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData;
347 uintptr_t con_end = con_start + sec->SizeOfRawData;
348 if (con_end > uintptr_t(Data->getBufferEnd()))
349 return object_error::parse_failed;
350 Result = StringRef(reinterpret_cast<const char*>(con_start),
352 return object_error::success;
355 error_code COFFObjectFile::getSectionAlignment(DataRefImpl Sec,
356 uint64_t &Res) const {
357 const coff_section *sec = toSec(Sec);
359 return object_error::parse_failed;
360 Res = uint64_t(1) << (((sec->Characteristics & 0x00F00000) >> 20) - 1);
361 return object_error::success;
364 error_code COFFObjectFile::isSectionText(DataRefImpl Sec,
365 bool &Result) const {
366 const coff_section *sec = toSec(Sec);
367 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE;
368 return object_error::success;
371 error_code COFFObjectFile::isSectionData(DataRefImpl Sec,
372 bool &Result) const {
373 const coff_section *sec = toSec(Sec);
374 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
375 return object_error::success;
378 error_code COFFObjectFile::isSectionBSS(DataRefImpl Sec,
379 bool &Result) const {
380 const coff_section *sec = toSec(Sec);
381 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
382 return object_error::success;
385 error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
387 bool &Result) const {
388 const coff_section *sec = toSec(Sec);
389 const coff_symbol *symb = toSymb(Symb);
390 const coff_section *symb_sec = 0;
391 if (error_code ec = getSection(symb->SectionNumber, symb_sec)) return ec;
396 return object_error::success;
399 relocation_iterator COFFObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
400 const coff_section *sec = toSec(Sec);
402 std::memset(&ret, 0, sizeof(ret));
403 if (sec->NumberOfRelocations == 0)
406 ret.p = reinterpret_cast<uintptr_t>(base() + sec->PointerToRelocations);
408 return relocation_iterator(RelocationRef(ret, this));
411 relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
412 const coff_section *sec = toSec(Sec);
414 std::memset(&ret, 0, sizeof(ret));
415 if (sec->NumberOfRelocations == 0)
418 ret.p = reinterpret_cast<uintptr_t>(
419 reinterpret_cast<const coff_relocation*>(
420 base() + sec->PointerToRelocations)
421 + sec->NumberOfRelocations);
423 return relocation_iterator(RelocationRef(ret, this));
426 COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
427 : ObjectFile(Binary::isCOFF, Object, ec)
432 , StringTableSize(0) {
433 // Check that we at least have enough room for a header.
434 if (!checkSize(Data, ec, sizeof(coff_file_header))) return;
436 // The actual starting location of the COFF header in the file. This can be
437 // non-zero in PE/COFF files.
438 uint64_t HeaderStart = 0;
440 // Check if this is a PE/COFF file.
441 if (base()[0] == 0x4d && base()[1] == 0x5a) {
442 // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
443 // PE signature to find 'normal' COFF header.
444 if (!checkSize(Data, ec, 0x3c + 8)) return;
445 HeaderStart = *reinterpret_cast<const ulittle16_t *>(base() + 0x3c);
446 // Check the PE header. ("PE\0\0")
447 if (std::memcmp(base() + HeaderStart, "PE\0\0", 4) != 0) {
448 ec = object_error::parse_failed;
451 HeaderStart += 4; // Skip the PE Header.
454 Header = reinterpret_cast<const coff_file_header *>(base() + HeaderStart);
455 if (!checkAddr(Data, ec, uintptr_t(Header), sizeof(coff_file_header)))
459 reinterpret_cast<const coff_section *>( base()
461 + sizeof(coff_file_header)
462 + Header->SizeOfOptionalHeader);
463 if (!checkAddr(Data, ec, uintptr_t(SectionTable),
464 Header->NumberOfSections * sizeof(coff_section)))
467 if (Header->PointerToSymbolTable != 0) {
469 reinterpret_cast<const coff_symbol *>(base()
470 + Header->PointerToSymbolTable);
471 if (!checkAddr(Data, ec, uintptr_t(SymbolTable),
472 Header->NumberOfSymbols * sizeof(coff_symbol)))
475 // Find string table.
476 StringTable = reinterpret_cast<const char *>(base())
477 + Header->PointerToSymbolTable
478 + Header->NumberOfSymbols * sizeof(coff_symbol);
479 if (!checkAddr(Data, ec, uintptr_t(StringTable), sizeof(ulittle32_t)))
482 StringTableSize = *reinterpret_cast<const ulittle32_t *>(StringTable);
483 if (!checkAddr(Data, ec, uintptr_t(StringTable), StringTableSize))
485 // Check that the string table is null terminated if has any in it.
486 if (StringTableSize < 4
487 || (StringTableSize > 4 && StringTable[StringTableSize - 1] != 0)) {
488 ec = object_error::parse_failed;
493 ec = object_error::success;
496 symbol_iterator COFFObjectFile::begin_symbols() const {
498 std::memset(&ret, 0, sizeof(DataRefImpl));
499 ret.p = reinterpret_cast<intptr_t>(SymbolTable);
500 return symbol_iterator(SymbolRef(ret, this));
503 symbol_iterator COFFObjectFile::end_symbols() const {
504 // The symbol table ends where the string table begins.
506 std::memset(&ret, 0, sizeof(DataRefImpl));
507 ret.p = reinterpret_cast<intptr_t>(StringTable);
508 return symbol_iterator(SymbolRef(ret, this));
511 symbol_iterator COFFObjectFile::begin_dynamic_symbols() const {
513 report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
516 symbol_iterator COFFObjectFile::end_dynamic_symbols() const {
518 report_fatal_error("Dynamic symbols unimplemented in COFFObjectFile");
521 section_iterator COFFObjectFile::begin_sections() const {
523 std::memset(&ret, 0, sizeof(DataRefImpl));
524 ret.p = reinterpret_cast<intptr_t>(SectionTable);
525 return section_iterator(SectionRef(ret, this));
528 section_iterator COFFObjectFile::end_sections() const {
530 std::memset(&ret, 0, sizeof(DataRefImpl));
531 ret.p = reinterpret_cast<intptr_t>(SectionTable + Header->NumberOfSections);
532 return section_iterator(SectionRef(ret, this));
535 uint8_t COFFObjectFile::getBytesInAddress() const {
536 return getArch() == Triple::x86_64 ? 8 : 4;
539 StringRef COFFObjectFile::getFileFormatName() const {
540 switch(Header->Machine) {
541 case COFF::IMAGE_FILE_MACHINE_I386:
543 case COFF::IMAGE_FILE_MACHINE_AMD64:
544 return "COFF-x86-64";
546 return "COFF-<unknown arch>";
550 unsigned COFFObjectFile::getArch() const {
551 switch(Header->Machine) {
552 case COFF::IMAGE_FILE_MACHINE_I386:
554 case COFF::IMAGE_FILE_MACHINE_AMD64:
555 return Triple::x86_64;
557 return Triple::UnknownArch;
561 error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const {
563 return object_error::success;
566 error_code COFFObjectFile::getSection(int32_t index,
567 const coff_section *&Result) const {
568 // Check for special index values.
569 if (index == COFF::IMAGE_SYM_UNDEFINED ||
570 index == COFF::IMAGE_SYM_ABSOLUTE ||
571 index == COFF::IMAGE_SYM_DEBUG)
573 else if (index > 0 && index <= Header->NumberOfSections)
574 // We already verified the section table data, so no need to check again.
575 Result = SectionTable + (index - 1);
577 return object_error::parse_failed;
578 return object_error::success;
581 error_code COFFObjectFile::getString(uint32_t offset,
582 StringRef &Result) const {
583 if (StringTableSize <= 4)
584 // Tried to get a string from an empty string table.
585 return object_error::parse_failed;
586 if (offset >= StringTableSize)
587 return object_error::unexpected_eof;
588 Result = StringRef(StringTable + offset);
589 return object_error::success;
592 error_code COFFObjectFile::getSymbol(uint32_t index,
593 const coff_symbol *&Result) const {
594 if (index < Header->NumberOfSymbols)
595 Result = SymbolTable + index;
597 return object_error::parse_failed;
598 return object_error::success;
601 error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
602 StringRef &Res) const {
603 // Check for string table entry. First 4 bytes are 0.
604 if (symbol->Name.Offset.Zeroes == 0) {
605 uint32_t Offset = symbol->Name.Offset.Offset;
606 if (error_code ec = getString(Offset, Res))
608 return object_error::success;
611 if (symbol->Name.ShortName[7] == 0)
612 // Null terminated, let ::strlen figure out the length.
613 Res = StringRef(symbol->Name.ShortName);
615 // Not null terminated, use all 8 bytes.
616 Res = StringRef(symbol->Name.ShortName, 8);
617 return object_error::success;
620 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
621 return reinterpret_cast<const coff_relocation*>(Rel.p);
623 error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
624 RelocationRef &Res) const {
625 Rel.p = reinterpret_cast<uintptr_t>(
626 reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
627 Res = RelocationRef(Rel, this);
628 return object_error::success;
630 error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
631 uint64_t &Res) const {
632 Res = toRel(Rel)->VirtualAddress;
633 return object_error::success;
635 error_code COFFObjectFile::getRelocationOffset(DataRefImpl Rel,
636 uint64_t &Res) const {
637 Res = toRel(Rel)->VirtualAddress;
638 return object_error::success;
640 error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel,
641 SymbolRef &Res) const {
642 const coff_relocation* R = toRel(Rel);
644 std::memset(&Symb, 0, sizeof(Symb));
645 Symb.p = reinterpret_cast<uintptr_t>(SymbolTable + R->SymbolTableIndex);
646 Res = SymbolRef(Symb, this);
647 return object_error::success;
649 error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
650 uint64_t &Res) const {
651 const coff_relocation* R = toRel(Rel);
653 return object_error::success;
656 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
657 case COFF::enum: res = #enum; break;
659 error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
660 SmallVectorImpl<char> &Result) const {
661 const coff_relocation *reloc = toRel(Rel);
663 switch (Header->Machine) {
664 case COFF::IMAGE_FILE_MACHINE_AMD64:
665 switch (reloc->Type) {
666 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ABSOLUTE);
667 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR64);
668 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32);
669 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32NB);
670 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32);
671 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_1);
672 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_2);
673 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_3);
674 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_4);
675 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_5);
676 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECTION);
677 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL);
678 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL7);
679 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_TOKEN);
680 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SREL32);
681 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_PAIR);
682 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SSPAN32);
687 case COFF::IMAGE_FILE_MACHINE_I386:
688 switch (reloc->Type) {
689 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_ABSOLUTE);
690 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR16);
691 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL16);
692 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32);
693 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32NB);
694 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SEG12);
695 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECTION);
696 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL);
697 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_TOKEN);
698 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL7);
699 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL32);
707 Result.append(res.begin(), res.end());
708 return object_error::success;
711 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
713 error_code COFFObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
714 int64_t &Res) const {
716 return object_error::success;
718 error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel,
719 SmallVectorImpl<char> &Result) const {
720 const coff_relocation *reloc = toRel(Rel);
721 const coff_symbol *symb = 0;
722 if (error_code ec = getSymbol(reloc->SymbolTableIndex, symb)) return ec;
724 ::memset(&sym, 0, sizeof(sym));
725 sym.p = reinterpret_cast<uintptr_t>(symb);
727 if (error_code ec = getSymbolName(sym, symname)) return ec;
728 Result.append(symname.begin(), symname.end());
729 return object_error::success;
734 ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
736 return new COFFObjectFile(Object, ec);
739 } // end namespace llvm