fix(managed): admit ReadyToRun images built for non-Windows hosts (#1985)

ReadyToRun images compiled for Linux, macOS or the BSDs store the COFF machine XORed with IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE (dotnet/runtime src/coreclr/inc/pedecoder.h). Every framework assembly in a Linux .NET install has machine 0xFD1D, so target admission and the managed PE reader rejected them as an unsupported architecture.

Decode the PE machine once in src/domain/peMachine.ts, replacing the two duplicated switches, and accept an OS override only on images with a CLI directory.
This commit is contained in:
Jeremy Levartovsky
2026-10-12 08:41:23 +08:00
committed by GitHub
parent 43f9c39dfb
commit 0d11f71e0d
6 changed files with 168 additions and 40 deletions
+35
View File
@@ -50,6 +50,41 @@ describe("executable header parsing", () => {
});
});
it.each([
["Linux x86_64", 0x8664 ^ 0x7b79, "x86_64"],
["Linux arm64", 0xaa64 ^ 0x7b79, "arm64"],
["Apple x86_64", 0x8664 ^ 0x4644, "x86_64"],
["Apple arm64", 0xaa64 ^ 0x4644, "arm64"],
["FreeBSD x86_64", 0x8664 ^ 0xadc4, "x86_64"],
["OpenBSD x86_64", 0x8664 ^ 0xadc5, "x86_64"],
["NetBSD x86_64", 0x8664 ^ 0x1993, "x86_64"],
["SunOS x86_64", 0x8664 ^ 0x1992, "x86_64"],
] as const)(
"decodes the %s ReadyToRun OS-override machine on a managed image",
(_label, machine, architecture) => {
const result = parseExecutableHeader(
pe(machine, 64, 0x2002, true),
"x64",
);
expect(result.ok && result.value).toMatchObject({
format: "pe",
architecture,
managed: true,
});
},
);
it("rejects an OS-override machine on a native image", () => {
const result = parseExecutableHeader(
pe(0x8664 ^ 0x7b79, 64, 0x2002),
"x64",
);
expect(result).toEqual({
ok: false,
error: "unsupported PE architecture",
});
});
it("selects the host architecture from a FAT table", () => {
const bytes = fat([0x01000007, 0x0100000c]);
const arm = parseExecutableHeader(bytes, "arm64");