Linker symbol resolution differences with LTO.

Shankar Easwaran shankarke@gmail.com
Tue Dec 8 00:19:00 GMT 2015


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 
?






More information about the Binutils mailing list