This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Add Leb128 encoding/decoding
ClosedPublic

Authored by vitalybuka on Nov 23 2021, 11:29 AM.

Diff Detail

Event Timeline

vitalybuka created this revision.Nov 23 2021, 11:29 AM
vitalybuka requested review of this revision.Nov 23 2021, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 23 2021, 11:29 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
kstoimenov added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
19

Why not making this iterator? I think it will make the code more readable. Plus it will still work with the regular pointers.

vitalybuka added inline comments.Nov 23 2021, 6:05 PM
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
19

Pointers will not be enough here, but iterators probably require more boilerplate on caller side. Not sure.

dvyukov accepted this revision.Nov 24 2021, 6:15 AM
dvyukov added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
35

templates don't need inline to avoid multiple definitions

This revision is now accepted and ready to land.Nov 24 2021, 6:15 AM
kstoimenov added inline comments.Nov 24 2021, 7:30 AM
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
19

What I am proposing is this:
template <typename T, typename It> inline void EncodeSLEB128(T v, It it) {
......
*(it++) = byte; // instead of fn(byte) on line 29

This will work both with regular pointers and STL integrators depending on the instantiation of the template. For example if you are using a container you can pass a back_insert_iterator.

vitalybuka added inline comments.Nov 24 2021, 9:21 AM
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
19

Problem is we don't have STL in compiler-rt, so for anything but pointer you to define one, which is a class with at least deference and increment operators vs just a lambda.

kstoimenov accepted this revision.Nov 24 2021, 9:44 AM

remove inline

vitalybuka added inline comments.Nov 24 2021, 10:00 AM
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
19

I don't have strong preference about Iterator vs lambda. Both will work.
I need some way to chain coders, in later patches (they are not yet uploaded), something stream like, but it's even more noise without stream lib like in llvm or STL. So I reconsider that later.

I understand the ULEB128 for compression. What will we need SLEB128 for?

kstoimenov accepted this revision.Nov 29 2021, 1:46 PM
kstoimenov added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
37

Nit: output value should be at the end of the list and a pointer according to g3 styleguide. Up to you.

fmayer added a subscriber: fmayer.Nov 29 2021, 3:58 PM
fmayer added inline comments.
compiler-rt/lib/sanitizer_common/sanitizer_leb128.h
37

The bit about pointers is no longer true: … while non-optional output and input/output parameters should usually be references (which cannot be null). See https://google.github.io/styleguide/cppguide.html#Inputs_and_Outputs.

This revision was automatically updated to reflect the committed changes.