fix(native): match compound otool keys exactly and badge unknown thread entrypoints (#534)

This commit is contained in:
morluto
2026-10-05 15:43:20 +08:00
committed by GitHub
parent 4007b20fc2
commit d40502aa3b
3 changed files with 54 additions and 12 deletions
+16 -10
View File
@@ -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),
+5 -1
View File
@@ -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;