tbaeder created this revision. tbaeder added reviewers: MaskRay, fhahn, tejohnson. Herald added subscribers: ormris, steven_wu, hiraditya, inglorion. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This is what the GCC driver does as well. This way, ld.bfd can properly handle inputs from a clang LTO build, without `-flto` being specified at link time explicitly. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D114229 Files: clang/lib/Driver/ToolChains/Gnu.cpp clang/test/Driver/lto.c Index: clang/test/Driver/lto.c =================================================================== --- clang/test/Driver/lto.c +++ clang/test/Driver/lto.c @@ -104,4 +104,19 @@ // FLTO-THIN-NOT: "-flto" // FLTO-THIN: -flto=thin // FLTO-THIN-NOT: "-flto" -// FLTO-THIN-NOT: -flto=full \ No newline at end of file +// FLTO-THIN-NOT: -flto=full + +// When ld.bfd is being used and no lto option has been specified, the driver +// should pass the lto plugin options to the linker anyway, so LTO +// input files can be linked. +// RUN: %clang -target x86_64-unknown-linux -fuse-ld=bfd -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=FLTO-NOT-SPECIFIED-BFD %s +// +// FLTO-NOT-SPECIFIED-BFD: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}" +// +// +// But not when LLD is used: +// RUN: %clang -target x86_64-unknown-linux -fuse-ld=lld -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=FLTO-NOT-SPECIFIED-LLD %s +// +// FLTO-NOT-SPECIFIED-LLD-NOT: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}" Index: clang/lib/Driver/ToolChains/Gnu.cpp =================================================================== --- clang/lib/Driver/ToolChains/Gnu.cpp +++ clang/lib/Driver/ToolChains/Gnu.cpp @@ -546,7 +546,14 @@ ToolChain.AddFilePathLibArgs(Args, CmdArgs); - if (D.isUsingLTO()) { + // If no LTO option has been specified, add the LTO options anyway. + // This has the upside of making the linking automatically work with + // LLVM bitcode files created from an LTO compile. If the input is not + // an LTO file, the LTO plugin will not be invoked. + // This is the same behavior the GCC driver uses. + if ((!Args.hasArg(options::OPT_flto_EQ) && + !Args.hasArg(options::OPT_fno_lto)) || + D.isUsingLTO()) { assert(!Inputs.empty() && "Must have at least one input."); addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0], D.getLTOMode() == LTOK_Thin);
Index: clang/test/Driver/lto.c =================================================================== --- clang/test/Driver/lto.c +++ clang/test/Driver/lto.c @@ -104,4 +104,19 @@ // FLTO-THIN-NOT: "-flto" // FLTO-THIN: -flto=thin // FLTO-THIN-NOT: "-flto" -// FLTO-THIN-NOT: -flto=full \ No newline at end of file +// FLTO-THIN-NOT: -flto=full + +// When ld.bfd is being used and no lto option has been specified, the driver +// should pass the lto plugin options to the linker anyway, so LTO +// input files can be linked. +// RUN: %clang -target x86_64-unknown-linux -fuse-ld=bfd -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=FLTO-NOT-SPECIFIED-BFD %s +// +// FLTO-NOT-SPECIFIED-BFD: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}" +// +// +// But not when LLD is used: +// RUN: %clang -target x86_64-unknown-linux -fuse-ld=lld -### %s 2>&1 | \ +// RUN: FileCheck --check-prefix=FLTO-NOT-SPECIFIED-LLD %s +// +// FLTO-NOT-SPECIFIED-LLD-NOT: "-plugin" "{{.*}}{{[/\\]}}LLVMgold.{{dll|dylib|so}}" Index: clang/lib/Driver/ToolChains/Gnu.cpp =================================================================== --- clang/lib/Driver/ToolChains/Gnu.cpp +++ clang/lib/Driver/ToolChains/Gnu.cpp @@ -546,7 +546,14 @@ ToolChain.AddFilePathLibArgs(Args, CmdArgs); - if (D.isUsingLTO()) { + // If no LTO option has been specified, add the LTO options anyway. + // This has the upside of making the linking automatically work with + // LLVM bitcode files created from an LTO compile. If the input is not + // an LTO file, the LTO plugin will not be invoked. + // This is the same behavior the GCC driver uses. + if ((!Args.hasArg(options::OPT_flto_EQ) && + !Args.hasArg(options::OPT_fno_lto)) || + D.isUsingLTO()) { assert(!Inputs.empty() && "Must have at least one input."); addLTOOptions(ToolChain, Args, CmdArgs, Output, Inputs[0], D.getLTOMode() == LTOK_Thin);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits