Commit Graph

4 Commits

Author SHA1 Message Date
Ben Dunbobbin aaeba6483f [LLD] [TEST] Add test case for patching an absolute relocation to a weak undef
I noticed that we had this case in our internal testsuite but couldn't find it in LLD's tests.

This adds that case.

Differential Revision: https://reviews.llvm.org/D110716
2021-10-11 13:14:45 +01:00
Fangrui Song 7b06bfc49e [ELF] -pie: produce dynamic relocations for absolute relocations referencing undef weak
See the comment for my understanding of -no-pie and -shared expectation.
-no-pie has freedom on choices. We choose dynamic relocations to be consistent
with the handling of GOT-generating relocations.

Note: GNU ld has arch-varying behaviors and its x86 -pie has a very
complex rule:
if there is at least one GOT-generating or PLT-generating relocation and
-z dynamic-undefined-weak (enabled by default) is in effect, generate a
dynamic relocation.

We don't emulate its rule.

Reviewed By: peter.smith

Differential Revision: https://reviews.llvm.org/D105164
2021-06-30 09:43:28 -07:00
Fangrui Song e05ca38101 [ELF] Don't emit dynamic relocations with weak undef in writable sections
In processRelocAux(), our handling of 1) link-time constant and 2) weak
undef is the same, so put them together to simplify the logic.

This moves the weak undef code around. The result is that: in a writable
section (or -z notext), we will no longer emit dynamic relocations for
weak undefined symbols.

The new behavior seems to match GNU linkers, and improves consistency
with the case of a readonly section.

The condition `!Config->Shared` was there probably because it is common
for a -shared link not to specify full dependencies. Keep it now but we
may revisit the decision in the future.

gABI says:

> The behavior of weak symbols in areas not specified by this document is
> implementation defined. Weak symbols are intended primarily for use in
> system software. Applications using weak symbols are unreliable since
> changes in the runtime environment might cause the execution to fail.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D63003

llvm-svn: 363399
2019-06-14 14:09:15 +00:00
Rafael Espindola 4b2350d79b Produce relocations with weak undef if the section is RW.
If a section is RW there is no reason to drop a relocation with a weak
undefined symbol.

llvm-svn: 321684
2018-01-03 01:24:58 +00:00