This is an archive of the discontinued LLVM Phabricator instance.

Diagnose if a SLEB128 is too large to fit in an int64_t.
ClosedPublic

Authored by rsmith on Jan 26 2021, 11:52 PM.

Details

Summary

Previously we'd hit UB due to an invalid left shift operand.

Also fix the WASM emitter to properly use SLEB128 encoding instead of
ULEB128 encoding for signed fields so that negative numbers don't
result in overly-large values that we can't read back any more.

In passing, don't diagnose a non-canonical ULEB128 that fits in a uint64_t but
has redundant trailing zero bytes.

Diff Detail

Event Timeline

rsmith created this revision.Jan 26 2021, 11:52 PM
rsmith requested review of this revision.Jan 26 2021, 11:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2021, 11:52 PM
Herald added a subscriber: aheejin. · View Herald Transcript
dblaikie accepted this revision.Jan 27 2021, 11:20 AM

Looks good - thanks!

This revision is now accepted and ready to land.Jan 27 2021, 11:20 AM
sbc100 added inline comments.Jan 27 2021, 11:33 AM
llvm/lib/ObjectYAML/WasmEmitter.cpp
585

I'm not sure about this part. The addend is currently defined to be the same data type regardless of the encoding of the relocation itself.

The addend is the value is added to the to the value before writing to relocation location. The encoding used when writing to the relocation address (LEB vs SLEB vs I32, etc) I think is independent of this.

See the definition of addend in https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md

585

Regardless of the discussion here it might make sense to split out this wasm-specific part of the change.

sbc100 added inline comments.Jan 27 2021, 11:36 AM
llvm/lib/ObjectYAML/WasmEmitter.cpp
585

It looks like perhaps the correct fix it to use encodeSLEB128 universally here.

rsmith updated this revision to Diff 319730.Jan 27 2021, 6:29 PM

Always use SLEB for Wasm reloc addeds.

aardappel accepted this revision.Jan 28 2021, 12:21 PM
This revision was landed with ongoing or failed builds.Feb 2 2021, 2:33 PM
This revision was automatically updated to reflect the committed changes.

I think this conveniently solves the TODO that I had in my in-review patch here: https://reviews.llvm.org/D78797
Thanks!