aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-07-09 17:43:50 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-07-09 17:43:50 +0000
commite7c352fd3e8d17065e0557e6dc63f9e21168e527 (patch)
tree87a01275f1261cdc0b5ffb4c8a8374cf36ebe56f
parentc947bce458eebe03dc53454cfbc2537800b7490c (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@241828 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--COFF/Symbols.cpp8
-rw-r--r--COFF/Symbols.h4
-rw-r--r--COFF/Writer.cpp4
-rw-r--r--test/COFF/symtab.test8
4 files changed, 19 insertions, 5 deletions
diff --git a/COFF/Symbols.cpp b/COFF/Symbols.cpp
index b3975a59c..402dd439c 100644
--- a/COFF/Symbols.cpp
+++ b/COFF/Symbols.cpp
@@ -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())
diff --git a/COFF/Symbols.h b/COFF/Symbols.h
index 88b0e69ae..5c8e55f01 100644
--- a/COFF/Symbols.h
+++ b/COFF/Symbols.h
@@ -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;
diff --git a/COFF/Writer.cpp b/COFF/Writer.cpp
index 60e901a76..23ce84855 100644
--- a/COFF/Writer.cpp
+++ b/COFF/Writer.cpp
@@ -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);
}
diff --git a/test/COFF/symtab.test b/test/COFF/symtab.test
index 4e865b01b..6e499320a 100644
--- a/test/COFF/symtab.test
+++ b/test/COFF/symtab.test
@@ -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: ]