[llvm-bugs] [Bug 44451] New: lld generates strange and incorrect thunk for aarch64 weak function call
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jan 3 03:09:03 PST 2020
https://bugs.llvm.org/show_bug.cgi?id=44451
Bug ID: 44451
Summary: lld generates strange and incorrect thunk for aarch64
weak function call
Product: lld
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: john.brawn at arm.com
CC: llvm-bugs at lists.llvm.org, peter.smith at linaro.org
If you have:
example.c
extern void weakfn() __attribute__((weak));
int call_weak() {
weakfn();
return 0;
}
script.ld
SECTIONS
{
.text 0x10000000 : { *(.text) }
}
and do:
clang --target=aarch64-none-eabi example.c -c -O1
ld.lld -T script.ld example.o
llvm-objdump --disassemble a.out
the llvm-objdump disassembly is:
0000000010000000 call_weak:
10000000: fd 7b bf a9 stp x29, x30, [sp, #-16]!
10000004: fd 03 00 91 mov x29, sp
10000008: 04 00 00 94 bl #16
<__AArch64AbsLongThunk_weakfn>
1000000c: e0 03 1f 2a mov w0, wzr
10000010: fd 7b c1 a8 ldp x29, x30, [sp], #16
10000014: c0 03 5f d6 ret
0000000010000018 __AArch64AbsLongThunk_weakfn:
10000018: 50 00 00 58 ldr x16, #8
1000001c: 00 02 1f d6 br x16
0000000010000020 $d:
10000020: 00 00 00 00 .word 0x00000000
10000024: 00 00 00 00 .word 0x00000000
The weak function call has been converted into a branch to a thunk which
branches to address zero, which is both strange and wrong.
Reducing the address of .text in the linker script to 0x1000000 gives something
more like what I'd expect, i.e. a branch to the next instruction (though a nop
would be better):
0000000001000000 call_weak:
1000000: fd 7b bf a9 stp x29, x30, [sp, #-16]!
1000004: fd 03 00 91 mov x29, sp
1000008: 01 00 00 94 bl #4 <call_weak+0xc>
100000c: e0 03 1f 2a mov w0, wzr
1000010: fd 7b c1 a8 ldp x29, x30, [sp], #16
1000014: c0 03 5f d6 ret
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200103/becd0019/attachment.html>
More information about the llvm-bugs
mailing list