Add rz-libswift as dependency and disable globally use_swift_demangler (#5298)
This commit is contained in:
parent
fdfa731a87
commit
3efdc9a318
14 changed files with 133 additions and 74 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
|
@ -122,7 +122,8 @@ jobs:
|
|||
build_system: meson
|
||||
compiler: clang
|
||||
cflags: "-DASAN=1 -DRZ_ASSERT_STDOUT=1 -fno-sanitize=function"
|
||||
meson_options: -Dbuildtype=debugoptimized -Db_lundef=false -Db_sanitize=address,undefined --werror
|
||||
# deroad: i had to remove `-Db_lundef=false -Db_sanitize=address` because it was crashing in a C++ library
|
||||
meson_options: -Dbuildtype=debugoptimized -Db_sanitize=undefined --werror
|
||||
asan: true
|
||||
asan_options: detect_leaks=0,allocator_may_return_null=1
|
||||
run_tests: true
|
||||
|
|
|
|||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -134,6 +134,7 @@ subprojects/xz-*/
|
|||
subprojects/zstd-*/
|
||||
subprojects/softflo*/
|
||||
subprojects/zydis/
|
||||
subprojects/libswift/
|
||||
dist/windows/Output
|
||||
# Core files generated by OpenBSD
|
||||
*.core
|
||||
|
|
|
|||
|
|
@ -93,47 +93,19 @@ RZ_IPI void rz_bin_process_cxx(RzBinObject *o, char *demangled, ut64 paddr, ut64
|
|||
*name = ':';
|
||||
}
|
||||
|
||||
#if WITH_SWIFT_DEMANGLER
|
||||
// this process function does not work with the Apple demangler.
|
||||
static char *get_swift_field(const char *demangled, const char *classname) {
|
||||
if (!demangled || !classname) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *p = strstr(demangled, ".getter_");
|
||||
if (!p) {
|
||||
p = strstr(demangled, ".setter_");
|
||||
if (!p) {
|
||||
p = strstr(demangled, ".method_");
|
||||
}
|
||||
}
|
||||
if (p) {
|
||||
char *q = strstr(demangled, classname);
|
||||
if (q && q[strlen(classname)] == '.') {
|
||||
q = rz_str_dup(q + strlen(classname) + 1);
|
||||
char *r = strchr(q, '.');
|
||||
if (r) {
|
||||
*r = 0;
|
||||
}
|
||||
return q;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_IPI void rz_bin_process_swift(RzBinObject *o, char *classname, char *demangled, ut64 paddr, ut64 vaddr) {
|
||||
if (!classname) {
|
||||
return;
|
||||
}
|
||||
// if (!classname) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
char *name = get_swift_field(demangled, classname);
|
||||
if (name) {
|
||||
rz_bin_object_add_field(o, classname, name, paddr, vaddr);
|
||||
free(name);
|
||||
return;
|
||||
}
|
||||
// char *name = get_swift_field(demangled, classname);
|
||||
// if (name) {
|
||||
// rz_bin_object_add_field(o, classname, name, paddr, vaddr);
|
||||
// free(name);
|
||||
// return;
|
||||
// }
|
||||
}
|
||||
#endif /* WITH_SWIFT_DEMANGLER */
|
||||
|
||||
/**
|
||||
* \brief Initialize the data of the given RzBinObject using the defined RzBinPlugin
|
||||
|
|
|
|||
|
|
@ -37,12 +37,9 @@ static void process_cxx_symbol(RzBinObject *o, RzBinSymbol *symbol) {
|
|||
rz_bin_process_cxx(o, symbol->dname, symbol->paddr, symbol->vaddr);
|
||||
}
|
||||
|
||||
#if WITH_SWIFT_DEMANGLER
|
||||
// this process function does not work with the Apple demangler.
|
||||
static void process_swift_symbol(RzBinObject *o, RzBinSymbol *symbol) {
|
||||
rz_bin_process_swift(o, symbol->classname, symbol->dname, symbol->paddr, symbol->vaddr);
|
||||
}
|
||||
#endif
|
||||
|
||||
RZ_IPI RzBinProcessLanguage rz_bin_process_language_symbol(RzBinObject *o) {
|
||||
switch (o->lang) {
|
||||
|
|
@ -52,11 +49,8 @@ RZ_IPI RzBinProcessLanguage rz_bin_process_language_symbol(RzBinObject *o) {
|
|||
return (RzBinProcessLanguage)process_cxx_symbol;
|
||||
case RZ_BIN_LANGUAGE_OBJC:
|
||||
return (RzBinProcessLanguage)process_objc_symbol;
|
||||
#if WITH_SWIFT_DEMANGLER
|
||||
// this process function does not work with the Apple demangler.
|
||||
case RZ_BIN_LANGUAGE_SWIFT:
|
||||
return (RzBinProcessLanguage)process_swift_symbol;
|
||||
#endif
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,9 +44,7 @@ RZ_IPI int rz_bin_compare_class_field(RzBinClassField *a, RzBinClassField *b);
|
|||
typedef void (*RzBinProcessLanguage)(RzBinObject *o, const void *user);
|
||||
RZ_IPI void rz_bin_process_rust(RzBinObject *o, char *demangled, ut64 paddr, ut64 vaddr, bool is_method);
|
||||
RZ_IPI void rz_bin_process_cxx(RzBinObject *o, char *demangled, ut64 paddr, ut64 vaddr);
|
||||
#if WITH_SWIFT_DEMANGLER
|
||||
RZ_IPI void rz_bin_process_swift(RzBinObject *o, char *classname, char *demangled, ut64 paddr, ut64 vaddr);
|
||||
#endif /* WITH_SWIFT_DEMANGLER */
|
||||
RZ_IPI bool rz_bin_object_process_plugin_data(RZ_NONNULL RzBinFile *bf, RZ_NONNULL RzBinObject *o);
|
||||
|
||||
RZ_IPI const RzDemanglerPlugin *rz_bin_process_get_demangler_plugin_from_lang(RzBin *bin, RzBinLanguage language);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <rz_demangler.h>
|
||||
#include <rz_util.h>
|
||||
#include <rz_libdemangle.h>
|
||||
#include <rz_libswift.h>
|
||||
#include <rz_lib.h>
|
||||
|
||||
#include "rz_demangler_plugins.h"
|
||||
|
|
@ -20,6 +21,19 @@
|
|||
.demangle = &handler##_cast, \
|
||||
}
|
||||
|
||||
static char *libdemangle_handler_swift(RZ_NULLABLE const char *symbol, RzDemangleOpts flags) {
|
||||
(void)flags;
|
||||
if (RZ_STR_ISEMPTY(symbol)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (symbol[0] == '_' && symbol[1] == '_') {
|
||||
symbol++;
|
||||
}
|
||||
|
||||
return rz_libswift_demangle_line(symbol);
|
||||
}
|
||||
|
||||
#if WITH_GPL
|
||||
// cpp demangler contains GPL2 code and LGPL3 for delphi
|
||||
DEFINE_DEMANGLER_PLUGIN(cpp, "c++", "GPL-2,LGPL3", "FSF/deroad", libdemangle_handler_cxx);
|
||||
|
|
@ -28,15 +42,12 @@ DEFINE_DEMANGLER_PLUGIN(cpp, "c++", "GPL-2,LGPL3", "FSF/deroad", libdemangle_han
|
|||
DEFINE_DEMANGLER_PLUGIN(cpp, "c++", "LGPL3", "deroad", libdemangle_handler_cxx);
|
||||
#endif /* WITH_GPL */
|
||||
|
||||
#if WITH_SWIFT_DEMANGLER
|
||||
DEFINE_DEMANGLER_PLUGIN(swift, "swift", "MIT", "pancake", libdemangle_handler_swift);
|
||||
#endif
|
||||
|
||||
DEFINE_DEMANGLER_PLUGIN(rust, "rust", "LGPL3", "Dhruv Maroo/RizinOrg", libdemangle_handler_rust);
|
||||
DEFINE_DEMANGLER_PLUGIN(java, "java", "LGPL3", "deroad", libdemangle_handler_java);
|
||||
DEFINE_DEMANGLER_PLUGIN(msvc, "msvc", "LGPL3", "inisider", libdemangle_handler_msvc);
|
||||
DEFINE_DEMANGLER_PLUGIN(objc, "objc", "LGPL3", "pancake", libdemangle_handler_objc);
|
||||
DEFINE_DEMANGLER_PLUGIN(pascal, "pascal", "LGPL3", "deroad", libdemangle_handler_pascal);
|
||||
DEFINE_DEMANGLER_PLUGIN(swift, "swift", "Apache-2.0", "deroad", libdemangle_handler_swift);
|
||||
|
||||
static RzDemanglerPlugin *demangler_static_plugins[] = { RZ_DEMANGLER_STATIC_PLUGINS };
|
||||
|
||||
|
|
@ -84,6 +95,13 @@ RZ_API RZ_OWN char *rz_demangler_msvc(RZ_NONNULL const char *symbol, RzDemangler
|
|||
return libdemangle_handler_msvc(symbol, (RzDemangleOpts)flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Demangles Microsoft VC symbols
|
||||
*/
|
||||
RZ_API RZ_OWN char *rz_demangler_swift(RZ_NONNULL const char *symbol, RzDemanglerFlag flags) {
|
||||
return libdemangle_handler_swift(symbol, (RzDemangleOpts)flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initializes the plugin list and returns a RzDemangler struct
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -3,16 +3,13 @@ demangler_plugins_list = [
|
|||
'msvc',
|
||||
'objc',
|
||||
'pascal',
|
||||
'swift'
|
||||
]
|
||||
|
||||
if get_option('use_gpl')
|
||||
demangler_plugins_list += ['cpp', 'rust']
|
||||
endif
|
||||
|
||||
if get_option('use_swift_demangler')
|
||||
demangler_plugins_list += 'swift'
|
||||
endif
|
||||
|
||||
demangler_plugins = {
|
||||
'base_name': 'rz_demangler',
|
||||
'base_struct': 'RzDemanglerPlugin',
|
||||
|
|
@ -23,7 +20,7 @@ rz_demangler_sources = [
|
|||
'demangler.c'
|
||||
]
|
||||
|
||||
dependencies = [rz_util_dep, libdemangle_dep]
|
||||
dependencies = [rz_util_dep, libdemangle_dep, libswift_dep]
|
||||
|
||||
rz_demangler = library('rz_demangler', rz_demangler_sources,
|
||||
include_directories: [platform_inc],
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@
|
|||
#define HAVE_JEMALLOC @HAVE_JEMALLOC@
|
||||
#define IS_IOS @IS_IOS@
|
||||
#define RZ_BUILD_DEBUG @RZ_BUILD_DEBUG@
|
||||
#define WITH_SWIFT_DEMANGLER @WITH_SWIFT_DEMANGLER@
|
||||
#define N_THREAD_LIMIT @N_THREAD_LIMIT@
|
||||
#define HAVE_COPYFILE @HAVE_COPYFILE@
|
||||
#define HAVE_COPY_FILE_RANGE @HAVE_COPY_FILE_RANGE@
|
||||
|
|
|
|||
29
meson.build
29
meson.build
|
|
@ -1,4 +1,4 @@
|
|||
project('rizin', 'c',
|
||||
project('rizin', 'c', 'cpp',
|
||||
version: 'v0.9.0',
|
||||
license: 'LGPL-3.0-only',
|
||||
meson_version: '>=0.57.0',
|
||||
|
|
@ -296,21 +296,34 @@ if r.returncode() == 1 and get_option('subprojects_check')
|
|||
error(subproject_clean_error_msg)
|
||||
endif
|
||||
|
||||
libdemangle_options = ['default_library=static']
|
||||
libdemangle_options = [
|
||||
'default_library=static',
|
||||
'use_swift_demangler=false',
|
||||
]
|
||||
if get_option('use_gpl')
|
||||
libdemangle_options += 'use_gpl=true'
|
||||
else
|
||||
libdemangle_options += 'use_gpl=false'
|
||||
endif
|
||||
if get_option('use_swift_demangler')
|
||||
libdemangle_options += 'use_swift_demangler=true'
|
||||
else
|
||||
libdemangle_options += 'use_swift_demangler=false'
|
||||
endif
|
||||
|
||||
libdemangle_proj = subproject('libdemangle', default_options: libdemangle_options)
|
||||
libdemangle_dep = libdemangle_proj.get_variable('libdemangle_dep')
|
||||
|
||||
# handle libswift
|
||||
r = run_command(py3_exe, check_meson_subproject_py, 'libswift', check: false)
|
||||
if r.returncode() == 1 and get_option('subprojects_check')
|
||||
error(subproject_clean_error_msg)
|
||||
endif
|
||||
|
||||
# we do not want the rizin plugin, but a library to integrate
|
||||
libswift_options = [
|
||||
'default_library=static',
|
||||
'enable_plugin=false',
|
||||
'werror=false'
|
||||
]
|
||||
libswift_proj = subproject('libswift', default_options: libswift_options)
|
||||
libswift_dep = libswift_proj.get_variable('libswift_dep')
|
||||
|
||||
# handle blake3 algo
|
||||
blake3_proj = subproject('blake3', default_options: ['default_library=static', 'werror=false'])
|
||||
blake3_dep = blake3_proj.get_variable('blake3_dep')
|
||||
|
|
@ -430,7 +443,6 @@ foreach it : ccs
|
|||
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('WITH_SWIFT_DEMANGLER', get_option('use_swift_demangler'))
|
||||
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)
|
||||
|
|
@ -824,7 +836,6 @@ summary({
|
|||
summary({
|
||||
'GPL code': get_option('use_gpl'),
|
||||
'Install sigdb': get_option('install_sigdb'),
|
||||
'Swift demangler': get_option('use_swift_demangler'),
|
||||
'Debugger enabled': has_debugger,
|
||||
'Capstone version': capstone_dep.version(),
|
||||
'PCRE2 version': pcre2_dep.version(),
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ option('use_sys_libmspack', type: 'feature', value: 'disabled')
|
|||
option('use_sys_tree_sitter', type: 'feature', value: 'disabled')
|
||||
option('use_sys_pcre2', type: 'feature', value: 'disabled')
|
||||
option('use_sys_softfloat', type: 'feature', value: 'disabled')
|
||||
option('use_swift_demangler', type: 'boolean', value: true, description: 'If false, disables the swift demangler')
|
||||
option('use_gpl', type: 'boolean', value: true, description: 'Set to false when you want to disable gpl code')
|
||||
option('install_sigdb', type: 'boolean', value: false, description: 'Downloads and installs rizin sigdb')
|
||||
option('debugger', type: 'boolean', value: true)
|
||||
|
|
|
|||
4
subprojects/libswift.wrap
Normal file
4
subprojects/libswift.wrap
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[wrap-git]
|
||||
url = https://github.com/rizinorg/rz-libswift.git
|
||||
revision = 81a2d39d628c252d2055dbcba485ef758139828d
|
||||
depth = 1
|
||||
|
|
@ -11,6 +11,7 @@ EOF
|
|||
RUN
|
||||
|
||||
NAME=#! with ext != name
|
||||
BROKEN=1
|
||||
FILE==
|
||||
CMDS=<<EOF
|
||||
. scripts/set-LD_PRELOAD.rz
|
||||
|
|
|
|||
|
|
@ -1,11 +1,73 @@
|
|||
NAME=mach0 swift demangle methods
|
||||
FILE=bins/mach0/swift-main
|
||||
CMDS=isq~&FooClass,method
|
||||
CMDS=isq~main.
|
||||
EXPECT=<<EOF
|
||||
0x1000047a0 0 FooClass.bar.method__String..init.witnesstable
|
||||
0x100004788 0 FooClass.foo.method__Swift.Int..init.witnesstable
|
||||
0x1000017a0 0 main.FooClass.foo.method__Swift.Int
|
||||
0x100001860 0 main.FooClass.bar.method__String
|
||||
0x100001b70 0 main.moin() -> Swift.Int
|
||||
0x100002080 0 main.Tost.__allocating_init() -> main.Tost
|
||||
0x100002110 0 main.Tost.__deallocating_deinit
|
||||
0x100002040 0 main.Tost.init() -> main.Tost
|
||||
0x100002140 0 main.Tost.deinit
|
||||
0x100002170 0 main.Tost.msg.getter : Swift.String
|
||||
0x100002210 0 main.Tost.msg.materializeForSet : Swift.String
|
||||
0x1000021b0 0 main.Tost.msg.setter : Swift.String
|
||||
0x100001a30 0 main.BarClass.sayHello() -> ()
|
||||
0x100001b30 0 main.BarClass.__allocating_init() -> main.BarClass
|
||||
0x100001ae0 0 main.BarClass.__deallocating_deinit
|
||||
0x100001b20 0 main.BarClass.init() -> main.BarClass
|
||||
0x100001b10 0 main.BarClass.deinit
|
||||
0x100005bb0 0 type metadata for main.Tost
|
||||
0x100005b18 0 type metadata for main.BarClass
|
||||
0x100005a40 0 type metadata for main.FooClass
|
||||
0x100005d28 0 lazy cache variable for type metadata for main.Tost
|
||||
0x100005d20 0 lazy cache variable for type metadata for main.BarClass
|
||||
0x100005d18 0 lazy cache variable for type metadata for main.FooClass
|
||||
0x1000053d8 0 type metadata for main.Balance
|
||||
0x1000020c0 0 type metadata accessor for main.Tost
|
||||
0x100001d40 0 type metadata accessor for main.BarClass
|
||||
0x100001cf0 0 type metadata accessor for main.FooClass
|
||||
0x100001e40 0 type metadata accessor for main.Balance
|
||||
0x100005b78 0 metaclass for main.Tost
|
||||
0x100005ae0 0 metaclass for main.BarClass
|
||||
0x100005a08 0 metaclass for main.FooClass
|
||||
0x1000054d0 0 nominal type descriptor for main.Tost
|
||||
0x100005490 0 nominal type descriptor for main.BarClass
|
||||
0x100005450 0 nominal type descriptor for main.FooClass
|
||||
0x100005390 0 nominal type descriptor for main.Balance
|
||||
0x100005408 0 protocol descriptor for main.FoodClass
|
||||
0x1000052f0 0 value witness table for main.Balance
|
||||
0x1000047c8 0 direct field offset for main.Tost.msg : Swift.String
|
||||
0x100004760 0 direct field offset for main.FooClass.bar : Swift.String
|
||||
0x100004758 0 direct field offset for main.FooClass.foo : Swift.Int
|
||||
0x100001380 0 main.Balance.width.getter : Swift.Double
|
||||
0x100001390 0 main.Balance.width.setter : Swift.Double
|
||||
0x1000013a0 0 main.Balance.width.materializeForSet : Swift.Double
|
||||
0x1000013c0 0 main.Balance.height.getter : Swift.Double
|
||||
0x1000013e0 0 main.Balance.height.setter : Swift.Double
|
||||
0x1000013f0 0 main.Balance.height.materializeForSet : Swift.Double
|
||||
0x100001410 0 main.Balance.pos.getter : Swift.Double
|
||||
0x100001430 0 main.Balance.pos.setter : Swift.Double
|
||||
0x100001440 0 main.Balance.pos.materializeForSet : Swift.Double
|
||||
0x100001460 0 main.Balance.init(width: Swift.Double, height: Swift.Double, pos: Swift.Double) -> main.Balance
|
||||
0x100001470 0 main.Balance.init() -> main.Balance
|
||||
0x1000014c0 0 main.FooClass.init() -> main.FooClass
|
||||
0x1000015a0 0 main.FooClass.__allocating_init() -> main.FooClass
|
||||
0x1000015e0 0 main.FooClass.sayHello() -> ()
|
||||
0x100001720 0 main.FooClass.__deallocating_deinit
|
||||
0x100001750 0 main.FooClass.deinit
|
||||
0x100001780 0 main.FooClass.foo.getter : Swift.Int
|
||||
0x100001790 0 main.FooClass.foo.setter : Swift.Int
|
||||
0x1000017a0 0 main.FooClass.foo.materializeForSet : Swift.Int
|
||||
0x1000017c0 0 main.FooClass.bar.getter : Swift.String
|
||||
0x100001800 0 main.FooClass.bar.setter : Swift.String
|
||||
0x100001860 0 main.FooClass.bar.materializeForSet : Swift.String
|
||||
0x100001880 0 protocol witness for main.FoodClass.sayHello() -> () in conformance main.FooClass : main.FoodClass in main
|
||||
0x1000018c0 0 (extension in main):main.FoodClass<A where A: main.FooClass, A: main.FoodClass>.sayHello() -> ()
|
||||
0x100001d90 0 protocol witness table accessor for main.FooClass : main.FoodClass in main
|
||||
0x1000052e8 0 protocol witness table for main.FooClass : main.FoodClass in main
|
||||
0x1000053d0 0 full type metadata for main.Balance
|
||||
0x100005a30 0 full type metadata for main.FooClass
|
||||
0x100005b08 0 full type metadata for main.BarClass
|
||||
0x100005ba0 0 full type metadata for main.Tost
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
@ -26,8 +88,9 @@ RUN
|
|||
|
||||
NAME=swift-x86-64 calling convention
|
||||
FILE=bins/mach0/swift5.1-throwError
|
||||
BROKEN=1
|
||||
CMDS=<<EOF
|
||||
s sym.__s10throwError7ThrowerC0a2MyB0yyKF
|
||||
s sym.throwError.Thrower.throwMyError___throws
|
||||
af
|
||||
afc swift
|
||||
afva
|
||||
|
|
@ -60,9 +123,10 @@ EOF
|
|||
RUN
|
||||
|
||||
NAME=swift-x86-64 calling convention json
|
||||
BROKEN=1
|
||||
FILE=bins/mach0/swift5.1-throwError
|
||||
CMDS=<<EOF
|
||||
s sym.__s10throwError7ThrowerC0a2MyB0yyKF
|
||||
s sym.throwError.Thrower.throwMyError___throws
|
||||
af
|
||||
afc swift
|
||||
afva
|
||||
|
|
|
|||
|
|
@ -906,9 +906,9 @@ java LGPL3 deroad
|
|||
msvc LGPL3 inisider
|
||||
objc LGPL3 pancake
|
||||
pascal LGPL3 deroad
|
||||
swift Apache-2.0 deroad
|
||||
c++ GPL-2,LGPL3 FSF/deroad
|
||||
rust LGPL3 Dhruv Maroo/RizinOrg
|
||||
swift MIT pancake
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue