[PATCH] D136117: [lld][WebAssembly] Don't allow `--global-base` to be specified in -share/-pie or --relocatable modes

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 18 14:23:33 PDT 2022


sbc100 added inline comments.


================
Comment at: lld/wasm/Writer.cpp:269
+    if (!config->globalBase && !config->relocatable && !config->isPic) {
+      config->globalBase = 1024;
+    }
----------------
sunfish wrote:
> Could you add a comment here explaining why this is 1024? I think it's to avoid putting any global at address 0 which C/C++ would consider to be a null pointer, and 1024 is a nice round (in binary) number. Is there any other consideration here?
yes, I agree we should document.  Note that this change doesn't change the default value though, it just shifts it from being set in one place to another.  In the old code the default value of 1024 was in Driver.cpp: `config->globalBase = args::getInteger(args, OPT_global_base, 1024);`.

As to the history of 1024, I think it was chosen so to keep some kind of "red zone" so addresses that are zero, or close the zero would end up clobbering the red zone, which can then be detected by the runtime,    I also believe this value was being used by emscripten prior the existence of wasm-ld.

I do think it seems reasonable though.  I guess we would argue it could be smaller?   Maybe 128 or 512?  But this change is not about changing that value.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136117/new/

https://reviews.llvm.org/D136117



More information about the llvm-commits mailing list