CONSTRUCT 3 RUNTIME CODE
It looks like at a certain point the code in the module got split into two functions for codegen purposes. Main: &(dyn Fn() -> i32 + Sync + crate::panic::RefUnwindSafe), Okay so we know we export some functions for panicking but what about the actual setup code for the runtime? // To reduce the generated code of the new `lang_start`, this function is doing Having the scaffolding in place to catch these automatically for us or at least aborting the program for us is great and we don't even have to set it up by hand every time. Being able to abort properly or catching panics and unwinding the stack is good! Panics are great when the state of the program or the assumptions you made no longer are in a recoverable state. This really isn't a good tradeoff unless binary size really matters, say in like an embeded environment. The only way to get rid of it all is to write your own start function and not setting up any of this panic/abort machinery like I had done in my "Oxidizing the technical interview" article. It still has code related to aborting, which is less than the normal panic machinery which does stack unwinding and lets you catch the panic if it happens, but it still has code related to aborting in it. This is why even with panic = "abort" set in your Cargo.toml file you'll still see a decent sized chunk of code in the assembly output. If we didn't have the machinery set up to catch and print out panics in the runtime we'd have to do it ourselves. This calls the machinery to print out that error message we see above or in the case of you setting your own panic hook it will dispatch that hook instead of the default built in one.
CONSTRUCT 3 RUNTIME HOW TO
The begin_panic function handles how to deal with well panicking. Note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace Thread 'main' panicked at 'This is my roaring, roaring panic's!', src/main.rs:2:5 Running `target/debug/panic-at-the-function-call` We can trace what all these do if we visit the panicking module of libstd and all of the intricate details, but the big take away is whenever you see this: ~/panic-at-the-function-call is ? v0.1.0 via ? v1.43.0Ĭompiling panic-at-the-function-call v0.1.0 (/Users/michael/panic-at-the-function-call)įinished dev target(s) in 0.75s No really it does! I blew past that aspect in my most recent post "Oxidizing the technical interview" when I put in the line: The greatest trick the Devil ever played was convincing C and Rust programmers their language has no runtime.Īnd you can see there's a bit more to the machinery in running a Rust program with this bit of code used in that post: #įn start(main: fn() -> T, _: isize, _: *const *const u8) -> isize