Fix PR22408 - LLVM producing AArch64 TLS relocations that GNU linkers cannot handle...
authorKristof Beyls <kristof.beyls@arm.com>
Wed, 4 Mar 2015 09:12:08 +0000 (09:12 +0000)
committerKristof Beyls <kristof.beyls@arm.com>
Wed, 4 Mar 2015 09:12:08 +0000 (09:12 +0000)
commit78c4ef5120290311f336c4a355e2ff3c583609ae
treec7a5981cbeea5a30a79da97fe9df7cf5ec69ade7
parentb660ece8606b7db70739f36f1b5bd8ac2a2c0398
Fix PR22408 - LLVM producing AArch64 TLS relocations that GNU linkers cannot handle yet.

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.
* 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).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231227 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/AArch64/AArch64AsmPrinter.cpp
lib/Target/AArch64/AArch64CleanupLocalDynamicTLSPass.cpp
lib/Target/AArch64/AArch64ISelLowering.cpp
lib/Target/AArch64/AArch64ISelLowering.h
lib/Target/AArch64/AArch64InstrInfo.td
lib/Target/AArch64/AArch64MCInstLower.cpp
lib/Target/AArch64/Utils/AArch64BaseInfo.h
test/CodeGen/AArch64/arm64-tls-dynamics.ll
test/CodeGen/AArch64/arm64-tls-execs.ll