[llvm] r276710 - [CMake] Support feeding DYLD_LIBRARY_PATH into archiver calls

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 16:46:08 PDT 2016


Author: cbieneman
Date: Mon Jul 25 18:46:08 2016
New Revision: 276710

URL: http://llvm.org/viewvc/llvm-project?rev=276710&view=rev
Log:
[CMake] Support feeding DYLD_LIBRARY_PATH into archiver calls

OS X 10.11 has a feature named System Integrity Protection. The goal of the feature is to make system binaries immutable (even as root). One part of this is that protected binaries do not receive DYLD_* environment variables because the kernel scrubs them before process launch.

This causes problems for LTO bootstrap builds on Darwin that try to use the just-built libLTO with the host ar, ranlib, or libtool.

This patch addresses two problems.

(1) The tools themselves aren't protected binaries but the shim tools installed at / are, so we need to call xcrun -find to find libtool instead of using the one CMake finds.

(2) Some build tools (ninja and make) use /bin/sh to invoke their subprocesses. Since /bin/sh is a system binary, the kernel scrubs the DYLD envars from their environment. To work around this we need to set the environment variables as part of the archiver commands, so the envars are set by the shell process instead of on the shell process.

Modified:
    llvm/trunk/CMakeLists.txt

Modified: llvm/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/CMakeLists.txt?rev=276710&r1=276709&r2=276710&view=diff
==============================================================================
--- llvm/trunk/CMakeLists.txt (original)
+++ llvm/trunk/CMakeLists.txt Mon Jul 25 18:46:08 2016
@@ -50,19 +50,43 @@ project(LLVM
   ${cmake_3_0_LANGUAGES}
   C CXX ASM)
 
-if(APPLE)
-  if(NOT CMAKE_LIBTOOL)
+# This should only apply if you are both on an Apple host, and targeting Apple.
+if(CMAKE_HOST_APPLE AND APPLE)
+  if(NOT CMAKE_XCRUN)
+    find_program(CMAKE_XCRUN NAMES xcrun)
+  endif()
+  if(CMAKE_XCRUN)
+    execute_process(COMMAND ${CMAKE_XCRUN} -find libtool
+      OUTPUT_VARIABLE CMAKE_LIBTOOL
+      OUTPUT_STRIP_TRAILING_WHITESPACE)
+  endif()
+
+  if(NOT CMAKE_LIBTOOL OR NOT EXISTS CMAKE_LIBTOOL)
     find_program(CMAKE_LIBTOOL NAMES libtool)
   endif()
+
+  get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
   if(CMAKE_LIBTOOL)
     set(CMAKE_LIBTOOL ${CMAKE_LIBTOOL} CACHE PATH "libtool executable")
     message(STATUS "Found libtool - ${CMAKE_LIBTOOL}")
-    get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
     foreach(lang ${languages})
       set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
         "${CMAKE_LIBTOOL} -static -o <TARGET> <LINK_FLAGS> <OBJECTS> ")
     endforeach()
   endif()
+
+  # If DYLD_LIBRARY_PATH is set we need to set it on archiver commands
+  if(DYLD_LIBRARY_PATH)
+    set(dyld_envar "DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}")
+    foreach(lang ${languages})
+      foreach(cmd ${CMAKE_${lang}_CREATE_STATIC_LIBRARY})
+        list(APPEND CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW
+             "${dyld_envar} ${cmd}")
+      endforeach()
+      set(CMAKE_${lang}_CREATE_STATIC_LIBRARY
+        ${CMAKE_${lang}_CREATE_STATIC_LIBRARY_NEW})
+    endforeach()
+  endif()
 endif()
 
 # The following only works with the Ninja generator in CMake >= 3.0.




More information about the llvm-commits mailing list