From ae598863db1b09e1e9dfcc0b8a696dc7c508bb89 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Wed, 31 Jul 2019 14:42:57 +0000 Subject: [PATCH] [AARCH64] Switch relocations R_AARCH64_TLS_TPREL64 and R_AARCH64_DTPMOD64 The ELF for the Arm 64-bit Architecture document originally specified R_AARCH64_TLS_DTPREL64 = 0x404 R_AARCH64_TLS_DTPMOD64 = 0x405 LLVM correctly followed the document. Unfortunately in binutils these two codes were reversed: R_AARCH64_TLS_DTPMOD64 = 0x404 R_AARCH64_TLS_DTPREL64 = 0x405 Given that binaries had shipped this change has become the defacto standard interpretation of these relocation codes for any toolchain that wanted to remain compatible with GNU. To recognize this the latest version of the ABI document has renamed the relocations to R_AARCH64_TLS_IMPDEF1 and R_AARCH64_TLS_IMPDEF2 permitting a toolchain to choose between the two relocation types, and recommending that toolchains follow the GNU interpretation for maximum compatibility. Given that upstream llvm has never implemented the standard TLS model for AArch64 so we have no binary legacy, synchronize with GCC so that we don't create incompatible objects in the future. So far the only visible change is in llvm-readobj as it can decode these relocations. Tthis change will mean that llvm-readobj decodes the same way as GNU readelf. fixes PR40507 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@367437 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/BinaryFormat/ELFRelocs/AArch64.def | 7 +++++-- test/tools/llvm-readobj/Inputs/relocs.py | 4 ++-- test/tools/llvm-readobj/reloc-types-elf-aarch64.test | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/llvm/BinaryFormat/ELFRelocs/AArch64.def b/include/llvm/BinaryFormat/ELFRelocs/AArch64.def index 4afcd7d1f09..c8364133e31 100644 --- a/include/llvm/BinaryFormat/ELFRelocs/AArch64.def +++ b/include/llvm/BinaryFormat/ELFRelocs/AArch64.def @@ -124,8 +124,11 @@ ELF_RELOC(R_AARCH64_COPY, 0x400) ELF_RELOC(R_AARCH64_GLOB_DAT, 0x401) ELF_RELOC(R_AARCH64_JUMP_SLOT, 0x402) ELF_RELOC(R_AARCH64_RELATIVE, 0x403) -ELF_RELOC(R_AARCH64_TLS_DTPREL64, 0x404) -ELF_RELOC(R_AARCH64_TLS_DTPMOD64, 0x405) +// 0x404 and 0x405 are now R_AARCH64_TLS_IMPDEF1 and R_AARCH64_TLS_IMPDEF2 +// We follow GNU and define TLS_IMPDEF1 as TLS_DTPMOD64 and TLS_IMPDEF2 as +// TLS_DTPREL64 +ELF_RELOC(R_AARCH64_TLS_DTPMOD64, 0x404) +ELF_RELOC(R_AARCH64_TLS_DTPREL64, 0x405) ELF_RELOC(R_AARCH64_TLS_TPREL64, 0x406) ELF_RELOC(R_AARCH64_TLSDESC, 0x407) ELF_RELOC(R_AARCH64_IRELATIVE, 0x408) diff --git a/test/tools/llvm-readobj/Inputs/relocs.py b/test/tools/llvm-readobj/Inputs/relocs.py index 8e621cef5cd..d0a7341dcb6 100644 --- a/test/tools/llvm-readobj/Inputs/relocs.py +++ b/test/tools/llvm-readobj/Inputs/relocs.py @@ -710,8 +710,8 @@ class Relocs_Elf_AArch64(Enum): R_AARCH64_GLOB_DAT = 0x401 R_AARCH64_JUMP_SLOT = 0x402 R_AARCH64_RELATIVE = 0x403 - R_AARCH64_TLS_DTPREL64 = 0x404 - R_AARCH64_TLS_DTPMOD64 = 0x405 + R_AARCH64_TLS_DTPMOD64 = 0x404 + R_AARCH64_TLS_DTPREL64 = 0x405 R_AARCH64_TLS_TPREL64 = 0x406 R_AARCH64_TLSDESC = 0x407 R_AARCH64_IRELATIVE = 0x408 diff --git a/test/tools/llvm-readobj/reloc-types-elf-aarch64.test b/test/tools/llvm-readobj/reloc-types-elf-aarch64.test index ba9cc7da65c..f50668c3539 100644 --- a/test/tools/llvm-readobj/reloc-types-elf-aarch64.test +++ b/test/tools/llvm-readobj/reloc-types-elf-aarch64.test @@ -122,8 +122,8 @@ # CHECK: Type: R_AARCH64_GLOB_DAT (1025) # CHECK: Type: R_AARCH64_JUMP_SLOT (1026) # CHECK: Type: R_AARCH64_RELATIVE (1027) -# CHECK: Type: R_AARCH64_TLS_DTPREL64 (1028) -# CHECK: Type: R_AARCH64_TLS_DTPMOD64 (1029) +# CHECK: Type: R_AARCH64_TLS_DTPMOD64 (1028) +# CHECK: Type: R_AARCH64_TLS_DTPREL64 (1029) # CHECK: Type: R_AARCH64_TLS_TPREL64 (1030) # CHECK: Type: R_AARCH64_TLSDESC (1031) # CHECK: Type: R_AARCH64_IRELATIVE (1032) @@ -382,9 +382,9 @@ Sections: - Offset: 0x00000000000001D4 Type: R_AARCH64_RELATIVE - Offset: 0x00000000000001D8 - Type: R_AARCH64_TLS_DTPREL64 - - Offset: 0x00000000000001DC Type: R_AARCH64_TLS_DTPMOD64 + - Offset: 0x00000000000001DC + Type: R_AARCH64_TLS_DTPREL64 - Offset: 0x00000000000001E0 Type: R_AARCH64_TLS_TPREL64 - Offset: 0x00000000000001E4 -- 2.50.0