File tree Expand file tree Collapse file tree 6 files changed +35
-22
lines changed Expand file tree Collapse file tree 6 files changed +35
-22
lines changed Original file line number Diff line number Diff line change @@ -1167,7 +1167,9 @@ void LinkerScript::adjustOutputSections() {
1167
1167
// * The address assignment.
1168
1168
// The other option is to pick flags that minimize the impact the section
1169
1169
// will have on the rest of the linker. That is why we copy the flags from
1170
- // the previous sections. Only a few flags are needed to keep the impact low.
1170
+ // the previous sections. We copy just SHF_ALLOC and SHF_WRITE to keep the
1171
+ // impact low. We do not propagate SHF_EXECINSTR as in some cases this can
1172
+ // lead to executable writeable section.
1171
1173
uint64_t flags = SHF_ALLOC;
1172
1174
1173
1175
SmallVector<StringRef, 0 > defPhdrs;
@@ -1193,8 +1195,8 @@ void LinkerScript::adjustOutputSections() {
1193
1195
// We do not want to keep any special flags for output section
1194
1196
// in case it is empty.
1195
1197
if (isEmpty)
1196
- sec->flags = flags & ((sec-> nonAlloc ? 0 : ( uint64_t )SHF_ALLOC) |
1197
- SHF_WRITE | SHF_EXECINSTR );
1198
+ sec->flags =
1199
+ flags & ((sec-> nonAlloc ? 0 : ( uint64_t )SHF_ALLOC) | SHF_WRITE );
1198
1200
1199
1201
// The code below may remove empty output sections. We should save the
1200
1202
// specified program headers (if exist) and propagate them to subsequent
Original file line number Diff line number Diff line change @@ -97,6 +97,16 @@ The presence of ``address`` can cause the condition unsatisfied. LLD will warn.
97
97
GNU ld from Binutils 2.35 onwards will reduce sh_addralign so that
98
98
sh_addr=0 (modulo sh_addralign).
99
99
100
+ When an output section has no input section, GNU ld will eliminate it if it
101
+ only contains symbol assignments (e.g. ``.foo { symbol = 42; } ``). LLD will
102
+ retain such sections unless all the symbol assignments are unreferenced
103
+ ``PROVIDED ``.
104
+
105
+ When an output section has no input section but advances the location counter,
106
+ GNU ld sets the ``SHF_WRITE `` flag. LLD sets the SHF_WRITE flag only if the
107
+ preceding output section with non-empty input sections also has the SHF_WRITE
108
+ flag.
109
+
100
110
Output section type
101
111
-------------------
102
112
Original file line number Diff line number Diff line change 29
29
# EMPTY-NEXT: Type: SHT_PROGBITS
30
30
# EMPTY-NEXT: Flags [
31
31
# EMPTY-NEXT: SHF_ALLOC
32
- # EMPTY-NEXT: SHF_EXECINSTR
33
32
# EMPTY-NEXT: ]
34
33
35
34
.section .foo,"ax"
Original file line number Diff line number Diff line change @@ -19,12 +19,13 @@ SECTIONS {
19
19
.data.rel.ro : { *(.data.rel.ro) }
20
20
}
21
21
22
- # CHECK: .rodata PROGBITS 0000000000000215 000215 000001 00 A 0
23
- # CHECK-NEXT: foo PROGBITS 0000000000000216 000216 000000 00 A 0
24
- # CHECK-NEXT: .text PROGBITS 0000000000000218 000218 000001 00 AX 0
25
- # CHECK-NEXT: bar PROGBITS 0000000000000219 000219 000de7 00 AX 0
22
+ # CHECK: .rodata PROGBITS 000000000000024d 00024d 000001 00 A 0
23
+ # CHECK-NEXT: foo PROGBITS 000000000000024e 00024e 000000 00 A 0
24
+ # CHECK-NEXT: .text PROGBITS 0000000000000250 000250 000001 00 AX 0
25
+ # CHECK-NEXT: bar PROGBITS 0000000000000251 000251 000daf 00 A 0
26
26
# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA 0
27
27
28
- # CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x000216 0x000216 R 0x1000
29
- # CHECK: LOAD 0x000218 0x0000000000000218 0x0000000000000218 0x000de8 0x000de8 R E 0x1000
28
+ # CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x00024e 0x00024e R 0x1000
29
+ # CHECK-NEXT: LOAD 0x000250 0x0000000000000250 0x0000000000000250 0x000001 0x000001 R E 0x1000
30
+ # CHECK-NEXT: LOAD 0x000251 0x0000000000000251 0x0000000000000251 0x000daf 0x000daf R 0x1000
30
31
# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW 0x1000
Original file line number Diff line number Diff line change 9
9
# RUN: llvm-readelf -S -l %t1 | FileCheck %s
10
10
# CHECK: Name Type Address Off Size ES Flg
11
11
# CHECK-NEXT: NULL
12
- # CHECK-NEXT: .foo.text PROGBITS 0000000000000000 001000 000008 00 AX
13
- # CHECK-NEXT: .text PROGBITS 0000000000000008 001008 000008 00 AX
14
- # CHECK-NEXT: .byte PROGBITS 0000000000000010 001010 000001 00 AX
15
- # CHECK-NEXT: .foo.data PROGBITS 0000000000000011 001011 000008 00 WA
16
- # CHECK-NEXT: .data PROGBITS 0000000000000019 001019 000008 00 WA
12
+ # CHECK-NEXT: .foo.text PROGBITS 0000000000000000 001000 000008 00 AX 0
13
+ # CHECK-NEXT: .text PROGBITS 0000000000000008 001008 000008 00 AX 0
14
+ # CHECK-NEXT: .byte PROGBITS 0000000000000010 001010 000001 00 A 0
15
+ # CHECK-NEXT: .foo.data PROGBITS 0000000000000011 001011 000008 00 WA 0
16
+ # CHECK-NEXT: .data PROGBITS 0000000000000019 001019 000008 00 WA 0
17
17
# CHECK: Type
18
18
# CHECK-NEXT: LOAD {{.*}} R E
19
+ # CHECK-NEXT: LOAD {{.*}} R
19
20
# CHECK-NEXT: LOAD {{.*}} RW
20
21
# CHECK-NEXT: GNU_STACK {{.*}} RW
21
22
Original file line number Diff line number Diff line change 7
7
# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
8
8
# CHECK-NEXT: NULL 0000000000000000 000000 000000 00 0 0 0
9
9
# CHECK-NEXT: .text PROGBITS 0000000008000000 001000 000001 00 AX 0 0 4
10
- # CHECK-NEXT: .data PROGBITS 0000000020000000 002000 000006 00 AX 0 0 8
11
- # CHECK-NEXT: .data2 PROGBITS 000000000800000e 00200e 000008 00 AX 0 0 1
12
- # CHECK-NEXT: .data3 PROGBITS 0000000020000008 002018 000000 00 AX 0 0 8
13
- # CHECK-NEXT: .data4 PROGBITS 0000000008000018 002018 000008 00 AX 0 0 1
10
+ # CHECK-NEXT: .data PROGBITS 0000000020000000 002000 000006 00 A 0 0 8
11
+ # CHECK-NEXT: .data2 PROGBITS 000000000800000e 00200e 000008 00 A 0 0 1
12
+ # CHECK-NEXT: .data3 PROGBITS 0000000020000008 002018 000000 00 A 0 0 8
13
+ # CHECK-NEXT: .data4 PROGBITS 0000000008000018 002018 000008 00 A 0 0 1
14
14
15
15
16
16
# CHECK: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
17
17
# CHECK-NEXT: LOAD 0x001000 0x0000000008000000 0x0000000008000000 0x000001 0x000001 R E 0x1000
18
- # CHECK-NEXT: LOAD 0x002000 0x0000000020000000 0x0000000008000008 0x000006 0x000006 R E 0x1000
19
- # CHECK-NEXT: LOAD 0x00200e 0x000000000800000e 0x000000000800000e 0x000008 0x000008 R E 0x1000
20
- # CHECK-NEXT: LOAD 0x002018 0x0000000008000018 0x0000000008000018 0x000008 0x000008 R E 0x1000
18
+ # CHECK-NEXT: LOAD 0x002000 0x0000000020000000 0x0000000008000008 0x000006 0x000006 R 0x1000
19
+ # CHECK-NEXT: LOAD 0x00200e 0x000000000800000e 0x000000000800000e 0x000008 0x000008 R 0x1000
20
+ # CHECK-NEXT: LOAD 0x002018 0x0000000008000018 0x0000000008000018 0x000008 0x000008 R 0x1000
21
21
22
22
MEMORY {
23
23
CODE (rx) : ORIGIN = 0x08000000, LENGTH = 100K
You can’t perform that action at this time.
0 commit comments