https://sourceware.org/bugzilla/show_bug.cgi?id=33260
Bug ID: 33260
Summary: ld should emit relative relocations for defined,
protected symbols
Product: binutils
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: thiago at kde dot org
Target Milestone: ---
ld is currently emitting relocations by name for addresses of protected symbols
defined in this library, which is unnecessary, as the symbols cannot be
interposed. This is related to a number of previous copy-relocation problems,
but different, because it happens on stored addresses, not calls from code.
Testcase:
$ cat a.c
#ifdef USE_PROTECTED
# define EXPORT __attribute__((visibility("protected")))
#else
# define EXPORT __attribute__((visibility("default")))
#endif
#define EXPORT_OVERRIDABLE __attribute__((visibility("default"), weak))
EXPORT void my_func() {}
EXPORT_OVERRIDABLE void my_func_overridable() {}
$ cat b.c
#ifdef USE_PROTECTED
# define EXPORT __attribute__((visibility("protected")))
#else
# define EXPORT __attribute__((visibility("default")))
#endif
#define EXPORT_OVERRIDABLE __attribute__((visibility("default"), weak))
EXPORT void my_func(void);
EXPORT_OVERRIDABLE void my_func_overridable(void);
static void (*vtable[])(void) = {
&my_func, &my_func_overridable
};
void *f() { my_func(); return vtable; }
$ cc -fPIC -DUSE_PROTECTED -O2 -fvisibility=hidden -mno-direct-extern-access
-shared -o a.so a.c b.c
The relocations emitted are:
$ eu-readelf --dyn-syms a.so
Symbol table [ 3] '.dynsym' contains 7 entries:
1 local symbol String table: [ 4] '.dynstr'
Num: Value Size Type Bind Vis Ndx Name
0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UNDEF
1: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF
_ITM_deregisterTMCloneTable
2: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF __gmon_start__
3: 0000000000000000 0 NOTYPE WEAK DEFAULT UNDEF
_ITM_registerTMCloneTable
4: 0000000000000000 0 FUNC WEAK DEFAULT UNDEF
__cxa_finalize@GLIBC_2.2.5 (2)
5: 0000000000001100 1 FUNC GLOBAL PROTECTED 11 my_func
6: 0000000000001110 1 FUNC WEAK DEFAULT 11
my_func_overridable
$ objdump -R a.so
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
0000000000003e18 R_X86_64_RELATIVE *ABS*+0x00000000000010f0
0000000000003e20 R_X86_64_RELATIVE *ABS*+0x00000000000010b0
0000000000004000 R_X86_64_RELATIVE *ABS*+0x0000000000004000
0000000000003fc8 R_X86_64_GLOB_DAT _ITM_deregisterTMCloneTable@Base
0000000000003fd0 R_X86_64_GLOB_DAT __gmon_start__@Base
0000000000003fd8 R_X86_64_GLOB_DAT _ITM_registerTMCloneTable@Base
0000000000003fe0 R_X86_64_GLOB_DAT __cxa_finalize@GLIBC_2.2.5
0000000000004010 R_X86_64_64 my_func@@Base
0000000000004018 R_X86_64_64 my_func_overridable@@Base
The two R_X86_64_64 relocations at the end correspond to the vtable array: the
entry for the "my_func" should have been a R_X86_64_RELATIVE because the symbol
is protected.
Note how the call to it was resolved without the need for a relocation:
$ objdump -d a.so | sed -n '/<f>/,/^$/p'
0000000000001120 <f>:
1120: 48 83 ec 08 sub $0x8,%rsp
1124: e8 d7 ff ff ff call 1100 <my_func>
1129: 48 8d 05 e0 2e 00 00 lea 0x2ee0(%rip),%rax # 4010
<my_func@@Base+0x2f10>
1130: 48 83 c4 08 add $0x8,%rsp
1134: c3 ret
--
You are receiving this mail because:
You are on the CC list for the bug.