Bug 27039 - Gold doesn't support SHF_GNU_RETAIN
Summary: Gold doesn't support SHF_GNU_RETAIN
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: 2.36
Assignee: Cary Coutant
URL: https://sourceware.org/pipermail/binu...
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-09 13:11 UTC by H.J. Lu
Modified: 2020-12-15 12:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A patch (1.46 KB, patch)
2020-12-09 15:11 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2020-12-09 13:11:24 UTC
[hjl@gnu-cfl-2 gold-1]$ cat x.s 
	.global	discard0
	.section	.bss.discard0,"aw"
	.type	discard0, %object
discard0:
	.zero	2

	.global	discard1
	.section	.bss.discard1,"aw"
	.type	discard1, %object
discard1:
	.zero	2

	.global	discard2
	.section	.data.discard2,"aw"
	.type	discard2, %object
discard2:
	.word	1

	.section	.bss.sdiscard0,"aw"
	.type	sdiscard0, %object
sdiscard0:
	.zero	2

	.section	.bss.sdiscard1,"aw"
	.type	sdiscard1, %object
sdiscard1:
	.zero	2

	.section	.data.sdiscard2,"aw"
	.type	sdiscard2, %object
sdiscard2:
	.word	1

	.section	.text.fndiscard0,"ax"
	.global	fndiscard0
	.type	fndiscard0, %function
fndiscard0:
	.word 0

	.global	retain0
	.section	.bss.retain0,"awR"
	.type	retain0, %object
retain0:
	.zero	2

	.global	retain1
	.section	.bss.retain1,"awR"
	.type	retain1, %object
retain1:
	.zero	2

	.global	retain2
	.section	.data.retain2,"awR"
	.type	retain2, %object
retain2:
	.word	1

	.section	.bss.sretain0,"awR"
	.type	sretain0, %object
sretain0:
	.zero	2

	.section	.bss.sretain1,"awR"
	.type	sretain1, %object
sretain1:
	.zero	2

	.section	.data.sretain2,"aRw"
	.type	sretain2, %object
sretain2:
	.word	1

	.section	.text.fnretain1,"Rax"
	.global	fnretain1
	.type	fnretain1, %function
fnretain1:
	.word	0

	.section	.text.fndiscard2,"ax"
	.global	fndiscard2
	.type	fndiscard2, %function
fndiscard2:
	.word	0

	.section	.bss.lsretain0,"awR"
	.type	lsretain0.2, %object
lsretain0.2:
	.zero	2

	.section	.bss.lsretain1,"aRw"
	.type	lsretain1.1, %object
lsretain1.1:
	.zero	2

	.section	.data.lsretain2,"aRw"
	.type	lsretain2.0, %object
lsretain2.0:
	.word	1

	.section	.text._start,"ax"
	.global	_start
	.type	_start, %function
_start:
	.word 0
[hjl@gnu-cfl-2 gold-1]$ make x
as   -o x.o x.s
./ld -e _start --gc-sections -o x x.o 
[hjl@gnu-cfl-2 gold-1]$ nm x
0000000000000000 A __bss_start
0000000000000000 A _edata
0000000000000000 A _end
00000000004000d0 T _start
[hjl@gnu-cfl-2 gold-1]$ cat y.s
	.section .preinit_array.01000,"aw",%preinit_array
	.dc.a 0

	.section .init_array.01000,"aw",%init_array
	.dc.a 0

	.section .fini_array.01000,"aw",%fini_array
	.dc.a 0

	.section .preinit_array.01000,"awR",%preinit_array
	.dc.a 0

	.section .init_array.01000,"awR",%init_array
	.dc.a 0

	.section .fini_array.01000,"awR",%fini_array
	.dc.a 0

	.text
	.globl _start
_start:
	.dc.a 0
[hjl@gnu-cfl-2 gold-1]$ make y
as   -o y.o y.s
./ld -pie -e _start --gc-sections -o y y.o 
[hjl@gnu-cfl-2 gold-1]$ readelf -d y

Dynamic section at offset 0xe60 contains 21 entries:
  Tag        Type                         Name/Value
 0x0000000000000015 (DEBUG)              0x0
 0x0000000000000006 (SYMTAB)             0x1f8
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000005 (STRTAB)             0x210
 0x000000000000000a (STRSZ)              1 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x218
 0x0000000000000004 (HASH)               0x238
 0x0000000000000020 (PREINIT_ARRAY)      0x1e30
 0x0000000000000021 (PREINIT_ARRAYSZ)    0x8
 0x0000000000000019 (INIT_ARRAY)         0x1e38
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x1e40
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x0000000000000020 (PREINIT_ARRAY)      0x1e48
 0x0000000000000021 (PREINIT_ARRAYSZ)    0x8
 0x0000000000000019 (INIT_ARRAY)         0x1e50
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x1e58
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffffb (FLAGS_1)            Flags: PIE
 0x0000000000000000 (NULL)               0x0
[hjl@gnu-cfl-2 gold-1]$
Comment 1 H.J. Lu 2020-12-09 15:11:38 UTC
Created attachment 13029 [details]
A patch
Comment 2 H.J. Lu 2020-12-09 16:08:35 UTC
A patch is posted at

https://sourceware.org/pipermail/binutils/2020-December/114458.html
Comment 3 Sourceware Commits 2020-12-14 23:50:12 UTC
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ff4bc37d77a0ca7286883a477adcb3aa145fc782

commit ff4bc37d77a0ca7286883a477adcb3aa145fc782
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Mon Dec 14 15:46:47 2020 -0800

    Keep input SHF_GNU_RETAIN sections and strip output SHF_GNU_RETAIN for GNU/FreBSD ELFOSABIs.
    
    2020-12-14  H.J. Lu  <hjl.tools@gmail.com>
                Cary Coutant  <ccoutant@gmail.com>
    
    elfcpp/
            PR gold/27039
            * elfcpp.h (SHF): Add SHF_GNU_RETAIN.
    
    gold/
            PR gold/27039
            * layout.cc (Layout::layout): Strip SHF_GNU_RETAIN.
            * object.cc (Sized_relobj_file::Sized_relobj_file): Initialize osabi_.
            (Sized_relobj_file::do_layout): Keep SHF_GNU_RETAIN sections for
            GNU/FreBSD ELFOSABIs.
            * object.h (Osabi) New class.
            (Sized_relobj_file): Add osabi() and osabi_.
            * testsuite/Makefile.am (check_SCRIPTS): Add retain.sh.
            (check_DATA): Add retain_1.out retain_2.out.
            (MOSTLYCLEANFILES): Add retain_1 retain_2.
            (retain_1.out): New target.
            (retain_1): Likewise.
            (retain_1.o): Likewise.
            (retain_2.out): Likewise.
            (retain_2): Likewise.
            (retain_2.o): Likewise.
            * testsuite/Makefile.in: Regenerate.
            * testsuite/retain.sh: New file.
            * testsuite/retain_1.s: Likewise.
            * testsuite/retain_2.s: Likewise.
Comment 4 H.J. Lu 2020-12-15 12:57:09 UTC
Fixed for 2.36.