Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update releng to allow optional bitcode/prefixing of symbols #4

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions devkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = []

Expand Down Expand Up @@ -532,4 +538,4 @@ def tweak_flags(cflags, ldflags):


def deduplicate(items):
return list(OrderedDict.fromkeys(items))
return list(OrderedDict.fromkeys(items))
15 changes: 10 additions & 5 deletions env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions env_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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++",
Expand Down
3 changes: 2 additions & 1 deletion env_apple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion env_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 6 additions & 1 deletion meson_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion mkdevkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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:
Expand All @@ -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)
Expand Down