This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Linker symbol resolution differences with LTO.


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 
?





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]