Author: Fangrui Song Date: 2020-05-08T23:36:29-07:00 New Revision: 6bf0ad78dc01020c9036ad49de2e0f4d59b6def9
URL: https://github.com/llvm/llvm-project/commit/6bf0ad78dc01020c9036ad49de2e0f4d59b6def9 DIFF: https://github.com/llvm/llvm-project/commit/6bf0ad78dc01020c9036ad49de2e0f4d59b6def9.diff LOG: [Driver] Don't pass -u__llvm_profile_runtime for clang -fprofile-arcs a.o clang --coverage a.o # InstrProfilingRuntime.cpp.o not linked in clang --fprofile-arcs a.o # InstrProfilingRuntime.cpp.o unexpectedly linked in Fix --fprofile-arcs. Added: Modified: clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChains/Darwin.cpp clang/lib/Driver/ToolChains/Linux.cpp clang/test/Driver/coverage-ld.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp index c8f6207ec584..6258276a0092 100644 --- a/clang/lib/Driver/ToolChain.cpp +++ b/clang/lib/Driver/ToolChain.cpp @@ -497,18 +497,14 @@ bool ToolChain::needsProfileRT(const ArgList &Args) { if (Args.hasArg(options::OPT_noprofilelib)) return false; - if (needsGCovInstrumentation(Args) || - Args.hasArg(options::OPT_fprofile_generate) || - Args.hasArg(options::OPT_fprofile_generate_EQ) || - Args.hasArg(options::OPT_fcs_profile_generate) || - Args.hasArg(options::OPT_fcs_profile_generate_EQ) || - Args.hasArg(options::OPT_fprofile_instr_generate) || - Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || - Args.hasArg(options::OPT_fcreate_profile) || - Args.hasArg(options::OPT_forder_file_instrumentation)) - return true; - - return false; + return Args.hasArg(options::OPT_fprofile_generate) || + Args.hasArg(options::OPT_fprofile_generate_EQ) || + Args.hasArg(options::OPT_fcs_profile_generate) || + Args.hasArg(options::OPT_fcs_profile_generate_EQ) || + Args.hasArg(options::OPT_fprofile_instr_generate) || + Args.hasArg(options::OPT_fprofile_instr_generate_EQ) || + Args.hasArg(options::OPT_fcreate_profile) || + Args.hasArg(options::OPT_forder_file_instrumentation); } bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) { @@ -764,7 +760,8 @@ void ToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {} void ToolChain::addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { - if (!needsProfileRT(Args)) return; + if (!needsProfileRT(Args) && !needsGCovInstrumentation(Args)) + return; CmdArgs.push_back(getCompilerRTArgString(Args, "profile")); } diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index df340145f9fa..f6e93eecb460 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1158,7 +1158,8 @@ static void addSectalignToPage(const ArgList &Args, ArgStringList &CmdArgs, void Darwin::addProfileRTLibs(const ArgList &Args, ArgStringList &CmdArgs) const { - if (!needsProfileRT(Args)) return; + if (!needsProfileRT(Args) && !needsGCovInstrumentation(Args)) + return; AddLinkRuntimeLib(Args, CmdArgs, "profile", RuntimeLinkOptions(RLO_AlwaysLink | RLO_FirstLink)); diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp index 5c63998ce94f..99c23e71eb0c 100644 --- a/clang/lib/Driver/ToolChains/Linux.cpp +++ b/clang/lib/Driver/ToolChains/Linux.cpp @@ -867,12 +867,13 @@ SanitizerMask Linux::getSupportedSanitizers() const { void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const { - if (!needsProfileRT(Args)) return; + bool Profile = needsProfileRT(Args); + if (!Profile && !needsGCovInstrumentation(Args)) + return; // Add linker option -u__llvm_profile_runtime to cause runtime // initialization module to be linked in. - if ((!Args.hasArg(options::OPT_coverage)) && - (!Args.hasArg(options::OPT_ftest_coverage))) + if (Profile) CmdArgs.push_back(Args.MakeArgString( Twine("-u", llvm::getInstrProfRuntimeHookVarName()))); ToolChain::addProfileRTLibs(Args, CmdArgs); diff --git a/clang/test/Driver/coverage-ld.c b/clang/test/Driver/coverage-ld.c index 282fcb65145c..c15531fa05e9 100644 --- a/clang/test/Driver/coverage-ld.c +++ b/clang/test/Driver/coverage-ld.c @@ -1,15 +1,21 @@ // Test coverage ld flags. // -// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ -// RUN: -target i386-unknown-linux --coverage -fuse-ld=ld \ +// RUN: %clang -no-canonical-prefixes %s -### 2>&1 \ +// RUN: -target i386-unknown-linux -fprofile-arcs \ +// RUN: -resource-dir=%S/Inputs/resource_dir \ +// RUN: --sysroot=%S/Inputs/basic_linux_tree \ +// RUN: | FileCheck --check-prefix=CHECK-LINUX-I386 %s +// +// RUN: %clang -no-canonical-prefixes %s -### 2>&1 \ +// RUN: -target i386-unknown-linux --coverage \ // RUN: -resource-dir=%S/Inputs/resource_dir \ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | FileCheck --check-prefix=CHECK-LINUX-I386 %s // -// CHECK-LINUX-I386: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" // CHECK-LINUX-I386-NOT: "-u__llvm_profile_runtime" -// CHECK-LINUX-I386: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.profile-i386.a" {{.*}} "-lc" +// CHECK-LINUX-I386: /Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.profile-i386.a" // CHECK-LINUX-I386-NOT: "-u__llvm_profile_runtime" +// CHECK-LINUX-I386: "-lc" // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: -target x86_64-unknown-linux --coverage -fuse-ld=ld \ _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits