diff --git a/tools/android_asm_convert.py b/tools/android_asm_convert.py index 9d87bf62..8436ad39 100644 --- a/tools/android_asm_convert.py +++ b/tools/android_asm_convert.py @@ -217,6 +217,12 @@ class Converter: if op == ".align": self.emit(f"\t.p2align {args}") return + if op in (".ascii", ".asciz", ".string"): + # string data, kept as it is: no symbol names in it (renamed, a + # "_" at the start of a word was dropped: a string with \" in it + # went wrong, Opus's tables among them) + self.emit(f"\t{op} {args}") + return if op.startswith("."): self.emit(f"\t{op} {self.operands(args)}" if args else f"\t{op}") return diff --git a/tools/test_android_asm_convert.py b/tools/test_android_asm_convert.py new file mode 100644 index 00000000..8c6e21a1 --- /dev/null +++ b/tools/test_android_asm_convert.py @@ -0,0 +1,32 @@ +"""Tests of tools/android_asm_convert.py, the Mach-O to ELF assembly +conversion of the Android build's guest code.""" +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +from android_asm_convert import Converter # noqa: E402 + + +def convert(*lines): + return Converter(list(lines)).run().split("\n") + + +def test_symbols_lose_their_underscore(): + out = convert("_main:", "\tbl\t_foo", "\t.long\t_bar") + assert out[:3] == ["main:", "\tbl foo", "\t.long bar"] + + +def test_strings_are_kept(): + # (a string starting with "_", or one with \" in it, lost a "_": Opus's + # pulse cache was one byte short, and its encoder crashed) + out = convert( + '\t.asciz\t"_lan_"', + '\t.ascii\t"\\"$&\'\\0063_\\206"', + '\t.string\t"l_.str _foo"', + ) + assert out[:3] == [ + '\t.asciz "_lan_"', + '\t.ascii "\\"$&\'\\0063_\\206"', + '\t.string "l_.str _foo"', + ]