12
12
13
13
#include " ToolChains.h"
14
14
15
+ #include " swift/ABI/System.h"
16
+ #include " swift/AST/DiagnosticsDriver.h"
15
17
#include " swift/Basic/Dwarf.h"
16
18
#include " swift/Basic/LLVM.h"
17
19
#include " swift/Basic/Platform.h"
@@ -196,6 +198,15 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
196
198
Arguments.push_back (" -v" );
197
199
}
198
200
201
+ // WebAssembly doesn't reserve low addresses But without "extra inhabitants"
202
+ // of the pointer representation, runtime performance and memory footprint are
203
+ // worse. So assume that compiler driver uses wasm-ld and --global-base=1024
204
+ // to reserve low 1KB.
205
+ Arguments.push_back (" -Xlinker" );
206
+ Arguments.push_back (context.Args .MakeArgString (
207
+ Twine (" --global-base=" ) +
208
+ std::to_string (SWIFT_ABI_WASM32_LEAST_VALID_POINTER)));
209
+
199
210
// These custom arguments should be right before the object file at the end.
200
211
context.Args .AddAllArgs (Arguments, options::OPT_linker_option_Group);
201
212
context.Args .AddAllArgs (Arguments, options::OPT_Xlinker);
@@ -212,6 +223,23 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
212
223
return II;
213
224
}
214
225
226
+ void validateLinkerArguments (DiagnosticEngine &diags,
227
+ ArgStringList linkerArgs) {
228
+ for (auto arg : linkerArgs) {
229
+ if (StringRef (arg).startswith (" --global-base=" )) {
230
+ diags.diagnose (SourceLoc (), diag::error_option_not_supported, arg,
231
+ " wasm32" );
232
+ }
233
+ }
234
+ }
235
+ void toolchains::WebAssembly::validateArguments (DiagnosticEngine &diags,
236
+ const llvm::opt::ArgList &args,
237
+ StringRef defaultTarget) const {
238
+ ArgStringList linkerArgs;
239
+ args.AddAllArgValues (linkerArgs, options::OPT_Xlinker);
240
+ validateLinkerArguments (diags, linkerArgs);
241
+ }
242
+
215
243
ToolChain::InvocationInfo
216
244
toolchains::WebAssembly::constructInvocation (const StaticLinkJobAction &job,
217
245
const JobContext &context) const {
0 commit comments