peachsim 0.1.2589 → 0.1.2591
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +2 -2
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +5 -5
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +3 -3
- package/dist-lib/bundle-channel.cjs +1490 -534
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +3 -3
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +3 -3
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +2 -2
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +7 -7
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +5 -5
- package/dist-lib/detox/index.cjs +1 -1
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-6FUOY6FX.mjs → acorn-EMX4WZ72.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-33SCXU3Y.mjs → chunk-4QHHRGO4.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-Y4PV4HZB.mjs → chunk-7627LKJK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-M4KUWGU3.mjs → chunk-AKKHSVJ4.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-MKSOJCRT.mjs → chunk-EGKH2L6J.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-5EFD2VBY.mjs → chunk-ILWFGZWW.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-57FFWABF.mjs → chunk-J676B57D.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-JLOJZF2Y.mjs → chunk-JHXDM3YU.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-464CBA5U.mjs → chunk-MC6NMYWY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-CRIYVOMB.mjs → chunk-NX23AMX4.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-EAIFG4MQ.mjs → chunk-Q4NA6PUR.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-47K4QPVA.mjs → chunk-QBMFX3J2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FQQ2DMXS.mjs → chunk-RKQZGWX2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-5QWQDXXD.mjs → chunk-SOAYP72T.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-XTKKROVU.mjs → chunk-TFG4LZ5T.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-KFHCRS5K.mjs → chunk-UIVXVMS5.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-BSAAJR25.mjs → chunk-UYJXLDCG.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FMWEI6OI.mjs → chunk-VD27WNCT.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-3VNUC4DT.mjs → chunk-VF5WVB3D.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WQ73RKJY.mjs → chunk-VRVXRZI4.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-L3OSVIGA.mjs → chunk-VYZ5DC3M.mjs} +1359 -487
- package/dist-lib/esm-chunks/{chunk-I22LAVD5.mjs → chunk-YR6DNV76.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-PUBH3EXI.mjs → chunk-ZL5N6ENT.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-T5QIJTEV.mjs → metro-layout-parser-ANKZARNW.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-AWTZHPDM.mjs → swift-package-prebuilt-4N5CXBOZ.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-MGTJTVKU.mjs → swift-sdk-app-module-5IUSRXYA.mjs} +151 -67
- package/dist-lib/esm-chunks/{swift-sdk-image-JABGF3ZR.mjs → swift-sdk-image-7T2LMQS5.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-RJRJ3EFU.mjs → swift-sdk-image-producer-7QJ3BF6E.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +1489 -533
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +7 -7
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +1518 -557
- package/dist-lib/host/fetch-proxy-handler.cjs +4 -4
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +2 -2
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +1 -1
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +3 -3
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +3 -3
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +4 -4
- package/dist-lib/native-app-identity-project.cjs +2 -2
- package/dist-lib/native-app-identity-project.mjs +16 -16
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +6 -6
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +3 -3
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +2 -2
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +3 -3
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +81 -81
- package/dist-lib/public-origins-lib.json +69 -69
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +2 -2
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +8 -8
- package/dist-lib/skills.cjs +1520 -559
- package/dist-lib/swift-compile.cjs +1486 -530
- package/dist-lib/swift-compile.mjs +10 -10
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +3 -3
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +6 -6
- package/dist-lib/swift-svg-raster.cjs +1 -1
- package/dist-lib/swift-svg-raster.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vendor/@peculiar/x509.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/nodes.js.cjs +1 -1
- package/dist-lib/vendor/@ruby/prism/src/parsePrism.js.cjs +1 -1
- package/dist-lib/vendor/@xmldom/xmldom.cjs +1 -1
- package/dist-lib/vendor/acorn.cjs +1 -1
- package/dist-lib/vendor/bplist-parser.cjs +1 -1
- package/dist-lib/vendor/ignore.cjs +1 -1
- package/dist-lib/vendor/magic-string.cjs +1 -1
- package/dist-lib/vendor/plist.cjs +1 -1
- package/dist-lib/vendor/smol-toml.cjs +1 -1
- package/dist-lib/vendor/stream-json.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/index.js.cjs +1 -1
- package/dist-lib/vendor/sucrase/dist/parser/tokenizer/types.js.cjs +1 -1
- package/dist-lib/vendor/sucrase.cjs +1 -1
- package/dist-lib/vendor/terser.cjs +1 -1
- package/dist-lib/vendor/valibot.cjs +1 -1
- package/dist-lib/vendor/ws.cjs +1 -1
- package/dist-lib/vendor/zod.cjs +1 -1
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +3 -3
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/src/swift-guest-compile.ts +43 -10
- package/src/swift-guest-dyld-table.ts +9 -2
- package/src/swift-guest-image-ledger.ts +403 -208
- package/src/swift-guest-link.ts +258 -113
- package/src/swift-guest-linked-spans.ts +217 -28
- package/src/swift-guest-manifest.ts +24 -13
- package/src/swift-guest-projection-storage.ts +6 -8
- package/src/swift-guest-projection.ts +7 -6
- package/src/swift-guest-source-inputs.ts +158 -30
- package/src/swift-sdk-app-module.ts +146 -59
- package/src/swift-sdk-image-map.ts +137 -35
- package/src/swift-wasm-prune.ts +263 -85
- package/src/swiftGuestImageContract.ts +1 -1
package/src/swift-guest-link.ts
CHANGED
|
@@ -88,6 +88,7 @@ export interface GuestLinkOptions {
|
|
|
88
88
|
readonly resolvePlan?: (
|
|
89
89
|
selection: readonly GuestLinkSelection[],
|
|
90
90
|
plan: GuestLinkPlan,
|
|
91
|
+
readSelected?: (item: GuestLinkSelection) => Uint8Array,
|
|
91
92
|
) => GuestLinkPlan
|
|
92
93
|
}
|
|
93
94
|
|
|
@@ -279,6 +280,7 @@ export function selectedGuestLinkInputs(
|
|
|
279
280
|
args: readonly string[],
|
|
280
281
|
whyExtract: string,
|
|
281
282
|
linkTrace: string,
|
|
283
|
+
archiveCache?: Map<string, ReturnType<typeof readArMembers>>,
|
|
282
284
|
): GuestLinkSelection[] {
|
|
283
285
|
const rows = whyExtract.trimEnd().split('\n')
|
|
284
286
|
if (rows.shift() !== 'reference\textracted\tsymbol')
|
|
@@ -294,8 +296,38 @@ export function selectedGuestLinkInputs(
|
|
|
294
296
|
for (const file of extracted)
|
|
295
297
|
if (!traced.has(file))
|
|
296
298
|
throw new Error(`extracted guest input is absent from link trace ${file}`)
|
|
299
|
+
const foundOccurrences = occurrences(plan, args)
|
|
300
|
+
const archivePaths = new Set<string>()
|
|
301
|
+
for (const { artifact } of foundOccurrences)
|
|
302
|
+
if (artifact.kind === 'archive') archivePaths.add(artifact.path)
|
|
303
|
+
const tracedMembers = new Map<string, string[]>()
|
|
304
|
+
if (archivePaths.size > 0) {
|
|
305
|
+
const archivePrefixes = [...archivePaths].map(
|
|
306
|
+
(archivePath) => [archivePath, `${archivePath}(`] as const,
|
|
307
|
+
)
|
|
308
|
+
for (const item of traced) {
|
|
309
|
+
if (!item.endsWith(')')) continue
|
|
310
|
+
const open = item.lastIndexOf('(')
|
|
311
|
+
if (open > 0) {
|
|
312
|
+
const archivePath = item.slice(0, open)
|
|
313
|
+
if (archivePaths.has(archivePath)) {
|
|
314
|
+
let list = tracedMembers.get(archivePath)
|
|
315
|
+
if (!list) tracedMembers.set(archivePath, (list = []))
|
|
316
|
+
list.push(item.slice(open + 1, -1))
|
|
317
|
+
continue
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for (const [archivePath, prefix] of archivePrefixes) {
|
|
321
|
+
if (item.startsWith(prefix)) {
|
|
322
|
+
let list = tracedMembers.get(archivePath)
|
|
323
|
+
if (!list) tracedMembers.set(archivePath, (list = []))
|
|
324
|
+
list.push(item.slice(prefix.length, -1))
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
297
329
|
const result: GuestLinkSelection[] = []
|
|
298
|
-
for (const { artifact, lazy, whole } of
|
|
330
|
+
for (const { artifact, lazy, whole } of foundOccurrences) {
|
|
299
331
|
if (artifact.kind === 'object') {
|
|
300
332
|
if (!lazy && !traced.has(artifact.path))
|
|
301
333
|
throw new Error(`eager guest input is absent from link trace ${artifact.path}`)
|
|
@@ -303,17 +335,21 @@ export function selectedGuestLinkInputs(
|
|
|
303
335
|
result.push({ artifact: artifact.path, member: null })
|
|
304
336
|
continue
|
|
305
337
|
}
|
|
306
|
-
const
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
338
|
+
const names = tracedMembers.get(artifact.path) ?? []
|
|
339
|
+
const nameSet = new Set(names)
|
|
340
|
+
let members = archiveCache?.get(artifact.path)
|
|
341
|
+
if (!members) {
|
|
342
|
+
members = readArMembers(fs.readFileSync(artifact.path))
|
|
343
|
+
archiveCache?.set(artifact.path, members)
|
|
344
|
+
}
|
|
345
|
+
const memberCounts = new Map<string, number>()
|
|
311
346
|
for (const member of members) {
|
|
312
|
-
|
|
347
|
+
memberCounts.set(member.name, (memberCounts.get(member.name) ?? 0) + 1)
|
|
348
|
+
if (whole || nameSet.has(member.name))
|
|
313
349
|
result.push({ artifact: artifact.path, member: member.name })
|
|
314
350
|
}
|
|
315
351
|
for (const name of names)
|
|
316
|
-
if (
|
|
352
|
+
if (memberCounts.get(name) !== 1)
|
|
317
353
|
throw new Error(
|
|
318
354
|
`ambiguous or unsupported archive member ${artifact.path}(${name})`,
|
|
319
355
|
)
|
|
@@ -402,14 +438,25 @@ export function linkGuestImages(
|
|
|
402
438
|
}
|
|
403
439
|
const archives = new Map<string, ReturnType<typeof readArMembers>>()
|
|
404
440
|
const memberBytes = new Map<string, Map<string, Buffer>>()
|
|
441
|
+
const objectBytes = new Map<string, Buffer>()
|
|
405
442
|
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]))
|
|
406
443
|
const providerSymbol = '__peach_dlsym_from_image'
|
|
407
444
|
const readSelected = (item: GuestLinkSelection): Buffer => {
|
|
408
|
-
if (item.member === null)
|
|
445
|
+
if (item.member === null) {
|
|
446
|
+
let bytes = objectBytes.get(item.artifact)
|
|
447
|
+
if (!bytes) {
|
|
448
|
+
bytes = fs.readFileSync(item.artifact)
|
|
449
|
+
objectBytes.set(item.artifact, bytes)
|
|
450
|
+
}
|
|
451
|
+
return bytes
|
|
452
|
+
}
|
|
409
453
|
let byName = memberBytes.get(item.artifact)
|
|
410
454
|
if (!byName) {
|
|
411
|
-
|
|
412
|
-
|
|
455
|
+
let members = archives.get(item.artifact)
|
|
456
|
+
if (!members) {
|
|
457
|
+
members = readArMembers(fs.readFileSync(item.artifact))
|
|
458
|
+
archives.set(item.artifact, members)
|
|
459
|
+
}
|
|
413
460
|
byName = new Map()
|
|
414
461
|
for (const member of members)
|
|
415
462
|
if (!byName.has(member.name))
|
|
@@ -433,7 +480,13 @@ export function linkGuestImages(
|
|
|
433
480
|
`--why-extract=${whyPath}`,
|
|
434
481
|
`--Map=${mapPath}`,
|
|
435
482
|
])
|
|
436
|
-
return selectedGuestLinkInputs(
|
|
483
|
+
return selectedGuestLinkInputs(
|
|
484
|
+
plan,
|
|
485
|
+
args,
|
|
486
|
+
fs.readFileSync(whyPath, 'utf8'),
|
|
487
|
+
trace,
|
|
488
|
+
archives,
|
|
489
|
+
)
|
|
437
490
|
}
|
|
438
491
|
const needsProvider = (item: GuestLinkSelection) => {
|
|
439
492
|
if (!artifacts.get(item.artifact)!.instrumentDynamicLookups) return false
|
|
@@ -479,7 +532,7 @@ export function linkGuestImages(
|
|
|
479
532
|
),
|
|
480
533
|
])
|
|
481
534
|
const originalOwnership = identity(plan)
|
|
482
|
-
const resolved = options.resolvePlan(selected, plan)
|
|
535
|
+
const resolved = options.resolvePlan(selected, plan, readSelected)
|
|
483
536
|
if (identity(resolved) !== originalOwnership)
|
|
484
537
|
throw new Error('resolved guest scopes changed input ownership')
|
|
485
538
|
plan = resolved
|
|
@@ -544,6 +597,7 @@ export function linkGuestImages(
|
|
|
544
597
|
}
|
|
545
598
|
// the final link adds generated inputs after this layout and changes no other order.
|
|
546
599
|
let discoveryRegions: number[] | undefined
|
|
600
|
+
let liveSymbols: Set<string>
|
|
547
601
|
if (discoveryProjection && options.projection) {
|
|
548
602
|
const owners = new Map([[discoveryProjection, options.projection.image]])
|
|
549
603
|
for (const item of selected)
|
|
@@ -552,10 +606,15 @@ export function linkGuestImages(
|
|
|
552
606
|
selectedGuestInputImage(artifacts.get(item.artifact)!, item.member),
|
|
553
607
|
)
|
|
554
608
|
const wasm = fs.readFileSync(discovery)
|
|
609
|
+
liveSymbols = new Set<string>()
|
|
555
610
|
discoveryRegions = guestProjectionRegionCounts(
|
|
556
611
|
plan.images.length,
|
|
557
|
-
guestLinkedSpans(guestLinkLines(mapPath), wasm, wasm, owners
|
|
612
|
+
guestLinkedSpans(guestLinkLines(mapPath), wasm, wasm, owners, undefined, false, {
|
|
613
|
+
collectSymbols: liveSymbols,
|
|
614
|
+
}),
|
|
558
615
|
)
|
|
616
|
+
} else {
|
|
617
|
+
liveSymbols = linkedMapSymbols(guestLinkLines(mapPath))
|
|
559
618
|
}
|
|
560
619
|
const ledger = createGuestImageLedger({
|
|
561
620
|
images: plan.images.map((image) => ({
|
|
@@ -564,7 +623,7 @@ export function linkGuestImages(
|
|
|
564
623
|
})),
|
|
565
624
|
callers: plan.callers,
|
|
566
625
|
symbols: plan.symbols,
|
|
567
|
-
liveSymbols
|
|
626
|
+
liveSymbols,
|
|
568
627
|
commandLineSymbols: commandLineSymbols(args),
|
|
569
628
|
directBindings: plan.directBindings,
|
|
570
629
|
registerAppTables: sdkCallers !== undefined,
|
|
@@ -715,6 +774,7 @@ export function linkGuestImages(
|
|
|
715
774
|
plan,
|
|
716
775
|
selected,
|
|
717
776
|
projection.identities,
|
|
777
|
+
readSelected,
|
|
718
778
|
)
|
|
719
779
|
const images = projection.images.map((image) =>
|
|
720
780
|
createGuestImageManifest({
|
|
@@ -724,6 +784,9 @@ export function linkGuestImages(
|
|
|
724
784
|
regions: [],
|
|
725
785
|
}),
|
|
726
786
|
)
|
|
787
|
+
objectBytes.clear()
|
|
788
|
+
memberBytes.clear()
|
|
789
|
+
archives.clear()
|
|
727
790
|
if (!discoveryRegions) throw new Error('guest projection layout object missing')
|
|
728
791
|
const regionsBefore = discoveryRegions
|
|
729
792
|
// generated pieces belong to one image each: the lookup tables to the ledger data
|
|
@@ -756,6 +819,9 @@ export function linkGuestImages(
|
|
|
756
819
|
{ stdio: 'pipe' },
|
|
757
820
|
)
|
|
758
821
|
finalTrace = linkFinal(projectionObject, callerMap ? undefined : layoutMap)
|
|
822
|
+
// sharedSdk builds never finalize final.wasm; app-module reserves and validates
|
|
823
|
+
// the combined app + SDK projection storage against app.wasm instead.
|
|
824
|
+
if (sharedSdk) break
|
|
759
825
|
const wasm = fs.readFileSync(finalOutput)
|
|
760
826
|
const actual = guestProjectionRegionCounts(
|
|
761
827
|
images.length,
|
|
@@ -829,10 +895,51 @@ export function linkGuestImages(
|
|
|
829
895
|
// every symbol name a linker map lists, which is what the link kept.
|
|
830
896
|
function linkedMapSymbols(lines: Iterable<string>): Set<string> {
|
|
831
897
|
const names = new Set<string>()
|
|
832
|
-
const symbol = /^ +\S+ +[0-9a-f]+ +[0-9a-f]+ {9,}([^\s/<]\S*)/
|
|
833
898
|
for (const line of lines) {
|
|
834
|
-
const
|
|
835
|
-
if (
|
|
899
|
+
const length = line.length
|
|
900
|
+
if (length < 15 || line.charCodeAt(0) !== 32) continue
|
|
901
|
+
let pos = 1
|
|
902
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
903
|
+
// col 1: \S+
|
|
904
|
+
const c1 = pos
|
|
905
|
+
while (pos < length) {
|
|
906
|
+
const ch = line.charCodeAt(pos)
|
|
907
|
+
if (ch === 32 || (ch >= 9 && ch <= 13)) break
|
|
908
|
+
pos++
|
|
909
|
+
}
|
|
910
|
+
if (pos === c1 || pos >= length || line.charCodeAt(pos) !== 32) continue
|
|
911
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
912
|
+
// col 2: [0-9a-f]+
|
|
913
|
+
const c2 = pos
|
|
914
|
+
while (pos < length) {
|
|
915
|
+
const ch = line.charCodeAt(pos)
|
|
916
|
+
if (!((ch >= 48 && ch <= 57) || (ch >= 97 && ch <= 102))) break
|
|
917
|
+
pos++
|
|
918
|
+
}
|
|
919
|
+
if (pos === c2 || pos >= length || line.charCodeAt(pos) !== 32) continue
|
|
920
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
921
|
+
// col 3: [0-9a-f]+
|
|
922
|
+
const c3 = pos
|
|
923
|
+
while (pos < length) {
|
|
924
|
+
const ch = line.charCodeAt(pos)
|
|
925
|
+
if (!((ch >= 48 && ch <= 57) || (ch >= 97 && ch <= 102))) break
|
|
926
|
+
pos++
|
|
927
|
+
}
|
|
928
|
+
if (pos === c3 || pos >= length || line.charCodeAt(pos) !== 32) continue
|
|
929
|
+
// {9,} spaces
|
|
930
|
+
const sStart = pos
|
|
931
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
932
|
+
if (pos - sStart < 9 || pos >= length) continue
|
|
933
|
+
const first = line.charCodeAt(pos)
|
|
934
|
+
if (first === 47 || first === 60 || first === 32 || (first >= 9 && first <= 13))
|
|
935
|
+
continue
|
|
936
|
+
let end = pos + 1
|
|
937
|
+
while (end < length) {
|
|
938
|
+
const ch = line.charCodeAt(end)
|
|
939
|
+
if (ch === 32 || (ch >= 9 && ch <= 13)) break
|
|
940
|
+
end++
|
|
941
|
+
}
|
|
942
|
+
names.add(line.slice(pos, end))
|
|
836
943
|
}
|
|
837
944
|
return names
|
|
838
945
|
}
|
|
@@ -957,7 +1064,10 @@ export function discoverGuestLinkInputs(options: {
|
|
|
957
1064
|
fs.mkdirSync(options.directory, { recursive: true })
|
|
958
1065
|
const why = path.join(options.directory, 'preselection-why.txt')
|
|
959
1066
|
const response = path.join(options.directory, 'preselection.rsp')
|
|
960
|
-
const output =
|
|
1067
|
+
const output =
|
|
1068
|
+
process.platform !== 'win32'
|
|
1069
|
+
? '/dev/null'
|
|
1070
|
+
: path.join(options.directory, 'preselection.wasm')
|
|
961
1071
|
const flags = [
|
|
962
1072
|
...withOutput(args, output, true),
|
|
963
1073
|
...options.objects,
|
|
@@ -1088,6 +1198,7 @@ export function prepareGuestRuntimeInputs(options: {
|
|
|
1088
1198
|
export function selectedGuestSymbolInputs(
|
|
1089
1199
|
plan: GuestLinkPlan,
|
|
1090
1200
|
selected: readonly GuestLinkSelection[],
|
|
1201
|
+
readSelected?: (item: GuestLinkSelection) => Uint8Array,
|
|
1091
1202
|
): {
|
|
1092
1203
|
readonly symbols: readonly string[]
|
|
1093
1204
|
readonly definitions: readonly string[]
|
|
@@ -1112,22 +1223,27 @@ export function selectedGuestSymbolInputs(
|
|
|
1112
1223
|
if (!artifact) throw new Error(`selected symbol input has no owner ${item.artifact}`)
|
|
1113
1224
|
let bytes: Uint8Array
|
|
1114
1225
|
let name = item.artifact
|
|
1115
|
-
if (item.member === null)
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
if (
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
)
|
|
1123
|
-
|
|
1226
|
+
if (item.member === null) {
|
|
1227
|
+
bytes = readSelected ? readSelected(item) : fs.readFileSync(item.artifact)
|
|
1228
|
+
} else {
|
|
1229
|
+
if (readSelected) {
|
|
1230
|
+
bytes = readSelected(item)
|
|
1231
|
+
} else {
|
|
1232
|
+
let members = archives.get(item.artifact)
|
|
1233
|
+
if (!members) {
|
|
1234
|
+
members = Map.groupBy(
|
|
1235
|
+
readArMembers(fs.readFileSync(item.artifact)),
|
|
1236
|
+
(member) => member.name,
|
|
1237
|
+
)
|
|
1238
|
+
archives.set(item.artifact, members)
|
|
1239
|
+
}
|
|
1240
|
+
const matching = members.get(item.member) ?? []
|
|
1241
|
+
if (matching.length !== 1)
|
|
1242
|
+
throw new Error(
|
|
1243
|
+
`ambiguous selected symbol input ${item.artifact}(${item.member})`,
|
|
1244
|
+
)
|
|
1245
|
+
bytes = matching[0]!.bytes
|
|
1124
1246
|
}
|
|
1125
|
-
const matching = members.get(item.member) ?? []
|
|
1126
|
-
if (matching.length !== 1)
|
|
1127
|
-
throw new Error(
|
|
1128
|
-
`ambiguous selected symbol input ${item.artifact}(${item.member})`,
|
|
1129
|
-
)
|
|
1130
|
-
bytes = matching[0]!.bytes
|
|
1131
1247
|
name += `(${item.member})`
|
|
1132
1248
|
}
|
|
1133
1249
|
if (owners.has(name)) throw new Error(`duplicate selected symbol input ${name}`)
|
|
@@ -1140,9 +1256,9 @@ export function selectedGuestSymbolInputs(
|
|
|
1140
1256
|
for (const symbol of names.tags) tags.add(symbol)
|
|
1141
1257
|
for (const symbol of names.defined) {
|
|
1142
1258
|
definitions.add(symbol)
|
|
1143
|
-
|
|
1259
|
+
let objects = definitionObjects.get(symbol)
|
|
1260
|
+
if (!objects) definitionObjects.set(symbol, (objects = new Set<string>()))
|
|
1144
1261
|
objects.add(name)
|
|
1145
|
-
definitionObjects.set(symbol, objects)
|
|
1146
1262
|
}
|
|
1147
1263
|
}
|
|
1148
1264
|
return {
|
|
@@ -1196,7 +1312,10 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1196
1312
|
if (!symbols.length) return { bindings: [], directBindings: [] }
|
|
1197
1313
|
fs.mkdirSync(options.directory, { recursive: true })
|
|
1198
1314
|
const response = path.join(options.directory, 'scope-trace.rsp')
|
|
1199
|
-
const output =
|
|
1315
|
+
const output =
|
|
1316
|
+
process.platform !== 'win32'
|
|
1317
|
+
? '/dev/null'
|
|
1318
|
+
: path.join(options.directory, 'scope-trace.wasm')
|
|
1200
1319
|
const args = [
|
|
1201
1320
|
...withOutput(normalizedGuestLinkArgs(options.args), output, true),
|
|
1202
1321
|
...options.objects,
|
|
@@ -1221,33 +1340,39 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1221
1340
|
physicalModule: boolean
|
|
1222
1341
|
}
|
|
1223
1342
|
>()
|
|
1224
|
-
const
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1343
|
+
for (const line of guestLinkLines(tracePath)) {
|
|
1344
|
+
const refSep = line.lastIndexOf(': reference to ')
|
|
1345
|
+
const defSep = line.lastIndexOf(': definition of ')
|
|
1346
|
+
if (refSep < 0 && defSep < 0) continue
|
|
1347
|
+
const isRef = refSep > defSep
|
|
1348
|
+
const sep = isRef ? refSep : defSep
|
|
1349
|
+
const symbol = line.slice(sep + (isRef ? 15 : 16))
|
|
1350
|
+
if (!requested.has(symbol) || options.hostImports.has(symbol)) continue
|
|
1351
|
+
let record = records.get(symbol)
|
|
1352
|
+
if (!record) {
|
|
1353
|
+
record = {
|
|
1354
|
+
references: new Map<string, number>(),
|
|
1355
|
+
providers: new Map<string, number>(),
|
|
1356
|
+
physicalModule: false,
|
|
1357
|
+
}
|
|
1358
|
+
records.set(symbol, record)
|
|
1234
1359
|
}
|
|
1360
|
+
const object = line.slice(0, sep)
|
|
1235
1361
|
// an internal reference is wasm-ld's own, such as the real half of a --wrap, with no object to scope
|
|
1236
1362
|
if (object === '<internal>') {
|
|
1237
|
-
if (
|
|
1363
|
+
if (!isRef) record.physicalModule = true
|
|
1238
1364
|
} else {
|
|
1239
|
-
const image = options.owners.get(object
|
|
1365
|
+
const image = options.owners.get(object)
|
|
1240
1366
|
if (image === undefined)
|
|
1241
1367
|
throw new Error(`traced guest object has no owner ${object}`)
|
|
1242
|
-
;(
|
|
1243
|
-
object!,
|
|
1244
|
-
image,
|
|
1245
|
-
)
|
|
1368
|
+
;(isRef ? record.references : record.providers).set(object, image)
|
|
1246
1369
|
}
|
|
1247
|
-
records.set(symbol!, record)
|
|
1248
1370
|
}
|
|
1249
|
-
for (const line of guestLinkLines(tracePath)) consume(line)
|
|
1250
1371
|
const callers = new Map(options.callers.map((caller) => [caller.image, caller.next]))
|
|
1372
|
+
const callerSets = new Map(
|
|
1373
|
+
options.callers.map((caller) => [caller.image, new Set(caller.next)]),
|
|
1374
|
+
)
|
|
1375
|
+
const rootScope = callerSets.get(0)
|
|
1251
1376
|
const result: {
|
|
1252
1377
|
symbol: string
|
|
1253
1378
|
caller: number
|
|
@@ -1258,28 +1383,38 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1258
1383
|
const record = records.get(symbol)
|
|
1259
1384
|
if (!record || !record.references.size) continue
|
|
1260
1385
|
if (!record.providers.size && options.hostImports.has(symbol)) continue
|
|
1261
|
-
const startupReferences = [
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
(
|
|
1268
|
-
|
|
1386
|
+
const startupReferences: [string, number][] = []
|
|
1387
|
+
const otherReferences: [string, number][] = []
|
|
1388
|
+
let allWeakRefs = true
|
|
1389
|
+
for (const [object, caller] of record.references) {
|
|
1390
|
+
const isWeakRef = options.weakReferences.get(object)?.has(symbol) === true
|
|
1391
|
+
if (!isWeakRef) allWeakRefs = false
|
|
1392
|
+
if (isWeakRef && options.startupObjects.has(object)) {
|
|
1393
|
+
startupReferences.push([object, caller])
|
|
1394
|
+
} else {
|
|
1395
|
+
otherReferences.push([object, caller])
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1269
1398
|
for (const [, caller] of startupReferences)
|
|
1270
1399
|
if (!callers.has(caller))
|
|
1271
1400
|
throw new Error(`guest image has no caller scope ${caller}`)
|
|
1272
1401
|
if (startupReferences.length && !record.physicalModule) {
|
|
1273
|
-
const candidates = options.definitionObjects.get(symbol)
|
|
1274
|
-
|
|
1402
|
+
const candidates = options.definitionObjects.get(symbol)
|
|
1403
|
+
const candidateSize = candidates?.size ?? 0
|
|
1404
|
+
if (candidateSize > 1 || record.providers.size > 1)
|
|
1275
1405
|
throw new Error(`ambiguous startup provider ${symbol}`)
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1406
|
+
let unproven = candidateSize !== record.providers.size
|
|
1407
|
+
if (!unproven && candidates) {
|
|
1408
|
+
for (const object of record.providers.keys()) {
|
|
1409
|
+
if (!candidates.has(object)) {
|
|
1410
|
+
unproven = true
|
|
1411
|
+
break
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
if (unproven) throw new Error(`unproven startup provider ${symbol}`)
|
|
1281
1416
|
if (record.providers.size === 1) {
|
|
1282
|
-
const [providerObject, providerImage] =
|
|
1417
|
+
const [providerObject, providerImage] = record.providers.entries().next().value!
|
|
1283
1418
|
if (options.weakDefinitions.get(providerObject)?.has(symbol))
|
|
1284
1419
|
throw new Error(`weak startup provider ${symbol}`)
|
|
1285
1420
|
for (const [object] of startupReferences)
|
|
@@ -1289,29 +1424,26 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1289
1424
|
}
|
|
1290
1425
|
// an unresolved weak import stays absent, as in dyld; wasm-ld reports it
|
|
1291
1426
|
// as an internal undefined_weak definition.
|
|
1292
|
-
if (
|
|
1293
|
-
!record.providers.size &&
|
|
1294
|
-
!record.physicalModule &&
|
|
1295
|
-
[...record.references.keys()].every((object) =>
|
|
1296
|
-
options.weakReferences.get(object)?.has(symbol),
|
|
1297
|
-
)
|
|
1298
|
-
)
|
|
1299
|
-
continue
|
|
1427
|
+
if (!record.providers.size && !record.physicalModule && allWeakRefs) continue
|
|
1300
1428
|
const providerImages = new Set(record.providers.values())
|
|
1301
1429
|
// the flat trace can report only the selected copy. the image scopes use
|
|
1302
1430
|
// all definitions from the selected objects.
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1431
|
+
const candidates = options.definitionObjects.get(symbol)
|
|
1432
|
+
const copyImages = new Set<number>()
|
|
1433
|
+
const strongImages = new Set<number>()
|
|
1434
|
+
let weakDefinerImages: Set<number> | undefined
|
|
1435
|
+
if (candidates) {
|
|
1436
|
+
for (const object of candidates) {
|
|
1305
1437
|
const image = options.owners.get(object)
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1438
|
+
if (image === undefined) continue
|
|
1439
|
+
copyImages.add(image)
|
|
1440
|
+
if (options.weakDefinitions.get(object)?.has(symbol)) {
|
|
1441
|
+
;(weakDefinerImages ??= new Set()).add(image)
|
|
1442
|
+
} else {
|
|
1443
|
+
strongImages.add(image)
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1315
1447
|
const interposed = !record.physicalModule && copyImages.size > 1
|
|
1316
1448
|
const providerCount = interposed
|
|
1317
1449
|
? 1
|
|
@@ -1321,11 +1453,13 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1321
1453
|
if (!providerCount) continue
|
|
1322
1454
|
if (providerCount !== 1)
|
|
1323
1455
|
throw new Error(`guest symbol has ambiguous provider ${symbol}`)
|
|
1324
|
-
const scopedReferences = record.physicalModule
|
|
1325
|
-
|
|
1326
|
-
: otherReferences
|
|
1456
|
+
const scopedReferences = record.physicalModule ? record.references : otherReferences
|
|
1457
|
+
const firstProviderImage = providerImages.values().next().value
|
|
1327
1458
|
const uniqueProvider =
|
|
1328
|
-
strongImages.size > 1
|
|
1459
|
+
strongImages.size > 1
|
|
1460
|
+
? undefined
|
|
1461
|
+
: (strongImages.values().next().value ?? firstProviderImage)
|
|
1462
|
+
let interposedByCaller: Map<number, number | undefined> | undefined
|
|
1329
1463
|
for (const [object, caller] of scopedReferences) {
|
|
1330
1464
|
const scope = callers.get(caller)
|
|
1331
1465
|
if (!scope) throw new Error(`guest image has no caller scope ${caller}`)
|
|
@@ -1333,9 +1467,27 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1333
1467
|
result.push({ symbol, caller, provider: { kind: 'physical-module' } })
|
|
1334
1468
|
continue
|
|
1335
1469
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1470
|
+
let provider: number | undefined
|
|
1471
|
+
if (interposed) {
|
|
1472
|
+
if (interposedByCaller?.has(caller)) {
|
|
1473
|
+
provider = interposedByCaller.get(caller)
|
|
1474
|
+
} else {
|
|
1475
|
+
if (copyImages.has(caller)) {
|
|
1476
|
+
provider = caller
|
|
1477
|
+
} else {
|
|
1478
|
+
for (const image of scope) {
|
|
1479
|
+
if (copyImages.has(image)) {
|
|
1480
|
+
provider = image
|
|
1481
|
+
break
|
|
1482
|
+
}
|
|
1483
|
+
}
|
|
1484
|
+
if (provider === undefined) provider = uniqueProvider
|
|
1485
|
+
}
|
|
1486
|
+
;(interposedByCaller ??= new Map()).set(caller, provider)
|
|
1487
|
+
}
|
|
1488
|
+
} else {
|
|
1489
|
+
provider = firstProviderImage!
|
|
1490
|
+
}
|
|
1339
1491
|
if (provider === undefined) {
|
|
1340
1492
|
if (options.weakReferences.get(object)?.has(symbol)) continue
|
|
1341
1493
|
throw new Error(`guest scope ${caller} omits every provider of ${symbol}`)
|
|
@@ -1343,16 +1495,8 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1343
1495
|
if (caller === provider) continue
|
|
1344
1496
|
// every image carries its own copy of a weak definition, so a caller
|
|
1345
1497
|
// whose image defines one binds to it and needs no other provider.
|
|
1346
|
-
if (
|
|
1347
|
-
|
|
1348
|
-
(definer) =>
|
|
1349
|
-
options.owners.get(definer) === caller &&
|
|
1350
|
-
options.weakDefinitions.get(definer)?.has(symbol),
|
|
1351
|
-
)
|
|
1352
|
-
)
|
|
1353
|
-
continue
|
|
1354
|
-
if (!scope.includes(provider)) {
|
|
1355
|
-
const candidates = options.definitionObjects.get(symbol) ?? new Set<string>()
|
|
1498
|
+
if (weakDefinerImages?.has(caller)) continue
|
|
1499
|
+
if (!callerSets.get(caller)!.has(provider)) {
|
|
1356
1500
|
const traced = [...record.providers.keys()]
|
|
1357
1501
|
// the one strong definition a link traces wins over weak fallbacks beside it
|
|
1358
1502
|
const strongTraced = traced.filter(
|
|
@@ -1368,29 +1512,30 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1368
1512
|
continue
|
|
1369
1513
|
// weak definitions of one symbol are copies of the same code, so a
|
|
1370
1514
|
// strong reference may bind to whichever copy the link traced
|
|
1515
|
+
const candidateSet = candidates ?? new Set<string>()
|
|
1371
1516
|
const equivalentCopies =
|
|
1372
1517
|
providers.length === 1 &&
|
|
1373
|
-
|
|
1374
|
-
[...
|
|
1518
|
+
candidateSet.has(providers[0]!) &&
|
|
1519
|
+
[...candidateSet].every((definer) =>
|
|
1375
1520
|
options.weakDefinitions.get(definer)?.has(symbol),
|
|
1376
1521
|
)
|
|
1377
|
-
const strongCandidates = [...
|
|
1522
|
+
const strongCandidates = [...candidateSet].filter(
|
|
1378
1523
|
(definer) => !options.weakDefinitions.get(definer)?.has(symbol),
|
|
1379
1524
|
)
|
|
1380
1525
|
const soleCandidate =
|
|
1381
|
-
|
|
1526
|
+
candidateSet.size === 1 ||
|
|
1382
1527
|
(strongCandidates.length === 1 && strongCandidates[0] === providers[0])
|
|
1383
1528
|
if (
|
|
1384
1529
|
!equivalentCopies &&
|
|
1385
1530
|
(!soleCandidate ||
|
|
1386
1531
|
providers.length !== 1 ||
|
|
1387
|
-
!
|
|
1532
|
+
!candidateSet.has(providers[0]!) ||
|
|
1388
1533
|
!(
|
|
1389
1534
|
options.systemProviders.has(providers[0]!) ||
|
|
1390
1535
|
// a strong undefined reference binds through the process global
|
|
1391
1536
|
// scope, the root image and its dependency closure, as in elf.
|
|
1392
1537
|
provider === 0 ||
|
|
1393
|
-
|
|
1538
|
+
rootScope?.has(provider) ||
|
|
1394
1539
|
(!options.weakReferences.get(object)?.has(symbol) &&
|
|
1395
1540
|
options.frameworkProviders.get(object)?.has(providers[0]!))
|
|
1396
1541
|
))
|