[PATCH] D39020: Made shlib compile explicitly AFTER all tools.

Mitch Phillips via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 14:15:17 PDT 2017


hctim created this revision.
Herald added a subscriber: mgorny.

llvm-cfi-verify (https://reviews.llvm.org/D38379) introduced a potential build failure when compiling with `-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON`. Specific versions of cmake seem to treat the `add_subdirectory()` rule differently. It seems as if old versions of cmake BFS these rules, adding them to the fringe for expansion later. Newer versions of cmake seem to immediately execute CMakeFiles that are present in this subdirectory.

If the subdirectory is expanded through the fringe, the globbing resultant from `llvm_add_implicit_projects()` from `cmake/modules/AddLLVM.cmake:1012` means that `tools/llvm-shlib/CMakeFile.txt` gets executed before `tools/llvm-cfi-verify/lib/CMakeFile.txt`. As the latter CMakeFile adds a new library, this expansion order means that the library files required the unit tests in `unittests/tools/llvm-cfi-verify/` are not present in the dynamic library. This causes unit tests to fail as the required functions can't be found.

This change solves the issue by ensuring that `tools/llvm-shlib` (and thus the shared library generation) is built after all the rest of the tools are built. This also potentially resolves further issues where a library defined in a directory that occurs lexicograpically after `llvm-shlib` would fail to add the library to the shared library.


https://reviews.llvm.org/D39020

Files:
  cmake/modules/AddLLVM.cmake
  tools/CMakeLists.txt


Index: tools/CMakeLists.txt
===================================================================
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -56,4 +56,8 @@
   add_llvm_external_project(${p})
 endforeach(p)
 
+# Add shlib as a subdirectory. This allows directories in this folder to add
+# libraries without worrying about which target will be executed first.
+add_llvm_subdirectory(LLVM TOOL llvm-shlib)
+
 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
Index: cmake/modules/AddLLVM.cmake
===================================================================
--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -1013,6 +1013,12 @@
   set(list_of_implicit_subdirs "")
   file(GLOB sub-dirs "${CMAKE_CURRENT_SOURCE_DIR}/*")
   foreach(dir ${sub-dirs})
+    # Exclude shlib from being implicitly added.
+    string(FIND ${dir} llvm-shlib is_shlib)
+    if(NOT(${is_shlib} EQUAL -1))
+      continue()
+    endif()
+
     if(IS_DIRECTORY "${dir}" AND EXISTS "${dir}/CMakeLists.txt")
       canonicalize_tool_name(${dir} name)
       if (${project}_TOOL_${name}_BUILD)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39020.119387.patch
Type: text/x-patch
Size: 1099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171017/8470dc8d/attachment.bin>


More information about the llvm-commits mailing list