https://bugs.llvm.org/show_bug.cgi?id=40507
Bug ID: 40507
Summary: LLVM and binutils disagree about values of
R_AARCH64_TLS_DTPMOD64 and R_AARCH64_TLS_DTPREL64
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: AArch64
Assignee: unassignedb...@nondot.org
Reporter: rprich...@google.com
CC: arnaud.degrandmai...@arm.com,
llvm-bugs@lists.llvm.org, peter.sm...@linaro.org,
ties.st...@arm.com
Both LLVM (ELFRelocs/AArch64.def) and the AArch64 ELF ABI spec (IHI0056B) list
the values of the R_AARCH64_TLS_DTPREL64 and R_AARCH64_TLS_DTPMOD64 relocations
as:
- R_AARCH64_TLS_DTPREL64 == 1028
- R_AARCH64_TLS_DTPMOD64 == 1029
binutils and glibc (and other projects) instead use these flipped values:
- R_AARCH64_TLS_DTPMOD64 == 1028
- R_AARCH64_TLS_DTPREL64 == 1029
The relocations are used in executables and shared objects, and they're
relocated by a dynamic loader. AFAIK, the effect on LLVM is minimal because
Clang and lld only implement the TLSDESC scheme for dynamic TLS accesses, which
use R_AARCH64_TLSDESC relocations instead of DTPMOD/DTPREL.
The disagreement is observable when using gcc's -mtls-dialect=trad mode with
llvm-readelf, though:
$ cat test.c
__thread int somevar;
int bump() {
return ++somevar;
}
$ aarch64-linux-gnu-gcc-7 test.c -fpic -shared -mtls-dialect=trad
$ aarch64-linux-gnu-readelf -rW a.out | grep TLS
0000000000010fd0 0000000a00000404 R_AARCH64_TLS_DTPMOD64 0000000000000000
somevar + 0
0000000000010fd8 0000000a00000405 R_AARCH64_TLS_DTPREL64 0000000000000000
somevar + 0
$ llvm-readelf -r a.out | grep TLS
0000000000010fd0 0000000a00000404 R_AARCH64_TLS_DTPREL64 0000000000000000
somevar + 0
0000000000010fd8 0000000a00000405 R_AARCH64_TLS_DTPMOD64 0000000000000000
somevar + 0
musl is using the same relocation values as glibc.
FreeBSD recently added support for these two relocations using the glibc values
in https://reviews.freebsd.org/rS341738. It adds a comment:
/*
* !!! BEWARE !!!
* ARM ELF ABI defines TLS_DTPMOD64 as 1029, and TLS_DTPREL64
* as 1028. But actual bfd linker and the glibc RTLD linker
* treats TLS_DTPMOD64 as 1028 and TLS_DTPREL64 1029.
*/
case R_AARCH64_TLS_DTPREL64: /* efectively is TLS_DTPMOD64 */
*where += (Elf_Addr)defobj->tlsindex;
break;
case R_AARCH64_TLS_DTPMOD64: /* efectively is TLS_DTPREL64 */
*where += (Elf_Addr)(def->st_value + rela->r_addend);
break;
FWIW: I'm adding arm64 ELF TLS support to Bionic/Android. For now, I've omitted
the DTPMOD/DTPREL relocations on arm64:
https://android-review.googlesource.com/c/platform/bionic/+/886116
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs