[llvm-bugs] [Bug 47777] New: Merge equally named output sections in linker scripts
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Oct 9 05:00:16 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47777
Bug ID: 47777
Summary: Merge equally named output sections in linker scripts
Product: lld
Version: unspecified
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: konstantin.schwarz at hightec-rt.com
CC: llvm-bugs at lists.llvm.org, smithp352 at googlemail.com
This is rather a feature request than a bug report.
Consider the following assembler input:
$ cat foo.s
.text
.globl _start
_start:
nop
and the following linker script:
$ cat linker.ld
SECTIONS {
.text : {
*(.text*)
}
.myTable : {
LONG(0);
}
/* Subcomponent #include's go here..., e.g. */
.myTable : {
LONG(1);
}
/* End marker of the table */
.myTable : {
LONG(-1);
}
}
Linking with GNU ld (GNU ld (GNU Binutils for Ubuntu) 2.30) (ld -static -T
link.ld foo.o) results in the following section headers:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000000000 00200000
0000000000000001 0000000000000000 AX 0 0 4
[ 2] .myTable PROGBITS 0000000000000001 00200001
000000000000000c 0000000000000000 WA 0 0 1
[ 3] .symtab SYMTAB 0000000000000000 00200010
0000000000000060 0000000000000018 4 3 8
[ 4] .strtab STRTAB 0000000000000000 00200070
0000000000000008 0000000000000000 0 0 1
[ 5] .shstrtab STRTAB 0000000000000000 00200078
000000000000002a 0000000000000000 0 0 1
Linking with ld.lld gives
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .text PROGBITS 0000000000000000 00001000
0000000000000001 0000000000000000 AX 0 0 4
[ 2] .myTable PROGBITS 0000000000000001 00001001
0000000000000004 0000000000000000 AX 0 0 1
[ 3] .myTable PROGBITS 0000000000000005 00001005
0000000000000004 0000000000000000 AX 0 0 1
[ 4] .myTable PROGBITS 0000000000000009 00001009
0000000000000004 0000000000000000 AX 0 0 1
[ 5] .comment PROGBITS 0000000000000000 0000100d
0000000000000076 0000000000000001 MS 0 0 1
[ 6] .symtab SYMTAB 0000000000000000 00001088
0000000000000030 0000000000000018 8 1 8
[ 7] .shstrtab STRTAB 0000000000000000 000010b8
0000000000000033 0000000000000000 0 0 1
[ 8] .strtab STRTAB 0000000000000000 000010eb
0000000000000008 0000000000000000 0 0 1
As can be seen, GNU ld merges all equally named output sections into one single
output section of the same name.
Our users make use of this "feature" to create different kinds of tables in
linker scripts:
An application typically consists of many different components, potentially
developed by different vendors.
Each component can provide its own linker script snippet, #include'd in the
final application's "main" linker script.
The main linker script contains the start and end markers of the tables, and
each subcomponent can amend to the table
by providing an equally named output section. The linker merges all output
sections into one section, enabling the creation of
contiguous tables:
$ objdump -D ld-built.elf:
Disassembly of section .myTable:
0000000000000001 <.myTable>:
1: 00 00 add %al,(%rax)
3: 00 00 add %al,(%rax)
5: 01 00 add %eax,(%rax)
7: 00 00 add %al,(%rax)
9: ff (bad)
a: ff (bad)
b: ff (bad)
c: ff .byte 0xff
$ objdump -D lld-built.elf
Disassembly of section .myTable:
0000000000000001 <.myTable>:
1: 00 00 add %al,(%rax)
...
Disassembly of section .myTable:
0000000000000005 <.myTable>:
5: 01 00 add %eax,(%rax)
...
Disassembly of section .myTable:
0000000000000009 <.myTable>:
9: ff (bad)
a: ff (bad)
b: ff (bad)
c: ff .byte 0xff
Since I could not find any documentation or reference for this behavior in the
GNU ld manuals, I assume this is some kind of implementation
defined behavior. GNU gold behaves similarly to lld in this case.
Would it still be feasible to support this in lld, or can this be achieved my
other means in the linker script?
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201009/c91d8042/attachment-0001.html>
More information about the llvm-bugs
mailing list