This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Error on import/export of mutable global without `mutable-globals` feature
ClosedPublic

Authored by sbc100 on Sep 11 2020, 11:36 AM.

Details

Summary

Also add the +mutable-globals features in clang when
when building with -fPIC since the linker will generate mutable
globals imports and exports in that case.

Diff Detail

Event Timeline

sbc100 created this revision.Sep 11 2020, 11:36 AM
sbc100 requested review of this revision.Sep 11 2020, 11:36 AM
sbc100 edited the summary of this revision. (Show Details)Sep 11 2020, 11:37 AM
sbc100 added a reviewer: tlively.

Discussed offline and decided that it would be better to error out in the linker and depend on the frontend to generate the necessary features based on flags like -mmutable-globals or -fPIC.

sbc100 updated this revision to Diff 291317.Sep 11 2020, 12:48 PM
sbc100 edited the summary of this revision. (Show Details)

switch to verification in wasm-ld

Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2020, 12:48 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
sbc100 retitled this revision from [lld][WebAssembly] Add mutable-globals to feature section if needed to [lld][WebAssembly] Error on import/export of mutable global without `mutable-globals` feature.Sep 11 2020, 12:49 PM
sbc100 edited the summary of this revision. (Show Details)

OK.. updated PTAL

tlively added inline comments.Sep 11 2020, 1:01 PM
clang/lib/Driver/ToolChains/WebAssembly.cpp
246–252

This should also check that the user didn't pass options::OPT_mno_mutable_globals and a test should be added in clang/test/Driver/wasm-toolchain.c.

lld/wasm/Writer.cpp
478

could this if (sym->isExported()) be turned into an assert(sym->isExported())?

sbc100 marked an inline comment as done.Sep 11 2020, 1:20 PM
sbc100 added inline comments.
lld/wasm/Writer.cpp
478

I don't think so. What about regular internal globals that are neither imported nor exported? Unless I'm missing something?

sbc100 updated this revision to Diff 291323.Sep 11 2020, 1:20 PM
sbc100 edited the summary of this revision. (Show Details)

add test

tlively added inline comments.Sep 11 2020, 6:47 PM
clang/lib/Driver/ToolChains/WebAssembly.cpp
246–252

Sorry, I meant that if the user passes -fPIC as well as -mno-mutable-globals, we should give them a diag::err_drv_argument_not_allowed_with error, like we do above for -pthread features and below for -fwasm-exceptions features,

lld/wasm/Writer.cpp
478

Ah, makes sense.

sbc100 updated this revision to Diff 291380.Sep 12 2020, 4:35 AM

Feedback

tlively accepted this revision.Sep 12 2020, 2:08 PM

Thanks!

This revision is now accepted and ready to land.Sep 12 2020, 2:08 PM