[PATCH] D35544: [COFF, ARM64] Force ADRP relocations
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 18 12:39:32 PDT 2017
mstorsjo added a comment.
In https://reviews.llvm.org/D35544#812979, @t.p.northover wrote:
> > I'd be interested in knowing why this isn't done by default (i.e. why this doesn't need to be done at all for MachO) btw, if someone has got time to explain.
>
> I'm pretty sure that's a bug, I get the wrong answer when I actually try out this function on iOS:
>
> .text
> .global _foo
> .p2align 12
> _foo:
> .fill 1023, 4, 0xd503201f
> adrp x0, Lthere
> Lthere:
> ret
>
>
> I suspect it hasn't come up on MachO because CodeGen never used ADRP to address objects in the __text section so you need assembly to trigger it.
I did a quick test like this:
static int the_func(int a);
void *get_func(void) {
return the_func;
}
static int the_func(int a) {
return 2*a;
}
and got this:
$ clang test.c -c -o test.o -O3 -target arm64-apple-darwin
$ llvm-objdump -d -r test.o
test.o: file format Mach-O arm64
Disassembly of section __TEXT,__text:
ltmp0:
0: 00 00 00 90 adrp x0, #0
0000000000000000: ARM64_RELOC_PAGE21 _the_func
4: 00 00 00 91 add x0, x0, #0
0000000000000004: ARM64_RELOC_PAGEOFF12 _the_func
8: c0 03 5f d6 ret
_the_func:
c: 00 78 1f 53 lsl w0, w0, #1
10: c0 03 5f d6 ret
So it seems to me like it actually does use ADRP, but probably via some other codepath, since it does generate a relocation. But fixing it for handwritten assembly obviously also is worthwhile.
> So would you mind putting that function into the base AArch64AsmBackend?
Sure, will do.
https://reviews.llvm.org/D35544
More information about the llvm-commits
mailing list