COFF: Fill in the type and storage class in the symbol table

We can use the type and storage class from the symbol's original object
file to fill in the linked executable's symbol table.

llvm-svn: 241828
This commit is contained in:
David Majnemer 2015-07-09 17:43:50 +00:00
parent a717f255b6
commit 3a62d3d456
4 changed files with 19 additions and 5 deletions

View File

@ -209,6 +209,14 @@ uint64_t Defined::getFileOff() {
llvm_unreachable("unknown symbol kind");
}
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
size_t SymSize = File->getCOFFObj()->getSymbolTableEntrySize();
if (SymSize == sizeof(coff_symbol16))
return COFFSymbolRef(reinterpret_cast<const coff_symbol16 *>(Sym));
assert(SymSize == sizeof(coff_symbol32));
return COFFSymbolRef(reinterpret_cast<const coff_symbol32 *>(Sym));
}
ErrorOr<std::unique_ptr<InputFile>> Lazy::getMember() {
auto MBRefOrErr = File->getMember(&Sym);
if (auto EC = MBRefOrErr.getError())

View File

@ -27,6 +27,8 @@ using llvm::object::Archive;
using llvm::object::COFFSymbolRef;
using llvm::object::coff_import_header;
using llvm::object::coff_symbol_generic;
using llvm::object::coff_symbol16;
using llvm::object::coff_symbol32;
class ArchiveFile;
class BitcodeFile;
@ -142,6 +144,8 @@ public:
int getFileIndex() { return File->Index; }
COFFSymbolRef getCOFFSymbol();
protected:
ObjectFile *File;
const coff_symbol_generic *Sym;

View File

@ -327,9 +327,11 @@ void Writer::createSymbolAndStringTable() {
memcpy(Sym.Name.ShortName, Name.data(), Name.size());
}
COFFSymbolRef DSymRef= D->getCOFFSymbol();
Sym.Value = SymbolValue;
Sym.SectionNumber = SymSec->SectionIndex;
Sym.StorageClass = IMAGE_SYM_CLASS_NULL;
Sym.Type = DSymRef.getType();
Sym.StorageClass = DSymRef.getStorageClass();
Sym.NumberOfAuxSymbols = 0;
OutputSymtab.push_back(Sym);
}

View File

@ -9,7 +9,7 @@
# CHECK-NEXT: Section: .text
# CHECK-NEXT: BaseType: Null (0x0)
# CHECK-NEXT: ComplexType: Null (0x0)
# CHECK-NEXT: StorageClass: Null (0x0)
# CHECK-NEXT: StorageClass: Static
# CHECK-NEXT: AuxSymbolCount: 0
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
@ -18,7 +18,7 @@
# CHECK-NEXT: Section: .text
# CHECK-NEXT: BaseType: Null (0x0)
# CHECK-NEXT: ComplexType: Null (0x0)
# CHECK-NEXT: StorageClass: Null (0x0)
# CHECK-NEXT: StorageClass: External
# CHECK-NEXT: AuxSymbolCount: 0
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
@ -27,7 +27,7 @@
# CHECK-NEXT: Section: .text
# CHECK-NEXT: BaseType: Null (0x0)
# CHECK-NEXT: ComplexType: Null (0x0)
# CHECK-NEXT: StorageClass: Null (0x0)
# CHECK-NEXT: StorageClass: External
# CHECK-NEXT: AuxSymbolCount: 0
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
@ -36,7 +36,7 @@
# CHECK-NEXT: Section: .text
# CHECK-NEXT: BaseType: Null (0x0)
# CHECK-NEXT: ComplexType: Null (0x0)
# CHECK-NEXT: StorageClass: Null (0x0)
# CHECK-NEXT: StorageClass: External
# CHECK-NEXT: AuxSymbolCount: 0
# CHECK-NEXT: }
# CHECK-NEXT: ]