This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Linker symbol resolution differences with LTO.
- From: Shankar Easwaran <shankarke at gmail dot com>
- To: binutils at sourceware dot org
- Date: Tue, 8 Dec 2015 00:19:06 +0000 (UTC)
- Subject: Linker symbol resolution differences with LTO.
- Authentication-results: sourceware.org; auth=none
Why is symbol resolution different when you use LTO versus a non LTO build.
Test :-
cat > 1.c << \!
int bar() {
return foo();
}
__attribute__((weak)) int foo() {
return 0;
}
!
cat > 2.c << \!
int baz() {
return foo();
}
__attribute__((weak)) int foo() {
return 1;
}
!
gcc -c 1.c -ffunction-sections -flto
gcc -c 2.c -ffunction-sections
# Linker picks the definition of foo from 2.o
ld 1.o 2.o -y foo
2.o: definition of foo
gcc -c 1.c -ffunction-sections
gcc -c 2.c -ffunction-sections
# Linker picks the definition of foo from 1.o
ld 1.o 2.o -y foo
1.o: definition of foo
This will confuse a lot of users moving to LTO builds.
Changing symbol visibility complicates things even more.
Can this be fixed (or) is there a user specific way of controlling behavior
?