[lld] r212571 - [PECOFF] Fix .bss section alignment

Rui Ueyama ruiu at google.com
Tue Jul 8 16:11:02 PDT 2014


Author: ruiu
Date: Tue Jul  8 18:11:01 2014
New Revision: 212571

URL: http://llvm.org/viewvc/llvm-project?rev=212571&view=rev
Log:
[PECOFF] Fix .bss section alignment

Previously the alignment of the .bss section was not
properly set because of a bug in AtomizeDefinedSymbolsInSection.
We set the alignment of the section at the end of the function,
but we use an eraly return for the .bss section, so the code had
been skipped.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
    lld/trunk/test/pecoff/Inputs/alignment.obj.yaml
    lld/trunk/test/pecoff/alignment.test

Modified: lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp?rev=212571&r1=212570&r2=212571&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp Tue Jul  8 18:11:01 2014
@@ -678,10 +678,6 @@ std::error_code FileCOFF::AtomizeDefined
     _symbolAtom[*si] = atom;
     _definedAtomLocations[section][(*si)->Value].push_back(atom);
   }
-
-  // Finally, set alignment to the first atom so that the section contents
-  // will be aligned as specified by the object section header.
-  _definedAtomLocations[section][0][0]->setAlignment(getAlignment(section));
   return std::error_code();
 }
 
@@ -698,6 +694,11 @@ std::error_code FileCOFF::AtomizeDefined
             AtomizeDefinedSymbolsInSection(section, symbols, atoms))
       return ec;
 
+    // Set alignment to the first atom so that the section contents
+    // will be aligned as specified by the object section header.
+    if (atoms.size() > 0)
+      atoms[0]->setAlignment(getAlignment(section));
+
     // Connect atoms with layout-before/layout-after edges.
     connectAtomsWithLayoutEdge(atoms);
 

Modified: lld/trunk/test/pecoff/Inputs/alignment.obj.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/Inputs/alignment.obj.yaml?rev=212571&r1=212570&r2=212571&view=diff
==============================================================================
--- lld/trunk/test/pecoff/Inputs/alignment.obj.yaml (original)
+++ lld/trunk/test/pecoff/Inputs/alignment.obj.yaml Tue Jul  8 18:11:01 2014
@@ -23,6 +23,14 @@ sections:
     Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
     Alignment:       0
     SectionData:     22
+  - Name:            .bss$1
+    Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+    Alignment:       16
+    SectionData:     0000
+  - Name:            .bss$2
+    Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
+    Alignment:       16
+    SectionData:     0000
 symbols:
   - Name:            .text
     Value:           0
@@ -60,4 +68,16 @@ symbols:
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_FUNCTION
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            .bss$1
+    Value:           0
+    SectionNumber:   6
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
+  - Name:            .bss$2
+    Value:           0
+    SectionNumber:   7
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_STATIC
 ...

Modified: lld/trunk/test/pecoff/alignment.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/alignment.test?rev=212571&r1=212570&r2=212571&view=diff
==============================================================================
--- lld/trunk/test/pecoff/alignment.test (original)
+++ lld/trunk/test/pecoff/alignment.test Tue Jul  8 18:11:01 2014
@@ -1,9 +1,12 @@
 # RUN: yaml2obj %p/Inputs/alignment.obj.yaml > %t.obj
 #
-# RUN: lld -flavor link /out:%t.exe /subsystem:console /force /entry:start \
-# RUN:   -- %t.obj
+# RUN: lld -flavor link /out:%t.exe /subsystem:console /force \
+# RUN:   /entry:start /opt:noref -- %t.obj
 # RUN: llvm-readobj -sections %t.exe | FileCheck %s
 
+CHECK: Name: .bss (2E 62 73 73 00 00 00 00)
+CHECK: RawDataSize: 18
+
 CHECK:      Name: .data (2E 64 61 74 61 00 00 00)
 CHECK-NEXT: VirtualSize: 0x6
 





More information about the llvm-commits mailing list