-
Notifications
You must be signed in to change notification settings - Fork 17.2k
[WebAssembly] WASIP3 Library Call Thread Context Support #175800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
48a90dd
540d785
8f222c9
e9775de
6d2b464
0bf29ae
4a18333
927daeb
e632709
f44bf29
18a1ee3
8980e38
08a3a16
9092b93
81ffb2b
a9e7310
c369bb2
d368838
61f03e5
c9665c1
07e122d
651c362
0175bd5
9a93078
85fab66
e577185
446d56d
3f10fe8
dbae3ef
e0dcb2a
e8babc7
822ea98
cb2fb8d
6cf7c2a
fa7eea8
cc1ea2f
b9039eb
1b490cd
b55ae63
a1c563b
69654ef
b98b9ab
7121ea5
70b3b93
43f756f
4ffe623
36c39bf
d953510
0656bbf
c5190ff
6e0c9c0
3386a11
5775592
4d7a81e
1001e65
7a44741
4c62c81
5bebe2a
e9fa9fc
10ed134
2ee9845
c6ddead
2bae426
557bfac
61c25c8
0fe07f0
7a58fce
8047c76
24cb457
ff172dc
d11664a
f04b74a
6bdff2c
a637ae1
0bf18a6
6c9c276
f019ea9
de9424c
5954755
1f9e903
f61837a
bde41fc
daf5b03
36ea1df
41f8893
0a8c6ec
90c342f
a42942c
13d3870
f75cb64
e1992e8
c3d46dc
9ecceef
9d296ec
95fc53a
ae859d0
abc859d
3749d9e
0028170
f9f40b7
c8d5420
9908d72
0e1a5a9
e187d8e
a2e3a85
b7bc6a3
a79dc2f
09f0fe3
1ee14c4
af1eb70
c661e66
e00d35f
742ae7c
9b688ca
3570777
45ff0f0
e841994
da1949c
8dfc97c
cdca5aa
7559ec5
4135d3d
a1cacc9
a2367c8
dfbfcd9
5c04563
08080df
92880bd
4f658ae
a3a46eb
87190fe
ed65fda
086608e
f0651c3
a69b43d
7cf2aa7
6b13795
fb482d1
aa5c37f
b92a49c
a50c1e7
b467230
4562305
92c7b06
b2d8f85
5ebc91d
f177461
9a7eac9
7b0520d
880a277
c363a1a
a9c8aa0
d20cda1
bf8aef5
33a19dd
58f864b
4d25f80
ff62651
de0e782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -656,15 +656,16 @@ static void readConfigs(opt::InputArgList &args) { | |
| ctx.arg.exportDynamic = | ||
| args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, ctx.arg.shared); | ||
|
|
||
| // Parse wasm32/64. | ||
| // Parse wasm32/64 and maybe -wasip3. | ||
| if (auto *arg = args.getLastArg(OPT_m)) { | ||
| StringRef s = arg->getValue(); | ||
| if (s == "wasm32") | ||
| if (s.starts_with("wasm32")) | ||
| ctx.arg.is64 = false; | ||
| else if (s == "wasm64") | ||
| else if (s.starts_with("wasm64")) | ||
| ctx.arg.is64 = true; | ||
| else | ||
| error("invalid target architecture: " + s); | ||
| ctx.arg.isWasip3 = s.ends_with("-wasip3"); | ||
| } | ||
|
|
||
| // --threads= takes a positive integer and provides the default value for | ||
|
|
@@ -827,6 +828,10 @@ static void checkOptions(opt::InputArgList &args) { | |
| if (ctx.arg.tableBase) | ||
| error("--table-base may not be used with -shared/-pie"); | ||
| } | ||
|
|
||
| if (ctx.arg.sharedMemory && ctx.arg.isWasip3) { | ||
| error("--shared-memory is incompatible with the wasip3 target"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this true? Is there no way to experiment with shared memories and wasmip3? (like there is with wasip1?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've since changed this to an incompatibility between |
||
| } | ||
| } | ||
|
|
||
| static const char *getReproduceOption(opt::InputArgList &args) { | ||
|
|
@@ -885,7 +890,7 @@ static void writeWhyExtract() { | |
| // Equivalent of demote demoteSharedAndLazySymbols() in the ELF linker | ||
| static void demoteLazySymbols() { | ||
| for (Symbol *sym : symtab->symbols()) { | ||
| if (auto* s = dyn_cast<LazySymbol>(sym)) { | ||
| if (auto *s = dyn_cast<LazySymbol>(sym)) { | ||
| if (s->signature) { | ||
| LLVM_DEBUG(llvm::dbgs() | ||
| << "demoting lazy func: " << s->getName() << "\n"); | ||
|
|
@@ -906,6 +911,18 @@ createUndefinedGlobal(StringRef name, llvm::wasm::WasmGlobalType *type) { | |
| return sym; | ||
| } | ||
|
|
||
| static UndefinedFunction * | ||
| createUndefinedFunction(StringRef name, std::optional<StringRef> importName, | ||
| std::optional<StringRef> importModule, | ||
|
TartanLlama marked this conversation as resolved.
Outdated
|
||
| WasmSignature *signature) { | ||
| auto *sym = cast<UndefinedFunction>(symtab->addUndefinedFunction( | ||
| name, importName, importModule, WASM_SYMBOL_UNDEFINED, nullptr, signature, | ||
| true)); | ||
| ctx.arg.allowUndefinedSymbols.insert(sym->getName()); | ||
| sym->isUsedInRegularObj = true; | ||
| return sym; | ||
| } | ||
|
|
||
| static InputGlobal *createGlobal(StringRef name, bool isMutable) { | ||
| llvm::wasm::WasmGlobal wasmGlobal; | ||
| bool is64 = ctx.arg.is64.value_or(false); | ||
|
|
@@ -946,11 +963,13 @@ static void createSyntheticSymbols() { | |
|
|
||
| bool is64 = ctx.arg.is64.value_or(false); | ||
|
|
||
| auto stack_pointer_name = | ||
| ctx.arg.isWasip3 ? "__init_stack_pointer" : "__stack_pointer"; | ||
| if (ctx.isPic) { | ||
| ctx.sym.stackPointer = | ||
| createUndefinedGlobal("__stack_pointer", ctx.arg.is64.value_or(false) | ||
| ? &mutableGlobalTypeI64 | ||
| : &mutableGlobalTypeI32); | ||
| createUndefinedGlobal(stack_pointer_name, ctx.arg.is64.value_or(false) | ||
| ? &mutableGlobalTypeI64 | ||
| : &mutableGlobalTypeI32); | ||
| // For PIC code, we import two global variables (__memory_base and | ||
| // __table_base) from the environment and use these as the offset at | ||
| // which to load our static data and function table. | ||
|
|
@@ -963,14 +982,15 @@ static void createSyntheticSymbols() { | |
| ctx.sym.tableBase->markLive(); | ||
| } else { | ||
| // For non-PIC code | ||
| ctx.sym.stackPointer = createGlobalVariable("__stack_pointer", true); | ||
| ctx.sym.stackPointer = createGlobalVariable(stack_pointer_name, true); | ||
| ctx.sym.stackPointer->markLive(); | ||
| } | ||
|
|
||
| if (ctx.arg.sharedMemory) { | ||
| if (ctx.arg.isMultithreaded()) { | ||
| // TLS symbols are all hidden/dso-local | ||
| ctx.sym.tlsBase = | ||
| createGlobalVariable("__tls_base", true, WASM_SYMBOL_VISIBILITY_HIDDEN); | ||
| auto tls_base_name = ctx.arg.isWasip3 ? "__init_tls_base" : "__tls_base"; | ||
| ctx.sym.tlsBase = createGlobalVariable(tls_base_name, true, | ||
| WASM_SYMBOL_VISIBILITY_HIDDEN); | ||
| ctx.sym.tlsSize = createGlobalVariable("__tls_size", false, | ||
| WASM_SYMBOL_VISIBILITY_HIDDEN); | ||
| ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false, | ||
|
|
@@ -979,6 +999,21 @@ static void createSyntheticSymbols() { | |
| "__wasm_init_tls", WASM_SYMBOL_VISIBILITY_HIDDEN, | ||
| make<SyntheticFunction>(is64 ? i64ArgSignature : i32ArgSignature, | ||
| "__wasm_init_tls")); | ||
| if (ctx.arg.isWasip3) { | ||
| ctx.sym.tlsBase->markLive(); | ||
| ctx.sym.tlsSize->markLive(); | ||
| ctx.sym.tlsAlign->markLive(); | ||
| static WasmSignature contextSet1Signature{{}, {ValType::I32}}; | ||
| ctx.sym.contextSet1 = createUndefinedFunction( | ||
| "__wasm_component_model_builtin_context_set_1", "[context-set-1]", | ||
| "$root", &contextSet1Signature); | ||
| ctx.sym.contextSet1->markLive(); | ||
| static WasmSignature contextGet1Signature{{ValType::I32}, {}}; | ||
| ctx.sym.contextGet1 = createUndefinedFunction( | ||
| "__wasm_component_model_builtin_context_get_1", "[context-get-1]", | ||
| "$root", &contextGet1Signature); | ||
| ctx.sym.contextGet1->markLive(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1014,7 +1049,7 @@ static void createOptionalSymbols() { | |
| // | ||
| // __tls_size and __tls_align are not needed in this case since they are only | ||
| // needed for __wasm_init_tls (which we do not create in this case). | ||
| if (!ctx.arg.sharedMemory) | ||
| if (!ctx.arg.sharedMemory && !ctx.arg.isWasip3) | ||
| ctx.sym.tlsBase = createOptionalGlobal("__tls_base", false); | ||
| } | ||
|
|
||
|
|
@@ -1023,15 +1058,15 @@ static void processStubLibrariesPreLTO() { | |
| for (auto &stub_file : ctx.stubFiles) { | ||
| LLVM_DEBUG(llvm::dbgs() | ||
| << "processing stub file: " << stub_file->getName() << "\n"); | ||
| for (auto [name, deps]: stub_file->symbolDependencies) { | ||
| auto* sym = symtab->find(name); | ||
| for (auto [name, deps] : stub_file->symbolDependencies) { | ||
| auto *sym = symtab->find(name); | ||
| // If the symbol is not present at all (yet), or if it is present but | ||
| // undefined, then mark the dependent symbols as used by a regular | ||
| // object so they will be preserved and exported by the LTO process. | ||
| if (!sym || sym->isUndefined()) { | ||
| for (const auto dep : deps) { | ||
| auto* needed = symtab->find(dep); | ||
| if (needed ) { | ||
| auto *needed = symtab->find(dep); | ||
| if (needed) { | ||
| needed->isUsedInRegularObj = true; | ||
| // Like with handleLibcall we have to extract any LTO archive | ||
| // members that might need to be exported due to stub library | ||
|
|
@@ -1103,8 +1138,8 @@ static void processStubLibraries() { | |
|
|
||
| // First look for any imported symbols that directly match | ||
| // the names of the stub imports | ||
| for (auto [name, deps]: stub_file->symbolDependencies) { | ||
| auto* sym = symtab->find(name); | ||
| for (auto [name, deps] : stub_file->symbolDependencies) { | ||
| auto *sym = symtab->find(name); | ||
| if (sym && sym->isUndefined()) { | ||
| depsAdded |= addStubSymbolDeps(stub_file, sym, deps); | ||
| } else { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this function or can use the
HasLibcallThreadContextfromclang/lib/Basic/Targets/WebAssembly.h?