[PATCH v2] aarch64: Emit jump slot for conditional branches to weak_undef

Fangrui Song i@maskray.me
Sun May 17 21:54:03 GMT 2020


On Sat, May 16, 2020 at 8:42 PM Siddhesh Poyarekar <siddhesh@gotplt.org> wrote:
>
> On 16/05/20 16:43, Wilco Dijkstra wrote:
> > Hi Siddhesh,
> >
> > So how does this work if the PLT slot is out of range? Or if the section is larger than
> > the maximum range of the conditional branch? It seems to me doing this will create
> > new branch range issues.
>
> Not really, the branch range issues were already there.  Out of range
> targets will generate an error like they do for non-PLT conditional
> branches.  My understanding is that we do not extend range of
> conditional branches by choice.  If range extension is desirable for
> conditional branches too, I can post that as a follow-up fix.  In fact
> anything that makes the conditional and unconditional branch behaviour
> similar would simplify the code; that includes replacing branches to
> weak_undef targets with a NOP.
>
> This patch only makes the behaviour of conditional branches with
> non-weak undefined symbols[1] a bit more sane and in line with lld.
>
> Siddhesh
>
> [1] I just noticed I wrote weak_undef in the subject line; that's wrong
> and I'll fix that up to just "undefined" before committing.

Yes, LLD resolves such relocations referencing an undefined weak
symbol to the next instruction.
https://github.com/llvm/llvm-project/blob/master/lld/ELF/InputSection.cpp#L543

Is there a better way organizing ld/testsuite/ld-aarch64/emit-relocs-*
tests 😀 ? We've now reached 560...

A test like (https://github.com/llvm/llvm-project/blob/master/lld/test/ELF/aarch64-undefined-weak.s)

.weak target

.globl _start
_start:
 b target
 bl target
 b.eq target
 cbz x1, target

in -no-pie and -shared modes can provide enough coverage.


More information about the Binutils mailing list