fix(apple): distinguish dyld logging from path overrides

This commit is contained in:
morluto
2026-10-08 23:46:06 +08:00
parent 0cbef126a5
commit 5be3eeb1e6
3 changed files with 59 additions and 4 deletions
+31
View File
@@ -926,3 +926,34 @@ it("propagates embedded search-path uncertainty through found, missing, lazy and
"dyld-environment-present",
]);
});
it.each([
"DYLD_PRINT_LIBRARIES=1",
"DYLD_PRINT_RPATHS=1",
"DYLD_LIBRARY_PATH_LOG=/tmp",
"DYLD_LIBRARY_PATH",
])(
"retains %s as an observation without adding path uncertainty",
async (setting) => {
const child = "Contents/MacOS/child.dylib";
const trace = await traceDylibLoading(
memoryView({
[MAIN]: executable({
dyld_environment: [setting],
dependencies: [dependency("@executable_path/child.dylib")],
}),
[child]: parsed(slice()),
}),
{ roots: [MAIN] },
);
expect(trace.edges[0]?.resolution.status).toBe("resolved");
expect(trace.coverage.status).toBe("complete");
expect(
trace.images.find(({ path }) => path === MAIN)?.slices[0]
?.dyld_environment,
).toEqual([setting]);
expect(trace.findings.map(({ kind }) => kind)).toContain(
"dyld-environment-present",
);
},
);
+27 -3
View File
@@ -44,6 +44,29 @@ export {
type Candidate = DylibCandidate;
type Edge = DylibEdge;
// Apple's PathOverrides consumes these variable names. Print/logging variables
// remain observations and do not change which library a search selects.
const DYLD_PATH_VARIABLES: ReadonlySet<string> = new Set([
"DYLD_LIBRARY_PATH",
"DYLD_FRAMEWORK_PATH",
"DYLD_FALLBACK_LIBRARY_PATH",
"DYLD_FALLBACK_FRAMEWORK_PATH",
"DYLD_VERSIONED_LIBRARY_PATH",
"DYLD_VERSIONED_FRAMEWORK_PATH",
"DYLD_INSERT_LIBRARIES",
"DYLD_IMAGE_SUFFIX",
"DYLD_ROOT_PATH",
"DYLD_OVERLAY_PATH",
]);
const hasDyldPathOverrides = (slice: MachoSlice): boolean =>
slice.dyld_environment.some((setting) => {
const delimiter = setting.indexOf("=");
return (
delimiter > 0 && DYLD_PATH_VARIABLES.has(setting.slice(0, delimiter))
);
});
interface LoadedImage {
readonly slice: MachoSlice;
/** Images from the process root to this image; the rpath stack, outermost first. */
@@ -396,7 +419,7 @@ export const traceDylibLoading = async (
root,
architecture: slice.architecture,
platforms: slice.platforms,
searchPathsUnknown: slice.dyld_environment.length > 0,
searchPathsUnknown: hasDyldPathOverrides(slice),
executable: slice.file_type === "execute" ? root : null,
loaded: new Map(),
byInstallName: new Map(),
@@ -423,8 +446,9 @@ export const traceDylibLoading = async (
const facts = images.get(image);
return (
facts?.status === "parsed" &&
(facts.slices.find((s) => s.architecture === architecture)
?.dyld_environment.length ?? 0) > 0
facts.slices.some(
(s) => s.architecture === architecture && hasDyldPathOverrides(s),
)
);
});
return {
+1 -1
View File
@@ -69,7 +69,7 @@ export const deriveFindings = (
edge_index: null,
image,
basis: "derived",
explanation: `${image} (${architecture}) sets dyld environment variables through LC_DYLD_ENVIRONMENT (${environment.join(", ")}); search paths they add are not modeled.`,
explanation: `${image} (${architecture}) sets dyld environment variables through LC_DYLD_ENVIRONMENT (${environment.join(", ")}); any image-selection overrides they request are not modeled. Diagnostic settings alone do not alter resolution.`,
});
}
return findings;