forked from OSchip/llvm-project
[Driver] Support Solaris/amd64 GetTls
This is the driver part of D91605 <https://reviews.llvm.org/D91605>, a workaround to allow direct calls to `__tls_get_addr` on Solaris/amd64. Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`. Differential Revision: https://reviews.llvm.org/D119829
This commit is contained in:
parent
a3bfb01d94
commit
b1fc966d2e
|
@ -14,6 +14,8 @@
|
|||
#include "clang/Driver/Driver.h"
|
||||
#include "clang/Driver/DriverDiagnostic.h"
|
||||
#include "clang/Driver/Options.h"
|
||||
#include "clang/Driver/SanitizerArgs.h"
|
||||
#include "clang/Driver/ToolChain.h"
|
||||
#include "llvm/Option/ArgList.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
|
@ -145,8 +147,18 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
CmdArgs.push_back("-lgcc");
|
||||
CmdArgs.push_back("-lm");
|
||||
}
|
||||
if (NeedsSanitizerDeps)
|
||||
if (NeedsSanitizerDeps) {
|
||||
linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
|
||||
|
||||
// Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
|
||||
// However, ld -z relax=transtls is available since Solaris 11.2, but not
|
||||
// in Illumos.
|
||||
const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
|
||||
if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
|
||||
(SA.needsAsanRt() || SA.needsStatsRt() ||
|
||||
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime())))
|
||||
CmdArgs.push_back("-zrelax=transtls");
|
||||
}
|
||||
}
|
||||
|
||||
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/// General tests that the ld -z relax=transtls workaround is only applied
|
||||
/// on Solaris/amd64. Note that we use sysroot to make these tests
|
||||
/// independent of the host system.
|
||||
|
||||
/// Check sparc-sun-solaris2.11, 32bit
|
||||
// RUN: %clang --target=sparc-sun-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
|
||||
// CHECK-LD-SPARC32-NOT: -zrelax=transtls
|
||||
|
||||
/// Check sparc-sun-solaris2.11, 32bit
|
||||
// RUN: %clang -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-SPARC32 %s
|
||||
// CHECK-LD-SPARC32-NOT: -zrelax=transtls
|
||||
|
||||
/// Check sparc-sun-solaris2.11, 64bit
|
||||
// RUN: %clang -m64 --target=sparc-sun-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
|
||||
// CHECK-LD-SPARC64-NOT: -zrelax=transtls
|
||||
|
||||
/// Check sparc-sun-solaris2.11, 64bit
|
||||
// RUN: %clang -m64 -fsanitize=undefined --target=sparc-sun-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_sparc_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
|
||||
// CHECK-LD-SPARC64-NOT: -zrelax=transtls
|
||||
|
||||
/// Check i386-pc-solaris2.11, 32bit
|
||||
// RUN: %clang --target=i386-pc-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-X32 %s
|
||||
// CHECK-LD-X32-NOT: -zrelax=transtls
|
||||
|
||||
/// Check i386-pc-solaris2.11, 32bit
|
||||
// RUN: %clang -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-X32 %s
|
||||
// CHECK-LD-X32-NOT: -zrelax=transtls
|
||||
|
||||
/// Check i386-pc-solaris2.11, 64bit
|
||||
// RUN: %clang -m64 --target=i386-pc-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-X64 %s
|
||||
// CHECK-LD-X64-NOT: -zrelax=transtls
|
||||
|
||||
/// Check i386-pc-solaris2.11, 64bit
|
||||
// RUN: %clang -m64 -fsanitize=undefined --target=i386-pc-solaris2.11 %s -### 2>&1 \
|
||||
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
|
||||
// CHECK-LD-X64-UBSAN: -zrelax=transtls
|
Loading…
Reference in New Issue