Closed
Description
We need to find a way to handle the following pattern, specifically in case where foo() is not defined at link time:
int foo() __attribute__((weak));
int main() {
if (&foo) {
return foo();
}
return 0;
}
Currently llvm will generate a call instruction to foo and a relocation at the call site to inject the function index. If foo turns out to be undefined at link time there is no valid function which the linker can insert.
@NWilson and I have discuess a few possible options (see https://reviews.llvm.org/D44028):
- Have the linker error out. This seems bad as the above code is valid and should link.
- Have the linker generate a synthetic function that abort (i.e. contains only an unreachable) and use the index of the synthetic function here. The doenside is that this adds complexity to the linker and that it would need to generate a new function for each signature.
- Have llc always emit call_indirect when calling weak references. Then bad FUNCTION_INDEX relocations against weak symbols in the object format.
(3) seems like the nicest so long as it is feasilbe in llvm and that use increased use of call_indirect doesn't cause a performance drop. My guess is that weak symbols are not that common, but it also seems valid to assume that declaring a symbol as weak should not have a runtime overhead.
Metadata
Metadata
Assignees
Labels
No labels