| Issue |
238428
|
| Summary |
[ORC][ELF] TLS storage is duplicated across objects in one JITDylib
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
cyx-6
|
Two ELF objects linked into the same JITDylib can observe different addresses and independent storage for the same resolved TLS symbol within one execution thread.
A downstream shared-counter reproducer returned `[8, 8, 9]` instead of `[8, 9, 10]` when calls alternated between objects. This breaks TLS identity and shared writes across translation units.
### Environment and trigger
Confirmed on Linux AArch64 with LLVM 23.1.1 through an ORC object-file loader. The missing cache insertion is also present at LLVM main base `32dbc53c2ae4cc795e97250b5d027dc99d0ec9c6`.
The issue occurs with canonical `.tdata` / `.tbss` sections and is independent of subsection registration in #236373. No GPU is needed.
### Reproducer and expected behavior
The proposed regression is [tls-multi-object.c](https://github.com/cyx-6/llvm-project/blob/1f62ecc0e5dcf105e32151d72504bf27f44e08a9/compiler-rt/test/orc/TestCases/Linux/Generic/tls-multi-object.c). Save that file and use a Linux LLVM build with the ORC runtime:
```sh
# LLVM_BIN: directory containing the LLVM tools, including split-file
# ORC_RT: absolute path to the built ORC runtime archive for the host target
"$LLVM_BIN/split-file" tls-multi-object.c tls-multi-object
"$LLVM_BIN/clang" -fPIC -c tls-multi-object/main.c -o tls-main.o
"$LLVM_BIN/clang" -fPIC -c tls-multi-object/access.c -o tls-access.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" tls-main.o tls-access.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" -num-threads=2 tls-main.o tls-access.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" -slab-allocate=1MB tls-main.o tls-access.o
```
One object defines initialized and zero-initialized TLS variables; the other accesses them via `extern _Thread_local`. Both must see the same addresses and writes within one thread. A worker thread repeats the checks with independent storage. All runs should return zero.
The reported pre-fix counter mismatch was reproduced in the LLVM 23.1.1 downstream loader. The linked native regression is included in the proposed LLVM-main fix; those are separate validation paths.
### Cause and proposed fix
`ELFNixPlatformPlugin::fixTLVSectionsAndEdges` looks up `JITDylibToPThreadKey`, calls `createPThreadKey()` on a miss, but never inserts the newly created key. Each object consequently receives a different pthread key and per-thread TLV manager.
PR #236374 caches the key and serializes lookup, creation, and insertion under `PlatformMutex`, so concurrent links reuse one key per JITDylib. It also erases the association during JITDylib teardown. Runtime pthread-key reclamation is unchanged.
The corresponding downstream fix passed remote AArch64 multi-object and multi-thread validation. [Official CI for the current PR revision](https://github.com/llvm/llvm-project/actions/runs/40696109555) passes on Linux, Windows, and macOS arm64.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs