[PATCH] D42330: [Fuzzer] Use a custom macro to build internal version of libc++

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 19 18:54:47 PST 2018


phosek created this revision.
phosek added a reviewer: vitalybuka.
Herald added subscribers: Sanitizers, llvm-commits, mgorny.
Herald added a reviewer: EricWF.

add_custom_libcxx uses the just built compiler and installs the
built libc++, e.g. for testing, neither of which is desirable in
case of Fuzzer where the libc++ should be built using the host
compiler and it's only linked into the libFuzzer and should never
be installed. This change introduces add_internal_libcxx which
allows building such version of libc++.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D42330

Files:
  cmake/Modules/AddCompilerRT.cmake
  lib/fuzzer/CMakeLists.txt


Index: lib/fuzzer/CMakeLists.txt
===================================================================
--- lib/fuzzer/CMakeLists.txt
+++ lib/fuzzer/CMakeLists.txt
@@ -95,9 +95,9 @@
   foreach(arch ${FUZZER_SUPPORTED_ARCH})
     get_target_flags_for_arch(${arch} TARGET_CFLAGS)
     set(LIBCXX_${arch}_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_fuzzer_${arch})
-    add_custom_libcxx(libcxx_fuzzer_${arch} ${LIBCXX_${arch}_PREFIX}
+    add_internal_libcxx(libcxx_fuzzer_${arch} ${LIBCXX_${arch}_PREFIX}
       CFLAGS ${TARGET_CFLAGS}
-             -D_LIBCPP_ABI_VERSION=__Fuzzer
+             -D_LIBCPP_ABI_VERSION=Fuzzer
              -D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS=1
              -fvisibility=hidden
       CMAKE_ARGS -DLIBCXX_ENABLE_EXCEPTIONS=OFF
Index: cmake/Modules/AddCompilerRT.cmake
===================================================================
--- cmake/Modules/AddCompilerRT.cmake
+++ cmake/Modules/AddCompilerRT.cmake
@@ -459,6 +459,53 @@
     DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin)
 endmacro(add_compiler_rt_script src name)
 
+# Builds internal version of libc++.
+# Can be used to build private libc++ to be linked to other libraries.
+# add_internal_libcxx(<name> <prefix>
+#                     DEPS <list of build deps>
+#                     CFLAGS <list of compile flags>)
+macro(add_internal_libcxx name prefix)
+  if(NOT COMPILER_RT_LIBCXX_PATH)
+    message(FATAL_ERROR "libcxx not found!")
+  endif()
+
+  cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS;CMAKE_ARGS" ${ARGN})
+  foreach(flag ${LIBCXX_CFLAGS})
+    set(flagstr "${flagstr} ${flag}")
+  endforeach()
+  set(LIBCXX_CFLAGS ${flagstr})
+
+  ExternalProject_Add(${name}
+    PREFIX ${prefix}
+    SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
+    CMAKE_ARGS -DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM}
+               -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
+               -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
+               -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS}
+               -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS}
+               -DCMAKE_BUILD_TYPE=Release
+               -DLLVM_PATH=${LLVM_MAIN_SRC_DIR}
+               -DLIBCXX_STANDALONE_BUILD=On
+               ${LIBCXX_CMAKE_ARGS}
+    INSTALL_COMMAND ""
+    LOG_BUILD 1
+    LOG_CONFIGURE 1
+    )
+  set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
+
+  ExternalProject_Add_Step(${name} force-reconfigure
+    DEPENDERS configure
+    ALWAYS 1
+    )
+
+  ExternalProject_Add_Step(${name} clobber
+    COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
+    COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
+    COMMENT "Clobberring ${name} build directory..."
+    DEPENDERS configure
+    )
+endmacro()
+
 # Builds custom version of libc++ and installs it in <prefix>.
 # Can be used to build sanitized versions of libc++ for running unit tests.
 # add_custom_libcxx(<name> <prefix>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42330.130744.patch
Type: text/x-patch
Size: 2878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180120/d5c709a3/attachment.bin>


More information about the llvm-commits mailing list