Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Allow relative relocs against absolute symbols
In the previous commit (c325cc0), I argued that PC-relative relocations are not representable if they refer absolute symbols, and I made a change so that such relocations are handled as errors. Even though what I did is technically correct, that results in a failure of an important use case of the weak undefined symbol. Here is why. If you have an weak undefined symbol `foo`, you would use it as follows: if (foo) foo(); If `foo` is defined (i.e. has an address other than 0), `foo` is called. If `foo` is undefined (i.e. has the address 0), the subsequent CALL instruction will have an offset from the CALL instruction to address 0. That displacement is computed at link-time. If the output is position- independent, the call instruction may not have a correct displacement from address 0 to the instruction at runtime due to base relocation. However, that's not a problem in practice, because the function call is guarded by `if (foo)`, and that will always evaluated to false if `foo` is undefined. Therefore, the faulty `CALL` instruction will never be executed. So, that means we need to relocate PC-relative relocations against absolute symbols even if doing so results in an incorrect result. This patch implement that.
- Loading branch information