llvm-project/compiler-rt/lib/scudo/standalone/CMakeLists.txt

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

168 lines
4.3 KiB
CMake
Raw Normal View History

add_compiler_rt_component(scudo_standalone)
if (COMPILER_RT_HAS_GWP_ASAN)
add_dependencies(scudo_standalone gwp_asan)
endif()
include_directories(../.. include)
set(SCUDO_CFLAGS)
list(APPEND SCUDO_CFLAGS
[scudo][standalone] Optimization pass Summary: This introduces a bunch of small optimizations with the purpose of making the fastpath tighter: - tag more conditions as `LIKELY`/`UNLIKELY`: as a rule of thumb we consider that every operation related to the secondary is unlikely - attempt to reduce the number of potentially extraneous instructions - reorganize the `Chunk` header to not straddle a word boundary and use more appropriate types Note that some `LIKELY`/`UNLIKELY` impact might be less obvious as they are in slow paths (for example in `secondary.cc`), but at this point I am throwing a pretty wide net, and it's consistant and doesn't hurt. This was mosly done for the benfit of Android, but other platforms benefit from it too. An aarch64 Android benchmark gives: - before: ``` BM_youtube/min_time:15.000/repeats:4/manual_time_mean 445244 us 659385 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_median 445007 us 658970 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_stddev 885 us 1332 us 4 ``` - after: ``` BM_youtube/min_time:15.000/repeats:4/manual_time_mean 415697 us 621925 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_median 415913 us 622061 us 4 BM_youtube/min_time:15.000/repeats:4/manual_time_stddev 990 us 1163 us 4 ``` Additional since `-Werror=conversion` is enabled on some platforms we are built on, enable it upstream to catch things early: a few sign conversions had slept through and needed additional casting. Reviewers: hctim, morehouse, eugenis, vitalybuka Reviewed By: vitalybuka Subscribers: srhines, mgorny, javed.absar, kristof.beyls, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D64664 llvm-svn: 366918
2019-07-25 00:36:01 +08:00
-Werror=conversion
-Wall
-nostdinc++)
# Remove -stdlib= which is unused when passing -nostdinc++.
string(REGEX REPLACE "-stdlib=[a-zA-Z+]*" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding SCUDO_CFLAGS)
append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SCUDO_CFLAGS)
scudo: Support memory tagging in the secondary allocator. This patch enhances the secondary allocator to be able to detect buffer overflow, and (on hardware supporting memory tagging) use-after-free and buffer underflow. Use-after-free detection is implemented by setting memory page protection to PROT_NONE on free. Because this must be done immediately rather than after the memory has been quarantined, we no longer use the combined allocator quarantine for secondary allocations. Instead, a quarantine has been added to the secondary allocator cache. Buffer overflow detection is implemented by aligning the allocation to the right of the writable pages, so that any overflows will spill into the guard page to the right of the allocation, which will have PROT_NONE page protection. Because this would require the secondary allocator to produce a header at the correct position, the responsibility for ensuring chunk alignment has been moved to the secondary allocator. Buffer underflow detection has been implemented on hardware supporting memory tagging by tagging the memory region between the start of the mapping and the start of the allocation with a non-zero tag. Due to the cost of pre-tagging secondary allocations and the memory bandwidth cost of tagged accesses, the allocation itself uses a tag of 0 and only the first four pages have memory tagging enabled. This is a reland of commit 7a0da8894348 which was reverted in commit 9678b07e42ee. This reland includes the following changes: - Fix the calculation of BlockSize which led to incorrect statistics returned by mallinfo(). - Add -Wno-pedantic to silence GCC warning. - Optionally add some slack at the end of secondary allocations to help work around buggy applications that read off the end of their allocation. Differential Revision: https://reviews.llvm.org/D93731
2020-12-22 10:39:03 +08:00
append_list_if(COMPILER_RT_HAS_WNO_PEDANTIC -Wno-pedantic SCUDO_CFLAGS)
# FIXME: find cleaner way to agree with GWPAsan flags
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SCUDO_CFLAGS)
if (COMPILER_RT_HAS_GWP_ASAN)
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG -fno-omit-frame-pointer
SCUDO_CFLAGS)
append_list_if(COMPILER_RT_HAS_OMIT_FRAME_POINTER_FLAG
-mno-omit-leaf-frame-pointer SCUDO_CFLAGS)
endif() # COMPILER_RT_HAS_GWP_ASAN
if(COMPILER_RT_DEBUG)
list(APPEND SCUDO_CFLAGS -O0)
else()
list(APPEND SCUDO_CFLAGS -O3)
endif()
set(SCUDO_LINK_FLAGS)
list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro)
append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SCUDO_LINK_FLAGS)
if(ANDROID)
list(APPEND SCUDO_CFLAGS -fno-emulated-tls)
# Put the shared library in the global group. For more details, see
# android-changes-for-ndk-developers.md#changes-to-library-search-order
append_list_if(COMPILER_RT_HAS_Z_GLOBAL -Wl,-z,global SCUDO_LINK_FLAGS)
endif()
set(SCUDO_HEADERS
allocator_config.h
atomic_helpers.h
bytemap.h
checksum.h
chunk.h
combined.h
flags.h
flags_parser.h
fuchsia.h
internal_defs.h
linux.h
list.h
local_cache.h
mutex.h
platform.h
primary32.h
primary64.h
quarantine.h
release.h
report.h
secondary.h
size_class_map.h
stats.h
string_utils.h
tsd.h
tsd_exclusive.h
tsd_shared.h
vector.h
wrappers_c_checks.h
wrappers_c.h
include/scudo/interface.h
)
set(SCUDO_SOURCES
checksum.cpp
crc32_hw.cpp
common.cpp
flags.cpp
flags_parser.cpp
fuchsia.cpp
linux.cpp
release.cpp
report.cpp
string_utils.cpp
)
# Enable the SSE 4.2 instruction set for crc32_hw.cpp, if available.
if (COMPILER_RT_HAS_MSSE4_2_FLAG)
set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -msse4.2)
endif()
# Enable the AArch64 CRC32 feature for crc32_hw.cpp, if available.
# Note that it is enabled by default starting with armv8.1-a.
if (COMPILER_RT_HAS_MCRC_FLAG)
set_source_files_properties(crc32_hw.cpp PROPERTIES COMPILE_FLAGS -mcrc)
endif()
set(SCUDO_SOURCES_C_WRAPPERS
wrappers_c.cpp
)
set(SCUDO_SOURCES_CXX_WRAPPERS
wrappers_cpp.cpp
)
set(SCUDO_OBJECT_LIBS)
if (COMPILER_RT_HAS_GWP_ASAN)
list(APPEND SCUDO_OBJECT_LIBS
RTGwpAsan RTGwpAsanBacktraceLibc RTGwpAsanSegvHandler)
list(APPEND SCUDO_CFLAGS -DGWP_ASAN_HOOKS)
endif()
if(COMPILER_RT_HAS_SCUDO_STANDALONE)
add_compiler_rt_object_libraries(RTScudoStandalone
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS})
add_compiler_rt_object_libraries(RTScudoStandaloneCWrappers
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES_C_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS})
add_compiler_rt_object_libraries(RTScudoStandaloneCxxWrappers
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS})
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}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
PARENT_TARGET scudo_standalone)
add_compiler_rt_runtime(clang_rt.scudo_standalone_cxx
STATIC
ARCHS ${SCUDO_STANDALONE_SUPPORTED_ARCH}
SOURCES ${SCUDO_SOURCES_CXX_WRAPPERS}
ADDITIONAL_HEADERS ${SCUDO_HEADERS}
CFLAGS ${SCUDO_CFLAGS}
OBJECT_LIBS ${SCUDO_OBJECT_LIBS}
PARENT_TARGET scudo_standalone)
add_subdirectory(benchmarks)
if(COMPILER_RT_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
endif()