-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
don't make intra-crate calls to exported functions go through the PLT or similar #32887
Comments
AFAIK we don't explicitly ask for this anywhere, so it's just an accident or a consequence of something we're passing down to LLVM. We pass down a few "position independent please" flags, but other than that I can't recall anything offhand. In any case this is probably a pretty simple fix to just pass a flag or two to LLVM. |
Looking at the LLVM docs, I think "protected" visibility style is what we want: http://llvm.org/docs/LangRef.html#visibility-styles
Making it the default doesn't seem like a bad idea, pulling weird |
Nice find! We may want to hold off on changing |
So this is actually much harder than originally expected. Turns out the behaviour of "protected" visibility is complicated, and might run into GCC bugs. The specific problem I'm running into is this:
The creation of the function pointer is the problem. There seems to be some weird behaviour going from an Also, my research suggests that using protected visibility may slow down users of the library, though it's unclear if the issue affects us or not. |
R_X86_64_PC32 may not work. This seems to be a good description of _PC32 vs _64: Strangely, I can't get rustc to generate X86_64_64. I've tried -C code-model=large. I think I should probably create a new issue. |
Improve symbol visibility handling for dynamic libraries. This will hopefully fix issue #37530 and maybe also #32887. I'm relying on @m4b to post some numbers on how awesome the improvement for cdylibs is `:)` cc @rust-lang/compiler @rust-lang/tools @cuviper @froydnj r? @alexcrichton
I cannot reproduce this anymore, so I'm going to close -- I think #38117 fixed this. |
Apologies for the mouthful of an issue title. Here's some example Rust for the issue at hand:
Compiling this with
rustc -O -C inline-threshold=0
results in the following on x86-64 Linux (the use of-C inline-threshold=0
is a bit artificial, but I've seen the same sort of issue when disassemblingstd
, which presumably doesn't modifyinline-threshold
):That
R_X86_64_PLT32
relocation is going to get resolved to a call into the PLT, which introduces a small amount of overhead on every call, in addition to taking up unneeded space with the PLT entry and the function pointer in the GOT. It would be better to use aR_X86_64_PC32
relocation there, which will get turned into a direct jump at link time.glibc
uses this technique to great effect so that all intra-libc calls (except for a few things likemalloc
, etc.) don't go through the PLT.Folks might want the ability to override public functions of a crate via
LD_PRELOAD
or similar, but doing so seems a little tricky with the current name mangling scheme. Perhaps a-C
option could be added?The text was updated successfully, but these errors were encountered: