r293420 - [windows] [asan] Add linker flag when including "asan_dynamic_runtime_thunk".

2017-01-29 Thread Marcos Pividori via cfe-commits
Author: mpividori
Date: Sun Jan 29 00:03:05 2017
New Revision: 293420

URL: http://llvm.org/viewvc/llvm-project?rev=293420&view=rev
Log:
[windows] [asan] Add linker flag when including "asan_dynamic_runtime_thunk".

I modify clang driver for windows to include:
"-wholearchive:asan_dynamic_runtime_thunk", so all object files in the
static library: asan_dynamic_runtime_thunk are considered by the linker.
This is necessary, because some object files only include linker pragmas,
and doesn't resolve any symbol. If we don't include that flag, the
linker will ignore them, and won't read the linker pragmas.

Differential Revision: https://reviews.llvm.org/D29159

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/cl-link.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=293420&r1=293419&r2=293420&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Sun Jan 29 00:03:05 2017
@@ -10990,6 +10990,10 @@ void visualstudio::Linker::ConstructJob(
   TC.getArch() == llvm::Triple::x86
   ? "-include:___asan_seh_interceptor"
   : "-include:__asan_seh_interceptor"));
+  // Make sure the linker consider all object files from the dynamic 
runtime
+  // thunk.
+  CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
+  TC.getCompilerRT(Args, "asan_dynamic_runtime_thunk")));
 } else if (DLL) {
   CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dll_thunk"));
 } else {

Modified: cfe/trunk/test/Driver/cl-link.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-link.c?rev=293420&r1=293419&r2=293420&view=diff
==
--- cfe/trunk/test/Driver/cl-link.c (original)
+++ cfe/trunk/test/Driver/cl-link.c Sun Jan 29 00:03:05 2017
@@ -22,8 +22,9 @@
 // ASAN-MD: "-debug"
 // ASAN-MD: "-incremental:no"
 // ASAN-MD: "{{.*}}clang_rt.asan_dynamic-i386.lib"
-// ASAN-MD: "{{.*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib"
+// ASAN-MD: "{{[^"]*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib"
 // ASAN-MD: "-include:___asan_seh_interceptor"
+// ASAN-MD: "-wholearchive:{{.*}}clang_rt.asan_dynamic_runtime_thunk-i386.lib"
 // ASAN-MD: "{{.*}}cl-link{{.*}}.obj"
 
 // RUN: %clang_cl /LD -### /Tc%s 2>&1 | FileCheck --check-prefix=DLL %s


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293668 - [windows] [asan] Add wholearchive flag when including static lib asan.

2017-01-31 Thread Marcos Pividori via cfe-commits
Author: mpividori
Date: Tue Jan 31 12:31:38 2017
New Revision: 293668

URL: http://llvm.org/viewvc/llvm-project?rev=293668&view=rev
Log:
[windows] [asan] Add wholearchive flag when including static lib asan.

In Windows, when the sanitizer is implemented as a static library, we use
auxiliary static library dll_thunk that will be linked to the dlls that have
instrumentation, so they can refer to the runtime in the main executable.
It uses interception to get a pointer the function in the main executable and
override its function with that pointer.
Because of that, we need to ensure that the main executable exports all the
sanitizers' interface, otherwise the initialization in dll_thunk will fail.

In this commit we add the flag -wholearchive to clang driver to ensure that
the linker does not omit any object files from asan library.

Differential Revision: https://reviews.llvm.org/D29334

Modified:
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=293668&r1=293667&r2=293668&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Jan 31 12:31:38 2017
@@ -11002,6 +11002,11 @@ void visualstudio::Linker::ConstructJob(
 } else {
   for (const auto &Lib : {"asan", "asan_cxx"})
 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
+  // Make sure the linker consider all object files from the static 
library.
+  // This is necessary because instrumented dlls need access to all the
+  // interface exported by the static lib in the main executable.
+  CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
+  TC.getCompilerRT(Args, "asan")));
 }
   }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r293676 - [windows] [asan] Fix tests failing after 293668.

2017-01-31 Thread Marcos Pividori via cfe-commits
Author: mpividori
Date: Tue Jan 31 13:05:05 2017
New Revision: 293676

URL: http://llvm.org/viewvc/llvm-project?rev=293676&view=rev
Log:
[windows] [asan] Fix tests failing after 293668.

