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.
CVSROOT: /cvs/src Module name: src Changes by: ian@sourceware.org 2011-06-29 14:43:08 Modified files: gold : ChangeLog symtab.cc Log message: PR gold/12818 * symtab.cc (Symbol::should_add_dynsym_entry): Don't add undefined symbols which are not used in a relocation. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/ChangeLog.diff?cvsroot=src&r1=1.773&r2=1.774 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gold/symtab.cc.diff?cvsroot=src&r1=1.155&r2=1.156
Fixed in the development sources. Thanks for noticing it.