diff --git a/devkit.py b/devkit.py index ba63856..e210316 100644 --- a/devkit.py +++ b/devkit.py @@ -31,7 +31,8 @@ def __init__(self, kit: str, machine: MachineSpec, meson_config: Mapping[str, Union[str, Sequence[str]]], - output_dir: Path): + output_dir: Path, + prefix_syms: bool = True): self.kit = kit package, umbrella_header = DEVKITS[kit] self.package = package @@ -42,6 +43,7 @@ def __init__(self, self.compiler_argument_syntax = None self.output_dir = output_dir self.library_filename = None + self.prefix_syms = prefix_syms def run(self): output_dir = self.output_dir @@ -263,14 +265,18 @@ def _do_generate_library_unix(self, library_paths): objcopy = meson_config.get("objcopy", None) if objcopy is not None: - thirdparty_symbol_mappings = get_thirdparty_symbol_mappings(output_path, meson_config) - - renames = "\n".join([f"{original} {renamed}" for original, renamed in thirdparty_symbol_mappings]) + "\n" - with tempfile.NamedTemporaryFile() as renames_file: - renames_file.write(renames.encode("utf-8")) - renames_file.flush() - subprocess.run(objcopy + ["--redefine-syms=" + renames_file.name, output_path], - check=True) + # New option to prevent renaming, to avoid erroneous bitcode symbols + if self.prefix_syms: + thirdparty_symbol_mappings = get_thirdparty_symbol_mappings(output_path, meson_config) + + renames = "\n".join([f"{original} {renamed}" for original, renamed in thirdparty_symbol_mappings]) + "\n" + with tempfile.NamedTemporaryFile() as renames_file: + renames_file.write(renames.encode("utf-8")) + renames_file.flush() + subprocess.run(objcopy + ["--redefine-syms=" + renames_file.name, output_path], + check=True) + else: + thirdparty_symbol_mappings = [] else: thirdparty_symbol_mappings = [] @@ -532,4 +538,4 @@ def tweak_flags(cflags, ldflags): def deduplicate(items): - return list(OrderedDict.fromkeys(items)) + return list(OrderedDict.fromkeys(items)) \ No newline at end of file diff --git a/env.py b/env.py index 2d850ea..ac656f1 100644 --- a/env.py +++ b/env.py @@ -69,7 +69,8 @@ def generate_machine_configs(build_machine: MachineSpec, host_sdk_prefix: Optional[Path], call_selected_meson: Callable, default_library: DefaultLibrary, - outdir: Path) -> tuple[MachineConfig, MachineConfig]: + outdir: Path, + options: dict = {}) -> tuple[MachineConfig, MachineConfig]: is_cross_build = host_machine != build_machine if is_cross_build: @@ -86,7 +87,8 @@ def generate_machine_configs(build_machine: MachineSpec, build_sdk_prefix, call_selected_meson, default_library, - outdir) + outdir, + options) if is_cross_build: host_config = generate_machine_config(host_machine, @@ -97,7 +99,8 @@ def generate_machine_configs(build_machine: MachineSpec, host_sdk_prefix, call_selected_meson, default_library, - outdir) + outdir, + options) else: host_config = build_config @@ -112,7 +115,8 @@ def generate_machine_config(machine: MachineSpec, sdk_prefix: Optional[Path], call_selected_meson: Callable, default_library: DefaultLibrary, - outdir: Path) -> MachineConfig: + outdir: Path, + options: dict = {}) -> MachineConfig: config = ConfigParser(dict_type=OrderedDict) config["constants"] = OrderedDict() config["binaries"] = OrderedDict() @@ -152,7 +156,8 @@ def generate_machine_config(machine: MachineSpec, config, outpath, outenv, - outdir) + outdir, + options) if machine.toolchain_is_msvc: builtin_options["b_vscrt"] = str_to_meson(machine.config) diff --git a/env_android.py b/env_android.py index a1233ba..4cac922 100644 --- a/env_android.py +++ b/env_android.py @@ -17,7 +17,8 @@ def init_machine_config(machine: MachineSpec, config: ConfigParser, outpath: list[str], outenv: dict[str, str], - outdir: Path): + outdir: Path, + options: dict = {}): ndk_found = False try: ndk_root = Path(environ["ANDROID_NDK_ROOT"]) @@ -64,9 +65,10 @@ def init_machine_config(machine: MachineSpec, ] c_like_flags = [ "-DANDROID", - "-ffunction-sections", - "-fdata-sections", ] + if "EMBED_BITCODE" not in options: + c_like_flags.append("-ffunction-sections") + c_like_flags.append("-fdata-sections") cxx_like_flags = [] cxx_link_flags = [ "-static-libstdc++", diff --git a/env_apple.py b/env_apple.py index 6a34e5d..75588a1 100644 --- a/env_apple.py +++ b/env_apple.py @@ -18,7 +18,8 @@ def init_machine_config(machine: MachineSpec, config: ConfigParser, outpath: list[str], outenv: dict[str, str], - outdir: Path): + outdir: Path, + options: dict = {}): xcenv = {**environ} if machine.arch == "arm64eoabi": try: diff --git a/env_generic.py b/env_generic.py index 3ca63c0..abb51a3 100644 --- a/env_generic.py +++ b/env_generic.py @@ -21,7 +21,8 @@ def init_machine_config(machine: MachineSpec, config: ConfigParser, outpath: list[str], outenv: dict[str, str], - outdir: Path): + outdir: Path, + options: dict = {}): allow_undefined_symbols = machine.os == "freebsd" options = config["built-in options"] diff --git a/meson_configure.py b/meson_configure.py index cf90ade..7fd9fc6 100644 --- a/meson_configure.py +++ b/meson_configure.py @@ -199,6 +199,10 @@ def configure(sourcedir: Path, except deps.BundleNotFoundError as e: raise_sdk_not_found(e, "host", host_machine) + options = {} + if '-Dbitcode=true' in extra_meson_options: + options["EMBED_BITCODE"] = True + build_config, host_config = \ env.generate_machine_configs(build_machine, host_machine, @@ -208,7 +212,8 @@ def configure(sourcedir: Path, host_sdk_prefix, call_selected_meson, default_library, - builddir) + builddir, + options) meson_options += [f"--native-file={build_config.machine_file}"] if host_config is not build_config: diff --git a/mkdevkit.py b/mkdevkit.py index 91a2295..7c7f798 100755 --- a/mkdevkit.py +++ b/mkdevkit.py @@ -45,6 +45,12 @@ def main(): dest="flavor", const="_thin", default="") + parser.add_argument("-p", "--prefixsyms", + help="redefine the produced symbols with the frida_ prefix", + action="store_const", + dest="prefix_syms", + const="prefix_syms", + default=False) parser.add_argument("--cc", help="C compiler to use", type=lambda v: parse_array_option_value(v, ool_optvals)) @@ -61,6 +67,7 @@ def main(): machine = options.machine outdir = options.outdir.resolve() flavor = options.flavor + prefix_syms = options.prefix_syms cc = options.cc if cc is not None: @@ -82,7 +89,7 @@ def main(): assert meson_config is not None try: - app = devkit.CompilerApplication(kit, machine, meson_config, outdir) + app = devkit.CompilerApplication(kit, machine, meson_config, outdir, prefix_syms) app.run() except subprocess.CalledProcessError as e: print(e, file=sys.stderr)