-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Towards faster symbol lookup via DT_GNU_HASH #73855
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
Comments
Is this a static linker argument? |
@lzutao // Do not use 'gnu' hash style for Mips targets because .gnu.hash
// and the MIPS ABI require .dynsym to be sorted in different ways.
// .gnu.hash needs symbols to be grouped by hash code whereas the MIPS
// ABI requires a mapping between the GOT and the symbol table.
// Android loader does not support .gnu.hash until API 23.
// Hexagon linker/loader does not support .gnu.hash
if (!IsMips && !IsHexagon) {
if (Distro.IsRedhat() || Distro.IsOpenSUSE() || Distro.IsAlpineLinux() ||
(Distro.IsUbuntu() && Distro >= Distro::UbuntuMaverick) ||
(IsAndroid && !Triple.isAndroidVersionLT(23)))
ExtraOpts.push_back("--hash-style=gnu");
if (Distro.IsDebian() || Distro.IsOpenSUSE() ||
Distro == Distro::UbuntuLucid || Distro == Distro::UbuntuJaunty ||
Distro == Distro::UbuntuKarmic ||
(IsAndroid && Triple.isAndroidVersionLT(23)))
ExtraOpts.push_back("--hash-style=both");
} So every target is supported except Android 23, MIPS and hexagon. Rust has already done such a thing in the past with relro support #29877 |
Thanks for the info. |
For the most targets rustc invokes a linker through a compiler driver which already configures |
@tmiasko It would be nice to link the related code but great to hear that! Feel free to close the issue then :) |
@LifeIsStrange in other words: Rust does not call linker directly but instead invokes system C compiler (GCC or Clang). That compiler will use proper |
@mati865 oh thanks for the clarification, then I still believe that this is harmfully too conservative as many distros are not registered e.g archlinux |
@LifeIsStrange this is arguably Clang's issue, another issue is |
@mati865 I believe that it's easier to change rust that it is to change clang but if this is what the rust community want we can close this thread and wait for upstream instead of overriding it's current behavior. |
Well, there are plans to directly link with LLD at some point and in that mode Rust will have to choose hash-style itself. When using other compiler as the linker IMO Rust should follow what the other compiler does but let's cc Rust's linkage expert @petrochenkov
That in Clang code hasn't been updated for years and I doubt anybody is going to touch that mess soon... |
@LifeIsStrange could you clarify what OS, distro, linker, compilation flags do you use that GNU hash section is not generated? |
@tmiasko I'm on manjaro (a archlinux) and I did not test it but by looking at the linux.cpp code from llvm it seems clear that it is not enabled. Is there a command to check whether a binary has gnu.hash set? (and ideally that the classic hash section is empty so that it doesn't needlessly take storage) |
On Arch the rustc will be using GCC as a compiler driver which as indicated earlier by mati865 is configured to use $ readelf -S /usr/lib/librustc_macros-8398e2791a3728ac.so | grep -A1 -i hash
[ 2] .gnu.hash GNU_HASH 0000000000000298 00000298
0000000000005df8 0000000000000000 A 3 0 8 |
@tmiasko Clang is using
I'll prepare patch for Clang when I have a time unless I forget. |
On manjaro with a binary compiled on my system on nightly rust I get:
So as you said @tmiasko it seems to works fine for rust, at least on arch |
I can imagine people wanting to both force turn-on and turn-off this functionality. This could be implemented as a |
The official rustc 1.70.0 build for x86_64-unknown-linux-gnu uses
|
As explains this blog, https://flapenguin.me/elf-dt-gnu-hash ELF has an alternative hashmap for symbol lookup that is up to 50% faster!
Therefore, rustc should pass to the linker the following argument: --hash-style SHT_GNU_HASH
Also: This saves a few hundreds bytes to a few kilobytes for typical executables. (DT_HASH is usually larger than DT_GNU_HASH because it does not skip undefined dynsym entries)
The text was updated successfully, but these errors were encountered: