[llvm] r203986 - Object/COFF: change data type of SymbolNumber from int16 to uint16.

Rui Ueyama ruiu at google.com
Fri Mar 14 17:04:08 PDT 2014


Author: ruiu
Date: Fri Mar 14 19:04:08 2014
New Revision: 203986

URL: http://llvm.org/viewvc/llvm-project?rev=203986&view=rev
Log:
Object/COFF: change data type of SymbolNumber from int16 to uint16.

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

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

Modified: llvm/trunk/include/llvm/Object/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/COFF.h?rev=203986&r1=203985&r2=203986&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/COFF.h (original)
+++ llvm/trunk/include/llvm/Object/COFF.h Fri Mar 14 19:04:08 2014
@@ -193,7 +193,7 @@ struct coff_symbol {
   } Name;
 
   support::ulittle32_t Value;
-  support::little16_t SectionNumber;
+  support::ulittle16_t SectionNumber;
 
   support::ulittle16_t Type;
 

Modified: llvm/trunk/include/llvm/Support/COFF.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/COFF.h?rev=203986&r1=203985&r2=203986&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/COFF.h (original)
+++ llvm/trunk/include/llvm/Support/COFF.h Fri Mar 14 19:04:08 2014
@@ -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
   };
 

Modified: llvm/trunk/test/MC/COFF/feat00.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/feat00.s?rev=203986&r1=203985&r2=203986&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/feat00.s (original)
+++ llvm/trunk/test/MC/COFF/feat00.s Fri Mar 14 19:04:08 2014
@@ -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)

Modified: llvm/trunk/test/MC/COFF/weak.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/weak.s?rev=203986&r1=203985&r2=203986&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/weak.s (original)
+++ llvm/trunk/test/MC/COFF/weak.s Fri Mar 14 19:04:08 2014
@@ -52,7 +52,7 @@ LBB0_2:
 // 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

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=203986&r1=203985&r2=203986&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Fri Mar 14 19:04:08 2014
@@ -317,7 +317,9 @@ static char getSymbolNMTypeChar(COFFObje
     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 '?';





More information about the llvm-commits mailing list