http://sourceware.org/bugzilla/show_bug.cgi?id=12818
Summary: gold linker failed to remove all dead code dependency properly Product: binutils Version: 2.22 (HEAD) Status: NEW Severity: normal Priority: P2 Component: gold AssignedTo: i...@airs.com ReportedBy: grabli_2...@mail.ru Initially reported as https://bugzilla.novell.com/show_bug.cgi?id=694266 http://sourceware.org/bugzilla/show_bug.cgi?id=12772 I`ve found, that this bug applied to gold linker too: ----- test.cpp #include <string.h> #include <stdlib.h> #include <unistd.h> extern "C" int __attribute__((visibility("default"))) func(char *ptr) { static const char g_const[] = { 1, 1, 0 }; memcpy(ptr, g_const, 3); return 0; } extern "C" char *func2(char *ptr) { static char buf[4096]; if (!getcwd(buf, sizeof(buf))) buf[0] = 0; #define STR "test_string" memcpy(ptr, STR, sizeof(STR)); return buf; } ----- gcc -O3 -c -fpic -shared -fdata-sections -ffunction-sections \ -fvisibility-inlines-hidden -fvisibility=hidden -o test.o test.cpp gold -m elf_x86_64 -gc-sections -s -shared -o test.so test.o readelf -s 5540450000000000.so Symbol table '.dynsym' contains 7 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000270 23 FUNC GLOBAL DEFAULT 4 func 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND _GLOBAL_OFFSET_TABLE_ 3: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND getcwd 4: 0000000000001380 0 NOTYPE GLOBAL DEFAULT ABS _edata 5: 0000000000001380 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 6: 0000000000001380 0 NOTYPE GLOBAL DEFAULT ABS _end As we see - getcwd dependency not discarded properly. Also I`ve note that this way I can get smallest shared object size - 1888 bytes, while using "gcc -O3 -Wl,-x,-gc-sections,-s -fpic -flto -shared -fdata-sections -ffunction-sections -fvisibility-inlines-hidden -fvisibility=hidden -o test.o test.cpp" size is 4552, and without -flto: "gcc -O3 -Wl,-x,-gc-sections,-s -fpic -shared -fdata-sections -ffunction-sections -fvisibility-inlines-hidden -fvisibility=hidden -o test.o test.cpp" size is 6280 I assume something going not ringht. -- Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email ------- 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