Skip to content

Commit

Permalink
[SCUDO] add cmake options for custom sysroot
Browse files Browse the repository at this point in the history
These options will allow the SCUDO standalone to be built with custom
headers. Specifically, this patch will enable building with the
LLVM-libc headers.

Reviewed By: abrachet

Differential Revision: https://reviews.llvm.org/D135702
  • Loading branch information
michaelrj-google committed Oct 12, 2022
1 parent 9f1f21c commit b9663eb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
7 changes: 7 additions & 0 deletions compiler-rt/CMakeLists.txt
Expand Up @@ -57,6 +57,13 @@ option(COMPILER_RT_BUILD_GWP_ASAN "Build GWP-ASan, and link it into SCUDO" ON)
mark_as_advanced(COMPILER_RT_BUILD_GWP_ASAN)
option(COMPILER_RT_ENABLE_CET "Build Compiler RT with CET enabled" OFF)

option(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH "Set custom sysroot for building SCUDO standalone" OFF)
mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
option(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED "Build SCUDO standalone for shared libraries" ON)
mark_as_advanced(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
option(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC "Build SCUDO standalone with LLVM's libc headers" OFF)
mark_as_advanced(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)

if(FUCHSIA)
set(COMPILER_RT_HWASAN_WITH_INTERCEPTORS_DEFAULT OFF)
else()
Expand Down
46 changes: 33 additions & 13 deletions compiler-rt/lib/scudo/standalone/CMakeLists.txt
Expand Up @@ -38,6 +38,10 @@ list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sectio
append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS)
append_list_if(CXX_SUPPORTS_UNWINDLIB_NONE_FLAG --unwindlib=none SCUDO_LINK_FLAGS)

if(COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH)
list(APPEND SCUDO_CFLAGS "--sysroot=${COMPILER_RT_SCUDO_STANDALONE_SYSROOT_PATH}")
endif()

if(ANDROID)
list(APPEND SCUDO_CFLAGS -fno-emulated-tls)

Expand Down Expand Up @@ -137,6 +141,14 @@ endif()

set(SCUDO_LINK_LIBS ${COMPILER_RT_UNWINDER_LINK_LIBS})

if(COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC)
include_directories(${COMPILER_RT_BINARY_DIR}/../libc/include/)

set(SCUDO_DEPS libc-headers)

list(APPEND SCUDO_CFLAGS "-ffreestanding")
endif()

append_list_if(COMPILER_RT_HAS_LIBPTHREAD -pthread SCUDO_LINK_FLAGS)

append_list_if(FUCHSIA zircon SCUDO_LINK_LIBS)
Expand All @@ -150,24 +162,28 @@ if(COMPILER_RT_HAS_SCUDO_STANDALONE)
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS})
CFLAGS ${SCUDO_CFLAGS}
DEPS ${SCUDO_DEPS})
add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES_C_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS})
CFLAGS ${SCUDO_CFLAGS}
DEPS ${SCUDO_DEPS})
add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS})
CFLAGS ${SCUDO_CFLAGS}
DEPS ${SCUDO_DEPS})

add_compiler_rt_runtime(clang_rt.scudo_standalone
STATIC
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS}
DEPS ${SCUDO_DEPS}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
PARENT_TARGET scudo_standalone)
add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx
Expand All @@ -176,18 +192,22 @@ if(COMPILER_RT_HAS_SCUDO_STANDALONE)
SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS}
DEPS ${SCUDO_DEPS}
PARENT_TARGET scudo_standalone)

add_compiler_rt_runtime(clang_rt.scudo_standalone
SHARED
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
LINK_FLAGS ${SCUDO_LINK_FLAGS}
LINK_LIBS ${SCUDO_LINK_LIBS}
PARENT_TARGET scudo_standalone)
if(COMPILER_RT_SCUDO_STANDALONE_BUILD_SHARED)
add_compiler_rt_runtime(clang_rt.scudo_standalone
SHARED
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES} ${SCUDO_SOURCES_C_WRAPPERS} ${SCUDO_SOURCES_CXX_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS}
DEPS ${SCUDO_DEPS}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
LINK_FLAGS ${SCUDO_LINK_FLAGS}
LINK_LIBS ${SCUDO_LINK_LIBS}
PARENT_TARGET scudo_standalone)
endif()

add_subdirectory(benchmarks)
if(COMPILER_RT_INCLUDE_TESTS)
Expand Down

0 comments on commit b9663eb

Please sign in to comment.