This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add support for the GNU ILP32 ABI
ClosedPublic

Authored by Amanieu on Jan 5 2021, 6:22 PM.

Details

Summary

Add the aarch64[_be]-*-gnu_ilp32 targets to support the GNU ILP32 ABI for AArch64.

The needed codegen changes were mostly already implemented in D61259, which added support for the watchOS ILP32 ABI. The main changes are:

  • Wiring up the new target to enable ILP32 codegen and MC.
  • ILP32 va_list support.
  • ILP32 TLSDESC relocation support.

There was existing MC support for ELF ILP32 relocations from D25159 which could be enabled by passing "-target-abi ilp32" to llvm-mc. This was changed to check for "gnu_ilp32" in the target triple instead. This shouldn't cause any issues since the existing support was slightly broken: it was generating ELF64 objects instead of the ELF32 object files expected by the GNU ILP32 toolchain.

This target has been tested by running the full rustc testsuite on a big-endian ILP32 system based on the GCC ILP32 toolchain.

Diff Detail

Event Timeline

Amanieu created this revision.Jan 5 2021, 6:22 PM
Amanieu requested review of this revision.Jan 5 2021, 6:22 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2021, 6:22 PM

I'm happy to see this change. It has been on my TO DO list for a very long time. I will review it soon.

Amanieu updated this revision to Diff 315849.Jan 11 2021, 10:20 AM

clang-format & clang-tidy fixes

Amanieu updated this revision to Diff 316165.Jan 12 2021, 10:56 AM

In D16213 I introduced the MCTargetOptions argument to the MCAsmBackend constructor, as well as in constructor wrapper functions. This change touched multiple (every, probably) backend. Given the extension to embed the ABI in the Triple, can the MCTargetOptions argument be removed? That shouldn't be in this commit, I think.

I have't checked the new test cases for completeness. I also haven't checked whether there are existing test cases not in this commit that might usefully have "-target-abi=ilp32" changed to "-triple aarch64-none-linux-gnu_ilp32"

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
6952–6953

For all the following comments of the form:
// ... at offset n
perhaps change it to:
// ... at offset m * pointer size
so, for example, the next comment would be
// void *__gr_top at offset 1 * pointer size

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
229

I may be over using "?:", but I think using Explaining Variables (AKA Extract Variable) makes the code clearer.

std::string Endian(LittleEndian ? "e" : "E");
std::string Ptr32(TT.getEnvironment == Triple::GNUILP32 ? "-p:32:32" : "");
return Endian + "-m:e" + Ptr32 + "-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128";
llvm/test/CodeGen/AArch64/ilp32-tlsdesc.ll
23

Should the CHECK-RELOC lines contain more complete checks like arm32-elf-relocs.s, for example, does? That is symbol name and offset.

Amanieu marked 2 inline comments as done.Jan 12 2021, 1:28 PM

In D16213 I introduced the MCTargetOptions argument to the MCAsmBackend constructor, as well as in constructor wrapper functions. This change touched multiple (every, probably) backend. Given the extension to embed the ABI in the Triple, can the MCTargetOptions argument be removed? That shouldn't be in this commit, I think.

That sounds reasonable. After this is accepted I will prepare another diff to revert D16213.

I have't checked the new test cases for completeness. I also haven't checked whether there are existing test cases not in this commit that might usefully have "-target-abi=ilp32" changed to "-triple aarch64-none-linux-gnu_ilp32"

I've converted every existing test case using -target-abi=ilp32 to use the new target triple.

llvm/test/CodeGen/AArch64/ilp32-tlsdesc.ll
23

I mostly copied this test from arm64-tls-dynamic.ll which also only checks the relocation name.

Amanieu updated this revision to Diff 316219.Jan 12 2021, 1:28 PM

LGTM. I think someone else has to approve it.

llvm/lib/Support/Triple.cpp
244

(nit) I'd ignore the previous lint warning and combine lines here.

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
6952–6953

Nice. I like the separate accounting better than what I suggested.

My understanding is that AArch64 gnu_ilp32 support is present in mainline gcc, but not in mainline glibc nor in the mainline linux kernel. My understanding is also that it's unlikely that AArch64 gnu_ilp32 support will be added to mainline glibc or linux kernel anytime soon.
That makes me wonder how useful it is to support AArch64 gnu_ilp32 in mainline LLVM. It seems unlikely that it can be used for linux targets anytime soon. Are there non-linux targets using AArch64 gnu_ilp32?

There isn't any support for ILP32 in the mainline Linux kernel, and there isn't likely to be. However, mainline glibc has had ILP32 support. I don't know the current status.

Amanieu updated this revision to Diff 316960.Jan 15 2021, 8:43 AM

Undo some unnecessary formatting changes.

My understanding is that AArch64 gnu_ilp32 support is present in mainline gcc, but not in mainline glibc nor in the mainline linux kernel. My understanding is also that it's unlikely that AArch64 gnu_ilp32 support will be added to mainline glibc or linux kernel anytime soon.
That makes me wonder how useful it is to support AArch64 gnu_ilp32 in mainline LLVM. It seems unlikely that it can be used for linux targets anytime soon. Are there non-linux targets using AArch64 gnu_ilp32?

ILP32 is used internally in Huawei for some network devices, which run a Linux-based RTOS. Until now they have been using a GCC-based toolchain but we would like to use Rust on the platform, which requires LLVM support.

While kernel and glibc support for ILP32 are unlikely to be supported upstream this is not a concern for LLVM: the ILP32 ABI has a published spec and is supported by mainline GCC.

kristof.beyls accepted this revision.Jan 20 2021, 2:16 AM
This revision is now accepted and ready to land.Jan 20 2021, 2:16 AM
This revision was landed with ongoing or failed builds.Jan 20 2021, 5:36 AM
This revision was automatically updated to reflect the committed changes.

Hi experts:
I am working on compiler-rt to get asan runtime libs for aarch64 ilp32 and I get blocked with https://stackoverflow.com/questions/65806679/llvm-ompiler-rt-sanitizer-not-support-aarch64-ilp32-asan-interceptors-vfork-s-i
I can't tell you how much I appreciate for your reply.