Page MenuHomePhabricator

[ORC][ORC_RT][AArch64] Implement TLS descriptor in ELFNixPlatform.
ClosedPublic

Authored by sunho on Jun 26 2022, 12:33 AM.

Details

Summary

Implements TLS descriptor relocations in JITLink ELF/AARCH64 backend and support the relevant runtime functions in ELFNixPlatform.

Unlike traditional TLS model, TLS descriptor model requires linker to return the "offset" from thread pointer via relocaiton not the actual pointer to thread local variable. There is no public libc api for adding new allocations to TLS block dynamically which thread pointer points to. So, we support this by taking delta from thread base pointer to the actual thread local variable in our allocated section.

Diff Detail

Unit TestsFailed

TimeTest
240 msx64 debian > BOLT.runtime/X86::user-func-reorder.c
Script: -- : 'RUN: at line 30'; /usr/bin/clang --target=x86_64-linux -fuse-ld=lld -Wl,--unresolved-symbols=ignore-all -no-pie /var/lib/buildkite-agent/builds/llvm-project/bolt/test/runtime/X86/user-func-reorder.c -o /var/lib/buildkite-agent/builds/llvm-project/build/tools/bolt/test/runtime/X86/Output/user-func-reorder.c.tmp.exe -Wl,-q
60,340 msx64 debian > Clang.Driver::arm-cortex-cpus-2.c
Script: -- : 'RUN: at line 8'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -target armv8a-linux-eabi -mcpu=cortex-a53+fp16 -### -c /var/lib/buildkite-agent/builds/llvm-project/clang/test/Driver/arm-cortex-cpus-2.c 2>&1 | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --check-prefix CHECK-CORTEX-A53-FP16 /var/lib/buildkite-agent/builds/llvm-project/clang/test/Driver/arm-cortex-cpus-2.c
60,120 msx64 debian > Clang.Driver::emit-reproducer.c
Script: -- : 'RUN: at line 1'; rm -rf /var/lib/buildkite-agent/builds/llvm-project/build/tools/clang/test/Driver/Output/emit-reproducer.c.tmp && mkdir /var/lib/buildkite-agent/builds/llvm-project/build/tools/clang/test/Driver/Output/emit-reproducer.c.tmp
60,350 msx64 debian > Clang.Driver::fsanitize.c
Script: -- : 'RUN: at line 1'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-trap=undefined /var/lib/buildkite-agent/builds/llvm-project/clang/test/Driver/fsanitize.c -### 2>&1 | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck /var/lib/buildkite-agent/builds/llvm-project/clang/test/Driver/fsanitize.c --check-prefix=CHECK-UNDEFINED-TRAP
60,410 msx64 debian > Clang.OpenMP::target_defaultmap_codegen_01.cpp
Script: -- : 'RUN: at line 8'; /var/lib/buildkite-agent/builds/llvm-project/build/bin/clang -cc1 -internal-isystem /var/lib/buildkite-agent/builds/llvm-project/build/lib/clang/15.0.0/include -nostdsysteminc -no-opaque-pointers -no-enable-noundef-analysis -DCK1 -verify -fopenmp -fopenmp-version=50 -fopenmp-targets=powerpc64le-ibm-linux-gnu -x c++ -triple powerpc64le-unknown-unknown -emit-llvm /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/target_defaultmap_codegen_01.cpp -o - | /var/lib/buildkite-agent/builds/llvm-project/build/bin/FileCheck --allow-unused-prefixes -allow-deprecated-dag-overlap /var/lib/buildkite-agent/builds/llvm-project/clang/test/OpenMP/target_defaultmap_codegen_01.cpp --check-prefix CK1
View Full Test Results (7 Failed)

Event Timeline

sunho created this revision.Jun 26 2022, 12:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2022, 12:33 AM
sunho requested review of this revision.Jun 26 2022, 12:33 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 26 2022, 12:33 AM
Herald added subscribers: llvm-commits, Restricted Project. · View Herald Transcript
sunho edited the summary of this revision. (Show Details)Jun 26 2022, 12:37 AM
sunho updated this revision to Diff 440044.Jun 26 2022, 12:57 AM
sunho edited the summary of this revision. (Show Details)Jun 26 2022, 4:36 AM
sunho updated this revision to Diff 442130.Jul 4 2022, 11:46 AM
sunho edited the summary of this revision. (Show Details)

Use delta.

lhames added a comment.Jul 4 2022, 6:46 PM

Amazing -- TLV was supposed to be a stretch goal. ;)

compiler-rt/lib/orc/elfnix_tls.aarch64.S
21

Could this re-entry code have a fast-path for instances once they've been allocated (as in https://github.com/llvm/llvm-project/issues/51162, though obviously the specifics would be different for TLSDESC). If so it's probably worth a comment here "// TODO: add fast-path for repeat access".

llvm/include/llvm/ExecutionEngine/JITLink/aarch64.h
25

Is Nop actually needed here, or could we just not introduce the edge?

34–35

I think that these (TLVPage21 and TLVPageOffset12) should stay in: The idea is to have the edge kinds in the initially parsed graph be very descriptive (e.g. "I am a page21-expr offset _to a TLV pointer_") so that early passes have a clear picture of what the graph represents.

227–228

Braces aren't needed here, since no new decls are introduced.

sunho updated this revision to Diff 442325.Jul 5 2022, 9:10 AM

Addres comments.

sunho marked 3 inline comments as done.Jul 5 2022, 9:11 AM
lhames accepted this revision.Jul 5 2022, 3:25 PM

Otherwise LGTM. Thank you again! :)

llvm/lib/ExecutionEngine/JITLink/ELF_aarch64.cpp
320

Can we just return Error::success(); here, rather than setting a skip variable?

This revision is now accepted and ready to land.Jul 5 2022, 3:25 PM
sunho updated this revision to Diff 442491.Jul 6 2022, 3:02 AM
This revision was landed with ongoing or failed builds.Jul 6 2022, 4:13 AM
This revision was automatically updated to reflect the committed changes.