From: Vedant Kumar Date: Mon, 3 Dec 2018 20:53:58 +0000 (+0000) Subject: [gcov/Darwin] Ensure external symbols are exported when using an export list X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96556093d0bdcdc7ead3fba1e514e375fbc66bb5;p=clang [gcov/Darwin] Ensure external symbols are exported when using an export list Make sure that symbols needed to implement runtime support for gcov are exported when using an export list on Darwin. Without the clang driver exporting these symbols, the linker hides them, resulting in tapi verification failures. rdar://45944768 Differential Revision: https://reviews.llvm.org/D55151 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348187 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index 9b0590a761..73fd914ad1 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -381,6 +381,9 @@ public: /// needsProfileRT - returns true if instrumentation profile is on. static bool needsProfileRT(const llvm::opt::ArgList &Args); + /// Returns true if gcov instrumentation (-fprofile-arcs or --coverage) is on. + static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args); + /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables /// by default. virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const; diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 1667536c56..294e775a85 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -403,19 +403,23 @@ std::string ToolChain::getArchSpecificLibPath() const { } bool ToolChain::needsProfileRT(const ArgList &Args) { - if (Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, - false) || + if (needsGCovInstrumentation(Args) || Args.hasArg(options::OPT_fprofile_generate) || Args.hasArg(options::OPT_fprofile_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_coverage)) + Args.hasArg(options::OPT_fcreate_profile)) return true; return false; } +bool ToolChain::needsGCovInstrumentation(const llvm::opt::ArgList &Args) { + return Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs, + false) || + Args.hasArg(options::OPT_coverage); +} + Tool *ToolChain::SelectTool(const JobAction &JA) const { if (getDriver().ShouldUseClangCompiler(JA)) return getClang(); Action::ActionClass AC = JA.getKind(); diff --git a/lib/Driver/ToolChains/Darwin.cpp b/lib/Driver/ToolChains/Darwin.cpp index 50c0db5b5a..452b6b89ca 100644 --- a/lib/Driver/ToolChains/Darwin.cpp +++ b/lib/Driver/ToolChains/Darwin.cpp @@ -1034,11 +1034,17 @@ void Darwin::addProfileRTLibs(const ArgList &Args, // runtime, automatically export symbols necessary to implement some of the // runtime's functionality. if (hasExportSymbolDirective(Args)) { - addExportedSymbol(CmdArgs, "___llvm_profile_filename"); - addExportedSymbol(CmdArgs, "___llvm_profile_raw_version"); - addExportedSymbol(CmdArgs, "_lprofCurFilename"); + if (needsGCovInstrumentation(Args)) { + addExportedSymbol(CmdArgs, "___gcov_flush"); + addExportedSymbol(CmdArgs, "_flush_fn_list"); + addExportedSymbol(CmdArgs, "_writeout_fn_list"); + } else { + addExportedSymbol(CmdArgs, "___llvm_profile_filename"); + addExportedSymbol(CmdArgs, "___llvm_profile_raw_version"); + addExportedSymbol(CmdArgs, "_lprofCurFilename"); + addExportedSymbol(CmdArgs, "_lprofMergeValueProfData"); + } addExportedSymbol(CmdArgs, "_lprofDirMode"); - addExportedSymbol(CmdArgs, "_lprofMergeValueProfData"); } } diff --git a/test/Driver/darwin-ld.c b/test/Driver/darwin-ld.c index 3c339a117d..5198ef057b 100644 --- a/test/Driver/darwin-ld.c +++ b/test/Driver/darwin-ld.c @@ -341,10 +341,22 @@ // RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log // PROFILE_EXPORT: "-exported_symbol" "___llvm_profile_filename" "-exported_symbol" "___llvm_profile_raw_version" "-exported_symbol" "_lprofCurFilename" // -// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### %t.o 2> %t.log +// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate --coverage -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=NO_PROFILE_EXPORT %s < %t.log // NO_PROFILE_EXPORT-NOT: "-exported_symbol" // +// RUN: %clang -target x86_64-apple-darwin12 --coverage -exported_symbols_list /dev/null -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log +// RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Wl,-exported_symbols_list,/dev/null -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log +// RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Wl,-exported_symbol,foo -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log +// RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Xlinker -exported_symbol -Xlinker foo -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log +// RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Xlinker -exported_symbols_list -Xlinker /dev/null -### %t.o 2> %t.log +// RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log +// GCOV_EXPORT: "-exported_symbol" "___gcov_flush" +// // Check that we can pass the outliner down to the linker. // RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target arm64-apple-darwin -moutline -### %t.o 2> %t.log