fix(native): select one slice when universal Mach-O slices share a CPU type (#2040)
* fix(native): select one slice when universal Mach-O slices share a CPU type On macOS 27 most system binaries are universal files whose slices share CPU_TYPE_ARM64: arm64e + arm64e.x1 (Calculator, TextEdit), x86_64 + arm64e + arm64e.x1 (/bin/ls), or arm64 + arm64e.x1 (ShortcutDroplet). Target admission names slices by CPU family, so these targets have availableArchitectures ["arm64"] while the file holds two arm64 slices. inspect_macho read that family count as a slice count and ran otool, nm, dyld_info, dwarfdump and vtool without -arch. ShortcutDroplet failed with "Malformed otool load-command output" (40 load commands against ncmds 20). Calculator reported both slices' imports (4138 instead of 2069), nm's "(for architecture ...)" header lines as exports, and no selected slice. selectArchitecture now also filters when lipo lists more than one slice. Its preference is unchanged: the family name, then arm64e, then the first arm64e.<variant>. inspect_native_dispatch_metadata matched FAT slices by CPU type only and refused /bin/ls and TextEdit as "Ambiguous FAT architecture slice". selectMachoSlice now ranks slices of the requested CPU type by base subtype in the same order: arm64 (0, then 1) or x86_64 (3), then arm64e (2), then other variants such as arm64e.x1 in FAT table order. It reports ambiguity only when the top-ranked slices share a subtype. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(native): share Mach-O slice preference across inspections * chore: preserve upstream process capture test during merge --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
morluto
parent
b69d20a300
commit
96fc84f1fb
@@ -1,7 +1,10 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { inspectMachoSchema } from "../../../../src/domain/native/nativeInspection.js";
|
||||
import { err } from "../../../../src/domain/result.js";
|
||||
import { NativeCommandFailure } from "../../../../src/native/CommandRunner.js";
|
||||
import {
|
||||
NativeCommandFailure,
|
||||
type NativeCommandRunner,
|
||||
} from "../../../../src/native/CommandRunner.js";
|
||||
import { NativeMacOSProvider } from "../../../../src/native/NativeMacOSProvider.js";
|
||||
import {
|
||||
NativeFixtureRunner,
|
||||
@@ -9,6 +12,35 @@ import {
|
||||
nativeMachoTarget,
|
||||
} from "../../../fixtures/nativeCommands.js";
|
||||
|
||||
/** Replay fixtures, failing any slice command that does not name the expected slice. */
|
||||
const sliceSelectingRunner = (
|
||||
fixtures: NativeFixtureRunner,
|
||||
selected: string,
|
||||
dyldArchitecture: string,
|
||||
calls: {
|
||||
readonly tool: string;
|
||||
readonly arguments_: readonly string[];
|
||||
}[] = [],
|
||||
): NativeCommandRunner => ({
|
||||
run(tool, arguments_) {
|
||||
calls.push({ tool, arguments_ });
|
||||
const expected = tool === "dyld_info" ? dyldArchitecture : selected;
|
||||
if (
|
||||
!["file", "lipo"].includes(tool) &&
|
||||
!arguments_.some(
|
||||
(argument, index) =>
|
||||
argument === expected ||
|
||||
argument === `--arch=${expected}` ||
|
||||
(argument === "-arch" && arguments_[index + 1] === expected),
|
||||
)
|
||||
)
|
||||
return Promise.resolve(
|
||||
err(new NativeCommandFailure(tool, "nonzero-exit", 1)),
|
||||
);
|
||||
return fixtures.run(tool, arguments_);
|
||||
},
|
||||
});
|
||||
|
||||
it("does not attribute the first universal slice's UUID and segments to the selected target", async () => {
|
||||
const singleSlice = await nativeFixture("otool-load.txt");
|
||||
const selected = new NativeFixtureRunner();
|
||||
@@ -77,25 +109,7 @@ it.each([
|
||||
});
|
||||
const client = new NativeMacOSProvider(
|
||||
{},
|
||||
{
|
||||
run(tool, arguments_) {
|
||||
calls.push({ tool, arguments_ });
|
||||
const expected = tool === "dyld_info" ? dyldArchitecture : selected;
|
||||
if (
|
||||
!["file", "lipo"].includes(tool) &&
|
||||
!arguments_.some(
|
||||
(argument, index) =>
|
||||
argument === expected ||
|
||||
argument === `--arch=${expected}` ||
|
||||
(argument === "-arch" && arguments_[index + 1] === expected),
|
||||
)
|
||||
)
|
||||
return Promise.resolve(
|
||||
err(new NativeCommandFailure(tool, "nonzero-exit", 1)),
|
||||
);
|
||||
return fixtures.run(tool, arguments_);
|
||||
},
|
||||
},
|
||||
sliceSelectingRunner(fixtures, selected, dyldArchitecture, calls),
|
||||
"darwin",
|
||||
).createClient(nativeMachoTarget("/owned/universal"));
|
||||
|
||||
@@ -116,6 +130,36 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ capture: "calculator.txt", selected: "arm64e" },
|
||||
{ capture: "shortcut-droplet.txt", selected: "arm64" },
|
||||
])(
|
||||
"selects one slice when every universal slice has the target's CPU type ($capture)",
|
||||
async ({ capture, selected }) => {
|
||||
const base = nativeMachoTarget("/owned/universal");
|
||||
if (base.kind !== "executable")
|
||||
throw new Error("Expected executable fixture");
|
||||
// Admission names arm64, arm64e and arm64e.x1 slices by one CPU family.
|
||||
const target = { ...base, availableArchitectures: ["arm64"] as const };
|
||||
const fixtures = new NativeFixtureRunner({
|
||||
lipo: await nativeFixture(`lipo-same-cpu/${capture}`),
|
||||
});
|
||||
const result = await new NativeMacOSProvider(
|
||||
{},
|
||||
sliceSelectingRunner(fixtures, selected, selected),
|
||||
"darwin",
|
||||
)
|
||||
.createClient(target)
|
||||
.execute("inspect_macho", {});
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.result).toMatchObject({
|
||||
selected_architecture: { name: selected, container_file_offset: 16384 },
|
||||
architectures: { total: 2 },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("projects universal segment evidence into the selected slice's container offsets", async () => {
|
||||
const client = new NativeMacOSProvider(
|
||||
{},
|
||||
|
||||
Reference in New Issue
Block a user