2025-08-27 10:38:10 +08:00
project ( 'rizin' , 'c' ,
2026-08-02 20:38:57 +02:00
version : 'v0.10.0' ,
2024-10-29 16:59:42 +01:00
license : 'LGPL-3.0-only' ,
2026-03-22 14:19:44 +08:00
meson_version : '>=0.58.0' ,
2021-02-03 12:31:11 -01:00
default_options : [
2021-03-10 18:00:56 +08:00
'buildtype=debugoptimized' ,
2021-02-03 12:31:11 -01:00
'b_vscrt=from_buildtype' ,
2022-07-06 22:03:37 +08:00
'warning_level=1' ,
2021-02-03 12:31:11 -01:00
]
2021-01-27 17:13:23 +01:00
)
2018-03-06 10:28:40 +03:00
2020-11-16 09:36:51 +01:00
py3_exe = import ( 'python' ) . find_installation ( )
2018-05-16 07:32:26 +01:00
git_exe = find_program ( 'git' , required : false )
2018-03-23 09:47:46 +03:00
pkgconfig_mod = import ( 'pkgconfig' )
2017-05-29 22:35:59 +02:00
2020-12-01 09:17:24 +01:00
# Python scripts used during the build process
create_tags_rz_py = files ( 'sys/create_tags_rz.py' )
syscall_preprocessing_py = files ( 'sys/syscall_preprocessing.py' )
2021-02-03 12:31:11 -01:00
check_meson_subproject_py = files ( 'sys/check_meson_subproject.py' )
2021-01-27 09:42:47 +01:00
git_exe_repo_py = files ( 'sys/meson_git_wrapper.py' )
2021-12-17 10:16:25 +01:00
cmake_package_prefix_dir_py = files ( 'sys/meson_cmake_prefix_dir.py' )
2020-12-01 09:17:24 +01:00
2021-01-29 09:54:18 +01:00
is_static_build = get_option ( 'static_runtime' )
2021-12-17 10:16:25 +01:00
is_static_libs_only = get_option ( 'default_library' ) == 'static'
if is_static_build and not is_static_libs_only
2021-02-03 12:31:11 -01:00
error ( 'Cannot use `static_runtime` when libraries are dynamically built. Set `--default-library=static` if you want to build statically.' )
2021-01-29 09:54:18 +01:00
endif
2021-01-27 17:13:23 +01:00
# Get rizin version and compute various version parts
2021-01-27 17:57:27 +01:00
rizin_version = meson . project_version ( ) . split ( 'v' ) [ 1 ]
2021-01-27 17:13:23 +01:00
rizin_version_split = rizin_version . split ( '.' )
rizin_version_major = rizin_version_split [ 0 ] . to_int ( )
rizin_version_minor = rizin_version_split [ 1 ] . to_int ( )
rizin_version_patch = rizin_version_split [ 2 ] . split ( '-' ) [ 0 ] . to_int ( )
rizin_version_number = 1000000 * rizin_version_major + 1000 * rizin_version_minor + rizin_version_patch
2022-08-03 17:04:11 +02:00
repo = meson . current_source_dir ( )
2018-02-06 15:41:42 +03:00
2022-05-10 11:06:59 +02:00
rizin_libversion = '@0@.@1@' . format ( rizin_version_major , rizin_version_minor )
2020-10-13 11:30:58 +02:00
message ( 'rizin lib version: ' + rizin_libversion )
2018-04-10 23:44:54 +03:00
2017-05-02 14:18:36 +02:00
# system dependencies
cc = meson . get_compiler ( 'c' )
2022-07-01 22:40:31 +02:00
cc_native = meson . get_compiler ( 'c' , native : true )
2017-05-02 14:18:36 +02:00
2017-12-03 21:26:13 +01:00
platform_deps = [ ]
2026-03-29 17:44:45 +08:00
platform_inc = [ '.' , 'librz' , 'librz/include' ]
2017-05-14 23:06:00 +02:00
if host_machine . system ( ) == 'windows'
2022-07-19 04:40:46 -03:00
add_project_arguments ( '-DPSAPI_VERSION=1' , language : 'c' )
2021-01-29 09:54:18 +01:00
platform_deps = [
cc . find_library ( 'ws2_32' ) ,
cc . find_library ( 'wininet' ) ,
cc . find_library ( 'psapi' ) ,
2026-01-12 18:55:20 +02:00
cc . find_library ( 'dbghelp' ) ,
2021-01-29 09:54:18 +01:00
]
2018-03-31 00:35:12 +03:00
endif
platform_inc = include_directories ( platform_inc )
2021-12-17 10:16:25 +01:00
lib_name_suffix = [ ]
lib_name_prefix = [ ]
if is_static_libs_only and cc . get_id ( ) == 'msvc'
# On MSVC meson uses the .a suffix and lib as prefix, but cmake and other
# tools expect a .lib suffix and no prefix
# https://mesonbuild.com/FAQ.html#why-does-building-my-project-with-msvc-output-static-libraries-called-libfooa
lib_name_suffix = 'lib'
lib_name_prefix = ''
endif
2021-03-02 11:26:47 +01:00
if is_static_build
if cc . get_id ( ) == 'msvc'
# Use -Db_vscrt=static_from_buildtype to avoid warnings due to multiple /M options
if get_option ( 'b_vscrt' ) == 'from_buildtype'
warning ( 'To avoid warnings due to multiple /M options, please also set -Db_vscrt=mt or -Db_vscrt=mtd.' )
add_project_arguments ( '/MT' , language : 'c' )
endif
else
if cc . has_link_argument ( '-static' )
add_project_link_arguments ( '-static' , language : 'c' )
endif
endif
2017-05-14 23:06:00 +02:00
endif
2017-05-30 18:38:19 +02:00
2024-10-29 09:11:34 +00:00
# These two warnings enum compare and conversion are necessary for the Capstone compatibility header.
# Newer compilers will warn about the comparison of different enums (arm64 and aarch64) in the header.
# Hence, we have to disable them for the newer once.
# Older compilers don't have these warnings and should not be included with #pragma
if cc . has_argument ( '-Wenum-conversion' )
2024-11-11 12:07:34 +01:00
add_project_arguments ( '-DCC_SUPPORTS_W_ENUM_CONVERION' , language : [ 'c' , 'cpp' ] )
2024-10-29 09:11:34 +00:00
endif
if cc . has_argument ( '-Wenum-compare' )
2024-11-11 12:07:34 +01:00
add_project_arguments ( '-DCC_SUPPORTS_W_ENUM_COMPARE' , language : [ 'c' , 'cpp' ] )
2024-10-29 09:11:34 +00:00
endif
2025-04-25 02:26:58 +08:00
if cc . has_argument ( '-std=gnu99' )
add_project_arguments ( '-std=gnu99' , language : [ 'c' , 'cpp' ] )
elif cc . has_argument ( '--std=gnu99' )
add_project_arguments ( '--std=gnu99' , language : [ 'c' , 'cpp' ] )
elif cc . has_argument ( '-std=c99' )
add_project_arguments ( '-std=c99' , language : [ 'c' , 'cpp' ] )
elif cc . has_argument ( '--std=c99' )
add_project_arguments ( '--std=c99' , language : [ 'c' , 'cpp' ] )
endif
2021-02-02 19:17:44 +01:00
# Sanitize correct usage of rz_strf()
if cc . has_argument ( '-Werror=sizeof-pointer-memaccess' )
2024-10-29 16:59:42 +01:00
add_project_arguments ( '-Werror=sizeof-pointer-memaccess' , language : [ 'c' , 'cpp' ] )
2021-02-02 19:17:44 +01:00
endif
2022-03-24 01:27:18 +01:00
if cc . has_argument ( '-Wimplicit-fallthrough=3' )
add_project_arguments ( '-Wimplicit-fallthrough=3' , language : [ 'c' , 'cpp' ] )
endif
2019-08-16 07:10:00 +03:00
if cc . get_id ( ) == 'clang-cl'
2021-02-11 16:04:38 +01:00
if cc . has_argument ( '-fcommon' )
add_project_arguments ( '-fcommon' , language : 'c' )
endif
2019-08-16 07:10:00 +03:00
add_project_arguments ( '-D__STDC__=1' , language : 'c' )
add_project_arguments ( '-D_CRT_DECLARE_NONSTDC_NAMES ' , language : 'c' )
add_project_arguments ( '-D_CRT_SECURE_NO_WARNINGS' , language : 'c' )
add_project_arguments ( '-D_CRT_NONSTDC_NO_DEPRECATE' , language : 'c' )
endif
2018-09-03 10:07:28 +02:00
if get_option ( 'default_library' ) == 'shared'
2021-02-03 12:31:11 -01:00
if cc . has_argument ( '-fvisibility=hidden' )
2024-10-29 16:59:42 +01:00
add_project_arguments ( '-fvisibility=hidden' , language : 'c' )
2018-09-03 10:07:28 +02:00
endif
endif
2022-07-17 15:33:51 +02:00
add_project_arguments ( [ '-DRZ_PLUGIN_INCORE=1' ] , language : 'c' )
2021-11-17 21:02:02 +08:00
b_sanitize_opt = get_option ( 'b_sanitize' )
if ( b_sanitize_opt . contains ( 'address' ) or b_sanitize_opt . contains ( 'undefined' ) ) and cc . get_id ( ) == 'clang'
2024-10-29 16:59:42 +01:00
add_project_arguments ( '-shared-libasan' , language : 'c' )
add_project_link_arguments ( '-shared-libasan' , language : 'c' )
add_project_arguments ( '-shared-libasan' , language : 'c' , native : true )
add_project_link_arguments ( '-shared-libasan' , language : 'c' , native : true )
2021-11-17 21:02:02 +08:00
endif
2018-09-03 10:07:28 +02:00
2022-08-01 23:28:34 +08:00
fs = import ( 'fs' )
2020-12-18 11:28:19 +01:00
rizin_prefix = get_option ( 'prefix' )
2021-01-21 09:13:41 +01:00
rizin_bindir = get_option ( 'bindir' )
2020-12-18 11:28:19 +01:00
rizin_libdir = get_option ( 'libdir' )
2021-12-17 10:16:25 +01:00
rizin_cmakedir = rizin_libdir / 'cmake'
2020-12-18 11:28:19 +01:00
rizin_incdir = get_option ( 'includedir' ) / 'librz'
rizin_datdir = get_option ( 'datadir' )
2023-03-30 10:00:38 +02:00
extra_prefix = get_option ( 'extra_prefix' )
2018-04-28 11:02:55 +03:00
if host_machine . system ( ) == 'windows'
2022-04-03 04:44:01 -03:00
rizin_prefix = fs . as_posix ( rizin_prefix ) . replace ( '/' , '\\\\' )
rizin_bindir = fs . as_posix ( rizin_bindir ) . replace ( '/' , '\\\\' )
rizin_libdir = fs . as_posix ( rizin_libdir ) . replace ( '/' , '\\\\' )
rizin_cmakedir = fs . as_posix ( rizin_cmakedir ) . replace ( '/' , '\\\\' )
rizin_incdir = fs . as_posix ( rizin_incdir ) . replace ( '/' , '\\\\' )
rizin_datdir = fs . as_posix ( rizin_datdir ) . replace ( '/' , '\\\\' )
2023-03-30 10:00:38 +02:00
rizin_datdir_rz = fs . as_posix ( rizin_datdir ) . replace ( '/' , '\\\\' )
2018-04-28 11:02:55 +03:00
else
2020-12-18 11:28:19 +01:00
rizin_datdir_rz = rizin_datdir / 'rizin'
endif
2023-03-30 10:00:38 +02:00
load_dirs = {
'rizin_sdb' : rizin_datdir_rz ,
'rizin_wwwroot' : rizin_datdir_rz / 'www' ,
'rizin_sigdb' : rizin_datdir_rz / 'sigdb' ,
'rizin_themes' : rizin_datdir_rz / 'cons' ,
'rizin_fortunes' : rizin_datdir_rz / 'fortunes' ,
'rizin_flags' : rizin_datdir_rz / 'flag' ,
'rizin_hud' : rizin_datdir_rz / 'hud' ,
'rizin_plugins' : rizin_libdir / 'rizin' / 'plugins' ,
'rizin_bindings' : rizin_libdir / 'rizin-bindings' ,
}
2022-02-22 03:08:56 +00:00
# Calcualte BINDIR's depth to be able to find the root directory during runtime
# in portable builds
2022-10-09 04:14:36 +02:00
py_cmd = 'import os; from pathlib import Path; print(len(Path(os.path.normpath(r"@0@")).parents) - len(Path(os.path.normpath(r"@1@")).parents))' . format ( rizin_prefix / rizin_bindir , rizin_prefix )
2022-03-25 15:57:39 +01:00
py_cmd = run_command ( py3_exe , '-c' , py_cmd , check : true )
2022-02-22 03:08:56 +00:00
bindir_depth = py_cmd . stdout ( ) . strip ( )
2023-03-30 10:00:38 +02:00
foreach load_dir , default_subdir : load_dirs
val = get_option ( load_dir )
2020-12-18 11:28:19 +01:00
if val != ''
2023-03-30 10:00:38 +02:00
set_variable ( load_dir , val )
else
val = default_subdir
if host_machine . system ( ) == 'windows'
val = fs . as_posix ( val ) . replace ( '/' , '\\\\' )
endif
set_variable ( load_dir , val )
2020-12-18 11:28:19 +01:00
endif
endforeach
2020-10-13 11:30:58 +02:00
2022-03-25 15:57:39 +01:00
cmake_package_relative_path = run_command ( py3_exe , cmake_package_prefix_dir_py , rizin_prefix , rizin_cmakedir / 'xxx' , check : true ) . stdout ( ) . strip ( )
2021-12-17 10:16:25 +01:00
2023-08-01 16:45:09 +08:00
subproject_clean_error_msg = 'Subprojects are not updated. Please run `git clean -dxff subprojects/` to delete all local subprojects directories. If you want to compile against current subprojects then set option `subprojects_check=false`.'
2021-12-11 13:30:01 +01:00
# handle capstone dependency
2026-05-05 23:39:52 +08:00
capstone_check_deps = [ ]
capstone_check_includes = [ ]
Make AArch64/ARM analysis and asm plugins Capstone v6 compatible. (#4011)
This commit refactors the AArch64 and partially the ARM
plugin to make it Capstone v6 compatible.
Due to the big API changes in Capstone v6 several changes
had to be made.
Because we need to be compatible to Capstone v4 and v5
many include guards are added as well.
Overview of changes done:
**ARM**
- Instruction alias were introduced. This leads to different
decoding and analysis paths taken for certain instructions.
Some alias have their IL code generated like the real
instruction now (no special handling needed anymore).
This change is responsible for many changes you'll encounter.
- The operand details of each instruction are now always the
one of the real instruction. Also for alias.
For example, if "MOV <Wd>, #<imm>" is an alias for `ORR <Wd>, WZR, #<imm>`,
the details by CS hold all three operands of "ORR".
Before, they held only the two of "MOV".
- Several bugs in variable and argument generation
were fixed. Especially the default variable width
for ARM Thumb was changed to 32bit instead of the 16bit.
**AArch64/ARM64**
The changes listed above for ARM, also apply to AArch64.
Additionally:
- Capstone v6 changed the name ARM64 now everywhere to AArch64.
To be compatible with Capstone v4/v5 AArch64 names must be wrapped
into macros which resolve the name, depending on the CS version used.
- Capstone v6 is now more consistent with
register real and alias names.
From now on we use the register alias by default.
**List squashed commit messages:**
[AArch64 CS v6 BEGIN] Change subproject config to use cs-auto-sync-aarch64 branch
Replace ARM64 with version sensitive macros.
Exclude alias if CS version >= 6
Update access to writeback member
Exclude instr alias from inclusion
Update memory operand printing to json.
Enable real instr. detail only for AArch64
Set correct arch name in meson.build for CS
Fix U/SBFM instructions and their alias.
Mark parameters with RZ_OUt/BORROW
Optimize register extension to skip some, if the width already matches.
Adapt width and lsb of U/SBFM alias instructions (ImmR and ImmS are from U/SBFM).
Fix tests correct semantic buy bad syntax
Pass alias MOV instructions to mov()
Handle CSET and CSETM alias
Fix lsl, lsr and asr by handling them as alias.
Fix mov alias.
Handle TST alias
Fix CNEG, CINV alias
Fix bfi and bfxil alias.
Fix sign extensions.
Fix compare instructions.
Fix NEG, NGC, NGCS, NEGS, MVN
Fix CINC
Fix multiply instructions.
Fix ROR
Run clang-format
Handle CMP for ESIL
Handle new position of memory disponents of post index operands.
Fix post-index operations.
Add missing writeback checks for Post and preindex
Handle UBFM and SBFM alias
Handl BFM alias
Handle CMP, CSET and CINC alias
Update meson file of for cs-aarch64 branch
Fix asm tests. Use reg alias now.
Fix condition confusion and incorrect operand usage.
Fix plf test.
Run clang-format
Use register alias in tests
Add support for fp and lr reg alias assembly.
Use reg alias in test
Rename cond tranlate functions r2 -> rz
Fix condition check which assume 0 == invalid.
Fix issues intruduced by rebase
Set CS commit to current next branch.
Rename ARM64 -> AArch64
Add missing source file to meson.build
Remove DisassemblerExtension.c file for CS v5
Update to newest capstone next branch
Bump up CS version
REVERT ME: Get Capstone v4/v5 via git clone until new tars are released.
Wrap setting of CS_DETAIL_REAL into CS version check
Add maybe-unitialized to Capstone C args.
Fix CS pre v6 build by adding guards.
Use reg alias now printed by default by CS.
Bump CS version to most recent next.
Fix build errors due to stircter alias handling in ARM.
Fix RzIL tests introduced by alias introduction to ARM.
Fix ESIL bugs introduced with ARM alias introduction.
- stackptr hasn't been set for POP and PUSH
Add support again for Thumb1 pop/push
Handle PUSHW and POPW alias
Update test case
Add more POP and PUSH alias and enrich detail for other versions of them.
Fix incorrect mem access width guesses for ARM thumb.
Set POP return info if it writes to PC
Fix tests about default var size and POP mem write direction.
Bump CS version to newest next.
Fix incorrect tests.
- TriCore: Functions were in ro section.
- Default arg width in ARM thumb is 32bit.
Revert check for a set stackptr.
stackptr is used in different ways:
1. Safes the offset from the stack frame base.
2. Is interpreted as somthing else for x86 and I cannot find out what, in a reasonably time.
Hence we cannot use it here consistently.
Remove check for non existing ARM_GRP_RET in CSv5
Fix incorrect stack offsets of variables.
'push <reg-list>' instructions for which the second register was the FP,
reset the stackptr variable to 0. This led to wrong bp offsets in the variable names.
In this case it was +0xc.
Bump CS version.
Add copy of meta-programming macros for capstone-sys build.
Update capstone-next.wrap
Use bracket-less met-programming macro to fix Windows build warnings.
Update wrap files for Capstone with branch names
Add new meta-programming macro
Add workaround for MSVC pre-processor bug.
2023-12-19 17:00:31 +00:00
capstone_dep = dependency ( 'capstone' , version : '>=4.0.2' , required : get_option ( 'use_sys_capstone' ) , static : is_static_build )
2021-12-11 13:30:01 +01:00
if not capstone_dep . found ( )
capstone_version = get_option ( 'use_capstone_version' )
2021-01-11 19:05:48 +00:00
if fs . is_file ( 'subprojects/capstone-' + capstone_version + '.wrap' )
r = run_command ( py3_exe , check_meson_subproject_py , 'capstone-' + capstone_version , check : false )
2021-12-11 13:30:01 +01:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-12-11 13:30:01 +01:00
endif
2021-01-11 19:05:48 +00:00
capstone_proj = subproject ( 'capstone-' + capstone_version , default_options : [ 'default_library=static' ] )
2021-12-11 13:30:01 +01:00
else
error ( 'Wrong capstone version selected. Please use one of the supported versions.' )
endif
capstone_dep = capstone_proj . get_variable ( 'capstone_dep' )
2026-05-05 23:39:52 +08:00
capstone_check_includes = capstone_proj . get_variable ( 'capstone_includes' )
Make AArch64/ARM analysis and asm plugins Capstone v6 compatible. (#4011)
This commit refactors the AArch64 and partially the ARM
plugin to make it Capstone v6 compatible.
Due to the big API changes in Capstone v6 several changes
had to be made.
Because we need to be compatible to Capstone v4 and v5
many include guards are added as well.
Overview of changes done:
**ARM**
- Instruction alias were introduced. This leads to different
decoding and analysis paths taken for certain instructions.
Some alias have their IL code generated like the real
instruction now (no special handling needed anymore).
This change is responsible for many changes you'll encounter.
- The operand details of each instruction are now always the
one of the real instruction. Also for alias.
For example, if "MOV <Wd>, #<imm>" is an alias for `ORR <Wd>, WZR, #<imm>`,
the details by CS hold all three operands of "ORR".
Before, they held only the two of "MOV".
- Several bugs in variable and argument generation
were fixed. Especially the default variable width
for ARM Thumb was changed to 32bit instead of the 16bit.
**AArch64/ARM64**
The changes listed above for ARM, also apply to AArch64.
Additionally:
- Capstone v6 changed the name ARM64 now everywhere to AArch64.
To be compatible with Capstone v4/v5 AArch64 names must be wrapped
into macros which resolve the name, depending on the CS version used.
- Capstone v6 is now more consistent with
register real and alias names.
From now on we use the register alias by default.
**List squashed commit messages:**
[AArch64 CS v6 BEGIN] Change subproject config to use cs-auto-sync-aarch64 branch
Replace ARM64 with version sensitive macros.
Exclude alias if CS version >= 6
Update access to writeback member
Exclude instr alias from inclusion
Update memory operand printing to json.
Enable real instr. detail only for AArch64
Set correct arch name in meson.build for CS
Fix U/SBFM instructions and their alias.
Mark parameters with RZ_OUt/BORROW
Optimize register extension to skip some, if the width already matches.
Adapt width and lsb of U/SBFM alias instructions (ImmR and ImmS are from U/SBFM).
Fix tests correct semantic buy bad syntax
Pass alias MOV instructions to mov()
Handle CSET and CSETM alias
Fix lsl, lsr and asr by handling them as alias.
Fix mov alias.
Handle TST alias
Fix CNEG, CINV alias
Fix bfi and bfxil alias.
Fix sign extensions.
Fix compare instructions.
Fix NEG, NGC, NGCS, NEGS, MVN
Fix CINC
Fix multiply instructions.
Fix ROR
Run clang-format
Handle CMP for ESIL
Handle new position of memory disponents of post index operands.
Fix post-index operations.
Add missing writeback checks for Post and preindex
Handle UBFM and SBFM alias
Handl BFM alias
Handle CMP, CSET and CINC alias
Update meson file of for cs-aarch64 branch
Fix asm tests. Use reg alias now.
Fix condition confusion and incorrect operand usage.
Fix plf test.
Run clang-format
Use register alias in tests
Add support for fp and lr reg alias assembly.
Use reg alias in test
Rename cond tranlate functions r2 -> rz
Fix condition check which assume 0 == invalid.
Fix issues intruduced by rebase
Set CS commit to current next branch.
Rename ARM64 -> AArch64
Add missing source file to meson.build
Remove DisassemblerExtension.c file for CS v5
Update to newest capstone next branch
Bump up CS version
REVERT ME: Get Capstone v4/v5 via git clone until new tars are released.
Wrap setting of CS_DETAIL_REAL into CS version check
Add maybe-unitialized to Capstone C args.
Fix CS pre v6 build by adding guards.
Use reg alias now printed by default by CS.
Bump CS version to most recent next.
Fix build errors due to stircter alias handling in ARM.
Fix RzIL tests introduced by alias introduction to ARM.
Fix ESIL bugs introduced with ARM alias introduction.
- stackptr hasn't been set for POP and PUSH
Add support again for Thumb1 pop/push
Handle PUSHW and POPW alias
Update test case
Add more POP and PUSH alias and enrich detail for other versions of them.
Fix incorrect mem access width guesses for ARM thumb.
Set POP return info if it writes to PC
Fix tests about default var size and POP mem write direction.
Bump CS version to newest next.
Fix incorrect tests.
- TriCore: Functions were in ro section.
- Default arg width in ARM thumb is 32bit.
Revert check for a set stackptr.
stackptr is used in different ways:
1. Safes the offset from the stack frame base.
2. Is interpreted as somthing else for x86 and I cannot find out what, in a reasonably time.
Hence we cannot use it here consistently.
Remove check for non existing ARM_GRP_RET in CSv5
Fix incorrect stack offsets of variables.
'push <reg-list>' instructions for which the second register was the FP,
reset the stackptr variable to 0. This led to wrong bp offsets in the variable names.
In this case it was +0xc.
Bump CS version.
Add copy of meta-programming macros for capstone-sys build.
Update capstone-next.wrap
Use bracket-less met-programming macro to fix Windows build warnings.
Update wrap files for Capstone with branch names
Add new meta-programming macro
Add workaround for MSVC pre-processor bug.
2023-12-19 17:00:31 +00:00
else
2026-05-05 23:39:52 +08:00
capstone_check_deps = [ capstone_dep ]
Make AArch64/ARM analysis and asm plugins Capstone v6 compatible. (#4011)
This commit refactors the AArch64 and partially the ARM
plugin to make it Capstone v6 compatible.
Due to the big API changes in Capstone v6 several changes
had to be made.
Because we need to be compatible to Capstone v4 and v5
many include guards are added as well.
Overview of changes done:
**ARM**
- Instruction alias were introduced. This leads to different
decoding and analysis paths taken for certain instructions.
Some alias have their IL code generated like the real
instruction now (no special handling needed anymore).
This change is responsible for many changes you'll encounter.
- The operand details of each instruction are now always the
one of the real instruction. Also for alias.
For example, if "MOV <Wd>, #<imm>" is an alias for `ORR <Wd>, WZR, #<imm>`,
the details by CS hold all three operands of "ORR".
Before, they held only the two of "MOV".
- Several bugs in variable and argument generation
were fixed. Especially the default variable width
for ARM Thumb was changed to 32bit instead of the 16bit.
**AArch64/ARM64**
The changes listed above for ARM, also apply to AArch64.
Additionally:
- Capstone v6 changed the name ARM64 now everywhere to AArch64.
To be compatible with Capstone v4/v5 AArch64 names must be wrapped
into macros which resolve the name, depending on the CS version used.
- Capstone v6 is now more consistent with
register real and alias names.
From now on we use the register alias by default.
**List squashed commit messages:**
[AArch64 CS v6 BEGIN] Change subproject config to use cs-auto-sync-aarch64 branch
Replace ARM64 with version sensitive macros.
Exclude alias if CS version >= 6
Update access to writeback member
Exclude instr alias from inclusion
Update memory operand printing to json.
Enable real instr. detail only for AArch64
Set correct arch name in meson.build for CS
Fix U/SBFM instructions and their alias.
Mark parameters with RZ_OUt/BORROW
Optimize register extension to skip some, if the width already matches.
Adapt width and lsb of U/SBFM alias instructions (ImmR and ImmS are from U/SBFM).
Fix tests correct semantic buy bad syntax
Pass alias MOV instructions to mov()
Handle CSET and CSETM alias
Fix lsl, lsr and asr by handling them as alias.
Fix mov alias.
Handle TST alias
Fix CNEG, CINV alias
Fix bfi and bfxil alias.
Fix sign extensions.
Fix compare instructions.
Fix NEG, NGC, NGCS, NEGS, MVN
Fix CINC
Fix multiply instructions.
Fix ROR
Run clang-format
Handle CMP for ESIL
Handle new position of memory disponents of post index operands.
Fix post-index operations.
Add missing writeback checks for Post and preindex
Handle UBFM and SBFM alias
Handl BFM alias
Handle CMP, CSET and CINC alias
Update meson file of for cs-aarch64 branch
Fix asm tests. Use reg alias now.
Fix condition confusion and incorrect operand usage.
Fix plf test.
Run clang-format
Use register alias in tests
Add support for fp and lr reg alias assembly.
Use reg alias in test
Rename cond tranlate functions r2 -> rz
Fix condition check which assume 0 == invalid.
Fix issues intruduced by rebase
Set CS commit to current next branch.
Rename ARM64 -> AArch64
Add missing source file to meson.build
Remove DisassemblerExtension.c file for CS v5
Update to newest capstone next branch
Bump up CS version
REVERT ME: Get Capstone v4/v5 via git clone until new tars are released.
Wrap setting of CS_DETAIL_REAL into CS version check
Add maybe-unitialized to Capstone C args.
Fix CS pre v6 build by adding guards.
Use reg alias now printed by default by CS.
Bump CS version to most recent next.
Fix build errors due to stircter alias handling in ARM.
Fix RzIL tests introduced by alias introduction to ARM.
Fix ESIL bugs introduced with ARM alias introduction.
- stackptr hasn't been set for POP and PUSH
Add support again for Thumb1 pop/push
Handle PUSHW and POPW alias
Update test case
Add more POP and PUSH alias and enrich detail for other versions of them.
Fix incorrect mem access width guesses for ARM thumb.
Set POP return info if it writes to PC
Fix tests about default var size and POP mem write direction.
Bump CS version to newest next.
Fix incorrect tests.
- TriCore: Functions were in ro section.
- Default arg width in ARM thumb is 32bit.
Revert check for a set stackptr.
stackptr is used in different ways:
1. Safes the offset from the stack frame base.
2. Is interpreted as somthing else for x86 and I cannot find out what, in a reasonably time.
Hence we cannot use it here consistently.
Remove check for non existing ARM_GRP_RET in CSv5
Fix incorrect stack offsets of variables.
'push <reg-list>' instructions for which the second register was the FP,
reset the stackptr variable to 0. This led to wrong bp offsets in the variable names.
In this case it was +0xc.
Bump CS version.
Add copy of meta-programming macros for capstone-sys build.
Update capstone-next.wrap
Use bracket-less met-programming macro to fix Windows build warnings.
Update wrap files for Capstone with branch names
Add new meta-programming macro
Add workaround for MSVC pre-processor bug.
2023-12-19 17:00:31 +00:00
# Package managers CS version has no meta programming macros for AArch64 -> ARM64 renaming
# (because it is outdated).
# With this define we includeour copy of those macros.
add_project_arguments ( [ '-DUSE_SYS_CAPSTONE' ] , language : 'c' )
2021-12-11 13:30:01 +01:00
endif
2026-05-05 23:39:52 +08:00
has_capstone_m68k_cpu32 = cc . compiles ( '' '
#include <capstone/capstone.h>
int main ( void ) {
cs_mode mode = CS_MODE_M68K_CPU32 ;
return mode == 0 ;
}
'' ' ,
dependencies : capstone_check_deps ,
include_directories : capstone_check_includes ,
name : 'Capstone has M68K CPU32 mode'
)
if has_capstone_m68k_cpu32
add_project_arguments ( [ '-DRZ_CAPSTONE_HAS_M68K_CPU32' ] , language : 'c' )
endif
2026-05-31 16:15:56 +08:00
has_capstone_m68k_coldfire = cc . compiles ( '' '
#include <capstone/capstone.h>
int main ( void ) {
cs_mode mode = CS_MODE_M68K_COLDFIRE | CS_MODE_M68K_CFV1 | CS_MODE_M68K_CFV2 | CS_MODE_M68K_CFV3 | CS_MODE_M68K_CFV4 | CS_MODE_M68K_CFV4E | CS_MODE_M68K_CFV5 ;
return mode == 0 ;
}
'' ' ,
dependencies : capstone_check_deps ,
include_directories : capstone_check_includes ,
name : 'Capstone has M68K ColdFire modes'
)
if has_capstone_m68k_coldfire
add_project_arguments ( [ '-DRZ_CAPSTONE_HAS_M68K_COLDFIRE' ] , language : 'c' )
endif
2026-05-06 09:23:40 +05:30
has_capstone_m680x_hcs12x = cc . compiles ( '' '
#include <capstone/capstone.h>
int main ( void ) {
cs_mode mode = CS_MODE_M680X_HCS12X ;
return mode == 0 ;
}
'' ' ,
dependencies : capstone_check_deps ,
include_directories : capstone_check_includes ,
name : 'Capstone has M680X HCS12X mode'
)
if has_capstone_m680x_hcs12x
add_project_arguments ( [ '-DRZ_CAPSTONE_HAS_M680X_HCS12X' ] , language : 'c' )
endif
2024-02-05 04:51:16 +00:00
# Handle PCRE2
cpu_jit_supported = [ 'aarch64' , 'arm' , 'mips' , 'mips64' , 'ppc' , 'ppc64' , 'riscv32' , 'riscv64' , 's390x' , 'x86' , 'x86_64' ]
2026-02-23 22:04:05 +05:30
pcre2_jit_supported = target_machine . cpu_family ( ) in cpu_jit_supported and cc . get_id ( ) != 'tcc' and target_machine . system ( ) not in [ 'darwin' , 'serenity' ]
2024-02-05 04:51:16 +00:00
if pcre2_jit_supported
add_project_arguments ( [ '-DSUPPORTS_PCRE2_JIT' ] , language : 'c' )
endif
pcre2_dep_opt = get_option ( 'use_sys_pcre2' )
pcre2_dep = disabler ( )
2025-10-01 10:09:55 +08:00
sys_pcre2_found = false
2024-02-05 04:51:16 +00:00
if ( pcre2_dep_opt . enabled ( ) or pcre2_dep_opt . auto ( ) ) and not meson . is_cross_build ( )
2025-10-01 10:09:55 +08:00
pcre2_deps = [ ]
sys_pcre2_found = true
foreach utf : [ 8 , 16 , 32 ]
pcre2_utf_dep = dependency ( 'libpcre2-@0@' . format ( utf ) , required : false , static : false )
if not pcre2_utf_dep . found ( )
sys_pcre2_found = false
endif
pcre2_deps + = pcre2_utf_dep
endforeach
if sys_pcre2_found
pcre2_dep = declare_dependency ( dependencies : pcre2_deps , version : pcre2_deps [ 0 ] . version ( ) )
else
2024-02-05 04:51:16 +00:00
pcre2_dep = cc . find_library ( 'pcre2' , required : true , static : true )
endif
else
2026-01-12 16:54:54 +00:00
pcre2_dep = dependency ( 'pcre2' , version : '>=10.42' , required : true , static : true , allow_fallback : true )
2024-02-05 04:51:16 +00:00
endif
if meson . is_cross_build ( )
pcre2_native_dep = dependency ( 'pcre2_cross_native' , required : true , static : true , native : true )
endif
2018-08-10 10:17:48 +02:00
# handle magic library
2021-11-25 00:39:57 +01:00
sys_magic_opt = get_option ( 'use_sys_magic' )
sys_magic = disabler ( )
if sys_magic_opt . enabled ( ) or sys_magic_opt . auto ( )
sys_magic = dependency ( 'libmagic' , required : false , static : is_static_build )
if not sys_magic . found ( )
sys_magic = cc . find_library ( 'magic' , required : sys_magic_opt , static : is_static_build )
endif
endif
2018-07-09 16:58:38 +02:00
2025-05-23 21:03:46 +08:00
# Handle Zydis library
sys_zydis_opt = get_option ( 'use_sys_zydis' )
zydis_dep = disabler ( )
if sys_zydis_opt . enabled ( ) or sys_zydis_opt . auto ( )
zydis_dep = dependency ( 'zydis' , required : false , static : is_static_build )
if not zydis_dep . found ( )
2026-06-25 09:39:18 +00:00
zydis_dep = cc . find_library ( 'Zydis' , required : sys_zydis_opt , static : is_static_build )
2025-05-23 21:03:46 +08:00
endif
endif
if ( sys_zydis_opt . auto ( ) and not zydis_dep . found ( ) ) or sys_zydis_opt . disabled ( )
zydis_proj = subproject ( 'zydis' , default_options : [ 'default_library=static' ] )
zydis_dep = zydis_proj . get_variable ( 'zydis_dep' )
add_project_arguments ( [ '-DZYDIS_STATIC_BUILD' ] , language : 'c' )
endif
2022-06-27 23:52:07 +02:00
# handle libmspack library
sys_libmspack_opt = get_option ( 'use_sys_libmspack' )
libmspack_dep = disabler ( )
if sys_libmspack_opt . enabled ( ) or sys_libmspack_opt . auto ( )
libmspack_dep = dependency ( 'libmspack' , required : false , static : is_static_build )
if not libmspack_dep . found ( )
libmspack_dep = cc . find_library ( 'mspack' , required : sys_libmspack_opt , static : is_static_build )
endif
endif
if ( sys_libmspack_opt . auto ( ) and not libmspack_dep . found ( ) ) or sys_libmspack_opt . disabled ( )
libmspack_proj = subproject ( 'libmspack' , default_options : [ 'default_library=static' ] )
libmspack_dep = libmspack_proj . get_variable ( 'libmspack_dep' )
endif
2018-08-10 10:17:48 +02:00
# handle xxhash library
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'xxhash' , check : false )
2021-02-05 21:14:46 +01:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-02-05 21:14:46 +01:00
endif
2021-02-04 13:06:12 +01:00
sys_xxhash_opt = get_option ( 'use_sys_xxhash' )
2021-02-05 21:14:46 +01:00
if sys_xxhash_opt . enabled ( ) or sys_xxhash_opt . auto ( )
2021-11-25 00:39:57 +01:00
xxhash_dep = dependency ( 'libxxhash' , required : false , static : is_static_build )
2021-02-05 21:14:46 +01:00
if not xxhash_dep . found ( )
xxhash_dep = cc . find_library ( 'xxhash' , required : sys_xxhash_opt , static : is_static_build )
endif
endif
2021-11-25 00:39:57 +01:00
if ( sys_xxhash_opt . auto ( ) and not xxhash_dep . found ( ) ) or sys_xxhash_opt . disabled ( )
2021-02-05 21:14:46 +01:00
xxhash_proj = subproject ( 'xxhash' , default_options : [ 'default_library=static' ] )
xxhash_dep = xxhash_proj . get_variable ( 'xxhash_dep' )
2018-08-06 15:18:50 +02:00
endif
2021-10-01 12:45:38 +02:00
# handle libdemangle
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'libdemangle' , check : false )
2021-10-01 12:45:38 +02:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-10-01 12:45:38 +02:00
endif
2025-08-16 00:03:55 +08:00
libdemangle_options = [
'default_library=static' ,
'use_swift_demangler=false' ,
]
2021-10-01 12:45:38 +02:00
libdemangle_proj = subproject ( 'libdemangle' , default_options : libdemangle_options )
libdemangle_dep = libdemangle_proj . get_variable ( 'libdemangle_dep' )
2026-03-06 19:47:59 +05:30
blake2_dep = dependency ( 'libblake2' , fallback : [ 'blake2' , 'libblake2_dep' ] )
2022-09-17 18:38:21 +02:00
# handle blake3 algo
2025-09-28 13:11:33 +08:00
blake3_dep = dependency ( 'libblake3' , required : get_option ( 'use_sys_blake3' ) , static : is_static_build )
if not blake3_dep . found ( )
blake3_proj = subproject ( 'blake3' , default_options : [ 'default_library=static' , 'werror=false' ] )
blake3_dep = blake3_proj . get_variable ( 'blake3_dep' )
endif
2022-09-17 18:38:21 +02:00
2018-08-10 10:17:48 +02:00
# handle openssl library
2021-02-04 13:06:12 +01:00
sys_openssl = dependency ( 'openssl' , required : get_option ( 'use_sys_openssl' ) , static : is_static_build )
2018-08-10 10:17:48 +02:00
2021-07-20 01:46:45 +08:00
# handle tree-sitter
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'tree-sitter' , check : false )
2021-07-20 01:46:45 +08:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-07-20 01:46:45 +08:00
endif
tree_sitter_dep = dependency ( 'tree-sitter' , required : get_option ( 'use_sys_tree_sitter' ) , static : is_static_build , fallback : [ ] )
if not tree_sitter_dep . found ( )
tree_sitter_proj = subproject ( 'tree-sitter' , default_options : [ 'default_library=static' ] )
tree_sitter_dep = tree_sitter_proj . get_variable ( 'tree_sitter_dep' )
2022-04-27 19:38:03 +02:00
meson . override_dependency ( 'tree-sitter' , tree_sitter_dep )
2021-07-20 01:46:45 +08:00
endif
2024-09-10 00:14:00 +08:00
# handle rizin-grammar-c
r = run_command ( py3_exe , check_meson_subproject_py , 'rizin-grammar-c' , check : false )
2024-06-14 08:26:37 +08:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
error ( subproject_clean_error_msg )
endif
2025-09-25 20:17:06 +08:00
rizin_grammar_c_proj = subproject ( 'rizin-grammar-c' , default_options : [ 'default_library=static' , 'werror=false' ] )
2025-04-29 18:14:32 +03:00
rizin_grammar_c_dep = rizin_grammar_c_proj . get_variable ( 'rizin_grammar_c_dep' )
# override done in rizin-grammar-c subproject
2024-06-14 08:26:37 +08:00
2018-11-27 15:46:35 +01:00
has_debugger = get_option ( 'debugger' )
2021-07-04 22:27:57 +01:00
have_ptrace = not [ 'windows' , 'cygwin' , 'sunos' , 'haiku' ] . contains ( host_machine . system ( ) )
2018-10-12 12:20:18 +02:00
use_ptrace_wrap = [ 'linux' ] . contains ( host_machine . system ( ) )
2018-11-27 15:46:35 +01:00
have_ptrace = have_ptrace and has_debugger
use_ptrace_wrap = use_ptrace_wrap and has_debugger
2018-10-12 12:20:18 +02:00
message ( 'HAVE_PTRACE: @0@' . format ( have_ptrace ) )
message ( 'USE_PTRACE_WRAP: @0@' . format ( use_ptrace_wrap ) )
2018-10-29 11:48:12 +01:00
checks_level = get_option ( 'checks_level' )
2020-10-02 16:09:13 +02:00
message ( 'RZ_CHECKS_LEVEL: @0@' . format ( checks_level ) )
2025-04-13 21:08:17 +08:00
if checks_level < 0 or checks_level > 3
error ( '`checks_level` must be between 0 and 3.' )
endif
2018-10-29 11:48:12 +01:00
2017-05-29 13:06:10 +02:00
userconf = configuration_data ( )
2022-07-01 22:40:31 +02:00
ccs = [ [ cc , userconf , host_machine , false ] ]
if meson . is_cross_build ( )
userconf_native = configuration_data ( )
ccs + = [ [ cc_native , userconf_native , build_machine , true ] ]
endif
userconfs = [ ]
foreach it : ccs
it_cc = it [ 0 ]
it_userconf = it [ 1 ]
it_machine = it [ 2 ]
it_native = it [ 3 ]
# required for linux
it_utl = it_cc . find_library ( 'util' , required : false , static : is_static_build )
it_ldl = it_cc . find_library ( 'dl' , required : false , static : is_static_build )
it_th = dependency ( 'threads' , required : false , static : is_static_build , native : it_native )
have_pthread = it_th . found ( ) and it_machine . system ( ) != 'windows'
if it_machine . system ( ) == 'sunos'
# workaround for Solaris until https://github.com/mesonbuild/meson/issues/4328 is fixed
2024-10-29 16:59:42 +01:00
it_mth = declare_dependency ( link_args : '-lm' )
2022-07-01 22:40:31 +02:00
else
it_mth = it_cc . find_library ( 'm' , required : false , static : is_static_build )
endif
it_lrt = dependency ( '' , required : false , native : it_native )
if not it_cc . has_function ( 'clock_gettime' , prefix : '#include <time.h>' ) and it_cc . has_header_symbol ( 'features.h' , '__GLIBC__' )
it_lrt = it_cc . find_library ( 'rt' , required : true , static : is_static_build )
endif
2026-02-23 22:04:05 +05:30
have_lrt = not [ 'windows' , 'darwin' , 'openbsd' , 'android' , 'haiku' , 'serenity' ] . contains ( it_machine . system ( ) )
2022-07-01 22:40:31 +02:00
if have_lrt and not it_lrt . found ( )
it_lrt = it_cc . find_library ( 'rt' , required : true , static : is_static_build )
endif
2023-10-05 05:38:33 +03:00
# FreeBSD has backtrace() in libexecinfo
it_lexecinfo = it_cc . find_library ( 'execinfo' , required : false )
2022-06-07 23:44:41 +02:00
2022-07-01 22:40:31 +02:00
it_userconf . set ( 'RZ_CHECKS_LEVEL' , checks_level )
it_userconf . set10 ( 'IS_PORTABLE' , get_option ( 'portable' ) )
it_userconf . set10 ( 'HAVE_LIB_MAGIC' , sys_magic . found ( ) )
it_userconf . set10 ( 'USE_LIB_MAGIC' , sys_magic . found ( ) )
2024-02-05 04:51:16 +00:00
it_userconf . set10 ( 'HAVE_LIB_PCRE2' , pcre2_dep . found ( ) )
it_userconf . set10 ( 'USE_LIB_PCRE2' , pcre2_dep . found ( ) )
2022-07-01 22:40:31 +02:00
it_userconf . set10 ( 'HAVE_LIB_XXHASH' , xxhash_dep . found ( ) )
it_userconf . set10 ( 'USE_LIB_XXHASH' , xxhash_dep . found ( ) )
it_userconf . set10 ( 'DEBUGGER' , has_debugger )
2023-03-30 10:00:38 +02:00
if extra_prefix != ''
it_userconf . set_quoted ( 'EXTRA_PREFIX' , extra_prefix )
else
it_userconf . set10 ( 'EXTRA_PREFIX' , false )
endif
2022-07-01 22:40:31 +02:00
it_userconf . set ( 'PREFIX' , rizin_prefix )
it_userconf . set ( 'BINDIR' , rizin_bindir )
it_userconf . set ( 'BINDIR_DEPTH' , bindir_depth )
it_userconf . set ( 'LIBDIR' , rizin_libdir )
it_userconf . set ( 'INCLUDEDIR' , rizin_incdir )
it_userconf . set ( 'DATADIR_RZ' , rizin_datdir_rz )
is_ppc = it_machine . cpu_family ( ) == 'ppc' or it_machine . cpu_family ( ) == 'ppc64'
it_userconf . set ( 'DATADIR' , rizin_datdir )
it_userconf . set ( 'WWWROOT' , rizin_wwwroot )
it_userconf . set ( 'SDB' , rizin_sdb )
it_userconf . set ( 'SIGDB' , rizin_sigdb )
it_userconf . set ( 'THEMES' , rizin_themes )
it_userconf . set ( 'FORTUNES' , rizin_fortunes )
it_userconf . set ( 'FLAGS' , rizin_flags )
it_userconf . set ( 'HUD' , rizin_hud )
it_userconf . set ( 'PLUGINS' , rizin_plugins )
it_userconf . set ( 'BINDINGS' , rizin_bindings )
2026-07-06 18:27:24 +08:00
if sys_openssl . found ( )
it_userconf . set10 ( 'HAVE_OPENSSL' , true )
ok = it_cc . has_function ( 'EVP_sm3' , prefix : '#include <openssl/evp.h>' , dependencies : [ sys_openssl ] )
it_userconf . set10 ( 'HAVE_OPENSSL_SM3' , ok )
else
it_userconf . set10 ( 'HAVE_OPENSSL' , false )
it_userconf . set10 ( 'HAVE_OPENSSL_SM3' , false )
endif
2022-07-01 22:40:31 +02:00
it_userconf . set10 ( 'WANT_DYLINK' , true )
it_userconf . set10 ( 'HAVE_PTRACE' , have_ptrace )
it_userconf . set10 ( 'USE_PTRACE_WRAP' , use_ptrace_wrap )
it_userconf . set10 ( 'WITH_GPL' , get_option ( 'use_gpl' ) )
it_userconf . set10 ( 'RZ_BUILD_DEBUG' , get_option ( 'buildtype' ) . startswith ( 'debug' ) )
ok = it_cc . has_header_symbol ( 'sys/personality.h' , 'ADDR_NO_RANDOMIZE' )
it_userconf . set10 ( 'HAVE_DECL_ADDR_NO_RANDOMIZE' , ok )
ok = it_cc . has_header_symbol ( 'sys/procctl.h' , 'PROC_ASLR_CTL' )
it_userconf . set10 ( 'HAVE_DECL_PROCCTL_ASLR_CTL' , ok )
it_userconf . set10 ( 'HAVE_THREADS' , it_th . found ( ) )
it_userconf . set10 ( 'HAVE_PTHREAD' , have_pthread )
it_userconf . set10 ( 'HAVE_LZMA' , get_option ( 'use_lzma' ) )
it_userconf . set10 ( 'HAVE_ZLIB' , get_option ( 'use_zlib' ) )
2025-10-01 10:10:41 +08:00
it_userconf . set10 ( 'USE_SYS_ZYDIS' , zydis_dep . found ( ) and zydis_dep . type_name ( ) != 'internal' )
2024-02-05 04:51:16 +00:00
it_userconf . set10 ( 'SUPPORTS_PCRE2_JIT' , pcre2_jit_supported )
2024-06-02 11:49:00 +08:00
it_userconf . set ( 'N_THREAD_LIMIT' , get_option ( 'n_thread_limit' ) )
2022-07-01 22:40:31 +02:00
if it_machine . system ( ) == 'freebsd' or it_machine . system ( ) == 'dragonfly'
add_project_link_arguments ( '-Wl,--unresolved-symbols,ignore-in-object-files' , language : 'c' , native : it_native )
add_project_link_arguments ( '-Wl,--allow-shlib-undefined' , language : 'c' , native : it_native )
endif
Use O_CLOEXEC when creating pipes so they are closed on exec
By default, pipes file descriptors are not closed on exec. This means
they are inherited by the child process. However, this may be a problem
in particular in multi-threading programs (e.g. rz-test), because EOF is
not sent to a pipe until the last pipe file descriptor is closed.
This commit makes sure that by default pipes are created with O_CLOEXEC,
so they are closed whenever an exec syscall is executed. Usually pipe
file descriptors are duplicated to be stdin/stdout/stderr of the
children process and those dupped file descriptors won't be closed on
exec.
In case pipe2 is not available (e.g. MacOS), we do a pipe + fcntl, which
is in theory racy (see man open(2)). For this reason pipe, exec, system,
etc. are wrapped in rz_sys and they use a global mutex to make sure a
pipe is either created and set as O_CLOEXEC or not created at all before
an exec operation is done.
On very old systems, O_CLOEXEC may not be available at all. In those
cases, which should be rare, we just keep a list of file descriptors
created with rz_sys_pipe that we need to close before executing another
process.
Interaction with external libs may be tricky. We expect external libs to
create files/pipes that need to be closed on exec with the right flags
and we expect rizin code to manually close pipes file descriptors as
appropriate if the exec syscall is executed by an external library
(non-rizin code).
Make sure execl is found by acr/make
2020-12-03 13:28:31 +01:00
2026-06-18 11:05:41 +08:00
# Old GNU ld (binutils 2.22, shipped with Debian Wheezy) combined with the
# --as-needed flag that Meson passes by default drops shared libraries that
# are needed only indirectly -- through another shared library -- rather than
# directly by the linked object files. It then (defaulting to
# --no-copy-dt-needed-entries) also refuses to resolve the symbol through the
# dropped library's own DT_NEEDED entry. Linking the rizin tools against the
# rizin shared libraries therefore fails with:
# librz_main.so.0.9.0: undefined reference to symbol 'rz_buf_size'
# librz_util.so.0.9.0: could not read symbols: Invalid operation
# even though librz_util, which defines the symbol, is already on the link
# line. Disable --as-needed for these old linkers so the indirectly-needed
# libraries stay on the link line and resolve directly; newer linkers handle
# this correctly on their own and keep the optimisation.
if it_cc . get_linker_id ( ) == 'ld.bfd'
ld_bin = find_program ( 'ld' , required : false , native : it_native )
if ld_bin . found ( )
ld_version_raw = run_command ( ld_bin , '--version' , check : false ) . stdout ( )
if ld_version_raw != ''
ld_version = ld_version_raw . split ( '\n' ) [ 0 ] . split ( ' ' ) [ - 1 ] . strip ( )
if ld_version . version_compare ( '<2.31' )
add_project_link_arguments ( '-Wl,--no-as-needed' , language : 'c' , native : it_native )
endif
endif
endif
endif
2022-07-01 22:40:31 +02:00
if it_machine . system ( ) == 'darwin'
# On older Mac OS X versions (at least Lion and older), environ is only available when compiling an executable,
# but we will use is primarily in shared libs. Unfortunately, it_cc.links() only checks for executable compiling,
# so this does not help us.
# But in fact, even the environ(7) man page on macOS 11.6 still claims that environ is not avaliable for
# shared libs (even though it seems to work) and suggests using _NSGetEnviron(), so let's just do this always.
have_environ = false
2022-07-18 21:37:19 -03:00
elif host_machine . system ( ) == 'windows'
code = '#include <stdlib.h>\n\nint main() { char **env = environ; }'
have_environ = cc . links ( code , name : 'have environ' )
2022-07-01 22:40:31 +02:00
else
code = '#include <unistd.h>\nextern char **environ;\nint main() { char **env = environ; }'
have_environ = it_cc . links ( code , name : 'have extern char **environ' )
endif
it_userconf . set10 ( 'HAVE_ENVIRON' , have_environ )
message ( 'HAVE_ENVIRON: @0@' . format ( have_environ ) )
code = '#if __is_target_os(ios)\nint x = 0;\n#endif\nint main() { x++; }'
is_ios = it_cc . links ( code , name : 'target is ios' )
it_userconf . set10 ( 'IS_IOS' , is_ios )
message ( 'IS_IOS: @0@' . format ( is_ios ) )
foreach item : [
2023-08-10 12:06:52 +02:00
[ 'arc4random' , '#include <stdlib.h>' , [ ] ] ,
2022-07-01 22:40:31 +02:00
[ 'arc4random_uniform' , '#include <stdlib.h>' , [ ] ] ,
[ 'explicit_bzero' , '#include <string.h>' , [ ] ] ,
[ 'explicit_memset' , '#include <string.h>' , [ ] ] ,
[ 'clock_nanosleep' , '#include <time.h>' , [ ] ] ,
[ 'clock_gettime' , '#include <time.h>' , [ it_lrt ] ] ,
[ 'sigaction' , '#include <signal.h>' , [ ] ] ,
[ 'pipe' , '#include <unistd.h>' , [ ] ] ,
[ 'execv' , '#include <unistd.h>' , [ ] ] ,
[ 'execve' , '#include <unistd.h>' , [ ] ] ,
[ 'execvp' , '#include <unistd.h>' , [ ] ] ,
[ 'execl' , '#include <unistd.h>' , [ ] ] ,
[ 'system' , '#include <stdlib.h>' , [ ] ] ,
[ 'realpath' , '#include <stdlib.h>' , [ ] ] ,
[ 'fork' , '#include <unistd.h>' , [ ] ] ,
[ 'nice' , '#include <unistd.h>' , [ ] ] ,
[ 'copyfile' , '#include <copyfile.h>' , [ ] ] ,
[ 'strlcpy' , '#include <string.h>' , [ ] ] ,
2025-08-24 16:10:19 +03:00
[ 'strlcat' , '#include <string.h>' , [ ] ] ,
2022-07-01 22:40:31 +02:00
[ 'strnlen' , '#include <string.h>' , [ ] ] ,
[ 'shm_open' , '#include <sys/mman.h>' , [ it_lrt ] ] ,
[ 'openpty' , '' , [ it_utl ] ] ,
[ 'forkpty' , '' , [ it_utl ] ] ,
[ 'login_tty' , '' , [ it_utl ] ] ,
[ 'pipe2' , '#define _GNU_SOURCE\n#include <fcntl.h>\n#include <unistd.h>' , [ ] ] ,
# copy_file_range for now disable on freebsd as it s not reliable even for small chunks
[ 'copy_file_range' , '#ifdef __linux__\n#define _GNU_SOURCE\n#include <unistd.h>\n#endif' , [ ] ] ,
2023-10-05 05:38:33 +03:00
[ 'backtrace' , '' , [ it_lexecinfo ] ] ,
2023-01-22 19:00:21 +05:30
[ '__builtin_bswap16' , '' , [ ] ] ,
[ '__builtin_bswap32' , '' , [ ] ] ,
[ '__builtin_bswap64' , '' , [ ] ] ,
2023-06-05 15:59:18 +08:00
[ '__builtin_clzll' , '' , [ ] ] ,
2025-09-16 16:07:44 +00:00
[ '__builtin_ctzll' , '' , [ ] ] ,
2026-04-13 10:15:49 +00:00
[ '__builtin_expect' , '' , [ ] ] ,
2023-02-27 18:19:23 +08:00
[ 'posix_memalign' , '#include <stdlib.h>' , [ ] ] ,
[ '_aligned_malloc' , '#include <malloc.h>' , [ ] ] ,
2022-07-01 22:40:31 +02:00
]
func = item [ 0 ]
ok = it_cc . has_function ( func , prefix : item [ 1 ] , dependencies : item [ 2 ] )
it_userconf . set10 ( 'HAVE_@0@' . format ( func . to_upper ( ) ) , ok )
endforeach
2026-03-02 06:31:35 +02:00
# Try to compile a basic SSE2 code snippet to discover if SSE2 is supported for the target arch
2026-03-04 17:54:18 +02:00
sse2_compiler_flag = it_cc . get_id ( ) == 'msvc' ? '/arch:SSE2' : '-msse2'
2026-03-02 06:31:35 +02:00
sse2_code = '' ' #include <emmintrin.h>
int main ( int argc , char * argv [ ] ) { __m128i v = _mm_set_epi32 ( 2 , 3 , 0 , 1 ) ; return 0 ; }
'' '
2026-03-04 17:54:18 +02:00
has_sse2 = it_cc . compiles ( sse2_code , args : [ sse2_compiler_flag ] , name : 'SSE2 code snippet' )
2026-03-02 06:31:35 +02:00
it_userconf . set10 ( 'HAVE_SSE2' , has_sse2 )
2026-03-04 17:54:18 +02:00
# Enable SSE2 compiler support since it may not be enabled by default
if has_sse2 and it_machine . cpu_family ( ) in [ 'x86' , 'x86_64' ]
add_project_arguments ( [ sse2_compiler_flag ] , language : 'c' , native : it_native )
endif
2022-07-01 22:40:31 +02:00
foreach item : [
[ 'linux/ashmem.h' , '' , [ ] ] ,
[ 'sys/shm.h' , '' , [ ] ] ,
[ 'sys/ipc.h' , '' , [ ] ] ,
[ 'sys/mman.h' , '' , [ ] ] ,
[ 'inttypes.h' , '' , [ ] ] ,
]
hdr = item [ 0 ]
ok = it_cc . has_header ( hdr , prefix : item [ 1 ] , dependencies : item [ 2 ] )
it_userconf . set10 ( 'HAVE_HEADER_@0@' . format ( hdr . underscorify ( ) . to_upper ( ) ) , ok )
endforeach
if it_userconf . get ( 'HAVE_PIPE2' ) == 1
add_project_arguments ( '-D_GNU_SOURCE' , language : [ 'c' , 'cpp' ] , native : it_native )
endif
userconfs + = [ [ it_userconf , it_lrt , it_utl , it_ldl , it_mth , it_th ] ]
endforeach
userconf = userconfs [ 0 ] [ 0 ]
lrt = userconfs [ 0 ] [ 1 ]
utl = userconfs [ 0 ] [ 2 ]
ldl = userconfs [ 0 ] [ 3 ]
mth = userconfs [ 0 ] [ 4 ]
th = userconfs [ 0 ] [ 5 ]
if meson . is_cross_build ( )
userconf_native = userconfs [ 1 ] [ 0 ]
lrt_native = userconfs [ 1 ] [ 1 ]
utl_native = userconfs [ 1 ] [ 2 ]
ldl_native = userconfs [ 1 ] [ 3 ]
mth_native = userconfs [ 1 ] [ 4 ]
th_native = userconfs [ 1 ] [ 5 ]
endif
rz_userconf_h_in = files ( 'librz/include/rz_userconf.h.in' )
2020-10-01 16:13:03 +02:00
rz_userconf_h = configure_file (
2022-07-01 22:40:31 +02:00
input : rz_userconf_h_in ,
2020-10-01 16:13:03 +02:00
output : 'rz_userconf.h' ,
2018-04-25 14:07:43 +03:00
configuration : userconf ,
2020-12-18 11:28:19 +01:00
install_dir : rizin_incdir
2018-03-23 09:47:46 +03:00
)
2017-05-29 13:06:10 +02:00
2021-01-27 09:42:47 +01:00
packager = get_option ( 'packager' )
packager_version = get_option ( 'packager_version' )
2021-01-27 16:43:47 +01:00
message ( 'Version Major: @0@0' . format ( rizin_version_major ) )
message ( 'Version Minor: @0@0' . format ( rizin_version_minor ) )
message ( 'Version Patch: @0@0' . format ( rizin_version_patch ) )
2021-01-27 09:42:47 +01:00
2017-05-29 22:35:59 +02:00
versionconf = configuration_data ( )
2020-10-13 11:30:58 +02:00
versionconf . set ( 'RZ_VERSION_MAJOR' , rizin_version_major )
versionconf . set ( 'RZ_VERSION_MINOR' , rizin_version_minor )
versionconf . set ( 'RZ_VERSION_PATCH' , rizin_version_patch )
versionconf . set ( 'RZ_VERSION_NUMBER' , rizin_version_number )
versionconf . set ( 'RZ_VERSION' , rizin_version )
2021-01-27 09:42:47 +01:00
if packager_version != ''
versionconf . set_quoted ( 'RZ_PACKAGER_VERSION' , packager_version )
if packager != ''
versionconf . set_quoted ( 'RZ_PACKAGER' , packager )
endif
endif
2020-10-01 16:13:03 +02:00
rz_version_h = configure_file (
2022-08-13 22:20:36 +08:00
input : 'librz/include/rz_build_version.h.in' ,
2022-08-10 10:49:17 -03:00
output : 'rz_build_version.h' ,
2018-04-25 14:07:43 +03:00
configuration : versionconf ,
2020-12-18 11:28:19 +01:00
install_dir : rizin_incdir
2018-03-23 09:47:46 +03:00
)
2017-06-17 16:29:42 -07:00
2022-08-01 23:28:34 +08:00
if git_exe . found ( ) and fs . exists ( '.git' )
gittip_file = custom_target ( 'gittip_file' ,
build_always_stale : true ,
build_by_default : true ,
output : 'gittip' ,
2024-10-29 16:59:42 +01:00
command : [ py3_exe , git_exe_repo_py , git_exe , repo , '@OUTPUT@' , 'rev-parse' , 'HEAD' ] ,
2022-08-01 23:28:34 +08:00
install : true ,
2022-08-11 23:13:38 +08:00
install_dir : rizin_datdir_rz
2022-08-01 23:28:34 +08:00
)
endif
2020-07-21 10:28:43 +02:00
# handle zlib dependency
2022-07-14 15:20:33 +02:00
zlib_dep = disabler ( )
if get_option ( 'use_zlib' )
r = run_command ( py3_exe , check_meson_subproject_py , 'zlib' , check : false )
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2022-07-14 15:20:33 +02:00
endif
2021-02-11 16:06:05 +01:00
2022-07-14 15:20:33 +02:00
zlib_dep = dependency ( 'zlib' , required : get_option ( 'use_sys_zlib' ) , static : is_static_build )
if not zlib_dep . found ( )
2023-06-02 12:15:59 +08:00
zlib_proj = subproject ( 'zlib' , default_options : [ 'default_library=static' , 'werror=false' ] )
2022-07-14 15:20:33 +02:00
zlib_dep = zlib_proj . get_variable ( 'zlib_dep' )
meson . override_dependency ( 'zlib' , zlib_dep )
endif
2020-07-21 10:28:43 +02:00
endif
2021-12-11 13:30:01 +01:00
# handle lz4 dependency
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'lz4' , check : false )
2021-12-11 13:30:01 +01:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-12-11 13:30:01 +01:00
endif
lz4_dep = dependency ( 'liblz4' , required : get_option ( 'use_sys_lz4' ) , static : is_static_build )
if not lz4_dep . found ( )
lz4_proj = subproject ( 'lz4' , default_options : [ 'default_library=static' ] )
lz4_dep = lz4_proj . get_variable ( 'lz4_dep' )
endif
2022-06-28 18:48:32 +02:00
# handle lzma dependency
liblzma_dep = disabler ( )
if get_option ( 'use_lzma' )
r = run_command ( py3_exe , check_meson_subproject_py , 'lzma' , check : false )
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2022-06-28 18:48:32 +02:00
endif
liblzma_dep = dependency ( 'liblzma' , required : get_option ( 'use_sys_lzma' ) , static : is_static_build )
if not liblzma_dep . found ( )
liblzma_proj = subproject ( 'liblzma' , default_options : [ 'default_library=static' ] )
liblzma_dep = liblzma_proj . get_variable ( 'lzma_dep' )
meson . override_dependency ( 'liblzma' , liblzma_dep )
endif
endif
2024-06-25 22:06:24 +05:30
# handle softfloat dependency
r = run_command ( py3_exe , check_meson_subproject_py , 'softfloat' , check : false )
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
error ( subproject_clean_error_msg )
endif
Improve RzIL floating-point support (#6626)
The `RzFloat` changes fix or improve:
- binary80 explicit-integer-bit, pseudo-value, infinity, and NaN handling;
- binary16 conversions;
- gradual underflow and directed rounding;
- overflow, underflow, invalid-operation, and inexact exception reporting;
- exception propagation through nested conversions and arithmetic operations;
- binary80 fused multiply-add rounding, including reduced-precision and double-rounding edge cases;
- thread-local SoftFloat state, preventing rounding state from leaking between threads.
The `RzIL` changes add scoped binary80 precision support through `RzFloatRPrecision` and `FWITH_RPREC`. The supported precisions are 32, 64, and 80. Precision scopes restore the
previous thread-local SoftFloat state after successful evaluation and evaluation failures.
Runtime rounding modes are represented explicitly by dedicated pure opcodes:
- `FCONVERT_WITH_RMODE`
- `FROUND_WITH_RMODE`
- `FSQRT_WITH_RMODE`
- `FADD_WITH_RMODE`
- `FSUB_WITH_RMODE`
- `FMUL_WITH_RMODE`
- `FDIV_WITH_RMODE`
- `FMOD_WITH_RMODE`
Their rounding-mode operand is a 32-bit IL bitvector whose values correspond to `RzFloatRMode`: RNE, RNA, RTP, RTN, and RTZ. Invalid operand widths are rejected by validation,
while invalid runtime values cause evaluation to fail with an error.
Dedicated opcodes keep runtime-controlled floating-point expressions compact. This is useful for architectures whose rounding mode is selected from register state and avoids the
expression duplication caused by expanding every operation into nested `ITE` branches.
The new operations are supported by:
- construction, duplication, and destruction;
- type and operand validation;
- VM evaluation;
- plain, Unicode, and JSON exporters;
- graph output and opcode stringification.
`FEXCEPT` now emits a VM event only when the queried exception is present, while preserving exceptions raised by nested conversions and arithmetic operations.
2026-08-10 01:06:17 +08:00
use_sys_softfloat = get_option ( 'use_sys_softfloat' )
# Keep the system probes method-specific so a rejected system dependency does
# not occupy the generic name overridden by the bundled subproject.
softfloat_probe_required = use_sys_softfloat . disabled ( ) ? use_sys_softfloat : false
softfloat_dep = dependency ( 'softfloat' , required : softfloat_probe_required , static : is_static_build , method : 'pkg-config' )
if not softfloat_dep . found ( ) and not use_sys_softfloat . disabled ( ) and host_machine . system ( ) in [ 'darwin' , 'ios' , 'tvos' , 'visionos' , 'watchos' ]
softfloat_dep = dependency ( 'softfloat' , required : false , static : is_static_build , method : 'extraframework' )
endif
if not softfloat_dep . found ( ) and not use_sys_softfloat . disabled ( )
softfloat_dep = dependency ( 'softfloat' , required : use_sys_softfloat , static : is_static_build , method : 'cmake' )
endif
use_bundled_softfloat = not softfloat_dep . found ( )
if softfloat_dep . found ( )
softfloat_tls_probe = '' '
#include <stdint.h>
#include <softfloat.h>
#if defined(_MSC_VER)
#define RZ_SOFTFLOAT_THREAD_LOCAL __declspec(thread)
#else
#define RZ_SOFTFLOAT_THREAD_LOCAL __thread
#endif
/ * Fails to compile unless < softfloat . h > itself declares the mutable state
* as thread - local , and fails to link unless the library definitions agree
* with those declarations . * /
extern RZ_SOFTFLOAT_THREAD_LOCAL uint_fast8_t softfloat_detectTininess ;
extern RZ_SOFTFLOAT_THREAD_LOCAL uint_fast8_t softfloat_roundingMode ;
extern RZ_SOFTFLOAT_THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags ;
extern RZ_SOFTFLOAT_THREAD_LOCAL uint_fast8_t extF80_roundingPrecision ;
int main ( void ) {
return softfloat_detectTininess + softfloat_roundingMode +
softfloat_exceptionFlags + extF80_roundingPrecision ;
}
'' '
if not cc . links ( softfloat_tls_probe , dependencies : softfloat_dep , name : 'system SoftFloat has thread-local state' )
if use_sys_softfloat . enabled ( )
error ( 'System SoftFloat must define its mutable state as thread-local' )
endif
warning ( 'System SoftFloat does not provide thread-local state; using the bundled dependency' )
use_bundled_softfloat = true
endif
endif
if use_bundled_softfloat
2024-09-04 03:18:21 +02:00
softfloat_proj = subproject ( 'softfloat' , default_options : [ 'default_library=static' ] )
2024-06-25 22:06:24 +05:30
softfloat_dep = softfloat_proj . get_variable ( 'softfloat_dep' )
endif
2024-08-16 17:40:32 +08:00
if meson . is_cross_build ( )
2024-09-04 03:18:21 +02:00
softfloat_cross_native_proj = subproject ( 'softfloat_cross_native' , default_options : [ 'default_library=static' , 'cross_native=true' ] )
softfloat_cross_native_dep = softfloat_cross_native_proj . get_variable ( 'softfloat_dep' )
2024-08-16 17:40:32 +08:00
endif
2021-12-11 13:30:01 +01:00
# handle zip dependency
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'libzip' , check : false )
2021-12-11 13:30:01 +01:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-12-11 13:30:01 +01:00
endif
libzip_dep = dependency ( 'libzip' , required : get_option ( 'use_sys_libzip' ) , static : is_static_build )
if not libzip_dep . found ( )
libzip_proj = subproject ( 'libzip' , default_options : [
'default_library=static' ,
2025-03-01 15:25:09 +08:00
'werror=false' ,
2021-12-11 13:30:01 +01:00
'static_runtime=@0@' . format ( is_static_build ) ,
'use_sys_openssl=@0@' . format ( get_option ( 'use_sys_libzip_openssl' ) ) ,
] )
libzip_dep = libzip_proj . get_variable ( 'libzip_dep' )
endif
2026-02-23 22:04:05 +05:30
if host_machine . system ( ) == 'serenity' and libzip_dep . found ( )
zlib_dep = dependency ( 'zlib' , required : true , static : is_static_build )
libzip_dep = declare_dependency (
dependencies : [ libzip_dep , zlib_dep ]
)
endif
2023-08-29 07:23:48 +08:00
# handle zstd dependency
r = run_command ( py3_exe , check_meson_subproject_py , 'zstd' , check : false )
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
error ( subproject_clean_error_msg )
endif
2023-09-15 08:38:37 +02:00
libzstd_dep = dependency ( 'libzstd' , required : get_option ( 'use_sys_libzstd' ) , static : is_static_build , fallback : [ ] )
if not libzstd_dep . found ( )
zstd_proj = subproject ( 'zstd' , default_options : [
'default_library=static' ,
'static_runtime=@0@' . format ( is_static_build ) ,
] )
libzstd_dep = zstd_proj . get_variable ( 'libzstd_dep' )
meson . override_dependency ( 'zstd' , libzstd_dep )
endif
2023-08-29 07:23:48 +08:00
2021-12-22 02:20:39 +01:00
# handle yxml dependency
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'yxml' , check : false )
2021-12-22 02:20:39 +01:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2021-12-22 02:20:39 +01:00
endif
yxml_proj = subproject ( 'yxml' , default_options : [ 'default_library=static' ] )
yxml_dep = yxml_proj . get_variable ( 'yxml_dep' )
2026-02-12 21:52:11 +08:00
# handle rzheap dependency
rzheap_proj = subproject ( 'rzheap' , default_options : [ 'default_library=static' ] )
rzheap_dep = rzheap_proj . get_variable ( 'rzheap_dep' )
2020-12-10 17:07:39 +01:00
use_rpath = false
2021-11-09 00:04:34 +01:00
use_rpath_absolute = false
2020-12-10 17:07:39 +01:00
if host_machine . system ( ) != 'windows' and get_option ( 'default_library' ) == 'shared'
2021-11-09 00:04:34 +01:00
if get_option ( 'local' ) == 'enabled'
2020-12-10 17:07:39 +01:00
use_rpath = true
2021-11-09 00:04:34 +01:00
elif get_option ( 'local' ) == 'absolute'
use_rpath_absolute = true
elif get_option ( 'local' ) == 'auto' and get_option ( 'prefix' ) != '/usr'
if host_machine . system ( ) == 'openbsd'
# OpenBSD's $ORIGIN only works in the way we would need it when running an
# executable by its actual path, but not when run through PATH.
# So let's use absolute rpaths there.
use_rpath_absolute = true
else
use_rpath = true
endif
2020-12-10 17:07:39 +01:00
endif
endif
2020-09-15 15:16:14 +08:00
rpath_exe = ''
rpath_lib = ''
2021-11-09 00:04:34 +01:00
rpath_summary = 'disabled'
2020-12-10 17:07:39 +01:00
if use_rpath
2022-02-22 03:08:56 +00:00
# Use bindir depth to create a path to the rootdir from bindir
2022-03-25 15:57:39 +01:00
py_cmd = 'import os; print("../" * @0@)' . format ( bindir_depth . to_int ( ) )
py_cmd = run_command ( py3_exe , '-c' , py_cmd , check : true )
path_to_rootdir = py_cmd . stdout ( ) . strip ( )
2022-02-22 03:08:56 +00:00
rpath_exe = '$ORIGIN/' + path_to_rootdir + get_option ( 'libdir' )
2020-09-15 15:16:14 +08:00
rpath_lib = '$ORIGIN'
2021-11-09 00:04:34 +01:00
rpath_summary = 'relative'
elif use_rpath_absolute
rpath_exe = get_option ( 'prefix' ) / get_option ( 'libdir' )
rpath_lib = get_option ( 'prefix' ) / get_option ( 'libdir' )
rpath_summary = 'absolute'
2020-09-15 15:16:14 +08:00
endif
2020-12-23 10:51:40 +01:00
# NOTE: this is to workaround an issue on Windows where unit tests don't use
# the right libraries, resulting in tests not being run properly
test_env_common_path = [ ]
build_root = meson . current_build_dir ( )
if host_machine . system ( ) == 'windows'
test_env_common_path + = [
2024-03-03 13:05:10 +08:00
build_root / 'librz' / 'arch' ,
2020-12-23 10:51:40 +01:00
build_root / 'librz' / 'bin' ,
build_root / 'librz' / 'config' ,
build_root / 'librz' / 'cons' ,
2021-11-11 20:29:59 +01:00
build_root / 'librz' / 'signature' ,
2020-12-23 10:51:40 +01:00
build_root / 'librz' / 'core' ,
2021-10-01 12:45:38 +02:00
build_root / 'librz' / 'demangler' ,
2021-05-14 13:47:30 +02:00
build_root / 'librz' / 'diff' ,
2020-12-23 10:51:40 +01:00
build_root / 'librz' / 'crypto' ,
build_root / 'librz' / 'debug' ,
build_root / 'librz' / 'egg' ,
build_root / 'librz' / 'flag' ,
2025-09-02 03:06:01 +05:00
build_root / 'librz' / 'mark' ,
2020-12-23 10:51:40 +01:00
build_root / 'librz' / 'hash' ,
build_root / 'librz' / 'io' ,
build_root / 'librz' / 'lang' ,
build_root / 'librz' / 'magic' ,
build_root / 'librz' / 'main' ,
build_root / 'librz' / 'parse' ,
build_root / 'librz' / 'reg' ,
build_root / 'librz' / 'search' ,
build_root / 'librz' / 'socket' ,
build_root / 'librz' / 'syscall' ,
2021-04-06 18:04:00 +08:00
build_root / 'librz' / 'type' ,
2020-12-23 10:51:40 +01:00
build_root / 'librz' / 'util' ,
]
endif
2020-09-15 15:16:14 +08:00
2021-12-22 02:20:39 +01:00
subdir ( 'librz' )
2018-03-05 02:10:28 +03:00
2022-02-28 14:32:38 +01:00
if get_option ( 'install_sigdb' )
2022-03-29 15:02:34 +02:00
r = run_command ( py3_exe , check_meson_subproject_py , 'sigdb' , check : false )
2022-02-28 14:32:38 +01:00
if r . returncode ( ) == 1 and get_option ( 'subprojects_check' )
2023-08-01 16:45:09 +08:00
error ( subproject_clean_error_msg )
2022-02-28 14:32:38 +01:00
endif
subproject ( 'sigdb' , default_options : [ 'sigdb_path=@0@' . format ( get_option ( 'prefix' ) / rizin_sigdb ) ] )
endif
2020-09-10 14:55:06 +02:00
cli_option = get_option ( 'cli' )
2021-12-22 02:20:39 +01:00
cli_enabled = cli_option . auto ( ) ? not meson . is_subproject ( ) : cli_option . enabled ( )
2020-09-10 14:55:06 +02:00
if cli_enabled
2021-12-22 02:20:39 +01:00
subdir ( 'binrz' )
2020-09-10 14:55:06 +02:00
2021-12-22 02:20:39 +01:00
install_data ( 'doc/hud' ,
install_dir : rizin_hud ,
rename : 'main'
2018-12-06 21:17:25 +07:00
)
endif
2018-03-05 02:10:28 +03:00
2021-12-22 02:20:39 +01:00
subdir ( 'test' )
2025-12-14 02:39:34 +08:00
subdir ( 'examples' )
2020-02-05 09:55:30 +01:00
2018-12-27 20:17:54 +07:00
install_data (
'doc/fortunes.fun' ,
'doc/fortunes.tips' ,
2020-10-13 11:30:58 +02:00
install_dir : rizin_fortunes
2018-03-05 02:10:28 +03:00
)
2021-12-17 22:01:21 +08:00
dist_script = 'sys/meson_dist_script.py'
2022-03-25 15:57:39 +01:00
if meson . version ( ) . version_compare ( '>=0.49.0' ) and meson . version ( ) . version_compare ( '<0.57.0' )
2021-12-17 22:01:21 +08:00
meson . add_dist_script ( meson . source_root ( ) / dist_script )
else
meson . add_dist_script ( files ( dist_script ) )
endif
2021-12-16 12:37:13 +01:00
2020-12-18 11:28:19 +01:00
summary ( {
'prefix' : rizin_prefix ,
2021-01-21 09:13:41 +01:00
'bindir' : rizin_bindir ,
2020-12-18 11:28:19 +01:00
'libdir' : rizin_libdir ,
'includedir' : rizin_incdir ,
'datadir' : rizin_datdir ,
'wwwroot' : rizin_wwwroot ,
'sdb' : rizin_sdb ,
2022-02-28 14:32:38 +01:00
'sigdb' : rizin_sigdb ,
2020-12-18 11:28:19 +01:00
'themes' : rizin_themes ,
'fortunes' : rizin_fortunes ,
'flags' : rizin_flags ,
'hud' : rizin_hud ,
'plugins' : rizin_plugins ,
'bindings' : rizin_bindings ,
} , section : 'Directories' )
summary ( {
2021-10-01 12:45:38 +02:00
'GPL code' : get_option ( 'use_gpl' ) ,
2022-02-28 14:32:38 +01:00
'Install sigdb' : get_option ( 'install_sigdb' ) ,
2020-12-18 11:28:19 +01:00
'Debugger enabled' : has_debugger ,
2021-12-11 13:30:01 +01:00
'Capstone version' : capstone_dep . version ( ) ,
2024-02-05 04:51:16 +00:00
'PCRE2 version' : pcre2_dep . version ( ) ,
'PCRE2 JIT' : pcre2_jit_supported ,
2021-02-04 13:06:12 +01:00
'System magic library' : sys_magic . found ( ) and sys_magic . type_name ( ) != 'internal' ,
2025-10-01 10:09:55 +08:00
'System pcre2 library' : pcre2_dep . found ( ) and sys_pcre2_found ,
2021-02-05 21:14:46 +01:00
'System xxhash library' : xxhash_dep . found ( ) and xxhash_dep . type_name ( ) != 'internal' ,
2022-06-27 23:52:07 +02:00
'System libmspack library' : libmspack_dep . found ( ) and libmspack_dep . type_name ( ) != 'internal' ,
2021-02-04 13:06:12 +01:00
'System openssl library' : sys_openssl . found ( ) and sys_openssl . type_name ( ) != 'internal' ,
2026-07-15 22:50:41 +08:00
'System openssl has SM3' : userconf . get ( 'HAVE_OPENSSL_SM3' , 0 ) != 0 ,
2021-02-04 13:06:12 +01:00
'System capstone library' : capstone_dep . found ( ) and capstone_dep . type_name ( ) != 'internal' ,
2025-05-23 21:03:46 +08:00
'System zydis library' : zydis_dep . found ( ) and zydis_dep . type_name ( ) != 'internal' ,
2021-02-04 13:06:12 +01:00
'System tree-sitter library' : tree_sitter_dep . found ( ) and tree_sitter_dep . type_name ( ) != 'internal' ,
'System lz4 library' : lz4_dep . found ( ) and lz4_dep . type_name ( ) != 'internal' ,
2022-06-28 18:48:32 +02:00
'System lzma library' : liblzma_dep . found ( ) and liblzma_dep . type_name ( ) != 'internal' ,
2024-06-25 22:06:24 +05:30
'System softfloat library' : softfloat_dep . found ( ) and softfloat_dep . type_name ( ) != 'internal' ,
2021-02-04 13:06:12 +01:00
'System zlib library' : zlib_dep . found ( ) and zlib_dep . type_name ( ) != 'internal' ,
2023-09-15 08:38:37 +02:00
'System zstd library' : libzstd_dep . found ( ) and libzstd_dep . type_name ( ) != 'internal' ,
2021-02-11 16:04:38 +01:00
'System zip library' : libzip_dep . found ( ) and libzip_dep . type_name ( ) != 'internal' ,
2025-09-28 13:11:33 +08:00
'System blake3 library' : blake3_dep . found ( ) and blake3_dep . type_name ( ) != 'internal' ,
2026-03-06 19:47:59 +05:30
'System blake2 library' : blake2_dep . found ( ) and blake2_dep . type_name ( ) != 'internal' ,
2020-12-18 11:28:19 +01:00
'Use ptrace-wrap' : use_ptrace_wrap ,
2021-11-09 00:04:34 +01:00
'Use RPATH' : rpath_summary ,
2020-12-18 11:28:19 +01:00
} , section : 'Configuration' , bool_yn : true )
2022-07-03 09:59:43 +08:00
# output will be slightly degraded if there's only 1 crca_crc hash plugin and/or last hash plugin is a crca_crc plugin
comb_hash_plugins = [ ]
in_crca_loop = false
2022-07-20 15:48:56 +02:00
foreach plugin : hash_plugins . get ( 'list' )
2022-07-03 09:59:43 +08:00
if plugin . startswith ( 'crca_crc' )
2022-07-04 09:19:10 +02:00
comb_hash_plugins + = ( in_crca_loop ? '' : 'crca_crc(' ) + plugin . split ( '_' ) [ 1 ] . split ( 'crc' ) [ 1 ]
2022-07-03 09:59:43 +08:00
in_crca_loop = true
else
if in_crca_loop
# add closing parenthesis to last crca_cec plugin
parenthesized_last = [ ]
foreach item : comb_hash_plugins
if item not in [ comb_hash_plugins [ - 1 ] ]
parenthesized_last + = item
endif
endforeach
parenthesized_last + = comb_hash_plugins [ - 1 ] + ')'
comb_hash_plugins = parenthesized_last
endif
comb_hash_plugins + = plugin
in_crca_loop = false
endif
endforeach
2020-12-18 11:28:19 +01:00
summary ( {
2024-03-03 13:05:10 +08:00
'Arch Plugins' : arch_plugins . get ( 'list' ) ,
2022-07-20 15:48:56 +02:00
'Binary Plugins' : bin_plugins . get ( 'list' ) ,
'BinXtr Plugins' : bin_xtr_plugins . get ( 'list' ) ,
'Core Plugins' : core_plugins . get ( 'list' ) ,
'Crypto Plugins' : crypto_plugins . get ( 'list' ) ,
'Debug Plugins' : debug_plugins . get ( 'list' ) ,
'Egg Plugins' : egg_plugins . get ( 'list' ) ,
'IO Plugins' : io_plugins . get ( 'list' ) ,
'Lang Plugins' : lang_plugins . get ( 'list' ) ,
2022-07-03 09:59:43 +08:00
'Hash Plugins' : comb_hash_plugins ,
2022-07-20 15:48:56 +02:00
'Demangler Plugins' : demangler_plugins . get ( 'list' ) ,
2021-01-05 17:36:12 +08:00
} , section : 'Plugins' , list_sep : ', ' )