# Vendored Ghidra decompiler (Apache-2.0, pinned — see VENDOR.md). # Builds libghidra_decompiler.a (full SSA decompiler), the SLEIGH spec compiler, # the per-arch .sla, and the pcode_dump smoke tool. Third-party code: warnings # suppressed and pinned to C++11 (the std it is validated against), independent # of fold's own warning/std flags. cpp_dir = 'cpp' # Use the z library without injecting SDK include dirs. On macOS Meson's zlib # dependency reports the SDK's usr/include as a normal -I path, which can appear # before libc++'s resource headers and break / lookup. The # headers are available through the compiler's default sysroot, so the link-only # dependency is sufficient for the vendored decompiler sources. zlib_dep = cpp.find_library('z', required: true) # Object sets mirror the upstream cpp/Makefile (CORE / DECCORE / SLEIGH). ghidra_core = [ 'xml', 'marshal', 'space', 'float', 'address', 'pcoderaw', 'translate', 'opcodes', 'globalcontext', ] ghidra_deccore = [ 'capability', 'architecture', 'options', 'graph', 'cover', 'block', 'cast', 'typeop', 'database', 'cpool', 'comment', 'stringmanage', 'modelrules', 'fspec', 'action', 'loadimage', 'grammar', 'varnode', 'op', 'type', 'variable', 'varmap', 'jumptable', 'emulate', 'emulateutil', 'flow', 'userop', 'expression', 'multiprecision', 'funcdata', 'funcdata_block', 'funcdata_op', 'funcdata_varnode', 'unionresolve', 'pcodeinject', 'heritage', 'prefersplit', 'rangeutil', 'ruleaction', 'subflow', 'blockaction', 'merge', 'double', 'transform', 'constseq', 'bitfield', 'coreaction', 'condexe', 'override', 'dynamic', 'crc32', 'prettyprint', 'printlanguage', 'printc', 'printjava', 'memstate', 'opbehavior', 'paramid', 'signature', ] ghidra_sleigh = [ 'sleigh', 'pcodeparse', 'pcodecompile', 'sleighbase', 'slghsymbol', 'slghpatexpress', 'slghpattern', 'semantics', 'context', 'slaformat', 'compression', 'filemanage', ] # Architecture / loader infrastructure (the EXTRA set, minus the BFD loader, # the GUI bridge, the SLEIGH compiler, the CLI console, and tests). Provides # SleighArchitecture + the spec-loading machinery the lifter embeds. ghidra_arch = [ 'sleigh_arch', 'inject_sleigh', 'loadimage_xml', 'xml_arch', 'raw_arch', ] ghidra_inc = include_directories(cpp_dir) ghidra_args = ['-w'] # vendored: do not police upstream warnings ghidra_opts = ['cpp_std=c++11', 'werror=false', 'optimization=2'] lib_srcs = [] foreach n : ghidra_core + ghidra_deccore + ghidra_sleigh + ghidra_arch lib_srcs += files(cpp_dir / (n + '.cc')) endforeach ghidra_decompiler = static_library( 'ghidra_decompiler', lib_srcs, cpp_args: ghidra_args, override_options: ghidra_opts, include_directories: ghidra_inc, dependencies: [zlib_dep], install: false, ) # link_whole: Ghidra registers print-language / architecture / loader # capabilities via global constructors; a plain static-lib link drops those # objects (nothing references them directly) and the decompiler then fails with # "No print languages registered". Whole-archive keeps every static initializer. ghidra_decompiler_dep = declare_dependency( link_whole: ghidra_decompiler, include_directories: ghidra_inc, dependencies: [zlib_dep], ) # SLEIGH spec compiler: CORE + SLEIGH runtime + the compiler-only TUs. sleigh_srcs = [] foreach n : ghidra_core + ghidra_sleigh + ['slgh_compile', 'slghparse', 'slghscan'] sleigh_srcs += files(cpp_dir / (n + '.cc')) endforeach ghidra_sleigh_exe = executable( 'ghidra_sleigh', sleigh_srcs, cpp_args: ghidra_args, override_options: ghidra_opts, include_directories: ghidra_inc, dependencies: [zlib_dep], install: false, ) # Compile target-arch .sla into the build dir (single-file form keeps the # source tree clean). Add arches here as their specs are vendored. ghidra_sla = [] foreach spec : ['AARCH64/AARCH64', 'AARCH64/AARCH64_AppleSilicon', 'AARCH64/AARCH64BE', 'x86/x86-64', 'x86/x86'] base = spec.split('/')[1] ghidra_sla += custom_target(base + '.sla', input: files('specs' / (spec + '.slaspec')), output: base + '.sla', command: [ghidra_sleigh_exe, '@INPUT@', '@OUTPUT@'], build_by_default: true, ) endforeach # Phase-1 smoke tool: lift a raw buffer to P-Code (no fold deps, no BFD). pcode_dump_exe = executable( 'pcode_dump', files('../../tools/pcode_dump.cpp'), cpp_args: ghidra_args, override_options: ghidra_opts, dependencies: [ghidra_decompiler_dep], install: false, ) # Phase-2 lifter glue + smoke driver. The glue (ghidra_lifter.cpp) includes the # Ghidra headers but is compiled at fold's C++ std (it returns std::optional / # fold::ir::pcode), linking the c++11-built ghidra lib. Warnings suppressed for # the Ghidra-header-heavy TU. fold_include = include_directories('../../include') ghidra_lifter_exe = executable( 'pcode_lift', files('../../tools/pcode_lift.cpp', '../../src/binary/ghidra_lifter.cpp'), cpp_args: ['-w'], override_options: ['werror=false'], include_directories: [fold_include, ghidra_inc], dependencies: [ghidra_decompiler_dep], install: false, )