This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by sbc100 on Oct 17 2022, 4:43 PM.

Details

Summary

Add some checks around this combination of flags

Also, honor --global-base when specified in --stack-first mode
rather than ignoring it. But error out if the specified base preseeds
the end of the stack.

Diff Detail

Event Timeline

sbc100 created this revision.Oct 17 2022, 4:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 4:43 PM
Herald added subscribers: pmatos, asb, wingo and 4 others. · View Herald Transcript
sbc100 requested review of this revision.Oct 17 2022, 4:43 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 4:43 PM
sunfish added inline comments.Oct 18 2022, 9:34 AM
lld/wasm/Writer.cpp
269

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?

sbc100 added inline comments.Oct 18 2022, 2:23 PM
lld/wasm/Writer.cpp
269

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.

sbc100 updated this revision to Diff 468710.Oct 18 2022, 2:55 PM
  • add comment
sunfish accepted this revision.Oct 18 2022, 4:52 PM

Looks good.

This revision is now accepted and ready to land.Oct 18 2022, 4:52 PM
This revision was landed with ongoing or failed builds.Oct 18 2022, 5:20 PM
This revision was automatically updated to reflect the committed changes.