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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.2590 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
import {
|
|
3
3
|
SWIFT_AUTOLINK_LINKER,
|
|
4
4
|
SWIFT_CACHE_HOLD_MARKER,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
windowAdmission,
|
|
19
19
|
withSwiftRootLock,
|
|
20
20
|
writeSwiftAutolinkLinker
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-JG4AANWA.mjs";
|
|
22
22
|
import {
|
|
23
23
|
SWIFT_BINARY_TREES_DIR,
|
|
24
24
|
SWIFT_NATIVE_INPUT_ROOT,
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
isSwiftResourcePath,
|
|
34
34
|
isSwiftSourceLinkGraph,
|
|
35
35
|
swiftProjectFilesProblems
|
|
36
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-5GNGHM5B.mjs";
|
|
37
37
|
import {
|
|
38
38
|
OBJC_RESOURCE_ACCESSOR_BODY,
|
|
39
39
|
OBJC_RESOURCE_ACCESSOR_HEADER,
|
|
@@ -57,16 +57,16 @@ import {
|
|
|
57
57
|
swiftPackagePartition,
|
|
58
58
|
swiftTargetModuleName,
|
|
59
59
|
withoutGlogModuleMap
|
|
60
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-GBD26EBV.mjs";
|
|
61
61
|
import {
|
|
62
62
|
rnxPublicBrand
|
|
63
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-ADKUIQXX.mjs";
|
|
64
64
|
import {
|
|
65
65
|
isRecord
|
|
66
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-WPDY5IAD.mjs";
|
|
67
67
|
import {
|
|
68
68
|
__publicField
|
|
69
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-NZY4GOG5.mjs";
|
|
70
70
|
|
|
71
71
|
// src/swift-compile.ts
|
|
72
72
|
import {
|
|
@@ -3200,6 +3200,7 @@ function stageOverlaySlot(realRoot, stagingRoot, relPath) {
|
|
|
3200
3200
|
const segment = segments[i];
|
|
3201
3201
|
for (const entry of readdirSync2(real)) {
|
|
3202
3202
|
if (entry === segment || i === 0 && entry === SWIFT_CACHE_HOLD_MARKER) continue;
|
|
3203
|
+
if (mirror === stagingRoot && entry === "configuration") continue;
|
|
3203
3204
|
const dest = path9.join(mirror, entry);
|
|
3204
3205
|
if (!fs3.lstatSync(dest, { throwIfNoEntry: false })) {
|
|
3205
3206
|
fs3.symlinkSync(path9.join(real, entry), dest);
|
|
@@ -3235,7 +3236,7 @@ function swiftSharedSdkViewOptions(moduleRoot, distribution, toolchainBin, sdk)
|
|
|
3235
3236
|
const stdint = path9.join(overlay, "include/stdint.h");
|
|
3236
3237
|
const key = JSON.stringify([
|
|
3237
3238
|
// bump the recipe when the transformation changes; bundling changes function text.
|
|
3238
|
-
"
|
|
3239
|
+
"v39",
|
|
3239
3240
|
[...WEAKEN_FOUNDATION_SYMS],
|
|
3240
3241
|
toolchainBin,
|
|
3241
3242
|
sdk,
|
|
@@ -4775,24 +4776,56 @@ function layout(bytes, readData = true, requireExports = true) {
|
|
|
4775
4776
|
const code = sections.get(10);
|
|
4776
4777
|
if (code) {
|
|
4777
4778
|
let pos = code[0];
|
|
4778
|
-
|
|
4779
|
-
|
|
4779
|
+
const codeStart = code[0];
|
|
4780
|
+
const codeEnd = code[1];
|
|
4781
|
+
let count = 0;
|
|
4782
|
+
{
|
|
4783
|
+
let shift = 0;
|
|
4784
|
+
for (; ; ) {
|
|
4785
|
+
if (pos >= codeEnd || shift > 28) throw new Error("invalid wasm integer");
|
|
4786
|
+
const byte = bytes[pos++];
|
|
4787
|
+
count += (byte & 127) * 2 ** shift;
|
|
4788
|
+
if (!(byte & 128)) break;
|
|
4789
|
+
shift += 7;
|
|
4790
|
+
}
|
|
4791
|
+
}
|
|
4780
4792
|
for (let i = 0; i < count; i++) {
|
|
4781
4793
|
const prefix = pos;
|
|
4782
|
-
let size;
|
|
4783
|
-
|
|
4784
|
-
|
|
4794
|
+
let size = 0;
|
|
4795
|
+
const b0 = bytes[pos++];
|
|
4796
|
+
if (b0 < 128) {
|
|
4797
|
+
size = b0;
|
|
4798
|
+
} else {
|
|
4799
|
+
size = b0 & 127;
|
|
4800
|
+
let shift = 7;
|
|
4801
|
+
for (; ; ) {
|
|
4802
|
+
if (pos >= codeEnd || shift > 28) throw new Error("invalid wasm integer");
|
|
4803
|
+
const byte = bytes[pos++];
|
|
4804
|
+
size += (byte & 127) * 2 ** shift;
|
|
4805
|
+
if (!(byte & 128)) break;
|
|
4806
|
+
shift += 7;
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4809
|
+
functionsByCodeOffset.set(prefix - codeStart, imports + i);
|
|
4785
4810
|
if (imports + i === startFunction) startup = bytes.subarray(pos, pos + size);
|
|
4786
4811
|
pos += size;
|
|
4787
|
-
if (pos >
|
|
4812
|
+
if (pos > codeEnd) throw new Error("invalid wasm code");
|
|
4788
4813
|
}
|
|
4789
|
-
if (pos !==
|
|
4814
|
+
if (pos !== codeEnd) throw new Error("invalid wasm code section");
|
|
4790
4815
|
}
|
|
4791
4816
|
const functionsByTableSlot = /* @__PURE__ */ new Map();
|
|
4792
4817
|
const elements = sections.get(9);
|
|
4793
4818
|
if (elements) {
|
|
4794
4819
|
let pos = elements[0];
|
|
4820
|
+
const elemEnd = elements[1];
|
|
4795
4821
|
const read = () => {
|
|
4822
|
+
if (pos < elemEnd) {
|
|
4823
|
+
const b0 = bytes[pos];
|
|
4824
|
+
if (b0 < 128) {
|
|
4825
|
+
pos++;
|
|
4826
|
+
return b0;
|
|
4827
|
+
}
|
|
4828
|
+
}
|
|
4796
4829
|
const [value, next] = number2(bytes, pos);
|
|
4797
4830
|
pos = next;
|
|
4798
4831
|
return value;
|
|
@@ -4822,7 +4855,7 @@ function layout(bytes, readData = true, requireExports = true) {
|
|
|
4822
4855
|
functionsByTableSlot.set(slot, read());
|
|
4823
4856
|
}
|
|
4824
4857
|
}
|
|
4825
|
-
if (pos !==
|
|
4858
|
+
if (pos !== elemEnd) throw new Error("invalid wasm element section");
|
|
4826
4859
|
}
|
|
4827
4860
|
const data = [];
|
|
4828
4861
|
const passive = /* @__PURE__ */ new Map();
|
|
@@ -4887,36 +4920,141 @@ function guestWasmDataSegments(bytes, requireExports = true) {
|
|
|
4887
4920
|
length: segment.bytes.length
|
|
4888
4921
|
}));
|
|
4889
4922
|
}
|
|
4890
|
-
function
|
|
4923
|
+
function isMapSpace(code) {
|
|
4924
|
+
return code === 32 || code >= 9 && code <= 13;
|
|
4925
|
+
}
|
|
4926
|
+
function isMapHex(code) {
|
|
4927
|
+
return code >= 48 && code <= 57 || code >= 97 && code <= 102;
|
|
4928
|
+
}
|
|
4929
|
+
function mapHexDigit(code) {
|
|
4930
|
+
return code <= 57 ? code - 48 : code - 87;
|
|
4931
|
+
}
|
|
4932
|
+
function* stringLines(text2) {
|
|
4933
|
+
let start = 0;
|
|
4934
|
+
for (let end = text2.indexOf("\n"); end !== -1; end = text2.indexOf("\n", start)) {
|
|
4935
|
+
yield text2.slice(start, end);
|
|
4936
|
+
start = end + 1;
|
|
4937
|
+
}
|
|
4938
|
+
yield text2.slice(start);
|
|
4939
|
+
}
|
|
4940
|
+
function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE__ */ new Map(), importsLayout = false, extra) {
|
|
4891
4941
|
const unchanged = before === after;
|
|
4892
4942
|
const original = layout(before, !unchanged, !importsLayout);
|
|
4893
4943
|
const optimized = unchanged ? original : layout(after, true, !importsLayout);
|
|
4944
|
+
const collectSymbols = extra?.collectSymbols;
|
|
4945
|
+
const trackedObject = extra?.trackedObject;
|
|
4946
|
+
const trackedObjectOwner = extra?.trackedObjectOwner;
|
|
4947
|
+
const trackedLinearSpans = extra?.trackedLinearSpans;
|
|
4948
|
+
const hasSectionOwners = sectionOwners.size > 0;
|
|
4894
4949
|
let codeOffset;
|
|
4895
4950
|
let outputSection = "";
|
|
4896
4951
|
const codeOwners = /* @__PURE__ */ new Map();
|
|
4897
4952
|
const pieces = [];
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4953
|
+
const lines = typeof map === "string" ? stringLines(map) : map;
|
|
4954
|
+
for (const line of lines) {
|
|
4955
|
+
const lineLen = line.length;
|
|
4956
|
+
let pos = 0;
|
|
4957
|
+
let onlySpaces = true;
|
|
4958
|
+
while (pos < lineLen) {
|
|
4959
|
+
const ch = line.charCodeAt(pos);
|
|
4960
|
+
if (!isMapSpace(ch)) break;
|
|
4961
|
+
if (ch !== 32) onlySpaces = false;
|
|
4962
|
+
pos++;
|
|
4963
|
+
}
|
|
4964
|
+
const leadingSpaces = pos;
|
|
4965
|
+
if (pos >= lineLen) continue;
|
|
4966
|
+
const addrStart = pos;
|
|
4967
|
+
while (pos < lineLen && !isMapSpace(line.charCodeAt(pos))) pos++;
|
|
4968
|
+
const addrEnd = pos;
|
|
4969
|
+
if (pos >= lineLen) continue;
|
|
4970
|
+
const s1 = pos;
|
|
4971
|
+
while (pos < lineLen) {
|
|
4972
|
+
const ch = line.charCodeAt(pos);
|
|
4973
|
+
if (!isMapSpace(ch)) break;
|
|
4974
|
+
if (ch !== 32) onlySpaces = false;
|
|
4975
|
+
pos++;
|
|
4976
|
+
}
|
|
4977
|
+
if (pos === s1 || pos >= lineLen) continue;
|
|
4978
|
+
const offStart = pos;
|
|
4979
|
+
let offsetVal = 0;
|
|
4980
|
+
while (pos < lineLen && isMapHex(line.charCodeAt(pos))) {
|
|
4981
|
+
offsetVal = offsetVal * 16 + mapHexDigit(line.charCodeAt(pos++));
|
|
4982
|
+
}
|
|
4983
|
+
if (pos === offStart || pos >= lineLen) continue;
|
|
4984
|
+
const s2 = pos;
|
|
4985
|
+
while (pos < lineLen) {
|
|
4986
|
+
const ch = line.charCodeAt(pos);
|
|
4987
|
+
if (!isMapSpace(ch)) break;
|
|
4988
|
+
if (ch !== 32) onlySpaces = false;
|
|
4989
|
+
pos++;
|
|
4990
|
+
}
|
|
4991
|
+
if (pos === s2 || pos >= lineLen) continue;
|
|
4992
|
+
const sizeStart = pos;
|
|
4993
|
+
let sizeVal = 0;
|
|
4994
|
+
while (pos < lineLen && isMapHex(line.charCodeAt(pos))) {
|
|
4995
|
+
sizeVal = sizeVal * 16 + mapHexDigit(line.charCodeAt(pos++));
|
|
4996
|
+
}
|
|
4997
|
+
if (pos === sizeStart || pos >= lineLen) continue;
|
|
4998
|
+
const indentStart = pos;
|
|
4999
|
+
while (pos < lineLen && line.charCodeAt(pos) === 32) pos++;
|
|
5000
|
+
const indentLen = pos - indentStart;
|
|
5001
|
+
if (indentLen === 0 || pos >= lineLen) continue;
|
|
5002
|
+
const firstCh = line.charCodeAt(pos);
|
|
5003
|
+
if (isMapSpace(firstCh)) continue;
|
|
5004
|
+
const sourceStart = pos;
|
|
5005
|
+
if (collectSymbols && onlySpaces && leadingSpaces > 0 && indentLen >= 9 && firstCh !== 47 && firstCh !== 60) {
|
|
5006
|
+
let symEnd = sourceStart + 1;
|
|
5007
|
+
while (symEnd < lineLen && !isMapSpace(line.charCodeAt(symEnd))) symEnd++;
|
|
5008
|
+
collectSymbols.add(line.slice(sourceStart, symEnd));
|
|
5009
|
+
}
|
|
5010
|
+
const isDash = addrEnd - addrStart === 1 && line.charCodeAt(addrStart) === 45;
|
|
5011
|
+
if (isDash && indentLen === 1) {
|
|
5012
|
+
if (line.indexOf("\r", sourceStart) >= 0) continue;
|
|
5013
|
+
outputSection = line.slice(sourceStart);
|
|
5014
|
+
if (outputSection === "CODE") codeOffset = offsetVal;
|
|
4905
5015
|
continue;
|
|
4906
5016
|
}
|
|
4907
|
-
|
|
5017
|
+
if (sizeVal === 0) continue;
|
|
5018
|
+
const separator = line.indexOf(":(", sourceStart);
|
|
4908
5019
|
if (separator < 0) continue;
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
if (
|
|
4914
|
-
|
|
5020
|
+
if (line.indexOf("\r", sourceStart) >= 0) continue;
|
|
5021
|
+
let hasLineSep = false;
|
|
5022
|
+
for (let i = sourceStart; i < lineLen; i++) {
|
|
5023
|
+
const ch = line.charCodeAt(i);
|
|
5024
|
+
if (ch === 8232 || ch === 8233) {
|
|
5025
|
+
hasLineSep = true;
|
|
5026
|
+
break;
|
|
5027
|
+
}
|
|
5028
|
+
}
|
|
5029
|
+
if (hasLineSep) continue;
|
|
5030
|
+
const objectPath = line.slice(sourceStart, separator);
|
|
5031
|
+
let image = hasSectionOwners ? sectionOwners.get(line.slice(sourceStart)) : void 0;
|
|
5032
|
+
if (image === void 0) image = owners.get(objectPath);
|
|
5033
|
+
if (!isDash) {
|
|
5034
|
+
if (outputSection === "DATA") {
|
|
5035
|
+
let addressVal = 0;
|
|
5036
|
+
let allHex = true;
|
|
5037
|
+
for (let i = addrStart; i < addrEnd; i++) {
|
|
5038
|
+
const ch = line.charCodeAt(i);
|
|
5039
|
+
if (isMapHex(ch)) addressVal = addressVal * 16 + mapHexDigit(ch);
|
|
5040
|
+
else {
|
|
5041
|
+
allHex = false;
|
|
5042
|
+
break;
|
|
5043
|
+
}
|
|
5044
|
+
}
|
|
5045
|
+
if (!allHex) addressVal = parseInt(line.slice(addrStart, addrEnd), 16);
|
|
5046
|
+
pieces.push({
|
|
5047
|
+
image,
|
|
5048
|
+
address: addressVal,
|
|
5049
|
+
length: sizeVal,
|
|
5050
|
+
tracked: trackedObject !== void 0 && objectPath === trackedObject
|
|
5051
|
+
});
|
|
5052
|
+
}
|
|
4915
5053
|
continue;
|
|
4916
5054
|
}
|
|
4917
5055
|
if (image === void 0 || outputSection !== "CODE") continue;
|
|
4918
5056
|
if (codeOffset === void 0) throw new Error("link map has no code section");
|
|
4919
|
-
const index = original.functionsByCodeOffset.get(
|
|
5057
|
+
const index = original.functionsByCodeOffset.get(offsetVal - codeOffset);
|
|
4920
5058
|
if (index === void 0) throw new Error("link map function has no wasm body");
|
|
4921
5059
|
const existing = codeOwners.get(index);
|
|
4922
5060
|
if (existing !== void 0 && existing !== image)
|
|
@@ -4925,12 +5063,23 @@ function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE
|
|
|
4925
5063
|
}
|
|
4926
5064
|
pieces.sort((a, b) => a.address - b.address);
|
|
4927
5065
|
const spans = [];
|
|
4928
|
-
for (
|
|
4929
|
-
|
|
5066
|
+
for (let index = 0; index < pieces.length; index++) {
|
|
5067
|
+
const piece = pieces[index];
|
|
5068
|
+
const { image, address, length, tracked } = piece;
|
|
5069
|
+
if (image === void 0 && !tracked) continue;
|
|
4930
5070
|
let next = index + 1;
|
|
4931
5071
|
while (next < pieces.length && pieces[next].address < address + length) next++;
|
|
4932
5072
|
const end = pieces[next]?.address ?? address + length;
|
|
4933
|
-
|
|
5073
|
+
const spanLength = end - address;
|
|
5074
|
+
if (image !== void 0)
|
|
5075
|
+
spans.push({ image, space: "linear-memory", address, length: spanLength });
|
|
5076
|
+
if (tracked && trackedLinearSpans && trackedObjectOwner !== void 0)
|
|
5077
|
+
trackedLinearSpans.push({
|
|
5078
|
+
image: trackedObjectOwner,
|
|
5079
|
+
space: "linear-memory",
|
|
5080
|
+
address,
|
|
5081
|
+
length: spanLength
|
|
5082
|
+
});
|
|
4934
5083
|
}
|
|
4935
5084
|
const optimizedOwners = /* @__PURE__ */ new Map();
|
|
4936
5085
|
const dataAt = (module, start, length) => {
|
|
@@ -4969,7 +5118,7 @@ function guestLinkedSpans(map, before, after, owners, sectionOwners = /* @__PURE
|
|
|
4969
5118
|
throw new Error(`optimization changed linked data at ${span.address}`);
|
|
4970
5119
|
}
|
|
4971
5120
|
let previous;
|
|
4972
|
-
for (const span of
|
|
5121
|
+
for (const span of spans) {
|
|
4973
5122
|
if (previous && span.address < previous.address + previous.length && span.image !== previous.image)
|
|
4974
5123
|
throw new Error("linked data belongs to multiple images");
|
|
4975
5124
|
if (!previous || span.address + span.length > previous.address + previous.length)
|
|
@@ -5156,6 +5305,20 @@ var PARTITIONED = [
|
|
|
5156
5305
|
];
|
|
5157
5306
|
var chunkKey = (chunk, symbol = chunk.symbols[0]?.name ?? "") => `${chunk.object}:${chunk.section}:${symbol}`;
|
|
5158
5307
|
var isPartitioned = (section2) => PARTITIONED.some((name) => section2 === name || section2.startsWith(`${name}.`));
|
|
5308
|
+
function isHexChar(code) {
|
|
5309
|
+
return code >= 48 && code <= 57 || code >= 97 && code <= 102;
|
|
5310
|
+
}
|
|
5311
|
+
function hexDigit(code) {
|
|
5312
|
+
return code <= 57 ? code - 48 : code - 87;
|
|
5313
|
+
}
|
|
5314
|
+
function hasLineBreak(line, from) {
|
|
5315
|
+
if (line.indexOf("\r", from) >= 0) return true;
|
|
5316
|
+
for (let i = from; i < line.length; i++) {
|
|
5317
|
+
const ch = line.charCodeAt(i);
|
|
5318
|
+
if (ch === 8232 || ch === 8233) return true;
|
|
5319
|
+
}
|
|
5320
|
+
return false;
|
|
5321
|
+
}
|
|
5159
5322
|
function readWasmLinkMap(file, partition) {
|
|
5160
5323
|
const segments = /* @__PURE__ */ new Map();
|
|
5161
5324
|
const data = [];
|
|
@@ -5163,48 +5326,117 @@ function readWasmLinkMap(file, partition) {
|
|
|
5163
5326
|
let kind = "";
|
|
5164
5327
|
let segment = "";
|
|
5165
5328
|
let previous;
|
|
5166
|
-
const hex = (value) => value === "-" ? -1 : parseInt(value, 16);
|
|
5167
5329
|
for (const line of guestLinkLines(file)) {
|
|
5168
|
-
const
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5330
|
+
const length = line.length;
|
|
5331
|
+
let pos = 0;
|
|
5332
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
5333
|
+
if (pos >= length) continue;
|
|
5334
|
+
const leadingSpaces = pos;
|
|
5335
|
+
let address = -1;
|
|
5336
|
+
if (line.charCodeAt(pos) === 45) {
|
|
5337
|
+
pos++;
|
|
5338
|
+
} else {
|
|
5339
|
+
const start = pos;
|
|
5340
|
+
let value = 0;
|
|
5341
|
+
while (pos < length && isHexChar(line.charCodeAt(pos))) {
|
|
5342
|
+
value = value * 16 + hexDigit(line.charCodeAt(pos++));
|
|
5343
|
+
}
|
|
5344
|
+
if (pos === start) continue;
|
|
5345
|
+
address = value;
|
|
5346
|
+
}
|
|
5347
|
+
const s1 = pos;
|
|
5348
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
5349
|
+
if (pos === s1 || pos >= length) continue;
|
|
5350
|
+
const offStart = pos;
|
|
5351
|
+
let offset = 0;
|
|
5352
|
+
while (pos < length && isHexChar(line.charCodeAt(pos))) {
|
|
5353
|
+
offset = offset * 16 + hexDigit(line.charCodeAt(pos++));
|
|
5354
|
+
}
|
|
5355
|
+
if (pos === offStart) continue;
|
|
5356
|
+
const s2 = pos;
|
|
5357
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
5358
|
+
if (pos === s2 || pos >= length) continue;
|
|
5359
|
+
const sizeStart = pos;
|
|
5360
|
+
let size = 0;
|
|
5361
|
+
while (pos < length && isHexChar(line.charCodeAt(pos))) {
|
|
5362
|
+
size = size * 16 + hexDigit(line.charCodeAt(pos++));
|
|
5363
|
+
}
|
|
5364
|
+
if (pos === sizeStart || pos >= length) continue;
|
|
5365
|
+
const indentStart = pos;
|
|
5366
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
5367
|
+
const indent = pos - indentStart;
|
|
5368
|
+
if (indent === 0 || pos >= length) continue;
|
|
5369
|
+
if (indent === 17) {
|
|
5370
|
+
if (previous) {
|
|
5371
|
+
const first = line.charCodeAt(pos);
|
|
5372
|
+
if (first > 32 && !hasLineBreak(line, pos)) {
|
|
5373
|
+
previous.symbols.push({
|
|
5374
|
+
name: line.slice(pos),
|
|
5375
|
+
address,
|
|
5376
|
+
size
|
|
5377
|
+
});
|
|
5378
|
+
}
|
|
5379
|
+
}
|
|
5175
5380
|
continue;
|
|
5176
5381
|
}
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5382
|
+
if (indent === 1) {
|
|
5383
|
+
let hasWhitespace = false;
|
|
5384
|
+
for (let i = pos; i < length; i++) {
|
|
5385
|
+
const ch = line.charCodeAt(i);
|
|
5386
|
+
if (ch <= 32) {
|
|
5387
|
+
hasWhitespace = true;
|
|
5388
|
+
break;
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
if (hasWhitespace) continue;
|
|
5392
|
+
if (address < 0 && leadingSpaces > 0) {
|
|
5393
|
+
kind = line.slice(pos);
|
|
5394
|
+
} else if (kind === "DATA" && address >= 0) {
|
|
5395
|
+
segment = line.slice(pos);
|
|
5396
|
+
segments.set(segment, { address, size });
|
|
5397
|
+
}
|
|
5180
5398
|
continue;
|
|
5181
5399
|
}
|
|
5182
|
-
if (kind === "DATA") {
|
|
5183
|
-
const
|
|
5184
|
-
if (
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5400
|
+
if (indent === 9 && (kind === "DATA" || kind === "CODE")) {
|
|
5401
|
+
const first = line.charCodeAt(pos);
|
|
5402
|
+
if (first !== 47 && first !== 60) continue;
|
|
5403
|
+
if (hasLineBreak(line, pos)) continue;
|
|
5404
|
+
const name = line.slice(pos);
|
|
5405
|
+
let filePath = name;
|
|
5406
|
+
let section2 = "";
|
|
5407
|
+
if (name.charCodeAt(name.length - 1) === 41) {
|
|
5408
|
+
const splitAt = name.indexOf(":(");
|
|
5409
|
+
if (splitAt >= 0) {
|
|
5410
|
+
filePath = name.slice(0, splitAt);
|
|
5411
|
+
section2 = name.slice(splitAt + 2, -1);
|
|
5412
|
+
}
|
|
5188
5413
|
}
|
|
5414
|
+
let objectName;
|
|
5415
|
+
if (filePath.charCodeAt(filePath.length - 1) === 41) {
|
|
5416
|
+
const open = filePath.lastIndexOf("(");
|
|
5417
|
+
if (open >= 0 && open + 1 < filePath.length - 1) {
|
|
5418
|
+
const close = filePath.indexOf(")", open + 1);
|
|
5419
|
+
if (close === filePath.length - 1) {
|
|
5420
|
+
objectName = filePath.slice(open + 1, -1);
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
}
|
|
5424
|
+
if (objectName === void 0) objectName = basename(filePath);
|
|
5425
|
+
if (objectName.startsWith("lib") && objectName.includes("__")) {
|
|
5426
|
+
objectName = objectName.replace(/^lib\w*?__/, "");
|
|
5427
|
+
}
|
|
5428
|
+
previous = {
|
|
5429
|
+
inputFile: filePath,
|
|
5430
|
+
segment,
|
|
5431
|
+
address,
|
|
5432
|
+
offset,
|
|
5433
|
+
size,
|
|
5434
|
+
object: objectName,
|
|
5435
|
+
section: section2,
|
|
5436
|
+
symbols: []
|
|
5437
|
+
};
|
|
5438
|
+
(kind === "DATA" ? data : code).push(previous);
|
|
5189
5439
|
}
|
|
5190
|
-
if (kind !== "DATA" && kind !== "CODE") continue;
|
|
5191
|
-
const input = /^ *([0-9a-f]+|-) +([0-9a-f]+) +([0-9a-f]+) {9}([/<].*)$/.exec(line);
|
|
5192
|
-
if (!input) continue;
|
|
5193
|
-
const name = input[4];
|
|
5194
|
-
const split = /^(.*?):\((.*)\)$/s.exec(name);
|
|
5195
|
-
const path33 = split ? split[1] : name;
|
|
5196
|
-
const member = /\(([^()]+)\)$/.exec(path33);
|
|
5197
|
-
previous = {
|
|
5198
|
-
inputFile: path33,
|
|
5199
|
-
segment,
|
|
5200
|
-
address: hex(input[1]),
|
|
5201
|
-
offset: parseInt(input[2], 16),
|
|
5202
|
-
size: parseInt(input[3], 16),
|
|
5203
|
-
object: (member ? member[1] : basename(path33)).replace(/^lib\w*?__/, ""),
|
|
5204
|
-
section: split ? split[2] : "",
|
|
5205
|
-
symbols: []
|
|
5206
|
-
};
|
|
5207
|
-
(kind === "DATA" ? data : code).push(previous);
|
|
5208
5440
|
}
|
|
5209
5441
|
return { segments, data: partition ? data.flatMap(symbolPieces) : data, code };
|
|
5210
5442
|
}
|
|
@@ -6374,6 +6606,7 @@ function patchSwiftrtObject(src) {
|
|
|
6374
6606
|
return buf;
|
|
6375
6607
|
}
|
|
6376
6608
|
function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
6609
|
+
const rawBuf = Buffer.isBuffer(buf) ? buf : Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
6377
6610
|
let pos = 8;
|
|
6378
6611
|
let numImportFuncs = 0;
|
|
6379
6612
|
let importsDlsym = false;
|
|
@@ -6409,10 +6642,10 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
|
6409
6642
|
let [cnt, cp] = readULEB2(buf, p);
|
|
6410
6643
|
for (let i = 0; i < cnt; i++) {
|
|
6411
6644
|
const [mLen, m2] = readULEB2(buf, cp);
|
|
6412
|
-
const mName =
|
|
6645
|
+
const mName = rawBuf.toString("utf8", m2, m2 + mLen);
|
|
6413
6646
|
cp = m2 + mLen;
|
|
6414
6647
|
const [fLen, f2] = readULEB2(buf, cp);
|
|
6415
|
-
const fName =
|
|
6648
|
+
const fName = rawBuf.toString("utf8", f2, f2 + fLen);
|
|
6416
6649
|
cp = f2 + fLen;
|
|
6417
6650
|
const kind = buf[cp++];
|
|
6418
6651
|
if (kind === 0) {
|
|
@@ -6492,7 +6725,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
|
6492
6725
|
}
|
|
6493
6726
|
} else if (id === 0) {
|
|
6494
6727
|
const [nLen, np] = readULEB2(buf, p);
|
|
6495
|
-
const name =
|
|
6728
|
+
const name = rawBuf.toString("utf8", np, np + nLen);
|
|
6496
6729
|
const cp = np + nLen;
|
|
6497
6730
|
if (name === "linking") {
|
|
6498
6731
|
let [, lp] = readULEB2(buf, cp);
|
|
@@ -6505,7 +6738,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
|
6505
6738
|
let cur = p2;
|
|
6506
6739
|
for (let i = 0; i < cnt; i++) {
|
|
6507
6740
|
const [sLen, s2] = readULEB2(buf, cur);
|
|
6508
|
-
segNames.push(
|
|
6741
|
+
segNames.push(rawBuf.toString("utf8", s2, s2 + sLen));
|
|
6509
6742
|
cur = s2 + sLen;
|
|
6510
6743
|
const [, s3] = readULEB2(buf, cur);
|
|
6511
6744
|
const [fl, s4] = readULEB2(buf, s3);
|
|
@@ -6545,7 +6778,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
|
6545
6778
|
let sName = "";
|
|
6546
6779
|
if (!isUndef || isExplicitName) {
|
|
6547
6780
|
const [sLen, c4] = readULEB2(buf, cur);
|
|
6548
|
-
sName =
|
|
6781
|
+
sName = rawBuf.toString("utf8", c4, c4 + sLen);
|
|
6549
6782
|
cur = c4 + sLen;
|
|
6550
6783
|
} else if (kind === 0) {
|
|
6551
6784
|
sName = importFuncNames[el] ?? "";
|
|
@@ -6561,7 +6794,7 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
|
6561
6794
|
symNames.push(sName);
|
|
6562
6795
|
} else if (kind === 1) {
|
|
6563
6796
|
const [sLen, c3] = readULEB2(buf, cur);
|
|
6564
|
-
const sName =
|
|
6797
|
+
const sName = rawBuf.toString("utf8", c3, c3 + sLen);
|
|
6565
6798
|
cur = c3 + sLen;
|
|
6566
6799
|
if (!isUndef) {
|
|
6567
6800
|
const [segIdx, c4] = readULEB2(buf, cur);
|
|
@@ -6676,9 +6909,21 @@ function parseWasmObjectBytes(file, buf, isDist, symbolFlagOffsets) {
|
|
|
6676
6909
|
const offInSeg = ro - (sPayloadStarts[lo] ?? 0);
|
|
6677
6910
|
let ownerSymIdx = -1;
|
|
6678
6911
|
const topList = segTopSyms.get(lo);
|
|
6679
|
-
if (topList) {
|
|
6680
|
-
|
|
6681
|
-
|
|
6912
|
+
if (topList && topList.length > 0) {
|
|
6913
|
+
let tLo = 0;
|
|
6914
|
+
let tHi = topList.length - 1;
|
|
6915
|
+
while (tLo <= tHi) {
|
|
6916
|
+
const tMid = tLo + tHi >> 1;
|
|
6917
|
+
const top = topList[tMid];
|
|
6918
|
+
if (offInSeg < top.off) {
|
|
6919
|
+
tHi = tMid - 1;
|
|
6920
|
+
} else if (offInSeg >= top.end) {
|
|
6921
|
+
tLo = tMid + 1;
|
|
6922
|
+
} else {
|
|
6923
|
+
ownerSymIdx = top.symIdx;
|
|
6924
|
+
break;
|
|
6925
|
+
}
|
|
6926
|
+
}
|
|
6682
6927
|
}
|
|
6683
6928
|
if (ownerSymIdx !== -1) {
|
|
6684
6929
|
let list = symDataRelocs.get(ownerSymIdx);
|
|
@@ -6916,54 +7161,151 @@ function parseWasmObjectCached(file, isDist, entries2) {
|
|
|
6916
7161
|
return parsed;
|
|
6917
7162
|
}
|
|
6918
7163
|
function guestWasmSymbols(bytes) {
|
|
6919
|
-
const
|
|
7164
|
+
const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
7165
|
+
let cur = 8;
|
|
7166
|
+
const readU = () => {
|
|
7167
|
+
const b0 = bytes[cur++];
|
|
7168
|
+
if (b0 < 128) return b0;
|
|
7169
|
+
let res = b0 & 127;
|
|
7170
|
+
let shift = 7;
|
|
7171
|
+
while (true) {
|
|
7172
|
+
const byte = bytes[cur++];
|
|
7173
|
+
res |= (byte & 127) << shift;
|
|
7174
|
+
if ((byte & 128) === 0) return res;
|
|
7175
|
+
shift += 7;
|
|
7176
|
+
}
|
|
7177
|
+
};
|
|
7178
|
+
let importsDlsym = false;
|
|
7179
|
+
const importFuncNames = [];
|
|
7180
|
+
const importFuncModules = [];
|
|
7181
|
+
const importGlobalNames = [];
|
|
7182
|
+
const importTableNames = [];
|
|
7183
|
+
const importEventNames = [];
|
|
7184
|
+
const undefinedSyms = /* @__PURE__ */ new Set();
|
|
7185
|
+
const tags = /* @__PURE__ */ new Set();
|
|
7186
|
+
const globals = /* @__PURE__ */ new Set();
|
|
7187
|
+
const hostImports = /* @__PURE__ */ new Set();
|
|
7188
|
+
const weakUndefined = /* @__PURE__ */ new Set();
|
|
7189
|
+
const defined = /* @__PURE__ */ new Set();
|
|
7190
|
+
const weakDefined = /* @__PURE__ */ new Set();
|
|
7191
|
+
while (cur < bytes.length) {
|
|
7192
|
+
const id = bytes[cur++];
|
|
7193
|
+
const sz = readU();
|
|
7194
|
+
const end = cur + sz;
|
|
7195
|
+
if (id === 2) {
|
|
7196
|
+
const cnt = readU();
|
|
7197
|
+
for (let i = 0; i < cnt; i++) {
|
|
7198
|
+
const mLen = readU();
|
|
7199
|
+
const mName = rawBuf.toString("utf8", cur, cur + mLen);
|
|
7200
|
+
cur += mLen;
|
|
7201
|
+
const fLen = readU();
|
|
7202
|
+
const fName = rawBuf.toString("utf8", cur, cur + fLen);
|
|
7203
|
+
cur += fLen;
|
|
7204
|
+
const kind = bytes[cur++];
|
|
7205
|
+
if (kind === 0) {
|
|
7206
|
+
readU();
|
|
7207
|
+
importFuncNames.push(fName);
|
|
7208
|
+
importFuncModules.push(mName);
|
|
7209
|
+
if (mName === "env" && fName === "dlsym") importsDlsym = true;
|
|
7210
|
+
} else if (kind === 1) {
|
|
7211
|
+
cur++;
|
|
7212
|
+
const fl = readU();
|
|
7213
|
+
readU();
|
|
7214
|
+
if (fl & 1) readU();
|
|
7215
|
+
importTableNames.push(fName);
|
|
7216
|
+
} else if (kind === 2) {
|
|
7217
|
+
const fl = readU();
|
|
7218
|
+
readU();
|
|
7219
|
+
if (fl & 1) readU();
|
|
7220
|
+
} else if (kind === 3) {
|
|
7221
|
+
cur += 2;
|
|
7222
|
+
importGlobalNames.push(fName);
|
|
7223
|
+
} else if (kind === 4) {
|
|
7224
|
+
cur++;
|
|
7225
|
+
readU();
|
|
7226
|
+
importEventNames.push(fName);
|
|
7227
|
+
}
|
|
7228
|
+
}
|
|
7229
|
+
} else if (id === 0) {
|
|
7230
|
+
const nLen = readU();
|
|
7231
|
+
if (nLen === 7 && bytes[cur] === 108 && rawBuf.toString("utf8", cur, cur + nLen) === "linking") {
|
|
7232
|
+
cur += nLen;
|
|
7233
|
+
readU();
|
|
7234
|
+
while (cur < end) {
|
|
7235
|
+
const subId = bytes[cur++];
|
|
7236
|
+
const subLen = readU();
|
|
7237
|
+
const subEnd = cur + subLen;
|
|
7238
|
+
if (subId === 8) {
|
|
7239
|
+
const cnt = readU();
|
|
7240
|
+
for (let i = 0; i < cnt; i++) {
|
|
7241
|
+
const kind = bytes[cur++];
|
|
7242
|
+
const fl = readU();
|
|
7243
|
+
const isUndef = (fl & 16) !== 0;
|
|
7244
|
+
const isExplicitName = (fl & 64) !== 0;
|
|
7245
|
+
let sName = "";
|
|
7246
|
+
if (kind === 0 || kind === 2 || kind === 4 || kind === 5) {
|
|
7247
|
+
const el = readU();
|
|
7248
|
+
if (!isUndef || isExplicitName) {
|
|
7249
|
+
const sLen = readU();
|
|
7250
|
+
sName = rawBuf.toString("utf8", cur, cur + sLen);
|
|
7251
|
+
cur += sLen;
|
|
7252
|
+
} else if (kind === 0) {
|
|
7253
|
+
sName = importFuncNames[el] ?? "";
|
|
7254
|
+
} else if (kind === 2) {
|
|
7255
|
+
sName = importGlobalNames[el] ?? "";
|
|
7256
|
+
} else if (kind === 4) {
|
|
7257
|
+
sName = importEventNames[el] ?? "";
|
|
7258
|
+
} else if (kind === 5) {
|
|
7259
|
+
sName = importTableNames[el] ?? "";
|
|
7260
|
+
}
|
|
7261
|
+
if (isUndef && kind === 0 && importFuncModules[el] !== "env")
|
|
7262
|
+
hostImports.add(sName);
|
|
7263
|
+
} else if (kind === 1) {
|
|
7264
|
+
const sLen = readU();
|
|
7265
|
+
sName = rawBuf.toString("utf8", cur, cur + sLen);
|
|
7266
|
+
cur += sLen;
|
|
7267
|
+
if (!isUndef) {
|
|
7268
|
+
readU();
|
|
7269
|
+
readU();
|
|
7270
|
+
readU();
|
|
7271
|
+
}
|
|
7272
|
+
} else if (kind === 3) {
|
|
7273
|
+
readU();
|
|
7274
|
+
}
|
|
7275
|
+
if (sName) {
|
|
7276
|
+
if (isUndef) {
|
|
7277
|
+
undefinedSyms.add(sName);
|
|
7278
|
+
if ((fl & 19) === 17) weakUndefined.add(sName);
|
|
7279
|
+
} else if ((fl & 3) !== 2) {
|
|
7280
|
+
defined.add(sName);
|
|
7281
|
+
if ((fl & 19) === 1) weakDefined.add(sName);
|
|
7282
|
+
}
|
|
7283
|
+
if (kind === 4) tags.add(sName);
|
|
7284
|
+
else if (kind === 2 || kind === 5) globals.add(sName);
|
|
7285
|
+
}
|
|
7286
|
+
}
|
|
7287
|
+
break;
|
|
7288
|
+
}
|
|
7289
|
+
cur = subEnd;
|
|
7290
|
+
}
|
|
7291
|
+
break;
|
|
7292
|
+
}
|
|
7293
|
+
}
|
|
7294
|
+
cur = end;
|
|
7295
|
+
}
|
|
6920
7296
|
return {
|
|
6921
|
-
importsDlsym
|
|
6922
|
-
undefined: [
|
|
6923
|
-
...new Set(
|
|
6924
|
-
object2.symNames.filter(
|
|
6925
|
-
(name, index) => name && (object2.symFlags[index] & 16) !== 0
|
|
6926
|
-
)
|
|
6927
|
-
)
|
|
6928
|
-
],
|
|
7297
|
+
importsDlsym,
|
|
7298
|
+
undefined: [...undefinedSyms],
|
|
6929
7299
|
// a wasm tag is one module entity unified by name across the link, as the
|
|
6930
7300
|
// main module owns it for dynamic images, so no image scope applies.
|
|
6931
|
-
tags: [
|
|
6932
|
-
|
|
6933
|
-
object2.symNames.filter((name, index) => name && object2.symKind[index] === 4)
|
|
6934
|
-
)
|
|
6935
|
-
],
|
|
6936
|
-
globals: [
|
|
6937
|
-
...new Set(
|
|
6938
|
-
object2.symNames.filter(
|
|
6939
|
-
(name, index) => name && (object2.symKind[index] === 2 || object2.symKind[index] === 5)
|
|
6940
|
-
)
|
|
6941
|
-
)
|
|
6942
|
-
],
|
|
7301
|
+
tags: [...tags],
|
|
7302
|
+
globals: [...globals],
|
|
6943
7303
|
// an undefined function imported from a module other than env is supplied
|
|
6944
7304
|
// by the host, whatever linker symbol names it.
|
|
6945
|
-
hostImports: [...
|
|
6946
|
-
weakUndefined: [
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
(name, index) => name && (object2.symFlags[index] & 19) === 17
|
|
6950
|
-
)
|
|
6951
|
-
)
|
|
6952
|
-
],
|
|
6953
|
-
defined: [
|
|
6954
|
-
...new Set(
|
|
6955
|
-
object2.symNames.filter(
|
|
6956
|
-
(name, index) => name && (object2.symFlags[index] & 16) === 0 && (object2.symFlags[index] & 3) !== 2
|
|
6957
|
-
)
|
|
6958
|
-
)
|
|
6959
|
-
],
|
|
6960
|
-
weakDefined: [
|
|
6961
|
-
...new Set(
|
|
6962
|
-
object2.symNames.filter(
|
|
6963
|
-
(name, index) => name && (object2.symFlags[index] & 19) === 1
|
|
6964
|
-
)
|
|
6965
|
-
)
|
|
6966
|
-
]
|
|
7305
|
+
hostImports: [...hostImports],
|
|
7306
|
+
weakUndefined: [...weakUndefined],
|
|
7307
|
+
defined: [...defined],
|
|
7308
|
+
weakDefined: [...weakDefined]
|
|
6967
7309
|
};
|
|
6968
7310
|
}
|
|
6969
7311
|
function sdkObjectName(archive, member, ordinal) {
|
|
@@ -7494,9 +7836,12 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
|
|
|
7494
7836
|
for (const entry of waiting) tryActivateConformance(entry);
|
|
7495
7837
|
}
|
|
7496
7838
|
};
|
|
7839
|
+
const checkedProtocolTriggers = /* @__PURE__ */ new Set();
|
|
7497
7840
|
const checkProtocolTrigger = (rawSymName) => {
|
|
7498
7841
|
if (!rawSymName) return;
|
|
7499
7842
|
const sName = rawSymName.startsWith(".Lgot.") ? rawSymName.slice(6) : rawSymName;
|
|
7843
|
+
if (checkedProtocolTriggers.has(sName)) return;
|
|
7844
|
+
checkedProtocolTriggers.add(sName);
|
|
7500
7845
|
if (knownProtocols.has(sName)) {
|
|
7501
7846
|
markProtocolLive(sName);
|
|
7502
7847
|
return;
|
|
@@ -7529,6 +7874,43 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
|
|
|
7529
7874
|
}
|
|
7530
7875
|
}
|
|
7531
7876
|
};
|
|
7877
|
+
const typeIndexes = /* @__PURE__ */ new Map();
|
|
7878
|
+
const getTypeIndex = (obj) => {
|
|
7879
|
+
let idx = typeIndexes.get(obj);
|
|
7880
|
+
if (idx) return idx;
|
|
7881
|
+
const mnByPrefix = /* @__PURE__ */ new Map();
|
|
7882
|
+
for (let i = 0; i < obj.symNames.length; i++) {
|
|
7883
|
+
const name = obj.symNames[i];
|
|
7884
|
+
if ((obj.symFlags[i] & 16) === 0 && name.startsWith("$s") && name.endsWith("Mn")) {
|
|
7885
|
+
const pref = name.slice(0, -2);
|
|
7886
|
+
let list = mnByPrefix.get(pref);
|
|
7887
|
+
if (!list) mnByPrefix.set(pref, list = []);
|
|
7888
|
+
list.push(i);
|
|
7889
|
+
}
|
|
7890
|
+
}
|
|
7891
|
+
const objcRegByPrefix = /* @__PURE__ */ new Map();
|
|
7892
|
+
for (const [lf, p] of obj.objcRegisterFuncToTypePrefix) {
|
|
7893
|
+
let list = objcRegByPrefix.get(p);
|
|
7894
|
+
if (!list) objcRegByPrefix.set(p, list = []);
|
|
7895
|
+
list.push(lf);
|
|
7896
|
+
}
|
|
7897
|
+
const objcClassByPrefix = /* @__PURE__ */ new Map();
|
|
7898
|
+
for (const [classSym, p] of obj.objcClassSymToTypePrefix) {
|
|
7899
|
+
if (!classSym.startsWith("._OBJC_CLASS_")) continue;
|
|
7900
|
+
let list = objcClassByPrefix.get(p);
|
|
7901
|
+
if (!list) objcClassByPrefix.set(p, list = []);
|
|
7902
|
+
list.push(classSym.slice("._OBJC_CLASS_".length));
|
|
7903
|
+
}
|
|
7904
|
+
let minPrefLen = Infinity;
|
|
7905
|
+
let maxPrefLen = 0;
|
|
7906
|
+
for (const p of obj.typePrefixesInObj) {
|
|
7907
|
+
if (p.length < minPrefLen) minPrefLen = p.length;
|
|
7908
|
+
if (p.length > maxPrefLen) maxPrefLen = p.length;
|
|
7909
|
+
}
|
|
7910
|
+
idx = { mnByPrefix, objcRegByPrefix, objcClassByPrefix, minPrefLen, maxPrefLen };
|
|
7911
|
+
typeIndexes.set(obj, idx);
|
|
7912
|
+
return idx;
|
|
7913
|
+
};
|
|
7532
7914
|
const markTypeLive = (obj, pref) => {
|
|
7533
7915
|
const set = liveTypes.get(obj);
|
|
7534
7916
|
if (set.has(pref)) return;
|
|
@@ -7542,22 +7924,10 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
|
|
|
7542
7924
|
const outer = pref.slice(0, n);
|
|
7543
7925
|
if (obj.typePrefixesInObj.has(outer)) markTypeLive(obj, outer);
|
|
7544
7926
|
}
|
|
7545
|
-
const
|
|
7546
|
-
for (
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
}
|
|
7550
|
-
}
|
|
7551
|
-
for (const [lf, p] of obj.objcRegisterFuncToTypePrefix) {
|
|
7552
|
-
if (p === pref) {
|
|
7553
|
-
markFuncLive(obj, lf);
|
|
7554
|
-
}
|
|
7555
|
-
}
|
|
7556
|
-
for (const [classSym, p] of obj.objcClassSymToTypePrefix) {
|
|
7557
|
-
if (p === pref && classSym.startsWith("._OBJC_CLASS_")) {
|
|
7558
|
-
markObjCClassLive(classSym.slice("._OBJC_CLASS_".length));
|
|
7559
|
-
}
|
|
7560
|
-
}
|
|
7927
|
+
const idx = getTypeIndex(obj);
|
|
7928
|
+
for (const i of idx.mnByPrefix.get(pref) ?? []) activateSymbolInObj(obj, i);
|
|
7929
|
+
for (const lf of idx.objcRegByPrefix.get(pref) ?? []) markFuncLive(obj, lf);
|
|
7930
|
+
for (const cls of idx.objcClassByPrefix.get(pref) ?? []) markObjCClassLive(cls);
|
|
7561
7931
|
};
|
|
7562
7932
|
const checkTypeTrigger = (obj, rawSymName) => {
|
|
7563
7933
|
if (!rawSymName) return;
|
|
@@ -7582,11 +7952,12 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
|
|
|
7582
7952
|
}
|
|
7583
7953
|
}
|
|
7584
7954
|
}
|
|
7585
|
-
if (obj.file.endsWith("libswiftCore__Swift.o") || obj.file.endsWith("libswift_Concurrency___Concurrency.o")) {
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7955
|
+
if (obj.typePrefixesInObj.size > 0 && (obj.file.endsWith("libswiftCore__Swift.o") || obj.file.endsWith("libswift_Concurrency___Concurrency.o"))) {
|
|
7956
|
+
const { minPrefLen, maxPrefLen } = getTypeIndex(obj);
|
|
7957
|
+
const hi = Math.min(sName.length, maxPrefLen);
|
|
7958
|
+
for (let n = minPrefLen; n <= hi; n++) {
|
|
7959
|
+
const cand = sName.slice(0, n);
|
|
7960
|
+
if (obj.typePrefixesInObj.has(cand)) markTypeLive(obj, cand);
|
|
7590
7961
|
}
|
|
7591
7962
|
}
|
|
7592
7963
|
};
|
|
@@ -7679,7 +8050,8 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
|
|
|
7679
8050
|
for (const fIdx of obj.rootFuncs) markFuncLive(obj, fIdx);
|
|
7680
8051
|
for (const sIdx of obj.rootSegs) markSegLive(obj, sIdx);
|
|
7681
8052
|
for (const name of obj.symNames) {
|
|
7682
|
-
|
|
8053
|
+
if (!name || !name.startsWith("_c_") || !name.endsWith("__load")) continue;
|
|
8054
|
+
const loaded = name.match(/^_c_(\w+)__load$/)?.[1];
|
|
7683
8055
|
if (!loaded) continue;
|
|
7684
8056
|
const classSym = obj.symNames.indexOf(`._OBJC_CLASS_${loaded}`);
|
|
7685
8057
|
if (classSym !== -1 && (obj.symFlags[classSym] & 16) === 0)
|
|
@@ -7827,14 +8199,30 @@ function pruneSwiftWasmLink(directory, toolchainBin, moduleRoot, staticClangTarg
|
|
|
7827
8199
|
const keepObjCClassesNamedInSegment = (obj, segIdx) => {
|
|
7828
8200
|
const range = obj.segPayloadRanges[segIdx];
|
|
7829
8201
|
if (!range) return;
|
|
8202
|
+
const [rangeStart, rangeEnd] = range;
|
|
8203
|
+
if (rangeEnd - rangeStart < 4) return;
|
|
7830
8204
|
let bytes = objectBytes.get(obj);
|
|
7831
8205
|
if (!bytes) objectBytes.set(obj, bytes = fs5.readFileSync(obj.file));
|
|
7832
|
-
|
|
7833
|
-
|
|
7834
|
-
const
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
8206
|
+
let pos = rangeStart;
|
|
8207
|
+
while (pos < rangeEnd - 3) {
|
|
8208
|
+
const at = bytes.indexOf("So", pos);
|
|
8209
|
+
if (at < 0 || at >= rangeEnd - 2) break;
|
|
8210
|
+
let digitEnd = at + 2;
|
|
8211
|
+
let length = 0;
|
|
8212
|
+
while (digitEnd < rangeEnd) {
|
|
8213
|
+
const ch = bytes[digitEnd];
|
|
8214
|
+
if (ch < 48 || ch > 57) break;
|
|
8215
|
+
length = length * 10 + (ch - 48);
|
|
8216
|
+
digitEnd++;
|
|
8217
|
+
}
|
|
8218
|
+
if (digitEnd === at + 2) {
|
|
8219
|
+
pos = at + 2;
|
|
8220
|
+
continue;
|
|
8221
|
+
}
|
|
8222
|
+
pos = digitEnd;
|
|
8223
|
+
const nameEnd = digitEnd + length;
|
|
8224
|
+
if (nameEnd >= rangeEnd || bytes[nameEnd] !== 67) continue;
|
|
8225
|
+
const symbol = `._OBJC_CLASS_${bytes.toString("latin1", digitEnd, nameEnd)}`;
|
|
7838
8226
|
for (const provider of lazyProviders.get(symbol) ?? []) {
|
|
7839
8227
|
eagerDynamicObjects.add(provider);
|
|
7840
8228
|
extractObject(provider);
|
|
@@ -8645,7 +9033,62 @@ var NATIVE_DYLD_PACKS_SECTION = "peach.dyld-packs-v1";
|
|
|
8645
9033
|
|
|
8646
9034
|
// src/swift-guest-image-ledger.ts
|
|
8647
9035
|
import { createHash as createHash7 } from "node:crypto";
|
|
9036
|
+
var ByteWriter = class {
|
|
9037
|
+
constructor(initialCapacity = 256) {
|
|
9038
|
+
__publicField(this, "buf");
|
|
9039
|
+
__publicField(this, "pos", 0);
|
|
9040
|
+
this.buf = Buffer.allocUnsafe(Math.max(64, initialCapacity));
|
|
9041
|
+
}
|
|
9042
|
+
ensure(extra) {
|
|
9043
|
+
const needed = this.pos + extra;
|
|
9044
|
+
if (needed <= this.buf.length) return;
|
|
9045
|
+
let next = this.buf.length * 2;
|
|
9046
|
+
while (next < needed) next *= 2;
|
|
9047
|
+
const grown = Buffer.allocUnsafe(next);
|
|
9048
|
+
this.buf.copy(grown, 0, 0, this.pos);
|
|
9049
|
+
this.buf = grown;
|
|
9050
|
+
}
|
|
9051
|
+
byte(value) {
|
|
9052
|
+
this.ensure(1);
|
|
9053
|
+
this.buf[this.pos++] = value;
|
|
9054
|
+
}
|
|
9055
|
+
uleb(value) {
|
|
9056
|
+
this.ensure(10);
|
|
9057
|
+
let pos = this.pos;
|
|
9058
|
+
const buf = this.buf;
|
|
9059
|
+
do {
|
|
9060
|
+
let byte = value % 128;
|
|
9061
|
+
value = Math.floor(value / 128);
|
|
9062
|
+
if (value) byte |= 128;
|
|
9063
|
+
buf[pos++] = byte;
|
|
9064
|
+
} while (value);
|
|
9065
|
+
this.pos = pos;
|
|
9066
|
+
}
|
|
9067
|
+
bytes(source, start = 0, end = source.length) {
|
|
9068
|
+
const len = end - start;
|
|
9069
|
+
if (len <= 0) return;
|
|
9070
|
+
this.ensure(len);
|
|
9071
|
+
this.buf.set(source.subarray(start, end), this.pos);
|
|
9072
|
+
this.pos += len;
|
|
9073
|
+
}
|
|
9074
|
+
string(value) {
|
|
9075
|
+
const len = Buffer.byteLength(value, "utf8");
|
|
9076
|
+
this.uleb(len);
|
|
9077
|
+
if (len > 0) {
|
|
9078
|
+
this.ensure(len);
|
|
9079
|
+
this.buf.write(value, this.pos, len, "utf8");
|
|
9080
|
+
this.pos += len;
|
|
9081
|
+
}
|
|
9082
|
+
}
|
|
9083
|
+
finish() {
|
|
9084
|
+
return this.buf.subarray(0, this.pos);
|
|
9085
|
+
}
|
|
9086
|
+
};
|
|
8648
9087
|
function readNumber(bytes, position) {
|
|
9088
|
+
if (position < bytes.length) {
|
|
9089
|
+
const first = bytes[position];
|
|
9090
|
+
if (first < 128) return [first, position + 1];
|
|
9091
|
+
}
|
|
8649
9092
|
let value = 0;
|
|
8650
9093
|
let shift = 0;
|
|
8651
9094
|
for (; ; ) {
|
|
@@ -8657,6 +9100,7 @@ function readNumber(bytes, position) {
|
|
|
8657
9100
|
}
|
|
8658
9101
|
}
|
|
8659
9102
|
function encodeNumber(value) {
|
|
9103
|
+
if (value < 128) return Buffer.from([value]);
|
|
8660
9104
|
const bytes = [];
|
|
8661
9105
|
do {
|
|
8662
9106
|
let byte = value % 128;
|
|
@@ -8678,6 +9122,9 @@ function encodedString(value) {
|
|
|
8678
9122
|
const bytes = Buffer.from(value);
|
|
8679
9123
|
return Buffer.concat([encodeNumber(bytes.length), bytes]);
|
|
8680
9124
|
}
|
|
9125
|
+
function isWasmMagic(bytes) {
|
|
9126
|
+
return bytes.length >= 8 && bytes[0] === 0 && bytes[1] === 97 && bytes[2] === 115 && bytes[3] === 109 && bytes[4] === 1 && bytes[5] === 0 && bytes[6] === 0 && bytes[7] === 0;
|
|
9127
|
+
}
|
|
8681
9128
|
function llvmType(value) {
|
|
8682
9129
|
switch (value) {
|
|
8683
9130
|
case 127:
|
|
@@ -8695,11 +9142,12 @@ function llvmType(value) {
|
|
|
8695
9142
|
var OBJC_INIT_RECORD = ".objc_init";
|
|
8696
9143
|
var TABLE_INDEX_RELOCATIONS = /* @__PURE__ */ new Set([1, 2, 12, 18, 19, 24]);
|
|
8697
9144
|
function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLookups, preserveCanonical, options = {}) {
|
|
8698
|
-
if (
|
|
8699
|
-
|
|
9145
|
+
if (!isWasmMagic(bytes)) throw new Error("expected wasm object");
|
|
9146
|
+
const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
8700
9147
|
const { sdkLookupOnly, sdkProduct } = options;
|
|
8701
9148
|
const comdatScope = sdkProduct === void 0 ? callerAlias : `${callerAlias}:${sdkProduct}`;
|
|
8702
|
-
const
|
|
9149
|
+
const rewrite = binding !== void 0;
|
|
9150
|
+
const sections = rewrite ? [bytes.subarray(0, 8)] : void 0;
|
|
8703
9151
|
const types = [];
|
|
8704
9152
|
const functionTypes = [];
|
|
8705
9153
|
const definitions = [];
|
|
@@ -8713,45 +9161,74 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8713
9161
|
const usedSymbols = /* @__PURE__ */ new Set();
|
|
8714
9162
|
let position = 8;
|
|
8715
9163
|
while (position < bytes.length) {
|
|
9164
|
+
const headerStart = position;
|
|
8716
9165
|
const id = bytes[position++];
|
|
8717
|
-
|
|
9166
|
+
let size = 0;
|
|
9167
|
+
if (position < bytes.length && bytes[position] < 128) {
|
|
9168
|
+
size = bytes[position++];
|
|
9169
|
+
} else {
|
|
9170
|
+
const [val, next] = readNumber(bytes, position);
|
|
9171
|
+
size = val;
|
|
9172
|
+
position = next;
|
|
9173
|
+
}
|
|
9174
|
+
const start = position;
|
|
8718
9175
|
const end = start + size;
|
|
8719
9176
|
if (end > bytes.length) throw new Error("invalid wasm section");
|
|
8720
9177
|
position = end;
|
|
8721
|
-
if (
|
|
8722
|
-
|
|
8723
|
-
|
|
9178
|
+
if (id > 3) {
|
|
9179
|
+
if (sections) sections.push(bytes.subarray(headerStart, end));
|
|
9180
|
+
continue;
|
|
9181
|
+
}
|
|
9182
|
+
let offset = start;
|
|
8724
9183
|
const number3 = () => {
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
9184
|
+
if (offset < end) {
|
|
9185
|
+
const first = bytes[offset];
|
|
9186
|
+
if (first < 128) {
|
|
9187
|
+
offset++;
|
|
9188
|
+
return first;
|
|
9189
|
+
}
|
|
9190
|
+
}
|
|
9191
|
+
let value = 0;
|
|
9192
|
+
let shift = 0;
|
|
9193
|
+
for (; ; ) {
|
|
9194
|
+
if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
|
|
9195
|
+
const byte = bytes[offset++];
|
|
9196
|
+
value += (byte & 127) * 2 ** shift;
|
|
9197
|
+
if (!(byte & 128)) return value;
|
|
9198
|
+
shift += 7;
|
|
9199
|
+
}
|
|
8728
9200
|
};
|
|
8729
9201
|
const string2 = () => {
|
|
8730
|
-
const
|
|
8731
|
-
|
|
9202
|
+
const length = number3();
|
|
9203
|
+
const strEnd = offset + length;
|
|
9204
|
+
if (strEnd > end) throw new Error("invalid wasm string");
|
|
9205
|
+
const value = rawBuf.toString("utf8", offset, strEnd);
|
|
9206
|
+
offset = strEnd;
|
|
8732
9207
|
return value;
|
|
8733
9208
|
};
|
|
9209
|
+
let rewrittenSection;
|
|
8734
9210
|
if (id === 1) {
|
|
8735
9211
|
const count = number3();
|
|
8736
9212
|
for (let i = 0; i < count; i++) {
|
|
8737
|
-
if (
|
|
9213
|
+
if (bytes[offset++] !== 96) throw new Error("unsupported wasm type");
|
|
8738
9214
|
const parameterCount = number3();
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
|
|
9215
|
+
if (offset + parameterCount > end) throw new Error("invalid wasm type");
|
|
9216
|
+
const parameters = new Array(parameterCount);
|
|
9217
|
+
for (let p = 0; p < parameterCount; p++) parameters[p] = bytes[offset++];
|
|
8742
9218
|
const resultCount = number3();
|
|
8743
|
-
|
|
8744
|
-
|
|
8745
|
-
|
|
9219
|
+
if (offset + resultCount > end) throw new Error("invalid wasm type");
|
|
9220
|
+
const results = new Array(resultCount);
|
|
9221
|
+
for (let r = 0; r < resultCount; r++) results[r] = bytes[offset++];
|
|
8746
9222
|
types.push({ parameters, results });
|
|
8747
9223
|
}
|
|
8748
9224
|
} else if (id === 2) {
|
|
8749
9225
|
const count = number3();
|
|
8750
|
-
const
|
|
9226
|
+
const importWriter = rewrite ? new ByteWriter(size + 64) : void 0;
|
|
9227
|
+
importWriter?.uleb(count);
|
|
8751
9228
|
for (let i = 0; i < count; i++) {
|
|
8752
9229
|
const module = string2();
|
|
8753
9230
|
const name = string2();
|
|
8754
|
-
const kind =
|
|
9231
|
+
const kind = bytes[offset++];
|
|
8755
9232
|
const typeStart = offset;
|
|
8756
9233
|
let functionType = -1;
|
|
8757
9234
|
if (kind === 0) {
|
|
@@ -8759,7 +9236,7 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8759
9236
|
functionTypes.push(functionType);
|
|
8760
9237
|
functionImportNames.push(name);
|
|
8761
9238
|
} else if (kind === 1) {
|
|
8762
|
-
const referenceType =
|
|
9239
|
+
const referenceType = bytes[offset++];
|
|
8763
9240
|
if (referenceType !== 112 && referenceType !== 111)
|
|
8764
9241
|
throw new Error("unsupported table type");
|
|
8765
9242
|
const flags = number3();
|
|
@@ -8778,11 +9255,15 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8778
9255
|
} else throw new Error("unsupported wasm import");
|
|
8779
9256
|
const isDlsym = instrumentDynamicLookups && module === "env" && name === "dlsym" && kind === 0;
|
|
8780
9257
|
const isDlerror = instrumentDynamicLookups && module === "env" && name === "dlerror" && kind === 0;
|
|
8781
|
-
if (
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
9258
|
+
if (!rewrite) {
|
|
9259
|
+
if (module === "env" && names.has(name)) {
|
|
9260
|
+
usedSymbols.add(name);
|
|
9261
|
+
if (kind === 0) {
|
|
9262
|
+
const type = types[functionType];
|
|
9263
|
+
if (!type) throw new Error(`missing import type for ${name}`);
|
|
9264
|
+
functionImports.set(name, type);
|
|
9265
|
+
}
|
|
9266
|
+
}
|
|
8786
9267
|
}
|
|
8787
9268
|
if (isDlsym || isDlerror) {
|
|
8788
9269
|
const type = types[functionType];
|
|
@@ -8792,17 +9273,17 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8792
9273
|
}
|
|
8793
9274
|
if (isDlsym) usesDlsym = true;
|
|
8794
9275
|
if (isDlerror) usesDlerror = true;
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8798
|
-
isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module === "env" && name !== "dlsym" && name !== "dlerror" ? binding
|
|
8799
|
-
)
|
|
8800
|
-
|
|
8801
|
-
|
|
8802
|
-
|
|
9276
|
+
if (importWriter && binding) {
|
|
9277
|
+
importWriter.string(module);
|
|
9278
|
+
importWriter.string(
|
|
9279
|
+
isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module === "env" && name !== "dlsym" && name !== "dlerror" ? binding(name) ?? name : name
|
|
9280
|
+
);
|
|
9281
|
+
importWriter.byte(kind);
|
|
9282
|
+
importWriter.bytes(bytes, typeStart, offset);
|
|
9283
|
+
}
|
|
8803
9284
|
}
|
|
8804
|
-
if (offset !==
|
|
8805
|
-
if (
|
|
9285
|
+
if (offset !== end) throw new Error("invalid wasm import section");
|
|
9286
|
+
if (importWriter) rewrittenSection = importWriter.finish();
|
|
8806
9287
|
} else if (id === 3) {
|
|
8807
9288
|
const count = number3();
|
|
8808
9289
|
for (let i = 0; i < count; i++) functionTypes.push(number3());
|
|
@@ -8811,43 +9292,40 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8811
9292
|
if (sectionName === "linking") {
|
|
8812
9293
|
const version2 = number3();
|
|
8813
9294
|
if (version2 !== 2) throw new Error("unsupported wasm linking version");
|
|
8814
|
-
const subsections = [];
|
|
9295
|
+
const subsections = rewrite ? [] : void 0;
|
|
8815
9296
|
let objcLoader;
|
|
8816
|
-
while (offset <
|
|
8817
|
-
const kind =
|
|
9297
|
+
while (offset < end) {
|
|
9298
|
+
const kind = bytes[offset++];
|
|
8818
9299
|
const length = number3();
|
|
8819
9300
|
const stop = offset + length;
|
|
8820
|
-
if (stop >
|
|
8821
|
-
|
|
8822
|
-
if (kind === 7 && !sdkLookupOnly) {
|
|
8823
|
-
const
|
|
9301
|
+
if (stop > end) throw new Error("invalid linking subsection");
|
|
9302
|
+
const contentStart = offset;
|
|
9303
|
+
if (kind === 7 && rewrite && !sdkLookupOnly) {
|
|
9304
|
+
const comdatWriter = new ByteWriter(length + 64);
|
|
8824
9305
|
const count = number3();
|
|
8825
|
-
|
|
9306
|
+
comdatWriter.uleb(count);
|
|
8826
9307
|
for (let i = 0; i < count; i++) {
|
|
8827
9308
|
const group = string2();
|
|
8828
9309
|
const begin = offset;
|
|
8829
9310
|
number3();
|
|
8830
9311
|
const members = number3();
|
|
8831
9312
|
for (let member = 0; member < members * 2; member++) number3();
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
group === OBJC_INIT_RECORD ? group : `${comdatScope}:${group}`
|
|
8835
|
-
),
|
|
8836
|
-
section2.subarray(begin, offset)
|
|
9313
|
+
comdatWriter.string(
|
|
9314
|
+
group === OBJC_INIT_RECORD ? group : `${comdatScope}:${group}`
|
|
8837
9315
|
);
|
|
9316
|
+
comdatWriter.bytes(bytes, begin, offset);
|
|
8838
9317
|
}
|
|
8839
9318
|
if (offset !== stop) throw new Error("invalid comdat subsection");
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
if (kind === 8) {
|
|
8843
|
-
const
|
|
8844
|
-
|
|
9319
|
+
const buf = comdatWriter.finish();
|
|
9320
|
+
subsections.push({ kind, parts: [buf], byteLength: buf.length });
|
|
9321
|
+
} else if (kind === 8) {
|
|
9322
|
+
const entryWriter = rewrite ? new ByteWriter(length + 128) : void 0;
|
|
9323
|
+
let extraWriter;
|
|
8845
9324
|
const count = number3();
|
|
8846
|
-
entries2.push(encodeNumber(count));
|
|
8847
9325
|
let added = 0;
|
|
8848
9326
|
for (let i = 0; i < count; i++) {
|
|
8849
9327
|
const begin = offset;
|
|
8850
|
-
const symbolKind =
|
|
9328
|
+
const symbolKind = bytes[offset++];
|
|
8851
9329
|
const flags = number3();
|
|
8852
9330
|
const flagsEnd = offset;
|
|
8853
9331
|
let index = -1;
|
|
@@ -8875,25 +9353,43 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8875
9353
|
}
|
|
8876
9354
|
} else if (symbolKind === 3) number3();
|
|
8877
9355
|
else throw new Error("unsupported wasm symbol kind");
|
|
8878
|
-
if (symbolKind === 0)
|
|
9356
|
+
if (!rewrite && symbolKind === 0)
|
|
8879
9357
|
functionSymbols[i] = name || functionImportNames[index];
|
|
8880
|
-
if (!sdkLookupOnly && name === OBJC_LOAD_FUNCTION && symbolKind === 0 && !(flags & 16)) {
|
|
9358
|
+
if (rewrite && !sdkLookupOnly && name === OBJC_LOAD_FUNCTION && symbolKind === 0 && !(flags & 16)) {
|
|
8881
9359
|
objcLoader = i;
|
|
8882
9360
|
}
|
|
8883
9361
|
const alias = names.get(name);
|
|
8884
|
-
if (flags & 16 && symbolKind === 1 && alias)
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
9362
|
+
if (!rewrite && flags & 16 && symbolKind === 1 && alias)
|
|
9363
|
+
usedSymbols.add(name);
|
|
9364
|
+
if (entryWriter && binding) {
|
|
9365
|
+
if ((name === "dlsym" && usesDlsym || name === "dlerror" && usesDlerror) && flags & 16 && flags & 64 && symbolKind === 0) {
|
|
9366
|
+
entryWriter.bytes(bytes, begin, nameStart);
|
|
9367
|
+
entryWriter.string(name === "dlsym" ? callerAlias : dlerrorAlias);
|
|
9368
|
+
entryWriter.bytes(bytes, nameEnd, offset);
|
|
9369
|
+
} else if (flags & 16 && name !== "dlsym" && name !== "dlerror" && binding(name) !== void 0) {
|
|
9370
|
+
entryWriter.bytes(bytes, begin, nameStart);
|
|
9371
|
+
entryWriter.string(binding(name));
|
|
9372
|
+
entryWriter.bytes(bytes, nameEnd, offset);
|
|
9373
|
+
} else if (alias && !(flags & 16) && (flags & 3) !== 2) {
|
|
9374
|
+
if (symbolKind !== 0 && symbolKind !== 1)
|
|
9375
|
+
throw new Error(`unsupported symbol ${name}`);
|
|
9376
|
+
if (preserveCanonical.has(name)) {
|
|
9377
|
+
entryWriter.bytes(bytes, begin, offset);
|
|
9378
|
+
extraWriter ?? (extraWriter = new ByteWriter(256));
|
|
9379
|
+
extraWriter.byte(bytes[begin]);
|
|
9380
|
+
extraWriter.uleb(flags & ~32);
|
|
9381
|
+
extraWriter.bytes(bytes, flagsEnd, nameStart);
|
|
9382
|
+
extraWriter.string(alias);
|
|
9383
|
+
extraWriter.bytes(bytes, nameEnd, offset);
|
|
9384
|
+
added++;
|
|
9385
|
+
} else {
|
|
9386
|
+
entryWriter.bytes(bytes, begin, nameStart);
|
|
9387
|
+
entryWriter.string(alias);
|
|
9388
|
+
entryWriter.bytes(bytes, nameEnd, offset);
|
|
9389
|
+
}
|
|
9390
|
+
} else {
|
|
9391
|
+
entryWriter.bytes(bytes, begin, offset);
|
|
9392
|
+
}
|
|
8897
9393
|
} else if (alias && !(flags & 16) && (flags & 3) !== 2) {
|
|
8898
9394
|
if (symbolKind !== 0 && symbolKind !== 1)
|
|
8899
9395
|
throw new Error(`unsupported symbol ${name}`);
|
|
@@ -8907,63 +9403,73 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8907
9403
|
hidden: (flags & 4) !== 0,
|
|
8908
9404
|
type
|
|
8909
9405
|
});
|
|
8910
|
-
|
|
8911
|
-
entries2.push(section2.subarray(begin, offset));
|
|
8912
|
-
extraEntries.push(
|
|
8913
|
-
section2.subarray(begin, begin + 1),
|
|
8914
|
-
encodeNumber(flags & ~32),
|
|
8915
|
-
section2.subarray(flagsEnd, nameStart),
|
|
8916
|
-
encodedString(alias),
|
|
8917
|
-
section2.subarray(nameEnd, offset)
|
|
8918
|
-
);
|
|
8919
|
-
added++;
|
|
8920
|
-
} else {
|
|
8921
|
-
entries2.push(
|
|
8922
|
-
section2.subarray(begin, nameStart),
|
|
8923
|
-
encodedString(alias),
|
|
8924
|
-
section2.subarray(nameEnd, offset)
|
|
8925
|
-
);
|
|
8926
|
-
}
|
|
8927
|
-
} else entries2.push(section2.subarray(begin, offset));
|
|
9406
|
+
}
|
|
8928
9407
|
}
|
|
8929
9408
|
if (offset !== stop) throw new Error("invalid symbol subsection");
|
|
8930
|
-
|
|
8931
|
-
|
|
9409
|
+
if (entryWriter) {
|
|
9410
|
+
const countBytes = encodeNumber(count + added);
|
|
9411
|
+
const entryBuf = entryWriter.finish();
|
|
9412
|
+
if (extraWriter) {
|
|
9413
|
+
const extraBuf = extraWriter.finish();
|
|
9414
|
+
subsections.push({
|
|
9415
|
+
kind,
|
|
9416
|
+
parts: [countBytes, entryBuf, extraBuf],
|
|
9417
|
+
byteLength: countBytes.length + entryBuf.length + extraBuf.length
|
|
9418
|
+
});
|
|
9419
|
+
} else {
|
|
9420
|
+
subsections.push({
|
|
9421
|
+
kind,
|
|
9422
|
+
parts: [countBytes, entryBuf],
|
|
9423
|
+
byteLength: countBytes.length + entryBuf.length
|
|
9424
|
+
});
|
|
9425
|
+
}
|
|
9426
|
+
}
|
|
9427
|
+
} else if (subsections) {
|
|
9428
|
+
subsections.push({
|
|
9429
|
+
kind,
|
|
9430
|
+
parts: [bytes.subarray(contentStart, stop)],
|
|
9431
|
+
byteLength: length
|
|
9432
|
+
});
|
|
8932
9433
|
}
|
|
8933
9434
|
offset = stop;
|
|
8934
|
-
subsections.push({ kind, content });
|
|
8935
9435
|
}
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
const
|
|
8945
|
-
|
|
8946
|
-
|
|
8947
|
-
|
|
8948
|
-
content
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
9436
|
+
if (subsections) {
|
|
9437
|
+
const linkingWriter = new ByteWriter(size + 128);
|
|
9438
|
+
linkingWriter.string(sectionName);
|
|
9439
|
+
linkingWriter.uleb(version2);
|
|
9440
|
+
for (const subsection of subsections) {
|
|
9441
|
+
if (subsection.kind === 6 && objcLoader !== void 0) {
|
|
9442
|
+
const content = subsection.parts[0];
|
|
9443
|
+
const [count, entriesStart] = readNumber(content, 0);
|
|
9444
|
+
const initWriter = new ByteWriter(content.length + 16);
|
|
9445
|
+
initWriter.bytes(content, 0, entriesStart);
|
|
9446
|
+
let entryStart = entriesStart;
|
|
9447
|
+
for (let i = 0; i < count; i++) {
|
|
9448
|
+
const [, symbolStart] = readNumber(content, entryStart);
|
|
9449
|
+
const [symbol, entryEnd] = readNumber(content, symbolStart);
|
|
9450
|
+
if (symbol === objcLoader) {
|
|
9451
|
+
initWriter.uleb(1);
|
|
9452
|
+
initWriter.bytes(content, symbolStart, entryEnd);
|
|
9453
|
+
} else {
|
|
9454
|
+
initWriter.bytes(content, entryStart, entryEnd);
|
|
9455
|
+
}
|
|
9456
|
+
entryStart = entryEnd;
|
|
9457
|
+
}
|
|
9458
|
+
if (entryStart !== content.length)
|
|
9459
|
+
throw new Error("invalid init functions subsection");
|
|
9460
|
+
const initBuf = initWriter.finish();
|
|
9461
|
+
linkingWriter.byte(subsection.kind);
|
|
9462
|
+
linkingWriter.uleb(initBuf.length);
|
|
9463
|
+
linkingWriter.bytes(initBuf);
|
|
9464
|
+
} else {
|
|
9465
|
+
linkingWriter.byte(subsection.kind);
|
|
9466
|
+
linkingWriter.uleb(subsection.byteLength);
|
|
9467
|
+
for (const part of subsection.parts) linkingWriter.bytes(part);
|
|
8954
9468
|
}
|
|
8955
|
-
if (entryStart !== content.length)
|
|
8956
|
-
throw new Error("invalid init functions subsection");
|
|
8957
|
-
content = Buffer.concat(entries2);
|
|
8958
9469
|
}
|
|
8959
|
-
|
|
8960
|
-
Buffer.from([subsection.kind]),
|
|
8961
|
-
encodeNumber(content.length),
|
|
8962
|
-
content
|
|
8963
|
-
);
|
|
9470
|
+
rewrittenSection = linkingWriter.finish();
|
|
8964
9471
|
}
|
|
8965
|
-
|
|
8966
|
-
} else if (!sections && sectionName.startsWith("reloc.")) {
|
|
9472
|
+
} else if (!rewrite && sectionName.startsWith("reloc.")) {
|
|
8967
9473
|
number3();
|
|
8968
9474
|
for (let count = number3(); count > 0; count--) {
|
|
8969
9475
|
const type = number3();
|
|
@@ -8973,18 +9479,27 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
8973
9479
|
if (name !== void 0 && TABLE_INDEX_RELOCATIONS.has(type))
|
|
8974
9480
|
addressTaken.add(name);
|
|
8975
9481
|
}
|
|
8976
|
-
if (offset !==
|
|
8977
|
-
|
|
9482
|
+
if (offset !== end) throw new Error(`invalid relocation section ${sectionName}`);
|
|
9483
|
+
}
|
|
9484
|
+
}
|
|
9485
|
+
if (sections) {
|
|
9486
|
+
if (rewrittenSection) {
|
|
9487
|
+
sections.push(
|
|
9488
|
+
Buffer.from([id]),
|
|
9489
|
+
encodeNumber(rewrittenSection.length),
|
|
9490
|
+
rewrittenSection
|
|
9491
|
+
);
|
|
9492
|
+
} else {
|
|
9493
|
+
sections.push(bytes.subarray(headerStart, end));
|
|
8978
9494
|
}
|
|
8979
9495
|
}
|
|
8980
|
-
sections?.push(Buffer.from([id]), encodeNumber(section2.length), section2);
|
|
8981
9496
|
}
|
|
8982
9497
|
return {
|
|
8983
9498
|
bytes: sections ? Buffer.concat(sections) : bytes,
|
|
8984
9499
|
definitions,
|
|
8985
9500
|
functionImports,
|
|
8986
9501
|
usesDlsym,
|
|
8987
|
-
usedSymbols
|
|
9502
|
+
usedSymbols,
|
|
8988
9503
|
addressTaken: [...addressTaken]
|
|
8989
9504
|
};
|
|
8990
9505
|
}
|
|
@@ -9073,36 +9588,51 @@ function createGuestImageLedger(input) {
|
|
|
9073
9588
|
}
|
|
9074
9589
|
}
|
|
9075
9590
|
}
|
|
9076
|
-
|
|
9077
|
-
for (const definition of definitions)
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9591
|
+
let hasNonAscii = false;
|
|
9592
|
+
for (const definition of definitions) {
|
|
9593
|
+
const s = definition.name;
|
|
9594
|
+
for (let i = 0; i < s.length; i++) {
|
|
9595
|
+
if (s.charCodeAt(i) > 127) {
|
|
9596
|
+
hasNonAscii = true;
|
|
9597
|
+
break;
|
|
9598
|
+
}
|
|
9599
|
+
}
|
|
9600
|
+
if (hasNonAscii) break;
|
|
9601
|
+
}
|
|
9602
|
+
if (hasNonAscii) {
|
|
9603
|
+
const nameBytes = /* @__PURE__ */ new Map();
|
|
9604
|
+
for (const definition of definitions)
|
|
9605
|
+
if (!nameBytes.has(definition.name))
|
|
9606
|
+
nameBytes.set(definition.name, Buffer.from(definition.name));
|
|
9607
|
+
definitions.sort(
|
|
9608
|
+
(a, b) => Buffer.compare(nameBytes.get(a.name), nameBytes.get(b.name)) || a.image - b.image
|
|
9609
|
+
);
|
|
9610
|
+
} else {
|
|
9611
|
+
definitions.sort(
|
|
9612
|
+
(a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : a.image - b.image
|
|
9613
|
+
);
|
|
9614
|
+
}
|
|
9083
9615
|
const preserveCanonical = /* @__PURE__ */ new Set();
|
|
9084
9616
|
const definitionsByName = Map.groupBy(definitions, (definition) => definition.name);
|
|
9085
|
-
|
|
9617
|
+
if (symbolIndices.has("__cxa_throw")) {
|
|
9618
|
+
const name = "__cxa_throw";
|
|
9086
9619
|
const matching = definitionsByName.get(name) ?? [];
|
|
9087
|
-
if (new Set(matching.map((definition) => definition.image)).size
|
|
9088
|
-
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
);
|
|
9102
|
-
if (uses && caller.image !== runtime.image && !caller.next.includes(runtime.image))
|
|
9103
|
-
throw new Error(`weak interposition scope excludes runtime for ${name}`);
|
|
9620
|
+
if (new Set(matching.map((definition) => definition.image)).size >= 2 && matching.some((definition) => definition.weak)) {
|
|
9621
|
+
const weak = matching.filter((definition) => definition.weak);
|
|
9622
|
+
const strong = matching.filter((definition) => !definition.weak);
|
|
9623
|
+
if (weak.length !== 1 || strong.length !== 1)
|
|
9624
|
+
throw new Error(`unsupported weak interposition for ${name}`);
|
|
9625
|
+
const [local] = weak;
|
|
9626
|
+
const [runtime] = strong;
|
|
9627
|
+
if (local.kind !== "function" || runtime.kind !== "function" || local.result !== runtime.result || local.parameters.join(",") !== runtime.parameters.join(","))
|
|
9628
|
+
throw new Error(`incompatible weak interposition for ${name}`);
|
|
9629
|
+
for (const caller of input.callers) {
|
|
9630
|
+
const uses = caller.image === local.image || units.some((unit) => unit.image === caller.image && unit.usedSymbols.has(name));
|
|
9631
|
+
if (uses && caller.image !== runtime.image && !caller.next.includes(runtime.image))
|
|
9632
|
+
throw new Error(`weak interposition scope excludes runtime for ${name}`);
|
|
9633
|
+
}
|
|
9634
|
+
preserveCanonical.add(name);
|
|
9104
9635
|
}
|
|
9105
|
-
preserveCanonical.add(name);
|
|
9106
9636
|
}
|
|
9107
9637
|
for (const name of [
|
|
9108
9638
|
"dlsym",
|
|
@@ -9114,40 +9644,76 @@ function createGuestImageLedger(input) {
|
|
|
9114
9644
|
])
|
|
9115
9645
|
preserveCanonical.add(name);
|
|
9116
9646
|
for (const name of input.commandLineSymbols ?? []) preserveCanonical.add(name);
|
|
9117
|
-
const
|
|
9118
|
-
const
|
|
9647
|
+
const imageAliases = /* @__PURE__ */ new Map();
|
|
9648
|
+
const imageWeakNames = /* @__PURE__ */ new Map();
|
|
9649
|
+
const singleOwnerByName = /* @__PURE__ */ new Map();
|
|
9650
|
+
for (const definition of definitions) {
|
|
9651
|
+
let aliases = imageAliases.get(definition.image);
|
|
9652
|
+
if (!aliases) imageAliases.set(definition.image, aliases = /* @__PURE__ */ new Map());
|
|
9653
|
+
const existing = aliases.get(definition.name);
|
|
9654
|
+
if (existing === void 0) {
|
|
9655
|
+
aliases.set(definition.name, definition.alias);
|
|
9656
|
+
if (definition.weak) {
|
|
9657
|
+
let weak = imageWeakNames.get(definition.image);
|
|
9658
|
+
if (!weak) imageWeakNames.set(definition.image, weak = /* @__PURE__ */ new Set());
|
|
9659
|
+
weak.add(definition.name);
|
|
9660
|
+
}
|
|
9661
|
+
const owner = singleOwnerByName.get(definition.name);
|
|
9662
|
+
if (owner === void 0)
|
|
9663
|
+
singleOwnerByName.set(definition.name, {
|
|
9664
|
+
image: definition.image,
|
|
9665
|
+
alias: definition.alias
|
|
9666
|
+
});
|
|
9667
|
+
else if (owner !== null && owner.image !== definition.image)
|
|
9668
|
+
singleOwnerByName.set(definition.name, null);
|
|
9669
|
+
} else if (!definition.weak && imageWeakNames.get(definition.image)?.has(definition.name)) {
|
|
9670
|
+
aliases.set(definition.name, definition.alias);
|
|
9671
|
+
imageWeakNames.get(definition.image).delete(definition.name);
|
|
9672
|
+
const owner = singleOwnerByName.get(definition.name);
|
|
9673
|
+
if (owner && owner.image === definition.image) owner.alias = definition.alias;
|
|
9674
|
+
}
|
|
9675
|
+
}
|
|
9676
|
+
const sharedLookupByImage = /* @__PURE__ */ new Map();
|
|
9119
9677
|
for (const caller of input.callers) {
|
|
9120
|
-
const bindings = /* @__PURE__ */ new Map();
|
|
9121
|
-
const seen = /* @__PURE__ */ new Map();
|
|
9122
9678
|
const scope = [caller.image, ...caller.next];
|
|
9123
9679
|
if (input.systemImage !== void 0 && !scope.includes(input.systemImage))
|
|
9124
9680
|
scope.push(input.systemImage);
|
|
9125
|
-
|
|
9126
|
-
|
|
9127
|
-
|
|
9128
|
-
|
|
9129
|
-
|
|
9130
|
-
|
|
9131
|
-
|
|
9132
|
-
|
|
9133
|
-
|
|
9134
|
-
|
|
9135
|
-
|
|
9136
|
-
|
|
9137
|
-
|
|
9138
|
-
|
|
9139
|
-
|
|
9681
|
+
const scopeSet = new Set(scope);
|
|
9682
|
+
const scopeMaps = [];
|
|
9683
|
+
const seenImages = /* @__PURE__ */ new Set();
|
|
9684
|
+
for (const image of scope) {
|
|
9685
|
+
if (seenImages.has(image)) continue;
|
|
9686
|
+
seenImages.add(image);
|
|
9687
|
+
const aliases = imageAliases.get(image);
|
|
9688
|
+
if (aliases) scopeMaps.push(aliases);
|
|
9689
|
+
}
|
|
9690
|
+
const cache = /* @__PURE__ */ new Map();
|
|
9691
|
+
sharedLookupByImage.set(caller.image, (name) => {
|
|
9692
|
+
if (preserveCanonical.has(name)) return void 0;
|
|
9693
|
+
const single = singleOwnerByName.get(name);
|
|
9694
|
+
if (single === void 0) return void 0;
|
|
9695
|
+
if (single !== null) return scopeSet.has(single.image) ? single.alias : void 0;
|
|
9696
|
+
const hit = cache.get(name);
|
|
9697
|
+
if (hit !== void 0) return hit ?? void 0;
|
|
9698
|
+
for (const aliases of scopeMaps) {
|
|
9699
|
+
const alias = aliases.get(name);
|
|
9700
|
+
if (alias !== void 0) {
|
|
9701
|
+
cache.set(name, alias);
|
|
9702
|
+
return alias;
|
|
9140
9703
|
}
|
|
9141
9704
|
}
|
|
9142
|
-
|
|
9705
|
+
cache.set(name, null);
|
|
9706
|
+
return void 0;
|
|
9707
|
+
});
|
|
9143
9708
|
}
|
|
9144
9709
|
const startup = /* @__PURE__ */ new Map();
|
|
9710
|
+
const unitsByPath = new Map(units.map((unit) => [unit.object.path, unit]));
|
|
9145
9711
|
for (const binding of input.directBindings ?? []) {
|
|
9146
|
-
const unit =
|
|
9712
|
+
const unit = unitsByPath.get(binding.object);
|
|
9147
9713
|
const matches = (definitionsByName.get(binding.symbol) ?? []).filter(
|
|
9148
9714
|
(definition) => definition.object === binding.providerObject && definition.image === binding.providerImage
|
|
9149
9715
|
);
|
|
9150
|
-
if (!unit || !unit.usedSymbols.
|
|
9716
|
+
if (!unit || !unit.usedSymbols.has(binding.symbol) || matches.length !== 1)
|
|
9151
9717
|
throw new Error(`invalid startup binding ${binding.object} ${binding.symbol}`);
|
|
9152
9718
|
const bindings = startup.get(binding.object) ?? /* @__PURE__ */ new Map();
|
|
9153
9719
|
if (bindings.has(binding.symbol))
|
|
@@ -9188,11 +9754,11 @@ function createGuestImageLedger(input) {
|
|
|
9188
9754
|
}
|
|
9189
9755
|
}
|
|
9190
9756
|
const objects = units.map(({ image, object: object2, aliases, functionImports }) => {
|
|
9191
|
-
const shared =
|
|
9757
|
+
const shared = sharedLookupByImage.get(image);
|
|
9192
9758
|
const own = startup.get(object2.path);
|
|
9193
9759
|
const bindings = new Map(own);
|
|
9194
9760
|
const weak = input.sdkWeakReferences?.get(object2.path);
|
|
9195
|
-
const binding = (name) => bindings.get(name) ?? shared
|
|
9761
|
+
const binding = (name) => bindings.get(name) ?? shared(name) ?? (weak?.has(name) ? void 0 : sdkGlobalBindings.get(name));
|
|
9196
9762
|
for (const [name, type] of functionImports) {
|
|
9197
9763
|
const alias = binding(name);
|
|
9198
9764
|
const provider = alias === void 0 ? void 0 : definitionsByAlias.get(alias);
|
|
@@ -9884,8 +10450,11 @@ function moveGuestDyldTable(map, wasm, symbols, bindingValues = /* @__PURE__ */
|
|
|
9884
10450
|
function guestDyldValueRange(map) {
|
|
9885
10451
|
const suffix = `:(${GUEST_DYLD_VALUES_SECTION})`;
|
|
9886
10452
|
let found;
|
|
9887
|
-
for (
|
|
9888
|
-
|
|
10453
|
+
for (let at = map.indexOf(suffix); at !== -1; at = map.indexOf(suffix, at + suffix.length)) {
|
|
10454
|
+
const lineEnd = at + suffix.length;
|
|
10455
|
+
if (lineEnd < map.length && map.charCodeAt(lineEnd) !== 10) continue;
|
|
10456
|
+
const lineStart = map.lastIndexOf("\n", at) + 1;
|
|
10457
|
+
const line = map.slice(lineStart, lineEnd);
|
|
9889
10458
|
const match = /^\s*([\da-f]+)\s+[\da-f]+\s+([\da-f]+)\s/.exec(line);
|
|
9890
10459
|
if (!match) throw new Error("unreadable dyld values map line");
|
|
9891
10460
|
if (found) throw new Error("link map has several dyld value sections");
|
|
@@ -9912,7 +10481,7 @@ function selectedGuestInputImage(artifact, member) {
|
|
|
9912
10481
|
// src/swift-guest-manifest.ts
|
|
9913
10482
|
import { createHash as createHash9 } from "node:crypto";
|
|
9914
10483
|
import { readFileSync as readFileSync8 } from "node:fs";
|
|
9915
|
-
function selectedGuestManifestInputs(plan, selection, identities) {
|
|
10484
|
+
function selectedGuestManifestInputs(plan, selection, identities, readSelected) {
|
|
9916
10485
|
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]));
|
|
9917
10486
|
const archives = /* @__PURE__ */ new Map();
|
|
9918
10487
|
const images = /* @__PURE__ */ new Map();
|
|
@@ -9923,19 +10492,29 @@ function selectedGuestManifestInputs(plan, selection, identities) {
|
|
|
9923
10492
|
throw new Error(`selected input has no logical identity: ${item.artifact}`);
|
|
9924
10493
|
let bytes;
|
|
9925
10494
|
let memberIdentity = null;
|
|
9926
|
-
if (item.member === null)
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
if (
|
|
9930
|
-
|
|
9931
|
-
|
|
10495
|
+
if (item.member === null) {
|
|
10496
|
+
bytes = readSelected ? readSelected(item) : readFileSync8(item.artifact);
|
|
10497
|
+
} else {
|
|
10498
|
+
if (readSelected) {
|
|
10499
|
+
bytes = readSelected(item);
|
|
10500
|
+
} else {
|
|
10501
|
+
let members = archives.get(item.artifact);
|
|
10502
|
+
if (!members) {
|
|
10503
|
+
members = /* @__PURE__ */ new Map();
|
|
10504
|
+
for (const member of readArMembers(readFileSync8(item.artifact))) {
|
|
10505
|
+
let list = members.get(member.name);
|
|
10506
|
+
if (!list) members.set(member.name, list = []);
|
|
10507
|
+
list.push(member.bytes);
|
|
10508
|
+
}
|
|
10509
|
+
archives.set(item.artifact, members);
|
|
10510
|
+
}
|
|
10511
|
+
const matching = members.get(item.member);
|
|
10512
|
+
if (!matching || matching.length !== 1)
|
|
10513
|
+
throw new Error(
|
|
10514
|
+
`selected archive member is ambiguous: ${item.artifact}(${item.member})`
|
|
10515
|
+
);
|
|
10516
|
+
bytes = matching[0];
|
|
9932
10517
|
}
|
|
9933
|
-
const matching = members.filter((member) => member.name === item.member);
|
|
9934
|
-
if (matching.length !== 1)
|
|
9935
|
-
throw new Error(
|
|
9936
|
-
`selected archive member is ambiguous: ${item.artifact}(${item.member})`
|
|
9937
|
-
);
|
|
9938
|
-
bytes = matching[0].bytes;
|
|
9939
10518
|
const origin = artifact.memberOrigins?.get(item.member);
|
|
9940
10519
|
if (artifact.memberOrigins && !origin)
|
|
9941
10520
|
throw new Error(
|
|
@@ -10016,7 +10595,7 @@ function createGuestImageManifest(image) {
|
|
|
10016
10595
|
function isSwiftGuestImageManifest(value) {
|
|
10017
10596
|
const uint = (value2, maximum) => typeof value2 === "number" && Number.isInteger(value2) && value2 >= 0 && value2 <= maximum;
|
|
10018
10597
|
const text2 = (value2) => typeof value2 === "string" && value2.length > 0 && value2.length <= 4096 && !value2.includes("\0");
|
|
10019
|
-
const name = (value2) => text2(value2) &&
|
|
10598
|
+
const name = (value2) => text2(value2) && Buffer.byteLength(value2, "utf8") <= 16;
|
|
10020
10599
|
const version2 = (value2) => isRecord(value2) && uint(value2.major, 65535) && uint(value2.minor, 255) && uint(value2.patch, 255);
|
|
10021
10600
|
if (!isRecord(value) || value.version !== 1 || !text2(value.id) || !text2(value.installName) || value.resourceBundlePath !== void 0 && !isSwiftBundlePath(value.resourceBundlePath) || value.fileType !== "executable" && value.fileType !== "dylib" || !isRecord(value.target) || value.target.triple !== SWIFT_WASM_TRIPLE || value.target.pointerWidth !== 64 || value.target.byteOrder !== "little" || value.target.cpuType !== -1 || value.target.cpuSubtype !== 0 || typeof value.inputsSha256 !== "string" || !/^[a-f0-9]{64}$/.test(value.inputsSha256) || value.uuid !== value.inputsSha256.slice(0, 32) || !isRecord(value.buildVersion) || !uint(value.buildVersion.platform, 4294967295) || !version2(value.buildVersion.minimum) || !version2(value.buildVersion.sdk) || !Array.isArray(value.regions))
|
|
10022
10601
|
return false;
|
|
@@ -10316,27 +10895,25 @@ function planGuestProjectionRegions(images, capacities, spans) {
|
|
|
10316
10895
|
function finalizeGuestProjectionStorage(options) {
|
|
10317
10896
|
const owner = options.owners.get(options.projectionObject);
|
|
10318
10897
|
if (owner === void 0) throw new Error("guest projection object has no image owner");
|
|
10898
|
+
const ranges = [];
|
|
10319
10899
|
const spans = guestLinkedSpans(
|
|
10320
10900
|
options.map,
|
|
10321
10901
|
options.linked,
|
|
10322
10902
|
options.optimized,
|
|
10323
10903
|
options.owners,
|
|
10324
10904
|
options.sectionOwners,
|
|
10325
|
-
options.sdkSpans !== void 0
|
|
10905
|
+
options.sdkSpans !== void 0,
|
|
10906
|
+
{
|
|
10907
|
+
trackedObject: options.projectionObject,
|
|
10908
|
+
trackedObjectOwner: owner,
|
|
10909
|
+
trackedLinearSpans: ranges
|
|
10910
|
+
}
|
|
10326
10911
|
);
|
|
10327
10912
|
const images = planGuestProjectionRegions(
|
|
10328
10913
|
options.reserved.images,
|
|
10329
10914
|
options.reserved.capacities,
|
|
10330
10915
|
options.sdkSpans ? [...spans, ...options.sdkSpans] : spans
|
|
10331
10916
|
);
|
|
10332
|
-
const ranges = guestLinkedSpans(
|
|
10333
|
-
options.map,
|
|
10334
|
-
options.linked,
|
|
10335
|
-
options.optimized,
|
|
10336
|
-
/* @__PURE__ */ new Map([[options.projectionObject, owner]]),
|
|
10337
|
-
void 0,
|
|
10338
|
-
options.sdkSpans !== void 0
|
|
10339
|
-
).filter((span) => span.space === "linear-memory");
|
|
10340
10917
|
const result = Buffer.from(options.optimized);
|
|
10341
10918
|
const data = guestWasmDataSegments(options.optimized, options.sdkSpans === void 0);
|
|
10342
10919
|
const locations = /* @__PURE__ */ new Map();
|
|
@@ -11669,7 +12246,7 @@ function occurrences(plan, args) {
|
|
|
11669
12246
|
throw new Error("guest plan does not match linker inputs");
|
|
11670
12247
|
return found;
|
|
11671
12248
|
}
|
|
11672
|
-
function selectedGuestLinkInputs(plan, args, whyExtract, linkTrace) {
|
|
12249
|
+
function selectedGuestLinkInputs(plan, args, whyExtract, linkTrace, archiveCache) {
|
|
11673
12250
|
const rows = whyExtract.trimEnd().split("\n");
|
|
11674
12251
|
if (rows.shift() !== "reference extracted symbol")
|
|
11675
12252
|
throw new Error("invalid wasm-ld extraction report");
|
|
@@ -11684,8 +12261,38 @@ function selectedGuestLinkInputs(plan, args, whyExtract, linkTrace) {
|
|
|
11684
12261
|
for (const file of extracted)
|
|
11685
12262
|
if (!traced.has(file))
|
|
11686
12263
|
throw new Error(`extracted guest input is absent from link trace ${file}`);
|
|
12264
|
+
const foundOccurrences = occurrences(plan, args);
|
|
12265
|
+
const archivePaths = /* @__PURE__ */ new Set();
|
|
12266
|
+
for (const { artifact } of foundOccurrences)
|
|
12267
|
+
if (artifact.kind === "archive") archivePaths.add(artifact.path);
|
|
12268
|
+
const tracedMembers = /* @__PURE__ */ new Map();
|
|
12269
|
+
if (archivePaths.size > 0) {
|
|
12270
|
+
const archivePrefixes = [...archivePaths].map(
|
|
12271
|
+
(archivePath) => [archivePath, `${archivePath}(`]
|
|
12272
|
+
);
|
|
12273
|
+
for (const item of traced) {
|
|
12274
|
+
if (!item.endsWith(")")) continue;
|
|
12275
|
+
const open = item.lastIndexOf("(");
|
|
12276
|
+
if (open > 0) {
|
|
12277
|
+
const archivePath = item.slice(0, open);
|
|
12278
|
+
if (archivePaths.has(archivePath)) {
|
|
12279
|
+
let list = tracedMembers.get(archivePath);
|
|
12280
|
+
if (!list) tracedMembers.set(archivePath, list = []);
|
|
12281
|
+
list.push(item.slice(open + 1, -1));
|
|
12282
|
+
continue;
|
|
12283
|
+
}
|
|
12284
|
+
}
|
|
12285
|
+
for (const [archivePath, prefix] of archivePrefixes) {
|
|
12286
|
+
if (item.startsWith(prefix)) {
|
|
12287
|
+
let list = tracedMembers.get(archivePath);
|
|
12288
|
+
if (!list) tracedMembers.set(archivePath, list = []);
|
|
12289
|
+
list.push(item.slice(prefix.length, -1));
|
|
12290
|
+
}
|
|
12291
|
+
}
|
|
12292
|
+
}
|
|
12293
|
+
}
|
|
11687
12294
|
const result = [];
|
|
11688
|
-
for (const { artifact, lazy, whole } of
|
|
12295
|
+
for (const { artifact, lazy, whole } of foundOccurrences) {
|
|
11689
12296
|
if (artifact.kind === "object") {
|
|
11690
12297
|
if (!lazy && !traced.has(artifact.path))
|
|
11691
12298
|
throw new Error(`eager guest input is absent from link trace ${artifact.path}`);
|
|
@@ -11693,15 +12300,21 @@ function selectedGuestLinkInputs(plan, args, whyExtract, linkTrace) {
|
|
|
11693
12300
|
result.push({ artifact: artifact.path, member: null });
|
|
11694
12301
|
continue;
|
|
11695
12302
|
}
|
|
11696
|
-
const
|
|
11697
|
-
const
|
|
11698
|
-
|
|
12303
|
+
const names = tracedMembers.get(artifact.path) ?? [];
|
|
12304
|
+
const nameSet = new Set(names);
|
|
12305
|
+
let members = archiveCache?.get(artifact.path);
|
|
12306
|
+
if (!members) {
|
|
12307
|
+
members = readArMembers(fs9.readFileSync(artifact.path));
|
|
12308
|
+
archiveCache?.set(artifact.path, members);
|
|
12309
|
+
}
|
|
12310
|
+
const memberCounts = /* @__PURE__ */ new Map();
|
|
11699
12311
|
for (const member of members) {
|
|
11700
|
-
|
|
12312
|
+
memberCounts.set(member.name, (memberCounts.get(member.name) ?? 0) + 1);
|
|
12313
|
+
if (whole || nameSet.has(member.name))
|
|
11701
12314
|
result.push({ artifact: artifact.path, member: member.name });
|
|
11702
12315
|
}
|
|
11703
12316
|
for (const name of names)
|
|
11704
|
-
if (
|
|
12317
|
+
if (memberCounts.get(name) !== 1)
|
|
11705
12318
|
throw new Error(
|
|
11706
12319
|
`ambiguous or unsupported archive member ${artifact.path}(${name})`
|
|
11707
12320
|
);
|
|
@@ -11778,14 +12391,25 @@ function linkGuestImages(options) {
|
|
|
11778
12391
|
}
|
|
11779
12392
|
const archives = /* @__PURE__ */ new Map();
|
|
11780
12393
|
const memberBytes = /* @__PURE__ */ new Map();
|
|
12394
|
+
const objectBytes = /* @__PURE__ */ new Map();
|
|
11781
12395
|
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]));
|
|
11782
12396
|
const providerSymbol = "__peach_dlsym_from_image";
|
|
11783
12397
|
const readSelected = (item) => {
|
|
11784
|
-
if (item.member === null)
|
|
12398
|
+
if (item.member === null) {
|
|
12399
|
+
let bytes = objectBytes.get(item.artifact);
|
|
12400
|
+
if (!bytes) {
|
|
12401
|
+
bytes = fs9.readFileSync(item.artifact);
|
|
12402
|
+
objectBytes.set(item.artifact, bytes);
|
|
12403
|
+
}
|
|
12404
|
+
return bytes;
|
|
12405
|
+
}
|
|
11785
12406
|
let byName = memberBytes.get(item.artifact);
|
|
11786
12407
|
if (!byName) {
|
|
11787
|
-
|
|
11788
|
-
|
|
12408
|
+
let members = archives.get(item.artifact);
|
|
12409
|
+
if (!members) {
|
|
12410
|
+
members = readArMembers(fs9.readFileSync(item.artifact));
|
|
12411
|
+
archives.set(item.artifact, members);
|
|
12412
|
+
}
|
|
11789
12413
|
byName = /* @__PURE__ */ new Map();
|
|
11790
12414
|
for (const member of members)
|
|
11791
12415
|
if (!byName.has(member.name))
|
|
@@ -11809,7 +12433,13 @@ function linkGuestImages(options) {
|
|
|
11809
12433
|
`--why-extract=${whyPath}`,
|
|
11810
12434
|
`--Map=${mapPath}`
|
|
11811
12435
|
]);
|
|
11812
|
-
return selectedGuestLinkInputs(
|
|
12436
|
+
return selectedGuestLinkInputs(
|
|
12437
|
+
plan,
|
|
12438
|
+
args,
|
|
12439
|
+
fs9.readFileSync(whyPath, "utf8"),
|
|
12440
|
+
trace,
|
|
12441
|
+
archives
|
|
12442
|
+
);
|
|
11813
12443
|
};
|
|
11814
12444
|
const needsProvider = (item) => {
|
|
11815
12445
|
if (!artifacts.get(item.artifact).instrumentDynamicLookups) return false;
|
|
@@ -11849,7 +12479,7 @@ function linkGuestImages(options) {
|
|
|
11849
12479
|
)
|
|
11850
12480
|
]);
|
|
11851
12481
|
const originalOwnership = identity(plan);
|
|
11852
|
-
const resolved = options.resolvePlan(selected, plan);
|
|
12482
|
+
const resolved = options.resolvePlan(selected, plan, readSelected);
|
|
11853
12483
|
if (identity(resolved) !== originalOwnership)
|
|
11854
12484
|
throw new Error("resolved guest scopes changed input ownership");
|
|
11855
12485
|
plan = resolved;
|
|
@@ -11903,6 +12533,7 @@ function linkGuestImages(options) {
|
|
|
11903
12533
|
}
|
|
11904
12534
|
}
|
|
11905
12535
|
let discoveryRegions;
|
|
12536
|
+
let liveSymbols;
|
|
11906
12537
|
if (discoveryProjection && options.projection) {
|
|
11907
12538
|
const owners = /* @__PURE__ */ new Map([[discoveryProjection, options.projection.image]]);
|
|
11908
12539
|
for (const item of selected)
|
|
@@ -11911,10 +12542,15 @@ function linkGuestImages(options) {
|
|
|
11911
12542
|
selectedGuestInputImage(artifacts.get(item.artifact), item.member)
|
|
11912
12543
|
);
|
|
11913
12544
|
const wasm = fs9.readFileSync(discovery);
|
|
12545
|
+
liveSymbols = /* @__PURE__ */ new Set();
|
|
11914
12546
|
discoveryRegions = guestProjectionRegionCounts(
|
|
11915
12547
|
plan.images.length,
|
|
11916
|
-
guestLinkedSpans(guestLinkLines(mapPath), wasm, wasm, owners
|
|
12548
|
+
guestLinkedSpans(guestLinkLines(mapPath), wasm, wasm, owners, void 0, false, {
|
|
12549
|
+
collectSymbols: liveSymbols
|
|
12550
|
+
})
|
|
11917
12551
|
);
|
|
12552
|
+
} else {
|
|
12553
|
+
liveSymbols = linkedMapSymbols(guestLinkLines(mapPath));
|
|
11918
12554
|
}
|
|
11919
12555
|
const ledger = createGuestImageLedger({
|
|
11920
12556
|
images: plan.images.map((image) => ({
|
|
@@ -11923,7 +12559,7 @@ function linkGuestImages(options) {
|
|
|
11923
12559
|
})),
|
|
11924
12560
|
callers: plan.callers,
|
|
11925
12561
|
symbols: plan.symbols,
|
|
11926
|
-
liveSymbols
|
|
12562
|
+
liveSymbols,
|
|
11927
12563
|
commandLineSymbols: commandLineSymbols(args),
|
|
11928
12564
|
directBindings: plan.directBindings,
|
|
11929
12565
|
registerAppTables: sdkCallers !== void 0,
|
|
@@ -12055,7 +12691,8 @@ function linkGuestImages(options) {
|
|
|
12055
12691
|
const selectedInputs = selectedGuestManifestInputs(
|
|
12056
12692
|
plan,
|
|
12057
12693
|
selected,
|
|
12058
|
-
projection.identities
|
|
12694
|
+
projection.identities,
|
|
12695
|
+
readSelected
|
|
12059
12696
|
);
|
|
12060
12697
|
const images = projection.images.map(
|
|
12061
12698
|
(image) => createGuestImageManifest({
|
|
@@ -12065,6 +12702,9 @@ function linkGuestImages(options) {
|
|
|
12065
12702
|
regions: []
|
|
12066
12703
|
})
|
|
12067
12704
|
);
|
|
12705
|
+
objectBytes.clear();
|
|
12706
|
+
memberBytes.clear();
|
|
12707
|
+
archives.clear();
|
|
12068
12708
|
if (!discoveryRegions) throw new Error("guest projection layout object missing");
|
|
12069
12709
|
const regionsBefore = discoveryRegions;
|
|
12070
12710
|
const ledgerPieces = guestProjectionRegionCapacity([fs9.readFileSync(ledgerObject)], 0);
|
|
@@ -12158,10 +12798,47 @@ ${changed.join("\n")}`
|
|
|
12158
12798
|
}
|
|
12159
12799
|
function linkedMapSymbols(lines) {
|
|
12160
12800
|
const names = /* @__PURE__ */ new Set();
|
|
12161
|
-
const symbol = /^ +\S+ +[0-9a-f]+ +[0-9a-f]+ {9,}([^\s/<]\S*)/;
|
|
12162
12801
|
for (const line of lines) {
|
|
12163
|
-
const
|
|
12164
|
-
if (
|
|
12802
|
+
const length = line.length;
|
|
12803
|
+
if (length < 15 || line.charCodeAt(0) !== 32) continue;
|
|
12804
|
+
let pos = 1;
|
|
12805
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
12806
|
+
const c1 = pos;
|
|
12807
|
+
while (pos < length) {
|
|
12808
|
+
const ch = line.charCodeAt(pos);
|
|
12809
|
+
if (ch === 32 || ch >= 9 && ch <= 13) break;
|
|
12810
|
+
pos++;
|
|
12811
|
+
}
|
|
12812
|
+
if (pos === c1 || pos >= length || line.charCodeAt(pos) !== 32) continue;
|
|
12813
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
12814
|
+
const c2 = pos;
|
|
12815
|
+
while (pos < length) {
|
|
12816
|
+
const ch = line.charCodeAt(pos);
|
|
12817
|
+
if (!(ch >= 48 && ch <= 57 || ch >= 97 && ch <= 102)) break;
|
|
12818
|
+
pos++;
|
|
12819
|
+
}
|
|
12820
|
+
if (pos === c2 || pos >= length || line.charCodeAt(pos) !== 32) continue;
|
|
12821
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
12822
|
+
const c3 = pos;
|
|
12823
|
+
while (pos < length) {
|
|
12824
|
+
const ch = line.charCodeAt(pos);
|
|
12825
|
+
if (!(ch >= 48 && ch <= 57 || ch >= 97 && ch <= 102)) break;
|
|
12826
|
+
pos++;
|
|
12827
|
+
}
|
|
12828
|
+
if (pos === c3 || pos >= length || line.charCodeAt(pos) !== 32) continue;
|
|
12829
|
+
const sStart = pos;
|
|
12830
|
+
while (pos < length && line.charCodeAt(pos) === 32) pos++;
|
|
12831
|
+
if (pos - sStart < 9 || pos >= length) continue;
|
|
12832
|
+
const first = line.charCodeAt(pos);
|
|
12833
|
+
if (first === 47 || first === 60 || first === 32 || first >= 9 && first <= 13)
|
|
12834
|
+
continue;
|
|
12835
|
+
let end = pos + 1;
|
|
12836
|
+
while (end < length) {
|
|
12837
|
+
const ch = line.charCodeAt(end);
|
|
12838
|
+
if (ch === 32 || ch >= 9 && ch <= 13) break;
|
|
12839
|
+
end++;
|
|
12840
|
+
}
|
|
12841
|
+
names.add(line.slice(pos, end));
|
|
12165
12842
|
}
|
|
12166
12843
|
return names;
|
|
12167
12844
|
}
|
|
@@ -12260,7 +12937,7 @@ function discoverGuestLinkInputs(options) {
|
|
|
12260
12937
|
fs9.mkdirSync(options.directory, { recursive: true });
|
|
12261
12938
|
const why = path20.join(options.directory, "preselection-why.txt");
|
|
12262
12939
|
const response = path20.join(options.directory, "preselection.rsp");
|
|
12263
|
-
const output = path20.join(options.directory, "preselection.wasm");
|
|
12940
|
+
const output = process.platform !== "win32" ? "/dev/null" : path20.join(options.directory, "preselection.wasm");
|
|
12264
12941
|
const flags = [
|
|
12265
12942
|
...withOutput(args, output, true),
|
|
12266
12943
|
...options.objects,
|
|
@@ -12358,7 +13035,7 @@ function prepareGuestRuntimeInputs(options) {
|
|
|
12358
13035
|
});
|
|
12359
13036
|
return { args, selected, originalSelection, archives, sdkProducts, archiveArtifacts };
|
|
12360
13037
|
}
|
|
12361
|
-
function selectedGuestSymbolInputs(plan, selected) {
|
|
13038
|
+
function selectedGuestSymbolInputs(plan, selected, readSelected) {
|
|
12362
13039
|
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]));
|
|
12363
13040
|
const archives = /* @__PURE__ */ new Map();
|
|
12364
13041
|
const symbols = /* @__PURE__ */ new Set();
|
|
@@ -12374,22 +13051,27 @@ function selectedGuestSymbolInputs(plan, selected) {
|
|
|
12374
13051
|
if (!artifact) throw new Error(`selected symbol input has no owner ${item.artifact}`);
|
|
12375
13052
|
let bytes;
|
|
12376
13053
|
let name = item.artifact;
|
|
12377
|
-
if (item.member === null)
|
|
12378
|
-
|
|
12379
|
-
|
|
12380
|
-
if (
|
|
12381
|
-
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
)
|
|
12385
|
-
|
|
13054
|
+
if (item.member === null) {
|
|
13055
|
+
bytes = readSelected ? readSelected(item) : fs9.readFileSync(item.artifact);
|
|
13056
|
+
} else {
|
|
13057
|
+
if (readSelected) {
|
|
13058
|
+
bytes = readSelected(item);
|
|
13059
|
+
} else {
|
|
13060
|
+
let members = archives.get(item.artifact);
|
|
13061
|
+
if (!members) {
|
|
13062
|
+
members = Map.groupBy(
|
|
13063
|
+
readArMembers(fs9.readFileSync(item.artifact)),
|
|
13064
|
+
(member) => member.name
|
|
13065
|
+
);
|
|
13066
|
+
archives.set(item.artifact, members);
|
|
13067
|
+
}
|
|
13068
|
+
const matching = members.get(item.member) ?? [];
|
|
13069
|
+
if (matching.length !== 1)
|
|
13070
|
+
throw new Error(
|
|
13071
|
+
`ambiguous selected symbol input ${item.artifact}(${item.member})`
|
|
13072
|
+
);
|
|
13073
|
+
bytes = matching[0].bytes;
|
|
12386
13074
|
}
|
|
12387
|
-
const matching = members.get(item.member) ?? [];
|
|
12388
|
-
if (matching.length !== 1)
|
|
12389
|
-
throw new Error(
|
|
12390
|
-
`ambiguous selected symbol input ${item.artifact}(${item.member})`
|
|
12391
|
-
);
|
|
12392
|
-
bytes = matching[0].bytes;
|
|
12393
13075
|
name += `(${item.member})`;
|
|
12394
13076
|
}
|
|
12395
13077
|
if (owners.has(name)) throw new Error(`duplicate selected symbol input ${name}`);
|
|
@@ -12402,9 +13084,9 @@ function selectedGuestSymbolInputs(plan, selected) {
|
|
|
12402
13084
|
for (const symbol of names.tags) tags.add(symbol);
|
|
12403
13085
|
for (const symbol of names.defined) {
|
|
12404
13086
|
definitions.add(symbol);
|
|
12405
|
-
|
|
13087
|
+
let objects = definitionObjects.get(symbol);
|
|
13088
|
+
if (!objects) definitionObjects.set(symbol, objects = /* @__PURE__ */ new Set());
|
|
12406
13089
|
objects.add(name);
|
|
12407
|
-
definitionObjects.set(symbol, objects);
|
|
12408
13090
|
}
|
|
12409
13091
|
}
|
|
12410
13092
|
return {
|
|
@@ -12425,7 +13107,7 @@ function verifyGuestSymbolScopes(options) {
|
|
|
12425
13107
|
if (!symbols.length) return { bindings: [], directBindings: [] };
|
|
12426
13108
|
fs9.mkdirSync(options.directory, { recursive: true });
|
|
12427
13109
|
const response = path20.join(options.directory, "scope-trace.rsp");
|
|
12428
|
-
const output = path20.join(options.directory, "scope-trace.wasm");
|
|
13110
|
+
const output = process.platform !== "win32" ? "/dev/null" : path20.join(options.directory, "scope-trace.wasm");
|
|
12429
13111
|
const args = [
|
|
12430
13112
|
...withOutput(normalizedGuestLinkArgs(options.args), output, true),
|
|
12431
13113
|
...options.objects,
|
|
@@ -12443,55 +13125,76 @@ function verifyGuestSymbolScopes(options) {
|
|
|
12443
13125
|
fs9.closeSync(traceOutput);
|
|
12444
13126
|
}
|
|
12445
13127
|
const records = /* @__PURE__ */ new Map();
|
|
12446
|
-
const
|
|
12447
|
-
const
|
|
12448
|
-
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
const
|
|
12453
|
-
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
13128
|
+
for (const line of guestLinkLines(tracePath)) {
|
|
13129
|
+
const refSep = line.lastIndexOf(": reference to ");
|
|
13130
|
+
const defSep = line.lastIndexOf(": definition of ");
|
|
13131
|
+
if (refSep < 0 && defSep < 0) continue;
|
|
13132
|
+
const isRef = refSep > defSep;
|
|
13133
|
+
const sep = isRef ? refSep : defSep;
|
|
13134
|
+
const symbol = line.slice(sep + (isRef ? 15 : 16));
|
|
13135
|
+
if (!requested.has(symbol) || options.hostImports.has(symbol)) continue;
|
|
13136
|
+
let record = records.get(symbol);
|
|
13137
|
+
if (!record) {
|
|
13138
|
+
record = {
|
|
13139
|
+
references: /* @__PURE__ */ new Map(),
|
|
13140
|
+
providers: /* @__PURE__ */ new Map(),
|
|
13141
|
+
physicalModule: false
|
|
13142
|
+
};
|
|
13143
|
+
records.set(symbol, record);
|
|
13144
|
+
}
|
|
13145
|
+
const object2 = line.slice(0, sep);
|
|
12457
13146
|
if (object2 === "<internal>") {
|
|
12458
|
-
if (
|
|
13147
|
+
if (!isRef) record.physicalModule = true;
|
|
12459
13148
|
} else {
|
|
12460
13149
|
const image = options.owners.get(object2);
|
|
12461
13150
|
if (image === void 0)
|
|
12462
13151
|
throw new Error(`traced guest object has no owner ${object2}`);
|
|
12463
|
-
(
|
|
12464
|
-
object2,
|
|
12465
|
-
image
|
|
12466
|
-
);
|
|
13152
|
+
(isRef ? record.references : record.providers).set(object2, image);
|
|
12467
13153
|
}
|
|
12468
|
-
|
|
12469
|
-
};
|
|
12470
|
-
for (const line of guestLinkLines(tracePath)) consume(line);
|
|
13154
|
+
}
|
|
12471
13155
|
const callers = new Map(options.callers.map((caller) => [caller.image, caller.next]));
|
|
13156
|
+
const callerSets = new Map(
|
|
13157
|
+
options.callers.map((caller) => [caller.image, new Set(caller.next)])
|
|
13158
|
+
);
|
|
13159
|
+
const rootScope = callerSets.get(0);
|
|
12472
13160
|
const result = [];
|
|
12473
13161
|
const directBindings = [];
|
|
12474
13162
|
for (const symbol of symbols) {
|
|
12475
13163
|
const record = records.get(symbol);
|
|
12476
13164
|
if (!record || !record.references.size) continue;
|
|
12477
13165
|
if (!record.providers.size && options.hostImports.has(symbol)) continue;
|
|
12478
|
-
const startupReferences = [
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
const
|
|
12482
|
-
|
|
12483
|
-
|
|
13166
|
+
const startupReferences = [];
|
|
13167
|
+
const otherReferences = [];
|
|
13168
|
+
let allWeakRefs = true;
|
|
13169
|
+
for (const [object2, caller] of record.references) {
|
|
13170
|
+
const isWeakRef = options.weakReferences.get(object2)?.has(symbol) === true;
|
|
13171
|
+
if (!isWeakRef) allWeakRefs = false;
|
|
13172
|
+
if (isWeakRef && options.startupObjects.has(object2)) {
|
|
13173
|
+
startupReferences.push([object2, caller]);
|
|
13174
|
+
} else {
|
|
13175
|
+
otherReferences.push([object2, caller]);
|
|
13176
|
+
}
|
|
13177
|
+
}
|
|
12484
13178
|
for (const [, caller] of startupReferences)
|
|
12485
13179
|
if (!callers.has(caller))
|
|
12486
13180
|
throw new Error(`guest image has no caller scope ${caller}`);
|
|
12487
13181
|
if (startupReferences.length && !record.physicalModule) {
|
|
12488
|
-
const
|
|
12489
|
-
|
|
13182
|
+
const candidates2 = options.definitionObjects.get(symbol);
|
|
13183
|
+
const candidateSize = candidates2?.size ?? 0;
|
|
13184
|
+
if (candidateSize > 1 || record.providers.size > 1)
|
|
12490
13185
|
throw new Error(`ambiguous startup provider ${symbol}`);
|
|
12491
|
-
|
|
12492
|
-
|
|
13186
|
+
let unproven = candidateSize !== record.providers.size;
|
|
13187
|
+
if (!unproven && candidates2) {
|
|
13188
|
+
for (const object2 of record.providers.keys()) {
|
|
13189
|
+
if (!candidates2.has(object2)) {
|
|
13190
|
+
unproven = true;
|
|
13191
|
+
break;
|
|
13192
|
+
}
|
|
13193
|
+
}
|
|
13194
|
+
}
|
|
13195
|
+
if (unproven) throw new Error(`unproven startup provider ${symbol}`);
|
|
12493
13196
|
if (record.providers.size === 1) {
|
|
12494
|
-
const [providerObject, providerImage] =
|
|
13197
|
+
const [providerObject, providerImage] = record.providers.entries().next().value;
|
|
12495
13198
|
if (options.weakDefinitions.get(providerObject)?.has(symbol))
|
|
12496
13199
|
throw new Error(`weak startup provider ${symbol}`);
|
|
12497
13200
|
for (const [object2] of startupReferences)
|
|
@@ -12499,28 +13202,34 @@ function verifyGuestSymbolScopes(options) {
|
|
|
12499
13202
|
}
|
|
12500
13203
|
if (!otherReferences.length) continue;
|
|
12501
13204
|
}
|
|
12502
|
-
if (!record.providers.size && !record.physicalModule &&
|
|
12503
|
-
(object2) => options.weakReferences.get(object2)?.has(symbol)
|
|
12504
|
-
))
|
|
12505
|
-
continue;
|
|
13205
|
+
if (!record.providers.size && !record.physicalModule && allWeakRefs) continue;
|
|
12506
13206
|
const providerImages = new Set(record.providers.values());
|
|
12507
|
-
const
|
|
12508
|
-
|
|
13207
|
+
const candidates = options.definitionObjects.get(symbol);
|
|
13208
|
+
const copyImages = /* @__PURE__ */ new Set();
|
|
13209
|
+
const strongImages = /* @__PURE__ */ new Set();
|
|
13210
|
+
let weakDefinerImages;
|
|
13211
|
+
if (candidates) {
|
|
13212
|
+
for (const object2 of candidates) {
|
|
12509
13213
|
const image = options.owners.get(object2);
|
|
12510
|
-
|
|
13214
|
+
if (image === void 0) continue;
|
|
13215
|
+
copyImages.add(image);
|
|
13216
|
+
if (options.weakDefinitions.get(object2)?.has(symbol)) {
|
|
13217
|
+
;
|
|
13218
|
+
(weakDefinerImages ?? (weakDefinerImages = /* @__PURE__ */ new Set())).add(image);
|
|
13219
|
+
} else {
|
|
13220
|
+
strongImages.add(image);
|
|
13221
|
+
}
|
|
12511
13222
|
}
|
|
12512
|
-
|
|
12513
|
-
const copyImages = new Set(copies.map((copy) => copy.image));
|
|
12514
|
-
const strongImages = new Set(
|
|
12515
|
-
copies.filter((copy) => !copy.weak).map((copy) => copy.image)
|
|
12516
|
-
);
|
|
13223
|
+
}
|
|
12517
13224
|
const interposed = !record.physicalModule && copyImages.size > 1;
|
|
12518
13225
|
const providerCount = interposed ? 1 : providerImages.size + Number(record.physicalModule);
|
|
12519
13226
|
if (!providerCount) continue;
|
|
12520
13227
|
if (providerCount !== 1)
|
|
12521
13228
|
throw new Error(`guest symbol has ambiguous provider ${symbol}`);
|
|
12522
|
-
const scopedReferences = record.physicalModule ?
|
|
12523
|
-
const
|
|
13229
|
+
const scopedReferences = record.physicalModule ? record.references : otherReferences;
|
|
13230
|
+
const firstProviderImage = providerImages.values().next().value;
|
|
13231
|
+
const uniqueProvider = strongImages.size > 1 ? void 0 : strongImages.values().next().value ?? firstProviderImage;
|
|
13232
|
+
let interposedByCaller;
|
|
12524
13233
|
for (const [object2, caller] of scopedReferences) {
|
|
12525
13234
|
const scope = callers.get(caller);
|
|
12526
13235
|
if (!scope) throw new Error(`guest image has no caller scope ${caller}`);
|
|
@@ -12528,18 +13237,35 @@ function verifyGuestSymbolScopes(options) {
|
|
|
12528
13237
|
result.push({ symbol, caller, provider: { kind: "physical-module" } });
|
|
12529
13238
|
continue;
|
|
12530
13239
|
}
|
|
12531
|
-
|
|
13240
|
+
let provider;
|
|
13241
|
+
if (interposed) {
|
|
13242
|
+
if (interposedByCaller?.has(caller)) {
|
|
13243
|
+
provider = interposedByCaller.get(caller);
|
|
13244
|
+
} else {
|
|
13245
|
+
if (copyImages.has(caller)) {
|
|
13246
|
+
provider = caller;
|
|
13247
|
+
} else {
|
|
13248
|
+
for (const image of scope) {
|
|
13249
|
+
if (copyImages.has(image)) {
|
|
13250
|
+
provider = image;
|
|
13251
|
+
break;
|
|
13252
|
+
}
|
|
13253
|
+
}
|
|
13254
|
+
if (provider === void 0) provider = uniqueProvider;
|
|
13255
|
+
}
|
|
13256
|
+
;
|
|
13257
|
+
(interposedByCaller ?? (interposedByCaller = /* @__PURE__ */ new Map())).set(caller, provider);
|
|
13258
|
+
}
|
|
13259
|
+
} else {
|
|
13260
|
+
provider = firstProviderImage;
|
|
13261
|
+
}
|
|
12532
13262
|
if (provider === void 0) {
|
|
12533
13263
|
if (options.weakReferences.get(object2)?.has(symbol)) continue;
|
|
12534
13264
|
throw new Error(`guest scope ${caller} omits every provider of ${symbol}`);
|
|
12535
13265
|
}
|
|
12536
13266
|
if (caller === provider) continue;
|
|
12537
|
-
if (
|
|
12538
|
-
|
|
12539
|
-
))
|
|
12540
|
-
continue;
|
|
12541
|
-
if (!scope.includes(provider)) {
|
|
12542
|
-
const candidates = options.definitionObjects.get(symbol) ?? /* @__PURE__ */ new Set();
|
|
13267
|
+
if (weakDefinerImages?.has(caller)) continue;
|
|
13268
|
+
if (!callerSets.get(caller).has(provider)) {
|
|
12543
13269
|
const traced = [...record.providers.keys()];
|
|
12544
13270
|
const strongTraced = traced.filter(
|
|
12545
13271
|
(definer) => !options.weakDefinitions.get(definer)?.has(symbol)
|
|
@@ -12547,16 +13273,17 @@ function verifyGuestSymbolScopes(options) {
|
|
|
12547
13273
|
const providers = strongTraced.length === 1 ? strongTraced : traced;
|
|
12548
13274
|
if (options.weakReferences.get(object2)?.has(symbol) && !providers.some((provider2) => options.systemProviders.has(provider2)))
|
|
12549
13275
|
continue;
|
|
12550
|
-
const
|
|
13276
|
+
const candidateSet = candidates ?? /* @__PURE__ */ new Set();
|
|
13277
|
+
const equivalentCopies = providers.length === 1 && candidateSet.has(providers[0]) && [...candidateSet].every(
|
|
12551
13278
|
(definer) => options.weakDefinitions.get(definer)?.has(symbol)
|
|
12552
13279
|
);
|
|
12553
|
-
const strongCandidates = [...
|
|
13280
|
+
const strongCandidates = [...candidateSet].filter(
|
|
12554
13281
|
(definer) => !options.weakDefinitions.get(definer)?.has(symbol)
|
|
12555
13282
|
);
|
|
12556
|
-
const soleCandidate =
|
|
12557
|
-
if (!equivalentCopies && (!soleCandidate || providers.length !== 1 || !
|
|
13283
|
+
const soleCandidate = candidateSet.size === 1 || strongCandidates.length === 1 && strongCandidates[0] === providers[0];
|
|
13284
|
+
if (!equivalentCopies && (!soleCandidate || providers.length !== 1 || !candidateSet.has(providers[0]) || !(options.systemProviders.has(providers[0]) || // a strong undefined reference binds through the process global
|
|
12558
13285
|
// scope, the root image and its dependency closure, as in elf.
|
|
12559
|
-
provider === 0 ||
|
|
13286
|
+
provider === 0 || rootScope?.has(provider) || !options.weakReferences.get(object2)?.has(symbol) && options.frameworkProviders.get(object2)?.has(providers[0]))))
|
|
12560
13287
|
throw new Error(
|
|
12561
13288
|
`guest scope ${caller} omits traced provider ${provider} for ${symbol}`
|
|
12562
13289
|
);
|
|
@@ -13486,7 +14213,7 @@ async function compileGuestLink(options) {
|
|
|
13486
14213
|
};
|
|
13487
14214
|
const sdk = options.sdkImage;
|
|
13488
14215
|
const sdkCallers = sdk?.sdkInterface.guestCallers;
|
|
13489
|
-
const sdkObjects = sdk ? (await import("./swift-sdk-image-
|
|
14216
|
+
const sdkObjects = sdk ? (await import("./swift-sdk-image-WAC7GG2R.mjs")).readSwiftSdkManifestIndex(sdk).guestObjects : void 0;
|
|
13490
14217
|
if (sdk && (!sdkCallers || !sdkObjects))
|
|
13491
14218
|
throw new Error("the SDK image has no guest link manifest");
|
|
13492
14219
|
const result = linkPrunedGuestImages({
|
|
@@ -13692,9 +14419,9 @@ async function compileGuestLink(options) {
|
|
|
13692
14419
|
}
|
|
13693
14420
|
};
|
|
13694
14421
|
},
|
|
13695
|
-
resolvePlan: (selected, plan) => {
|
|
14422
|
+
resolvePlan: (selected, plan, readSelected) => {
|
|
13696
14423
|
if (!prepared) throw new Error("guest runtime selection is unavailable");
|
|
13697
|
-
const scope = selectedGuestSymbolInputs(plan, selected);
|
|
14424
|
+
const scope = selectedGuestSymbolInputs(plan, selected, readSelected);
|
|
13698
14425
|
const owners = new Map(scope.owners);
|
|
13699
14426
|
owners.set(path24.join(directory, "projection-discovery.o"), 0);
|
|
13700
14427
|
const providersByImage = Map.groupBy(scope.owners, ([, image]) => image);
|
|
@@ -13773,7 +14500,7 @@ async function compileGuestLink(options) {
|
|
|
13773
14500
|
finishSwiftAppModule,
|
|
13774
14501
|
linkSwiftAppModule,
|
|
13775
14502
|
readSwiftSdkUsage
|
|
13776
|
-
} = await import("./swift-sdk-app-module-
|
|
14503
|
+
} = await import("./swift-sdk-app-module-6H3G6AXD.mjs");
|
|
13777
14504
|
const project = options.project;
|
|
13778
14505
|
const work = project ? mkdtempSync2(path24.join(directory, "app-module-")) : path24.join(directory, "app-module");
|
|
13779
14506
|
if (project) chownSync(work, project.uid, project.gid);
|
|
@@ -16333,7 +17060,7 @@ var darwinRecordsRegion = (quoted2) => quoted2.length ? ["-Wl,--start-lib", ...q
|
|
|
16333
17060
|
var REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
|
|
16334
17061
|
var MULTI_MANIFEST_VERSION = 76;
|
|
16335
17062
|
var SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
|
|
16336
|
-
var compilerSourceDigest = true ? "
|
|
17063
|
+
var compilerSourceDigest = true ? "7b91fa4405159335b5484c82700e001e4c27abf15621b724ea8af4edea693f66" : swiftCompilerSourceDigest(import.meta.dirname);
|
|
16337
17064
|
function swiftArtifactHash(input, release, moduleRoot) {
|
|
16338
17065
|
return swiftCompileInputHash(input, release).update(swiftModuleDigest(moduleRoot)).digest("hex");
|
|
16339
17066
|
}
|
|
@@ -20934,7 +21661,7 @@ async function compileSwiftProjectOnce(sources, options) {
|
|
|
20934
21661
|
const distribution = swiftDistributionAt(moduleRoot);
|
|
20935
21662
|
const mirrorDistribution = options.linkOnly || options.project ? null : distribution;
|
|
20936
21663
|
if (distribution) refreshSwiftCacheHold(moduleRoot);
|
|
20937
|
-
const input = distribution && !options.intermediates ? (await import("./swift-package-prebuilt-
|
|
21664
|
+
const input = distribution && !options.intermediates ? (await import("./swift-package-prebuilt-5XDZ2HZZ.mjs")).useSwiftPackagePrebuilts(
|
|
20938
21665
|
sources,
|
|
20939
21666
|
moduleRoot,
|
|
20940
21667
|
options.toolchainBin
|
|
@@ -20948,7 +21675,7 @@ async function compileSwiftProjectOnce(sources, options) {
|
|
|
20948
21675
|
multi: compileTargets(input).length > 0
|
|
20949
21676
|
};
|
|
20950
21677
|
const sdkModule = options.sdkModule && !options.linkOnly;
|
|
20951
|
-
const sdkImage = sdkModule ? await (await import("./swift-sdk-image-
|
|
21678
|
+
const sdkImage = sdkModule ? await (await import("./swift-sdk-image-WAC7GG2R.mjs")).buildSwiftSdkImage(
|
|
20952
21679
|
moduleRoot,
|
|
20953
21680
|
!!guestGraph,
|
|
20954
21681
|
distribution ? [] : linkedFrameworkTargets(moduleRoot, input).imports,
|
|
@@ -21605,7 +22332,7 @@ ${cap}` : "";
|
|
|
21605
22332
|
if (sdkImage && binding)
|
|
21606
22333
|
sdkAsset = { key: sdkImage.key, sha256: sdkImage.sha256, binding };
|
|
21607
22334
|
} else if (sdkImage) {
|
|
21608
|
-
const { buildSwiftAppModule } = await import("./swift-sdk-app-module-
|
|
22335
|
+
const { buildSwiftAppModule } = await import("./swift-sdk-app-module-6H3G6AXD.mjs");
|
|
21609
22336
|
const binding = await buildSwiftAppModule({
|
|
21610
22337
|
buildRoot: root,
|
|
21611
22338
|
toolchainBin: options.toolchainBin,
|