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"
@@ -192,6 +194,15 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
192
194
Arguments.push_back (" -v" );
193
195
}
194
196
197
+ // WebAssembly doesn't reserve low addresses But without "extra inhabitants"
198
+ // of the pointer representation, runtime performance and memory footprint are
199
+ // worse. So assume that compiler driver uses wasm-ld and --global-base=1024
200
+ // to reserve low 1KB.
201
+ Arguments.push_back (" -Xlinker" );
202
+ Arguments.push_back (context.Args .MakeArgString (
203
+ Twine (" --global-base=" ) +
204
+ std::to_string (SWIFT_ABI_WASM32_LEAST_VALID_POINTER)));
205
+
195
206
// These custom arguments should be right before the object file at the end.
196
207
context.Args .AddAllArgs (Arguments, options::OPT_linker_option_Group);
197
208
context.Args .AddAllArgs (Arguments, options::OPT_Xlinker);
@@ -208,6 +219,23 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
208
219
return II;
209
220
}
210
221
222
+ void validateLinkerArguments (DiagnosticEngine &diags,
223
+ ArgStringList linkerArgs) {
224
+ for (auto arg : linkerArgs) {
225
+ if (StringRef (arg).startswith (" --global-base=" )) {
226
+ diags.diagnose (SourceLoc (), diag::error_option_not_supported, arg,
227
+ " wasm32" );
228
+ }
229
+ }
230
+ }
231
+ void toolchains::WebAssembly::validateArguments (DiagnosticEngine &diags,
232
+ const llvm::opt::ArgList &args,
233
+ StringRef defaultTarget) const {
234
+ ArgStringList linkerArgs;
235
+ args.AddAllArgValues (linkerArgs, options::OPT_Xlinker);
236
+ validateLinkerArguments (diags, linkerArgs);
237
+ }
238
+
211
239
ToolChain::InvocationInfo
212
240
toolchains::WebAssembly::constructInvocation (const StaticLinkJobAction &job,
213
241
const JobContext &context) const {
0 commit comments