Skip to content
Open
Show file tree
Hide file tree
Changes from 70 commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
48a90dd
Initial work
TartanLlama Jan 5, 2026
540d785
Get wasip3 into working state
TartanLlama Jan 9, 2026
8f222c9
Don't disable threads on WASIP3 if no atomics, and don't set the TLS …
TartanLlama Feb 17, 2026
e9775de
Merge branch 'main' into sy/wasip3
TartanLlama Feb 17, 2026
6d2b464
Factor out WASIP3 into options and features
TartanLlama Feb 17, 2026
0bf29ae
Merge branch 'sy/wasip3' of github.com:TartanLlama/llvm-project into …
TartanLlama Feb 17, 2026
4a18333
Tighten up features
TartanLlama Feb 17, 2026
927daeb
Make feature detection work properly
TartanLlama Feb 17, 2026
e632709
Fix TLS relocations for non WASIP3
TartanLlama Feb 17, 2026
f44bf29
Add stack pointer ABI test
TartanLlama Feb 17, 2026
18a1ee3
Add tests for component model threading feature
TartanLlama Feb 17, 2026
8980e38
Add wasm-features test
TartanLlama Feb 17, 2026
08a3a16
wasm-toolchain tests
TartanLlama Feb 17, 2026
9092b93
Formatting
TartanLlama Feb 17, 2026
81ffb2b
Formatting
TartanLlama Feb 17, 2026
a9e7310
Revert arch change
TartanLlama Feb 17, 2026
c369bb2
Formatting
TartanLlama Feb 17, 2026
d368838
Revert formatting change
TartanLlama Feb 17, 2026
61f03e5
Revert formatting change
TartanLlama Feb 17, 2026
c9665c1
Revert formatting changes
TartanLlama Feb 17, 2026
07e122d
Revert formatting changes
TartanLlama Feb 17, 2026
651c362
Revert formatting changes
TartanLlama Feb 17, 2026
0175bd5
Revert formatting changes
TartanLlama Feb 17, 2026
9a93078
Revert formatting changes
TartanLlama Feb 17, 2026
85fab66
Revert formatting changes
TartanLlama Feb 17, 2026
e577185
Revert formatting changes
TartanLlama Feb 17, 2026
446d56d
Revert formatting changes
TartanLlama Feb 17, 2026
3f10fe8
Remove linker flag
TartanLlama Feb 18, 2026
dbae3ef
Determine thread context ABI automatically
TartanLlama Feb 18, 2026
e0dcb2a
Merge branch 'main' into sy/wasip3
TartanLlama Feb 18, 2026
e8babc7
Fix comment
TartanLlama Feb 18, 2026
822ea98
Test updates
TartanLlama Feb 18, 2026
cb2fb8d
TLS fixes
TartanLlama Feb 18, 2026
6cf7c2a
TLS test
TartanLlama Feb 18, 2026
fa7eea8
Continue rather than break when determiting thread context ABI
TartanLlama Feb 18, 2026
cc1ea2f
Only consider the current object file's symbols for determining threa…
TartanLlama Feb 18, 2026
b9039eb
Typo
TartanLlama Feb 18, 2026
1b490cd
Formatting
TartanLlama Feb 18, 2026
b55ae63
TLS fixes
TartanLlama Feb 18, 2026
a1c563b
Tighten up Toolchain driver
TartanLlama Feb 18, 2026
69654ef
Fix clang test
TartanLlama Feb 18, 2026
b98b9ab
Add wasm-target-features test for preprocessor defines
TartanLlama Feb 18, 2026
7121ea5
Remove debug code
TartanLlama Feb 18, 2026
70b3b93
Complete asm printing/parsing changes
TartanLlama Feb 18, 2026
43f756f
Clean up target feature decision
TartanLlama Feb 20, 2026
4ffe623
Use llvm::Triple::WASIp3 rather than a string
TartanLlama Feb 20, 2026
36c39bf
More driver tests
TartanLlama Feb 20, 2026
d953510
Fix tests
TartanLlama Feb 20, 2026
0656bbf
Strip thread locals if no bulk memory
TartanLlama Feb 20, 2026
c5190ff
Thread pointer test
TartanLlama Feb 20, 2026
6e0c9c0
TLS local exec test
TartanLlama Feb 20, 2026
3386a11
Add stack abi test
TartanLlama Feb 20, 2026
5775592
Shared memory fixes
TartanLlama Feb 20, 2026
4d7a81e
Enable component model context in WASIP3 in LLVM
TartanLlama Feb 20, 2026
1001e65
Merge branch 'main' into sy/wasip3
TartanLlama Feb 20, 2026
7a44741
Tighten up linker changes
TartanLlama Feb 20, 2026
4c62c81
Fix LLVM tests
TartanLlama Feb 20, 2026
5bebe2a
Merge branch 'main' into sy/wasip3
TartanLlama Feb 20, 2026
e9fa9fc
Remove unused code
TartanLlama Feb 23, 2026
10ed134
Change asserts for symbol creation
TartanLlama Feb 23, 2026
2ee9845
Fix frame debug info
TartanLlama Feb 23, 2026
c6ddead
Merge branch 'main' into sy/wasip3
TartanLlama Feb 23, 2026
2bae426
Merge branch 'sy/wasip3' of github.com:TartanLlama/llvm-project into …
TartanLlama Feb 23, 2026
557bfac
Tighten up linker changes
TartanLlama Feb 23, 2026
61c25c8
Typo
TartanLlama Feb 23, 2026
0fe07f0
Improve TLS test
TartanLlama Feb 23, 2026
7a58fce
Fix TLS in shared objects
TartanLlama Feb 23, 2026
8047c76
Update comment
TartanLlama Feb 23, 2026
24cb457
Remove symbol file changes for now
TartanLlama Feb 23, 2026
ff172dc
Merge branch 'main' into sy/wasip3
TartanLlama Mar 3, 2026
d11664a
Clang format
TartanLlama Mar 3, 2026
f04b74a
Format
TartanLlama Mar 3, 2026
6bdff2c
Fix tests
TartanLlama Mar 3, 2026
a637ae1
fmt
TartanLlama Mar 3, 2026
0bf18a6
Add chain to TLS base
TartanLlama Mar 3, 2026
6c9c276
fmt
TartanLlama Mar 3, 2026
f019ea9
Change chain impl
TartanLlama Mar 3, 2026
de9424c
Correct chain
TartanLlama Mar 3, 2026
5954755
fmt
TartanLlama Mar 3, 2026
1f9e903
Simplify getTLSBase
TartanLlama Mar 3, 2026
f61837a
fmt
TartanLlama Mar 3, 2026
bde41fc
Add missing include
TartanLlama Mar 3, 2026
daf5b03
fmt
TartanLlama Mar 4, 2026
36ea1df
Merge branch 'main' into sy/wasip3
TartanLlama Mar 4, 2026
41f8893
Revert archive-export changes
TartanLlama Mar 4, 2026
0a8c6ec
Merge branch 'main' into sy/wasip3
TartanLlama Mar 4, 2026
90c342f
Revert archive-export changes
TartanLlama Mar 4, 2026
a42942c
Merge branch 'sy/wasip3' of github.com:TartanLlama/llvm-project into …
TartanLlama Mar 4, 2026
13d3870
Revert tailcail changes
TartanLlama Mar 4, 2026
f75cb64
Revert tail call change
TartanLlama Mar 4, 2026
e1992e8
Review comments
TartanLlama Mar 4, 2026
c3d46dc
Newlines
TartanLlama Mar 5, 2026
9ecceef
Newlines
TartanLlama Mar 5, 2026
9d296ec
Remove changes from other PR
TartanLlama Mar 5, 2026
95fc53a
Comments
TartanLlama Mar 5, 2026
ae859d0
split-file
TartanLlama Mar 5, 2026
abc859d
Don't disable feature for MVP cpu
TartanLlama Mar 5, 2026
3749d9e
Don't disable feature for MVP cpu
TartanLlama Mar 5, 2026
0028170
fmt
TartanLlama Mar 5, 2026
f9f40b7
Revert test changes
TartanLlama Mar 5, 2026
c8d5420
Merge branch 'main' into sy/wasip3
TartanLlama Mar 9, 2026
9908d72
Remove merge artifact
TartanLlama Mar 9, 2026
0e1a5a9
Move writer utils
TartanLlama Mar 9, 2026
e187d8e
Revert WriterUtils changes
TartanLlama Mar 9, 2026
a2e3a85
Merge branch 'main' into sy/wasip3
TartanLlama Mar 11, 2026
b7bc6a3
Merge branch 'main' into sy/wasip3
TartanLlama Mar 16, 2026
a79dc2f
Merge branch 'main' into sy/wasip3
TartanLlama Mar 20, 2026
09f0fe3
Merge branch 'main' into sy/wasip3
TartanLlama Mar 23, 2026
1ee14c4
Abstract out context.get/set builtins
TartanLlama Mar 23, 2026
af1eb70
fmt
TartanLlama Mar 23, 2026
c661e66
fmt
TartanLlama Mar 23, 2026
e00d35f
Merge branch 'main' into sy/wasip3
TartanLlama Mar 23, 2026
742ae7c
Add comment
TartanLlama Mar 24, 2026
9b688ca
Remove option
TartanLlama Mar 24, 2026
3570777
Refactor into two config options
TartanLlama Mar 24, 2026
45ff0f0
Merge branch 'main' into sy/wasip3
TartanLlama Mar 24, 2026
e841994
Refactor
TartanLlama Apr 1, 2026
da1949c
Merge branch 'sy/wasip3' of github.com:TartanLlama/llvm-project into …
TartanLlama Apr 1, 2026
8dfc97c
Cleanup
TartanLlama Apr 1, 2026
cdca5aa
fmt
TartanLlama Apr 1, 2026
7559ec5
Flag for libcall thread context
TartanLlama Apr 1, 2026
4135d3d
Test fixes
TartanLlama Apr 1, 2026
a1cacc9
fmt
TartanLlama Apr 1, 2026
a2367c8
Merge branch 'main' into sy/wasip3
TartanLlama Apr 2, 2026
dfbfcd9
Cleanup
TartanLlama Apr 2, 2026
5c04563
newline
TartanLlama Apr 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Options/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5670,6 +5670,8 @@ def mcall_indirect_overlong : Flag<["-"], "mcall-indirect-overlong">, Group<m_wa
def mno_call_indirect_overlong : Flag<["-"], "mno-call-indirect-overlong">, Group<m_wasm_Features_Group>;
def mcompact_imports : Flag<["-"], "mcompact-imports">, Group<m_wasm_Features_Group>;
def mno_compact_imports : Flag<["-"], "mno-compact-imports">, Group<m_wasm_Features_Group>;
def mcomponent_model_thread_context : Flag<["-"], "mcomponent-model-thread-context">, Group<m_wasm_Features_Group>;
def mno_component_model_thread_context : Flag<["-"], "mno-component-model-thread-context">, Group<m_wasm_Features_Group>;
def mexception_handing : Flag<["-"], "mexception-handling">, Group<m_wasm_Features_Group>;
def mno_exception_handing : Flag<["-"], "mno-exception-handling">, Group<m_wasm_Features_Group>;
def mextended_const : Flag<["-"], "mextended-const">, Group<m_wasm_Features_Group>;
Expand Down
20 changes: 16 additions & 4 deletions clang/lib/Basic/Targets/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ bool WebAssemblyTargetInfo::hasFeature(StringRef Feature) const {
.Case("bulk-memory", HasBulkMemory)
.Case("bulk-memory-opt", HasBulkMemoryOpt)
.Case("call-indirect-overlong", HasCallIndirectOverlong)
.Case("component-model-thread-context", HasComponentModelThreadContext)
.Case("compact-imports", HasCompactImports)
.Case("exception-handling", HasExceptionHandling)
.Case("extended-const", HasExtendedConst)
Expand Down Expand Up @@ -120,6 +121,8 @@ void WebAssemblyTargetInfo::getTargetDefines(const LangOptions &Opts,
Builder.defineMacro("__wasm_tail_call__");
if (HasWideArithmetic)
Builder.defineMacro("__wasm_wide_arithmetic__");
if (HasComponentModelThreadContext)
Builder.defineMacro("__wasm_component_model_thread_context__");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the note I added on the line just below here. i.e. does the feature need to be exposed via a C macro like this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it was better to have it and not need it when it comes to the libc implementation rather than need it and not have it. Happy to remove if you'd rather.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this'll be useful to have in wasi-libc, yeah, to enable conditional builds of wasm32-wasip3 with/without this feature.

// Note that not all wasm features appear here. For example,
// HasCompatctImports

Expand Down Expand Up @@ -374,6 +377,14 @@ bool WebAssemblyTargetInfo::handleTargetFeatures(
HasWideArithmetic = false;
continue;
}
if (Feature == "+component-model-thread-context") {
HasComponentModelThreadContext = true;
continue;
}
if (Feature == "-component-model-thread-context") {
HasComponentModelThreadContext = false;
continue;
}

Diags.Report(diag::err_opt_not_valid_with_opt)
<< Feature << "-target-feature";
Expand Down Expand Up @@ -407,10 +418,11 @@ WebAssemblyTargetInfo::getTargetBuiltins() const {
void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
const TargetInfo *Aux) {
TargetInfo::adjust(Diags, Opts, Aux);
// Turn off POSIXThreads and ThreadModel so that we don't predefine _REENTRANT
// or __STDCPP_THREADS__ if we will eventually end up stripping atomics
// because they are unsupported.
if (!HasAtomics || !HasBulkMemory) {
// If not using component model threading intrinsics, turn off POSIXThreads
// and ThreadModel so that we don't predefine _REENTRANT or __STDCPP_THREADS__
// if we will eventually end up stripping atomics because they are unsupported.
if (!HasComponentModelThreadContext &&
(!HasAtomics || !HasBulkMemory)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it impossible to enable HasComponentModelThreadContext at the same time as HasAtomics?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I find that features work best when they're additive and don't clash with each other since end users don't always have the greatest degree of control over what's enabled where and how it's enabled and such. Given that I'd say that ideally the features would continue to be orthogonal, and wherever the clash might otherwise be problematic that might be reasonable to require specifying some other option to disambiguate with some reasonable fallback or something like that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't see a strong reason to disallow it. Maybe you're compiling some code that uses atomics and targeting WASIp3; the operations don't need to be atomic, but we shouldn't necessitate making code changes just to save them cycles

Opts.POSIXThreads = false;
Opts.setThreadModel(LangOptions::ThreadModelKind::Single);
Opts.ThreadsafeStatics = false;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyTargetInfo : public TargetInfo {
bool HasBulkMemoryOpt = false;
bool HasCallIndirectOverlong = false;
bool HasCompactImports = false;
bool HasComponentModelThreadContext = false;
bool HasExceptionHandling = false;
bool HasExtendedConst = false;
bool HasFP16 = false;
Expand Down
68 changes: 45 additions & 23 deletions clang/lib/Driver/ToolChains/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ static bool WantsPthread(const llvm::Triple &Triple, const ArgList &Args) {
return WantsPthread;
}

static bool WantsComponentModelThreadContext(const llvm::Triple &Triple, const ArgList &Args) {
// If the target is WASIP3, then enable the
// component-model-thread-context feature by default, unless explicitly
// disabled.
return Triple.getOS() == llvm::Triple::WASIp3 &&
Args.hasFlag(options::OPT_mcomponent_model_thread_context,
options::OPT_mno_component_model_thread_context, true);
}

static bool WantsSharedMemory(const llvm::Triple &Triple, const ArgList &Args) {
return WantsPthread(Triple, Args) && !WantsComponentModelThreadContext(Triple, Args);
}

void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
Expand Down Expand Up @@ -160,7 +173,7 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,

AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);

if (WantsPthread(ToolChain.getTriple(), Args))
if (WantsSharedMemory(ToolChain.getTriple(), Args))
CmdArgs.push_back("--shared-memory");

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
Expand Down Expand Up @@ -307,36 +320,45 @@ void WebAssembly::addClangTargetOptions(const ArgList &DriverArgs,
options::OPT_fno_use_init_array, true))
CC1Args.push_back("-fno-use-init-array");

// '-pthread' implies atomics, bulk-memory, mutable-globals, and sign-ext
if (WantsComponentModelThreadContext(getTriple(), DriverArgs)) {
CC1Args.push_back("-target-feature");
CC1Args.push_back("+component-model-thread-context");
}

// '-pthread' implies bulk-memory, and, if shared memory is also used,
// also implies atomics, mutable-globals, and sign-ext.
if (WantsPthread(getTriple(), DriverArgs)) {
if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-atomics";
if (DriverArgs.hasFlag(options::OPT_mno_bulk_memory,
options::OPT_mbulk_memory, false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-bulk-memory";
if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
options::OPT_mmutable_globals, false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-mutable-globals";
if (DriverArgs.hasFlag(options::OPT_mno_sign_ext, options::OPT_msign_ext,
false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-sign-ext";
CC1Args.push_back("-target-feature");
CC1Args.push_back("+atomics");
CC1Args.push_back("-target-feature");
CC1Args.push_back("+bulk-memory");
CC1Args.push_back("-target-feature");
CC1Args.push_back("+mutable-globals");
CC1Args.push_back("-target-feature");
CC1Args.push_back("+sign-ext");

if (WantsSharedMemory(getTriple(), DriverArgs)) {
if (DriverArgs.hasFlag(options::OPT_mno_atomics, options::OPT_matomics,
false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-atomics";
if (DriverArgs.hasFlag(options::OPT_mno_mutable_globals,
options::OPT_mmutable_globals, false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-mutable-globals";
if (DriverArgs.hasFlag(options::OPT_mno_sign_ext, options::OPT_msign_ext,
false))
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< "-pthread"
<< "-mno-sign-ext";
CC1Args.push_back("-target-feature");
CC1Args.push_back("+atomics");
CC1Args.push_back("-target-feature");
CC1Args.push_back("+mutable-globals");
CC1Args.push_back("-target-feature");
CC1Args.push_back("+sign-ext");
}
}

if (!DriverArgs.hasFlag(options::OPT_mmutable_globals,
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/wasm-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,10 @@

// COMPACT-IMPORTS: "-target-feature" "+compact-imports"
// NO-COMPACT-IMPORTS: "-target-feature" "-compact-imports"

// RUN: %clang --target=wasm32-unknown-unknown -### %s -mcomponent-model-thread-context 2>&1 | FileCheck %s -check-prefix=COMPONENT-MODEL-THREAD-CONTEXT
// RUN: %clang --target=wasm32-unknown-unknown -### %s -mno-component-model-thread-context 2>&1 | FileCheck %s -check-prefix=NO-COMPONENT-MODEL-THREAD-CONTEXT

// COMPONENT-MODEL-THREAD-CONTEXT: "-target-feature" "+component-model-thread-context"
// NO-COMPONENT-MODEL-THREAD-CONTEXT: "-target-feature" "-component-model-thread-context"

18 changes: 15 additions & 3 deletions clang/test/Driver/wasm-toolchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
// '-pthread' sets +atomics, +bulk-memory, +mutable-globals, +sign-ext, and --shared-memory
// RUN: %clang -### --target=wasm32-unknown-unknown --sysroot=/foo %s -pthread 2>&1 \
// RUN: | FileCheck -check-prefix=PTHREAD %s
// PTHREAD: "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
// PTHREAD: "-cc1" {{.*}} "-target-feature" "+bulk-memory" "-target-feature" "+atomics" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
// PTHREAD: wasm-ld{{.*}}" "--shared-memory" "-lpthread"
//
// '-pthread' with '-nostdlib' should still set '--shared-memory' but not include '-lpthread'
// RUN: %clang -### --target=wasm32-unknown-unknown --sysroot=/foo %s -pthread -nostdlib 2>&1 \
// RUN: | FileCheck -check-prefix=PTHREAD-NOSTDLIB %s
// PTHREAD-NOSTDLIB: "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
// PTHREAD-NOSTDLIB: "-cc1" {{.*}} "-target-feature" "+bulk-memory" "-target-feature" "+atomics" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
// PTHREAD-NOSTDLIB: wasm-ld{{.*}}" "--shared-memory" "-o" "a.out"

// '-pthread' not allowed with '-mno-atomics'
Expand Down Expand Up @@ -113,7 +113,7 @@
// 'wasm32-wasi-threads' does the same thing as '-pthread'
// RUN: %clang -### --target=wasm32-wasi-threads --sysroot=/foo %s 2>&1 \
// RUN: | FileCheck -check-prefix=WASI_THREADS %s
// WASI_THREADS: "-cc1" {{.*}} "-target-feature" "+atomics" "-target-feature" "+bulk-memory" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
// WASI_THREADS: "-cc1" {{.*}} "-target-feature" "+bulk-memory" "-target-feature" "+atomics" "-target-feature" "+mutable-globals" "-target-feature" "+sign-ext"
// WASI_THREADS: wasm-ld{{.*}}" "--shared-memory" "-lpthread"

// '-mllvm -emscripten-cxx-exceptions-allowed=foo,bar' sets
Expand Down Expand Up @@ -303,3 +303,15 @@
// RUN: | FileCheck -check-prefix=LINK_WALI_BASIC %s
// LINK_WALI_BASIC: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
// LINK_WALI_BASIC: wasm-ld{{.*}}" "-L/foo/lib/wasm32-linux-muslwali" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins.a" "-o" "a.out"

// `wasm32-wasip3` passes `+component-model-thread-context` by default.

// RUN: %clang -### --target=wasm32-wasip3 --sysroot=/foo %s 2>&1 \
// RUN: | FileCheck -check-prefix=LINK_WASIP3_THREAD_CONTEXT %s
// LINK_WASIP3_THREAD_CONTEXT: "-cc1" {{.*}} "-target-feature" "+component-model-thread-context"

// `wasm32-wasip3` does not pass `+component-model-thread-context` when `-mno-component-model-thread-context` is used.

// RUN: %clang -### --target=wasm32-wasip3 --sysroot=/foo -mno-component-model-thread-context %s 2>&1 \
// RUN: | FileCheck -check-prefix=LINK_WASIP3_NO_THREAD_CONTEXT %s
// LINK_WASIP3_NO_THREAD_CONTEXT: "-cc1" {{.*}} "-target-feature" "-component-model-thread-context"
9 changes: 9 additions & 0 deletions clang/test/Preprocessor/wasm-target-features.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,12 @@
// RUN: | FileCheck %s -check-prefix=WIDE-ARITHMETIC
//
// WIDE-ARITHMETIC: #define __wasm_wide_arithmetic__ 1{{$}}

// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target wasm32-unknown-unknown -mcomponent-model-thread-context \
// RUN: | FileCheck %s -check-prefix=COMPONENT-MODEL-THREAD-CONTEXT
// RUN: %clang -E -dM %s -o - 2>&1 \
// RUN: -target wasm64-unknown-unknown -mcomponent-model-thread-context \
// RUN: | FileCheck %s -check-prefix=COMPONENT-MODEL-THREAD-CONTEXT

// COMPONENT-MODEL-THREAD-CONTEXT: #define __wasm_component_model_thread_context__ 1{{$}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Mark the feature as DISALLOWED
.section .custom_section.target_features,"",@
.int8 1
.int8 45
.int8 30
.ascii "component-model-thread-context"
11 changes: 11 additions & 0 deletions lld/test/wasm/Inputs/stack-pointer.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.globaltype __stack_pointer, i32

.globl _start
_start:
.functype _start () -> (i32)
global.get __stack_pointer
i32.const 16
i32.sub
drop
i32.const 0
end_function
6 changes: 6 additions & 0 deletions lld/test/wasm/Inputs/use-component-model-thread-context.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Mark the feature as USED
.section .custom_section.target_features,"",@
.int8 1
.int8 43
.int8 30
.ascii "component-model-thread-context"
6 changes: 3 additions & 3 deletions lld/test/wasm/archive-export.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ CHECK: Exports:
CHECK-NEXT: - Name: memory
CHECK-NEXT: Kind: MEMORY
CHECK-NEXT: Index: 0
CHECK-NEXT: - Name: __stack_pointer
CHECK-NEXT: Kind: GLOBAL
CHECK-NEXT: Index: 0
CHECK-NEXT: - Name: foo
CHECK-NEXT: Kind: FUNCTION
CHECK-NEXT: Index: 1
Expand All @@ -29,6 +26,9 @@ CHECK-NEXT: Index: 3
CHECK-NEXT: - Name: _start
CHECK-NEXT: Kind: FUNCTION
CHECK-NEXT: Index: 0
CHECK-NEXT: - Name: __stack_pointer
CHECK-NEXT: Kind: GLOBAL
CHECK-NEXT: Index: 0
CHECK-NEXT: - Type: CODE

NOEXPORT: Exports:
Expand Down
6 changes: 3 additions & 3 deletions lld/test/wasm/comdats.ll
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ entry:
; CHECK-NEXT: - Name: memory
; CHECK-NEXT: Kind: MEMORY
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: __stack_pointer
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Name: _start
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 1
Expand All @@ -53,6 +50,9 @@ entry:
; CHECK-NEXT: - Name: callComdatFn2
; CHECK-NEXT: Kind: FUNCTION
; CHECK-NEXT: Index: 5
; CHECK-NEXT: - Name: __stack_pointer
; CHECK-NEXT: Kind: GLOBAL
; CHECK-NEXT: Index: 0
; CHECK-NEXT: - Type: ELEM
; CHECK-NEXT: Segments:
; CHECK-NEXT: - Offset:
Expand Down
12 changes: 6 additions & 6 deletions lld/test/wasm/mutable-global-exports.s
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ _start:
# CHECK-SP-NEXT: - Name: memory
# CHECK-SP-NEXT: Kind: MEMORY
# CHECK-SP-NEXT: Index: 0
# CHECK-SP-NEXT: - Name: __stack_pointer
# CHECK-SP-NEXT: Kind: GLOBAL
# CHECK-SP-NEXT: Index: 0
# CHECK-SP-NEXT: - Name: _start
# CHECK-SP-NEXT: Kind: FUNCTION
# CHECK-SP-NEXT: Index: 0
# CHECK-SP-NEXT: - Name: __stack_pointer
# CHECK-SP-NEXT: Kind: GLOBAL
# CHECK-SP-NEXT: Index: 0
# CHECK-SP-NEXT: - Type: CODE

# CHECK-ALL: - Type: EXPORT
Expand All @@ -73,9 +73,6 @@ _start:
# CHECK-ALL-NEXT: - Name: __wasm_call_ctors
# CHECK-ALL-NEXT: Kind: FUNCTION
# CHECK-ALL-NEXT: Index: 0
# CHECK-ALL-NEXT: - Name: __stack_pointer
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 0
# CHECK-ALL-NEXT: - Name: _start
# CHECK-ALL-NEXT: Kind: FUNCTION
# CHECK-ALL-NEXT: Index: 1
Expand All @@ -85,6 +82,9 @@ _start:
# CHECK-ALL-NEXT: - Name: bar_global
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 5
# CHECK-ALL-NEXT: - Name: __stack_pointer
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 0
# CHECK-ALL-NEXT: - Name: __dso_handle
# CHECK-ALL-NEXT: Kind: GLOBAL
# CHECK-ALL-NEXT: Index: 6
Expand Down
4 changes: 4 additions & 0 deletions lld/test/wasm/pie.s
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ _start:
# CHECK-NEXT: GlobalType: I32
# CHECK-NEXT: GlobalMutable: true
# CHECK-NEXT: - Module: env
# CHECK-NEXT: Field: external_func
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: SigIndex: 1
# CHECK-NEXT: - Module: env
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know whats up with this change?

# CHECK-NEXT: Field: __memory_base
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: GlobalType: I32
Expand Down
8 changes: 4 additions & 4 deletions lld/test/wasm/shared-weak-symbols.s
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ call_weak:
# CHECK-NEXT: Memory:
# CHECK-NEXT: Minimum: 0x0
# CHECK-NEXT: - Module: env
# CHECK-NEXT: Field: weak_func
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: SigIndex: 0
# CHECK-NEXT: - Module: env
# CHECK-NEXT: Field: __memory_base
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: GlobalType: I32
Expand All @@ -51,10 +55,6 @@ call_weak:
# CHECK-NEXT: Kind: GLOBAL
# CHECK-NEXT: GlobalType: I32
# CHECK-NEXT: GlobalMutable: false
# CHECK-NEXT: - Module: env
# CHECK-NEXT: Field: weak_func
# CHECK-NEXT: Kind: FUNCTION
# CHECK-NEXT: SigIndex: 0
# CHECK-NEXT: - Type: FUNCTION

# CHECK: - Type: EXPORT
Expand Down
15 changes: 15 additions & 0 deletions lld/test/wasm/stack-pointer-abi.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t-component-model.o %S/Inputs/use-component-model-thread-context.s
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t-global.o %S/Inputs/disallow-component-model-thread-context.s
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
# RUN: wasm-ld --component-model-thread-context -o %t-component-model.wasm %t-component-model.o %t.o
# RUN: obj2yaml %t-component-model.wasm | FileCheck %s --check-prefix=COMPONENT-MODEL
# RUN: wasm-ld -o %t-original.wasm %t-global.o %t.o
# RUN: obj2yaml %t-original.wasm | FileCheck %s --check-prefix=GLOBAL

.globl _start
_start:
.functype _start () -> ()
end_function

# COMPONENT-MODEL: Name: __init_stack_pointer
# GLOBAL: Name: __stack_pointer
Loading
Loading