[Driver,CodeGen] Support -mtls-dialect= (#79256)
authorFangrui Song <i@maskray.me>
Fri, 26 Jan 2024 17:25:38 +0000 (09:25 -0800)
committerTom Stellard <tstellar@redhat.com>
Sat, 27 Jan 2024 03:51:03 +0000 (19:51 -0800)
commitaa4cb0e313a621bb9c2e5849de82684ed3c73c29
treec4e1c4c64e28968c397844fe41a832ed3dc611c8
parent147c623a86b39d6bc9993293487b5773de943dad
[Driver,CodeGen] Support -mtls-dialect= (#79256)

GCC supports -mtls-dialect= for several architectures to select TLSDESC.
This patch supports the following values

* x86: "gnu". "gnu2" (TLSDESC) is not supported yet.
* RISC-V: "trad" (general dynamic), "desc" (TLSDESC, see #66915)

AArch64 toolchains seem to support TLSDESC from the beginning, and the
general dynamic model has poor support. Nobody seems to use the option
-mtls-dialect= at all, so we don't bother with it.
There also seems very little interest in AArch32's TLSDESC support.

TLSDESC does not change IR, but affects object file generation. Without
a backend option the option is a no-op for in-process ThinLTO.

There seems no motivation to have fine-grained control mixing trad/desc
for TLS, so we just pass -mllvm, and don't bother with a modules flag
metadata or function attribute.

Co-authored-by: Paul Kirth <paulkirth@google.com>
(cherry picked from commit 36b4a9ccd9f7e04010476e6b2a311f2052a4ac20)
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
clang/test/CodeGen/RISCV/tls-dialect.c [new file with mode: 0644]
clang/test/Driver/tls-dialect.c [new file with mode: 0644]
llvm/include/llvm/TargetParser/Triple.h