2019-07-25 05:03:43 +08:00
|
|
|
cmake_minimum_required(VERSION 3.1.0)
|
2019-09-21 02:29:35 +08:00
|
|
|
|
|
|
|
include(CheckIncludeFiles)
|
|
|
|
|
2019-07-25 05:03:43 +08:00
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
|
|
|
project(libbolt_rt_project)
|
|
|
|
|
2019-09-21 02:29:35 +08:00
|
|
|
check_include_files(elf.h HAVE_ELF_H)
|
|
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
|
|
|
|
Adding automatic huge page support
Summary:
This patch enables automated hugify for Bolt.
When running Bolt against a binary with -hugify specified, Bolt will inject a call to a runtime library function at the entry of the binary. The runtime library calls madvise to map the hot code region into a 2M huge page. We support both new kernel with THP support and old kernels. For kernels with THP support we simply make a madvise call, while for old kernels, we first copy the code out, remap the memory with huge page, and then copy the code back.
With this change, we no longer need to manually call into hugify_self and precompile it with --hot-text. Instead, we could simply combine --hugify option with existing optimizations, and at runtime it will automatically move hot code into 2M pages.
Some details around the changes made:
1. Add an command line option to support --hugify. --hugify will automatically turn on --hot-text to get the proper hot code symbols. However, running with both --hugify and --hot-text is not allowed, since --hot-text is used on binaries that has precompiled call to hugify_self, which contradicts with the purpose of --hugify.
2. Moved the common utility functions out of instr.cpp to common.h, which will also be used by hugify.cpp. Added a few new system calls definitions.
3. Added a new class that inherits RuntimeLibrary, and implemented the necessary emit and link logic for hugify.
4. Added a simple test for hugify.
(cherry picked from FBD21384529)
2020-05-03 02:14:38 +08:00
|
|
|
add_library(bolt_rt_instr STATIC
|
2019-07-25 05:03:43 +08:00
|
|
|
instr.cpp
|
2019-09-21 02:29:35 +08:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
2019-07-25 05:03:43 +08:00
|
|
|
)
|
Adding automatic huge page support
Summary:
This patch enables automated hugify for Bolt.
When running Bolt against a binary with -hugify specified, Bolt will inject a call to a runtime library function at the entry of the binary. The runtime library calls madvise to map the hot code region into a 2M huge page. We support both new kernel with THP support and old kernels. For kernels with THP support we simply make a madvise call, while for old kernels, we first copy the code out, remap the memory with huge page, and then copy the code back.
With this change, we no longer need to manually call into hugify_self and precompile it with --hot-text. Instead, we could simply combine --hugify option with existing optimizations, and at runtime it will automatically move hot code into 2M pages.
Some details around the changes made:
1. Add an command line option to support --hugify. --hugify will automatically turn on --hot-text to get the proper hot code symbols. However, running with both --hugify and --hot-text is not allowed, since --hot-text is used on binaries that has precompiled call to hugify_self, which contradicts with the purpose of --hugify.
2. Moved the common utility functions out of instr.cpp to common.h, which will also be used by hugify.cpp. Added a few new system calls definitions.
3. Added a new class that inherits RuntimeLibrary, and implemented the necessary emit and link logic for hugify.
4. Added a simple test for hugify.
(cherry picked from FBD21384529)
2020-05-03 02:14:38 +08:00
|
|
|
add_library(bolt_rt_hugify STATIC
|
|
|
|
hugify.cpp
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
|
|
|
)
|
2019-09-21 02:29:35 +08:00
|
|
|
|
2019-08-08 07:09:50 +08:00
|
|
|
# Don't let the compiler think it can create calls to standard libs
|
Adding automatic huge page support
Summary:
This patch enables automated hugify for Bolt.
When running Bolt against a binary with -hugify specified, Bolt will inject a call to a runtime library function at the entry of the binary. The runtime library calls madvise to map the hot code region into a 2M huge page. We support both new kernel with THP support and old kernels. For kernels with THP support we simply make a madvise call, while for old kernels, we first copy the code out, remap the memory with huge page, and then copy the code back.
With this change, we no longer need to manually call into hugify_self and precompile it with --hot-text. Instead, we could simply combine --hugify option with existing optimizations, and at runtime it will automatically move hot code into 2M pages.
Some details around the changes made:
1. Add an command line option to support --hugify. --hugify will automatically turn on --hot-text to get the proper hot code symbols. However, running with both --hugify and --hot-text is not allowed, since --hot-text is used on binaries that has precompiled call to hugify_self, which contradicts with the purpose of --hugify.
2. Moved the common utility functions out of instr.cpp to common.h, which will also be used by hugify.cpp. Added a few new system calls definitions.
3. Added a new class that inherits RuntimeLibrary, and implemented the necessary emit and link logic for hugify.
4. Added a simple test for hugify.
(cherry picked from FBD21384529)
2020-05-03 02:14:38 +08:00
|
|
|
target_compile_options(bolt_rt_instr PRIVATE -ffreestanding -fno-exceptions -fno-rtti)
|
|
|
|
target_include_directories(bolt_rt_instr PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
target_compile_options(bolt_rt_hugify PRIVATE -ffreestanding -fno-exceptions -fno-rtti)
|
|
|
|
target_include_directories(bolt_rt_hugify PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
|
|
|
|
install(TARGETS bolt_rt_instr DESTINATION lib)
|
|
|
|
install(TARGETS bolt_rt_hugify DESTINATION lib)
|
2019-07-25 05:03:43 +08:00
|
|
|
|
2020-10-15 18:51:56 +08:00
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
add_library(bolt_rt_instr_osx STATIC
|
|
|
|
instr.cpp
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
|
|
|
)
|
|
|
|
target_include_directories(bolt_rt_instr_osx PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
|
|
|
target_compile_options(bolt_rt_instr_osx PRIVATE
|
|
|
|
-target x86_64-apple-darwin19.6.0
|
|
|
|
-ffreestanding
|
|
|
|
-fno-exceptions
|
|
|
|
-fno-rtti)
|
|
|
|
install(TARGETS bolt_rt_instr_osx DESTINATION lib)
|
|
|
|
endif()
|