<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - LLVM and binutils disagree about values of R_AARCH64_TLS_DTPMOD64 and R_AARCH64_TLS_DTPREL64"
href="https://bugs.llvm.org/show_bug.cgi?id=40507">40507</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM and binutils disagree about values of R_AARCH64_TLS_DTPMOD64 and R_AARCH64_TLS_DTPREL64
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: AArch64
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rprichard@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, peter.smith@linaro.org, Ties.Stuij@arm.com
</td>
</tr></table>
<p>
<div>
<pre>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 <a href="https://reviews.freebsd.org/rS341738">https://reviews.freebsd.org/rS341738</a>. 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:
<a href="https://android-review.googlesource.com/c/platform/bionic/+/886116">https://android-review.googlesource.com/c/platform/bionic/+/886116</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>