1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

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.

llvm-svn: 210373
This commit is contained in:
Saleem Abdulrasool 2014-06-06 21:40:16 +00:00
parent ab2896f4aa
commit 542dba4868
11 changed files with 92 additions and 79 deletions

View File

@ -833,13 +833,9 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
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;

View File

@ -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: }

View File

@ -25,10 +25,10 @@ _main: # @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: ]

View File

@ -25,10 +25,10 @@ L_.str: # @.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: ]

16
test/MC/COFF/early-dce.s Normal file
View File

@ -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: ]

View File

@ -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: }

View File

@ -41,43 +41,22 @@ 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: Name: secName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 3
// CHECK: Name: secName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 4
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 5
// CHECK: Name: SecName
// CHECK: Name: secName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 6
// CHECK: Name: SecName
// CHECK: Name: secName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
@ -96,11 +75,32 @@ Symbol7:
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 9
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 10
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: Section {
// CHECK: Number: 11
// CHECK: Name: SecName
// CHECK: Characteristics [
// CHECK: IMAGE_SCN_LNK_COMDAT
// CHECK: ]
// CHECK: }
// CHECK: ]
// 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: ]

View File

@ -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 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
// "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 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
// "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

View File

@ -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

View File

@ -36,10 +36,10 @@ _main: # @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: ]

View File

@ -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: ]