https://sourceware.org/bugzilla/show_bug.cgi?id=23309
Bug ID: 23309 Summary: ld.bfd -u option to force symbol discards symbol when used with LTO plugin and the symbol has hidden or internal visibility Product: binutils Version: 2.31 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: zenith432 at users dot sourceforge.net Target Milestone: --- Test Case: test.c ========== #include <stdio.h> int main(int argc, char** argv) { printf("Hello World\n"); return 0; } void KeepMe(void) { __asm__ volatile ( ".asciz \"This string should appear in the executable.\"" ); } ========== compile with gcc -o test -flto -fvisibility=hidden -ffunction-sections -save-temps -fuse-ld=bfd -Wl,--gc-sections,--print-gc-sections,-u,KeepMe test.c strings -a test | grep This Output: /usr/bin/ld.bfd: Removing unused section '.rodata.cst4' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o' /usr/bin/ld.bfd: Removing unused section '.data' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o' /usr/bin/ld.bfd: Removing unused section '.rodata' in file '/usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o' /usr/bin/ld.bfd: Removing unused section '.text.KeepMe' in file 'test.ltrans0.ltrans.o' Notice that KeepMe is discarded and does not appear in the output file. Save the file test.ltrans0.s as test.bfd.s Now compile with gcc -o test -flto -fvisibility=hidden -ffunction-sections -save-temps -fuse-ld=gold -Wl,--gc-sections,--print-gc-sections,-u,KeepMe test.c strings -a test | grep This (Using gold instead of bfd) Output: /usr/bin/ld.gold: removing unused section from '.rodata.cst4' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o' /usr/bin/ld.gold: removing unused section from '.data' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o' /usr/bin/ld.gold: removing unused section from '.bss' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crt1.o' /usr/bin/ld.gold: removing unused section from '.text' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o' /usr/bin/ld.gold: removing unused section from '.data' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o' /usr/bin/ld.gold: removing unused section from '.bss' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crti.o' /usr/bin/ld.gold: removing unused section from '.data' in file '/usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o' /usr/bin/ld.gold: removing unused section from '.rodata' in file '/usr/lib/gcc/x86_64-redhat-linux/8/crtbegin.o' /usr/bin/ld.gold: removing unused section from '.data' in file '/usr/lib64/libc_nonshared.a(elf-init.oS)' /usr/bin/ld.gold: removing unused section from '.bss' in file '/usr/lib64/libc_nonshared.a(elf-init.oS)' /usr/bin/ld.gold: removing unused section from '.text' in file '/usr/lib/gcc/x86_64-redhat-linux/8/crtend.o' /usr/bin/ld.gold: removing unused section from '.data' in file '/usr/lib/gcc/x86_64-redhat-linux/8/crtend.o' /usr/bin/ld.gold: removing unused section from '.bss' in file '/usr/lib/gcc/x86_64-redhat-linux/8/crtend.o' /usr/bin/ld.gold: removing unused section from '.text' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crtn.o' /usr/bin/ld.gold: removing unused section from '.data' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crtn.o' /usr/bin/ld.gold: removing unused section from '.bss' in file '/usr/lib/gcc/x86_64-redhat-linux/8/../../../../lib64/crtn.o' /usr/bin/ld.gold: removing unused section from '.text' in file 'test.ltrans0.ltrans.o' /usr/bin/ld.gold: removing unused section from '.data' in file 'test.ltrans0.ltrans.o' /usr/bin/ld.gold: removing unused section from '.bss' in file 'test.ltrans0.ltrans.o' This string should appear in the executable. So KeepMe is in the executable as it should be. Rename test.ltrans0.s to test.gold.s and then... diff test.bfd.s test.gold.s 30a31,32 > .globl KeepMe > .hidden KeepMe -- You are receiving this mail because: You are on the CC list for the bug. _______________________________________________ bug-binutils mailing list bug-binutils@gnu.org https://lists.gnu.org/mailman/listinfo/bug-binutils