Currently, if there are multiple definitions of the same symbol declared has weak linkage, the linker may choose the wrong one when they are compiled with integrated-as.
For example
> cat t1.c __attribute__((weak)) __attribute__((noinline)) int foo() { return 3; } int main() { return foo(); } > cat t2.c __attribute__((weak)) int foo() { return 1; } > ~/Source/install.opt/bin/ibm-clang t2.c t1.c -fintegrated-as && ./a.out; echo $? 3 > ~/Source/install.opt/bin/ibm-clang t2.c t1.c -fno-integrated-as && ./a.out; echo $? 1
This patch fixes the issue.
If the target symbol is a weak label we must not attempt to resolve the fixup directly. Emit a relocation and leave resolution of the final target address to the linker.
Hmm, ok, seems before this change, we assume R_RBR type relocation is only applied to function sections, so that we only need the virtual address of the section because the target function offset in the section are always 0.
Now, we will generate R_RBR for functions that has no own csect, so using section virtual address is now not enough, we also need to consider about the offset of the function in the "big" csect.
This change makes sense to me.