[lld] r241828 - COFF: Fill in the type and storage class in the symbol table

David Majnemer david.majnemer at gmail.com
Thu Jul 9 10:43:50 PDT 2015


Author: majnemer
Date: Thu Jul  9 12:43:50 2015
New Revision: 241828

URL: http://llvm.org/viewvc/llvm-project?rev=241828&view=rev
Log:
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.

Modified:
    lld/trunk/COFF/Symbols.cpp
    lld/trunk/COFF/Symbols.h
    lld/trunk/COFF/Writer.cpp
    lld/trunk/test/COFF/symtab.test

Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=241828&r1=241827&r2=241828&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Thu Jul  9 12:43:50 2015
@@ -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())

Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=241828&r1=241827&r2=241828&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Thu Jul  9 12:43:50 2015
@@ -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;

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=241828&r1=241827&r2=241828&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Thu Jul  9 12:43:50 2015
@@ -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);
     }

Modified: lld/trunk/test/COFF/symtab.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/symtab.test?rev=241828&r1=241827&r2=241828&view=diff
==============================================================================
--- lld/trunk/test/COFF/symtab.test (original)
+++ lld/trunk/test/COFF/symtab.test Thu Jul  9 12:43:50 2015
@@ -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: ]





More information about the llvm-commits mailing list