-
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
Output executable crashes with relocation-model=static #62017
Comments
This comment has been minimized.
This comment has been minimized.
@lzutao you have to use LLDB backtrace
@rustbot modify labels: +C-bug +O-linux |
Likely cause is that PIC libstd and libcore are used by the reporter – this results in assembly such as this: _ZN4test4main17h21e0b94bad749a9eE:
subq $104, %rsp
movq _ZN4core3fmt5float52_$LT$impl$u20$core..fmt..Display$u20$for$u20$f64$GT$3fmt17he52c1166ee322c16E@GOTPCREL, %rsi
<snip> Which after assembling then results in machine code like this (note a null pointer dereference):
which then linker relocates to, hiding the obvious null dereference:
From what I can tell this is very likely to be user error. |
@nagisa so, is there any way that I can get a version of libstd and libcore with relocation-model=static, or do I have to recompile it from scratch ? A link to the documentation would be helpful, thanks in advance. |
You can use |
I can reproduce this easily, but only with non-optimized builds. With any level of optimization this goes away. For example, this input:
will produce a crashing executable if compiled with
non-rip-relative GOTPCREL relocation. But if I add -Copt-level=1, it generates a proper rip-relative reference:
So I think there's more to it than just having static vs pic libstd. |
I think this might be in LLVM. I made a self-contained (i.e. doesn't pull in any library stuff like
The last LLIR before the instruction selection phases is
and immediately after the instruction selection phases, the call is lowered to:
Note how the MOV64rn has In contrast, when the example is modified slightly, so that it would need to unwind if
The LLIR right before ISel (excluding basic blocks which are only called if unwinding)
The LLVM language reference says about invoke
However, here, the lowering is
where the MOV64rn has A not-particularly-educated guess would be that FastISel has a fast path for The full example, including source and unabridged LLIR and MIR is https://gist.github.com/jesboat/a88aa28f0a80c876872425901bdd9279 |
I am reasonably confident at this point that this is a bug in LLVM's FastIsel. This LLIR
is sufficient to produce a broken binary on trunk LLVM with |
Thanks for all the replies, and I hope that LLVM developers will resolve this one as soon as possible. |
I just hit this problem. Did anyone report this bug to LLVM? |
The following code crashes with "relocation-model=static" on linux x86-64, reproducible.
The text was updated successfully, but these errors were encountered: