mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
fix(il2cpp): link arm64 builds whose registrations were inlined (#6989)
* fix(il2cpp): accept arm64 module arrays loaded through adrp/add pairs A Unity 2022.3 macOS Master (LTO) arm64 build keeps no static CodeRegistration, so the module-array fallback that only decoded x86-64 RIP-relative references reported code-registration-not-found. The registration owner now also decodes aligned adrp + add pairs in executable ranges and keeps the same exact-module-set and single-reference rules. A minimal Mach-O fixture failed on the previous reader (47 passed / 1 failed) and passes here with four fail-closed variants (48/48 binary tests). * fix(il2cpp): name the matched instruction form in inferred module-array limits The inferred-array limitation always described RIP-relative LEA/MOV, which is wrong for arm64 results. The provider now names the adrp/add pair on arm64, and the tool contract and docs cover both forms and state that a located array alone does not finish linking a Master build. The new arm64 provider case failed before the wording change (1 passed / 1 failed) and both cases pass now. * fix(il2cpp): accept type tables loaded without a static MetadataRegistration A Unity 2022.3.62f3 macOS Master build inlines MetadataRegistration as well as CodeRegistration, so linking stopped at metadata-registration-not-found after the module array was found. Registration now infers the only field linking reads, the Il2CppType table, from the one run of type-shaped pointers that covers every referenced type index and whose start is loaded by the existing RIP-relative or adrp/add forms; types_field is null and the Evidence is inferred. The new arm64 and x86-64 fixtures failed on the previous reader (52 passed / 2 failed). Four run-selection variants (interior reference, run extended before the loaded address, two loaded runs, run shorter than the referenced indices) keep metadata-registration-not-found; instruction decoding and record-shape checks are not covered by these fixtures. * test(il2cpp): pin adrp page deltas, register pairing and type-record shape Every adrp fixture targeted its own 4 KiB page, so dropping the page delta or its sign extension, the add register check, the type-kind bound or the type-definition bound left all binary tests passing. Fixtures now reach a later and an earlier page, pair an add with a different destination or source register, break the type run with an out-of-range kind or type-definition index, and bound type-table candidates when the metadata references few type indices. Each of those five source mutations now fails 1 to 3 of 85 binary and provider tests. * refactor(il2cpp): share Il2CppType kind decoding and document type-table bounds The type-table fallback decoded the Il2CppType kind and class/value-type kinds separately from the type namer; both now use the Types owner. Zero and unaligned words are rejected before mapping lookup (Master sample metadata-registration search 92 to 68 ms). Docs and the limitation state that types_count is an upper bound, that a run spanning mappings or a small referenced type range can fail, and credit Cpp2IL StrippedCodeRegSupport and the data-side MetadataRegistration searches of Il2CppDumper and Cpp2IL. Master sample output is unchanged (11,031 code addresses, 37,025 type rows). * fix(il2cpp): refuse generic instances when the type table was inferred An inferred type table has no static MetadataRegistration, so the genericMethodTable it would anchor cannot be located. Report generic-methods-unsupported instead of reading from a null field. * fix(il2cpp): fail closed when an inferred type table is not unique Adversarial review found that the type-table fallback could pick another type-shaped pointer table when the real one was unloaded or excluded, could replace a static MetadataRegistration whose counts matched, and accepted a run cut short by a mapping end. Require exactly one long-enough run in the image, ending inside its mapping and loaded by code; skip the fallback when a record's two counts matched; accept only assigned Il2CppTypeEnum kinds; and look records up through the indexed file mapping so many mappings cannot multiply the scan. Docs and limitations now describe the run length as at least every referenced type index rather than an upper bound. * fix(il2cpp): keep the type-table fallback cheap and its refusals exact Review follow-ups: check that an address can lie in a mapping before the throwing indexed lookup, so words pointing into gaps or zero-fill no longer build an exception each (64 MiB: 74 s to under 2 s); treat a run starting at its mapping start like one reaching its end; stop at the second long-enough run instead of a 64-candidate capacity error; ignore ADRP/ADD pairs on register 31; and say whether a counted MetadataRegistration was unusable or no code-loaded run was found. Docs no longer generalize from one build or state tool history they do not source. * fix(il2cpp): judge type-table slots by their loaded value The run scan read stored words, so a dyld-bound slot's placeholder could decide whether a run qualified. Confirm each slot through readSlot and give a run bounded by a bound or unresolved slot an unknown extent, so the placeholder no longer changes the choice. * docs(il2cpp): keep the failure-reason table layout Shorten the two changed meanings so the table keeps its column widths and the diff shows only those rows. * docs(il2cpp): keep the reason table at its formatted width * fix(il2cpp): read type-table record fields through the loader too The previous change confirmed table slots through readSlot but still read each record's kind and definition index from stored bytes. Read them with readUInt32 and readSlot, and treat a record field the loader binds or leaves unresolved like an unresolved slot: the run it bounds has an unknown extent. * perf(il2cpp): share image mappings across loader-aware reads --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { linkIl2cppBinary } from "../../../src/il2cpp/Il2cppBinaryFile.js";
|
||||
import {
|
||||
isMapped,
|
||||
openImageSteps,
|
||||
readPointer,
|
||||
readSlot,
|
||||
readUInt32,
|
||||
} from "../../../src/il2cpp/Il2cppBinaryImage.js";
|
||||
import { readIl2cppMetadataForLinking } from "../../../src/il2cpp/Il2cppMetadataFile.js";
|
||||
import {
|
||||
createElfFixture,
|
||||
createIl2cppBinaryFixture,
|
||||
createIl2cppTypeScanFixture,
|
||||
FIXTURE_BINARY_BASE,
|
||||
} from "../../fixtures/il2cpp/binary.js";
|
||||
import { createLinkedIl2cppMetadataFixture } from "../../fixtures/il2cpp/metadata.js";
|
||||
@@ -61,6 +63,42 @@ const withLoadRanges = (
|
||||
return result;
|
||||
};
|
||||
|
||||
it("reuses admitted mappings for repeated file-backed loader reads", () => {
|
||||
const original = createIl2cppBinaryFixture();
|
||||
const image = open(createElfFixture(original, { zeroFilledTable: true }));
|
||||
const mappings = vi.spyOn(image.container.mappings, Symbol.iterator);
|
||||
const zeroFills = vi.spyOn(image.container.zero_fills, "some");
|
||||
try {
|
||||
for (let index = 0; index < 32; index++) {
|
||||
expect(readSlot(image, FIXTURE_BINARY_BASE + 0x900n)).toBe(
|
||||
original.readBigUInt64LE(0x900),
|
||||
);
|
||||
expect(readUInt32(image, FIXTURE_BINARY_BASE + 0x988n)).toBe(
|
||||
original.readUInt32LE(0x988),
|
||||
);
|
||||
expect(isMapped(image, FIXTURE_BINARY_BASE + 0x980n, 12)).toBe(true);
|
||||
}
|
||||
expect(mappings).not.toHaveBeenCalled();
|
||||
expect(zeroFills).not.toHaveBeenCalled();
|
||||
} finally {
|
||||
mappings.mockRestore();
|
||||
zeroFills.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("links one code-loaded type table among short runs across many mappings", () => {
|
||||
const bytes = createIl2cppTypeScanFixture(64, 128);
|
||||
const snapshot = Buffer.from(bytes);
|
||||
const result = linkIl2cppBinary(bytes, metadata, {
|
||||
...facts,
|
||||
returnTypes: Int32Array.from(facts.returnTypes, () => 3),
|
||||
});
|
||||
expect(result.types_field).toBeNull();
|
||||
expect(result.types_count).toBe(4);
|
||||
expect(result.return_types.every((row) => row.name === "int")).toBe(true);
|
||||
expect(bytes).toEqual(snapshot);
|
||||
});
|
||||
|
||||
it.each([183, 62])(
|
||||
"links agreeing split ELF RELA spans without changing input bytes (machine %s)",
|
||||
(machine) => {
|
||||
|
||||
Reference in New Issue
Block a user