Skip to content

Commit ae66955

Browse files
committed
[LLD][COFF] Merge .bss at end of .data section.
Because it is full of zeros, it is expected that as much of it as possible is elided from the actual image, and that cannot happen if there is initialized data in the section after it.
1 parent 0547e84 commit ae66955

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

lld/test/COFF/merge-data-bss.test

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# RUN: yaml2obj %s -o %t.obj
2+
# RUN: lld-link /out:%t.exe /entry:main /subsystem:console /force \
3+
# RUN: /merge:.other=.data %t.obj /debug
4+
# RUN: llvm-readobj --sections %t.exe | FileCheck %s
5+
6+
# CHECK: Name: .data
7+
# CHECK-NEXT: VirtualSize: 0x2018
8+
# CHECK-NEXT: VirtualAddress: 0x3000
9+
# CHECK-NEXT: RawDataSize: 512
10+
# CHECK-NOT: Name: .other
11+
12+
--- !COFF
13+
header:
14+
Machine: IMAGE_FILE_MACHINE_AMD64
15+
Characteristics: [ ]
16+
sections:
17+
- Name: .text
18+
Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
19+
Alignment: 4
20+
SectionData: '90'
21+
SizeOfRawData: 1
22+
- Name: .data
23+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
24+
Alignment: 4
25+
SectionData: '010000000000000002'
26+
SizeOfRawData: 9
27+
- Name: .bss
28+
Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
29+
Alignment: 4
30+
SectionData: ''
31+
SizeOfRawData: 8192
32+
- Name: .other
33+
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
34+
Alignment: 4
35+
SectionData: '030000000000000004'
36+
SizeOfRawData: 9
37+
symbols:
38+
- Name: .text
39+
Value: 0
40+
SectionNumber: 1
41+
SimpleType: IMAGE_SYM_TYPE_NULL
42+
ComplexType: IMAGE_SYM_DTYPE_NULL
43+
StorageClass: IMAGE_SYM_CLASS_STATIC
44+
SectionDefinition:
45+
Length: 1
46+
NumberOfRelocations: 0
47+
NumberOfLinenumbers: 0
48+
CheckSum: 4027552580
49+
Number: 1
50+
- Name: .data
51+
Value: 0
52+
SectionNumber: 2
53+
SimpleType: IMAGE_SYM_TYPE_NULL
54+
ComplexType: IMAGE_SYM_DTYPE_NULL
55+
StorageClass: IMAGE_SYM_CLASS_STATIC
56+
SectionDefinition:
57+
Length: 9
58+
NumberOfRelocations: 0
59+
NumberOfLinenumbers: 0
60+
CheckSum: 4185224559
61+
Number: 2
62+
- Name: .bss
63+
Value: 0
64+
SectionNumber: 3
65+
SimpleType: IMAGE_SYM_TYPE_NULL
66+
ComplexType: IMAGE_SYM_DTYPE_NULL
67+
StorageClass: IMAGE_SYM_CLASS_STATIC
68+
SectionDefinition:
69+
Length: 8192
70+
NumberOfRelocations: 0
71+
NumberOfLinenumbers: 0
72+
CheckSum: 0
73+
Number: 3
74+
- Name: .other
75+
Value: 0
76+
SectionNumber: 4
77+
SimpleType: IMAGE_SYM_TYPE_NULL
78+
ComplexType: IMAGE_SYM_DTYPE_NULL
79+
StorageClass: IMAGE_SYM_CLASS_STATIC
80+
SectionDefinition:
81+
Length: 9
82+
NumberOfRelocations: 0
83+
NumberOfLinenumbers: 0
84+
CheckSum: 1054931164
85+
Number: 4
86+
- Name: main
87+
Value: 0
88+
SectionNumber: 1
89+
SimpleType: IMAGE_SYM_TYPE_NULL
90+
ComplexType: IMAGE_SYM_DTYPE_NULL
91+
StorageClass: IMAGE_SYM_CLASS_EXTERNAL
92+
...

0 commit comments

Comments
 (0)