fix(apple): gate shared-cache answers on platform and verified subcaches
- Use a supplied cache for a process only when it serves the process's CPU family and one of its LC_BUILD_VERSION or LC_VERSION_MIN platforms matches the cache's platform or alternate platform; slices now report platforms. A limitation names each root the cache was not used for, and why. - Treat an image listed in the cache but mapped in a missing or UUID-mismatched subcache as undetermined, list it in coverage.unverified_shared_cache_images, and mark coverage partial. - Keep a cache hit conditional when an earlier candidate is undeterminable. - Open a development cache's named subcaches beside its base name. - Describe absolute paths as not evaluated only when no cache is supplied. - Preflight dyld_info in verify:dyld-shared-cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
202661f83b
commit
305474df6c
@@ -6,6 +6,7 @@ import { describe, expect } from "vitest";
|
||||
import {
|
||||
FILE_TYPE,
|
||||
LC,
|
||||
buildVersionCommand,
|
||||
dylibCommand,
|
||||
machoImage,
|
||||
rpathCommand,
|
||||
@@ -202,15 +203,23 @@ describe("trace-dylib-resolution CLI inputs", () => {
|
||||
await writeFiles(directory, {
|
||||
tool: machoImage({
|
||||
commands: [
|
||||
buildVersionCommand(1),
|
||||
dylibCommand(LC.LOAD_DYLIB, "/usr/lib/libSystem.B.dylib"),
|
||||
dylibCommand(LC.LOAD_DYLIB, "/usr/lib/libnotcached.dylib"),
|
||||
dylibCommand(LC.LOAD_DYLIB, "/usr/lib/swift/libswiftCore.dylib"),
|
||||
],
|
||||
}),
|
||||
// The .01 subcache holding libswiftCore is not written.
|
||||
dyld_shared_cache_arm64e: dyldCacheFixture([
|
||||
{
|
||||
path: "/usr/lib/libSystem.B.dylib",
|
||||
bytes: machoImage({ fileType: FILE_TYPE.dylib }),
|
||||
},
|
||||
{
|
||||
path: "/usr/lib/swift/libswiftCore.dylib",
|
||||
bytes: machoImage({ fileType: FILE_TYPE.dylib }),
|
||||
inSubcache: true,
|
||||
},
|
||||
]).main,
|
||||
});
|
||||
const result = await cli.run({
|
||||
@@ -234,7 +243,12 @@ describe("trace-dylib-resolution CLI inputs", () => {
|
||||
expect(trace.edges.map(({ resolution }) => resolution.status)).toEqual([
|
||||
"shared-cache",
|
||||
"undetermined",
|
||||
"undetermined",
|
||||
]);
|
||||
expect(trace.coverage).toMatchObject({
|
||||
status: "partial",
|
||||
unverified_shared_cache_images: ["/usr/lib/swift/libswiftCore.dylib"],
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -27,13 +27,16 @@ const dylib = (installName: string, dependencies: readonly Uint8Array[] = []) =>
|
||||
commands: [dylibCommand(LC.ID_DYLIB, installName), ...dependencies],
|
||||
});
|
||||
|
||||
const writeCache = async (fixture: CacheFixture): Promise<string> => {
|
||||
const writeCache = async (
|
||||
fixture: CacheFixture,
|
||||
name = "dyld_shared_cache_arm64e",
|
||||
): Promise<string> => {
|
||||
const directory = await createTestTempDirectory("rea-dyld-cache-");
|
||||
const path = join(directory, "dyld_shared_cache_arm64e");
|
||||
await writeFile(path, fixture.main);
|
||||
const base = join(directory, "dyld_shared_cache_arm64e");
|
||||
await writeFile(join(directory, name), fixture.main);
|
||||
for (const { suffix, bytes } of fixture.subcaches)
|
||||
await writeFile(`${path}${suffix}`, bytes);
|
||||
return path;
|
||||
await writeFile(`${base}${suffix}`, bytes);
|
||||
return join(directory, name);
|
||||
};
|
||||
|
||||
const IMAGES = [
|
||||
@@ -122,6 +125,21 @@ describe("dyld shared cache inspection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("finds a development cache's subcaches beside its base name", async () => {
|
||||
const path = await writeCache(
|
||||
dyldCacheFixture(IMAGES),
|
||||
"dyld_shared_cache_arm64e.development",
|
||||
);
|
||||
const result = await inspectDyldSharedCache({
|
||||
cache_path: path,
|
||||
images: ["/usr/lib/swift/libswiftCore.dylib"],
|
||||
});
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
subcaches: [{ suffix: ".01", status: "present" }],
|
||||
inspected_images: [{ status: "parsed", file: ".01" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("reads legacy single-file headers without later fields", async () => {
|
||||
const path = await writeCache(
|
||||
dyldCacheFixture(IMAGES.slice(0, 1), { legacy: true }),
|
||||
|
||||
Reference in New Issue
Block a user