]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a check on whether LLD links shared object
authorBrett Dong <brett.browning.dong@gmail.com>
Tue, 5 Nov 2019 07:00:03 +0000 (15:00 +0800)
committerMatthias Maier <tamiko@43-1.org>
Thu, 6 Feb 2020 16:52:46 +0000 (10:52 -0600)
cmake/checks/check_02_compiler_features.cmake

index 2ac63a12fb66e62562333d206ba9405218856be6..ce3e92cebb80e1affbc7dfe7ade338e6a5c33b14 100644 (file)
@@ -462,9 +462,42 @@ IF(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
     "
     int main() { return 0; }
     "
-    DEAL_II_COMPILER_HAS_FUSE_LD_LLD)
+    DEAL_II_COMPILER_LLD_LINKS_EXEC)
   RESET_CMAKE_REQUIRED()
 
+# It is observed that LLD refuses to produce a shared object from an object
+# file compiled by Intel Compiler, throwing error message saying
+#   ld.lld: error: can't create dynamic relocation R_X86_64_64 against symbol:
+#   __gxx_personality_v0 in readonly segment; recompile object files with -fPIC
+#   or pass '-Wl,-z,notext' to allow text relocations in the output
+# even if we actually had -fPIC option present. If we add -Wl,-z,notext, it
+# will link, but the produced libdeal_II.so is faulty and will crash randomly.
+#
+# Therefore here adds a check on whether LLD could produce a .so from the
+# object file compiled by the specified C++ compiler.
+# 
+# - Binrui Dong, 2019
+  IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+    ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument")
+  ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
+    ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-diag-error warn")
+  ENDIF()
+  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Werror")
+  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fuse-ld=lld")
+  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-shared")
+  ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-fPIC")
+  CHECK_CXX_SOURCE_COMPILES(
+    "
+    #include <iostream>
+    void foo() { std::cout << \"Hello, world!\" << std::endl; }
+    "
+    DEAL_II_COMPILER_LLD_LINKS_SO)
+  RESET_CMAKE_REQUIRED()
+
+  IF(DEAL_II_COMPILER_LLD_LINKS_EXEC AND DEAL_II_COMPILER_LLD_LINKS_SO)
+    set(DEAL_II_COMPILER_HAS_FUSE_LD_LLD 1)
+  ENDIF()
+
   IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
     ADD_FLAGS(CMAKE_REQUIRED_FLAGS "-Wno-unused-command-line-argument")
   ELSEIF(CMAKE_CXX_COMPILER_ID MATCHES "Intel")

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.