llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-driver
            
<details>
<summary>Changes</summary>
https://reviews.llvm.org/D122407 added a static link against 
libclang_rt.asan_static whenever ASAN is linked, but ignored the 
-fno-sanitize-link-runtime flag.  Every other conditional in 
collectSanitizerRuntimes is already checking for SanArgs.linkRuntimes(), move 
it to the top of the function so that newly added conditionals don't need to 
remember to check it.
--
Full diff: https://github.com/llvm/llvm-project/pull/66414.diff

2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+27-27) 
- (modified) clang/test/Driver/sanitizer-ld.c (+2) 


<pre>
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 1db05b47e11ba6a..1768280e05b336f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1071,28 +1071,28 @@ collectSanitizerRuntimes(const ToolChain &amp;amp;TC, 
const ArgList &amp;amp;Args,
   const SanitizerArgs &amp;amp;SanArgs = TC.getSanitizerArgs(Args);
   // Collect shared runtimes.
   if (SanArgs.needsSharedRt()) {
-    if (SanArgs.needsAsanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+    if (SanArgs.needsAsanRt()) {
       SharedRuntimes.push_back(&amp;quot;asan&amp;quot;);
       if (!Args.hasArg(options::OPT_shared) &amp;amp;&amp;amp; 
!TC.getTriple().isAndroid())
         HelperStaticRuntimes.push_back(&amp;quot;asan-preinit&amp;quot;);
     }
-    if (SanArgs.needsMemProfRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+    if (SanArgs.needsMemProfRt()) {
       SharedRuntimes.push_back(&amp;quot;memprof&amp;quot;);
       if (!Args.hasArg(options::OPT_shared) &amp;amp;&amp;amp; 
!TC.getTriple().isAndroid())
         HelperStaticRuntimes.push_back(&amp;quot;memprof-preinit&amp;quot;);
     }
-    if (SanArgs.needsUbsanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+    if (SanArgs.needsUbsanRt()) {
       if (SanArgs.requiresMinimalRuntime())
         SharedRuntimes.push_back(&amp;quot;ubsan_minimal&amp;quot;);
       else
         SharedRuntimes.push_back(&amp;quot;ubsan_standalone&amp;quot;);
     }
-    if (SanArgs.needsScudoRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+    if (SanArgs.needsScudoRt()) {
       SharedRuntimes.push_back(&amp;quot;scudo_standalone&amp;quot;);
     }
-    if (SanArgs.needsTsanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes())
+    if (SanArgs.needsTsanRt())
       SharedRuntimes.push_back(&amp;quot;tsan&amp;quot;);
-    if (SanArgs.needsHwasanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+    if (SanArgs.needsHwasanRt()) {
       if (SanArgs.needsHwasanAliasesRt())
         SharedRuntimes.push_back(&amp;quot;hwasan_aliases&amp;quot;);
       else
@@ -1103,7 +1103,7 @@ collectSanitizerRuntimes(const ToolChain &amp;amp;TC, 
const ArgList &amp;amp;Args,
   }
 
   // The stats_client library is also statically linked into DSOs.
-  if (SanArgs.needsStatsRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes())
+  if (SanArgs.needsStatsRt())
     StaticRuntimes.push_back(&amp;quot;stats_client&amp;quot;);
 
   // Always link the static runtime regardless of DSO or executable.
@@ -1119,20 +1119,19 @@ collectSanitizerRuntimes(const ToolChain &amp;amp;TC, 
const ArgList &amp;amp;Args,
   // Each static runtime that has a DSO counterpart above is excluded below,
   // but runtimes that exist only as static are not affected by needsSharedRt.
 
-  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsAsanRt() 
&amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsAsanRt()) {
     StaticRuntimes.push_back(&amp;quot;asan&amp;quot;);
     if (SanArgs.linkCXXRuntimes())
       StaticRuntimes.push_back(&amp;quot;asan_cxx&amp;quot;);
   }
 
-  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsMemProfRt() 
&amp;amp;&amp;amp;
-      SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsMemProfRt()) {
     StaticRuntimes.push_back(&amp;quot;memprof&amp;quot;);
     if (SanArgs.linkCXXRuntimes())
       StaticRuntimes.push_back(&amp;quot;memprof_cxx&amp;quot;);
   }
 
-  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsHwasanRt() 
&amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsHwasanRt()) {
     if (SanArgs.needsHwasanAliasesRt()) {
       StaticRuntimes.push_back(&amp;quot;hwasan_aliases&amp;quot;);
       if (SanArgs.linkCXXRuntimes())
@@ -1143,22 +1142,21 @@ collectSanitizerRuntimes(const ToolChain &amp;amp;TC, 
const ArgList &amp;amp;Args,
         StaticRuntimes.push_back(&amp;quot;hwasan_cxx&amp;quot;);
     }
   }
-  if (SanArgs.needsDfsanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes())
+  if (SanArgs.needsDfsanRt())
     StaticRuntimes.push_back(&amp;quot;dfsan&amp;quot;);
-  if (SanArgs.needsLsanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes())
+  if (SanArgs.needsLsanRt())
     StaticRuntimes.push_back(&amp;quot;lsan&amp;quot;);
-  if (SanArgs.needsMsanRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (SanArgs.needsMsanRt()) {
     StaticRuntimes.push_back(&amp;quot;msan&amp;quot;);
     if (SanArgs.linkCXXRuntimes())
       StaticRuntimes.push_back(&amp;quot;msan_cxx&amp;quot;);
   }
-  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsTsanRt() 
&amp;amp;&amp;amp;
-      SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsTsanRt()) {
     StaticRuntimes.push_back(&amp;quot;tsan&amp;quot;);
     if (SanArgs.linkCXXRuntimes())
       StaticRuntimes.push_back(&amp;quot;tsan_cxx&amp;quot;);
   }
-  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsUbsanRt() 
&amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsUbsanRt()) {
     if (SanArgs.requiresMinimalRuntime()) {
       StaticRuntimes.push_back(&amp;quot;ubsan_minimal&amp;quot;);
     } else {
@@ -1167,24 +1165,24 @@ collectSanitizerRuntimes(const ToolChain &amp;amp;TC, 
const ArgList &amp;amp;Args,
         StaticRuntimes.push_back(&amp;quot;ubsan_standalone_cxx&amp;quot;);
     }
   }
-  if (SanArgs.needsSafeStackRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (SanArgs.needsSafeStackRt()) {
     NonWholeStaticRuntimes.push_back(&amp;quot;safestack&amp;quot;);
     RequiredSymbols.push_back(&amp;quot;__safestack_init&amp;quot;);
   }
-  if (!(SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsUbsanRt() 
&amp;amp;&amp;amp; SanArgs.linkRuntimes())) {
-    if (SanArgs.needsCfiRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes())
+  if (!(SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsUbsanRt())) {
+    if (SanArgs.needsCfiRt())
       StaticRuntimes.push_back(&amp;quot;cfi&amp;quot;);
-    if (SanArgs.needsCfiDiagRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+    if (SanArgs.needsCfiDiagRt()) {
       StaticRuntimes.push_back(&amp;quot;cfi_diag&amp;quot;);
       if (SanArgs.linkCXXRuntimes())
         StaticRuntimes.push_back(&amp;quot;ubsan_standalone_cxx&amp;quot;);
     }
   }
-  if (SanArgs.needsStatsRt() &amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (SanArgs.needsStatsRt()) {
     NonWholeStaticRuntimes.push_back(&amp;quot;stats&amp;quot;);
     RequiredSymbols.push_back(&amp;quot;__sanitizer_stats_register&amp;quot;);
   }
-  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsScudoRt() 
&amp;amp;&amp;amp; SanArgs.linkRuntimes()) {
+  if (!SanArgs.needsSharedRt() &amp;amp;&amp;amp; SanArgs.needsScudoRt()) {
     StaticRuntimes.push_back(&amp;quot;scudo_standalone&amp;quot;);
     if (SanArgs.linkCXXRuntimes())
       StaticRuntimes.push_back(&amp;quot;scudo_standalone_cxx&amp;quot;);
@@ -1195,13 +1193,15 @@ collectSanitizerRuntimes(const ToolChain &amp;amp;TC, 
const ArgList &amp;amp;Args,
 // C runtime, etc). Returns true if sanitizer system deps need to be linked in.
 bool tools::addSanitizerRuntimes(const ToolChain &amp;amp;TC, const ArgList 
&amp;amp;Args,
                                  ArgStringList &amp;amp;CmdArgs) {
+  const SanitizerArgs &amp;amp;SanArgs = TC.getSanitizerArgs(Args);
   SmallVector&amp;lt;StringRef, 4&amp;gt; SharedRuntimes, StaticRuntimes,
       NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
-  collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
-                           NonWholeStaticRuntimes, HelperStaticRuntimes,
-                           RequiredSymbols);
+  if (SanArgs.linkRuntimes()) {
+    collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,
+                             NonWholeStaticRuntimes, HelperStaticRuntimes,
+                             RequiredSymbols);
+  }
 
-  const SanitizerArgs &amp;amp;SanArgs = TC.getSanitizerArgs(Args);
   // Inject libfuzzer dependencies.
   if (SanArgs.needsFuzzer() &amp;amp;&amp;amp; SanArgs.linkRuntimes() 
&amp;amp;&amp;amp;
       !Args.hasArg(options::OPT_shared)) {
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index eacd5c4698842e6..2831c2dad8d24cc 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -23,6 +23,7 @@
 // RUN:     --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
 //
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan_static-x86_64
 // CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
 
 // RUN: %clang -fsanitize=address -fno-sanitize-link-runtime -### %s 
2&amp;gt;&amp;amp;1 \
@@ -31,6 +32,7 @@
 // RUN:     --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN %s
 //
+// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan_static
 // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN-NOT: libclang_rt.asan
 
 // RUN: %clang -fsanitize=address -### %s 2&amp;gt;&amp;amp;1 \
</pre>
</details>


https://github.com/llvm/llvm-project/pull/66414
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to