-
Notifications
You must be signed in to change notification settings - Fork 13.3k
regression: UB with extern fn() -> !
and LTO
#39253
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Results of bisecting Good: nightly-2016-08-01 - 7333c4a PRs merged between those nightlies: #35163 - Rollup of 8 pull requests So most likely the LLVM upgrade is the cause. |
This has (Rust) UB, and therefore, there is no guarantee about what will happen. What happens if you remove the (Rust) undefined behavior (namely, writing to |
@ubsan Same thing #![feature(lang_items)]
#![no_std]
#[no_mangle]
pub unsafe fn _start() {
extern "C" {
fn main() -> !;
}
main();
}
// stubs
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[lang = "panic_fmt"]
extern "C" fn panic_fmt() {}
(yes, it's empty) #![feature(lang_items)]
#![no_std]
use core::ptr;
#[no_mangle]
pub unsafe fn _start() {
extern "C" {
fn main() -> !;
}
ptr::read_volatile(_start as *const usize);
main();
}
// stubs
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[lang = "panic_fmt"]
extern "C" fn panic_fmt() {}
|
@japaric thanks! Relevant LLVM bug: https://llvm.org/bugs/show_bug.cgi?id=965 |
Related to #18785 |
STR
Compiling with LTO produces:
Note that the infinite loop is missing. This program will execute stuff that's not in the
.text
section.Whereas compiling without LTO produces:
Both
main
and the infinite loop are preserved.Meta
This is a regression because nightly-2016-08-01 (I haven't bisected) preserved the infinite loop in presence of LTO.
Looking at the emitted object files, before they are sent to the linker, reveals more information:
Note that today
_start
is simply not callingmain
at all.The text was updated successfully, but these errors were encountered: