Skip to content

Commit

Permalink
meson: Post-process Android binaries using termux-elf-cleaner
Browse files Browse the repository at this point in the history
Our legacy build system used to do this in a driver wrapper script.
  • Loading branch information
oleavr committed Apr 21, 2024
1 parent 03b5a8d commit 5a82d77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,13 @@ if host_os_family == 'linux' and cc.has_function('openpty', prefix: '#include <p
endif

if host_os == 'android'
termux_elf_cleaner = find_program('termux-elf-cleaner', native: true)
libselinux_dep = dependency('libselinux', version: '>=3.0')
libsepol_dep = dependency('libsepol', version: '>=3.0')
backend_deps_private += [libselinux_dep, libsepol_dep]
backend_reqs_private += ['libselinux', 'libsepol']
else
termux_elf_cleaner = []
endif

tls_provider_dep = dependency('gioopenssl', required: get_option('connectivity'))
Expand Down Expand Up @@ -598,10 +601,12 @@ post_process = [
python,
files('tools' / 'post-process.py'),
host_os,
host_abi,
'>>>', strip, '<<<',
get_option('strip').to_string(),
'>>>', install_name_tool, '<<<',
'>>>', codesign, '<<<',
'>>>', termux_elf_cleaner, '<<<',
'@OUTPUT@',
'@INPUT0@',
]
Expand Down
7 changes: 7 additions & 0 deletions subprojects/termux-elf-cleaner.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[wrap-git]
url = https://github.com/frida/termux-elf-cleaner.git
revision = 8e572cb066907cfc8ac1f73d511683844de906ee
depth = 1

[provide]
program_names = termux-elf-cleaner
7 changes: 7 additions & 0 deletions tools/post-process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
def main(argv):
args = argv[1:]
host_os = args.pop(0)
host_abi = args.pop(0)
strip_command = pop_cmd_array_arg(args)
strip_enabled = args.pop(0) == "true"
install_name_tool = pop_cmd_array_arg(args)
codesign = pop_cmd_array_arg(args)
termux_elf_cleaner = pop_cmd_array_arg(args)
output_path = Path(args.pop(0))
input_path = Path(args.pop(0))
kind = args.pop(0)
Expand Down Expand Up @@ -61,6 +63,11 @@ def main(argv):
if input_entitlements_path is not None and host_os in {"ios", "tvos"}:
codesign_args += ["--entitlements", input_entitlements_path]
subprocess.run(codesign + codesign_args + [intermediate_path], **run_kwargs)

if host_os == "android":
api_level = 19 if host_abi in {"x86", "arm"} else 21
subprocess.run(termux_elf_cleaner + ["--api-level", str(api_level), "--quiet", intermediate_path],
**run_kwargs)
except subprocess.CalledProcessError as e:
print(e, file=sys.stderr)
print("Output:\n\t| " + "\n\t| ".join(e.output.strip().split("\n")), file=sys.stderr)
Expand Down

0 comments on commit 5a82d77

Please sign in to comment.