-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix technical UB + compiler warnings #549
Conversation
Unfortunately Also FYI, note that, even in A potential workaround could be to work with |
I don't think anything becomes more "critical," because pointer difference is signed. For speed, can't we whenever
? |
You are right, I forgot that ptr substraction is a signed operation. Maybe the speed improvement could be the topic a separate PR ? |
Summary: * XXH*_update functions technically have UB on pointer arithmetic beyond the bounds of the input object, which can trigger a compiler warning in the case of statically sized input buffer. This can be solved with cast to uintptr_t where available. (In theory if your buffer is close to an extreme of your address space, it could still over/underflow, but eh.) * typedef XXH_endianess in implementation is unused, so removed. (When it was in xxhash.c it would cause compiler warning.) Test Plan: existing tests
036f934
to
4d6083b
Compare
So my update seeks not to affect performance, but get us into defined behavior whenever uintptr_t is available. Well-defined over/underflow is still possible in exotic cases. |
I'm a bit puzzled regarding this PR. On the other hand, I can easily imagine any future maintainers coming to this part of the code and being puzzled by the complex casting operation. |
I'm wondering if there is a way to reproduce this issue. |
As suggested by @pdillinger in #549, `XXH_endianess` is never used and should be removed.
I tried reproducing the warning in various ways but was not successful in latest xxhash, so I'm dropping this PR. facebook/rocksdb#8691 |
Summary: Upgrading xxhash.h to latest dev version as of 1/17/2023, which is d7197ddea81364a539051f116ca77926100fc77f This should improve performance on some ARM machines. I allowed some of our RocksDB-specific changes to be made obsolete where it seemed appropriate, for example * xxhash.h has its own fallthrough marker (which I hope works for us) * As in Cyan4973/xxHash#549 Merging and resolving conflicts one way or the other was all that went into this diff. Except I had to mix the two sides around `defined(__loongarch64)` How I did the upgrade (for future reference), so that I could use usual merge conflict resolution: ``` # New branch to help with merging git checkout -b xxh_merge_base # Check out RocksDB revision before last xxhash.h upgrade git reset --hard 22161b7^ # Create a commit with the raw base version from xxHash repo (from xxHash repo) git show 2c611a76f914828bed675f0f342d6c4199ffee1e:xxhash.h > ../rocksdb/util/xxhash.h # In RocksDB repo git commit -a # Merge in the last xxhash.h upgrade git merge 22161b7 # Resolve conflict using committed version git show 22161b7:util/xxhash.h > util/xxhash.h git commit -a # Catch up to upstream git merge upstream/main # Create a different branch for applying raw upgrade git checkout -b xxh_upgrade_2023 # Find the RocksDB commit we made for the raw base version from xxHash git log main..HEAD # Rewind to it git reset --hard 2428b72 # Copy in latest raw version (from xxHash repo) cat xxhash.h > ../rocksdb/util/xxhash.h # Merge in RocksDB changes, use typical tools for conflict resolution git merge xxh_merge_base ``` Branch https://github.com/facebook/rocksdb/tree/xxhash_merge_base can be used as a base for future xxhash merges. Fixes #11073 Pull Request resolved: #11098 Test Plan: existing tests (e.g. Bloom filter schema stability tests) Also seems to include a small performance boost on my Intel dev machine, using `./db_bench --benchmarks=xxh3[-X50] 2>&1 | egrep -o 'operations;.*' | sort` Fastest out of 50 runs, before: 15477.3 MB/s Fastest out of 50 runs, after: 15850.7 MB/s, and 11 more runs faster than the "before" number Slowest out of 50 runs, before: 12267.5 MB/s Slowest out of 50 runs, after: 13897.1 MB/s More repetitions show the distinction is repeatable Reviewed By: hx235 Differential Revision: D42560010 Pulled By: pdillinger fbshipit-source-id: c43ee52f1c5fe0ba3d6d6e4eebb22ded5f5492ea
Summary:
XXH*_update functions technically have UB on pointer arithmetic
beyond the bounds of the input object, which can trigger a compiler
warning in some cases (e.g. statically sized input buffer). This can be
suppressed with cast to uintptr_t where available. (In theory if your
buffer is close to an extreme of your address space, it could still
over/underflow, but eh.)
typedef XXH_endianess in implementation is unused, so removed.
(When it was in xxhash.c it would cause compiler warning.)
Test Plan: existing tests