[llvm] r210373 - MC: prevent early DCE of empty sections
Saleem Abdulrasool
compnerd at compnerd.org
Fri Jun 6 14:40:16 PDT 2014
Author: compnerd
Date: Fri Jun 6 16:40:16 2014
New Revision: 210373
URL: http://llvm.org/viewvc/llvm-project?rev=210373&view=rev
Log:
MC: prevent early DCE of empty sections
Prevent the early elimination of sections in the object writer. There may be
references to the section itself by other symbols, which may potentially not be
possible to resolve. ML (Visual Studio's Macro Assembler) also seems to retain
empty sections.
The elimination of symbols and sections which are unused should really occur at
the link phase. This will not cause any change in the resulting binary, simply
in the generated object files.
The adjustments to the other unit tests account for the fluctuating section
index caused by the appearance of sections which were previously discarded.
Added:
llvm/trunk/test/MC/COFF/early-dce.s
Modified:
llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
llvm/trunk/test/MC/COFF/alias.s
llvm/trunk/test/MC/COFF/basic-coff-64.s
llvm/trunk/test/MC/COFF/basic-coff.s
llvm/trunk/test/MC/COFF/linkonce.s
llvm/trunk/test/MC/COFF/section-comdat.s
llvm/trunk/test/MC/COFF/section-name-encoding.s
llvm/trunk/test/MC/COFF/seh.s
llvm/trunk/test/MC/COFF/symbol-fragment-offset-64.s
llvm/trunk/test/MC/COFF/symbol-fragment-offset.s
Modified: llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFObjectWriter.cpp Fri Jun 6 16:40:16 2014
@@ -833,13 +833,9 @@ void WinCOFFObjectWriter::WriteObject(MC
DenseMap<COFFSection *, uint16_t> SectionIndices;
for (auto & Section : Sections) {
- if (Layout.getSectionAddressSize(Section->MCData) > 0) {
- size_t Number = ++Header.NumberOfSections;
- SectionIndices[Section.get()] = Number;
- MakeSectionReal(*Section, Number);
- } else {
- Section->Number = -1;
- }
+ size_t Number = ++Header.NumberOfSections;
+ SectionIndices[Section.get()] = Number;
+ MakeSectionReal(*Section, Number);
}
Header.NumberOfSymbols = 0;
Modified: llvm/trunk/test/MC/COFF/alias.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/alias.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/alias.s (original)
+++ llvm/trunk/test/MC/COFF/alias.s Fri Jun 6 16:40:16 2014
@@ -1,4 +1,5 @@
-// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - | llvm-readobj -t -r | FileCheck %s
+// RUN: llvm-mc -filetype=obj -triple i686-pc-win32 %s -o - \
+// RUN: | llvm-readobj -t -r | FileCheck %s
local1:
external_aliased_to_local = local1
@@ -36,7 +37,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: AuxSymbolCount: 1
// CHECK: }
// CHECK: Symbol {
-// CHECK-NEXT: Name: local1
+// CHECK: Name: local1
// CHECK-NEXT: Value: 0
// CHECK-NEXT: Section: .text (1)
// CHECK-NEXT: BaseType: Null (0x0)
@@ -89,7 +90,7 @@ weak_aliased_to_external = external2
// CHECK-NEXT: StorageClass: WeakExternal (0x69)
// CHECK-NEXT: AuxSymbolCount: 1
// CHECK-NEXT: AuxWeakExternal {
-// CHECK-NEXT: Linked: external2 (9)
+// CHECK-NEXT: Linked: external2 (13)
// CHECK-NEXT: Search: Library (0x2)
// CHECK-NEXT: Unused: (00 00 00 00 00 00 00 00 00 00)
// CHECK-NEXT: }
Modified: llvm/trunk/test/MC/COFF/basic-coff-64.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/basic-coff-64.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/basic-coff-64.s (original)
+++ llvm/trunk/test/MC/COFF/basic-coff-64.s Fri Jun 6 16:40:16 2014
@@ -25,10 +25,10 @@ _main:
// CHECK: ImageFileHeader {
// CHECK: Machine: IMAGE_FILE_MACHINE_AMD64
-// CHECK: SectionCount: 2
+// CHECK: SectionCount: 3
// CHECK: TimeDateStamp: {{[0-9]+}}
// CHECK: PointerToSymbolTable: 0x{{[0-9A-F]+}}
-// CHECK: SymbolCount: 6
+// CHECK: SymbolCount: 8
// CHECK: OptionalHeaderSize: 0
// CHECK: Characteristics [ (0x0)
// CHECK: ]
Modified: llvm/trunk/test/MC/COFF/basic-coff.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/basic-coff.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/basic-coff.s (original)
+++ llvm/trunk/test/MC/COFF/basic-coff.s Fri Jun 6 16:40:16 2014
@@ -25,10 +25,10 @@ L_.str:
// CHECK: ImageFileHeader {
// CHECK: Machine: IMAGE_FILE_MACHINE_I386
-// CHECK: SectionCount: 2
+// CHECK: SectionCount: 3
// CHECK: TimeDateStamp: {{[0-9]+}}
// CHECK: PointerToSymbolTable: 0x{{[0-9A-F]+}}
-// CHECK: SymbolCount: 6
+// CHECK: SymbolCount: 8
// CHECK: OptionalHeaderSize: 0
// CHECK: Characteristics [ (0x0)
// CHECK: ]
Added: llvm/trunk/test/MC/COFF/early-dce.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/early-dce.s?rev=210373&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/early-dce.s (added)
+++ llvm/trunk/test/MC/COFF/early-dce.s Fri Jun 6 16:40:16 2014
@@ -0,0 +1,16 @@
+# RUN: llvm-mc -triple i686-windows -g -filetype obj -o - %s \
+# RUN: | llvm-readobj -s -t | FileCheck %s
+
+ .section .rdata
+
+ .align 8
+ .global data
+data:
+ .quad 0
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK: Name: .text
+# CHECK: }
+# CHECK: ]
+
Modified: llvm/trunk/test/MC/COFF/linkonce.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/linkonce.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/linkonce.s (original)
+++ llvm/trunk/test/MC/COFF/linkonce.s Fri Jun 6 16:40:16 2014
@@ -91,41 +91,41 @@
// CHECK: Symbols [
// CHECK: Symbol {
// CHECK: Name: s1
-// CHECK: Section: s1 (1)
+// CHECK: Section: s1 (4)
// CHECK: AuxSectionDef {
-// CHECK: Number: 1
+// CHECK: Number: 4
// CHECK: Selection: Any (0x2)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: s2
-// CHECK: Section: s2 (2)
+// CHECK: Section: s2 (5)
// CHECK: AuxSectionDef {
-// CHECK: Number: 2
+// CHECK: Number: 5
// CHECK: Selection: NoDuplicates (0x1)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: s3
-// CHECK: Section: s3 (3)
+// CHECK: Section: s3 (6)
// CHECK: AuxSectionDef {
-// CHECK: Number: 3
+// CHECK: Number: 6
// CHECK: Selection: Any (0x2)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: s4
-// CHECK: Section: s4 (4)
+// CHECK: Section: s4 (7)
// CHECK: AuxSectionDef {
-// CHECK: Number: 4
+// CHECK: Number: 7
// CHECK: Selection: SameSize (0x3)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: s5
-// CHECK: Section: s5 (5)
+// CHECK: Section: s5 (8)
// CHECK: AuxSectionDef {
-// CHECK: Number: 5
+// CHECK: Number: 8
// CHECK: Selection: ExactMatch (0x4)
// CHECK: }
// CHECK: }
@@ -134,17 +134,17 @@
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: s7
-// CHECK: Section: s7 (7)
+// CHECK: Section: s7 (10)
// CHECK: AuxSectionDef {
-// CHECK: Number: 7
+// CHECK: Number: 10
// CHECK: Selection: Largest (0x6)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: s8
-// CHECK: Section: s8 (8)
+// CHECK: Section: s8 (11)
// CHECK: AuxSectionDef {
-// CHECK: Number: 8
+// CHECK: Number: 11
// CHECK: Selection: Newest (0x7)
// CHECK: }
// CHECK: }
Modified: llvm/trunk/test/MC/COFF/section-comdat.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/section-comdat.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/section-comdat.s (original)
+++ llvm/trunk/test/MC/COFF/section-comdat.s Fri Jun 6 16:40:16 2014
@@ -41,56 +41,56 @@ Symbol7:
// CHECK: Sections [
// CHECK: Section {
-// CHECK: Number: 1
+// CHECK: Number: 4
// CHECK: Name: assocSec
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 2
+// CHECK: Number: 5
// CHECK: Name: secName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 3
+// CHECK: Number: 6
// CHECK: Name: secName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 4
+// CHECK: Number: 7
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 5
+// CHECK: Number: 8
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 6
+// CHECK: Number: 9
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 7
+// CHECK: Number: 10
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 8
+// CHECK: Number: 11
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
@@ -100,7 +100,7 @@ Symbol7:
// CHECK: Symbols [
// CHECK: Symbol {
// CHECK: Name: assocSec
-// CHECK: Section: assocSec (1)
+// CHECK: Section: assocSec (4)
// CHECK: AuxSectionDef {
// CHECK: Selection: Any
// CHECK: }
@@ -111,40 +111,40 @@ Symbol7:
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: secName
-// CHECK: Section: secName (2)
+// CHECK: Section: secName (5)
// CHECK: AuxSectionDef {
// CHECK: Selection: Any
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol1
-// CHECK: Section: secName (2)
+// CHECK: Section: secName (5)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: secName
-// CHECK: Section: secName (3)
+// CHECK: Section: secName (6)
// CHECK: AuxSectionDef {
// CHECK: Selection: NoDuplicates
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol2
-// CHECK: Section: secName (3)
+// CHECK: Section: secName (6)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
-// CHECK: Section: SecName (4)
+// CHECK: Section: SecName (7)
// CHECK: AuxSectionDef {
// CHECK: Selection: SameSize
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol3
-// CHECK: Section: SecName (4)
+// CHECK: Section: SecName (7)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
-// CHECK: Section: SecName (5)
+// CHECK: Section: SecName (8)
// CHECK: AuxSymbolCount: 1
// CHECK: AuxSectionDef {
// CHECK: Selection: ExactMatch
@@ -152,40 +152,40 @@ Symbol7:
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol4
-// CHECK: Section: SecName (5)
+// CHECK: Section: SecName (8)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
-// CHECK: Section: SecName (6)
+// CHECK: Section: SecName (9)
// CHECK: AuxSectionDef {
// CHECK: Selection: Associative
-// CHECK: AssocSection: assocSec (1)
+// CHECK: AssocSection: assocSec (4)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
-// CHECK: Section: SecName (7)
+// CHECK: Section: SecName (10)
// CHECK: AuxSectionDef {
// CHECK: Selection: Largest
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol6
-// CHECK: Section: SecName (7)
+// CHECK: Section: SecName (10)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: SecName
-// CHECK: Section: SecName (8)
+// CHECK: Section: SecName (11)
// CHECK: AuxSectionDef {
// CHECK: Selection: Newest (0x7)
// CHECK: }
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol7
-// CHECK: Section: SecName (8)
+// CHECK: Section: SecName (11)
// CHECK: }
// CHECK: Symbol {
// CHECK: Name: Symbol5
-// CHECK: Section: SecName (6)
+// CHECK: Section: SecName (9)
// CHECK: }
// CHECK: ]
Modified: llvm/trunk/test/MC/COFF/section-name-encoding.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/section-name-encoding.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/section-name-encoding.s (original)
+++ llvm/trunk/test/MC/COFF/section-name-encoding.s Fri Jun 6 16:40:16 2014
@@ -10,11 +10,11 @@
// Raw encoding
// CHECK: Section {
-// CHECK: Number: 1
+// CHECK: Number: 4
// CHECK: Name: s (73 00 00 00 00 00 00 00)
// CHECK: }
// CHECK: Section {
-// CHECK: Number: 2
+// CHECK: Number: 5
// CHECK: Name: s1234567 (73 31 32 33 34 35 36 37)
// CHECK: }
.section s; .long 1
@@ -25,7 +25,7 @@
// /4
// CHECK: Section {
-// CHECK: Number: 3
+// CHECK: Number: 6
// CHECK: Name: s12345678 (2F 34 00 00 00 00 00 00)
// CHECK: }
.section s12345678; .long 1
@@ -57,7 +57,7 @@ pad_sections aaaaaaaaaaaaaaaaaaaaaaaaaaa
// "s12345678\0" # of pad sections
//
// CHECK: Section {
-// CHECK: Number: 9
+// CHECK: Number: 12
// CHECK: Name: seven_digit (2F 31 30 30 30 30 32 39)
// CHECK: }
.section seven_digit; .long 1
@@ -82,7 +82,7 @@ pad_sections_ex aaaaaaaaaaaaaaaaaaaaaaaa
// "2F 2F 41 41 6D 4A 61 34" is "//AAmJa4", which decodes to "0 0 38 9 26 56".
//
// CHECK: Section {
-// CHECK: Number: 15
+// CHECK: Number: 18
// CHECK: Name: double_slash (2F 2F 41 41 6D 4A 61 34)
// CHECK: }
.section double_slash; .long 1
Modified: llvm/trunk/test/MC/COFF/seh.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/seh.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/seh.s (original)
+++ llvm/trunk/test/MC/COFF/seh.s Fri Jun 6 16:40:16 2014
@@ -35,13 +35,13 @@
// CHECK-NEXT: ]
// CHECK-NEXT: Relocations [
-// CHECK-NEXT: Section (2) .xdata {
+// CHECK-NEXT: Section (4) .xdata {
// CHECK-NEXT: 0x14 IMAGE_REL_AMD64_ADDR32NB __C_specific_handler
// CHECK-NEXT: 0x20 IMAGE_REL_AMD64_ADDR32NB func
// CHECK-NEXT: 0x24 IMAGE_REL_AMD64_ADDR32NB func
// CHECK-NEXT: 0x28 IMAGE_REL_AMD64_ADDR32NB .xdata
// CHECK-NEXT: }
-// CHECK-NEXT: Section (3) .pdata {
+// CHECK-NEXT: Section (5) .pdata {
// CHECK-NEXT: 0x0 IMAGE_REL_AMD64_ADDR32NB func
// CHECK-NEXT: 0x4 IMAGE_REL_AMD64_ADDR32NB func
// CHECK-NEXT: 0x8 IMAGE_REL_AMD64_ADDR32NB .xdata
Modified: llvm/trunk/test/MC/COFF/symbol-fragment-offset-64.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/symbol-fragment-offset-64.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/symbol-fragment-offset-64.s (original)
+++ llvm/trunk/test/MC/COFF/symbol-fragment-offset-64.s Fri Jun 6 16:40:16 2014
@@ -36,10 +36,10 @@ _main:
// CHECK: {
// CHECK: Machine: IMAGE_FILE_MACHINE_AMD64
-// CHECK: SectionCount: 2
+// CHECK: SectionCount: 3
// CHECK: TimeDateStamp: {{[0-9]+}}
// CHECK: PointerToSymbolTable: 0x{{[0-9A-F]+}}
-// CHECK: SymbolCount: 7
+// CHECK: SymbolCount: 9
// CHECK: OptionalHeaderSize: 0
// CHECK: Characteristics [ (0x0)
// CHECK: ]
Modified: llvm/trunk/test/MC/COFF/symbol-fragment-offset.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/symbol-fragment-offset.s?rev=210373&r1=210372&r2=210373&view=diff
==============================================================================
--- llvm/trunk/test/MC/COFF/symbol-fragment-offset.s (original)
+++ llvm/trunk/test/MC/COFF/symbol-fragment-offset.s Fri Jun 6 16:40:16 2014
@@ -36,10 +36,10 @@ L_.str2:
// CHECK: {
// CHECK: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
-// CHECK: SectionCount: 2
+// CHECK: SectionCount: 3
// CHECK: TimeDateStamp: {{[0-9]+}}
// CHECK: PointerToSymbolTable: 0x{{[0-9A-F]+}}
-// CHECK: SymbolCount: 7
+// CHECK: SymbolCount: 9
// CHECK: OptionalHeaderSize: 0
// CHECK: Characteristics [ (0x0)
// CHECK: ]
More information about the llvm-commits
mailing list