Issue 238427
Summary [ORC][ELF] TLS subsections are not registered with the runtime
Labels new issue
Assignees
Reporter cyx-6
    Loading an ELF object with TLS in `.tdata.*` or `.tbss.*` through `ELFNixPlatform` can fail on first access even though TLS relocations were resolved:

```text
orc runtime error: No thread local data section for key
```

In the downstream reproducer this is followed by a null TLS pointer and SIGSEGV. Ordinary canonical-section TLS and loading the same code through the system shared-library loader work.

### Environment and trigger

Confirmed on Linux AArch64 with LLVM 23.1.1 through an ORC object-file loader. GCC/NVCC COMDAT inline-function statics and `-fdata-sections` can emit TLS subsections. This is a CPU TLS issue; CUDA is not required to reproduce it.

The affected registration path is also present at LLVM main base `32dbc53c2ae4cc795e97250b5d027dc99d0ec9c6`.

### Reproducer and expected behavior

The proposed regression is [tls-subsections.cpp](https://github.com/cyx-6/llvm-project/blob/eddb661a45c422a5c859f9628ebdc215bacf5312/compiler-rt/test/orc/TestCases/Linux/Generic/tls-subsections.cpp). Save that file and use a Linux LLVM build with the ORC runtime:

```sh
# LLVM_BIN: directory containing the LLVM tools
# ORC_RT: absolute path to the built ORC runtime archive for the host target
"$LLVM_BIN/clang++" -fPIC -fdata-sections -c tls-subsections.cpp -o tls-subsections.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" tls-subsections.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" -slab-allocate=1MB tls-subsections.o
"$LLVM_BIN/clang++" -fPIC -fdata-sections -DWITH_CANONICAL -c tls-subsections.cpp -o tls-mixed.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" tls-mixed.o
"$LLVM_BIN/llvm-jitlink" -orc-runtime="$ORC_RT" -slab-allocate=1MB tls-mixed.o
```

Expected: all runs return zero, with initialized and zero-initialized TLS values preserved and subsequent writes visible. The regression covers subsection-only and mixed canonical/subsection objects, inline COMDAT TLS, and GNU linkonce TLS names.

The reported pre-fix crash 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::addEHAndTLVSupportPasses` only registers sections named exactly `.tdata` and `.tbss`. Descriptors for TLS in subsections therefore have no registered template range.

PR #236373 merges conventional `.tdata.*`, `.tbss.*`, `.gnu.linkonce.td.*`, and `.gnu.linkonce.tb.*` sections into their canonical sections before pruning and allocation, preserving blocks, symbols, contents, and alignment.

This is independent of the per-JITDylib pthread-key bug addressed by #236374. Both arose from the object-file loading use case in #175981.

The corresponding downstream fix passed remote AArch64 validation. [Official CI for the current PR revision](https://github.com/llvm/llvm-project/actions/runs/40696546894) passes on Linux, Windows, and macOS arm64.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to