peachsim 0.1.2588 → 0.1.2590
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 +1174 -447
- 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-DG2TVZRD.mjs → acorn-65FNEARV.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-LW5F24Y7.mjs → chunk-2GUB5OLB.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-4PNMHEJB.mjs → chunk-462CWTWI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ASL4MACC.mjs → chunk-4VCRUQ36.mjs} +1180 -453
- package/dist-lib/esm-chunks/{chunk-UFXK4UQL.mjs → chunk-5GNGHM5B.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BAU3IFLL.mjs → chunk-ADKUIQXX.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-4GOTTBDL.mjs → chunk-BZS5SIYK.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-JE7EWYAV.mjs → chunk-EFKDUMB5.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-WZHOX3BM.mjs → chunk-GBD26EBV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-QRKZ3NSY.mjs → chunk-HZTK7TP5.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ELSAXANF.mjs → chunk-JG4AANWA.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-V2PI4V6K.mjs → chunk-N2II5SRJ.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-C7MHFZIA.mjs → chunk-NZY4GOG5.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-AGQHPM6E.mjs → chunk-OZJ66CXY.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-PL3OUSN3.mjs → chunk-RGC2JNCL.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-GIS6FXRN.mjs → chunk-SLPXTLBK.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-BSPFA6V2.mjs → chunk-SRFKOU76.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BGCADZA2.mjs → chunk-V5TTEXYO.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-NSNT4FFS.mjs → chunk-WPDY5IAD.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-YHJXN2S6.mjs → chunk-WYDRQRJL.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-CJ6UJWGD.mjs → chunk-X2EKFONU.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-OLEYCMVV.mjs → chunk-XE3VHAU2.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-SDGYG4FM.mjs → chunk-YPPH6F77.mjs} +1 -1
- package/dist-lib/esm-chunks/{metro-layout-parser-VWCTMFOO.mjs → metro-layout-parser-CRI3GMCM.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-W7FEW6PS.mjs → swift-package-prebuilt-5XDZ2HZZ.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-J4KH7G35.mjs → swift-sdk-app-module-6H3G6AXD.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-MUWMBAKB.mjs → swift-sdk-image-WAC7GG2R.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-BLO2DZ2C.mjs → swift-sdk-image-producer-B3L27QTG.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +1173 -446
- 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 +1215 -480
- 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 +1225 -484
- package/dist-lib/swift-compile.cjs +1170 -443
- 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/dist-types/packages/peach-engine/src/ios/apps/canvas-map-data.d.ts +1 -1
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/src/one-native-controls-package.ts +8 -7
- package/src/swift-guest-compile.ts +2 -2
- package/src/swift-guest-dyld-table.ts +9 -2
- package/src/swift-guest-image-ledger.ts +403 -208
- package/src/swift-guest-link.ts +255 -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-sdk-image-map.ts +137 -35
- package/src/swift-shared-sdk.ts +8 -4
- 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
|
|
@@ -829,10 +892,51 @@ export function linkGuestImages(
|
|
|
829
892
|
// every symbol name a linker map lists, which is what the link kept.
|
|
830
893
|
function linkedMapSymbols(lines: Iterable<string>): Set<string> {
|
|
831
894
|
const names = new Set<string>()
|
|
832
|
-
const symbol = /^ +\S+ +[0-9a-f]+ +[0-9a-f]+ {9,}([^\s/<]\S*)/
|
|
833
895
|
for (const line of lines) {
|
|
834
|
-
const
|
|
835
|
-
if (
|
|
896
|
+
const length = line.length
|
|
897
|
+
if (length < 15 || line.charCodeAt(0) !== 32) continue
|
|
898
|
+
let pos = 1
|
|
899
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
900
|
+
// col 1: \S+
|
|
901
|
+
const c1 = pos
|
|
902
|
+
while (pos < length) {
|
|
903
|
+
const ch = line.charCodeAt(pos)
|
|
904
|
+
if (ch === 32 || (ch >= 9 && ch <= 13)) break
|
|
905
|
+
pos++
|
|
906
|
+
}
|
|
907
|
+
if (pos === c1 || pos >= length || line.charCodeAt(pos) !== 32) continue
|
|
908
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
909
|
+
// col 2: [0-9a-f]+
|
|
910
|
+
const c2 = pos
|
|
911
|
+
while (pos < length) {
|
|
912
|
+
const ch = line.charCodeAt(pos)
|
|
913
|
+
if (!((ch >= 48 && ch <= 57) || (ch >= 97 && ch <= 102))) break
|
|
914
|
+
pos++
|
|
915
|
+
}
|
|
916
|
+
if (pos === c2 || pos >= length || line.charCodeAt(pos) !== 32) continue
|
|
917
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
918
|
+
// col 3: [0-9a-f]+
|
|
919
|
+
const c3 = pos
|
|
920
|
+
while (pos < length) {
|
|
921
|
+
const ch = line.charCodeAt(pos)
|
|
922
|
+
if (!((ch >= 48 && ch <= 57) || (ch >= 97 && ch <= 102))) break
|
|
923
|
+
pos++
|
|
924
|
+
}
|
|
925
|
+
if (pos === c3 || pos >= length || line.charCodeAt(pos) !== 32) continue
|
|
926
|
+
// {9,} spaces
|
|
927
|
+
const sStart = pos
|
|
928
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++
|
|
929
|
+
if (pos - sStart < 9 || pos >= length) continue
|
|
930
|
+
const first = line.charCodeAt(pos)
|
|
931
|
+
if (first === 47 || first === 60 || first === 32 || (first >= 9 && first <= 13))
|
|
932
|
+
continue
|
|
933
|
+
let end = pos + 1
|
|
934
|
+
while (end < length) {
|
|
935
|
+
const ch = line.charCodeAt(end)
|
|
936
|
+
if (ch === 32 || (ch >= 9 && ch <= 13)) break
|
|
937
|
+
end++
|
|
938
|
+
}
|
|
939
|
+
names.add(line.slice(pos, end))
|
|
836
940
|
}
|
|
837
941
|
return names
|
|
838
942
|
}
|
|
@@ -957,7 +1061,10 @@ export function discoverGuestLinkInputs(options: {
|
|
|
957
1061
|
fs.mkdirSync(options.directory, { recursive: true })
|
|
958
1062
|
const why = path.join(options.directory, 'preselection-why.txt')
|
|
959
1063
|
const response = path.join(options.directory, 'preselection.rsp')
|
|
960
|
-
const output =
|
|
1064
|
+
const output =
|
|
1065
|
+
process.platform !== 'win32'
|
|
1066
|
+
? '/dev/null'
|
|
1067
|
+
: path.join(options.directory, 'preselection.wasm')
|
|
961
1068
|
const flags = [
|
|
962
1069
|
...withOutput(args, output, true),
|
|
963
1070
|
...options.objects,
|
|
@@ -1088,6 +1195,7 @@ export function prepareGuestRuntimeInputs(options: {
|
|
|
1088
1195
|
export function selectedGuestSymbolInputs(
|
|
1089
1196
|
plan: GuestLinkPlan,
|
|
1090
1197
|
selected: readonly GuestLinkSelection[],
|
|
1198
|
+
readSelected?: (item: GuestLinkSelection) => Uint8Array,
|
|
1091
1199
|
): {
|
|
1092
1200
|
readonly symbols: readonly string[]
|
|
1093
1201
|
readonly definitions: readonly string[]
|
|
@@ -1112,22 +1220,27 @@ export function selectedGuestSymbolInputs(
|
|
|
1112
1220
|
if (!artifact) throw new Error(`selected symbol input has no owner ${item.artifact}`)
|
|
1113
1221
|
let bytes: Uint8Array
|
|
1114
1222
|
let name = item.artifact
|
|
1115
|
-
if (item.member === null)
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
if (
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
)
|
|
1123
|
-
|
|
1223
|
+
if (item.member === null) {
|
|
1224
|
+
bytes = readSelected ? readSelected(item) : fs.readFileSync(item.artifact)
|
|
1225
|
+
} else {
|
|
1226
|
+
if (readSelected) {
|
|
1227
|
+
bytes = readSelected(item)
|
|
1228
|
+
} else {
|
|
1229
|
+
let members = archives.get(item.artifact)
|
|
1230
|
+
if (!members) {
|
|
1231
|
+
members = Map.groupBy(
|
|
1232
|
+
readArMembers(fs.readFileSync(item.artifact)),
|
|
1233
|
+
(member) => member.name,
|
|
1234
|
+
)
|
|
1235
|
+
archives.set(item.artifact, members)
|
|
1236
|
+
}
|
|
1237
|
+
const matching = members.get(item.member) ?? []
|
|
1238
|
+
if (matching.length !== 1)
|
|
1239
|
+
throw new Error(
|
|
1240
|
+
`ambiguous selected symbol input ${item.artifact}(${item.member})`,
|
|
1241
|
+
)
|
|
1242
|
+
bytes = matching[0]!.bytes
|
|
1124
1243
|
}
|
|
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
1244
|
name += `(${item.member})`
|
|
1132
1245
|
}
|
|
1133
1246
|
if (owners.has(name)) throw new Error(`duplicate selected symbol input ${name}`)
|
|
@@ -1140,9 +1253,9 @@ export function selectedGuestSymbolInputs(
|
|
|
1140
1253
|
for (const symbol of names.tags) tags.add(symbol)
|
|
1141
1254
|
for (const symbol of names.defined) {
|
|
1142
1255
|
definitions.add(symbol)
|
|
1143
|
-
|
|
1256
|
+
let objects = definitionObjects.get(symbol)
|
|
1257
|
+
if (!objects) definitionObjects.set(symbol, (objects = new Set<string>()))
|
|
1144
1258
|
objects.add(name)
|
|
1145
|
-
definitionObjects.set(symbol, objects)
|
|
1146
1259
|
}
|
|
1147
1260
|
}
|
|
1148
1261
|
return {
|
|
@@ -1196,7 +1309,10 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1196
1309
|
if (!symbols.length) return { bindings: [], directBindings: [] }
|
|
1197
1310
|
fs.mkdirSync(options.directory, { recursive: true })
|
|
1198
1311
|
const response = path.join(options.directory, 'scope-trace.rsp')
|
|
1199
|
-
const output =
|
|
1312
|
+
const output =
|
|
1313
|
+
process.platform !== 'win32'
|
|
1314
|
+
? '/dev/null'
|
|
1315
|
+
: path.join(options.directory, 'scope-trace.wasm')
|
|
1200
1316
|
const args = [
|
|
1201
1317
|
...withOutput(normalizedGuestLinkArgs(options.args), output, true),
|
|
1202
1318
|
...options.objects,
|
|
@@ -1221,33 +1337,39 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1221
1337
|
physicalModule: boolean
|
|
1222
1338
|
}
|
|
1223
1339
|
>()
|
|
1224
|
-
const
|
|
1225
|
-
const
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1340
|
+
for (const line of guestLinkLines(tracePath)) {
|
|
1341
|
+
const refSep = line.lastIndexOf(': reference to ')
|
|
1342
|
+
const defSep = line.lastIndexOf(': definition of ')
|
|
1343
|
+
if (refSep < 0 && defSep < 0) continue
|
|
1344
|
+
const isRef = refSep > defSep
|
|
1345
|
+
const sep = isRef ? refSep : defSep
|
|
1346
|
+
const symbol = line.slice(sep + (isRef ? 15 : 16))
|
|
1347
|
+
if (!requested.has(symbol) || options.hostImports.has(symbol)) continue
|
|
1348
|
+
let record = records.get(symbol)
|
|
1349
|
+
if (!record) {
|
|
1350
|
+
record = {
|
|
1351
|
+
references: new Map<string, number>(),
|
|
1352
|
+
providers: new Map<string, number>(),
|
|
1353
|
+
physicalModule: false,
|
|
1354
|
+
}
|
|
1355
|
+
records.set(symbol, record)
|
|
1234
1356
|
}
|
|
1357
|
+
const object = line.slice(0, sep)
|
|
1235
1358
|
// an internal reference is wasm-ld's own, such as the real half of a --wrap, with no object to scope
|
|
1236
1359
|
if (object === '<internal>') {
|
|
1237
|
-
if (
|
|
1360
|
+
if (!isRef) record.physicalModule = true
|
|
1238
1361
|
} else {
|
|
1239
|
-
const image = options.owners.get(object
|
|
1362
|
+
const image = options.owners.get(object)
|
|
1240
1363
|
if (image === undefined)
|
|
1241
1364
|
throw new Error(`traced guest object has no owner ${object}`)
|
|
1242
|
-
;(
|
|
1243
|
-
object!,
|
|
1244
|
-
image,
|
|
1245
|
-
)
|
|
1365
|
+
;(isRef ? record.references : record.providers).set(object, image)
|
|
1246
1366
|
}
|
|
1247
|
-
records.set(symbol!, record)
|
|
1248
1367
|
}
|
|
1249
|
-
for (const line of guestLinkLines(tracePath)) consume(line)
|
|
1250
1368
|
const callers = new Map(options.callers.map((caller) => [caller.image, caller.next]))
|
|
1369
|
+
const callerSets = new Map(
|
|
1370
|
+
options.callers.map((caller) => [caller.image, new Set(caller.next)]),
|
|
1371
|
+
)
|
|
1372
|
+
const rootScope = callerSets.get(0)
|
|
1251
1373
|
const result: {
|
|
1252
1374
|
symbol: string
|
|
1253
1375
|
caller: number
|
|
@@ -1258,28 +1380,38 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1258
1380
|
const record = records.get(symbol)
|
|
1259
1381
|
if (!record || !record.references.size) continue
|
|
1260
1382
|
if (!record.providers.size && options.hostImports.has(symbol)) continue
|
|
1261
|
-
const startupReferences = [
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
(
|
|
1268
|
-
|
|
1383
|
+
const startupReferences: [string, number][] = []
|
|
1384
|
+
const otherReferences: [string, number][] = []
|
|
1385
|
+
let allWeakRefs = true
|
|
1386
|
+
for (const [object, caller] of record.references) {
|
|
1387
|
+
const isWeakRef = options.weakReferences.get(object)?.has(symbol) === true
|
|
1388
|
+
if (!isWeakRef) allWeakRefs = false
|
|
1389
|
+
if (isWeakRef && options.startupObjects.has(object)) {
|
|
1390
|
+
startupReferences.push([object, caller])
|
|
1391
|
+
} else {
|
|
1392
|
+
otherReferences.push([object, caller])
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1269
1395
|
for (const [, caller] of startupReferences)
|
|
1270
1396
|
if (!callers.has(caller))
|
|
1271
1397
|
throw new Error(`guest image has no caller scope ${caller}`)
|
|
1272
1398
|
if (startupReferences.length && !record.physicalModule) {
|
|
1273
|
-
const candidates = options.definitionObjects.get(symbol)
|
|
1274
|
-
|
|
1399
|
+
const candidates = options.definitionObjects.get(symbol)
|
|
1400
|
+
const candidateSize = candidates?.size ?? 0
|
|
1401
|
+
if (candidateSize > 1 || record.providers.size > 1)
|
|
1275
1402
|
throw new Error(`ambiguous startup provider ${symbol}`)
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1403
|
+
let unproven = candidateSize !== record.providers.size
|
|
1404
|
+
if (!unproven && candidates) {
|
|
1405
|
+
for (const object of record.providers.keys()) {
|
|
1406
|
+
if (!candidates.has(object)) {
|
|
1407
|
+
unproven = true
|
|
1408
|
+
break
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
if (unproven) throw new Error(`unproven startup provider ${symbol}`)
|
|
1281
1413
|
if (record.providers.size === 1) {
|
|
1282
|
-
const [providerObject, providerImage] =
|
|
1414
|
+
const [providerObject, providerImage] = record.providers.entries().next().value!
|
|
1283
1415
|
if (options.weakDefinitions.get(providerObject)?.has(symbol))
|
|
1284
1416
|
throw new Error(`weak startup provider ${symbol}`)
|
|
1285
1417
|
for (const [object] of startupReferences)
|
|
@@ -1289,29 +1421,26 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1289
1421
|
}
|
|
1290
1422
|
// an unresolved weak import stays absent, as in dyld; wasm-ld reports it
|
|
1291
1423
|
// 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
|
|
1424
|
+
if (!record.providers.size && !record.physicalModule && allWeakRefs) continue
|
|
1300
1425
|
const providerImages = new Set(record.providers.values())
|
|
1301
1426
|
// the flat trace can report only the selected copy. the image scopes use
|
|
1302
1427
|
// all definitions from the selected objects.
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1428
|
+
const candidates = options.definitionObjects.get(symbol)
|
|
1429
|
+
const copyImages = new Set<number>()
|
|
1430
|
+
const strongImages = new Set<number>()
|
|
1431
|
+
let weakDefinerImages: Set<number> | undefined
|
|
1432
|
+
if (candidates) {
|
|
1433
|
+
for (const object of candidates) {
|
|
1305
1434
|
const image = options.owners.get(object)
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1435
|
+
if (image === undefined) continue
|
|
1436
|
+
copyImages.add(image)
|
|
1437
|
+
if (options.weakDefinitions.get(object)?.has(symbol)) {
|
|
1438
|
+
;(weakDefinerImages ??= new Set()).add(image)
|
|
1439
|
+
} else {
|
|
1440
|
+
strongImages.add(image)
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1315
1444
|
const interposed = !record.physicalModule && copyImages.size > 1
|
|
1316
1445
|
const providerCount = interposed
|
|
1317
1446
|
? 1
|
|
@@ -1321,11 +1450,13 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1321
1450
|
if (!providerCount) continue
|
|
1322
1451
|
if (providerCount !== 1)
|
|
1323
1452
|
throw new Error(`guest symbol has ambiguous provider ${symbol}`)
|
|
1324
|
-
const scopedReferences = record.physicalModule
|
|
1325
|
-
|
|
1326
|
-
: otherReferences
|
|
1453
|
+
const scopedReferences = record.physicalModule ? record.references : otherReferences
|
|
1454
|
+
const firstProviderImage = providerImages.values().next().value
|
|
1327
1455
|
const uniqueProvider =
|
|
1328
|
-
strongImages.size > 1
|
|
1456
|
+
strongImages.size > 1
|
|
1457
|
+
? undefined
|
|
1458
|
+
: (strongImages.values().next().value ?? firstProviderImage)
|
|
1459
|
+
let interposedByCaller: Map<number, number | undefined> | undefined
|
|
1329
1460
|
for (const [object, caller] of scopedReferences) {
|
|
1330
1461
|
const scope = callers.get(caller)
|
|
1331
1462
|
if (!scope) throw new Error(`guest image has no caller scope ${caller}`)
|
|
@@ -1333,9 +1464,27 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1333
1464
|
result.push({ symbol, caller, provider: { kind: 'physical-module' } })
|
|
1334
1465
|
continue
|
|
1335
1466
|
}
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1467
|
+
let provider: number | undefined
|
|
1468
|
+
if (interposed) {
|
|
1469
|
+
if (interposedByCaller?.has(caller)) {
|
|
1470
|
+
provider = interposedByCaller.get(caller)
|
|
1471
|
+
} else {
|
|
1472
|
+
if (copyImages.has(caller)) {
|
|
1473
|
+
provider = caller
|
|
1474
|
+
} else {
|
|
1475
|
+
for (const image of scope) {
|
|
1476
|
+
if (copyImages.has(image)) {
|
|
1477
|
+
provider = image
|
|
1478
|
+
break
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (provider === undefined) provider = uniqueProvider
|
|
1482
|
+
}
|
|
1483
|
+
;(interposedByCaller ??= new Map()).set(caller, provider)
|
|
1484
|
+
}
|
|
1485
|
+
} else {
|
|
1486
|
+
provider = firstProviderImage!
|
|
1487
|
+
}
|
|
1339
1488
|
if (provider === undefined) {
|
|
1340
1489
|
if (options.weakReferences.get(object)?.has(symbol)) continue
|
|
1341
1490
|
throw new Error(`guest scope ${caller} omits every provider of ${symbol}`)
|
|
@@ -1343,16 +1492,8 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1343
1492
|
if (caller === provider) continue
|
|
1344
1493
|
// every image carries its own copy of a weak definition, so a caller
|
|
1345
1494
|
// 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>()
|
|
1495
|
+
if (weakDefinerImages?.has(caller)) continue
|
|
1496
|
+
if (!callerSets.get(caller)!.has(provider)) {
|
|
1356
1497
|
const traced = [...record.providers.keys()]
|
|
1357
1498
|
// the one strong definition a link traces wins over weak fallbacks beside it
|
|
1358
1499
|
const strongTraced = traced.filter(
|
|
@@ -1368,29 +1509,30 @@ export function verifyGuestSymbolScopes(options: {
|
|
|
1368
1509
|
continue
|
|
1369
1510
|
// weak definitions of one symbol are copies of the same code, so a
|
|
1370
1511
|
// strong reference may bind to whichever copy the link traced
|
|
1512
|
+
const candidateSet = candidates ?? new Set<string>()
|
|
1371
1513
|
const equivalentCopies =
|
|
1372
1514
|
providers.length === 1 &&
|
|
1373
|
-
|
|
1374
|
-
[...
|
|
1515
|
+
candidateSet.has(providers[0]!) &&
|
|
1516
|
+
[...candidateSet].every((definer) =>
|
|
1375
1517
|
options.weakDefinitions.get(definer)?.has(symbol),
|
|
1376
1518
|
)
|
|
1377
|
-
const strongCandidates = [...
|
|
1519
|
+
const strongCandidates = [...candidateSet].filter(
|
|
1378
1520
|
(definer) => !options.weakDefinitions.get(definer)?.has(symbol),
|
|
1379
1521
|
)
|
|
1380
1522
|
const soleCandidate =
|
|
1381
|
-
|
|
1523
|
+
candidateSet.size === 1 ||
|
|
1382
1524
|
(strongCandidates.length === 1 && strongCandidates[0] === providers[0])
|
|
1383
1525
|
if (
|
|
1384
1526
|
!equivalentCopies &&
|
|
1385
1527
|
(!soleCandidate ||
|
|
1386
1528
|
providers.length !== 1 ||
|
|
1387
|
-
!
|
|
1529
|
+
!candidateSet.has(providers[0]!) ||
|
|
1388
1530
|
!(
|
|
1389
1531
|
options.systemProviders.has(providers[0]!) ||
|
|
1390
1532
|
// a strong undefined reference binds through the process global
|
|
1391
1533
|
// scope, the root image and its dependency closure, as in elf.
|
|
1392
1534
|
provider === 0 ||
|
|
1393
|
-
|
|
1535
|
+
rootScope?.has(provider) ||
|
|
1394
1536
|
(!options.weakReferences.get(object)?.has(symbol) &&
|
|
1395
1537
|
options.frameworkProviders.get(object)?.has(providers[0]!))
|
|
1396
1538
|
))
|