diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 1ff5be7b034b..2258f69ef8ef 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -7515,6 +7515,13 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA, D.DyldPrefix + getLinuxDynamicLinker(Args, ToolChain))); } + // Work around a bug in GNU ld (and gold) linker versions up to 2.25 + // that may mis-optimize code generated by this version of clang/LLVM + // to access general-dynamic or local-dynamic TLS variables. + if (ToolChain.getArch() == llvm::Triple::ppc64 || + ToolChain.getArch() == llvm::Triple::ppc64le) + CmdArgs.push_back("--no-tls-optimize"); + CmdArgs.push_back("-o"); CmdArgs.push_back(Output.getFilename()); diff --git a/clang/test/Driver/ppc-features.cpp b/clang/test/Driver/ppc-features.cpp index 39d6357dccda..feecf3ceedd1 100644 --- a/clang/test/Driver/ppc-features.cpp +++ b/clang/test/Driver/ppc-features.cpp @@ -132,8 +132,10 @@ // linker features // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK_BE_LD_ARGS %s // CHECK_BE_LD_ARGS: "elf64ppc" +// CHECK_BE_LD_ARGS: "--no-tls-optimize" // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck -check-prefix=CHECK_LE_LD_ARGS %s // CHECK_LE_LD_ARGS: "elf64lppc" +// CHECK_LE_LD_ARGS: "--no-tls-optimize"