aeubanks created this revision.
aeubanks added reviewers: hans, thakis.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

With recent MSVC releases, STL headers will add /INFERASANLIBS to the drectve 
section of object files that are compiled with clang. With this flag, link.exe 
will automatically attempt to look for asan libs.

When using clang as the driver to invoke the linker, we want to disable this 
feature because we explicitly pass the proper asan libraries, otherwise we get 
symbols defined multiple times.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144684

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-link.c


Index: clang/test/Driver/cl-link.c
===================================================================
--- clang/test/Driver/cl-link.c
+++ clang/test/Driver/cl-link.c
@@ -65,3 +65,11 @@
 
 // RUN: %clang_cl /Tc%s -fuse-ld=lld -### 2>&1 | FileCheck 
--check-prefix=USE_LLD %s
 // USE_LLD: lld-link
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=link 
-### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LINK %s
+// INFER-LINK: link.exe
+// INFER-LINK: /INFERASANLIBS:NO
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld 
-### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
+// INFER-LLD: lld-link
+// INFER-LLD-NOT: INFERASANLIBS
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -336,6 +336,11 @@
       }
     }
 
+    // Clang handles passing the proper asan libs to the linker, which goes
+    // against link.exe's /INFERASANLIBS which automatically finds asan libs.
+    if (TC.getSanitizerArgs(Args).needsAsanRt())
+      CmdArgs.push_back("/INFERASANLIBS:NO");
+
 #ifdef _WIN32
     // When cross-compiling with VS2017 or newer, link.exe expects to have
     // its containing bin directory at the top of PATH, followed by the


Index: clang/test/Driver/cl-link.c
===================================================================
--- clang/test/Driver/cl-link.c
+++ clang/test/Driver/cl-link.c
@@ -65,3 +65,11 @@
 
 // RUN: %clang_cl /Tc%s -fuse-ld=lld -### 2>&1 | FileCheck --check-prefix=USE_LLD %s
 // USE_LLD: lld-link
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=link -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LINK %s
+// INFER-LINK: link.exe
+// INFER-LINK: /INFERASANLIBS:NO
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
+// INFER-LLD: lld-link
+// INFER-LLD-NOT: INFERASANLIBS
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -336,6 +336,11 @@
       }
     }
 
+    // Clang handles passing the proper asan libs to the linker, which goes
+    // against link.exe's /INFERASANLIBS which automatically finds asan libs.
+    if (TC.getSanitizerArgs(Args).needsAsanRt())
+      CmdArgs.push_back("/INFERASANLIBS:NO");
+
 #ifdef _WIN32
     // When cross-compiling with VS2017 or newer, link.exe expects to have
     // its containing bin directory at the top of PATH, followed by the
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to