bfd: optimize bfd_elf_hash
Fangrui Song
i@maskray.me
Wed Apr 12 05:33:51 GMT 2023
On Tue, Apr 11, 2023 at 5:36 AM Alan Modra via Binutils
<binutils@sourceware.org> wrote:
>
> On Sun, Apr 09, 2023 at 06:55:13PM -0400, Nathan Sidwell via Binutils wrote:
> > * elf.c (bfd_elf_hash): Refactor to optimize loop.
> > (bfd_elf_gnu_hash): Refactor to use 32-bit type.
>
> Looks good to me.
>
> --
> Alan Modra
> Australia Development Lab, IBM
Thanks for the patch! The generic ABI code fragment may have an oversight.
When long represents a 64-bit integer, elf_hash((const unsigned char
*)"\xff\x0f\x0f\x0f\x0f\x0f\x12") returns 0x100000002, larger than
UINT32_MAX.
It is unclear whether a value larger than UINT32_MAX is intended.
I then investigated the binutils-gdb implementation and found that in
a 2003 commit (https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=32dfa85d9015feea4a06d423fe58f6eaf841456e),
Andrew Haley appeared to have noticed the issue and made a change to
"Mask lower 32 bits of hash."
This change made me more convinced that the generic ABI code fragment
had an oversight.
If the generic ABI code fragment is indeed an oversight, this
optimized version looks good to me.
I asked https://groups.google.com/g/generic-abi/c/8J_jtjsonrE ("What
if the result of elf_hash is larger than UINT32_MAX?").
More information about the Binutils
mailing list