Object/COFF: change data type of SymbolNumber from int16 to uint16.
authorRui Ueyama <ruiu@google.com>
Sat, 15 Mar 2014 00:04:08 +0000 (00:04 +0000)
committerRui Ueyama <ruiu@google.com>
Sat, 15 Mar 2014 00:04:08 +0000 (00:04 +0000)
Microsoft PE/COFF Spec clearly states that the field is of signed interger
type. However, in reality, it's unsigned. If cl.exe needs to create a large
number of sections for COMDAT sections, it will just create more than 32768
sections. Handling large section number as negative number is not correct.
I think this is a spec bug.

Differential Revision: http://llvm-reviews.chandlerc.com/D3088

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203986 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Object/COFF.h
include/llvm/Support/COFF.h
test/MC/COFF/feat00.s
test/MC/COFF/weak.s
tools/llvm-nm/llvm-nm.cpp

index 6bf059b9ea49c417c780f54fb92e9d1869630be4..8c292164e9aca93f6255349a4180fd06660fb448 100644 (file)
@@ -193,7 +193,7 @@ struct coff_symbol {
   } Name;
 
   support::ulittle32_t Value;
-  support::little16_t SectionNumber;
+  support::ulittle16_t SectionNumber;
 
   support::ulittle16_t Type;
 
index 7e796ed0926f4572821f587da82e79e6dffa4543..c408e828106e76dece8c2c46ecfd4bff6df78087 100644 (file)
@@ -138,8 +138,8 @@ namespace COFF {
   };
 
   enum SymbolSectionNumber {
-    IMAGE_SYM_DEBUG     = -2,
-    IMAGE_SYM_ABSOLUTE  = -1,
+    IMAGE_SYM_DEBUG     = 0xFFFE,
+    IMAGE_SYM_ABSOLUTE  = 0xFFFF,
     IMAGE_SYM_UNDEFINED = 0
   };
 
index d08f407cef58ac27dce111cc3fd9540251e8e2ae..bfd47ad4abc02465cf9a555461832b189a2a9cd6 100644 (file)
@@ -6,7 +6,7 @@
 // CHECK: Symbol {
 // CHECK:   Name: @feat.00
 // CHECK:   Value: 123
-// CHECK:   Section: (-1)
+// CHECK:   Section: (65535)
 // CHECK:   BaseType: Null (0x0)
 // CHECK:   ComplexType: Null (0x0)
 // CHECK:   StorageClass: External (0x2)
index b9df0f1df2fd5e567cf54efe6949371da77ef330..accd3f452eaf3add21e0f96240f02dc077ad7867 100644 (file)
@@ -52,7 +52,7 @@ LBB0_2:                                 # %return
 // CHECK:      Symbol {
 // CHECK:        Name:                .weak._test_weak.default
 // CHECK-NEXT:   Value:               0
-// CHECK-NEXT:   Section:             (-1)
+// CHECK-NEXT:   Section:             (65535)
 // CHECK-NEXT:   BaseType:            Null
 // CHECK-NEXT:   ComplexType:         Null
 // CHECK-NEXT:   StorageClass:        External
index 70c789f328c91142207d539c457659125c248e2e..88603d457534a86694c33d3d4b74be107e598a97 100644 (file)
@@ -317,7 +317,9 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
     return Ret;
 
   uint32_t Characteristics = 0;
-  if (Symb->SectionNumber > 0) {
+  if (Symb->SectionNumber > 0 &&
+      Symb->SectionNumber != llvm::COFF::IMAGE_SYM_DEBUG &&
+      Symb->SectionNumber != llvm::COFF::IMAGE_SYM_ABSOLUTE) {
     section_iterator SecI = Obj.section_end();
     if (error(SymI->getSection(SecI)))
       return '?';