[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/26358] New: --wrap: the special rule for "undefined symbol" is i
From: |
i at maskray dot me |
Subject: |
[Bug ld/26358] New: --wrap: the special rule for "undefined symbol" is incompatible with -flto or relocatable links |
Date: |
Sat, 08 Aug 2020 23:49:02 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=26358
Bug ID: 26358
Summary: --wrap: the special rule for "undefined symbol" is
incompatible with -flto or relocatable links
Product: binutils
Version: unspecified
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: i at maskray dot me
Target Milestone: ---
The manpage says
> Only undefined references are replaced by the linker. So, translation unit
> internal references to symbol are not resolved to "__wrap_symbol". In the
> next example, the call to "f" in "g" is not resolved to "__wrap_f".
The "undefined reference" rule can cause different views in non-LTO and LTO (or
-r).
>a.c<<e cat
int foo();
int main() { return foo(); }
e
>b.c<<e cat
int foo() { return 1; }
e
>c.c<<e cat
int __wrap_foo() { return 2; }
e
gcc -fuse-ld=bfd a.c b.c c.c -Wl,--wrap=foo -o a
gcc -fuse-ld=bfd -flto a.c b.c c.c -Wl,--wrap=foo -o a.lto
gcc -fuse-ld=bfd a.c b.c c.c -r -o a.ro && gcc -fuse-ld=bfd a.ro -o rel
./a returns 2 while both a.lto and rel return 1.
# -fuse-ld=gold has the same issue.
In the non-LTO case, the symbol in a.o is essentially changed to __wrap_foo and
then bound to the definition in c.o
In the relocatable case and the LTO case, foo is defined, so it is not renamed
to __wrap_foo. The definition in b.o is picked.
I think the majority of use cases use --wrap for an external definition, so
this strange behavior doesn't really matter. LLD's --wrap is implemented in
such a way that LTO, non-LTO and relocatable links behave the same:
--wrap is handled after all other symbol resolution steps. Symbol definitions
are not affected (i.e. the section order is unchanged: main,foo,__wrap_foo).
The symbol table of each object file is mangled (foo -> __wrap_foo; __real_foo
-> foo) so that all relocations to foo or __real_foo will be redirected.
--
You are receiving this mail because:
You are on the CC list for the bug.
- [Bug ld/26358] New: --wrap: the special rule for "undefined symbol" is incompatible with -flto or relocatable links,
i at maskray dot me <=