peachsim 0.1.2600 → 0.1.2602
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/cli/commands/detect.ts +16 -10
- 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 +11432 -11074
- 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 +11 -2276
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/esm-chunks/{acorn-FGRSVFK5.mjs → acorn-OY6WD7QV.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-GTJLYHLX.mjs → chunk-4RQOWOMT.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-RFLRGBWJ.mjs → chunk-7T3ACQVD.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-ZPZHTSVV.mjs → chunk-A4ONOIAH.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-7VUNHZJ4.mjs → chunk-DW7F2DCV.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-F72K7HJL.mjs → chunk-FTNF3J4Y.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-DB24TNAU.mjs → chunk-GCFOJXHC.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-23YC72IU.mjs → chunk-HA4NBBPR.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-66EJ2CSG.mjs → chunk-I47W3MVR.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-GNN4EGGX.mjs → chunk-I7DN6IVP.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-R5YW43IZ.mjs → chunk-IH7VXRII.mjs} +4 -4
- package/dist-lib/esm-chunks/{chunk-CC6C72OW.mjs → chunk-IUZHDZYD.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-FQRSMKOT.mjs → chunk-JFRVR54X.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-46MZJPMK.mjs → chunk-K5IL7A47.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-BVRFDE5A.mjs → chunk-OPEVMW4Z.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-C2BC7GUJ.mjs → chunk-PRC3KSZK.mjs} +2 -2
- package/dist-lib/esm-chunks/{chunk-7O5GHZNG.mjs → chunk-QREYIKY5.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-IEXENIW2.mjs → chunk-RS3CUH42.mjs} +3 -3
- package/dist-lib/esm-chunks/{chunk-IANEFUXF.mjs → chunk-T22TWE3B.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-LLIEH2SU.mjs → chunk-T6MXHYHI.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-T7BVUONU.mjs → chunk-VZORKVTY.mjs} +1 -1
- package/dist-lib/esm-chunks/{chunk-C3YFMHVW.mjs → chunk-WKCN2CSK.mjs} +5 -5
- package/dist-lib/esm-chunks/{chunk-G2OL3VLT.mjs → chunk-ZDI63AW4.mjs} +1024 -653
- package/dist-lib/esm-chunks/{metro-layout-parser-WVDFEJTE.mjs → metro-layout-parser-2ERWNLZ7.mjs} +3 -3
- package/dist-lib/esm-chunks/{swift-package-prebuilt-FRKYWMMQ.mjs → swift-package-prebuilt-SP4MCJOF.mjs} +10 -10
- package/dist-lib/esm-chunks/{swift-sdk-app-module-TMDS6TCR.mjs → swift-sdk-app-module-LXIPYGVM.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-73TU5HWR.mjs → swift-sdk-image-RTRI5IV4.mjs} +14 -14
- package/dist-lib/esm-chunks/{swift-sdk-image-producer-WJTPYSJ4.mjs → swift-sdk-image-producer-7NXHRRJE.mjs} +4 -4
- package/dist-lib/expo-swift-bundle.cjs +12833 -12475
- 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 +12809 -12451
- package/dist-lib/host/fetch-proxy-handler.cjs +5434 -5422
- 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 +10 -2275
- 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 +23 -11
- 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 +82 -81
- package/dist-lib/public-origins-lib.json +372 -429
- 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 +1093 -735
- package/dist-lib/swift-compile.cjs +1029 -652
- 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/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/java-platform/licenses/android.txt +3 -0
- package/java-platform/licenses/openjdk.txt +9 -2
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -2
- package/src/device-catalog.ts +4 -5
- package/src/ios-version.ts +8 -0
- package/src/swift-guest-compile.ts +5 -3
- package/src/swift-guest-image-ledger.ts +563 -264
- package/src/swift-guest-link.ts +628 -468
- package/src/wasm-binary-sections.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! peach v0.1.
|
|
1
|
+
/*! peach v0.1.2602 | (c) 2026 Tamagui LLC | Proprietary; see LICENSE */
|
|
2
2
|
let __sootsim_import_meta_url = '', __sootsim_import_meta_dirname = '', __sootsim_import_meta_filename = ''; try { __sootsim_import_meta_url = require('url').pathToFileURL(__filename).href; __sootsim_import_meta_dirname = __dirname; __sootsim_import_meta_filename = __filename; } catch {}
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
@@ -10741,13 +10741,24 @@ function llvmType(value) {
|
|
|
10741
10741
|
throw new Error(`unsupported wasm function value type ${value}`);
|
|
10742
10742
|
}
|
|
10743
10743
|
}
|
|
10744
|
+
function concatParts(parts) {
|
|
10745
|
+
let total = 0;
|
|
10746
|
+
for (let i = 0; i < parts.length; i++) total += parts[i].byteLength;
|
|
10747
|
+
const out = Buffer.allocUnsafe(total);
|
|
10748
|
+
let offset = 0;
|
|
10749
|
+
for (let i = 0; i < parts.length; i++) {
|
|
10750
|
+
const part = parts[i];
|
|
10751
|
+
out.set(part, offset);
|
|
10752
|
+
offset += part.byteLength;
|
|
10753
|
+
}
|
|
10754
|
+
return out;
|
|
10755
|
+
}
|
|
10744
10756
|
function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLookups, preserveCanonical, options = {}) {
|
|
10745
10757
|
if (!isWasmMagic(bytes)) throw new Error("expected wasm object");
|
|
10746
10758
|
const rawBuf = Buffer.isBuffer(bytes) ? bytes : Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
10747
|
-
const { sdkLookupOnly, sdkProduct, collectRewrittenSymbols } = options;
|
|
10759
|
+
const { sdkLookupOnly, sdkProduct, collectRewrittenSymbols, scan: scan2 } = options;
|
|
10748
10760
|
const comdatScope = sdkProduct === void 0 ? callerAlias : `${callerAlias}:${sdkProduct}`;
|
|
10749
10761
|
const rewrite = binding !== void 0;
|
|
10750
|
-
const sections = rewrite ? [bytes.subarray(0, 8)] : void 0;
|
|
10751
10762
|
const types = [];
|
|
10752
10763
|
const functionTypes = [];
|
|
10753
10764
|
const definitions = [];
|
|
@@ -10758,10 +10769,344 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
10758
10769
|
const eventImportNames = [];
|
|
10759
10770
|
const functionSymbols = [];
|
|
10760
10771
|
const addressTaken = /* @__PURE__ */ new Set();
|
|
10761
|
-
let usesDlsym = false;
|
|
10762
|
-
let usesDlerror = false;
|
|
10772
|
+
let usesDlsym = scan2?.usesDlsym ?? false;
|
|
10773
|
+
let usesDlerror = scan2?.usesDlerror ?? false;
|
|
10763
10774
|
const dlerrorAlias = sdkLookupOnly ? "__peach_sdk_dlerror" : "__peach_dlerror";
|
|
10764
10775
|
const usedSymbols = /* @__PURE__ */ new Set();
|
|
10776
|
+
const rewriteImportSection = (start, end) => {
|
|
10777
|
+
let offset = start;
|
|
10778
|
+
const number3 = () => {
|
|
10779
|
+
if (offset < end) {
|
|
10780
|
+
const first = bytes[offset];
|
|
10781
|
+
if (first < 128) {
|
|
10782
|
+
offset++;
|
|
10783
|
+
return first;
|
|
10784
|
+
}
|
|
10785
|
+
}
|
|
10786
|
+
let value = 0;
|
|
10787
|
+
let shift = 0;
|
|
10788
|
+
for (; ; ) {
|
|
10789
|
+
if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
|
|
10790
|
+
const byte = bytes[offset++];
|
|
10791
|
+
value += (byte & 127) * 2 ** shift;
|
|
10792
|
+
if (!(byte & 128)) return value;
|
|
10793
|
+
shift += 7;
|
|
10794
|
+
}
|
|
10795
|
+
};
|
|
10796
|
+
const string5 = () => {
|
|
10797
|
+
const length = number3();
|
|
10798
|
+
const strEnd = offset + length;
|
|
10799
|
+
if (strEnd > end) throw new Error("invalid wasm string");
|
|
10800
|
+
const value = rawBuf.toString("utf8", offset, strEnd);
|
|
10801
|
+
offset = strEnd;
|
|
10802
|
+
return value;
|
|
10803
|
+
};
|
|
10804
|
+
const count = number3();
|
|
10805
|
+
const importWriter = new ByteWriter(end - start + 64);
|
|
10806
|
+
importWriter.uleb(count);
|
|
10807
|
+
for (let i = 0; i < count; i++) {
|
|
10808
|
+
const entryStart = offset;
|
|
10809
|
+
const module2 = string5();
|
|
10810
|
+
const nameStart = offset;
|
|
10811
|
+
const name3 = string5();
|
|
10812
|
+
const nameEnd = offset;
|
|
10813
|
+
const kind = bytes[offset++];
|
|
10814
|
+
if (kind === 0) {
|
|
10815
|
+
number3();
|
|
10816
|
+
if (collectRewrittenSymbols) functionImportNames.push(name3);
|
|
10817
|
+
} else if (kind === 1) {
|
|
10818
|
+
const referenceType = bytes[offset++];
|
|
10819
|
+
if (referenceType !== 112 && referenceType !== 111)
|
|
10820
|
+
throw new Error("unsupported table type");
|
|
10821
|
+
const flags = number3();
|
|
10822
|
+
if (flags & ~7) throw new Error("unsupported table limits");
|
|
10823
|
+
number3();
|
|
10824
|
+
if (flags & 1) number3();
|
|
10825
|
+
} else if (kind === 2) {
|
|
10826
|
+
const flags = number3();
|
|
10827
|
+
if (flags & ~7) throw new Error("unsupported memory limits");
|
|
10828
|
+
number3();
|
|
10829
|
+
if (flags & 1) number3();
|
|
10830
|
+
} else if (kind === 3) offset += 2;
|
|
10831
|
+
else if (kind === 4) {
|
|
10832
|
+
number3();
|
|
10833
|
+
number3();
|
|
10834
|
+
} else throw new Error("unsupported wasm import");
|
|
10835
|
+
const isDlsym = instrumentDynamicLookups && module2 === "env" && name3 === "dlsym" && kind === 0;
|
|
10836
|
+
const isDlerror = instrumentDynamicLookups && module2 === "env" && name3 === "dlerror" && kind === 0;
|
|
10837
|
+
const rewrittenName = isDlsym ? callerAlias : isDlerror ? dlerrorAlias : module2 === "env" && name3 !== "dlsym" && name3 !== "dlerror" ? binding(name3) ?? name3 : name3;
|
|
10838
|
+
if (rewrittenName === name3) {
|
|
10839
|
+
importWriter.bytes(bytes, entryStart, offset);
|
|
10840
|
+
} else {
|
|
10841
|
+
importWriter.bytes(bytes, entryStart, nameStart);
|
|
10842
|
+
importWriter.string(rewrittenName);
|
|
10843
|
+
importWriter.bytes(bytes, nameEnd, offset);
|
|
10844
|
+
}
|
|
10845
|
+
if (collectRewrittenSymbols) {
|
|
10846
|
+
if (kind === 0)
|
|
10847
|
+
functionImportNames[functionImportNames.length - 1] = rewrittenName;
|
|
10848
|
+
else if (kind === 1) tableImportNames.push(rewrittenName);
|
|
10849
|
+
else if (kind === 3) globalImportNames.push(rewrittenName);
|
|
10850
|
+
else if (kind === 4) eventImportNames.push(rewrittenName);
|
|
10851
|
+
}
|
|
10852
|
+
}
|
|
10853
|
+
if (offset !== end) throw new Error("invalid wasm import section");
|
|
10854
|
+
return importWriter.finish();
|
|
10855
|
+
};
|
|
10856
|
+
const rewriteLinkingSection = (start, end) => {
|
|
10857
|
+
let offset = start;
|
|
10858
|
+
const number3 = () => {
|
|
10859
|
+
if (offset < end) {
|
|
10860
|
+
const first = bytes[offset];
|
|
10861
|
+
if (first < 128) {
|
|
10862
|
+
offset++;
|
|
10863
|
+
return first;
|
|
10864
|
+
}
|
|
10865
|
+
}
|
|
10866
|
+
let value = 0;
|
|
10867
|
+
let shift = 0;
|
|
10868
|
+
for (; ; ) {
|
|
10869
|
+
if (offset >= end || shift > 63) throw new Error("invalid wasm integer");
|
|
10870
|
+
const byte = bytes[offset++];
|
|
10871
|
+
value += (byte & 127) * 2 ** shift;
|
|
10872
|
+
if (!(byte & 128)) return value;
|
|
10873
|
+
shift += 7;
|
|
10874
|
+
}
|
|
10875
|
+
};
|
|
10876
|
+
const string5 = () => {
|
|
10877
|
+
const length = number3();
|
|
10878
|
+
const strEnd = offset + length;
|
|
10879
|
+
if (strEnd > end) throw new Error("invalid wasm string");
|
|
10880
|
+
const value = rawBuf.toString("utf8", offset, strEnd);
|
|
10881
|
+
offset = strEnd;
|
|
10882
|
+
return value;
|
|
10883
|
+
};
|
|
10884
|
+
const sectionName = string5();
|
|
10885
|
+
const version2 = number3();
|
|
10886
|
+
if (version2 !== 2) throw new Error("unsupported wasm linking version");
|
|
10887
|
+
const subsections = [];
|
|
10888
|
+
let objcLoader;
|
|
10889
|
+
while (offset < end) {
|
|
10890
|
+
const kind = bytes[offset++];
|
|
10891
|
+
const length = number3();
|
|
10892
|
+
const stop = offset + length;
|
|
10893
|
+
if (stop > end) throw new Error("invalid linking subsection");
|
|
10894
|
+
const contentStart = offset;
|
|
10895
|
+
if (kind === 7 && !sdkLookupOnly) {
|
|
10896
|
+
const comdatWriter = new ByteWriter(length + 64);
|
|
10897
|
+
const count = number3();
|
|
10898
|
+
comdatWriter.uleb(count);
|
|
10899
|
+
for (let i = 0; i < count; i++) {
|
|
10900
|
+
const group = string5();
|
|
10901
|
+
const begin = offset;
|
|
10902
|
+
number3();
|
|
10903
|
+
const members = number3();
|
|
10904
|
+
for (let member = 0; member < members * 2; member++) number3();
|
|
10905
|
+
comdatWriter.string(
|
|
10906
|
+
group === OBJC_INIT_RECORD ? group : `${comdatScope}:${group}`
|
|
10907
|
+
);
|
|
10908
|
+
comdatWriter.bytes(bytes, begin, offset);
|
|
10909
|
+
}
|
|
10910
|
+
if (offset !== stop) throw new Error("invalid comdat subsection");
|
|
10911
|
+
const buf = comdatWriter.finish();
|
|
10912
|
+
subsections.push({ kind, parts: [buf], byteLength: buf.length });
|
|
10913
|
+
} else if (kind === 8) {
|
|
10914
|
+
const entryWriter = new ByteWriter(length + 128);
|
|
10915
|
+
let extraWriter;
|
|
10916
|
+
const count = number3();
|
|
10917
|
+
let added = 0;
|
|
10918
|
+
for (let i = 0; i < count; i++) {
|
|
10919
|
+
const begin = offset;
|
|
10920
|
+
const symbolKind = bytes[offset++];
|
|
10921
|
+
const flags = number3();
|
|
10922
|
+
const flagsEnd = offset;
|
|
10923
|
+
let index = -1;
|
|
10924
|
+
let name3 = "";
|
|
10925
|
+
let nameStart = -1;
|
|
10926
|
+
let nameEnd = -1;
|
|
10927
|
+
const isLocalDefined = !(flags & 16) && (flags & 3) === 2;
|
|
10928
|
+
if (symbolKind === 0 || symbolKind === 2 || symbolKind === 4 || symbolKind === 5) {
|
|
10929
|
+
index = number3();
|
|
10930
|
+
if (!(flags & 16) || flags & 64) {
|
|
10931
|
+
nameStart = offset;
|
|
10932
|
+
const nameLen = number3();
|
|
10933
|
+
nameEnd = offset + nameLen;
|
|
10934
|
+
if (nameEnd > end) throw new Error("invalid wasm string");
|
|
10935
|
+
if (!isLocalDefined || !sdkLookupOnly && symbolKind === 0 && nameLen === OBJC_LOAD_FUNCTION.length) {
|
|
10936
|
+
name3 = rawBuf.toString("utf8", offset, nameEnd);
|
|
10937
|
+
}
|
|
10938
|
+
offset = nameEnd;
|
|
10939
|
+
}
|
|
10940
|
+
} else if (symbolKind === 1) {
|
|
10941
|
+
nameStart = offset;
|
|
10942
|
+
const nameLen = number3();
|
|
10943
|
+
nameEnd = offset + nameLen;
|
|
10944
|
+
if (nameEnd > end) throw new Error("invalid wasm string");
|
|
10945
|
+
if (!isLocalDefined) name3 = rawBuf.toString("utf8", offset, nameEnd);
|
|
10946
|
+
offset = nameEnd;
|
|
10947
|
+
if (!(flags & 16)) {
|
|
10948
|
+
if ((flags & 3) !== 3) {
|
|
10949
|
+
number3();
|
|
10950
|
+
number3();
|
|
10951
|
+
}
|
|
10952
|
+
number3();
|
|
10953
|
+
if ((flags & 3) === 3) offset++;
|
|
10954
|
+
}
|
|
10955
|
+
} else if (symbolKind === 3) number3();
|
|
10956
|
+
else throw new Error("unsupported wasm symbol kind");
|
|
10957
|
+
if (!sdkLookupOnly && symbolKind === 0 && !(flags & 16) && name3 === OBJC_LOAD_FUNCTION) {
|
|
10958
|
+
objcLoader = i;
|
|
10959
|
+
}
|
|
10960
|
+
if (isLocalDefined) {
|
|
10961
|
+
entryWriter.bytes(bytes, begin, offset);
|
|
10962
|
+
continue;
|
|
10963
|
+
}
|
|
10964
|
+
let rewrittenSym = name3;
|
|
10965
|
+
let addedCanonical;
|
|
10966
|
+
let bound;
|
|
10967
|
+
let alias;
|
|
10968
|
+
if ((name3 === "dlsym" && usesDlsym || name3 === "dlerror" && usesDlerror) && flags & 16 && flags & 64 && symbolKind === 0) {
|
|
10969
|
+
rewrittenSym = name3 === "dlsym" ? callerAlias : dlerrorAlias;
|
|
10970
|
+
entryWriter.bytes(bytes, begin, nameStart);
|
|
10971
|
+
entryWriter.string(rewrittenSym);
|
|
10972
|
+
entryWriter.bytes(bytes, nameEnd, offset);
|
|
10973
|
+
} else if (flags & 16 && name3 !== "dlsym" && name3 !== "dlerror" && (bound = binding(name3)) !== void 0) {
|
|
10974
|
+
rewrittenSym = bound;
|
|
10975
|
+
entryWriter.bytes(bytes, begin, nameStart);
|
|
10976
|
+
entryWriter.string(rewrittenSym);
|
|
10977
|
+
entryWriter.bytes(bytes, nameEnd, offset);
|
|
10978
|
+
} else if (!(flags & 16) && (alias = names.get(name3)) !== void 0) {
|
|
10979
|
+
if (symbolKind !== 0 && symbolKind !== 1)
|
|
10980
|
+
throw new Error(`unsupported symbol ${name3}`);
|
|
10981
|
+
if (preserveCanonical.has(name3)) {
|
|
10982
|
+
entryWriter.bytes(bytes, begin, offset);
|
|
10983
|
+
extraWriter ??= new ByteWriter(256);
|
|
10984
|
+
extraWriter.byte(bytes[begin]);
|
|
10985
|
+
extraWriter.uleb(flags & ~32);
|
|
10986
|
+
extraWriter.bytes(bytes, flagsEnd, nameStart);
|
|
10987
|
+
extraWriter.string(alias);
|
|
10988
|
+
extraWriter.bytes(bytes, nameEnd, offset);
|
|
10989
|
+
added++;
|
|
10990
|
+
addedCanonical = alias;
|
|
10991
|
+
} else {
|
|
10992
|
+
rewrittenSym = alias;
|
|
10993
|
+
entryWriter.bytes(bytes, begin, nameStart);
|
|
10994
|
+
entryWriter.string(alias);
|
|
10995
|
+
entryWriter.bytes(bytes, nameEnd, offset);
|
|
10996
|
+
}
|
|
10997
|
+
} else {
|
|
10998
|
+
entryWriter.bytes(bytes, begin, offset);
|
|
10999
|
+
}
|
|
11000
|
+
if (collectRewrittenSymbols) {
|
|
11001
|
+
if (flags & 16) {
|
|
11002
|
+
const resolved = flags & 64 || symbolKind === 1 ? rewrittenSym : symbolKind === 0 ? functionImportNames[index] ?? "" : symbolKind === 2 ? globalImportNames[index] ?? "" : symbolKind === 4 ? eventImportNames[index] ?? "" : symbolKind === 5 ? tableImportNames[index] ?? "" : "";
|
|
11003
|
+
if (resolved) collectRewrittenSymbols.referenced.add(resolved);
|
|
11004
|
+
} else {
|
|
11005
|
+
if (rewrittenSym) collectRewrittenSymbols.defined.add(rewrittenSym);
|
|
11006
|
+
if (addedCanonical) collectRewrittenSymbols.defined.add(addedCanonical);
|
|
11007
|
+
}
|
|
11008
|
+
}
|
|
11009
|
+
}
|
|
11010
|
+
if (offset !== stop) throw new Error("invalid symbol subsection");
|
|
11011
|
+
const countBytes = encodeNumber(count + added);
|
|
11012
|
+
const entryBuf = entryWriter.finish();
|
|
11013
|
+
if (extraWriter) {
|
|
11014
|
+
const extraBuf = extraWriter.finish();
|
|
11015
|
+
subsections.push({
|
|
11016
|
+
kind,
|
|
11017
|
+
parts: [countBytes, entryBuf, extraBuf],
|
|
11018
|
+
byteLength: countBytes.length + entryBuf.length + extraBuf.length
|
|
11019
|
+
});
|
|
11020
|
+
} else {
|
|
11021
|
+
subsections.push({
|
|
11022
|
+
kind,
|
|
11023
|
+
parts: [countBytes, entryBuf],
|
|
11024
|
+
byteLength: countBytes.length + entryBuf.length
|
|
11025
|
+
});
|
|
11026
|
+
}
|
|
11027
|
+
} else {
|
|
11028
|
+
subsections.push({
|
|
11029
|
+
kind,
|
|
11030
|
+
parts: [bytes.subarray(contentStart, stop)],
|
|
11031
|
+
byteLength: length
|
|
11032
|
+
});
|
|
11033
|
+
}
|
|
11034
|
+
offset = stop;
|
|
11035
|
+
}
|
|
11036
|
+
const linkingWriter = new ByteWriter(end - start + 128);
|
|
11037
|
+
linkingWriter.string(sectionName);
|
|
11038
|
+
linkingWriter.uleb(version2);
|
|
11039
|
+
for (const subsection of subsections) {
|
|
11040
|
+
if (subsection.kind === 6 && objcLoader !== void 0) {
|
|
11041
|
+
const content = subsection.parts[0];
|
|
11042
|
+
const [count, entriesStart] = readNumber(content, 0);
|
|
11043
|
+
const initWriter = new ByteWriter(content.length + 16);
|
|
11044
|
+
initWriter.bytes(content, 0, entriesStart);
|
|
11045
|
+
let entryStart = entriesStart;
|
|
11046
|
+
for (let i = 0; i < count; i++) {
|
|
11047
|
+
const [, symbolStart] = readNumber(content, entryStart);
|
|
11048
|
+
const [symbol, entryEnd] = readNumber(content, symbolStart);
|
|
11049
|
+
if (symbol === objcLoader) {
|
|
11050
|
+
initWriter.uleb(1);
|
|
11051
|
+
initWriter.bytes(content, symbolStart, entryEnd);
|
|
11052
|
+
} else {
|
|
11053
|
+
initWriter.bytes(content, entryStart, entryEnd);
|
|
11054
|
+
}
|
|
11055
|
+
entryStart = entryEnd;
|
|
11056
|
+
}
|
|
11057
|
+
if (entryStart !== content.length)
|
|
11058
|
+
throw new Error("invalid init functions subsection");
|
|
11059
|
+
const initBuf = initWriter.finish();
|
|
11060
|
+
linkingWriter.byte(subsection.kind);
|
|
11061
|
+
linkingWriter.uleb(initBuf.length);
|
|
11062
|
+
linkingWriter.bytes(initBuf);
|
|
11063
|
+
} else {
|
|
11064
|
+
linkingWriter.byte(subsection.kind);
|
|
11065
|
+
linkingWriter.uleb(subsection.byteLength);
|
|
11066
|
+
for (const part of subsection.parts) linkingWriter.bytes(part);
|
|
11067
|
+
}
|
|
11068
|
+
}
|
|
11069
|
+
return linkingWriter.finish();
|
|
11070
|
+
};
|
|
11071
|
+
if (rewrite && scan2 && (scan2.importHeaderStart < 0 || scan2.linkingHeaderStart < 0 || scan2.importHeaderStart < scan2.linkingHeaderStart)) {
|
|
11072
|
+
const parts = [];
|
|
11073
|
+
let cursor = 0;
|
|
11074
|
+
if (scan2.importHeaderStart >= 0) {
|
|
11075
|
+
if (scan2.importHeaderStart > cursor)
|
|
11076
|
+
parts.push(bytes.subarray(cursor, scan2.importHeaderStart));
|
|
11077
|
+
const rewrittenImport = rewriteImportSection(scan2.importStart, scan2.importEnd);
|
|
11078
|
+
parts.push(Buffer.from([2]), encodeNumber(rewrittenImport.length), rewrittenImport);
|
|
11079
|
+
cursor = scan2.importEnd;
|
|
11080
|
+
}
|
|
11081
|
+
if (scan2.linkingHeaderStart >= 0) {
|
|
11082
|
+
if (scan2.linkingHeaderStart > cursor)
|
|
11083
|
+
parts.push(bytes.subarray(cursor, scan2.linkingHeaderStart));
|
|
11084
|
+
const rewrittenLinking = rewriteLinkingSection(scan2.linkingStart, scan2.linkingEnd);
|
|
11085
|
+
parts.push(
|
|
11086
|
+
Buffer.from([0]),
|
|
11087
|
+
encodeNumber(rewrittenLinking.length),
|
|
11088
|
+
rewrittenLinking
|
|
11089
|
+
);
|
|
11090
|
+
cursor = scan2.linkingEnd;
|
|
11091
|
+
}
|
|
11092
|
+
if (cursor < bytes.length) parts.push(bytes.subarray(cursor));
|
|
11093
|
+
return {
|
|
11094
|
+
bytes: concatParts(parts),
|
|
11095
|
+
definitions,
|
|
11096
|
+
functionImports,
|
|
11097
|
+
usesDlsym,
|
|
11098
|
+
usesDlerror,
|
|
11099
|
+
usedSymbols,
|
|
11100
|
+
addressTaken: []
|
|
11101
|
+
};
|
|
11102
|
+
}
|
|
11103
|
+
const sections = rewrite ? [bytes.subarray(0, 8)] : void 0;
|
|
11104
|
+
let importHeaderStart = -1;
|
|
11105
|
+
let importStart = -1;
|
|
11106
|
+
let importEnd = -1;
|
|
11107
|
+
let linkingHeaderStart = -1;
|
|
11108
|
+
let linkingStart = -1;
|
|
11109
|
+
let linkingEnd = -1;
|
|
10765
11110
|
let position = 8;
|
|
10766
11111
|
while (position < bytes.length) {
|
|
10767
11112
|
const headerStart = position;
|
|
@@ -10825,6 +11170,9 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
10825
11170
|
types.push({ parameters, results });
|
|
10826
11171
|
}
|
|
10827
11172
|
} else if (id === 2) {
|
|
11173
|
+
importHeaderStart = headerStart;
|
|
11174
|
+
importStart = start;
|
|
11175
|
+
importEnd = end;
|
|
10828
11176
|
const count = number3();
|
|
10829
11177
|
const importWriter = rewrite ? new ByteWriter(size + 64) : void 0;
|
|
10830
11178
|
importWriter?.uleb(count);
|
|
@@ -10899,210 +11247,88 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
10899
11247
|
} else if (id === 0) {
|
|
10900
11248
|
const sectionName = string5();
|
|
10901
11249
|
if (sectionName === "linking") {
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
const
|
|
10909
|
-
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
const
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
const symbolKind = bytes[offset++];
|
|
10938
|
-
const flags = number3();
|
|
10939
|
-
const flagsEnd = offset;
|
|
10940
|
-
let index = -1;
|
|
10941
|
-
let name3 = "";
|
|
10942
|
-
let nameStart = -1;
|
|
10943
|
-
let nameEnd = -1;
|
|
10944
|
-
if (symbolKind === 0 || symbolKind === 2 || symbolKind === 4 || symbolKind === 5) {
|
|
10945
|
-
index = number3();
|
|
10946
|
-
if (!(flags & 16) || flags & 64) {
|
|
10947
|
-
nameStart = offset;
|
|
10948
|
-
name3 = string5();
|
|
10949
|
-
nameEnd = offset;
|
|
10950
|
-
}
|
|
10951
|
-
} else if (symbolKind === 1) {
|
|
10952
|
-
nameStart = offset;
|
|
10953
|
-
name3 = string5();
|
|
10954
|
-
nameEnd = offset;
|
|
10955
|
-
if (!(flags & 16)) {
|
|
10956
|
-
if ((flags & 3) !== 3) {
|
|
10957
|
-
number3();
|
|
11250
|
+
linkingHeaderStart = headerStart;
|
|
11251
|
+
linkingStart = start;
|
|
11252
|
+
linkingEnd = end;
|
|
11253
|
+
if (rewrite) {
|
|
11254
|
+
rewrittenSection = rewriteLinkingSection(start, end);
|
|
11255
|
+
} else {
|
|
11256
|
+
const version2 = number3();
|
|
11257
|
+
if (version2 !== 2) throw new Error("unsupported wasm linking version");
|
|
11258
|
+
while (offset < end) {
|
|
11259
|
+
const kind = bytes[offset++];
|
|
11260
|
+
const length = number3();
|
|
11261
|
+
const stop = offset + length;
|
|
11262
|
+
if (stop > end) throw new Error("invalid linking subsection");
|
|
11263
|
+
if (kind === 8) {
|
|
11264
|
+
const count = number3();
|
|
11265
|
+
for (let i = 0; i < count; i++) {
|
|
11266
|
+
const symbolKind = bytes[offset++];
|
|
11267
|
+
const flags = number3();
|
|
11268
|
+
let index = -1;
|
|
11269
|
+
let name3 = "";
|
|
11270
|
+
if (symbolKind === 0 || symbolKind === 2 || symbolKind === 4 || symbolKind === 5) {
|
|
11271
|
+
index = number3();
|
|
11272
|
+
if (!(flags & 16) || flags & 64) name3 = string5();
|
|
11273
|
+
} else if (symbolKind === 1) {
|
|
11274
|
+
const nameLen = number3();
|
|
11275
|
+
const nameEnd = offset + nameLen;
|
|
11276
|
+
if (nameEnd > end) throw new Error("invalid wasm string");
|
|
11277
|
+
if (flags & 16 || (flags & 3) !== 2)
|
|
11278
|
+
name3 = rawBuf.toString("utf8", offset, nameEnd);
|
|
11279
|
+
offset = nameEnd;
|
|
11280
|
+
if (!(flags & 16)) {
|
|
11281
|
+
if ((flags & 3) !== 3) {
|
|
11282
|
+
number3();
|
|
11283
|
+
number3();
|
|
11284
|
+
}
|
|
10958
11285
|
number3();
|
|
11286
|
+
if ((flags & 3) === 3) offset++;
|
|
10959
11287
|
}
|
|
10960
|
-
|
|
10961
|
-
|
|
10962
|
-
|
|
10963
|
-
|
|
10964
|
-
|
|
10965
|
-
|
|
10966
|
-
|
|
10967
|
-
if (rewrite && !sdkLookupOnly && name3 === OBJC_LOAD_FUNCTION && symbolKind === 0 && !(flags & 16)) {
|
|
10968
|
-
objcLoader = i;
|
|
10969
|
-
}
|
|
10970
|
-
const alias = names.get(name3);
|
|
10971
|
-
if (!rewrite && flags & 16 && symbolKind === 1 && alias)
|
|
10972
|
-
usedSymbols.add(name3);
|
|
10973
|
-
if (entryWriter && binding) {
|
|
10974
|
-
let rewrittenSym = name3;
|
|
10975
|
-
let addedCanonical;
|
|
10976
|
-
if ((name3 === "dlsym" && usesDlsym || name3 === "dlerror" && usesDlerror) && flags & 16 && flags & 64 && symbolKind === 0) {
|
|
10977
|
-
rewrittenSym = name3 === "dlsym" ? callerAlias : dlerrorAlias;
|
|
10978
|
-
entryWriter.bytes(bytes, begin, nameStart);
|
|
10979
|
-
entryWriter.string(rewrittenSym);
|
|
10980
|
-
entryWriter.bytes(bytes, nameEnd, offset);
|
|
10981
|
-
} else if (flags & 16 && name3 !== "dlsym" && name3 !== "dlerror" && binding(name3) !== void 0) {
|
|
10982
|
-
rewrittenSym = binding(name3);
|
|
10983
|
-
entryWriter.bytes(bytes, begin, nameStart);
|
|
10984
|
-
entryWriter.string(rewrittenSym);
|
|
10985
|
-
entryWriter.bytes(bytes, nameEnd, offset);
|
|
10986
|
-
} else if (alias && !(flags & 16) && (flags & 3) !== 2) {
|
|
11288
|
+
} else if (symbolKind === 3) number3();
|
|
11289
|
+
else throw new Error("unsupported wasm symbol kind");
|
|
11290
|
+
if (symbolKind === 0)
|
|
11291
|
+
functionSymbols[i] = name3 || functionImportNames[index];
|
|
11292
|
+
if (flags & 16) {
|
|
11293
|
+
if (symbolKind === 1 && names.has(name3)) usedSymbols.add(name3);
|
|
11294
|
+
} else if ((flags & 3) !== 2 && names.has(name3)) {
|
|
10987
11295
|
if (symbolKind !== 0 && symbolKind !== 1)
|
|
10988
11296
|
throw new Error(`unsupported symbol ${name3}`);
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
}
|
|
11000
|
-
rewrittenSym = alias;
|
|
11001
|
-
entryWriter.bytes(bytes, begin, nameStart);
|
|
11002
|
-
entryWriter.string(alias);
|
|
11003
|
-
entryWriter.bytes(bytes, nameEnd, offset);
|
|
11004
|
-
}
|
|
11005
|
-
} else {
|
|
11006
|
-
entryWriter.bytes(bytes, begin, offset);
|
|
11297
|
+
const type = symbolKind === 0 ? types[functionTypes[index]] : void 0;
|
|
11298
|
+
if (symbolKind === 0 && !type)
|
|
11299
|
+
throw new Error(`missing type for ${name3}`);
|
|
11300
|
+
definitions.push({
|
|
11301
|
+
name: name3,
|
|
11302
|
+
kind: symbolKind === 0 ? "function" : "data",
|
|
11303
|
+
weak: (flags & 3) === 1,
|
|
11304
|
+
exportName: (flags & 32) !== 0,
|
|
11305
|
+
hidden: (flags & 4) !== 0,
|
|
11306
|
+
type
|
|
11307
|
+
});
|
|
11007
11308
|
}
|
|
11008
|
-
if (collectRewrittenSymbols) {
|
|
11009
|
-
if (flags & 16) {
|
|
11010
|
-
const resolved = flags & 64 || symbolKind === 1 ? rewrittenSym : symbolKind === 0 ? functionImportNames[index] ?? "" : symbolKind === 2 ? globalImportNames[index] ?? "" : symbolKind === 4 ? eventImportNames[index] ?? "" : symbolKind === 5 ? tableImportNames[index] ?? "" : "";
|
|
11011
|
-
if (resolved) collectRewrittenSymbols.referenced.add(resolved);
|
|
11012
|
-
} else if ((flags & 3) !== 2) {
|
|
11013
|
-
if (rewrittenSym) collectRewrittenSymbols.defined.add(rewrittenSym);
|
|
11014
|
-
if (addedCanonical)
|
|
11015
|
-
collectRewrittenSymbols.defined.add(addedCanonical);
|
|
11016
|
-
}
|
|
11017
|
-
}
|
|
11018
|
-
} else if (alias && !(flags & 16) && (flags & 3) !== 2) {
|
|
11019
|
-
if (symbolKind !== 0 && symbolKind !== 1)
|
|
11020
|
-
throw new Error(`unsupported symbol ${name3}`);
|
|
11021
|
-
const type = symbolKind === 0 ? types[functionTypes[index]] : void 0;
|
|
11022
|
-
if (symbolKind === 0 && !type) throw new Error(`missing type for ${name3}`);
|
|
11023
|
-
definitions.push({
|
|
11024
|
-
name: name3,
|
|
11025
|
-
kind: symbolKind === 0 ? "function" : "data",
|
|
11026
|
-
weak: (flags & 3) === 1,
|
|
11027
|
-
exportName: (flags & 32) !== 0,
|
|
11028
|
-
hidden: (flags & 4) !== 0,
|
|
11029
|
-
type
|
|
11030
|
-
});
|
|
11031
|
-
}
|
|
11032
|
-
}
|
|
11033
|
-
if (offset !== stop) throw new Error("invalid symbol subsection");
|
|
11034
|
-
if (entryWriter) {
|
|
11035
|
-
const countBytes = encodeNumber(count + added);
|
|
11036
|
-
const entryBuf = entryWriter.finish();
|
|
11037
|
-
if (extraWriter) {
|
|
11038
|
-
const extraBuf = extraWriter.finish();
|
|
11039
|
-
subsections.push({
|
|
11040
|
-
kind,
|
|
11041
|
-
parts: [countBytes, entryBuf, extraBuf],
|
|
11042
|
-
byteLength: countBytes.length + entryBuf.length + extraBuf.length
|
|
11043
|
-
});
|
|
11044
|
-
} else {
|
|
11045
|
-
subsections.push({
|
|
11046
|
-
kind,
|
|
11047
|
-
parts: [countBytes, entryBuf],
|
|
11048
|
-
byteLength: countBytes.length + entryBuf.length
|
|
11049
|
-
});
|
|
11050
11309
|
}
|
|
11310
|
+
if (offset !== stop) throw new Error("invalid symbol subsection");
|
|
11051
11311
|
}
|
|
11052
|
-
|
|
11053
|
-
subsections.push({
|
|
11054
|
-
kind,
|
|
11055
|
-
parts: [bytes.subarray(contentStart, stop)],
|
|
11056
|
-
byteLength: length
|
|
11057
|
-
});
|
|
11312
|
+
offset = stop;
|
|
11058
11313
|
}
|
|
11059
|
-
offset = stop;
|
|
11060
|
-
}
|
|
11061
|
-
if (subsections) {
|
|
11062
|
-
const linkingWriter = new ByteWriter(size + 128);
|
|
11063
|
-
linkingWriter.string(sectionName);
|
|
11064
|
-
linkingWriter.uleb(version2);
|
|
11065
|
-
for (const subsection of subsections) {
|
|
11066
|
-
if (subsection.kind === 6 && objcLoader !== void 0) {
|
|
11067
|
-
const content = subsection.parts[0];
|
|
11068
|
-
const [count, entriesStart] = readNumber(content, 0);
|
|
11069
|
-
const initWriter = new ByteWriter(content.length + 16);
|
|
11070
|
-
initWriter.bytes(content, 0, entriesStart);
|
|
11071
|
-
let entryStart = entriesStart;
|
|
11072
|
-
for (let i = 0; i < count; i++) {
|
|
11073
|
-
const [, symbolStart] = readNumber(content, entryStart);
|
|
11074
|
-
const [symbol, entryEnd] = readNumber(content, symbolStart);
|
|
11075
|
-
if (symbol === objcLoader) {
|
|
11076
|
-
initWriter.uleb(1);
|
|
11077
|
-
initWriter.bytes(content, symbolStart, entryEnd);
|
|
11078
|
-
} else {
|
|
11079
|
-
initWriter.bytes(content, entryStart, entryEnd);
|
|
11080
|
-
}
|
|
11081
|
-
entryStart = entryEnd;
|
|
11082
|
-
}
|
|
11083
|
-
if (entryStart !== content.length)
|
|
11084
|
-
throw new Error("invalid init functions subsection");
|
|
11085
|
-
const initBuf = initWriter.finish();
|
|
11086
|
-
linkingWriter.byte(subsection.kind);
|
|
11087
|
-
linkingWriter.uleb(initBuf.length);
|
|
11088
|
-
linkingWriter.bytes(initBuf);
|
|
11089
|
-
} else {
|
|
11090
|
-
linkingWriter.byte(subsection.kind);
|
|
11091
|
-
linkingWriter.uleb(subsection.byteLength);
|
|
11092
|
-
for (const part of subsection.parts) linkingWriter.bytes(part);
|
|
11093
|
-
}
|
|
11094
|
-
}
|
|
11095
|
-
rewrittenSection = linkingWriter.finish();
|
|
11096
11314
|
}
|
|
11097
11315
|
} else if (!rewrite && sectionName.startsWith("reloc.")) {
|
|
11098
11316
|
number3();
|
|
11099
11317
|
for (let count = number3(); count > 0; count--) {
|
|
11100
|
-
const
|
|
11101
|
-
number3();
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11318
|
+
const b0 = bytes[offset];
|
|
11319
|
+
const type = b0 < 128 ? (offset++, b0) : number3();
|
|
11320
|
+
if (offset < end && bytes[offset] < 128) offset++;
|
|
11321
|
+
else number3();
|
|
11322
|
+
const b2 = bytes[offset];
|
|
11323
|
+
const symIdx = b2 < 128 ? (offset++, b2) : number3();
|
|
11324
|
+
if (ADDEND_RELOCATIONS.has(type)) {
|
|
11325
|
+
if (offset < end && bytes[offset] < 128) offset++;
|
|
11326
|
+
else number3();
|
|
11327
|
+
}
|
|
11328
|
+
if (TABLE_INDEX_RELOCATIONS.has(type)) {
|
|
11329
|
+
const name3 = functionSymbols[symIdx];
|
|
11330
|
+
if (name3 !== void 0) addressTaken.add(name3);
|
|
11331
|
+
}
|
|
11106
11332
|
}
|
|
11107
11333
|
if (offset !== end) throw new Error(`invalid relocation section ${sectionName}`);
|
|
11108
11334
|
}
|
|
@@ -11121,9 +11347,21 @@ function rewriteObject(bytes, names, callerAlias, binding, instrumentDynamicLook
|
|
|
11121
11347
|
}
|
|
11122
11348
|
return {
|
|
11123
11349
|
bytes: sections ? Buffer.concat(sections) : bytes,
|
|
11350
|
+
parts: sections,
|
|
11351
|
+
scan: !rewrite ? {
|
|
11352
|
+
importHeaderStart,
|
|
11353
|
+
importStart,
|
|
11354
|
+
importEnd,
|
|
11355
|
+
linkingHeaderStart,
|
|
11356
|
+
linkingStart,
|
|
11357
|
+
linkingEnd,
|
|
11358
|
+
usesDlsym,
|
|
11359
|
+
usesDlerror
|
|
11360
|
+
} : void 0,
|
|
11124
11361
|
definitions,
|
|
11125
11362
|
functionImports,
|
|
11126
11363
|
usesDlsym,
|
|
11364
|
+
usesDlerror,
|
|
11127
11365
|
usedSymbols,
|
|
11128
11366
|
addressTaken: [...addressTaken]
|
|
11129
11367
|
};
|
|
@@ -11193,7 +11431,8 @@ function createGuestImageLedger(input) {
|
|
|
11193
11431
|
object: object4,
|
|
11194
11432
|
aliases,
|
|
11195
11433
|
usedSymbols: rewritten.usedSymbols,
|
|
11196
|
-
functionImports: rewritten.functionImports
|
|
11434
|
+
functionImports: rewritten.functionImports,
|
|
11435
|
+
scan: rewritten.scan
|
|
11197
11436
|
});
|
|
11198
11437
|
for (const symbol of rewritten.definitions) {
|
|
11199
11438
|
if (symbol.type && symbol.type.results.length > 1)
|
|
@@ -11238,10 +11477,24 @@ function createGuestImageLedger(input) {
|
|
|
11238
11477
|
);
|
|
11239
11478
|
}
|
|
11240
11479
|
const preserveCanonical = /* @__PURE__ */ new Set();
|
|
11241
|
-
|
|
11480
|
+
let definitionsByName;
|
|
11481
|
+
const neededNames = /* @__PURE__ */ new Set();
|
|
11482
|
+
if (symbolIndices.has("__cxa_throw")) neededNames.add("__cxa_throw");
|
|
11483
|
+
for (const binding of input.directBindings ?? []) neededNames.add(binding.symbol);
|
|
11484
|
+
if (input.sdkWeakReferences) {
|
|
11485
|
+
definitionsByName = Map.groupBy(definitions, (definition) => definition.name);
|
|
11486
|
+
} else if (neededNames.size > 0) {
|
|
11487
|
+
definitionsByName = /* @__PURE__ */ new Map();
|
|
11488
|
+
for (const definition of definitions) {
|
|
11489
|
+
if (!neededNames.has(definition.name)) continue;
|
|
11490
|
+
let list = definitionsByName.get(definition.name);
|
|
11491
|
+
if (!list) definitionsByName.set(definition.name, list = []);
|
|
11492
|
+
list.push(definition);
|
|
11493
|
+
}
|
|
11494
|
+
}
|
|
11242
11495
|
if (symbolIndices.has("__cxa_throw")) {
|
|
11243
11496
|
const name3 = "__cxa_throw";
|
|
11244
|
-
const matching = definitionsByName
|
|
11497
|
+
const matching = definitionsByName?.get(name3) ?? [];
|
|
11245
11498
|
if (new Set(matching.map((definition) => definition.image)).size >= 2 && matching.some((definition) => definition.weak)) {
|
|
11246
11499
|
const weak = matching.filter((definition) => definition.weak);
|
|
11247
11500
|
const strong = matching.filter((definition) => !definition.weak);
|
|
@@ -11335,7 +11588,7 @@ function createGuestImageLedger(input) {
|
|
|
11335
11588
|
const unitsByPath = new Map(units.map((unit) => [unit.object.path, unit]));
|
|
11336
11589
|
for (const binding of input.directBindings ?? []) {
|
|
11337
11590
|
const unit = unitsByPath.get(binding.object);
|
|
11338
|
-
const matches = (definitionsByName
|
|
11591
|
+
const matches = (definitionsByName?.get(binding.symbol) ?? []).filter(
|
|
11339
11592
|
(definition) => definition.object === binding.providerObject && definition.image === binding.providerImage
|
|
11340
11593
|
);
|
|
11341
11594
|
if (!unit || !unit.usedSymbols.has(binding.symbol) || matches.length !== 1)
|
|
@@ -11379,7 +11632,7 @@ function createGuestImageLedger(input) {
|
|
|
11379
11632
|
}
|
|
11380
11633
|
}
|
|
11381
11634
|
const appSymbols = input.registerAppTables ? { referenced: /* @__PURE__ */ new Set(), defined: /* @__PURE__ */ new Set() } : void 0;
|
|
11382
|
-
const objects = units.map(({ image, object: object4, aliases, functionImports }) => {
|
|
11635
|
+
const objects = units.map(({ image, object: object4, aliases, functionImports, scan: scan2 }) => {
|
|
11383
11636
|
const shared = sharedLookupByImage.get(image);
|
|
11384
11637
|
const own = startup.get(object4.path);
|
|
11385
11638
|
const bindings = new Map(own);
|
|
@@ -11402,22 +11655,24 @@ function createGuestImageLedger(input) {
|
|
|
11402
11655
|
}
|
|
11403
11656
|
bindings.set(name3, wrapper.symbol);
|
|
11404
11657
|
}
|
|
11658
|
+
const rewritten = rewriteObject(
|
|
11659
|
+
object4.bytes,
|
|
11660
|
+
aliases,
|
|
11661
|
+
`__peach_dlsym_caller_${image}`,
|
|
11662
|
+
binding,
|
|
11663
|
+
object4.instrumentDynamicLookups,
|
|
11664
|
+
preserveCanonical,
|
|
11665
|
+
{
|
|
11666
|
+
sdkProduct: object4.sdkProduct,
|
|
11667
|
+
collectRewrittenSymbols: object4.sdkProduct === void 0 ? appSymbols : void 0,
|
|
11668
|
+
scan: scan2
|
|
11669
|
+
}
|
|
11670
|
+
);
|
|
11405
11671
|
return {
|
|
11406
11672
|
path: object4.path,
|
|
11407
11673
|
instrumentDynamicLookups: object4.instrumentDynamicLookups,
|
|
11408
11674
|
sdkProduct: object4.sdkProduct,
|
|
11409
|
-
bytes:
|
|
11410
|
-
object4.bytes,
|
|
11411
|
-
aliases,
|
|
11412
|
-
`__peach_dlsym_caller_${image}`,
|
|
11413
|
-
binding,
|
|
11414
|
-
object4.instrumentDynamicLookups,
|
|
11415
|
-
preserveCanonical,
|
|
11416
|
-
{
|
|
11417
|
-
sdkProduct: object4.sdkProduct,
|
|
11418
|
-
collectRewrittenSymbols: object4.sdkProduct === void 0 ? appSymbols : void 0
|
|
11419
|
-
}
|
|
11420
|
-
).bytes
|
|
11675
|
+
bytes: rewritten.bytes
|
|
11421
11676
|
};
|
|
11422
11677
|
});
|
|
11423
11678
|
const exported = /* @__PURE__ */ new Map();
|
|
@@ -11579,8 +11834,7 @@ function sdkGuestCallerId(product) {
|
|
|
11579
11834
|
return (hash | 2147483648) >>> 0;
|
|
11580
11835
|
}
|
|
11581
11836
|
function sdkGuestSymbolName(product, name3) {
|
|
11582
|
-
|
|
11583
|
-
return `__peach_sdk_symbol_${digest.slice(0, 32)}`;
|
|
11837
|
+
return `__peach_sdk_symbol_${sha256PairHex(product, name3).slice(0, 32)}`;
|
|
11584
11838
|
}
|
|
11585
11839
|
function rewriteSdkGuestLookup(bytes, callerId) {
|
|
11586
11840
|
return rewriteObject(
|
|
@@ -11654,7 +11908,7 @@ function nameGuestImageAliases(wasm, symbols) {
|
|
|
11654
11908
|
}
|
|
11655
11909
|
return Buffer.concat(parts);
|
|
11656
11910
|
}
|
|
11657
|
-
var import_node_crypto10, ByteWriter, OBJC_INIT_RECORD, TABLE_INDEX_RELOCATIONS, GUEST_DYLD_VALUES_SECTION, GUEST_LAZY_FUNCTION_BASE, SDK_DYLD_RESOLVER;
|
|
11911
|
+
var import_node_crypto10, ByteWriter, OBJC_INIT_RECORD, TABLE_INDEX_RELOCATIONS, sha256PairHex, GUEST_DYLD_VALUES_SECTION, GUEST_LAZY_FUNCTION_BASE, SDK_DYLD_RESOLVER;
|
|
11658
11912
|
var init_swift_guest_image_ledger = __esm({
|
|
11659
11913
|
"src/swift-guest-image-ledger.ts"() {
|
|
11660
11914
|
"use strict";
|
|
@@ -11715,6 +11969,7 @@ var init_swift_guest_image_ledger = __esm({
|
|
|
11715
11969
|
};
|
|
11716
11970
|
OBJC_INIT_RECORD = ".objc_init";
|
|
11717
11971
|
TABLE_INDEX_RELOCATIONS = /* @__PURE__ */ new Set([1, 2, 12, 18, 19, 24]);
|
|
11972
|
+
sha256PairHex = typeof Bun !== "undefined" ? (first, second) => new Bun.CryptoHasher("sha256").update(first).update("\0").update(second).digest("hex") : (first, second) => (0, import_node_crypto10.createHash)("sha256").update(first).update("\0").update(second).digest("hex");
|
|
11718
11973
|
GUEST_DYLD_VALUES_SECTION = "peach_dyld_values";
|
|
11719
11974
|
GUEST_LAZY_FUNCTION_BASE = 2 ** 32;
|
|
11720
11975
|
SDK_DYLD_RESOLVER = "__peach_sdk_dyld_resolve";
|
|
@@ -11732,7 +11987,7 @@ function encodeWasmNumber(value) {
|
|
|
11732
11987
|
}
|
|
11733
11988
|
}
|
|
11734
11989
|
function encodeWasmName(name3) {
|
|
11735
|
-
const bytes =
|
|
11990
|
+
const bytes = new TextEncoder().encode(name3);
|
|
11736
11991
|
return [...encodeWasmNumber(bytes.length), ...bytes];
|
|
11737
11992
|
}
|
|
11738
11993
|
function readWasmSection(bytes, start, end) {
|
|
@@ -12170,6 +12425,32 @@ var init_swift_guest_dyld_table = __esm({
|
|
|
12170
12425
|
}
|
|
12171
12426
|
});
|
|
12172
12427
|
|
|
12428
|
+
// ../../src/helpers/mapLimit.ts
|
|
12429
|
+
async function mapLimit(items, limit, worker) {
|
|
12430
|
+
const results = new Array(items.length);
|
|
12431
|
+
let next = 0;
|
|
12432
|
+
let failure;
|
|
12433
|
+
await Promise.all(
|
|
12434
|
+
Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
12435
|
+
while (!failure && next < items.length) {
|
|
12436
|
+
const index = next++;
|
|
12437
|
+
try {
|
|
12438
|
+
results[index] = await worker(items[index], index);
|
|
12439
|
+
} catch (error) {
|
|
12440
|
+
failure ??= { error };
|
|
12441
|
+
}
|
|
12442
|
+
}
|
|
12443
|
+
})
|
|
12444
|
+
);
|
|
12445
|
+
if (failure) throw failure.error;
|
|
12446
|
+
return results;
|
|
12447
|
+
}
|
|
12448
|
+
var init_mapLimit = __esm({
|
|
12449
|
+
"../../src/helpers/mapLimit.ts"() {
|
|
12450
|
+
"use strict";
|
|
12451
|
+
}
|
|
12452
|
+
});
|
|
12453
|
+
|
|
12173
12454
|
// src/swift-guest-link-plan.ts
|
|
12174
12455
|
function selectedGuestInputImage(artifact, member) {
|
|
12175
12456
|
if (artifact.kind === "object" !== (member === null))
|
|
@@ -13974,7 +14255,7 @@ function remapGuestLinkPlan(plan, rewritten) {
|
|
|
13974
14255
|
}))
|
|
13975
14256
|
};
|
|
13976
14257
|
}
|
|
13977
|
-
function
|
|
14258
|
+
function guestLinkInputFilesWithKind(args) {
|
|
13978
14259
|
const dirs = [];
|
|
13979
14260
|
for (let i = 0; i < args.length; i++) {
|
|
13980
14261
|
const arg = args[i];
|
|
@@ -13982,7 +14263,8 @@ function guestLinkInputFiles(args) {
|
|
|
13982
14263
|
else if (arg.startsWith("-L")) dirs.push(arg.slice(2));
|
|
13983
14264
|
else if (arg.startsWith("--library-path=")) dirs.push(arg.slice(15));
|
|
13984
14265
|
}
|
|
13985
|
-
const
|
|
14266
|
+
const magic = Buffer.allocUnsafe(8);
|
|
14267
|
+
const inputs = /* @__PURE__ */ new Map();
|
|
13986
14268
|
for (let i = 0; i < args.length; i++) {
|
|
13987
14269
|
const arg = args[i];
|
|
13988
14270
|
if (arg === "-L" || arg === "--library-path" || arg === "-o" || arg === "--output") {
|
|
@@ -13991,29 +14273,52 @@ function guestLinkInputFiles(args) {
|
|
|
13991
14273
|
}
|
|
13992
14274
|
if (arg.startsWith("@")) throw new Error(`nested linker response file ${arg}`);
|
|
13993
14275
|
let file;
|
|
14276
|
+
let kind;
|
|
13994
14277
|
if (arg === "-l" || arg === "--library" || arg.startsWith("--library=") || arg.startsWith("-l") && arg.length > 2) {
|
|
13995
14278
|
const name3 = arg === "-l" || arg === "--library" ? args[++i] : arg.startsWith("--library=") ? arg.slice(10) : arg.slice(2);
|
|
13996
14279
|
const archive = name3.startsWith(":") ? name3.slice(1) : `lib${name3}.a`;
|
|
13997
14280
|
file = dirs.map((dir) => import_node_path24.default.join(dir, archive)).find((item) => import_node_fs24.default.existsSync(item));
|
|
13998
14281
|
if (!file) throw new Error(`unresolved guest link library ${name3}`);
|
|
13999
|
-
} else if (!arg.startsWith("-")
|
|
14000
|
-
const
|
|
14001
|
-
|
|
14002
|
-
|
|
14003
|
-
|
|
14004
|
-
|
|
14005
|
-
|
|
14282
|
+
} else if (!arg.startsWith("-")) {
|
|
14283
|
+
const resolved = import_node_path24.default.resolve(arg);
|
|
14284
|
+
if (inputs.has(resolved)) continue;
|
|
14285
|
+
const stat = import_node_fs24.default.statSync(arg, { throwIfNoEntry: false });
|
|
14286
|
+
if (stat?.isFile()) {
|
|
14287
|
+
const fd = import_node_fs24.default.openSync(arg, "r");
|
|
14288
|
+
let read = 0;
|
|
14289
|
+
try {
|
|
14290
|
+
read = import_node_fs24.default.readSync(fd, magic, 0, 8, 0);
|
|
14291
|
+
} finally {
|
|
14292
|
+
import_node_fs24.default.closeSync(fd);
|
|
14293
|
+
}
|
|
14294
|
+
if (read >= 4) {
|
|
14295
|
+
if (read >= 8 && (magic.toString("ascii") === "!<arch>\n" || magic.toString("ascii") === "!<thin>\n")) {
|
|
14296
|
+
file = arg;
|
|
14297
|
+
kind = "archive";
|
|
14298
|
+
} else if (magic.subarray(0, 4).equals(WASM_MAGIC) || magic.subarray(0, 4).equals(BITCODE_MAGIC)) {
|
|
14299
|
+
file = arg;
|
|
14300
|
+
kind = "object";
|
|
14301
|
+
}
|
|
14302
|
+
}
|
|
14303
|
+
}
|
|
14304
|
+
}
|
|
14305
|
+
if (file) {
|
|
14306
|
+
const resolved = import_node_path24.default.resolve(file);
|
|
14307
|
+
if (!inputs.has(resolved)) {
|
|
14308
|
+
if (!kind) {
|
|
14309
|
+
const fd = import_node_fs24.default.openSync(resolved, "r");
|
|
14310
|
+
try {
|
|
14311
|
+
import_node_fs24.default.readSync(fd, magic, 0, 8, 0);
|
|
14312
|
+
} finally {
|
|
14313
|
+
import_node_fs24.default.closeSync(fd);
|
|
14314
|
+
}
|
|
14315
|
+
kind = magic.toString("ascii") === "!<arch>\n" ? "archive" : "object";
|
|
14316
|
+
}
|
|
14317
|
+
inputs.set(resolved, kind);
|
|
14006
14318
|
}
|
|
14007
|
-
if (magic.subarray(0, 4).equals(Buffer.from([0, 97, 115, 109])) || magic.subarray(0, 4).equals(Buffer.from([66, 67, 192, 222])) || magic.toString("ascii") === "!<arch>\n" || magic.toString("ascii") === "!<thin>\n")
|
|
14008
|
-
file = arg;
|
|
14009
14319
|
}
|
|
14010
|
-
if (file) inputs.add(import_node_path24.default.resolve(file));
|
|
14011
14320
|
}
|
|
14012
|
-
return [...inputs];
|
|
14013
|
-
}
|
|
14014
|
-
function unownedGuestLinkInputs(plan, args) {
|
|
14015
|
-
const owned = new Set(plan.artifacts.map((artifact) => import_node_path24.default.resolve(artifact.path)));
|
|
14016
|
-
return guestLinkInputFiles(args).filter((file) => !owned.has(file));
|
|
14321
|
+
return [...inputs].map(([filePath, kind]) => ({ path: filePath, kind }));
|
|
14017
14322
|
}
|
|
14018
14323
|
function occurrences(plan, args) {
|
|
14019
14324
|
const dirs = [];
|
|
@@ -14179,15 +14484,15 @@ function withOutput(args, output, discovery) {
|
|
|
14179
14484
|
result.push("-o", output);
|
|
14180
14485
|
return result;
|
|
14181
14486
|
}
|
|
14182
|
-
function linkGuestImages(options) {
|
|
14487
|
+
async function linkGuestImages(options) {
|
|
14183
14488
|
const { args, directory, wasmLd, clang, llvmAr } = options;
|
|
14184
14489
|
let plan = options.plan;
|
|
14185
14490
|
if (!plan.images.some((image) => image.id === options.ledgerDataImage))
|
|
14186
14491
|
throw new Error(`unknown ledger data image ${options.ledgerDataImage}`);
|
|
14187
14492
|
import_node_fs24.default.mkdirSync(directory, { recursive: true });
|
|
14188
|
-
|
|
14493
|
+
let discovery = import_node_path24.default.join(directory, "discovery.wasm");
|
|
14189
14494
|
const whyPath = import_node_path24.default.join(directory, "why-extract.txt");
|
|
14190
|
-
|
|
14495
|
+
let mapPath = import_node_path24.default.join(directory, "discovery.map");
|
|
14191
14496
|
const runLink = (name3, arguments_) => {
|
|
14192
14497
|
const response = import_node_path24.default.join(directory, `${name3}.rsp`);
|
|
14193
14498
|
const trace = import_node_path24.default.join(directory, `${name3}-inputs.txt`);
|
|
@@ -14206,19 +14511,24 @@ function linkGuestImages(options) {
|
|
|
14206
14511
|
}
|
|
14207
14512
|
return import_node_fs24.default.readFileSync(trace, "utf8");
|
|
14208
14513
|
};
|
|
14514
|
+
const preselection = options.projection && options.preselectionDiscovery ? options.preselectionDiscovery : void 0;
|
|
14209
14515
|
let discoveryProjection;
|
|
14210
14516
|
if (options.projection) {
|
|
14211
|
-
|
|
14212
|
-
|
|
14213
|
-
|
|
14214
|
-
source,
|
|
14215
|
-
|
|
14216
|
-
|
|
14217
|
-
|
|
14218
|
-
|
|
14219
|
-
|
|
14220
|
-
|
|
14221
|
-
|
|
14517
|
+
if (preselection) {
|
|
14518
|
+
discoveryProjection = preselection.projectionObject;
|
|
14519
|
+
} else {
|
|
14520
|
+
const source = import_node_path24.default.join(directory, "projection-discovery.c");
|
|
14521
|
+
discoveryProjection = import_node_path24.default.join(directory, "projection-discovery.o");
|
|
14522
|
+
import_node_fs24.default.writeFileSync(
|
|
14523
|
+
source,
|
|
14524
|
+
'#include "guest-image-projection.h"\nconst struct peach_guest_image __peach_guest_images[] = {{0}};\nconst uint32_t __peach_guest_image_count = 0;\n'
|
|
14525
|
+
);
|
|
14526
|
+
(0, import_node_child_process14.execFileSync)(
|
|
14527
|
+
clang,
|
|
14528
|
+
[...options.projection.clangOptions, "-c", source, "-o", discoveryProjection],
|
|
14529
|
+
{ stdio: "pipe" }
|
|
14530
|
+
);
|
|
14531
|
+
}
|
|
14222
14532
|
}
|
|
14223
14533
|
const archives = /* @__PURE__ */ new Map();
|
|
14224
14534
|
const memberBytes = /* @__PURE__ */ new Map();
|
|
@@ -14256,6 +14566,17 @@ function linkGuestImages(options) {
|
|
|
14256
14566
|
}
|
|
14257
14567
|
return byName.get(item.member);
|
|
14258
14568
|
};
|
|
14569
|
+
const reusePreselection = () => {
|
|
14570
|
+
discovery = preselection.wasm;
|
|
14571
|
+
mapPath = preselection.map;
|
|
14572
|
+
return selectedGuestLinkInputs(
|
|
14573
|
+
plan,
|
|
14574
|
+
args,
|
|
14575
|
+
import_node_fs24.default.readFileSync(preselection.why, "utf8"),
|
|
14576
|
+
import_node_fs24.default.readFileSync(preselection.trace, "utf8"),
|
|
14577
|
+
archives
|
|
14578
|
+
);
|
|
14579
|
+
};
|
|
14259
14580
|
const discover = (provider2) => {
|
|
14260
14581
|
const trace = runLink("discovery", [
|
|
14261
14582
|
...withOutput(args, discovery, true),
|
|
@@ -14285,9 +14606,10 @@ function linkGuestImages(options) {
|
|
|
14285
14606
|
const eagerProvider = [...eagerObjects].some(
|
|
14286
14607
|
(artifact) => needsProvider({ artifact, member: null })
|
|
14287
14608
|
);
|
|
14288
|
-
let selected = discover(eagerProvider);
|
|
14609
|
+
let selected = eagerProvider && preselection ? reusePreselection() : discover(eagerProvider);
|
|
14289
14610
|
const provider = eagerProvider || selected.some((item) => !eagerObjects.has(item.artifact) && needsProvider(item));
|
|
14290
|
-
if (provider && !eagerProvider)
|
|
14611
|
+
if (provider && !eagerProvider)
|
|
14612
|
+
selected = preselection ? reusePreselection() : discover(true);
|
|
14291
14613
|
if (options.resolvePlan) {
|
|
14292
14614
|
const identity = (value) => JSON.stringify([
|
|
14293
14615
|
value.images.map(({ id, name: name3 }) => [id, name3]),
|
|
@@ -14328,11 +14650,11 @@ function linkGuestImages(options) {
|
|
|
14328
14650
|
const product = (item.member === null ? void 0 : artifact.memberSdkProducts?.get(item.member)) ?? artifact.sdkProduct;
|
|
14329
14651
|
let sdkProduct;
|
|
14330
14652
|
if (sharedSdk && product !== void 0) {
|
|
14331
|
-
const
|
|
14332
|
-
if (
|
|
14653
|
+
const original = options.projection?.identities.get(artifact.path);
|
|
14654
|
+
if (original === void 0)
|
|
14333
14655
|
throw new Error(`SDK input has no projection identity ${artifact.path}`);
|
|
14334
14656
|
const origin = item.member === null ? void 0 : artifact.memberOrigins?.get(item.member);
|
|
14335
|
-
const identity = item.member === null ?
|
|
14657
|
+
const identity = item.member === null ? original : guestRuntimeMemberIdentity(original, {
|
|
14336
14658
|
member: origin?.name ?? item.member,
|
|
14337
14659
|
ordinal: origin?.ordinal ?? 1
|
|
14338
14660
|
});
|
|
@@ -14399,76 +14721,11 @@ function linkGuestImages(options) {
|
|
|
14399
14721
|
),
|
|
14400
14722
|
sdkCallerImages
|
|
14401
14723
|
});
|
|
14402
|
-
const
|
|
14403
|
-
const linkedOwners = /* @__PURE__ */ new Map();
|
|
14404
|
-
const ledgerObjects = new Map(ledger.objects.map((item) => [item.path, item]));
|
|
14405
|
-
const appObjects = /* @__PURE__ */ new Map();
|
|
14406
|
-
const sdkObjects = /* @__PURE__ */ new Map();
|
|
14407
|
-
const finalArchives = /* @__PURE__ */ new Map();
|
|
14408
|
-
for (const [index, artifact] of plan.artifacts.entries()) {
|
|
14409
|
-
const prefix = `${artifact.path}(`;
|
|
14410
|
-
if (artifact.kind === "object") {
|
|
14411
|
-
const object4 = ledgerObjects.get(artifact.path);
|
|
14412
|
-
if (!object4) continue;
|
|
14413
|
-
const output2 = import_node_path24.default.join(directory, `object-${index}.o`);
|
|
14414
|
-
import_node_fs24.default.writeFileSync(output2, object4.bytes);
|
|
14415
|
-
replacements.set(artifact.path, output2);
|
|
14416
|
-
linkedOwners.set(output2, selectedGuestInputImage(artifact, null));
|
|
14417
|
-
const image = selectedGuestInputImage(artifact, null);
|
|
14418
|
-
if (object4.sdkProduct === void 0) appObjects.set(output2, image);
|
|
14419
|
-
else
|
|
14420
|
-
sdkObjects.set(output2, {
|
|
14421
|
-
image,
|
|
14422
|
-
product: object4.sdkProduct,
|
|
14423
|
-
identity: sdkIdentities.get(object4.path)
|
|
14424
|
-
});
|
|
14425
|
-
continue;
|
|
14426
|
-
}
|
|
14427
|
-
const members = archives.get(artifact.path);
|
|
14428
|
-
if (!members) continue;
|
|
14429
|
-
const listing = (0, import_node_child_process14.execFileSync)(llvmAr, ["t", artifact.path], {
|
|
14430
|
-
encoding: "utf8"
|
|
14431
|
-
}).trimEnd();
|
|
14432
|
-
const listed = listing ? listing.split("\n") : [];
|
|
14433
|
-
if (listed.length !== members.length || new Set(listed).size !== listed.length || members.some(
|
|
14434
|
-
(member, i) => listed[i] !== member.name || import_node_path24.default.basename(member.name) !== member.name
|
|
14435
|
-
))
|
|
14436
|
-
throw new Error(`unsupported archive layout ${artifact.path}`);
|
|
14437
|
-
const memberDir = import_node_path24.default.join(directory, `archive-${index}`);
|
|
14438
|
-
import_node_fs24.default.mkdirSync(memberDir, { recursive: true });
|
|
14439
|
-
const output = import_node_path24.default.join(directory, `archive-${index}.a`);
|
|
14440
|
-
const inputs = members.map((member) => {
|
|
14441
|
-
const memberOutput = import_node_path24.default.join(memberDir, member.name);
|
|
14442
|
-
const rewritten = ledgerObjects.get(`${prefix}${member.name})`);
|
|
14443
|
-
import_node_fs24.default.writeFileSync(memberOutput, rewritten?.bytes ?? member.bytes);
|
|
14444
|
-
if (rewritten) {
|
|
14445
|
-
const image = selectedGuestInputImage(artifact, member.name);
|
|
14446
|
-
linkedOwners.set(`${output}(${member.name})`, image);
|
|
14447
|
-
if (rewritten.sdkProduct === void 0) appObjects.set(memberOutput, image);
|
|
14448
|
-
else
|
|
14449
|
-
sdkObjects.set(`${output}(${member.name})`, {
|
|
14450
|
-
image,
|
|
14451
|
-
product: rewritten.sdkProduct,
|
|
14452
|
-
identity: sdkIdentities.get(rewritten.path)
|
|
14453
|
-
});
|
|
14454
|
-
}
|
|
14455
|
-
return memberOutput;
|
|
14456
|
-
});
|
|
14457
|
-
import_node_fs24.default.rmSync(output, { force: true });
|
|
14458
|
-
const response = import_node_path24.default.join(memberDir, "members.rsp");
|
|
14459
|
-
import_node_fs24.default.writeFileSync(response, inputs.map((input) => JSON.stringify(input)).join(" "));
|
|
14460
|
-
(0, import_node_child_process14.execFileSync)(llvmAr, ["rcs", output, `@${response}`], { stdio: "pipe" });
|
|
14461
|
-
finalArchives.set(
|
|
14462
|
-
output,
|
|
14463
|
-
members.map((member) => ({ name: member.name, bytes: new Uint8Array(0) }))
|
|
14464
|
-
);
|
|
14465
|
-
replacements.set(artifact.path, output);
|
|
14466
|
-
}
|
|
14467
|
-
const compileLedger = (name3, source) => {
|
|
14724
|
+
const compileLedgerAsync = (name3, source) => {
|
|
14468
14725
|
const irPath = import_node_path24.default.join(directory, `${name3}.ll`);
|
|
14469
14726
|
const object4 = import_node_path24.default.join(directory, `${name3}.o`);
|
|
14470
14727
|
import_node_fs24.default.writeFileSync(irPath, source);
|
|
14471
|
-
|
|
14728
|
+
return execFileAsync(
|
|
14472
14729
|
clang,
|
|
14473
14730
|
[
|
|
14474
14731
|
"--target=wasm64-unknown-wasip1-threads",
|
|
@@ -14478,177 +14735,264 @@ function linkGuestImages(options) {
|
|
|
14478
14735
|
"-o",
|
|
14479
14736
|
object4
|
|
14480
14737
|
],
|
|
14481
|
-
{
|
|
14482
|
-
);
|
|
14483
|
-
return object4;
|
|
14738
|
+
{ maxBuffer: 64 * 1024 * 1024 }
|
|
14739
|
+
).then(() => object4);
|
|
14484
14740
|
};
|
|
14485
|
-
const
|
|
14486
|
-
const
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
ledger.
|
|
14491
|
-
|
|
14492
|
-
|
|
14493
|
-
|
|
14494
|
-
|
|
14495
|
-
|
|
14496
|
-
|
|
14497
|
-
|
|
14498
|
-
|
|
14499
|
-
|
|
14500
|
-
|
|
14501
|
-
|
|
14502
|
-
|
|
14503
|
-
|
|
14504
|
-
|
|
14505
|
-
|
|
14506
|
-
|
|
14507
|
-
|
|
14508
|
-
|
|
14509
|
-
|
|
14510
|
-
|
|
14511
|
-
|
|
14512
|
-
|
|
14513
|
-
|
|
14514
|
-
|
|
14515
|
-
|
|
14516
|
-
|
|
14517
|
-
|
|
14518
|
-
|
|
14519
|
-
|
|
14520
|
-
|
|
14521
|
-
|
|
14522
|
-
|
|
14523
|
-
|
|
14524
|
-
|
|
14525
|
-
|
|
14526
|
-
|
|
14527
|
-
|
|
14528
|
-
|
|
14529
|
-
|
|
14530
|
-
|
|
14531
|
-
|
|
14532
|
-
|
|
14533
|
-
|
|
14534
|
-
|
|
14535
|
-
|
|
14536
|
-
|
|
14537
|
-
|
|
14538
|
-
|
|
14539
|
-
|
|
14540
|
-
|
|
14541
|
-
|
|
14542
|
-
})
|
|
14543
|
-
);
|
|
14544
|
-
objectBytes.clear();
|
|
14545
|
-
memberBytes.clear();
|
|
14546
|
-
archives.clear();
|
|
14547
|
-
if (!discoveryRegions) throw new Error("guest projection layout object missing");
|
|
14548
|
-
const regionsBefore = discoveryRegions;
|
|
14549
|
-
const ledgerPieces = guestProjectionRegionCapacity([import_node_fs24.default.readFileSync(ledgerObject)], 0);
|
|
14550
|
-
const bundleCount = images.filter(
|
|
14551
|
-
(image) => image.resourceBundlePath !== void 0
|
|
14552
|
-
).length;
|
|
14553
|
-
const projectionPieces = images.length + 2 + (bundleCount ? bundleCount + 1 : 0);
|
|
14554
|
-
let capacities = ledger.images.map((image) => ({
|
|
14555
|
-
regions: regionsBefore[image.id] + 1 + ledger.callerWrappers.filter((wrapper) => wrapper.image === image.id).length + (image.id === options.ledgerDataImage ? ledgerPieces : 0) + (image.id === projection.image ? projectionPieces : 0),
|
|
14556
|
-
memoryProtection: projection.memoryProtection,
|
|
14557
|
-
tableProtection: projection.tableProtection
|
|
14558
|
-
}));
|
|
14559
|
-
const projectionSource = import_node_path24.default.join(directory, "projection.c");
|
|
14560
|
-
projectionObject = import_node_path24.default.join(directory, "projection.o");
|
|
14561
|
-
const callerMap = args.find((arg) => arg.startsWith("--Map="))?.slice("--Map=".length);
|
|
14562
|
-
const layoutMap = callerMap ?? import_node_path24.default.join(directory, "projection-layout.map");
|
|
14563
|
-
for (; ; ) {
|
|
14564
|
-
projectionStorage = reserveGuestProjectionStorage(images, capacities);
|
|
14565
|
-
import_node_fs24.default.writeFileSync(projectionSource, projectionStorage.source);
|
|
14566
|
-
(0, import_node_child_process14.execFileSync)(
|
|
14567
|
-
clang,
|
|
14568
|
-
[...projection.clangOptions, "-c", projectionSource, "-o", projectionObject],
|
|
14569
|
-
{ stdio: "pipe" }
|
|
14570
|
-
);
|
|
14571
|
-
finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
|
|
14572
|
-
if (sharedSdk) break;
|
|
14573
|
-
const wasm = import_node_fs24.default.readFileSync(finalOutput);
|
|
14574
|
-
const actual = guestProjectionRegionCounts(
|
|
14575
|
-
images.length,
|
|
14576
|
-
guestLinkedSpans(
|
|
14577
|
-
guestLinkLines(layoutMap),
|
|
14578
|
-
wasm,
|
|
14579
|
-
wasm,
|
|
14580
|
-
new Map(linkedOwners).set(projectionObject, projection.image),
|
|
14581
|
-
sectionOwners
|
|
14582
|
-
)
|
|
14741
|
+
const ledgerObjectPromise = compileLedgerAsync("ledger", ledger.llvmIR);
|
|
14742
|
+
const appLedgerObjectPromise = options.onSplitInputs && ledger.appLLVMIR ? compileLedgerAsync("app-ledger", ledger.appLLVMIR) : void 0;
|
|
14743
|
+
try {
|
|
14744
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
14745
|
+
const linkedOwners = /* @__PURE__ */ new Map();
|
|
14746
|
+
const ledgerObjects = new Map(ledger.objects.map((item) => [item.path, item]));
|
|
14747
|
+
const appObjects = /* @__PURE__ */ new Map();
|
|
14748
|
+
const sdkObjects = /* @__PURE__ */ new Map();
|
|
14749
|
+
const finalArchives = /* @__PURE__ */ new Map();
|
|
14750
|
+
const archiveJobs = [];
|
|
14751
|
+
for (const [index, artifact] of plan.artifacts.entries()) {
|
|
14752
|
+
const prefix = `${artifact.path}(`;
|
|
14753
|
+
if (artifact.kind === "object") {
|
|
14754
|
+
const object4 = ledgerObjects.get(artifact.path);
|
|
14755
|
+
if (!object4) continue;
|
|
14756
|
+
const output2 = import_node_path24.default.join(directory, `object-${index}.o`);
|
|
14757
|
+
import_node_fs24.default.writeFileSync(output2, object4.bytes);
|
|
14758
|
+
replacements.set(artifact.path, output2);
|
|
14759
|
+
linkedOwners.set(output2, selectedGuestInputImage(artifact, null));
|
|
14760
|
+
const image = selectedGuestInputImage(artifact, null);
|
|
14761
|
+
if (object4.sdkProduct === void 0) appObjects.set(output2, image);
|
|
14762
|
+
else
|
|
14763
|
+
sdkObjects.set(output2, {
|
|
14764
|
+
image,
|
|
14765
|
+
product: object4.sdkProduct,
|
|
14766
|
+
identity: sdkIdentities.get(object4.path)
|
|
14767
|
+
});
|
|
14768
|
+
continue;
|
|
14769
|
+
}
|
|
14770
|
+
const members = archives.get(artifact.path);
|
|
14771
|
+
if (!members) continue;
|
|
14772
|
+
const memberDir = import_node_path24.default.join(directory, `archive-${index}`);
|
|
14773
|
+
import_node_fs24.default.mkdirSync(memberDir, { recursive: true });
|
|
14774
|
+
const output = import_node_path24.default.join(directory, `archive-${index}.a`);
|
|
14775
|
+
const inputs = members.map((member) => {
|
|
14776
|
+
const memberOutput = import_node_path24.default.join(memberDir, member.name);
|
|
14777
|
+
const rewritten = ledgerObjects.get(`${prefix}${member.name})`);
|
|
14778
|
+
import_node_fs24.default.writeFileSync(memberOutput, rewritten?.bytes ?? member.bytes);
|
|
14779
|
+
if (rewritten) {
|
|
14780
|
+
const image = selectedGuestInputImage(artifact, member.name);
|
|
14781
|
+
linkedOwners.set(`${output}(${member.name})`, image);
|
|
14782
|
+
if (rewritten.sdkProduct === void 0) appObjects.set(memberOutput, image);
|
|
14783
|
+
else
|
|
14784
|
+
sdkObjects.set(`${output}(${member.name})`, {
|
|
14785
|
+
image,
|
|
14786
|
+
product: rewritten.sdkProduct,
|
|
14787
|
+
identity: sdkIdentities.get(rewritten.path)
|
|
14788
|
+
});
|
|
14789
|
+
}
|
|
14790
|
+
return memberOutput;
|
|
14791
|
+
});
|
|
14792
|
+
import_node_fs24.default.rmSync(output, { force: true });
|
|
14793
|
+
const response = import_node_path24.default.join(memberDir, "members.rsp");
|
|
14794
|
+
import_node_fs24.default.writeFileSync(response, inputs.map((input) => JSON.stringify(input)).join(" "));
|
|
14795
|
+
finalArchives.set(
|
|
14796
|
+
output,
|
|
14797
|
+
members.map((member) => ({ name: member.name, bytes: new Uint8Array(0) }))
|
|
14583
14798
|
);
|
|
14584
|
-
|
|
14585
|
-
|
|
14586
|
-
|
|
14587
|
-
|
|
14588
|
-
|
|
14589
|
-
|
|
14590
|
-
|
|
14591
|
-
|
|
14592
|
-
|
|
14593
|
-
|
|
14594
|
-
|
|
14595
|
-
|
|
14596
|
-
|
|
14597
|
-
|
|
14598
|
-
|
|
14599
|
-
|
|
14600
|
-
|
|
14601
|
-
|
|
14602
|
-
|
|
14603
|
-
|
|
14604
|
-
|
|
14605
|
-
|
|
14606
|
-
|
|
14607
|
-
|
|
14608
|
-
|
|
14609
|
-
);
|
|
14610
|
-
import_node_fs24.default.renameSync(finalOutput, outputPath(args));
|
|
14611
|
-
if (KEEP_WASM_NAMES)
|
|
14612
|
-
import_node_fs24.default.writeFileSync(
|
|
14613
|
-
outputPath(args),
|
|
14614
|
-
nameGuestImageAliases(import_node_fs24.default.readFileSync(outputPath(args)), plan.symbols)
|
|
14615
|
-
);
|
|
14616
|
-
if (projectionStorage && projectionObject)
|
|
14617
|
-
options.projection.onReserved(projectionStorage, projectionObject);
|
|
14618
|
-
options.onLinkedOwners?.(linkedOwners);
|
|
14619
|
-
options.onLinkedSections?.(sectionOwners);
|
|
14620
|
-
options.onDyldRows?.(ledger);
|
|
14621
|
-
if (options.onSplitInputs && ledger.appLLVMIR) {
|
|
14622
|
-
const appLedgerObject = compileLedger("app-ledger", ledger.appLLVMIR);
|
|
14623
|
-
const appSections = new Map(
|
|
14799
|
+
replacements.set(artifact.path, output);
|
|
14800
|
+
archiveJobs.push({ artifact, index, members, memberDir, output, response });
|
|
14801
|
+
}
|
|
14802
|
+
const [ledgerObject] = await Promise.all([
|
|
14803
|
+
ledgerObjectPromise,
|
|
14804
|
+
mapLimit(archiveJobs, 8, async ({ artifact, members, output, response }) => {
|
|
14805
|
+
const { stdout } = await execFileAsync(llvmAr, ["t", artifact.path], {
|
|
14806
|
+
encoding: "utf8",
|
|
14807
|
+
maxBuffer: 64 * 1024 * 1024
|
|
14808
|
+
});
|
|
14809
|
+
const listing = stdout.trimEnd();
|
|
14810
|
+
const listed = listing ? listing.split("\n") : [];
|
|
14811
|
+
if (listed.length !== members.length || new Set(listed).size !== listed.length || members.some(
|
|
14812
|
+
(member, i) => listed[i] !== member.name || import_node_path24.default.basename(member.name) !== member.name
|
|
14813
|
+
))
|
|
14814
|
+
throw new Error(`unsupported archive layout ${artifact.path}`);
|
|
14815
|
+
await execFileAsync(llvmAr, ["rcs", output, `@${response}`], {
|
|
14816
|
+
maxBuffer: 64 * 1024 * 1024
|
|
14817
|
+
});
|
|
14818
|
+
})
|
|
14819
|
+
]);
|
|
14820
|
+
const lazyExports = import_node_path24.default.join(directory, "lazy-exports.rsp");
|
|
14821
|
+
import_node_fs24.default.writeFileSync(lazyExports, guestLazyExports(ledger.lazyFunctions));
|
|
14822
|
+
linkedOwners.set(ledgerObject, options.ledgerDataImage);
|
|
14823
|
+
const sectionOwners = new Map(
|
|
14624
14824
|
ledger.callerWrappers.map(({ symbol, image }) => [
|
|
14625
|
-
`${
|
|
14825
|
+
`${ledgerObject}:(${symbol})`,
|
|
14626
14826
|
image
|
|
14627
14827
|
])
|
|
14628
14828
|
);
|
|
14629
|
-
|
|
14630
|
-
|
|
14631
|
-
|
|
14632
|
-
|
|
14633
|
-
|
|
14634
|
-
|
|
14635
|
-
|
|
14636
|
-
|
|
14637
|
-
|
|
14638
|
-
|
|
14639
|
-
|
|
14640
|
-
|
|
14641
|
-
options.onSplitInputs({
|
|
14642
|
-
appObjects,
|
|
14643
|
-
appSections,
|
|
14644
|
-
sdkObjects,
|
|
14645
|
-
lazyFunctions: ledger.appLazyFunctions ?? [],
|
|
14646
|
-
dyldSymbols: ledger.dyldSymbols,
|
|
14647
|
-
appReferencedSymbols,
|
|
14648
|
-
appDefinedSymbols
|
|
14829
|
+
const byToken = new Map(
|
|
14830
|
+
occurrences(plan, args).map(({ artifact, token }) => [
|
|
14831
|
+
token,
|
|
14832
|
+
replacements.get(artifact.path)
|
|
14833
|
+
])
|
|
14834
|
+
);
|
|
14835
|
+
const placed = /* @__PURE__ */ new Set();
|
|
14836
|
+
const finalArgs = args.map((arg) => byToken.get(arg) ?? arg).filter((arg) => {
|
|
14837
|
+
if (!arg.endsWith(".o") && !arg.endsWith(".a")) return true;
|
|
14838
|
+
if (placed.has(arg)) return false;
|
|
14839
|
+
placed.add(arg);
|
|
14840
|
+
return true;
|
|
14649
14841
|
});
|
|
14842
|
+
const finalOutput = import_node_path24.default.join(directory, "final.wasm");
|
|
14843
|
+
const finalWhy = import_node_path24.default.join(directory, "final-why-extract.txt");
|
|
14844
|
+
const linkFinal = (projectionObject2, layoutMap) => runLink("final", [
|
|
14845
|
+
...withOutput(finalArgs, finalOutput, false),
|
|
14846
|
+
ledgerObject,
|
|
14847
|
+
`@${lazyExports}`,
|
|
14848
|
+
...projectionObject2 ? [projectionObject2] : [],
|
|
14849
|
+
...provider ? [`--undefined=${providerSymbol}`] : [],
|
|
14850
|
+
...layoutMap ? [`--Map=${layoutMap}`] : [],
|
|
14851
|
+
`--why-extract=${finalWhy}`
|
|
14852
|
+
]);
|
|
14853
|
+
let projectionObject;
|
|
14854
|
+
let projectionStorage;
|
|
14855
|
+
let finalTrace;
|
|
14856
|
+
if (options.projection) {
|
|
14857
|
+
const projection = options.projection;
|
|
14858
|
+
if (!plan.images.some((image) => image.id === projection.image))
|
|
14859
|
+
throw new Error("guest projection has no source image");
|
|
14860
|
+
if (projection.images.length !== plan.images.length || projection.images.some(
|
|
14861
|
+
(image, index) => image.image !== index || plan.images[index]?.id !== index
|
|
14862
|
+
))
|
|
14863
|
+
throw new Error("guest projection image order differs from link plan");
|
|
14864
|
+
const selectedInputs = selectedGuestManifestInputs(
|
|
14865
|
+
plan,
|
|
14866
|
+
selected,
|
|
14867
|
+
projection.identities,
|
|
14868
|
+
readSelected
|
|
14869
|
+
);
|
|
14870
|
+
const images = projection.images.map(
|
|
14871
|
+
(image) => createGuestImageManifest({
|
|
14872
|
+
...image,
|
|
14873
|
+
inputs: selectedInputs.get(image.image) ?? [],
|
|
14874
|
+
linkOptions: projection.linkOptions,
|
|
14875
|
+
regions: []
|
|
14876
|
+
})
|
|
14877
|
+
);
|
|
14878
|
+
objectBytes.clear();
|
|
14879
|
+
memberBytes.clear();
|
|
14880
|
+
archives.clear();
|
|
14881
|
+
if (!discoveryRegions) throw new Error("guest projection layout object missing");
|
|
14882
|
+
const regionsBefore = discoveryRegions;
|
|
14883
|
+
const ledgerPieces = guestProjectionRegionCapacity(
|
|
14884
|
+
[import_node_fs24.default.readFileSync(ledgerObject)],
|
|
14885
|
+
0
|
|
14886
|
+
);
|
|
14887
|
+
const bundleCount = images.filter(
|
|
14888
|
+
(image) => image.resourceBundlePath !== void 0
|
|
14889
|
+
).length;
|
|
14890
|
+
const projectionPieces = images.length + 2 + (bundleCount ? bundleCount + 1 : 0);
|
|
14891
|
+
let capacities = ledger.images.map((image) => ({
|
|
14892
|
+
regions: regionsBefore[image.id] + 1 + ledger.callerWrappers.filter((wrapper) => wrapper.image === image.id).length + (image.id === options.ledgerDataImage ? ledgerPieces : 0) + (image.id === projection.image ? projectionPieces : 0),
|
|
14893
|
+
memoryProtection: projection.memoryProtection,
|
|
14894
|
+
tableProtection: projection.tableProtection
|
|
14895
|
+
}));
|
|
14896
|
+
const projectionSource = import_node_path24.default.join(directory, "projection.c");
|
|
14897
|
+
projectionObject = import_node_path24.default.join(directory, "projection.o");
|
|
14898
|
+
const callerMap = args.find((arg) => arg.startsWith("--Map="))?.slice("--Map=".length);
|
|
14899
|
+
const layoutMap = callerMap ?? import_node_path24.default.join(directory, "projection-layout.map");
|
|
14900
|
+
for (; ; ) {
|
|
14901
|
+
projectionStorage = reserveGuestProjectionStorage(images, capacities);
|
|
14902
|
+
import_node_fs24.default.writeFileSync(projectionSource, projectionStorage.source);
|
|
14903
|
+
(0, import_node_child_process14.execFileSync)(
|
|
14904
|
+
clang,
|
|
14905
|
+
[...projection.clangOptions, "-c", projectionSource, "-o", projectionObject],
|
|
14906
|
+
{ stdio: "pipe" }
|
|
14907
|
+
);
|
|
14908
|
+
finalTrace = linkFinal(projectionObject, callerMap ? void 0 : layoutMap);
|
|
14909
|
+
if (sharedSdk) break;
|
|
14910
|
+
const wasm = import_node_fs24.default.readFileSync(finalOutput);
|
|
14911
|
+
const actual = guestProjectionRegionCounts(
|
|
14912
|
+
images.length,
|
|
14913
|
+
guestLinkedSpans(
|
|
14914
|
+
guestLinkLines(layoutMap),
|
|
14915
|
+
wasm,
|
|
14916
|
+
wasm,
|
|
14917
|
+
new Map(linkedOwners).set(projectionObject, projection.image),
|
|
14918
|
+
sectionOwners
|
|
14919
|
+
)
|
|
14920
|
+
);
|
|
14921
|
+
if (actual.every((count, index) => count <= capacities[index].regions)) break;
|
|
14922
|
+
capacities = capacities.map((capacity, index) => ({
|
|
14923
|
+
...capacity,
|
|
14924
|
+
regions: Math.max(actual[index], capacity.regions)
|
|
14925
|
+
}));
|
|
14926
|
+
}
|
|
14927
|
+
linkedOwners.set(projectionObject, projection.image);
|
|
14928
|
+
} else finalTrace = linkFinal();
|
|
14929
|
+
const finalSelection = selectedGuestLinkInputs(
|
|
14930
|
+
remapGuestLinkPlan(plan, replacements),
|
|
14931
|
+
finalArgs,
|
|
14932
|
+
import_node_fs24.default.readFileSync(finalWhy, "utf8"),
|
|
14933
|
+
finalTrace,
|
|
14934
|
+
finalArchives
|
|
14935
|
+
);
|
|
14936
|
+
const original = new Map([...replacements].map(([before2, after2]) => [after2, before2]));
|
|
14937
|
+
const key = (item) => JSON.stringify([original.get(item.artifact) ?? item.artifact, item.member]);
|
|
14938
|
+
const before = new Set(selected.map(key));
|
|
14939
|
+
const after = new Set(finalSelection.map(key));
|
|
14940
|
+
const changed = [...before].filter((item) => !after.has(item));
|
|
14941
|
+
changed.push(...[...after].filter((item) => !before.has(item)));
|
|
14942
|
+
if (changed.length)
|
|
14943
|
+
throw new Error(
|
|
14944
|
+
`guest link selected different inputs after rewriting:
|
|
14945
|
+
${changed.join("\n")}`
|
|
14946
|
+
);
|
|
14947
|
+
import_node_fs24.default.renameSync(finalOutput, outputPath(args));
|
|
14948
|
+
if (KEEP_WASM_NAMES)
|
|
14949
|
+
import_node_fs24.default.writeFileSync(
|
|
14950
|
+
outputPath(args),
|
|
14951
|
+
nameGuestImageAliases(import_node_fs24.default.readFileSync(outputPath(args)), plan.symbols)
|
|
14952
|
+
);
|
|
14953
|
+
if (projectionStorage && projectionObject)
|
|
14954
|
+
options.projection.onReserved(projectionStorage, projectionObject);
|
|
14955
|
+
options.onLinkedOwners?.(linkedOwners);
|
|
14956
|
+
options.onLinkedSections?.(sectionOwners);
|
|
14957
|
+
options.onDyldRows?.(ledger);
|
|
14958
|
+
if (options.onSplitInputs && appLedgerObjectPromise) {
|
|
14959
|
+
const appLedgerObject = await appLedgerObjectPromise;
|
|
14960
|
+
const appSections = new Map(
|
|
14961
|
+
ledger.callerWrappers.map(({ symbol, image }) => [
|
|
14962
|
+
`${appLedgerObject}:(${symbol})`,
|
|
14963
|
+
image
|
|
14964
|
+
])
|
|
14965
|
+
);
|
|
14966
|
+
appObjects.set(appLedgerObject, options.ledgerDataImage);
|
|
14967
|
+
let appReferencedSymbols;
|
|
14968
|
+
let appDefinedSymbols;
|
|
14969
|
+
if (ledger.appReferencedSymbols && ledger.appDefinedSymbols) {
|
|
14970
|
+
const referenced = new Set(ledger.appReferencedSymbols);
|
|
14971
|
+
const defined = new Set(ledger.appDefinedSymbols);
|
|
14972
|
+
const ledgerSyms = guestWasmSymbols(import_node_fs24.default.readFileSync(appLedgerObject));
|
|
14973
|
+
for (const name3 of ledgerSyms.undefined) referenced.add(name3);
|
|
14974
|
+
for (const name3 of ledgerSyms.defined) defined.add(name3);
|
|
14975
|
+
appReferencedSymbols = referenced;
|
|
14976
|
+
appDefinedSymbols = defined;
|
|
14977
|
+
}
|
|
14978
|
+
options.onSplitInputs({
|
|
14979
|
+
appObjects,
|
|
14980
|
+
appSections,
|
|
14981
|
+
sdkObjects,
|
|
14982
|
+
lazyFunctions: ledger.appLazyFunctions ?? [],
|
|
14983
|
+
dyldSymbols: ledger.dyldSymbols,
|
|
14984
|
+
appReferencedSymbols,
|
|
14985
|
+
appDefinedSymbols
|
|
14986
|
+
});
|
|
14987
|
+
}
|
|
14988
|
+
return selected;
|
|
14989
|
+
} catch (error) {
|
|
14990
|
+
await Promise.allSettled([
|
|
14991
|
+
ledgerObjectPromise,
|
|
14992
|
+
...appLedgerObjectPromise ? [appLedgerObjectPromise] : []
|
|
14993
|
+
]);
|
|
14994
|
+
throw error;
|
|
14650
14995
|
}
|
|
14651
|
-
return selected;
|
|
14652
14996
|
}
|
|
14653
14997
|
function linkedMapSymbols(lines) {
|
|
14654
14998
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -14750,24 +15094,19 @@ function aliasGuestLinkArguments(input, archives) {
|
|
|
14750
15094
|
throw new Error("aliased guest archive is not a link input");
|
|
14751
15095
|
return result;
|
|
14752
15096
|
}
|
|
14753
|
-
function linkCompleteGuestImages(options) {
|
|
15097
|
+
async function linkCompleteGuestImages(options) {
|
|
14754
15098
|
const args = normalizedGuestLinkArgs(options.args);
|
|
14755
|
-
const
|
|
14756
|
-
|
|
14757
|
-
|
|
14758
|
-
|
|
14759
|
-
|
|
14760
|
-
import_node_fs24.default.readSync(descriptor, magic, 0, magic.length, 0);
|
|
14761
|
-
} finally {
|
|
14762
|
-
import_node_fs24.default.closeSync(descriptor);
|
|
14763
|
-
}
|
|
14764
|
-
return {
|
|
15099
|
+
const owned = new Set(
|
|
15100
|
+
options.plan.artifacts.map((artifact) => import_node_path24.default.resolve(artifact.path))
|
|
15101
|
+
);
|
|
15102
|
+
const candidates = guestLinkInputFilesWithKind(args).filter((item) => !owned.has(item.path)).map(
|
|
15103
|
+
({ path: file, kind }) => ({
|
|
14765
15104
|
path: file,
|
|
14766
|
-
kind
|
|
15105
|
+
kind,
|
|
14767
15106
|
image: null,
|
|
14768
15107
|
instrumentDynamicLookups: false
|
|
14769
|
-
}
|
|
14770
|
-
|
|
15108
|
+
})
|
|
15109
|
+
);
|
|
14771
15110
|
return linkGuestImages({
|
|
14772
15111
|
...options,
|
|
14773
15112
|
args,
|
|
@@ -14776,22 +15115,19 @@ function linkCompleteGuestImages(options) {
|
|
|
14776
15115
|
}
|
|
14777
15116
|
function discoverGuestLinkInputs(options) {
|
|
14778
15117
|
const args = normalizedGuestLinkArgs(options.args);
|
|
14779
|
-
const artifacts =
|
|
14780
|
-
|
|
14781
|
-
|
|
14782
|
-
|
|
14783
|
-
|
|
14784
|
-
|
|
14785
|
-
|
|
14786
|
-
|
|
14787
|
-
const kind = magic.toString("ascii") === "!<arch>\n" ? "archive" : "object";
|
|
14788
|
-
return { path: file, kind, image: 0, instrumentDynamicLookups: false };
|
|
14789
|
-
});
|
|
15118
|
+
const artifacts = guestLinkInputFilesWithKind(args).map(
|
|
15119
|
+
({ path: file, kind }) => ({
|
|
15120
|
+
path: file,
|
|
15121
|
+
kind,
|
|
15122
|
+
image: 0,
|
|
15123
|
+
instrumentDynamicLookups: false
|
|
15124
|
+
})
|
|
15125
|
+
);
|
|
14790
15126
|
const plan = { images: [], callers: [], artifacts, symbols: [] };
|
|
14791
15127
|
import_node_fs24.default.mkdirSync(options.directory, { recursive: true });
|
|
14792
15128
|
const why = import_node_path24.default.join(options.directory, "preselection-why.txt");
|
|
14793
15129
|
const response = import_node_path24.default.join(options.directory, "preselection.rsp");
|
|
14794
|
-
const output = process.platform !== "win32" ? "/dev/null" : import_node_path24.default.join(options.directory, "preselection.wasm");
|
|
15130
|
+
const output = options.output ?? (process.platform !== "win32" ? "/dev/null" : import_node_path24.default.join(options.directory, "preselection.wasm"));
|
|
14795
15131
|
const flags = [
|
|
14796
15132
|
...withOutput(args, output, true),
|
|
14797
15133
|
...options.objects,
|
|
@@ -14799,6 +15135,7 @@ function discoverGuestLinkInputs(options) {
|
|
|
14799
15135
|
// the selection that assigns member owners.
|
|
14800
15136
|
"--undefined=__peach_dlsym_from_image",
|
|
14801
15137
|
`--why-extract=${why}`,
|
|
15138
|
+
...options.mapPath ? [`--Map=${options.mapPath}`] : [],
|
|
14802
15139
|
"--trace"
|
|
14803
15140
|
];
|
|
14804
15141
|
import_node_fs24.default.writeFileSync(response, flags.map((flag) => JSON.stringify(flag)).join(" "));
|
|
@@ -14812,6 +15149,7 @@ function discoverGuestLinkInputs(options) {
|
|
|
14812
15149
|
} finally {
|
|
14813
15150
|
import_node_fs24.default.closeSync(traceOutput);
|
|
14814
15151
|
}
|
|
15152
|
+
options.onOutput?.({ why, trace, output, mapPath: options.mapPath });
|
|
14815
15153
|
return selectedGuestLinkInputs(
|
|
14816
15154
|
plan,
|
|
14817
15155
|
args,
|
|
@@ -14836,7 +15174,10 @@ function prepareGuestRuntimeInputs(options) {
|
|
|
14836
15174
|
)
|
|
14837
15175
|
);
|
|
14838
15176
|
const archives = [];
|
|
14839
|
-
for (const file of
|
|
15177
|
+
for (const { path: file, kind } of guestLinkInputFilesWithKind(
|
|
15178
|
+
normalizedGuestLinkArgs(options.args)
|
|
15179
|
+
)) {
|
|
15180
|
+
if (kind !== "archive") continue;
|
|
14840
15181
|
const original = originals.get(file) ?? file;
|
|
14841
15182
|
if (!recordedArchives.has(original) && libraryArchiveTarget(original) === null)
|
|
14842
15183
|
continue;
|
|
@@ -14851,11 +15192,23 @@ function prepareGuestRuntimeInputs(options) {
|
|
|
14851
15192
|
);
|
|
14852
15193
|
}
|
|
14853
15194
|
const args = aliasGuestLinkArguments(options.args, archives);
|
|
15195
|
+
let discovery;
|
|
14854
15196
|
const selected = discoverGuestLinkInputs({
|
|
14855
15197
|
args,
|
|
14856
15198
|
directory: options.directory,
|
|
14857
15199
|
wasmLd: options.wasmLd,
|
|
14858
|
-
objects: options.discoveryObjects
|
|
15200
|
+
objects: options.discoveryObjects,
|
|
15201
|
+
output: options.discoveryOutput,
|
|
15202
|
+
mapPath: options.discoveryMap,
|
|
15203
|
+
onOutput: options.discoveryOutput && options.discoveryMap && options.discoveryObjects.length === 1 ? ({ why, trace, output, mapPath }) => {
|
|
15204
|
+
discovery = {
|
|
15205
|
+
wasm: output,
|
|
15206
|
+
map: mapPath,
|
|
15207
|
+
why,
|
|
15208
|
+
trace,
|
|
15209
|
+
projectionObject: options.discoveryObjects[0]
|
|
15210
|
+
};
|
|
15211
|
+
} : void 0
|
|
14859
15212
|
});
|
|
14860
15213
|
const originalSelection = originalGuestArchiveSelections(selected, archives);
|
|
14861
15214
|
const closure = guestRuntimeProductsForInputs({
|
|
@@ -14887,7 +15240,15 @@ function prepareGuestRuntimeInputs(options) {
|
|
|
14887
15240
|
rewritten: options.rewritten,
|
|
14888
15241
|
images: new Map([...closure.images, ...closure.containingImages])
|
|
14889
15242
|
});
|
|
14890
|
-
return {
|
|
15243
|
+
return {
|
|
15244
|
+
args,
|
|
15245
|
+
selected,
|
|
15246
|
+
originalSelection,
|
|
15247
|
+
archives,
|
|
15248
|
+
sdkProducts,
|
|
15249
|
+
archiveArtifacts,
|
|
15250
|
+
discovery
|
|
15251
|
+
};
|
|
14891
15252
|
}
|
|
14892
15253
|
function selectedGuestSymbolInputs(plan, selected, readSelected) {
|
|
14893
15254
|
const artifacts = new Map(plan.artifacts.map((artifact) => [artifact.path, artifact]));
|
|
@@ -14981,10 +15342,21 @@ function verifyGuestSymbolScopes(options) {
|
|
|
14981
15342
|
const records = /* @__PURE__ */ new Map();
|
|
14982
15343
|
for (const line of guestLinkLines(tracePath)) {
|
|
14983
15344
|
const refSep = line.lastIndexOf(": reference to ");
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
15345
|
+
let isRef = false;
|
|
15346
|
+
let sep = -1;
|
|
15347
|
+
if (refSep >= 0) {
|
|
15348
|
+
const defAfter = line.indexOf(": definition of ", refSep + 15);
|
|
15349
|
+
if (defAfter >= 0) {
|
|
15350
|
+
sep = line.lastIndexOf(": definition of ");
|
|
15351
|
+
isRef = false;
|
|
15352
|
+
} else {
|
|
15353
|
+
sep = refSep;
|
|
15354
|
+
isRef = true;
|
|
15355
|
+
}
|
|
15356
|
+
} else {
|
|
15357
|
+
sep = line.lastIndexOf(": definition of ");
|
|
15358
|
+
if (sep < 0) continue;
|
|
15359
|
+
}
|
|
14988
15360
|
const symbol = line.slice(sep + (isRef ? 15 : 16));
|
|
14989
15361
|
if (!requested.has(symbol) || options.hostImports.has(symbol)) continue;
|
|
14990
15362
|
let record = records.get(symbol);
|
|
@@ -15154,139 +15526,139 @@ function verifyGuestSymbolScopes(options) {
|
|
|
15154
15526
|
}
|
|
15155
15527
|
return { bindings: result, directBindings };
|
|
15156
15528
|
}
|
|
15157
|
-
function linkPrunedGuestImages(options) {
|
|
15158
|
-
let
|
|
15529
|
+
async function linkPrunedGuestImages(options) {
|
|
15530
|
+
let pruned;
|
|
15159
15531
|
pruneSwiftWasmLink(
|
|
15160
15532
|
options.buildDirectory,
|
|
15161
15533
|
options.toolchainBin,
|
|
15162
15534
|
options.moduleRoot,
|
|
15163
15535
|
options.staticClangTargets,
|
|
15164
15536
|
void 0,
|
|
15165
|
-
(
|
|
15166
|
-
|
|
15167
|
-
|
|
15168
|
-
|
|
15169
|
-
|
|
15170
|
-
|
|
15171
|
-
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
|
|
15179
|
-
|
|
15180
|
-
|
|
15181
|
-
|
|
15182
|
-
|
|
15183
|
-
|
|
15184
|
-
|
|
15185
|
-
|
|
15186
|
-
|
|
15187
|
-
|
|
15188
|
-
|
|
15189
|
-
|
|
15190
|
-
|
|
15191
|
-
|
|
15192
|
-
|
|
15193
|
-
|
|
15194
|
-
|
|
15537
|
+
(args2, rewritten2, sdk2) => {
|
|
15538
|
+
pruned = { args: args2, rewritten: rewritten2, sdk: sdk2 };
|
|
15539
|
+
},
|
|
15540
|
+
options.resourceReferences
|
|
15541
|
+
);
|
|
15542
|
+
if (!pruned) throw new Error("guest link did not receive pruned inputs");
|
|
15543
|
+
const { args, rewritten, sdk } = pruned;
|
|
15544
|
+
if (args.some((arg) => arg === "--Map" || arg.startsWith("--Map=")))
|
|
15545
|
+
throw new Error("guest link already has a linker map");
|
|
15546
|
+
const framework = options.framework;
|
|
15547
|
+
const prepared = options.prepareRuntime?.(args, rewritten, sdk);
|
|
15548
|
+
if (prepared && options.sdkProducts !== null)
|
|
15549
|
+
throw new Error("guest runtime products supplied twice");
|
|
15550
|
+
const linkedArgs = prepared?.args ?? args;
|
|
15551
|
+
const sdkProducts = prepared?.sdkProducts ?? (typeof options.sdkProducts === "function" ? options.sdkProducts(args, rewritten, sdk) : options.sdkProducts);
|
|
15552
|
+
const sourcePlan = options.plan(linkedArgs, rewritten, sdk, sdkProducts);
|
|
15553
|
+
let frameworkArtifacts = [];
|
|
15554
|
+
const selectedObjects = prepared && new Set(
|
|
15555
|
+
prepared.selected.filter((item) => item.member === null).map((item) => import_node_path24.default.resolve(item.artifact))
|
|
15556
|
+
);
|
|
15557
|
+
const selectedFramework = framework && (!prepared || framework.product.objects.some((object4) => {
|
|
15558
|
+
const original = import_node_path24.default.resolve(framework.root, object4.path);
|
|
15559
|
+
const linked = import_node_path24.default.resolve(rewritten.get(original) ?? original);
|
|
15560
|
+
return selectedObjects?.has(linked) ?? false;
|
|
15561
|
+
}));
|
|
15562
|
+
if (framework && selectedFramework) {
|
|
15563
|
+
const image = sdkProducts?.images.get(frameworkRuntimeProductId(framework.product));
|
|
15564
|
+
if (image === void 0)
|
|
15565
|
+
throw new Error("framework objects require their declared compiler runtime image");
|
|
15566
|
+
frameworkArtifacts = guestFrameworkLinkArtifacts(
|
|
15567
|
+
framework.product,
|
|
15568
|
+
framework.root,
|
|
15569
|
+
linkedArgs,
|
|
15570
|
+
rewritten,
|
|
15571
|
+
image
|
|
15572
|
+
);
|
|
15573
|
+
}
|
|
15574
|
+
if (sdkProducts) {
|
|
15575
|
+
for (const image of guestSdkProductImages(
|
|
15576
|
+
sdkProducts.products.map((entry) => entry.product),
|
|
15577
|
+
sdkProducts.images
|
|
15578
|
+
)) {
|
|
15579
|
+
const planned = sourcePlan.images.find((entry) => entry.id === image.id);
|
|
15580
|
+
if (!planned || planned.name !== image.name || planned.dependencies.length !== image.dependencies.length || planned.dependencies.some(
|
|
15581
|
+
(dependency, index) => dependency !== image.dependencies[index]
|
|
15582
|
+
))
|
|
15583
|
+
throw new Error(`SDK image scope differs from source product ${image.name}`);
|
|
15584
|
+
}
|
|
15585
|
+
}
|
|
15586
|
+
const remappedPlan = remapGuestLinkPlan(
|
|
15587
|
+
{
|
|
15588
|
+
...sourcePlan,
|
|
15589
|
+
artifacts: [
|
|
15590
|
+
...sourcePlan.artifacts,
|
|
15591
|
+
...frameworkArtifacts,
|
|
15592
|
+
...sdkProducts ? guestSdkProductLinkArtifacts(
|
|
15593
|
+
sdkProducts.products,
|
|
15594
|
+
sdk,
|
|
15195
15595
|
linkedArgs,
|
|
15596
|
+
sdkProducts.linkedArchives,
|
|
15196
15597
|
rewritten,
|
|
15197
|
-
|
|
15198
|
-
|
|
15199
|
-
|
|
15200
|
-
|
|
15201
|
-
|
|
15202
|
-
sdkProducts.products.map((entry) => entry.product),
|
|
15203
|
-
sdkProducts.images
|
|
15204
|
-
)) {
|
|
15205
|
-
const planned = sourcePlan.images.find((entry) => entry.id === image.id);
|
|
15206
|
-
if (!planned || planned.name !== image.name || planned.dependencies.length !== image.dependencies.length || planned.dependencies.some(
|
|
15207
|
-
(dependency, index) => dependency !== image.dependencies[index]
|
|
15208
|
-
))
|
|
15209
|
-
throw new Error(`SDK image scope differs from source product ${image.name}`);
|
|
15210
|
-
}
|
|
15211
|
-
}
|
|
15212
|
-
const remappedPlan = remapGuestLinkPlan(
|
|
15213
|
-
{
|
|
15214
|
-
...sourcePlan,
|
|
15215
|
-
artifacts: [
|
|
15216
|
-
...sourcePlan.artifacts,
|
|
15217
|
-
...frameworkArtifacts,
|
|
15218
|
-
...sdkProducts ? guestSdkProductLinkArtifacts(
|
|
15219
|
-
sdkProducts.products,
|
|
15220
|
-
sdk,
|
|
15221
|
-
linkedArgs,
|
|
15222
|
-
sdkProducts.linkedArchives,
|
|
15223
|
-
rewritten,
|
|
15224
|
-
new Map([...sdkProducts.images, ...sdkProducts.containingImages]),
|
|
15225
|
-
prepared?.selected
|
|
15226
|
-
) : [],
|
|
15227
|
-
...prepared?.archiveArtifacts ?? []
|
|
15228
|
-
]
|
|
15229
|
-
},
|
|
15230
|
-
rewritten
|
|
15231
|
-
);
|
|
15232
|
-
const plan = aliasGuestLinkPlan(remappedPlan, prepared?.archives ?? []);
|
|
15233
|
-
let owners = /* @__PURE__ */ new Map();
|
|
15234
|
-
let generatedSectionOwners = /* @__PURE__ */ new Map();
|
|
15235
|
-
let projection = typeof options.projection === "function" ? options.projection(linkedArgs, rewritten, sdk, sdkProducts, plan) : options.projection;
|
|
15236
|
-
if (projection && prepared) {
|
|
15237
|
-
const identities = new Map(projection.identities);
|
|
15238
|
-
for (const [before, after] of rewritten) {
|
|
15239
|
-
const identity = identities.get(before);
|
|
15240
|
-
const existing = identities.get(after);
|
|
15241
|
-
if (identity !== void 0 && existing !== void 0 && existing !== identity)
|
|
15242
|
-
throw new Error(`rewritten guest input has conflicting identity ${after}`);
|
|
15243
|
-
if (identity !== void 0) identities.set(after, identity);
|
|
15244
|
-
}
|
|
15245
|
-
projection = {
|
|
15246
|
-
...projection,
|
|
15247
|
-
identities: aliasGuestLinkIdentities(identities, prepared.archives)
|
|
15248
|
-
};
|
|
15249
|
-
}
|
|
15250
|
-
const selected = linkCompleteGuestImages({
|
|
15251
|
-
plan,
|
|
15252
|
-
args: [...linkedArgs, `--Map=${options.mapPath}`],
|
|
15253
|
-
directory: options.linkDirectory,
|
|
15254
|
-
wasmLd: import_node_path24.default.join(options.toolchainBin, "wasm-ld"),
|
|
15255
|
-
clang: import_node_path24.default.join(options.toolchainBin, "clang"),
|
|
15256
|
-
llvmAr: import_node_path24.default.join(options.toolchainBin, "llvm-ar"),
|
|
15257
|
-
ledgerDataImage: options.ledgerDataImage,
|
|
15258
|
-
projection,
|
|
15259
|
-
resolvePlan: options.resolvePlan,
|
|
15260
|
-
sharedSdk: options.sharedSdk,
|
|
15261
|
-
onSplitInputs: options.onSplitInputs,
|
|
15262
|
-
onDyldRows: options.onDyldRows,
|
|
15263
|
-
onLinkedOwners: (value) => {
|
|
15264
|
-
owners = value;
|
|
15265
|
-
},
|
|
15266
|
-
onLinkedSections: (value) => {
|
|
15267
|
-
generatedSectionOwners = value;
|
|
15268
|
-
}
|
|
15269
|
-
});
|
|
15270
|
-
result = {
|
|
15271
|
-
selected,
|
|
15272
|
-
owners,
|
|
15273
|
-
generatedSectionOwners,
|
|
15274
|
-
sdk,
|
|
15275
|
-
mapPath: options.mapPath
|
|
15276
|
-
};
|
|
15598
|
+
new Map([...sdkProducts.images, ...sdkProducts.containingImages]),
|
|
15599
|
+
prepared?.selected
|
|
15600
|
+
) : [],
|
|
15601
|
+
...prepared?.archiveArtifacts ?? []
|
|
15602
|
+
]
|
|
15277
15603
|
},
|
|
15278
|
-
|
|
15604
|
+
rewritten
|
|
15279
15605
|
);
|
|
15280
|
-
|
|
15281
|
-
|
|
15606
|
+
const plan = aliasGuestLinkPlan(remappedPlan, prepared?.archives ?? []);
|
|
15607
|
+
let owners = /* @__PURE__ */ new Map();
|
|
15608
|
+
let generatedSectionOwners = /* @__PURE__ */ new Map();
|
|
15609
|
+
let projection = typeof options.projection === "function" ? options.projection(linkedArgs, rewritten, sdk, sdkProducts, plan) : options.projection;
|
|
15610
|
+
if (projection && prepared) {
|
|
15611
|
+
const identities = new Map(projection.identities);
|
|
15612
|
+
for (const [before, after] of rewritten) {
|
|
15613
|
+
const identity = identities.get(before);
|
|
15614
|
+
const existing = identities.get(after);
|
|
15615
|
+
if (identity !== void 0 && existing !== void 0 && existing !== identity)
|
|
15616
|
+
throw new Error(`rewritten guest input has conflicting identity ${after}`);
|
|
15617
|
+
if (identity !== void 0) identities.set(after, identity);
|
|
15618
|
+
}
|
|
15619
|
+
projection = {
|
|
15620
|
+
...projection,
|
|
15621
|
+
identities: aliasGuestLinkIdentities(identities, prepared.archives)
|
|
15622
|
+
};
|
|
15623
|
+
}
|
|
15624
|
+
const selected = await linkCompleteGuestImages({
|
|
15625
|
+
plan,
|
|
15626
|
+
args: [...linkedArgs, `--Map=${options.mapPath}`],
|
|
15627
|
+
directory: options.linkDirectory,
|
|
15628
|
+
wasmLd: import_node_path24.default.join(options.toolchainBin, "wasm-ld"),
|
|
15629
|
+
clang: import_node_path24.default.join(options.toolchainBin, "clang"),
|
|
15630
|
+
llvmAr: import_node_path24.default.join(options.toolchainBin, "llvm-ar"),
|
|
15631
|
+
ledgerDataImage: options.ledgerDataImage,
|
|
15632
|
+
projection,
|
|
15633
|
+
preselectionDiscovery: prepared?.discovery,
|
|
15634
|
+
resolvePlan: options.resolvePlan,
|
|
15635
|
+
sharedSdk: options.sharedSdk,
|
|
15636
|
+
onSplitInputs: options.onSplitInputs,
|
|
15637
|
+
onDyldRows: options.onDyldRows,
|
|
15638
|
+
onLinkedOwners: (value) => {
|
|
15639
|
+
owners = value;
|
|
15640
|
+
},
|
|
15641
|
+
onLinkedSections: (value) => {
|
|
15642
|
+
generatedSectionOwners = value;
|
|
15643
|
+
}
|
|
15644
|
+
});
|
|
15645
|
+
return {
|
|
15646
|
+
selected,
|
|
15647
|
+
owners,
|
|
15648
|
+
generatedSectionOwners,
|
|
15649
|
+
sdk,
|
|
15650
|
+
mapPath: options.mapPath
|
|
15651
|
+
};
|
|
15282
15652
|
}
|
|
15283
|
-
var import_node_child_process14, import_node_fs24, import_node_path24;
|
|
15653
|
+
var import_node_child_process14, import_node_fs24, import_node_path24, import_node_util3, execFileAsync, WASM_MAGIC, BITCODE_MAGIC;
|
|
15284
15654
|
var init_swift_guest_link = __esm({
|
|
15285
15655
|
"src/swift-guest-link.ts"() {
|
|
15286
15656
|
"use strict";
|
|
15287
15657
|
import_node_child_process14 = require("node:child_process");
|
|
15288
15658
|
import_node_fs24 = __toESM(require("node:fs"), 1);
|
|
15289
15659
|
import_node_path24 = __toESM(require("node:path"), 1);
|
|
15660
|
+
import_node_util3 = require("node:util");
|
|
15661
|
+
init_mapLimit();
|
|
15290
15662
|
init_swift_guest_archive();
|
|
15291
15663
|
init_swift_guest_dyld_functions();
|
|
15292
15664
|
init_swift_guest_image_ledger();
|
|
@@ -15300,6 +15672,9 @@ var init_swift_guest_link = __esm({
|
|
|
15300
15672
|
init_swift_wasm_prune();
|
|
15301
15673
|
init_swiftTargetContract();
|
|
15302
15674
|
init_wasm_optimize();
|
|
15675
|
+
execFileAsync = (0, import_node_util3.promisify)(import_node_child_process14.execFile);
|
|
15676
|
+
WASM_MAGIC = Buffer.from([0, 97, 115, 109]);
|
|
15677
|
+
BITCODE_MAGIC = Buffer.from([66, 67, 192, 222]);
|
|
15303
15678
|
}
|
|
15304
15679
|
});
|
|
15305
15680
|
|
|
@@ -16988,7 +17363,7 @@ async function produceSwiftSdkImage(input) {
|
|
|
16988
17363
|
await (0, import_promises5.setTimeout)(2e3, void 0, { signal: input.signal });
|
|
16989
17364
|
}
|
|
16990
17365
|
}
|
|
16991
|
-
var import_node_child_process20, import_node_crypto22, import_node_fs34, import_node_path34, import_promises5,
|
|
17366
|
+
var import_node_child_process20, import_node_crypto22, import_node_fs34, import_node_path34, import_promises5, import_node_util4, run, environmentNames, launcher;
|
|
16992
17367
|
var init_swift_sdk_image_producer = __esm({
|
|
16993
17368
|
"src/swift-sdk-image-producer.ts"() {
|
|
16994
17369
|
"use strict";
|
|
@@ -16997,12 +17372,12 @@ var init_swift_sdk_image_producer = __esm({
|
|
|
16997
17372
|
import_node_fs34 = require("node:fs");
|
|
16998
17373
|
import_node_path34 = __toESM(require("node:path"), 1);
|
|
16999
17374
|
import_promises5 = require("node:timers/promises");
|
|
17000
|
-
|
|
17375
|
+
import_node_util4 = require("node:util");
|
|
17001
17376
|
init_admitted_mac_build();
|
|
17002
17377
|
init_is_record();
|
|
17003
17378
|
init_swift_root_lock();
|
|
17004
17379
|
init_swift_toolchain();
|
|
17005
|
-
run = (0,
|
|
17380
|
+
run = (0, import_node_util4.promisify)(import_node_child_process20.execFile);
|
|
17006
17381
|
environmentNames = [
|
|
17007
17382
|
"CONTRAST_BUILDERS_ROOT",
|
|
17008
17383
|
"PEACH_HOME",
|
|
@@ -17697,7 +18072,7 @@ function readSwiftSdkManifest(image) {
|
|
|
17697
18072
|
}));
|
|
17698
18073
|
return setBoundedCache(cachedSdkManifests, cacheKey, { manifest, block, segments });
|
|
17699
18074
|
}
|
|
17700
|
-
var import_node_child_process21, import_node_crypto23, import_node_fs35, import_node_path35,
|
|
18075
|
+
var import_node_child_process21, import_node_crypto23, import_node_fs35, import_node_path35, import_node_util5, run2, SWIFT_SDK_IMAGE_VERSION, SWIFT_SDK_APP_MEMORY_BASE, SWIFT_SDK_MEMORY_BASE, SWIFT_SDK_APP_TABLE_BASE, EMPTY_APP, IMAGE_TABLES, IMAGE_ENTRY, imageApp, IMAGE_FILE, IMAGE_DIGEST, swiftSdkImageFile, INTERFACE_FILE, MANIFEST_FILE, MANIFEST_DATA_FILE, SWIFT_SDK_IMAGE_FILES, SWIFT_SDK_IMAGE_BUNDLE, MAX_CACHED_SDK_IMAGES, cachedSdkInterfaces, cachedSdkManifestIndices, cachedSdkManifests, SWIFT_SDK_PIECE_FIELDS, MANIFEST_BLOCKS, isManifestBlock;
|
|
17701
18076
|
var init_swift_sdk_image = __esm({
|
|
17702
18077
|
"src/swift-sdk-image.ts"() {
|
|
17703
18078
|
"use strict";
|
|
@@ -17705,7 +18080,7 @@ var init_swift_sdk_image = __esm({
|
|
|
17705
18080
|
import_node_crypto23 = require("node:crypto");
|
|
17706
18081
|
import_node_fs35 = require("node:fs");
|
|
17707
18082
|
import_node_path35 = __toESM(require("node:path"), 1);
|
|
17708
|
-
|
|
18083
|
+
import_node_util5 = require("node:util");
|
|
17709
18084
|
init_native_prebuilt();
|
|
17710
18085
|
init_swift_compile();
|
|
17711
18086
|
init_swift_darwin_records();
|
|
@@ -17719,7 +18094,7 @@ var init_swift_sdk_image = __esm({
|
|
|
17719
18094
|
init_swift_wasm_prune();
|
|
17720
18095
|
init_swiftTargetContract();
|
|
17721
18096
|
init_wasm_optimize();
|
|
17722
|
-
run2 = (0,
|
|
18097
|
+
run2 = (0, import_node_util5.promisify)(import_node_child_process21.execFile);
|
|
17723
18098
|
SWIFT_SDK_IMAGE_VERSION = 13;
|
|
17724
18099
|
SWIFT_SDK_APP_MEMORY_BASE = 8372224;
|
|
17725
18100
|
SWIFT_SDK_MEMORY_BASE = 128 * 1024 * 1024;
|
|
@@ -19330,7 +19705,7 @@ function partitionParent(section2) {
|
|
|
19330
19705
|
"__objc_class_refs"
|
|
19331
19706
|
].find((name3) => section2 === name3 || section2.startsWith(`${name3}.`));
|
|
19332
19707
|
}
|
|
19333
|
-
var import_node_child_process22, import_node_crypto24, import_node_fs36, import_node_path36,
|
|
19708
|
+
var import_node_child_process22, import_node_crypto24, import_node_fs36, import_node_path36, import_node_util6, import_node_zlib4, run3, RELOCATION_WIDTHS, GLOBAL_INDEX, TLS_SLEB64, SDK_TLS_HELPER, SDK_TLS_DELTA, OBJC_SECTION_BOUNDARY, uleb4, sleb2, encodedName2, SCANNED, RUN_GAP;
|
|
19334
19709
|
var init_swift_sdk_app_module = __esm({
|
|
19335
19710
|
"src/swift-sdk-app-module.ts"() {
|
|
19336
19711
|
"use strict";
|
|
@@ -19338,7 +19713,7 @@ var init_swift_sdk_app_module = __esm({
|
|
|
19338
19713
|
import_node_crypto24 = require("node:crypto");
|
|
19339
19714
|
import_node_fs36 = require("node:fs");
|
|
19340
19715
|
import_node_path36 = __toESM(require("node:path"), 1);
|
|
19341
|
-
|
|
19716
|
+
import_node_util6 = require("node:util");
|
|
19342
19717
|
import_node_zlib4 = require("node:zlib");
|
|
19343
19718
|
init_nativeSdkBindingContract();
|
|
19344
19719
|
init_nativeWasmContract();
|
|
@@ -19353,7 +19728,7 @@ var init_swift_sdk_app_module = __esm({
|
|
|
19353
19728
|
init_swiftTargetContract();
|
|
19354
19729
|
init_wasm_narrow_boundary();
|
|
19355
19730
|
init_wasm_optimize();
|
|
19356
|
-
run3 = (0,
|
|
19731
|
+
run3 = (0, import_node_util6.promisify)(import_node_child_process22.execFile);
|
|
19357
19732
|
RELOCATION_WIDTHS = {
|
|
19358
19733
|
1: { addend: false, width: "sleb5" },
|
|
19359
19734
|
2: { addend: false, width: "u32" },
|
|
@@ -19458,8 +19833,8 @@ async function compileGuestLink(options) {
|
|
|
19458
19833
|
`--sysroot=${options.sysroot}`,
|
|
19459
19834
|
`-I${import_node_path37.default.join(options.moduleRoot, "include")}`
|
|
19460
19835
|
];
|
|
19461
|
-
const stubSource = import_node_path37.default.join(directory, "
|
|
19462
|
-
const stub = import_node_path37.default.join(directory, "
|
|
19836
|
+
const stubSource = import_node_path37.default.join(directory, "projection-discovery.c");
|
|
19837
|
+
const stub = import_node_path37.default.join(directory, "projection-discovery.o");
|
|
19463
19838
|
(0, import_node_fs37.writeFileSync)(
|
|
19464
19839
|
stubSource,
|
|
19465
19840
|
'#include "guest-image-projection.h"\nconst struct peach_guest_image __peach_guest_images[] = {{0}};\nconst uint32_t __peach_guest_image_count = 0;\n'
|
|
@@ -19522,7 +19897,7 @@ async function compileGuestLink(options) {
|
|
|
19522
19897
|
const sdkObjects = sdk ? (await Promise.resolve().then(() => (init_swift_sdk_image(), swift_sdk_image_exports))).readSwiftSdkManifestIndex(sdk).guestObjects : void 0;
|
|
19523
19898
|
if (sdk && (!sdkCallers || !sdkObjects))
|
|
19524
19899
|
throw new Error("the SDK image has no guest link manifest");
|
|
19525
|
-
const result = linkPrunedGuestImages({
|
|
19900
|
+
const result = await linkPrunedGuestImages({
|
|
19526
19901
|
buildDirectory: options.buildDirectory,
|
|
19527
19902
|
toolchainBin: options.toolchainBin,
|
|
19528
19903
|
moduleRoot: options.moduleRoot,
|
|
@@ -19551,6 +19926,8 @@ async function compileGuestLink(options) {
|
|
|
19551
19926
|
wasmLd: import_node_path37.default.join(options.toolchainBin, "wasm-ld"),
|
|
19552
19927
|
llvmAr: import_node_path37.default.join(options.toolchainBin, "llvm-ar"),
|
|
19553
19928
|
discoveryObjects: [stub],
|
|
19929
|
+
discoveryOutput: import_node_path37.default.join(directory, "discovery.wasm"),
|
|
19930
|
+
discoveryMap: import_node_path37.default.join(directory, "discovery.map"),
|
|
19554
19931
|
products: catalogs.products,
|
|
19555
19932
|
rewritten,
|
|
19556
19933
|
sdk: sdk2,
|
|
@@ -20561,7 +20938,7 @@ async function swiftIcuBundleAsset(icu) {
|
|
|
20561
20938
|
contentType: "application/octet-stream"
|
|
20562
20939
|
};
|
|
20563
20940
|
}
|
|
20564
|
-
var import_node_child_process24, import_node_crypto26, import_node_fs39, import_promises6, import_node_os9, import_node_path40,
|
|
20941
|
+
var import_node_child_process24, import_node_crypto26, import_node_fs39, import_promises6, import_node_os9, import_node_path40, import_node_util7, import_node_zlib5, run4, deflate, compressBrotli, inflateGzip, ARCHIVE, MEMBER, raw, assets, brotliMemoryCache, packedFiles;
|
|
20565
20942
|
var init_swift_icu = __esm({
|
|
20566
20943
|
"src/swift-icu.ts"() {
|
|
20567
20944
|
"use strict";
|
|
@@ -20571,15 +20948,15 @@ var init_swift_icu = __esm({
|
|
|
20571
20948
|
import_promises6 = require("node:fs/promises");
|
|
20572
20949
|
import_node_os9 = __toESM(require("node:os"), 1);
|
|
20573
20950
|
import_node_path40 = __toESM(require("node:path"), 1);
|
|
20574
|
-
|
|
20951
|
+
import_node_util7 = require("node:util");
|
|
20575
20952
|
import_node_zlib5 = require("node:zlib");
|
|
20576
20953
|
init_icuData();
|
|
20577
20954
|
init_swift_toolchain();
|
|
20578
20955
|
init_swiftTargetContract();
|
|
20579
|
-
run4 = (0,
|
|
20580
|
-
deflate = (0,
|
|
20581
|
-
compressBrotli = (0,
|
|
20582
|
-
inflateGzip = (0,
|
|
20956
|
+
run4 = (0, import_node_util7.promisify)(import_node_child_process24.execFile);
|
|
20957
|
+
deflate = (0, import_node_util7.promisify)(import_node_zlib5.gzip);
|
|
20958
|
+
compressBrotli = (0, import_node_util7.promisify)(import_node_zlib5.brotliCompress);
|
|
20959
|
+
inflateGzip = (0, import_node_util7.promisify)(import_node_zlib5.gunzip);
|
|
20583
20960
|
ARCHIVE = "wasi/lib_FoundationICU.a";
|
|
20584
20961
|
MEMBER = "icu_packaged_data.cpp.obj";
|
|
20585
20962
|
raw = /* @__PURE__ */ new Map();
|
|
@@ -28077,7 +28454,7 @@ ${wasmThreadLinkFlags.map((flag) => ` "-Xlinker", ${JSON.stringify(flag
|
|
|
28077
28454
|
REACTOR_FLAG = '"-Xclang-linker", "-mexec-model=reactor",\n';
|
|
28078
28455
|
MULTI_MANIFEST_VERSION = 76;
|
|
28079
28456
|
SWIFT_HEADER_PRODUCTS_TARGET = "PeachHeaderProducts";
|
|
28080
|
-
compilerSourceDigest = true ? "
|
|
28457
|
+
compilerSourceDigest = true ? "6fbcbab3535da2f464a19f4d3c1db8a7e4b393927e5158477332f4cc978cc22f" : swiftCompilerSourceDigest(__sootsim_import_meta_dirname);
|
|
28081
28458
|
nativeCxxCompilerFlags = ["-fno-cxx-modules"];
|
|
28082
28459
|
MODULE_MAP_RESPONSE_FILE_RUN = 16;
|
|
28083
28460
|
cFlagArray = (flags) => JSON.stringify(withoutGlogModuleMap(flags));
|