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::getSymbolOffset(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->VirtualAddress + 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 = reinterpret_cast<uintptr_t>(base() +
135 Section->PointerToRawData +
138 Result = reinterpret_cast<uintptr_t>(base() + symb->Value);
139 return object_error::success;
142 error_code COFFObjectFile::getSymbolType(DataRefImpl Symb,
143 SymbolRef::Type &Result) const {
144 const coff_symbol *symb = toSymb(Symb);
145 Result = SymbolRef::ST_Other;
146 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
147 symb->SectionNumber == COFF::IMAGE_SYM_UNDEFINED) {
148 Result = SymbolRef::ST_External;
150 if (symb->Type.ComplexType == COFF::IMAGE_SYM_DTYPE_FUNCTION) {
151 Result = SymbolRef::ST_Function;
154 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
156 if (Type == 'r' || Type == 'R') {
157 Result = SymbolRef::ST_Data;
161 return object_error::success;
164 error_code COFFObjectFile::isSymbolGlobal(DataRefImpl Symb,
165 bool &Result) const {
166 const coff_symbol *symb = toSymb(Symb);
167 Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL);
168 return object_error::success;
171 error_code COFFObjectFile::isSymbolWeak(DataRefImpl Symb,
172 bool &Result) const {
173 const coff_symbol *symb = toSymb(Symb);
174 Result = (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL);
175 return object_error::success;
178 error_code COFFObjectFile::getSymbolSize(DataRefImpl Symb,
179 uint64_t &Result) const {
180 // FIXME: Return the correct size. This requires looking at all the symbols
181 // in the same section as this symbol, and looking for either the next
182 // symbol, or the end of the section.
183 const coff_symbol *symb = toSymb(Symb);
184 const coff_section *Section = NULL;
185 if (error_code ec = getSection(symb->SectionNumber, Section))
188 if (error_code ec = getSymbolNMTypeChar(Symb, Type))
190 if (Type == 'U' || Type == 'w')
191 Result = UnknownAddressOrSize;
193 Result = Section->SizeOfRawData - symb->Value;
196 return object_error::success;
199 error_code COFFObjectFile::getSymbolNMTypeChar(DataRefImpl Symb,
200 char &Result) const {
201 const coff_symbol *symb = toSymb(Symb);
203 if (error_code ec = getSymbolName(Symb, name))
205 char ret = StringSwitch<char>(name)
206 .StartsWith(".debug", 'N')
207 .StartsWith(".sxdata", 'N')
212 return object_error::success;
215 uint32_t Characteristics = 0;
216 if (symb->SectionNumber > 0) {
217 const coff_section *Section = NULL;
218 if (error_code ec = getSection(symb->SectionNumber, Section))
220 Characteristics = Section->Characteristics;
223 switch (symb->SectionNumber) {
224 case COFF::IMAGE_SYM_UNDEFINED:
225 // Check storage classes.
226 if (symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) {
228 return object_error::success; // Don't do ::toupper.
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;
285 if (error_code ec = getSection(symb->SectionNumber, sec)) return ec;
287 Sec.p = reinterpret_cast<uintptr_t>(sec);
288 Result = section_iterator(SectionRef(Sec, this));
290 return object_error::success;
293 error_code COFFObjectFile::getSectionNext(DataRefImpl Sec,
294 SectionRef &Result) const {
295 const coff_section *sec = toSec(Sec);
297 Sec.p = reinterpret_cast<uintptr_t>(sec);
298 Result = SectionRef(Sec, this);
299 return object_error::success;
302 error_code COFFObjectFile::getSectionName(DataRefImpl Sec,
303 StringRef &Result) const {
304 const coff_section *sec = toSec(Sec);
306 if (sec->Name[7] == 0)
307 // Null terminated, let ::strlen figure out the length.
310 // Not null terminated, use all 8 bytes.
311 name = StringRef(sec->Name, 8);
313 // Check for string table entry. First byte is '/'.
314 if (name[0] == '/') {
316 name.substr(1).getAsInteger(10, Offset);
317 if (error_code ec = getString(Offset, name))
322 return object_error::success;
325 error_code COFFObjectFile::getSectionAddress(DataRefImpl Sec,
326 uint64_t &Result) const {
327 const coff_section *sec = toSec(Sec);
328 Result = sec->VirtualAddress;
329 return object_error::success;
332 error_code COFFObjectFile::getSectionSize(DataRefImpl Sec,
333 uint64_t &Result) const {
334 const coff_section *sec = toSec(Sec);
335 Result = sec->SizeOfRawData;
336 return object_error::success;
339 error_code COFFObjectFile::getSectionContents(DataRefImpl Sec,
340 StringRef &Result) const {
341 const coff_section *sec = toSec(Sec);
342 // The only thing that we need to verify is that the contents is contained
343 // within the file bounds. We don't need to make sure it doesn't cover other
344 // data, as there's nothing that says that is not allowed.
345 uintptr_t con_start = uintptr_t(base()) + sec->PointerToRawData;
346 uintptr_t con_end = con_start + sec->SizeOfRawData;
347 if (con_end >= uintptr_t(Data->getBufferEnd()))
348 return object_error::parse_failed;
349 Result = StringRef(reinterpret_cast<const char*>(con_start),
351 return object_error::success;
354 error_code COFFObjectFile::getSectionAlignment(DataRefImpl Sec,
355 uint64_t &Res) const {
356 const coff_section *sec = toSec(Sec);
358 return object_error::parse_failed;
359 Res = uint64_t(1) << (((sec->Characteristics & 0x00F00000) >> 20) - 1);
360 return object_error::success;
363 error_code COFFObjectFile::isSectionText(DataRefImpl Sec,
364 bool &Result) const {
365 const coff_section *sec = toSec(Sec);
366 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_CODE;
367 return object_error::success;
370 error_code COFFObjectFile::isSectionData(DataRefImpl Sec,
371 bool &Result) const {
372 const coff_section *sec = toSec(Sec);
373 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
374 return object_error::success;
377 error_code COFFObjectFile::isSectionBSS(DataRefImpl Sec,
378 bool &Result) const {
379 const coff_section *sec = toSec(Sec);
380 Result = sec->Characteristics & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
381 return object_error::success;
384 error_code COFFObjectFile::sectionContainsSymbol(DataRefImpl Sec,
386 bool &Result) const {
387 const coff_section *sec = toSec(Sec);
388 const coff_symbol *symb = toSymb(Symb);
389 const coff_section *symb_sec;
390 if (error_code ec = getSection(symb->SectionNumber, symb_sec)) return ec;
395 return object_error::success;
398 relocation_iterator COFFObjectFile::getSectionRelBegin(DataRefImpl Sec) const {
399 const coff_section *sec = toSec(Sec);
401 std::memset(&ret, 0, sizeof(ret));
402 if (sec->NumberOfRelocations == 0)
405 ret.p = reinterpret_cast<uintptr_t>(base() + sec->PointerToRelocations);
407 return relocation_iterator(RelocationRef(ret, this));
410 relocation_iterator COFFObjectFile::getSectionRelEnd(DataRefImpl Sec) const {
411 const coff_section *sec = toSec(Sec);
413 std::memset(&ret, 0, sizeof(ret));
414 if (sec->NumberOfRelocations == 0)
417 ret.p = reinterpret_cast<uintptr_t>(
418 reinterpret_cast<const coff_relocation*>(
419 base() + sec->PointerToRelocations)
420 + sec->NumberOfRelocations);
422 return relocation_iterator(RelocationRef(ret, this));
425 COFFObjectFile::COFFObjectFile(MemoryBuffer *Object, error_code &ec)
426 : ObjectFile(Binary::isCOFF, Object, ec) {
427 // Check that we at least have enough room for a header.
428 if (!checkSize(Data, ec, sizeof(coff_file_header))) return;
430 // The actual starting location of the COFF header in the file. This can be
431 // non-zero in PE/COFF files.
432 uint64_t HeaderStart = 0;
434 // Check if this is a PE/COFF file.
435 if (base()[0] == 0x4d && base()[1] == 0x5a) {
436 // PE/COFF, seek through MS-DOS compatibility stub and 4-byte
437 // PE signature to find 'normal' COFF header.
438 if (!checkSize(Data, ec, 0x3c + 8)) return;
439 HeaderStart += *reinterpret_cast<const ulittle32_t *>(base() + 0x3c);
440 // Check the PE header. ("PE\0\0")
441 if (std::memcmp(base() + HeaderStart, "PE\0\0", 4) != 0) {
442 ec = object_error::parse_failed;
445 HeaderStart += 4; // Skip the PE Header.
448 Header = reinterpret_cast<const coff_file_header *>(base() + HeaderStart);
449 if (!checkAddr(Data, ec, uintptr_t(Header), sizeof(coff_file_header)))
453 reinterpret_cast<const coff_section *>( base()
455 + sizeof(coff_file_header)
456 + Header->SizeOfOptionalHeader);
457 if (!checkAddr(Data, ec, uintptr_t(SectionTable),
458 Header->NumberOfSections * sizeof(coff_section)))
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;
485 ec = object_error::success;
488 symbol_iterator COFFObjectFile::begin_symbols() const {
490 std::memset(&ret, 0, sizeof(DataRefImpl));
491 ret.p = reinterpret_cast<intptr_t>(SymbolTable);
492 return symbol_iterator(SymbolRef(ret, this));
495 symbol_iterator COFFObjectFile::end_symbols() const {
496 // The symbol table ends where the string table begins.
498 std::memset(&ret, 0, sizeof(DataRefImpl));
499 ret.p = reinterpret_cast<intptr_t>(StringTable);
500 return symbol_iterator(SymbolRef(ret, this));
503 section_iterator COFFObjectFile::begin_sections() const {
505 std::memset(&ret, 0, sizeof(DataRefImpl));
506 ret.p = reinterpret_cast<intptr_t>(SectionTable);
507 return section_iterator(SectionRef(ret, this));
510 section_iterator COFFObjectFile::end_sections() const {
512 std::memset(&ret, 0, sizeof(DataRefImpl));
513 ret.p = reinterpret_cast<intptr_t>(SectionTable + Header->NumberOfSections);
514 return section_iterator(SectionRef(ret, this));
517 uint8_t COFFObjectFile::getBytesInAddress() const {
518 return getArch() == Triple::x86_64 ? 8 : 4;
521 StringRef COFFObjectFile::getFileFormatName() const {
522 switch(Header->Machine) {
523 case COFF::IMAGE_FILE_MACHINE_I386:
525 case COFF::IMAGE_FILE_MACHINE_AMD64:
526 return "COFF-x86-64";
528 return "COFF-<unknown arch>";
532 unsigned COFFObjectFile::getArch() const {
533 switch(Header->Machine) {
534 case COFF::IMAGE_FILE_MACHINE_I386:
536 case COFF::IMAGE_FILE_MACHINE_AMD64:
537 return Triple::x86_64;
539 return Triple::UnknownArch;
543 error_code COFFObjectFile::getHeader(const coff_file_header *&Res) const {
545 return object_error::success;
548 error_code COFFObjectFile::getSection(int32_t index,
549 const coff_section *&Result) const {
550 // Check for special index values.
551 if (index == COFF::IMAGE_SYM_UNDEFINED ||
552 index == COFF::IMAGE_SYM_ABSOLUTE ||
553 index == COFF::IMAGE_SYM_DEBUG)
555 else if (index > 0 && index <= Header->NumberOfSections)
556 // We already verified the section table data, so no need to check again.
557 Result = SectionTable + (index - 1);
559 return object_error::parse_failed;
560 return object_error::success;
563 error_code COFFObjectFile::getString(uint32_t offset,
564 StringRef &Result) const {
565 if (StringTableSize <= 4)
566 // Tried to get a string from an empty string table.
567 return object_error::parse_failed;
568 if (offset >= StringTableSize)
569 return object_error::unexpected_eof;
570 Result = StringRef(StringTable + offset);
571 return object_error::success;
574 error_code COFFObjectFile::getSymbol(uint32_t index,
575 const coff_symbol *&Result) const {
576 if (index >= 0 && index < Header->NumberOfSymbols)
577 Result = SymbolTable + index;
579 return object_error::parse_failed;
580 return object_error::success;
583 error_code COFFObjectFile::getSymbolName(const coff_symbol *symbol,
584 StringRef &Res) const {
585 // Check for string table entry. First 4 bytes are 0.
586 if (symbol->Name.Offset.Zeroes == 0) {
587 uint32_t Offset = symbol->Name.Offset.Offset;
588 if (error_code ec = getString(Offset, Res))
590 return object_error::success;
593 if (symbol->Name.ShortName[7] == 0)
594 // Null terminated, let ::strlen figure out the length.
595 Res = StringRef(symbol->Name.ShortName);
597 // Not null terminated, use all 8 bytes.
598 Res = StringRef(symbol->Name.ShortName, 8);
599 return object_error::success;
602 const coff_relocation *COFFObjectFile::toRel(DataRefImpl Rel) const {
603 return reinterpret_cast<const coff_relocation*>(Rel.p);
605 error_code COFFObjectFile::getRelocationNext(DataRefImpl Rel,
606 RelocationRef &Res) const {
607 Rel.p = reinterpret_cast<uintptr_t>(
608 reinterpret_cast<const coff_relocation*>(Rel.p) + 1);
609 Res = RelocationRef(Rel, this);
610 return object_error::success;
612 error_code COFFObjectFile::getRelocationAddress(DataRefImpl Rel,
613 uint64_t &Res) const {
614 Res = toRel(Rel)->VirtualAddress;
615 return object_error::success;
617 error_code COFFObjectFile::getRelocationSymbol(DataRefImpl Rel,
618 SymbolRef &Res) const {
619 const coff_relocation* R = toRel(Rel);
621 Symb.p = reinterpret_cast<uintptr_t>(SymbolTable + R->SymbolTableIndex);
622 Res = SymbolRef(Symb, this);
623 return object_error::success;
625 error_code COFFObjectFile::getRelocationType(DataRefImpl Rel,
626 uint32_t &Res) const {
627 const coff_relocation* R = toRel(Rel);
629 return object_error::success;
632 #define LLVM_COFF_SWITCH_RELOC_TYPE_NAME(enum) \
633 case COFF::enum: res = #enum; break;
635 error_code COFFObjectFile::getRelocationTypeName(DataRefImpl Rel,
636 SmallVectorImpl<char> &Result) const {
637 const coff_relocation *reloc = toRel(Rel);
639 switch (Header->Machine) {
640 case COFF::IMAGE_FILE_MACHINE_AMD64:
641 switch (reloc->Type) {
642 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ABSOLUTE);
643 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR64);
644 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32);
645 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_ADDR32NB);
646 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32);
647 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_1);
648 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_2);
649 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_3);
650 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_4);
651 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_REL32_5);
652 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECTION);
653 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL);
654 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SECREL7);
655 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_TOKEN);
656 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SREL32);
657 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_PAIR);
658 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_AMD64_SSPAN32);
663 case COFF::IMAGE_FILE_MACHINE_I386:
664 switch (reloc->Type) {
665 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_ABSOLUTE);
666 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR16);
667 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL16);
668 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32);
669 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_DIR32NB);
670 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SEG12);
671 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECTION);
672 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL);
673 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_TOKEN);
674 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_SECREL7);
675 LLVM_COFF_SWITCH_RELOC_TYPE_NAME(IMAGE_REL_I386_REL32);
683 Result.append(res.begin(), res.end());
684 return object_error::success;
687 #undef LLVM_COFF_SWITCH_RELOC_TYPE_NAME
689 error_code COFFObjectFile::getRelocationAdditionalInfo(DataRefImpl Rel,
690 int64_t &Res) const {
692 return object_error::success;
694 error_code COFFObjectFile::getRelocationValueString(DataRefImpl Rel,
695 SmallVectorImpl<char> &Result) const {
696 const coff_relocation *reloc = toRel(Rel);
697 const coff_symbol *symb = 0;
698 if (error_code ec = getSymbol(reloc->SymbolTableIndex, symb)) return ec;
700 ::memset(&sym, 0, sizeof(sym));
701 sym.p = reinterpret_cast<uintptr_t>(symb);
703 if (error_code ec = getSymbolName(sym, symname)) return ec;
704 Result.append(symname.begin(), symname.end());
705 return object_error::success;
710 ObjectFile *ObjectFile::createCOFFObjectFile(MemoryBuffer *Object) {
712 return new COFFObjectFile(Object, ec);
715 } // end namespace llvm