Comments (14)
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 <[email protected]>"]
[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"
}
$ xargo build --target thumbv6m-none-eabi --release
Compiling foo v0.1.0 (file:///home/japaric/tmp/foo)
error: linking with `arm-none-eabi-gcc` failed: exit code: 1
|
= note: "arm-none-eabi-gcc" "-L" "/home/japaric/.xargo/lib/rustlib/thumbv6m-none-eabi/lib" "/home/japaric/tmp/foo/target/thumbv6m-none-eabi/release/foo.0.o" "-o" "/home/japaric/tmp/foo/target/thumbv6m-none-eabi/release/foo" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/japaric/tmp/foo/target/thumbv6m-none-eabi/release/deps" "-L" "/home/japaric/.xargo/lib/rustlib/thumbv6m-none-eabi/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/tmp/rustc.Jxy0hf5HsfzM/librustc_builtins-5c8a87f356eb958c.rlib" "-nostartfiles"
= note: /tmp/rustc.Jxy0hf5HsfzM/librustc_builtins-5c8a87f356eb958c.rlib(rustc_builtins-5c8a87f356eb958c.0.o): In function `__aeabi_uidiv':
rustc_builtins.cgu-0.rs:(.text.__aeabi_uidiv+0xde): undefined reference to `core::panicking::panic::h2a0ea99cd46c9ef6'
collect2: error: ld returned 1 exit status
error: aborting due to previous error
error: Could not compile `foo`.
To learn more, run the command again with --verbose.
error: `cargo` process didn't exit successfully
from compiler-builtins.
So, what I think is happening is that, because core
participates in LTO but rustc_builtins
doesn't, LLVM looks at _start
and says "oh, this can't panic let's drop the panicking::panic symbol". After LTO, the object looks like this
(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.
from compiler-builtins.
I think what we could do is:
- Have rustc_builtins participate in LTO. But than would bring back the infinite recursive call problem with __aeabi_memcpy.
- Don't use anything that's in
core
in therustc_builtins
crate. This is a non-starter. - Perhaps, have rustc_builtins participate in LTO but isolate the symbols that have the infinite recursive call problem into another crate that doesn't participate in LTO. rustc_builtins would depend on that other crate.
- Don't use
panic!
in rustc_builtins. That would fix this particular case but there would still be problems with other symbols defined in core that get used in rustc_builtins but that don't get used in the top-crate/executable.
from compiler-builtins.
Another alternative: move the memcpy stuff (including the aeabi aliases) to a separate no_builtin
crate.
from compiler-builtins.
@Amanieu yeah, that's the third alternative I mentioned 😄.
from compiler-builtins.
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 #[inline]
, and we're already looking at symbols in the compiled output, so perhaps we could assert that there are no undefined symbols that we don't know about?
from compiler-builtins.
$ nm -u target/debug/librustc_builtins.rlib
rustc_builtins.0.o:
U rust_eh_personality
U _Unwind_Resume
U _ZN4core9panicking5panic17h1a2d1a6b50eaa468E
$ nm -u target/release/librustc_builtins.rlib
rustc_builtins.0.o:
U _ZN4core9panicking5panic17h1a2d1a6b50eaa468E
Should we stop using panic!
in our implementation and switch to compilerrt_abort
?
On that note, the libcompiler-rt.a that we used to distribute is filled with undefined compilerrt_abort_impl
symbols. I don't know how that used to work.
from compiler-builtins.
Yeah in my mind this crate should never panic, but if it must be fallible it's safe to tear down everything.
from compiler-builtins.
Yeah in my mind this crate should never panic
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 (unsafe
) with input = 0 or use the intrinsics::unchecked_div
in the standard library. unchecked_div
says that it's UB to call it with denominator = 0. Does that give us permission to replace the panics in our division by zero branches with intrinsics::unreachable
?
from compiler-builtins.
I'd prefer to stick with intrinsics::abort
for now, but in general I think unreachable
should be ok in the long term (once we've verified everything)
from compiler-builtins.
Some more guards for this were added in #166, so I think this is resolved.
from compiler-builtins.
This seems to have regressed again. ssh://[email protected]/BartMassey/mixy
on Linux/x86-64, remove the -O
flag in the Makefile
. Shall I file a separate issue for the regression?
from compiler-builtins.
@BartMassey yes please do!
from compiler-builtins.
@alexcrichton Issue #245. I think it's probably all my fault, but I'm not sure exactly what to do, so…
from compiler-builtins.
Related Issues (20)
- `__extenddftf2` is found to be missing at runtime when using the WASI SDK to build Rust crates' C code HOT 2
- Getting C-defined intrinsics into a project that uses the stable compiler doesn't work because of all the `#![feature]` checks HOT 2
- Unable to find long double symbols on `aarch64-apple-darwin` HOT 4
- Adding feature to port `libm` for any target HOT 3
- Unable to use static macOS libraries in Unreal Engine projects HOT 2
- Regression: build failure on i686-pc-windows-gnu due to multiple definition of `_alloca` HOT 15
- Undefined reference to __chkstk, __alloca when building target i686-unknown-uefi
- aarch64 windows build failure HOT 1
- `aarch64-linux` `multf3` symbol has incorrect rounding HOT 1
- Unable to `-Zbuild-std` because std depends on `compiler-builtins` without the `no-f16-f128` features HOT 5
- Rounding error in `__mulsf3` HOT 6
- Inconsistent truncation of -0.0 HOT 6
- powerpc64le truncation failure HOT 1
- Errors building latest version on arm-android HOT 7
- Infinite recursion in sqrt HOT 4
- "was built for iOS 16.4" warning HOT 4
- Infinite recursion in `__extendhfsf2` and `__truncsfhf2` on "no-f16-f128" platforms HOT 6
- Various symbols on win/apple are no longer weak after #598 HOT 13
- Presence of `f16` in signatures causes missing symbols on PPC HOT 2
- Optimizing Compiler builtins causes build failure on VxWorks HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiler-builtins.