Modified:
cfe/trunk/test/Driver/cl-link.c

Modified: cfe/trunk/test/Driver/cl-link.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-link.c?rev=293676&r1=293675&r2=293676&view=diff
==
--- cfe/trunk/test/Driver/cl-link.c (original)
+++ cfe/trunk/test/Driver/cl-link.c Tue Jan 31 13:05:05 2017
@@ -13,8 +13,9 @@
 // ASAN: link.exe
 // ASAN: "-debug"
 // ASAN: "-incremental:no"
-// ASAN: "{{.*}}clang_rt.asan-i386.lib"
+// ASAN: "{{[^"]*}}clang_rt.asan-i386.lib"
 // ASAN: "{{.*}}clang_rt.asan_cxx-i386.lib"
+// ASAN: "-wholearchive:{{.*}}clang_rt.asan-i386.lib"
 // ASAN: "{{.*}}cl-link{{.*}}.obj"
 
 // RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /MD /Tc%s -### 
-fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-MD %s


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r294604 - [windows] [asan] Add wholearchive flag when including asan_cxx lib.

2017-02-09 Thread Marcos Pividori via cfe-commits
Author: mpividori
Date: Thu Feb  9 12:22:35 2017
New Revision: 294604

URL: http://llvm.org/viewvc/llvm-project?rev=294604&view=rev
Log:
[windows] [asan] Add wholearchive flag when including asan_cxx lib.

We need -wholearchive for asan_cxx, the same than for asan.
Clang Driver will add asan_cxx at the beginning of the arg list that we pass to
the linker. To ensure that all the static libraries are linked to asan_cxx, we
force the linker to include the object files in asan_cxx.

This fixes some linker errors when compiling with address sanitizer for MT and
passing the static library libFuzzer.

Differential Revision: https://reviews.llvm.org/D29754

Modified:
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=294604&r1=294603&r2=294604&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Feb  9 12:22:35 2017
@@ -11006,13 +11006,14 @@ void visualstudio::Linker::ConstructJob(
 } else if (DLL) {
   CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dll_thunk"));
 } else {
-  for (const auto &Lib : {"asan", "asan_cxx"})
+  for (const auto &Lib : {"asan", "asan_cxx"}) {
 CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
-  // Make sure the linker consider all object files from the static 
library.
-  // This is necessary because instrumented dlls need access to all the
-  // interface exported by the static lib in the main executable.
-  CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
-  TC.getCompilerRT(Args, "asan")));
+// Make sure the linker consider all object files from the static lib.
+// This is necessary because instrumented dlls need access to all the
+// interface exported by the static lib in the main executable.
+CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
+TC.getCompilerRT(Args, Lib)));
+  }
 }
   }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r294609 - [windows] Fix test for cl driver.

2017-02-09 Thread Marcos Pividori via cfe-commits
Author: mpividori
Date: Thu Feb  9 12:40:52 2017
New Revision: 294609

URL: http://llvm.org/viewvc/llvm-project?rev=294609&view=rev
Log:
[windows] Fix test for cl driver.

cl-link.c test was failing after r294604 because of the change in the order of
parameters.

Modified:
cfe/trunk/test/Driver/cl-link.c

Modified: cfe/trunk/test/Driver/cl-link.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-link.c?rev=294609&r1=294608&r2=294609&view=diff
==
--- cfe/trunk/test/Driver/cl-link.c (original)
+++ cfe/trunk/test/Driver/cl-link.c Thu Feb  9 12:40:52 2017
@@ -14,8 +14,9 @@
 // ASAN: "-debug"
 // ASAN: "-incremental:no"
 // ASAN: "{{[^"]*}}clang_rt.asan-i386.lib"
-// ASAN: "{{.*}}clang_rt.asan_cxx-i386.lib"
 // ASAN: "-wholearchive:{{.*}}clang_rt.asan-i386.lib"
+// ASAN: "{{[^"]*}}clang_rt.asan_cxx-i386.lib"
+// ASAN: "-wholearchive:{{.*}}clang_rt.asan_cxx-i386.lib"
 // ASAN: "{{.*}}cl-link{{.*}}.obj"
 
 // RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /MD /Tc%s -### 
-fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-MD %s


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits