fix(apple): distinguish dyld logging from path overrides
This commit is contained in:
@@ -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",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user