-
Notifications
You must be signed in to change notification settings - Fork 214
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
LTO causes undefined references to core::panicking::panic #79
Comments
I couldn't set up the 3ds dev environment but still managed to reproduce this with: // src/main.rs
#![feature(lang_items)]
#![no_main]
#![no_std]
extern crate rustc_builtins;
use core::ptr;
#[no_mangle]
pub unsafe fn _start() -> u32 {
let x = ptr::read_volatile(0x0 as *const u32);
let y = ptr::read_volatile(0x0 as *const u32);
x / y
}
#[no_mangle]
pub fn __aeabi_unwind_cpp_pr0() {}
#[lang = "panic_fmt"]
extern fn panic_fmt() {} # Cargo.toml
[package]
name = "foo"
version = "0.1.0"
authors = ["Jorge Aparicio <japaricious@gmail.com>"]
[dependencies]
rustc_builtins = { git = "https://github.com/japaric/rustc-builtins" }
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
lto = true # .cargo/config
[build]
rustflags = ["-C", "link-arg=-nostartfiles"] // thumbv6m-none-eabi.json
{
"arch": "arm",
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64",
"executables": true,
"features": "+strict-align",
"linker": "arm-none-eabi-gcc",
"llvm-target": "thumbv6m-none-eabi",
"os": "none",
"target-endian": "little",
"target-pointer-width": "32"
}
|
So, what I think is happening is that, because (this is foo.0.o) 00000000 <_start>:
0: b580 push {r7, lr}
2: 2100 movs r1, #0
4: 6808 ldr r0, [r1, #0]
6: 6809 ldr r1, [r1, #0]
8: f7ff fffe bl 0 <__aeabi_uidiv>
c: bd80 pop {r7, pc}
Disassembly of section .text.__aeabi_unwind_cpp_pr0:
00000000 <__aeabi_unwind_cpp_pr0>:
0: 4770 bx lr
Disassembly of section .text.rust_begin_unwind:
00000000 <rust_begin_unwind>:
0: 4770 bx lr Note that there is an undefined reference to __aeabi_uidiv (this is expected). But then when linking happens, the linker links in the __aeabi_uidiv symbol but that symbol depends on panicking::panic and there is no other object that provides it! The core crate has the panicking::panic symbol but that crate doesn't participate in the linking process because it already was LTOed. |
I think what we could do is:
|
Another alternative: move the memcpy stuff (including the aeabi aliases) to a separate |
@Amanieu yeah, that's the third alternative I mentioned 😄. |
Morally I feel like "Don't use anything that's in core in the rustc_builtins crate" is the correct approach here because that's what the dependencies actually look like. Perhaps though we could tweak this to "Don't use any symbol that's in core in the rustc_builtins crate". That is, almost all of libcore is tagged with |
Should we stop using On that note, the libcompiler-rt.a that we used to distribute is filled with undefined |
Yeah in my mind this crate should never panic, but if it must be fallible it's safe to tear down everything. |
Some of the implementations have branches that panic for stuff like division by zero but we should never reach those paths because Rust would trigger a panic before those intrinsics are called (I can't where in the compiler this behavior is implemented). I think the only way to reach those branches is to directly call the intrinsic ( |
I'd prefer to stick with |
Some more guards for this were added in #166, so I think this is resolved. |
This seems to have regressed again. |
@BartMassey yes please do! |
@alexcrichton Issue #245. I think it's probably all my fault, but I'm not sure exactly what to do, so… |
Temporary workaround for the well known "the undefined references problem for debug-assertions+lto" (rust-lang#79)
Temporary workaround for the well known "the undefined references problem for debug-assertions+lto" (rust-lang#79)
Temporary workaround for the well known "undefined references problem for debug-assertions+lto" (rust-lang#79)
Update
After #80, this only occurs with profile.dev (+debug-assertions) + LTO. To fix this we'll have to create newtypes over primitives types that
intrinsics::abort()
on bad inputs (division by zero) and overflow.Getting a funky error when attempting to use
rustc-builtins
for nintendo 3DS shenanigans instead the prebuilt copy oflibcompiler-rt
that we've been using up to this point:However, the error only occurs if
lto = true
is set in Cargo.toml. If LTO is disabled, the result is a successful build.The text was updated successfully, but these errors were encountered: