[PATCH] D27870: [libFuzzer] Diff 25 - Fix test with shared libraries on Windows.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 16:00:57 PST 2017


mpividori updated this revision to Diff 85210.
mpividori added a comment.

@kcc @zturner  Again here. I was confused but the previous changes didn't fix this for Windows. This is the situation:

- We need to set `BINARY_DIR` to: `${CMAKE_BINARY_DIR}/lib/Fuzzer/test`  , so the dll is placed in the same directory than the test `LLVMFuzzer-DSOTest`, and is found when executing that test.

- As we are using `CMAKE_CXX_CREATE_SHARED_LIBRARY` to link the dll, we can't modify the output directory for the import library. It will be created in the same directory than the dll (in `BINARY_DIR`), no matter which value we set to `LIBRARY_DIR`. So, if we set `LIBRARY_DIR` to a different directory than `BINARY_DIR`, when linking `LLVMFuzzer-DSOTest`, cmake will look for the import library `LLVMFuzzer-DSO1.lib` in `LIBRARY_DIR`, and won't find it, since it was created in `BINARY_DIR`. So, for Windows, we need that `LIBRARY_DIR` and `BINARY_DIR` are the same directory.


https://reviews.llvm.org/D27870

Files:
  lib/Fuzzer/test/CMakeLists.txt
  lib/Fuzzer/test/DSO1.cpp
  lib/Fuzzer/test/DSO2.cpp


Index: lib/Fuzzer/test/DSO2.cpp
===================================================================
--- lib/Fuzzer/test/DSO2.cpp
+++ lib/Fuzzer/test/DSO2.cpp
@@ -2,7 +2,9 @@
 // License. See LICENSE.TXT for details.
 
 // Source code for a simple DSO.
-
+#ifdef _WIN32
+__declspec( dllexport )
+#endif
 int DSO2(int a) {
   if (a < 3598235)
     return 0;
Index: lib/Fuzzer/test/DSO1.cpp
===================================================================
--- lib/Fuzzer/test/DSO1.cpp
+++ lib/Fuzzer/test/DSO1.cpp
@@ -2,7 +2,9 @@
 // License. See LICENSE.TXT for details.
 
 // Source code for a simple DSO.
-
+#ifdef _WIN32
+__declspec( dllexport )
+#endif
 int DSO1(int a) {
   if (a < 123456)
     return 0;
Index: lib/Fuzzer/test/CMakeLists.txt
===================================================================
--- lib/Fuzzer/test/CMakeLists.txt
+++ lib/Fuzzer/test/CMakeLists.txt
@@ -205,10 +205,20 @@
 
 set_target_properties(LLVMFuzzer-DSOTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY
   "${CMAKE_BINARY_DIR}/lib/Fuzzer/test")
-set_target_properties(LLVMFuzzer-DSO1 PROPERTIES LIBRARY_OUTPUT_DIRECTORY
-  "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
-set_target_properties(LLVMFuzzer-DSO2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY
-  "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
+
+if(MSVC)
+  set_output_directory(LLVMFuzzer-DSO1
+    BINARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test"
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test")
+  set_output_directory(LLVMFuzzer-DSO2
+    BINARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test"
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/test")
+else(MSVC)
+  set_output_directory(LLVMFuzzer-DSO1
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
+  set_output_directory(LLVMFuzzer-DSO2
+    LIBRARY_DIR "${CMAKE_BINARY_DIR}/lib/Fuzzer/lib")
+endif()
 
 set(TestBinaries ${TestBinaries} LLVMFuzzer-DSOTest)
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27870.85210.patch
Type: text/x-patch
Size: 1844 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170121/4d986e3a/attachment-0001.bin>


More information about the llvm-commits mailing list