3 ms·
This might be a stupid question, but why don't they construct a perfect hash (like gperf, etc) at build time?
by dividuum 6y ago
This might be a stupid question, but why don't they construct a perfect hash (like gperf, etc) at build time?
- Someone 6y agoWouldn’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 6y agoThanks 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-lookup.c;h=3d2369dbf2b7ca219eaf80a820e2a8e1329fbf50;hb=HEAD#l364 https://sourceware.org/git/?p=glibc.git;a=blob;f=elf/dl-look... correctly, linear search through all mapped libraries happens already.
- JoshTriplett 6y agoI don't know the original reason, but that would substantially increase linking time, and wouldn't be simple to aggregate from multiple objects. It might be a good idea if you're already taking time to do things like LTO, though.