Skip to content

Commit 9a4b18a

Browse files
committed
[lld][ELF] Coalesce uniqued .sbss and .sdata sections
RISC-V GCC with `-fdata-sections` will emit `.sbss.<name>` and `.sdata.<name>` sections for small data items. We intend to add the same behaviour to Clang/LLVM in #87040. This change ensures that any section starting `.sbss` is put in an output section called `.sbss`, and the same for `.sdata`, so that the RISC-V specific code for allocating an output order for `.sbss` and `.sdata` sections can apply. I did not add a `.sdata.rel.ro` prefix to the list as clang/llvm does not seem to create these at all. Whether it should be or not is a different matter.
1 parent 7332713 commit 9a4b18a

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lld/ELF/LinkerScript.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static StringRef getOutputSectionName(const InputSectionBase *s) {
109109
for (StringRef v :
110110
{".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss", ".ldata",
111111
".lrodata", ".lbss", ".gcc_except_table", ".init_array", ".fini_array",
112-
".tbss", ".tdata", ".ARM.exidx", ".ARM.extab", ".ctors", ".dtors"})
112+
".tbss", ".tdata", ".ARM.exidx", ".ARM.extab", ".ctors", ".dtors",
113+
".sbss", ".sdata"})
113114
if (isSectionPrefix(v, s->name))
114115
return v;
115116

lld/test/ELF/riscv-section-layout.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@
5757
.section .tbss,"awT",@nobits; .space 1
5858
.ifdef SDATA
5959
.section .sdata,"aw",@progbits; .space 1
60+
.section .sdata.suffix,"aw",@progbits; .space 1
6061
.section .sbss,"aw",@nobits; .space 1
62+
.section .sbss.suffix,"aw",@nobits; .space 1
6163
.endif

lld/test/ELF/section-name.s

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ _start:
4141
.byte 0
4242
.section .tdata.foo,"aGwT",@progbits,foo,comdat
4343
.byte 0
44+
.section .sdata.foo,"aw"
45+
.byte 0
46+
.section .sbss.foo,"aw",@nobits
47+
.byte 0
48+
4449

4550
// CHECK: .rodata 00000002
4651
// CHECK-NEXT: .gcc_except_table 00000001
@@ -52,8 +57,10 @@ _start:
5257
// CHECK-NEXT: .data 00000002
5358
// CHECK-NEXT: .foo.a 00000001
5459
// CHECK-NEXT: .foo 00000001
60+
// CHECK-NEXT: .sdata 00000001
5561
// CHECK-NEXT: .bss 00000002
62+
// CHECK-NEXT: .sbss 00000001
5663
// CHECK-NEXT: .comment 00000008
5764
// CHECK-NEXT: .symtab 00000030
58-
// CHECK-NEXT: .shstrtab 00000084
65+
// CHECK-NEXT: .shstrtab 00000091
5966
// CHECK-NEXT: .strtab 00000008

0 commit comments

Comments
 (0)