]> granicus.if.org Git - clang/commitdiff
Link in profile library on Linux using --whole-archive
authorAlexey Samsonov <samsonov@google.com>
Fri, 28 Mar 2014 15:39:08 +0000 (15:39 +0000)
committerAlexey Samsonov <samsonov@google.com>
Fri, 28 Mar 2014 15:39:08 +0000 (15:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205012 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp
test/Driver/coverage-ld.c

index 2141cc9656bdbf2672ab79afd72c4b88c9809757..e4af66b7835eea30d07d74b62a61330cc26af35b 100644 (file)
@@ -1817,18 +1817,16 @@ static void addProfileRT(
         Args.hasArg(options::OPT_coverage)))
     return;
 
-  // Pull in runtime for -fprofile-inst-generate.  This is required since there
-  // are no calls to the runtime in the code.
-  if (Args.hasArg(options::OPT_fprofile_instr_generate)) {
-    CmdArgs.push_back("-u");
-    CmdArgs.push_back("___llvm_profile_runtime");
-  }
-
   SmallString<128> LibProfile = getCompilerRTLibDir(TC);
   llvm::sys::path::append(LibProfile,
       Twine("libclang_rt.profile-") + getArchNameForCompilerRTLib(TC) + ".a");
 
-  CmdArgs.push_back(Args.MakeArgString(LibProfile));
+  SmallVector<const char *, 3> LibProfileArgs;
+  LibProfileArgs.push_back("-whole-archive");
+  LibProfileArgs.push_back(Args.MakeArgString(LibProfile));
+  LibProfileArgs.push_back("-no-whole-archive");
+
+  CmdArgs.insert(CmdArgs.end(), LibProfileArgs.begin(), LibProfileArgs.end());
 }
 
 static void addSanitizerRTLinkFlags(
index 0e39249a2f3e878129059448341e87825eaa75e3..bb70fe56c8179b10e6a89c4c16623fb95a710ca0 100644 (file)
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64 %s
 //
 // CHECK-LINUX-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
-// CHECK-LINUX-X86-64: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
-//
+// CHECK-LINUX-X86-64: "-whole-archive"
+// CHECK-LINUX-X86-64: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.profile-x86_64.a"
+// CHECK-LINUX-X86-64: "-no-whole-archive"
+// CHECK-LINUX-X86-64: "-lc"
+
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN:     -target x86_64-unknown-freebsd --coverage \
 // RUN:     -resource-dir=%S/Inputs/resource_dir \