Skip to content

Commit

Permalink
Add support for architecture registration
Browse files Browse the repository at this point in the history
To support building a static Capstone with many supported architectures
and only paying for the ones needed in each consumer. In this way they
won't have to build multiple copies of Capstone to minimize footprint.
  • Loading branch information
oleavr committed Jan 19, 2024
1 parent 25a69b5 commit 2663e20
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 112 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ option(CAPSTONE_BUILD_TESTS "Build tests" ${PROJECT_IS_TOP_LEVEL})
option(CAPSTONE_BUILD_CSTOOL "Build cstool" ${PROJECT_IS_TOP_LEVEL})
option(CAPSTONE_BUILD_CSTEST "Build cstest" OFF)
option(CAPSTONE_USE_DEFAULT_ALLOC "Use default memory allocation functions" ON)
option(CAPSTONE_USE_ARCH_REGISTRATION "Use explicit architecture registration" OFF)
option(CAPSTONE_ARCHITECTURE_DEFAULT "Whether architectures are enabled by default" ON)
option(CAPSTONE_DEBUG "Whether to enable extra debug assertions" OFF)
option(CAPSTONE_INSTALL "Generate install target" ${PROJECT_IS_TOP_LEVEL})
Expand Down Expand Up @@ -96,6 +97,10 @@ if(CAPSTONE_USE_DEFAULT_ALLOC)
add_definitions(-DCAPSTONE_USE_SYS_DYN_MEM)
endif()

if(CAPSTONE_USE_ARCH_REGISTRATION)
add_definitions(-DCAPSTONE_USE_ARCH_REGISTRATION)
endif()

if(CAPSTONE_X86_REDUCE)
add_definitions(-DCAPSTONE_X86_REDUCE)
endif()
Expand Down
7 changes: 5 additions & 2 deletions COMPILE_CMAKE.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ Get CMake for free from http://www.cmake.org.
Set this of OFF with -DCAPSTONE_ARCHITECTURE_DEFAULT=OFF to disable all architectures by default.
You can then enable them again with one of the CAPSTONE_<ARCH>_SUPPORT options.

By default, all architectures are compiled in.

By default, all architectures are compiled in. If you're building a static library that you intend to link into
multiple consumers, and they have differing architecture requirements, you may want -DCAPSTONE_USE_ARCH_REGISTRATION=1
and call cs_arch_register_*() for the architectures you need in each particular consumer. In this way you only pay
footprint size for the the architectures you're actually using in each consumer, without having to compile Capstone
multiple times.

Besides, Capstone also allows some more customization via following macros.

Expand Down
Loading

0 comments on commit 2663e20

Please sign in to comment.