Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -14,6 +14,7 @@ #include "clang/Basic/LangOptions.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/Version.h" +#include "clang/Basic/VirtualFileSystem.h" #include "clang/Config/config.h" #include "clang/Driver/Action.h" #include "clang/Driver/Compilation.h" @@ -2151,8 +2152,14 @@ // as gold requires -plugin to come before any -plugin-opt that -Wl might // forward. CmdArgs.push_back("-plugin"); + // Try the full path first. However, if the file does not exist, just let gold + // fall back to regular library lookup instead of passing a known-invalid + // path. This is meant to fix non-standard Gentoo install of LLVMgold.so + // plugin. std::string Plugin = ToolChain.getDriver().Dir + "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold.so"; + if (!D.getVFS().exists(Plugin)) + Plugin = "LLVMgold.so"; CmdArgs.push_back(Args.MakeArgString(Plugin)); // Try to pass driver level flags relevant to LTO code generation down to Index: test/Driver/gold-lto.c =================================================================== --- test/Driver/gold-lto.c +++ test/Driver/gold-lto.c @@ -3,14 +3,14 @@ // RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \ // RUN: -Wl,-plugin-opt=foo -O3 \ // RUN: | FileCheck %s --check-prefix=CHECK-X86-64-BASIC -// CHECK-X86-64-BASIC: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-X86-64-BASIC: "-plugin" "{{.*}}LLVMgold.so" // CHECK-X86-64-BASIC: "-plugin-opt=O3" // CHECK-X86-64-BASIC: "-plugin-opt=foo" // // RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \ // RUN: -march=corei7 -Wl,-plugin-opt=foo -Ofast \ // RUN: | FileCheck %s --check-prefix=CHECK-X86-64-COREI7 -// CHECK-X86-64-COREI7: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-X86-64-COREI7: "-plugin" "{{.*}}LLVMgold.so" // CHECK-X86-64-COREI7: "-plugin-opt=mcpu=corei7" // CHECK-X86-64-COREI7: "-plugin-opt=O3" // CHECK-X86-64-COREI7: "-plugin-opt=foo" @@ -18,11 +18,11 @@ // RUN: %clang -target arm-unknown-linux -### %t.o -flto 2>&1 \ // RUN: -march=armv7a -Wl,-plugin-opt=foo -O0 \ // RUN: | FileCheck %s --check-prefix=CHECK-ARM-V7A -// CHECK-ARM-V7A: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-ARM-V7A: "-plugin" "{{.*}}LLVMgold.so" // CHECK-ARM-V7A: "-plugin-opt=mcpu=cortex-a8" // CHECK-ARM-V7A: "-plugin-opt=O0" // CHECK-ARM-V7A: "-plugin-opt=foo" // // RUN: %clang -target i686-linux-android -### %t.o -flto 2>&1 \ // RUN: | FileCheck %s --check-prefix=CHECK-X86-ANDROID -// CHECK-X86-ANDROID: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-X86-ANDROID: "-plugin" "{{.*}}LLVMgold.so" Index: test/Driver/lto.c =================================================================== --- test/Driver/lto.c +++ test/Driver/lto.c @@ -36,19 +36,19 @@ // RUN: %clang -target x86_64-unknown-linux -### %s -flto 2> %t // RUN: FileCheck -check-prefix=CHECK-LINK-LTO-ACTION < %t %s // -// CHECK-LINK-LTO-ACTION: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-LINK-LTO-ACTION: "-plugin" "{{.*}}LLVMgold.so" // -flto=full should cause link using gold plugin // RUN: %clang -target x86_64-unknown-linux -### %s -flto=full 2> %t // RUN: FileCheck -check-prefix=CHECK-LINK-FULL-ACTION < %t %s // -// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}LLVMgold.so" // Check that subsequent -fno-lto takes precedence // RUN: %clang -target x86_64-unknown-linux -### %s -flto=full -fno-lto 2> %t // RUN: FileCheck -check-prefix=CHECK-LINK-NOLTO-ACTION < %t %s // -// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}LLVMgold.so" // -flto passes along an explicit debugger tuning argument. // RUN: %clang -target x86_64-unknown-linux -### %s -flto -glldb 2> %t Index: test/Driver/thinlto.c =================================================================== --- test/Driver/thinlto.c +++ test/Driver/thinlto.c @@ -19,19 +19,19 @@ // RUN: %clang -target x86_64-unknown-linux -### %s -flto=full -fno-lto -flto=thin 2> %t // RUN: FileCheck -check-prefix=CHECK-LINK-THIN-ACTION < %t %s // -// CHECK-LINK-THIN-ACTION: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-LINK-THIN-ACTION: "-plugin" "{{.*}}LLVMgold.so" // CHECK-LINK-THIN-ACTION: "-plugin-opt=thinlto" // Check that subsequent -flto=full takes precedence // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -flto=full 2> %t // RUN: FileCheck -check-prefix=CHECK-LINK-FULL-ACTION < %t %s // -// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-LINK-FULL-ACTION: "-plugin" "{{.*}}LLVMgold.so" // CHECK-LINK-FULL-ACTION-NOT: "-plugin-opt=thinlto" // Check that subsequent -fno-lto takes precedence // RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-lto 2> %t // RUN: FileCheck -check-prefix=CHECK-LINK-NOLTO-ACTION < %t %s // -// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}/LLVMgold.so" +// CHECK-LINK-NOLTO-ACTION-NOT: "-plugin" "{{.*}}LLVMgold.so" // CHECK-LINK-NOLTO-ACTION-NOT: "-plugin-opt=thinlto"