[PATCH] D35944: [ELF] Disable relocation validation when targeting weak undefined symbols
ben via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 31 14:09:32 PDT 2017
bd1976llvm added a comment.
In https://reviews.llvm.org/D35944#824267, @ruiu wrote:
> Yeah. If the ELF specification says that unresolved weak symbols must be handled as address zero, and if address zero is not representable for some relocation, then I think the logical consequence is we should report it as error.
Hi Rui,
Although this is being abandoned I wanted to point out that the behaviour of either ignoring the overflowing relocation or not performing the validation is correct and lld's current behavior is broken.
To see why consider the following example:
#pragma weak foo
void foo();
void main() {if (&foo) {foo();}}
Here I only want to call foo if there is a declaration. To do this I am using the "pragma weak" feature. The documentation for the feature states:
> #pragma weak symbol
> This pragma declares symbol to be weak, as if the declaration had the attribute of the same name. The pragma may appear before or after the declaration of symbol. It is not an error for symbol to never be defined at all.
However, with the current behavior of lld if I link this program at high address (e.g: lld main.o -Ttext=0xBADBADBAD) then lld errors with a relocation overflow error - lld, currently, breaks the "pragma weak" feature which guarantees that "it is not an error for the symbol to never be defined at all".
https://reviews.llvm.org/D35944
More information about the llvm-commits
mailing list