Skip to content

Add -static-libasan alias for -static-libsan. #98194

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

eugenis
Copy link
Contributor

@eugenis eugenis commented Jul 9, 2024

This helps compatibility with gcc, which has (static|shared)-libasan, but not *-libsan.

Clang currently has
-shared-libasan
-shared-libsan
-static-libsan

This change improves consistency by adding
-static-libasan

This helps compatibility with gcc, which has (static|shared)-libasan,
but not *-libsan.

Clang currently has
  -shared-libasan
  -shared-libsan
  -static-libsan

This change improves consistency by adding
  -static-libasan
@eugenis eugenis requested review from vitalybuka and enh-google July 9, 2024 17:27
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Jul 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Evgenii Stepanov (eugenis)

Changes

This helps compatibility with gcc, which has (static|shared)-libasan, but not *-libsan.

Clang currently has
-shared-libasan
-shared-libsan
-static-libsan

This change improves consistency by adding
-static-libasan


Full diff: https://github.com/llvm/llvm-project/pull/98194.diff

2 Files Affected:

  • (modified) clang/include/clang/Driver/Options.td (+1)
  • (modified) clang/test/Driver/sanitizer-ld.c (+7)
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index be7c3b60c20f1..93292a35841c4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1618,6 +1618,7 @@ def shared_libsan : Flag<["-"], "shared-libsan">,
 def static_libsan : Flag<["-"], "static-libsan">,
   HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
 def : Flag<["-"], "shared-libasan">, Alias<shared_libsan>;
+def : Flag<["-"], "static-libasan">, Alias<static_libsan>;
 def fasm : Flag<["-"], "fasm">, Group<f_Group>;
 
 defm assume_unique_vtables : BoolFOption<"assume-unique-vtables",
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index 93702f456229f..e215c034070e0 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -196,6 +196,13 @@
 // RUN:     -static-libsan \
 // RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-STATICLIBASAN %s
 //
+// RUN: %clang -### %s 2>&1 \
+// RUN:     --target=arm-linux-androideabi -fuse-ld=ld -fsanitize=address \
+// RUN:     --sysroot=%S/Inputs/basic_android_tree/sysroot \
+// RUN:     -resource-dir=%S/Inputs/resource_dir \
+// RUN:     -static-libasan \
+// RUN:   | FileCheck --check-prefix=CHECK-ASAN-ANDROID-STATICLIBASAN %s
+//
 // CHECK-ASAN-ANDROID-STATICLIBASAN: "{{(.*[^.0-9A-Z_a-z])?}}ld.lld{{(.exe)?}}"
 // CHECK-ASAN-ANDROID-STATICLIBASAN: libclang_rt.asan.a"
 // CHECK-ASAN-ANDROID-STATICLIBASAN-NOT: "-lpthread"

@eugenis eugenis merged commit dcf70e1 into llvm:main Jul 10, 2024
10 checks passed
@eugenis eugenis deleted the static-libasan branch July 10, 2024 17:23
landley added a commit to landley/toybox that referenced this pull request Jul 11, 2024
Even building standalone hello world complains "ASan runtime does
not come first in initial library list" and says to use LD_PRELOAD
without saying WHAT to set it to. This avoids that. (It breaks llvm,
but llvm/llvm-project#98194 fixes it.)
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
This helps compatibility with gcc, which has (static|shared)-libasan,
but not *-libsan.

Clang currently has
  -shared-libasan
  -shared-libsan
  -static-libsan

This change improves consistency by adding
  -static-libasan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants