This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] fix PR22408: clang no longer bootstraps itself on AArch64 linux
ClosedPublic

Authored by kristof.beyls on Feb 16 2015, 12:02 PM.

Details

Reviewers
t.p.northover
Summary

This patch fixes PR22408.

As is described at http://llvm.org/bugs/show_bug.cgi?id=22408, the GNU linkers
ld.bfd and ld.gold currently only support a subset of the whole range of AArch64
ELF TLS relocations. Furthermore, they assume that some of the code sequences to
access thread-local variables are produced in a very specific sequence.
When the sequence is not as the linker expects, it can silently mis-relaxe/mis-optimize
the instructions.
Even if that wouldn't be the case, it's good to produce the exact sequence,
as that ensures that linkers can perform optimizing relaxations.

This patch:

  • implements support for 16MiB TLS area size instead of 4GiB TLS area size. Ideally clang would grow an -mtls-size option to allow support for both, but that's not part of this patch.
  • by default doesn't produce local dynamic access patterns, as even modern ld.bfd and ld.gold linkers do not support the associated relocations. An option (-aarch64-elf-ldtls-generation) is added to enable generation of local dynamic code sequence, but is off by default. Alternatively, I think that LLVM could fixup the local dynamic fixups itself, instead of producing relocations leaving the work for the linker, but that didn't seem straightforward to do.
  • makes sure that the exact expected code sequence for local dynamic and general dynamic accesses is produced, by making use of a new pseudo instruction. The patch also removes two (AArch64ISD::TLSDESC_BLR, AArch64ISD::TLSDESC_CALL) pre-existing AArch64-specific pseudo SDNode instructions that are superseded by the new one (TLSDESC_CALLSEQ).

Diff Detail

Repository
rL LLVM

Event Timeline

kristof.beyls retitled this revision from to [AArch64] fix PR22408: clang no longer bootstraps itself on AArch64 linux.
kristof.beyls updated this object.
kristof.beyls edited the test plan for this revision. (Show Details)
kristof.beyls added a reviewer: t.p.northover.
kristof.beyls set the repository for this revision to rL LLVM.
kristof.beyls added a subscriber: Unknown Object (MLST).

I've cleaned up one comment, and removed 3 FIXME's that after checking were not necessary:

  • For local exec, we obviously don't need to produce fixed sequences as the linker won't relax that any further.
  • For initial exec, no fixed sequence is necessary, as linkers don't need to and won't (checked in ld.bfd and ld.gold) assume a fixed sequence of instructions when relaxing from initial exec to local exec.
  • The FIXME removed from the regression test should have been removed already in the initial patch: I had fixed up that test already.
t.p.northover edited edge metadata.Mar 2 2015, 6:58 PM

It makes me sad, but there's nothing structurally wrong with the patch that I could see. Just that it's working around a wilfully broken linker that no-one even seems to intend to fix.

So, reluctantly, LGTM.

lib/Target/AArch64/AArch64InstrInfo.td
1066

It definitely shouldn't, unfortunately it probably is the simplest implementation, and this entire hack is obscene enough that I don't think it's worth polluting any more of the backend with it than we have too.

t.p.northover accepted this revision.Mar 2 2015, 7:00 PM
t.p.northover edited edge metadata.

So, reluctantly, LGTM.

Actually, scratch that. Looks necessary to me. This is in no way good, even as an idiomatic empty formality.

This revision is now accepted and ready to land.Mar 2 2015, 7:00 PM
emaste added a subscriber: emaste.Mar 3 2015, 9:46 PM