[PATCH] ld: Add -z start-stop-gc to let __start_/__stop_ not retain C identifier name sections

Alan Modra amodra@gmail.com
Mon Mar 1 07:28:29 GMT 2021


On Sun, Feb 28, 2021 at 11:03:19PM -0800, Fangrui Song wrote:
> Here is another interesting test.
> 
> .weak __start_xx
> .weak __stop_xx
> 
> .global _start
> _start:
>   movq __start_xx@gotpcrel(%rip), %rdi
>   movq __stop_xx@gotpcrel(%rip), %rsi
> 
> .section xx,"a",unique,0
> .byte 0
> 
> .section xx,"a",unique,1
> .byte 1
> 
> .section xx,"a",unique,2
> .byte 2
> 
> 
> ld-new a.o --gc-sections --print-gc-sections -pie -z start-stop-gc can discard 3 sections.
> ld-new a.o --gc-sections --print-gc-sections -shared -z start-stop-gc can only discard 2 - there may be a lurking bug somewhere.

I see
./ld-new: removing unused section 'xx' in file 'a.o'
./ld-new: removing unused section 'xx' in file 'a.o'
./ld-new: removing unused section 'xx' in file 'a.o'
./ld-new: a.o: relocation R_X86_64_PC32 against undefined protected symbol `__start_xx' can not be used when making a shared object
./ld-new: final link failed: bad value

I'm guessing that an x86 optimisation is being confused.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list