https://bugzilla.novell.com/show_bug.cgi?id=694266
https://bugzilla.novell.com/show_bug.cgi?id=694266#c0
Summary: default gcc linker failed to remove all dead code
dependency properly
Classification: openSUSE
Product: openSUSE 11.4
Version: Factory
Platform: x86-64
OS/Version: openSUSE 11.4
Status: NEW
Severity: Normal
Priority: P5 - None
Component: Development
AssignedTo: pth@novell.com
ReportedBy: grabli_2005@mail.ru
QAContact: qa@suse.de
Found By: ---
Blocker: ---
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64;
Trident/5.0)
When linking shared object, only way I`ve found to remove dead code and export
only needed symbols is visibility control through
__attribute__((visibility("default\hidden"))). But it still leave garbage at
least in import(unresolved) symbol table. Here small example:
---
#include
#include
#include
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;
}
---
Compile it using switches:
gcc -O3 -Wl,-x,-gc-sections,-s -fpic -flto -shared \
-fdata-sections -ffunction-sections \
-fvisibility-inlines-hidden -fvisibility=hidden \
-o test.so test.cpp
Now check symbols using readelf -s \ objdump -T:
Symbol table '.dynsym' contains 11 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
2: 00000000000004b8 0 FUNC GLOBAL DEFAULT 10 _init
3: 000000000000061c 16 FUNC GLOBAL DEFAULT 13 _fini
4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND getcwd@GLIBC_2.2.5
(2)
5: 0000000000000000 0 FUNC WEAK DEFAULT UND
__cxa_finalize@GLIBC_2.2.5 (2)
6: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
7: 00000000000005c0 23 FUNC GLOBAL DEFAULT 12 func
8: 00000000000018d0 0 NOTYPE GLOBAL DEFAULT ABS _edata
9: 00000000000018d0 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
10: 00000000000018e0 0 NOTYPE GLOBAL DEFAULT ABS _end
As we can see getcwd dependency still here, while func2 function properly
eliminated with "test_string" string dependency (can check it in binary
editor). It produce false dependency on other shared libs and increase shared
object size.
I`ve also try -retain-symbols-file linker switch without luck, it seems with -s
switch -retain-symbols-file have no effect at all.
Also -flto makes shared object smaller, while symbol table remains the same. I
don`t how reproduce same size without -flto, it seems without it linker leaves
some other garbage in other tables\sections.
All tested on gcc 3.5 & 3.6.
Reproducible: Always
Steps to Reproduce:
1. Compile c++ sample above
2. Check for getcwd function dependency
Actual Results:
getcwd function dependency remains
Expected Results:
getcwd function dependency eliminated, without -flto linker generates
compareble size shared object as with -flto in example above.
--
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.