@@ -77,31 +77,43 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
7777 Args.AddAllArgs (CmdArgs, options::OPT_u);
7878 ToolChain.AddFilePathLibArgs (Args, CmdArgs);
7979
80- const char *Crt1 = " crt1.o" ;
80+ bool IsCommand = true ;
81+ const char *Crt1;
8182 const char *Entry = nullptr ;
8283
83- // If crt1-command.o exists, it supports new-style commands, so use it.
84- // Otherwise, use the old crt1.o. This is a temporary transition measure.
85- // Once WASI libc no longer needs to support LLVM versions which lack
86- // support for new-style command, it can make crt1.o the same as
87- // crt1-command.o. And once LLVM no longer needs to support WASI libc
88- // versions before that, it can switch to using crt1-command.o.
89- if (ToolChain.GetFilePath (" crt1-command.o" ) != " crt1-command.o" )
90- Crt1 = " crt1-command.o" ;
84+ // When -shared is specified, use the reactor exec model unless
85+ // specified otherwise.
86+ if (Args.hasArg (options::OPT_shared))
87+ IsCommand = false ;
9188
9289 if (const Arg *A = Args.getLastArg (options::OPT_mexec_model_EQ)) {
9390 StringRef CM = A->getValue ();
9491 if (CM == " command" ) {
95- // Use default values.
92+ IsCommand = true ;
9693 } else if (CM == " reactor" ) {
97- Crt1 = " crt1-reactor.o" ;
98- Entry = " _initialize" ;
94+ IsCommand = false ;
9995 } else {
10096 ToolChain.getDriver ().Diag (diag::err_drv_invalid_argument_to_option)
10197 << CM << A->getOption ().getName ();
10298 }
10399 }
104- if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_shared))
100+
101+ if (IsCommand) {
102+ // If crt1-command.o exists, it supports new-style commands, so use it.
103+ // Otherwise, use the old crt1.o. This is a temporary transition measure.
104+ // Once WASI libc no longer needs to support LLVM versions which lack
105+ // support for new-style command, it can make crt1.o the same as
106+ // crt1-command.o. And once LLVM no longer needs to support WASI libc
107+ // versions before that, it can switch to using crt1-command.o.
108+ Crt1 = " crt1.o" ;
109+ if (ToolChain.GetFilePath (" crt1-command.o" ) != " crt1-command.o" )
110+ Crt1 = " crt1-command.o" ;
111+ } else {
112+ Crt1 = " crt1-reactor.o" ;
113+ Entry = " _initialize" ;
114+ }
115+
116+ if (!Args.hasArg (options::OPT_nostdlib, options::OPT_nostartfiles))
105117 CmdArgs.push_back (Args.MakeArgString (ToolChain.GetFilePath (Crt1)));
106118 if (Entry) {
107119 CmdArgs.push_back (Args.MakeArgString (" --entry" ));
0 commit comments