fix(native): match compound otool keys exactly and badge unknown thread entrypoints (#534)
This commit is contained in:
@@ -106,6 +106,16 @@ const normalizeMacho = (
|
||||
/UUID:\s*([A-Fa-f0-9-]+)/u.exec(byTool("dwarfdump").stdout)?.[1] ??
|
||||
load.uuid;
|
||||
const provenance = captures.map(toInvocation);
|
||||
// A thread-state command carries the entrypoint in architecture-specific
|
||||
// register state, so an absent decoded offset means unknown, not absent.
|
||||
const threadEntrypoint =
|
||||
load.entrypoints.length === 0 &&
|
||||
load.commands.some(
|
||||
(command) =>
|
||||
command.kind === "LC_UNIXTHREAD" || command.kind === "LC_THREAD",
|
||||
);
|
||||
const threadEntrypointLimitation =
|
||||
"Thread-state entrypoints (LC_UNIXTHREAD/LC_THREAD) are retained as raw load commands; file offsets are not derived.";
|
||||
const limitations = [
|
||||
"Imports and exports combine dyld_info and nm; stripped or toolchain-hidden symbols may be absent.",
|
||||
...(captures.some(({ tool }) => tool === "vtool")
|
||||
@@ -114,15 +124,7 @@ const normalizeMacho = (
|
||||
]
|
||||
: []),
|
||||
...additionalLimitations,
|
||||
...(load.entrypoints.length === 0 &&
|
||||
load.commands.some(
|
||||
(command) =>
|
||||
command.kind === "LC_UNIXTHREAD" || command.kind === "LC_THREAD",
|
||||
)
|
||||
? [
|
||||
"Thread-state entrypoints (LC_UNIXTHREAD/LC_THREAD) are retained as raw load commands; file offsets are not derived.",
|
||||
]
|
||||
: []),
|
||||
...(threadEntrypoint ? [threadEntrypointLimitation] : []),
|
||||
...(imageBase === null &&
|
||||
/^\s*offset\s+symbol\s*$/mu.test(byTool("dyld_info", 1).stdout)
|
||||
? [
|
||||
@@ -137,7 +139,11 @@ const normalizeMacho = (
|
||||
file_type: load.fileType,
|
||||
flags: load.flags,
|
||||
uuid: uuid ?? null,
|
||||
entrypoints: covered(load.entrypoints, true),
|
||||
entrypoints: covered(
|
||||
load.entrypoints,
|
||||
!threadEntrypoint,
|
||||
threadEntrypoint ? [threadEntrypointLimitation] : [],
|
||||
),
|
||||
architectures: covered(architectures, true),
|
||||
build_metadata: covered(load.builds, true),
|
||||
load_commands: covered(load.commands, true),
|
||||
|
||||
@@ -188,7 +188,11 @@ const parseFields = (block: string): Record<string, string | number | null> => {
|
||||
const fields: Record<string, string | number | null> = {};
|
||||
for (const rawLine of block.split(/\r?\n/u).slice(1)) {
|
||||
const line = rawLine.trim();
|
||||
const match = /^(\S+(?:\s+(?:version|stamp))?)\s+(.+)$/u.exec(line);
|
||||
// Keys are `token` or a compound `token version`. `time stamp` is the one
|
||||
// other real key, and it must be matched as a whole: treating `stamp` as a
|
||||
// generic suffix would swallow an install name such as
|
||||
// `name stamp plugin.dylib`, hiding the dependency path behind `unknown`.
|
||||
const match = /^((?:time stamp)|\S+(?:\s+version)?)\s+(.+)$/u.exec(line);
|
||||
if (match?.[1] === undefined || match[2] === undefined) continue;
|
||||
const value = match[2].trim();
|
||||
fields[match[1]] = numeric(value) ?? value;
|
||||
|
||||
@@ -27,6 +27,31 @@ it("retains lazily loaded library dependencies", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves dependency install names that begin with the word stamp", () => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
[
|
||||
"Load command 2",
|
||||
" cmd LC_LOAD_DYLIB",
|
||||
" name stamp plugin.dylib (offset 24)",
|
||||
" time stamp 2 Thu Jan 1 00:00:02 1970",
|
||||
" current version 1.0.0",
|
||||
"compatibility version 1.0.0",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
expect(load.dependencies).toContainEqual({
|
||||
path: "stamp plugin.dylib",
|
||||
kind: "LC_LOAD_DYLIB",
|
||||
current_version: "1.0.0",
|
||||
compatibility_version: "1.0.0",
|
||||
});
|
||||
expect(
|
||||
load.commands.find((command) => command.kind === "LC_LOAD_DYLIB")?.fields[
|
||||
"time stamp"
|
||||
],
|
||||
).toMatch(/^2 Thu Jan/);
|
||||
});
|
||||
|
||||
it("normalizes legacy version-minimum commands into build metadata", () => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
[
|
||||
@@ -77,7 +102,14 @@ it("limits thread-state entrypoints instead of reporting none silently", async (
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(result.value.result).toMatchObject({
|
||||
entrypoints: { items: [] },
|
||||
entrypoints: {
|
||||
items: [],
|
||||
total: null,
|
||||
exhaustive: false,
|
||||
limitations: [
|
||||
"Thread-state entrypoints (LC_UNIXTHREAD/LC_THREAD) are retained as raw load commands; file offsets are not derived.",
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(result.value.limitations).toContain(
|
||||
"Thread-state entrypoints (LC_UNIXTHREAD/LC_THREAD) are retained as raw load commands; file offsets are not derived.",
|
||||
|
||||
Reference in New Issue
Block a user