[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt created this revision. Herald added subscribers: pmatos, asb, sunfish, jgravelle-google, sbc100, dschuff. Herald added a project: All. yamt requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, aheejin. Herald added a project: clang. This allows -mexec-model=reactor -shared produces a library module with _initialize entrypoint, which is preferrable over __wasm_call_ctors. This partially reverts https://reviews.llvm.org/D153293 Discussion: https://github.com/dicej/component-linking-demo/issues/3 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D156205 Files: clang/lib/Driver/ToolChains/WebAssembly.cpp Index: clang/lib/Driver/ToolChains/WebAssembly.cpp === --- clang/lib/Driver/ToolChains/WebAssembly.cpp +++ clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -101,7 +101,7 @@ << CM << A->getOption().getName(); } } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared)) + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1))); if (Entry) { CmdArgs.push_back(Args.MakeArgString("--entry")); Index: clang/lib/Driver/ToolChains/WebAssembly.cpp === --- clang/lib/Driver/ToolChains/WebAssembly.cpp +++ clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -101,7 +101,7 @@ << CM << A->getOption().getName(); } } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared)) + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1))); if (Entry) { CmdArgs.push_back(Args.MakeArgString("--entry")); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt added a comment. > Should -shared modules also link with crt1-reactor.o by default then? Or > should we add crt1-shared.o and use the whenever -shared is passed. Should we > also make -shared incompatible with -mexec-model? It seems like -mexec-model > should only apply to the main module, and not to the shared library that it > loads. wasi reactor model is for libraries. i feel it's natural to make it cover shared libraries as well. but i agree it can be done as you described too. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156205/new/ https://reviews.llvm.org/D156205 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt updated this revision to Diff 544275. yamt added a comment. update test Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156205/new/ https://reviews.llvm.org/D156205 Files: clang/lib/Driver/ToolChains/WebAssembly.cpp clang/test/Driver/wasm-toolchain.c Index: clang/test/Driver/wasm-toolchain.c === --- clang/test/Driver/wasm-toolchain.c +++ clang/test/Driver/wasm-toolchain.c @@ -33,19 +33,19 @@ // LINK_KNOWN: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" // LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with a known OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with a known OS. -// RUN: %clang -### -shared --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_KNOWN_SHARED %s // LINK_KNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with an unknown OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with an unknown OS. -// RUN: %clang -### -shared --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_UNKNOWN_SHARED %s // LINK_UNKNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" // A basic C link command-line with optimization with known OS. Index: clang/lib/Driver/ToolChains/WebAssembly.cpp === --- clang/lib/Driver/ToolChains/WebAssembly.cpp +++ clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -101,7 +101,7 @@ << CM << A->getOption().getName(); } } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared)) + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1))); if (Entry) { CmdArgs.push_back(Args.MakeArgString("--entry")); Index: clang/test/Driver/wasm-toolchain.c === --- clang/test/Driver/wasm-toolchain.c +++ clang/test/Driver/wasm-toolchain.c @@ -33,19 +33,19 @@ // LINK_KNOWN: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" // LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with a known OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with a known OS. -// RUN: %clang -### -shared --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_KNOWN_SHARED %s // LINK_KNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with an unknown OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with an unknown OS. -// RUN: %clang -### -shared --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_UNKNOWN_SHARED %s // LINK_UNKNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.ou
[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt marked an inline comment as done. yamt added a comment. can this land? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156205/new/ https://reviews.llvm.org/D156205 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt updated this revision to Diff 546417. yamt added a comment. when -shared, use the reactor model by default Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156205/new/ https://reviews.llvm.org/D156205 Files: clang/lib/Driver/ToolChains/WebAssembly.cpp clang/test/Driver/wasm-toolchain.c Index: clang/test/Driver/wasm-toolchain.c === --- clang/test/Driver/wasm-toolchain.c +++ clang/test/Driver/wasm-toolchain.c @@ -33,19 +33,19 @@ // LINK_KNOWN: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" // LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with a known OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with a known OS. -// RUN: %clang -### -shared --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_KNOWN_SHARED %s // LINK_KNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with an unknown OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with an unknown OS. -// RUN: %clang -### -shared --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_UNKNOWN_SHARED %s // LINK_UNKNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" // A basic C link command-line with optimization with known OS. Index: clang/lib/Driver/ToolChains/WebAssembly.cpp === --- clang/lib/Driver/ToolChains/WebAssembly.cpp +++ clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -77,31 +77,43 @@ Args.AddAllArgs(CmdArgs, options::OPT_u); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - const char *Crt1 = "crt1.o"; + bool isCommand = true; + const char *Crt1; const char *Entry = nullptr; - // If crt1-command.o exists, it supports new-style commands, so use it. - // Otherwise, use the old crt1.o. This is a temporary transition measure. - // Once WASI libc no longer needs to support LLVM versions which lack - // support for new-style command, it can make crt1.o the same as - // crt1-command.o. And once LLVM no longer needs to support WASI libc - // versions before that, it can switch to using crt1-command.o. - if (ToolChain.GetFilePath("crt1-command.o") != "crt1-command.o") -Crt1 = "crt1-command.o"; + // When -shared is specified, use the reactor exec model unless + // specified otherwise. + if (Args.hasArg(options::OPT_shared)) +isCommand = false; if (const Arg *A = Args.getLastArg(options::OPT_mexec_model_EQ)) { StringRef CM = A->getValue(); if (CM == "command") { - // Use default values. + isCommand = true; } else if (CM == "reactor") { - Crt1 = "crt1-reactor.o"; - Entry = "_initialize"; + isCommand = false; } else { ToolChain.getDriver().Diag(diag::err_drv_invalid_argument_to_option) << CM << A->getOption().getName(); } } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared)) + + if (isCommand) { +// If crt1-command.o exists, it supports new-style commands, so use it. +// Otherwise, use the old crt1.o. This is a temporary transition measure. +// Once WASI libc no longer needs to support LLVM versions which lack +// support for new-style command, it can make crt1.o the same as +// crt1-command.o. And once LLVM no longer needs to support WASI libc +// versions before that, it can switch to using crt1-command.o. +Crt1 = "crt1.o"; +if (ToolChain.GetFilePath("crt1-command.o") != "crt1-command.o") + Crt1 = "crt1-command.o"; + } else { +Crt1 = "crt1-reactor.o"; +Entry = "_initialize"; + } + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1))); if (Entry) { CmdArgs.push_back(Args.MakeArgString("--entry")
[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt updated this revision to Diff 546525. yamt added a comment. isCommand -> IsCommand Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156205/new/ https://reviews.llvm.org/D156205 Files: clang/lib/Driver/ToolChains/WebAssembly.cpp clang/test/Driver/wasm-toolchain.c Index: clang/test/Driver/wasm-toolchain.c === --- clang/test/Driver/wasm-toolchain.c +++ clang/test/Driver/wasm-toolchain.c @@ -33,19 +33,19 @@ // LINK_KNOWN: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" // LINK_KNOWN: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with a known OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with a known OS. -// RUN: %clang -### -shared --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-wasi --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_KNOWN_SHARED %s // LINK_KNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_KNOWN_SHARED: wasm-ld{{.*}}" "-L/foo/lib/wasm32-wasi" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" -// -shared should be passed through to `wasm-ld` and not include crt1.o with an unknown OS. +// -shared should be passed through to `wasm-ld` and include crt1-reactor.o with an unknown OS. -// RUN: %clang -### -shared --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ +// RUN: %clang -### -shared -mexec-model=reactor --target=wasm32-unknown-unknown --sysroot=/foo %s 2>&1 \ // RUN: | FileCheck -check-prefix=LINK_UNKNOWN_SHARED %s // LINK_UNKNOWN_SHARED: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]" -// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" +// LINK_UNKNOWN_SHARED: wasm-ld{{.*}}" "crt1-reactor.o" "--entry" "_initialize" "-shared" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out" // A basic C link command-line with optimization with known OS. Index: clang/lib/Driver/ToolChains/WebAssembly.cpp === --- clang/lib/Driver/ToolChains/WebAssembly.cpp +++ clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -77,31 +77,43 @@ Args.AddAllArgs(CmdArgs, options::OPT_u); ToolChain.AddFilePathLibArgs(Args, CmdArgs); - const char *Crt1 = "crt1.o"; + bool IsCommand = true; + const char *Crt1; const char *Entry = nullptr; - // If crt1-command.o exists, it supports new-style commands, so use it. - // Otherwise, use the old crt1.o. This is a temporary transition measure. - // Once WASI libc no longer needs to support LLVM versions which lack - // support for new-style command, it can make crt1.o the same as - // crt1-command.o. And once LLVM no longer needs to support WASI libc - // versions before that, it can switch to using crt1-command.o. - if (ToolChain.GetFilePath("crt1-command.o") != "crt1-command.o") -Crt1 = "crt1-command.o"; + // When -shared is specified, use the reactor exec model unless + // specified otherwise. + if (Args.hasArg(options::OPT_shared)) +IsCommand = false; if (const Arg *A = Args.getLastArg(options::OPT_mexec_model_EQ)) { StringRef CM = A->getValue(); if (CM == "command") { - // Use default values. + IsCommand = true; } else if (CM == "reactor") { - Crt1 = "crt1-reactor.o"; - Entry = "_initialize"; + IsCommand = false; } else { ToolChain.getDriver().Diag(diag::err_drv_invalid_argument_to_option) << CM << A->getOption().getName(); } } - if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared)) + + if (IsCommand) { +// If crt1-command.o exists, it supports new-style commands, so use it. +// Otherwise, use the old crt1.o. This is a temporary transition measure. +// Once WASI libc no longer needs to support LLVM versions which lack +// support for new-style command, it can make crt1.o the same as +// crt1-command.o. And once LLVM no longer needs to support WASI libc +// versions before that, it can switch to using crt1-command.o. +Crt1 = "crt1.o"; +if (ToolChain.GetFilePath("crt1-command.o") != "crt1-command.o") + Crt1 = "crt1-command.o"; + } else { +Crt1 = "crt1-reactor.o"; +Entry = "_initialize"; + } + + if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1))); if (Entry) { CmdArgs.push_back(Args.MakeArgString("--entry")); Index: clang/test/D
[PATCH] D156205: wasm: link crt1 even in case of -shared
yamt added inline comments. Comment at: clang/lib/Driver/ToolChains/WebAssembly.cpp:80 - const char *Crt1 = "crt1.o"; + bool isCommand = true; + const char *Crt1; sbc100 wrote: > LLCM coding style is `IsCommand` (at last for now: > https://llvm.org/docs/Proposals/VariableNames.html) oops. fixed. thank you. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D156205/new/ https://reviews.llvm.org/D156205 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D144970: [llvm-c] Remove bindings for creating legacy passes
yamt added a comment. at least some of these stuff is used by wasm-micro-runtime. do you have a suggestion about how to adapt it? https://github.com/bytecodealliance/wasm-micro-runtime/blob/72fc872afe9a51228b2a32bc7b08475b176f187f/core/iwasm/compilation/aot_compiler.c#L2666-L2670 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D144970/new/ https://reviews.llvm.org/D144970 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]
yamt added a comment. > musttail provide assurances that the tail call can be optimized on all > targets. Such a definition doesn't make much sense because for some targets tail call optimization isn't available at all. Eg. Wasm w/o tail call proposal, xtensa windowed abi. So I'm not sure what's the point of the new attribute. It seems simpler to fix the existing musttail attribute. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D147714/new/ https://reviews.llvm.org/D147714 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits