
ELF: Better Symbol Lookup via Dt_gnu_hash (2017) - fanf2
https://flapenguin.me/elf-dt-gnu-hash
======
dividuum
This might be a stupid question, but why don't they construct a perfect hash
(like gperf, etc) at build time?

~~~
Someone
Wouldn’t that mean having distinct hashes for every library? If so, that means
you would have to, somehow, serialize the hash function inside each library
and provide an efficient way to compute hashes.

It also would mean having to hash each function name multiple times during
linking (once for each library searched until you got a hit)

Also, I think you would have to change the hash function (almost) every time a
symbol is added to a library, but that isn’t a show stopper. In the end, the
linker will compare strings, anyways.

~~~
dividuum
Thanks for you response. It would mean that, but if I understand the code at
[https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-
look...](https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-
lookup.c;h=3d2369dbf2b7ca219eaf80a820e2a8e1329fbf50;hb=HEAD#l364) correctly,
linear search through all mapped libraries happens already.

------
loeg
(2017) (And the format dates to much, much earlier — but still interesting
material if you like this kind of thing.)

> The problem with it is that DT_GNU_HASH is not documented anywhere other
> than in GNU binutils and glibc source code.

Not really documentation either, but it is of course also implemented in LLVM
and e.g., FreeBSD rtld.

------
londons_explore
If this is so great, why isn't it the default?

