This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix incorrect relocation encodings for ILP32
AbandonedPublic

Authored by joelkevinjones on Jan 26 2017, 11:11 AM.

Details

Summary

Only effects code where the ABI is "ilp32"

Patch by Joel Jones

Diff Detail

Repository
rL LLVM

Event Timeline

I've checked that the relocation name is correct. I'm a bit suspicious of allowing the fixup_aarch64_ldst_imm12_scale8 in LP32, with a 32-bit sized GOT I think that this is likely to be a programming mistake that we should probably error on. I'm not hugely familiar with lp32 programming so there may be a case for it that I'm missing?

lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
253

I think it is more a bad fixup rather than Bad LP64 relocation. The other error messages are of the form "invalid fixup for ..."
Possible suggestion "invalid fixup for got relative load/store instruction on LP64".

I don't have a particularly strong opinion here though.

266

Is there a case where this fixup is valid in ILP32 given the size of the .got is 32-bits? I think that from your test cases you would expect it for // CHECK: ldr x24, [x23, :got_lo12:sym]
This should probably be an error so that we only accept ldr w24, [x23, :got_lo12:sym].

test/MC/AArch64/arm32-elf-relocs.s
226

The removal of the # has uncommented out these instructions, but I don't see any extra CHECKs. If they are superfluous I recommend removing them.

joelkevinjones added inline comments.Jan 31 2017, 2:56 PM
lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
266

I think you're right, but it does match what the gcc implementation of ilp32 does:

`crb6 % cat ldr-reloc.s

.global foo
.type   foo, %function
ldr x24, [x23, :got_lo12:sym]
ldr w24, [x23, :got_lo12:sym]

crb6 % gcc -mabi=ilp32 -c ldr-reloc.s
crb6 % objdump -rd ldr-reloc.o

ldr-reloc.o: file format elf32-littleaarch64

Disassembly of section .text:

00000000 <.text>:

   0:	f94002f8 	ldr	x24, [x23]
			0: R_AARCH64_P32_LD32_GOT_LO12_NC	sym
   4:	b94002f8 	ldr	w24, [x23]
			4: R_AARCH64_P32_LD32_GOT_LO12_NC	sym

crb6 % gcc -c ldr-reloc.s
crb6 % objdump -rd ldr-reloc.o

ldr-reloc.o: file format elf64-littleaarch64

Disassembly of section .text:

0000000000000000 <.text>:

   0:	f94002f8 	ldr	x24, [x23]
			0: R_AARCH64_LD64_GOT_LO12_NC	sym
   4:	b94002f8 	ldr	w24, [x23]
			4: R_AARCH64_LD64_GOT_LO12_NC	sym`
test/MC/AArch64/arm32-elf-relocs.s
226

Concur

peter.smith added inline comments.Feb 1 2017, 2:59 AM
lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
266

I spoke to a member of our GNU team and they thought that GAS wasn't doing it right either. My weak preference would be for MC to fault it and raise a bug on GAS. If it is rejected then put the compatibility in then. Happy to hear other opinions on this though.

joelkevinjones added inline comments.Feb 1 2017, 8:49 AM
lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
266

I discussed this with Andrew Pinski (who did ILP32 for gcc and the linux kernel) and he came to the same conclusion. I've already filed a defect on gas: https://sourceware.org/bugzilla/show_bug.cgi?id=21098

Thanks for the update, I don't have any more comments.

I haven't abandoned this patch. In working on this one, I've found several issues that I am going to deal with first.

mcrosier resigned from this revision.Mar 6 2017, 1:05 PM
joelkevinjones abandoned this revision.Apr 13 2017, 9:06 PM

This revision is included in an omnibus ILP32 relocation change: https://reviews.llvm.org/D32072