fix(macho)!: select arm64e.x1 slices of universal Mach-O files by exact subtype (#14881)

* fix(macho): select arm64e.x1 slices of universal Mach-O files by exact subtype

macOS 27 system binaries such as /bin/ls and /usr/bin/codesign hold
x86_64, arm64e and arm64e.x1 slices. The caller's architecture selector
counted arm64e.x1 as arm64e and had no value of its own for it, so
inspect_native_initializers, inspect_go_binary, inspect_rust_binary and
inspect_dwarf_units refused arm64e as matching several slices and
rejected arm64e.x1 as an argument. Neither arm64e slice could be read.

Name each arm64e subtype exactly, as lipo -thin and otool -arch do:
arm64e reads only the arm64e slice and the new arm64e.x1 value only the
arm64e.x1 slice. arm64 keeps reading its family's only slice. A refusal
and the unread-slice limitation now offer arm64e.x1 where it selects one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(macho): record the advertised schemas that accept arm64e.x1

The architecture enum of inspect_native_initializers, inspect_go_binary,
inspect_rust_binary and inspect_dwarf_units gained arm64e.x1, which
changes their advertised input schemas. Commit the regenerated summaries
so verify-advertised-schemas matches the catalog.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(macho): check the selected DWARF slice subtype and document arm64e.x1

inspect_dwarf_units accepted a report whose CPU family matched the
request, so an arm64e or arm64e.x1 request answered by the other arm64e
slice still produced Evidence. Validate the report's selected_slice with
machoSelectionAnswersArchitecture, as the initializer, Go and Rust
readers do.

The tool's architecture field, its CLI option and dwarf-units.md still
described a CPU family and listed only x86, x86_64, arm and arm64. Name
arm64e and arm64e.x1 and their exact-subtype rule there as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lewis Wang
2026-11-27 23:56:06 +08:00
committed by GitHub
parent 2874a6e21f
commit 92b082bcaf
21 changed files with 229 additions and 117 deletions
+8 -3
View File
@@ -19,9 +19,14 @@ requires an absolute filesystem path:
}
```
A universal Mach-O needs `architecture` (`x86`, `x86_64`, `arm`, or `arm64`).
The same value is rejected for every other image. A `.dSYM` bundle is not
opened. Pass the DWARF file inside the bundle.
A universal Mach-O needs `architecture` (`x86`, `x86_64`, `arm`, `arm64`,
`arm64e`, or `arm64e.x1`). A CPU family with one slice is selected by its family
name; `arm64e` and `arm64e.x1` each read only a slice of that subtype, as
`lipo -thin` does. When several slices share the family, `arm64` reads the
`arm64` (or `arm64v8`) slice and `x86_64` the canonical `x86_64` slice, and a
value that matches no slice or several is refused. The same value is rejected
for every other image. A `.dSYM` bundle is not opened. Pass the DWARF file
inside the bundle.
## Observations
+10 -10
View File
@@ -169,8 +169,8 @@ read within individual segments or sections. The historical two-word string
descriptor follows the
[Go 1.17.13 reader](https://github.com/golang/go/blob/go1.17.13/src/cmd/go/internal/version/version.go#L212).
A universal (FAT) Mach-O needs `architecture` (`x86`, `x86_64`, `arm`, `arm64`
or `arm64e`; CLI `--architecture`). REA reads its own FAT table, without `lipo`,
A universal (FAT) Mach-O needs `architecture` (`x86`, `x86_64`, `arm`, `arm64`,
`arm64e` or `arm64e.x1`; CLI `--architecture`). REA reads its own FAT table, without `lipo`,
rejects a table whose slices overlap, and validates the selected slice's range,
alignment and Mach-O header CPU against the table. The result keeps the
universal file as `artifact` (its SHA-256 and size), adds `selected_slice` with
@@ -179,14 +179,14 @@ reports every source range as a file offset inside that slice. Without
`architecture`, or when the file has no slice of that CPU family, the request
fails on `architecture` and lists the slices present. A CPU family with one
slice is selected by its family name, so `arm64` also reads a lone `arm64e`
slice; `arm64e` reads only an `arm64e` slice. When several slices share the
family, the value must name the slice's subtype, as `lipo -thin` does: `arm64`
reads the `arm64` (or `arm64v8`) slice, `arm64e` the `arm64e` (or `arm64e.x1`)
slice, and `x86_64` the canonical `x86_64` slice. Capability bits are ignored
when subtypes are compared. REA does not choose a slice by preference. When no
slice or several slices carry the named subtype, the request fails on
`architecture` and names any other value that selects exactly one verified
slice; `arm64e` beside `arm64e.x1`, for example, is refused. Other subtypes,
slice; `arm64e` and `arm64e.x1` each read only a slice of that subtype, as
`lipo -thin` does. When several slices share the family, the value must name
the slice's subtype: `arm64` reads the `arm64` (or `arm64v8`) slice,
`arm64e` the `arm64e` slice, `arm64e.x1` the `arm64e.x1` slice, and `x86_64`
the canonical `x86_64` slice. Capability bits are ignored when subtypes are
compared. REA does not choose a slice by preference. When no slice or several
slices carry the named subtype, the request fails on `architecture` and names
any other value that selects exactly one verified slice. Other subtypes,
such as `x86_64h` and the `x86` (i386) and 32-bit `arm` subtypes, have no value
of their own; they are read only as the only slice of their family.
`limitations` lists the same-family slices that were not read and the value, if
+11 -10
View File
@@ -20,16 +20,17 @@ requires an absolute filesystem path:
}
```
A universal Mach-O requires `architecture` (`x86`, `x86_64`, `arm`, `arm64` or
`arm64e`) to select one slice. A CPU family with one slice is selected by its
family name; `arm64e` reads only an `arm64e` slice. When several slices share
the family, such as the `arm64` and `arm64e` slices of stock macOS tools, the
value must name the slice's subtype, as `lipo -thin` does: `arm64` reads the
`arm64` (or `arm64v8`) slice, `arm64e` the `arm64e` (or `arm64e.x1`) slice, and
`x86_64` the canonical `x86_64` slice. REA does not choose a slice by
preference. When no slice or several slices carry the named subtype (capability
bits are ignored when comparing), the request fails on `architecture`; `arm64e`
beside `arm64e.x1`, for example, is refused. `slice` reports the selected
A universal Mach-O requires `architecture` (`x86`, `x86_64`, `arm`, `arm64`,
`arm64e` or `arm64e.x1`) to select one slice. A CPU family with one slice is
selected by its family name; `arm64e` and `arm64e.x1` each read only a slice of
that subtype, as `lipo -thin` does. When several slices share the family, such
as the `arm64` and `arm64e` slices of stock macOS tools or the `arm64e` and
`arm64e.x1` slices of `/bin/ls` on macOS 27, the value must name the slice's
subtype: `arm64` reads the `arm64` (or `arm64v8`) slice, `arm64e` the `arm64e`
slice, `arm64e.x1` the `arm64e.x1` slice, and `x86_64` the canonical `x86_64`
slice. REA does not choose a slice by preference. When no slice or several
slices carry the named subtype (capability bits are ignored when comparing), the
request fails on `architecture`. `slice` reports the selected
subtype, and `limitations` lists the same-family slices that were not read and
the value, if any, that selects each. A slice whose Mach-O header does not match
its FAT declaration, such as a different CPU subtype, is listed as unverified,
+10 -10
View File
@@ -198,8 +198,8 @@ packages or the compiler.
ELF, PE, thin Mach-O, one selected slice of a universal Mach-O, and
WebAssembly core modules are the supported containers.
A universal (FAT) Mach-O needs `architecture` (`x86`, `x86_64`, `arm`, `arm64`
or `arm64e`; CLI `--architecture`). REA reads its own FAT table, without `lipo`,
A universal (FAT) Mach-O needs `architecture` (`x86`, `x86_64`, `arm`, `arm64`,
`arm64e` or `arm64e.x1`; CLI `--architecture`). REA reads its own FAT table, without `lipo`,
rejects a table whose slices overlap, and validates the selected slice's range,
alignment and Mach-O header CPU against the table. The result keeps the
universal file as `artifact` (its SHA-256 and size), adds `selected_slice` with
@@ -208,14 +208,14 @@ reports the section and rustc-path offsets as a file offset inside that slice.
Without `architecture`, or when the file has no slice of that CPU family, the
request fails on `architecture` and lists the slices present. A CPU family with
one slice is selected by its family name, so `arm64` also reads a lone `arm64e`
slice; `arm64e` reads only an `arm64e` slice. When several slices share the
family, the value must name the slice's subtype, as `lipo -thin` does: `arm64`
reads the `arm64` (or `arm64v8`) slice, `arm64e` the `arm64e` (or `arm64e.x1`)
slice, and `x86_64` the canonical `x86_64` slice. Capability bits are ignored
when subtypes are compared. REA does not choose a slice by preference. When no
slice or several slices carry the named subtype, the request fails on
`architecture` and names any other value that selects exactly one verified
slice; `arm64e` beside `arm64e.x1`, for example, is refused. Other subtypes,
slice; `arm64e` and `arm64e.x1` each read only a slice of that subtype, as
`lipo -thin` does. When several slices share the family, the value must name
the slice's subtype: `arm64` reads the `arm64` (or `arm64v8`) slice,
`arm64e` the `arm64e` slice, `arm64e.x1` the `arm64e.x1` slice, and `x86_64`
the canonical `x86_64` slice. Capability bits are ignored when subtypes are
compared. REA does not choose a slice by preference. When no slice or several
slices carry the named subtype, the request fails on `architecture` and names
any other value that selects exactly one verified slice. Other subtypes,
such as `x86_64h` and the `x86` (i386) and 32-bit `arm` subtypes, have no value
of their own; they are read only as the only slice of their family.
`limitations` lists the same-family slices that were not read and the value, if
@@ -1,6 +1,6 @@
{
"schemas": {
"input compact": "af9c8704831d9edc",
"input compact": "05f8e7b2a79590b2",
"output compact": "fc6c5d5a78a47254"
},
"patterns": {
@@ -1,6 +1,6 @@
{
"schemas": {
"input compact": "76e008d5c9b4d474",
"input compact": "4da052ea4100ae2a",
"output compact": "fc6c5d5a78a47254"
},
"patterns": {
@@ -1,6 +1,6 @@
{
"schemas": {
"input compact": "05b6c37dc36da5cd",
"input compact": "116394f67f74e433",
"output compact": "fc6c5d5a78a47254"
},
"patterns": {
@@ -1,6 +1,6 @@
{
"schemas": {
"input compact": "54626e583b89f833",
"input compact": "454f43f2d5b6b374",
"output compact": "fc6c5d5a78a47254"
},
"patterns": {
@@ -133,29 +133,43 @@ it("retains caller-selected parameters if cancellation arrives as the provider c
expect(evidenceIds[0]).not.toBe(evidenceIds[1]);
});
it("accepts an arm64e request answered by its arm64-family slice", async () => {
const result = await new DwarfUnitsService({
identity,
inspect: () =>
Promise.resolve(
ok({
...report,
format: "macho",
architecture: "arm64",
selected_slice: {
kind: "macho-selected-image-v1",
container: "fat",
offset: 4096,
byte_length: 128,
cpu_type: 0x0100000c,
cpu_subtype: 2,
container_table_sha256: "b".repeat(64),
},
}),
),
}).inspect({ path: report.artifact.path, architecture: "arm64e" });
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({
normalized_result: { architecture: "arm64" },
});
});
it.each([
{ architecture: "arm64e", subtype: "0x80000002", accepted: true },
{ architecture: "arm64e", subtype: "0x8000000c", accepted: false },
{ architecture: "arm64e", subtype: "0x0", accepted: false },
{ architecture: "arm64e.x1", subtype: "0x8000000c", accepted: true },
{ architecture: "arm64e.x1", subtype: "0x80000002", accepted: false },
] as const)(
"accepts $architecture for a report of subtype $subtype: $accepted",
async ({ architecture, subtype, accepted }) => {
const result = await new DwarfUnitsService({
identity,
inspect: () =>
Promise.resolve(
ok({
...report,
format: "macho",
architecture: "arm64",
selected_slice: {
kind: "macho-selected-image-v1",
container: "fat",
offset: 4096,
byte_length: 128,
cpu_type: 0x0100000c,
cpu_subtype: Number(subtype),
container_table_sha256: "b".repeat(64),
},
}),
),
}).inspect({ path: report.artifact.path, architecture });
if (accepted) {
if (!result.ok) throw result.error;
expect(result.value).toMatchObject({
normalized_result: { architecture: "arm64" },
});
} else {
expect(result.ok).toBe(false);
if (!result.ok) expect(result.error).toBeInstanceOf(AnalysisOutputError);
}
},
);
@@ -1,8 +1,11 @@
import { machoSliceFamily } from "../../domain/apple/machoTargetSelection.js";
import {
machoSelectionAnswersArchitecture,
machoSliceFamily,
metadataReportSubjectFormat,
} from "../../domain/apple/machoTargetSelection.js";
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
import type { DwarfUnitsPort } from "../../ports/binaryDiagnostics/DwarfUnitsPort.js";
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
import { metadataReportSubjectFormat } from "../../domain/apple/machoTargetSelection.js";
import { binaryMetadataArchitecture } from "../../domain/binaryMetadataArchitecture.js";
import { createEvidence, type Evidence } from "../../domain/evidence.js";
import {
@@ -104,9 +107,9 @@ const validReport = (
if (report.page.offset !== input.offset || report.page.limit !== input.limit)
return false;
const requested = input.architecture;
const slice = report.selected_slice;
if ((requested === undefined) !== (slice === undefined)) return false;
// Reports name the CPU family; arm64e selects an arm64 slice.
if (!machoSelectionAnswersArchitecture(report.selected_slice, requested))
return false;
// Reports name the CPU family; arm64e and arm64e.x1 select arm64 slices.
return (
requested === undefined ||
report.architecture === machoSliceFamily(requested)
@@ -233,22 +233,29 @@ it("refuses a slice architecture label that disagrees with the selected image",
});
});
it("accepts an arm64e request only for a report of an arm64e slice", async () => {
it("accepts an arm64e or arm64e.x1 request only for a report of that subtype", async () => {
const selected = await selectedArm64Report();
const inspect = (cpuSubtype: number) =>
const inspect = (
cpuSubtype: number,
architecture: "arm64e" | "arm64e.x1" = "arm64e",
) =>
serviceFor({
...selected,
slice: { ...selected.slice, cpu_subtype: cpuSubtype },
}).inspect({ path: report.artifact.path, architecture: "arm64e" });
// arm64 (0x0) and arm64v8 (0x1) are not what arm64e names.
for (const cpuSubtype of [0, 1])
}).inspect({ path: report.artifact.path, architecture });
// arm64 (0x0), arm64v8 (0x1) and arm64e.x1 (0xc) are not what arm64e names.
for (const cpuSubtype of [0, 1, 0x8000000c])
expect(await inspect(cpuSubtype)).toMatchObject({
ok: false,
error: { _tag: "AnalysisOutputError" },
});
// arm64e with capability bits, and arm64e.x1.
for (const cpuSubtype of [0x80000002, 12])
expect((await inspect(cpuSubtype)).ok).toBe(true);
// arm64e with capability bits.
expect((await inspect(0x80000002)).ok).toBe(true);
expect((await inspect(0x8000000c, "arm64e.x1")).ok).toBe(true);
expect(await inspect(0x80000002, "arm64e.x1")).toMatchObject({
ok: false,
error: { _tag: "AnalysisOutputError" },
});
// A family name may read the family's only slice, such as /bin/ls's arm64e.
const lone = await serviceFor({
...selected,
@@ -89,7 +89,7 @@ const validReport = (
const slice = report.slice;
if (!machoSelectionAnswersArchitecture(slice, input.architecture))
return false;
// Slice and report labels name the CPU family; arm64e selects an arm64 slice.
// Slice and report labels name the CPU family; arm64e and arm64e.x1 select arm64 slices.
if (
slice !== null &&
input.architecture !== undefined &&
+2 -2
View File
@@ -61,7 +61,7 @@ export const registerBinaryDiagnosticsCommands = (
},
architecture: {
description:
"CPU family of the slice to read from a universal Mach-O; required for universal files",
"Slice to read from a universal Mach-O, by CPU family; arm64e and arm64e.x1 read only a slice of that subtype, as lipo -thin does; required for universal files",
},
},
},
@@ -113,7 +113,7 @@ export const registerBinaryDiagnosticsCommands = (
},
architecture: {
description:
"Slice to read from a universal Mach-O, by CPU family; when several slices share a family, arm64 (arm64 or arm64v8), arm64e (arm64e or arm64e.x1) or x86_64 names the subtype, and a value matching several slices is refused; required for universal files",
"Slice to read from a universal Mach-O, by CPU family; arm64e and arm64e.x1 read only a slice of that subtype, as lipo -thin does; when several slices share a family, arm64 (arm64 or arm64v8) or x86_64 names the subtype, and a value matching several slices is refused; required for universal files",
},
},
},
+1 -1
View File
@@ -26,7 +26,7 @@ export const registerGoCommands = (cli: CliInstance, logger: Logger): void => {
},
architecture: {
description:
"Slice to read from a universal Mach-O, by CPU family; when several slices share a family, arm64 (arm64 or arm64v8), arm64e (arm64e or arm64e.x1) or x86_64 names the subtype, and a value matching several slices is refused; required for universal files",
"Slice to read from a universal Mach-O, by CPU family; arm64e and arm64e.x1 read only a slice of that subtype, as lipo -thin does; when several slices share a family, arm64 (arm64 or arm64v8) or x86_64 names the subtype, and a value matching several slices is refused; required for universal files",
},
include_string_literals: {
description:
+1 -1
View File
@@ -37,7 +37,7 @@ export const registerRustCommands = (
producer_limits: { description: PRODUCER_LIMITS_HELP },
architecture: {
description:
"Slice to read from a universal Mach-O, by CPU family; when several slices share a family, arm64 (arm64 or arm64v8), arm64e (arm64e or arm64e.x1) or x86_64 names the subtype, and a value matching several slices is refused; required for universal files",
"Slice to read from a universal Mach-O, by CPU family; arm64e and arm64e.x1 read only a slice of that subtype, as lipo -thin does; when several slices share a family, arm64 (arm64 or arm64v8) or x86_64 names the subtype, and a value matching several slices is refused; required for universal files",
},
detail: {
description:
+7 -5
View File
@@ -12,6 +12,7 @@ import {
import {
MACHO_CPU_TYPES,
machoSliceFamily,
machoSliceNamesSubtypeOnly,
machoSliceSubtypeSelector,
type MachoSliceArchitecture,
type MachoTargetSelection,
@@ -66,6 +67,7 @@ export const SHARED_SLICE_SELECTION_INPUT: SliceSelectionInput = {
arm: "arm",
arm64: "arm64",
arm64e: "arm64e",
"arm64e.x1": "arm64e.x1",
},
};
@@ -147,15 +149,15 @@ interface FatSlice {
/** Whether a value names a subtype, not only a CPU family. */
const namesSubtype = (architecture: MachoSliceArchitecture): boolean =>
architecture === "arm64" ||
architecture === "arm64e" ||
architecture === "x86_64";
architecture === "x86_64" ||
machoSliceNamesSubtypeOnly(architecture);
/** The architecture values that address slices of this value's CPU family. */
const familyValues = (
architecture: MachoSliceArchitecture,
): readonly MachoSliceArchitecture[] =>
architecture === "arm64" || architecture === "arm64e"
? ["arm64", "arm64e"]
machoSliceFamily(architecture) === "arm64"
? ["arm64", "arm64e", "arm64e.x1"]
: [architecture];
/**
@@ -166,7 +168,7 @@ const addressedSlices = <Slice extends FatSlice>(
family: readonly Slice[],
architecture: MachoSliceArchitecture,
): readonly Slice[] =>
architecture !== "arm64e" && family.length === 1
!machoSliceNamesSubtypeOnly(architecture) && family.length === 1
? family
: family.filter(
(slice) =>
@@ -12,7 +12,10 @@ it.each([
["arm64 for arm64", [CPU_ARM64, 0], "arm64", true],
["a lone arm64e slice for arm64", [CPU_ARM64, 0x80000002], "arm64", true],
["arm64e for arm64e", [CPU_ARM64, 0x80000002], "arm64e", true],
["arm64e.x1 for arm64e", [CPU_ARM64, 12], "arm64e", true],
["arm64e.x1 for arm64e", [CPU_ARM64, 0x8000000c], "arm64e", false],
["arm64e.x1 for arm64e.x1", [CPU_ARM64, 0x8000000c], "arm64e.x1", true],
["arm64e for arm64e.x1", [CPU_ARM64, 0x80000002], "arm64e.x1", false],
["a lone arm64e.x1 slice for arm64", [CPU_ARM64, 12], "arm64", true],
["arm64 for arm64e", [CPU_ARM64, 0], "arm64e", false],
["arm64v8 for arm64e", [CPU_ARM64, 1], "arm64e", false],
["arm64 for x86_64", [CPU_ARM64, 0], "x86_64", false],
+32 -17
View File
@@ -3,7 +3,6 @@ import { z } from "zod";
import type { AnalysisProfileCommitment } from "../analysisProfile.js";
import type { BinaryArchitecture } from "../binaryTargetTypes.js";
import {
machoArchitectureFamily,
machoKnownArm64Subtype,
machoKnownX86_64Subtype,
} from "./machoCpuIdentity.js";
@@ -60,35 +59,50 @@ export const MACHO_CPU_TYPES = {
/** Caller-selected architecture of one universal Mach-O slice. */
export const machoSliceArchitectureSchema = z
.enum(["x86", "x86_64", "arm", "arm64", "arm64e"])
.enum(["x86", "x86_64", "arm", "arm64", "arm64e", "arm64e.x1"])
.describe(
"Architecture of the slice to read from a universal (FAT) Mach-O. Required for universal files and rejected for every other image. A CPU family with one slice is selected by its family name; arm64e reads only an arm64e slice. When several slices share a family, the value must name the slice's subtype, as lipo -thin does: arm64 reads the arm64 or arm64v8 slice, arm64e the arm64e or arm64e.x1 slice, and x86_64 the x86_64 slice but not x86_64h; capability bits are ignored. A value that matches no slice or several, such as arm64e beside arm64e.x1, is refused.",
) satisfies z.ZodType<keyof typeof MACHO_CPU_TYPES | "arm64e">;
"Architecture of the slice to read from a universal (FAT) Mach-O. Required for universal files and rejected for every other image. A CPU family with one slice is selected by its family name; arm64e and arm64e.x1 each read only a slice of that subtype, as lipo -thin does. When several slices share a family, the value must name the slice's subtype: arm64 reads the arm64 or arm64v8 slice, and x86_64 the x86_64 slice but not x86_64h; capability bits are ignored. A value that matches no slice or several is refused.",
) satisfies z.ZodType<keyof typeof MACHO_CPU_TYPES | "arm64e" | "arm64e.x1">;
export type MachoSliceArchitecture = z.infer<
typeof machoSliceArchitectureSchema
>;
/** The CPU family whose slices an architecture value selects; arm64e is an arm64 subtype. */
/**
* Whether a value names an arm64 subtype rather than a CPU family, so it reads
* only a slice of that subtype, even as its family's only slice.
*/
export const machoSliceNamesSubtypeOnly = (
architecture: MachoSliceArchitecture,
): architecture is "arm64e" | "arm64e.x1" =>
architecture === "arm64e" || architecture === "arm64e.x1";
/** The CPU family whose slices an architecture value selects. */
export const machoSliceFamily = (
architecture: MachoSliceArchitecture,
): keyof typeof MACHO_CPU_TYPES =>
architecture === "arm64e" ? "arm64" : architecture;
machoSliceNamesSubtypeOnly(architecture) ? "arm64" : architecture;
/**
* The architecture value that names a slice's subtype exactly, as
* `lipo -thin` does, or undefined when no accepted value names it. Capability
* bits are ignored; `arm64v8` reads as `arm64` and `arm64e.x1` as `arm64e`.
* bits are ignored, and `arm64v8` reads as `arm64`.
*/
export const machoSliceSubtypeSelector = (
cpuType: number,
cpuSubtype: number,
): MachoSliceArchitecture | undefined => {
if (cpuType === MACHO_CPU_TYPES.arm64) {
const name = machoKnownArm64Subtype(cpuSubtype);
const family =
name === undefined ? undefined : machoArchitectureFamily(name);
return family === "arm64" || family === "arm64e" ? family : undefined;
}
if (cpuType === MACHO_CPU_TYPES.arm64)
switch (machoKnownArm64Subtype(cpuSubtype)) {
case "arm64":
case "arm64v8":
return "arm64";
case "arm64e":
return "arm64e";
case "arm64e.x1":
return "arm64e.x1";
default:
return undefined;
}
if (cpuType === MACHO_CPU_TYPES.x86_64)
return machoKnownX86_64Subtype(cpuSubtype) === "x86_64"
? "x86_64"
@@ -99,8 +113,9 @@ export const machoSliceSubtypeSelector = (
/**
* Whether a reported universal slice answers the caller's architecture value.
* Only a universal image has a selection, and only one needs a value. The
* slice must be of the value's CPU family; arm64e also requires its subtype,
* while a family name may read the family's only slice whatever its subtype.
* slice must be of the value's CPU family; arm64e and arm64e.x1 also require
* their subtype, while a family name may read the family's only slice
* whatever its subtype.
*/
export const machoSelectionAnswersArchitecture = (
selection:
@@ -113,9 +128,9 @@ export const machoSelectionAnswersArchitecture = (
? (selection === null || selection === undefined) ===
(architecture === undefined)
: selection.cpu_type === MACHO_CPU_TYPES[machoSliceFamily(architecture)] &&
(architecture !== "arm64e" ||
(!machoSliceNamesSubtypeOnly(architecture) ||
machoSliceSubtypeSelector(selection.cpu_type, selection.cpu_subtype) ===
"arm64e");
architecture);
/** Confirm the selected header's CPU family agrees with the caller's request. */
export const machoTargetSelectionMatchesArchitecture = (
+1 -1
View File
@@ -295,7 +295,7 @@ export const inspectDwarfUnitsInputSchema = z.strictObject({
architecture: machoSliceArchitectureSchema
.exactOptional()
.describe(
"CPU family of the slice to read from a universal Mach-O. Required for universal files and rejected for every other image.",
"Slice to read from a universal Mach-O, by CPU family; arm64e and arm64e.x1 read only a slice of that subtype, as lipo -thin does. Required for universal files and rejected for every other image.",
),
});
+12 -12
View File
@@ -65,8 +65,8 @@ describe("selectNativeImage subtype names", () => {
[CPU_ARM64, 12],
]);
for (const [architecture, index, other] of [
["arm64", 0, "arm64e"],
["arm64e", 1, "arm64"],
["arm64", 0, "arm64e.x1"],
["arm64e.x1", 1, "arm64"],
] as const) {
expect(selectNativeImage(bytes, architecture)).toMatchObject({
ok: true,
@@ -80,25 +80,25 @@ describe("selectNativeImage subtype names", () => {
}
});
it("distinguishes ambiguous and absent selectors for the same subtype table", () => {
const { bytes } = fat([
it("reads arm64e and arm64e.x1 slices of one table by their own selectors", () => {
const { bytes, offsets } = fat([
[CPU_ARM64, 2],
[CPU_ARM64, 12],
]);
expect(selectNativeImage(bytes, "arm64e")).toEqual({
ok: false,
error: {
kind: "ambiguous_architecture",
message:
"Universal Mach-O holds several arm64e slices (arm64 (subtype 0x2), arm64 (subtype 0xc)); no slice was selected.",
},
expect(selectNativeImage(bytes, "arm64e")).toMatchObject({
ok: true,
value: { fileOffset: offsets[0] },
});
expect(selectNativeImage(bytes, "arm64e.x1")).toMatchObject({
ok: true,
value: { fileOffset: offsets[1] },
});
expect(selectNativeImage(bytes, "arm64")).toEqual({
ok: false,
error: {
kind: "architecture_not_present",
message:
"Universal Mach-O holds arm64 (subtype 0x2), arm64 (subtype 0xc); no slice has the arm64 subtype.",
"Universal Mach-O holds arm64 (subtype 0x2), arm64 (subtype 0xc); no slice has the arm64 subtype. Select architecture arm64e or arm64e.x1.",
},
});
});
@@ -384,6 +384,62 @@ sliceTest(
},
);
sliceTest(
"selects arm64e and arm64e.x1 slices of one file by their exact subtype names",
async ({ slices: { client, write } }) => {
// macOS 27 /bin/ls ships x86_64, arm64e and arm64e.x1 slices.
// lipo -thin and otool -arch name each arm64e subtype exactly.
const go = (goVersion: string) =>
createGoBinaryFixture({ format: "macho", goVersion }).bytes;
const universal = universalMacho([
{ bytes: go("go1.25.0"), cpuType: CPU_ARM64, cpuSubtype: 0x80000002 },
{ bytes: go("go1.26.1"), cpuType: CPU_ARM64, cpuSubtype: 0x8000000c },
]);
const [arm64e, x1] = universal.slices;
if (arm64e === undefined || x1 === undefined)
throw new Error("expected two slices");
const path = await write("arm64e-and-arm64e-x1", universal.bytes);
const advertised = (await client.listTools()).tools.find(
({ name }) => name === "inspect_go_binary",
);
if (advertised === undefined)
throw new Error("Missing advertised Go input schema");
const validateInput = new Ajv2020({
strict: false,
validateFormats: false,
}).compile(advertised.inputSchema);
const read = async (architecture: string) => {
expect(validateInput({ path, architecture })).toBe(true);
const response = await client.callTool({
name: "inspect_go_binary",
arguments: { path, architecture },
});
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
return goBinarySchema.parse(
toolContract("inspect_go_binary").outputSchema.parse(
response.structuredContent,
).normalized_result,
);
};
const plain = await read("arm64e");
expect(plain).toMatchObject({
selected_slice: { offset: arm64e.offset, cpu_subtype: 0x80000002 },
build_info: { go_version: "go1.25.0" },
});
expect(plain.limitations).toContain(
`Only the selected arm64e slice (arm64 (subtype 0x80000002) at file offset ${String(arm64e.offset)}) was read; this universal Mach-O also holds arm64 (subtype 0x8000000c) at file offset ${String(x1.offset)} (architecture arm64e.x1 selects it).`,
);
const variant = await read("arm64e.x1");
expect(variant).toMatchObject({
selected_slice: { offset: x1.offset, cpu_subtype: 0x8000000c },
build_info: { go_version: "go1.26.1" },
});
expect(variant.limitations).toContain(
`Only the selected arm64e.x1 slice (arm64 (subtype 0x8000000c) at file offset ${String(x1.offset)}) was read; this universal Mach-O also holds arm64 (subtype 0x80000002) at file offset ${String(arm64e.offset)} (architecture arm64e selects it).`,
);
},
);
sliceTest(
"refuses a subtype that is missing or shared instead of choosing by preference",
async ({ slices: { client, write } }) => {
@@ -422,6 +478,12 @@ sliceTest(
const missing = await refusal("arm64-only", [0, 1], "arm64e");
expect(missing).toMatchObject({ path: ["architecture"] });
expect(missing?.message).not.toMatch(/Select architecture/u);
// arm64e does not read an arm64e.x1 slice, as lipo -thin arm64e does not.
const variantOnly = await refusal("arm64e-x1-only", [0x8000000c], "arm64e");
expect(variantOnly).toMatchObject({ path: ["architecture"] });
expect(variantOnly?.message).toMatch(
/no slice has the arm64e subtype\. Select architecture arm64 or arm64e\.x1\.$/u,
);
},
);