-
Notifications
You must be signed in to change notification settings - Fork 18
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
Regression: error: this directive must appear between .cfi_startproc and .cfi_endproc directives
#39
Comments
I cannot reproduce this |
UPDATE: A follow-up comment of mine details a working fix that's probably appropriate? Hopefully this reproduction works for you to verify?
This should provide a fairly good reproduction: docker run --rm -it --workdir /example fedora:41
dnf install -y nano gcc rustup-init
rustup-init -y --profile minimal --default-toolchain nightly && . "$HOME/.cargo/env"
cargo init
cargo add unwinding
# Add `extern crate unwinding;` at the top:
nano src/main.rs # Build:
$ RUSTFLAGS='-C panic=abort' cargo +nightly build --release --target x86_64-unknown-linux-gnu
Downloaded unwinding v0.2.3
Downloaded gimli v0.31.1
Downloaded libc v0.2.159
Downloaded 3 crates (1.1 MB) in 0.35s
Compiling libc v0.2.159
Compiling gimli v0.31.1
Compiling unwinding v0.2.3
error: this directive must appear between .cfi_startproc and .cfi_endproc directives
--> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unwinding-0.2.3/src/unwinder/arch/x86_64.rs:66:13
|
66 | .cfi_def_cfa_offset 0xA0
| ^
|
note: instantiated into assembly here
--> <inline asm>:4:13
|
4 | .cfi_def_cfa_offset 0xA0
| ^
error: this directive must appear between .cfi_startproc and .cfi_endproc directives
--> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unwinding-0.2.3/src/unwinder/arch/x86_64.rs:90:13
|
90 | .cfi_def_cfa_offset 8
| ^
|
note: instantiated into assembly here
--> <inline asm>:28:13
|
28 | .cfi_def_cfa_offset 8
| ^ [package]
name = "example"
version = "0.1.0"
edition = "2021"
[dependencies]
unwinding = "0.2.3" extern crate unwinding;
fn main() {
println!("Hello, world!");
} If you cannot reproduce with the above environment, then I suppose it could be an issue with my kernel? Otherwise everything else should be the fairly well isolated within that Docker container? $ uname -a
Linux 4065fe3fc76f 5.15.123.1-microsoft-standard-WSL2 #1 SMP Mon Aug 7 19:01:48 UTC 2023 x86_64 GNU/Linux
$ rustc --version --verbose
rustc 1.84.0-nightly (798fb83f7 2024-10-16)
binary: rustc
commit-hash: 798fb83f7d24e31b16acca113496f39ff168c143
commit-date: 2024-10-16
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1 |
The errors do point to two lines from here: unwinding/src/unwinder/arch/x86_64.rs Lines 59 to 95 in 41a5258
That function was modified for the |
Working fix?@nbdd0121 I cloned this repo and followed the error output advice to include These lines were inserted after and before the respective opening/closing Actually I see that a PR isn't available for the Side-note: For some reason you haven't been tagging commits for releases after Affects other archs tooI don't know how to easily/properly test for the other archs, but I assume they'd likewise raise that failure if I did have. I was able to produce the same failure for rustup target add aarch64-unknown-linux-gnu
dnf install -y zig
cargo install cargo-zigbuild
RUSTFLAGS='-C panic=abort' cargo +nightly build --release --target aarch64-unknown-linux-gnu And applying the same change to get a successful build. I did the same for Unsure if correct approachI also have no idea if that's the right fix for this, as assembly isn't something I have any experience in, so the placement may be incorrect. No clue why my specific build environment fails to build if you're able to reproduce it with that Docker reproduction, but not in a different build environment 🤷♂️ (any context as to what your build environment is?) I did find this reference from |
No, cfi_startproc must not be added. It will break all builds other than your setup. I've managed to reproduce the issue, all of the following must happen:
In which case, |
Oh alright, thanks for pointing that out then :)
I was doing some Until this Also I thought in this scenario it might also resolve the implicit $ dnf install -y musl-libc-static
$ RUSTFLAGS='-L /usr/x86_64-linux-musl/lib64 -C target-feature=+crt-static -C link-self-contained=no -C panic=abort' \
cargo +nightly build --release --target x86_64-unknown-linux-musl \
-Z build-std=std,panic_abort
error: linking with `cc` failed: exit status: 1
= note: /usr/bin/ld: cannot find -lunwind: No such file or directory The Lines 8 to 9 in 41a5258
Lines 38 to 41 in 41a5258
|
For the Eyra example, here is a minimal reproduction. RUSTFLAGS='-C link-arg=-nostartfiles -C target-feature=+crt-static -C panic=abort' \
cargo build --release --target x86_64-unknown-linux-gnu \
-Z build-std=std,panic_abort
error: this directive must appear between .cfi_startproc and .cfi_endproc directives
--> /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unwinding-0.2.3/src/unwinder/arch/x86_64.rs:66:13
|
66 | .cfi_def_cfa_offset 0xA0
| ^ extern crate eyra;
fn main() {
println!("Hello, world!");
} [package]
name = "example"
version = "0.1.0"
edition = "2021"
[dependencies]
eyra = "0.19.0" The
|
A workaround is to enable debug information. I need to figure out if it's possible to have conditional CFI directives, but it could be difficult. @bjorn3 do you have any suggestions that would make this setup work without having to remove the CFI instructions? |
I guess one workaround would be to move from naked asm to global asm and explicitly add cfi_startproc and cfi_endproc directives. Also IMO this is arguably a bug in rustc. Rust's inline asm rules state that the cfi directives are allowed in inline asm. There is no explicit restriction against using them with panic=abort, so it would be reasonable to assume that the compiler will always either insert cfi_startproc as necessary even with panic=abort or remove all cfi directives when panic=abort is used. |
Remove "unwinding" as a dependency of "nightly", and make it a dependency of "panic-handler" and "eh-personality" instead. This makes it possible to avoid depending on "unwinding" when it isn't needed, which helps with nbdd0121/unwinding#39.
…#149) * Make depending on "unwinding" conditional on `cfg(panic = "unwind)`. Using `cfg(panic = "unwind")` in Cargo.toml means we can avoid depending on the "unwinding" crate when unwinding isn't enabled. This avoids nbdd0121/unwinding#39. * Use a unique crate name in origin-start-dynamic-linker. * Add a panic=abort example.
I can reproduce this bug in a simple example without eyra or any other dependency other than unwinding, using current Rust nightly (2024-10-19). Cargo.toml: [package]
name = "repro"
version = "0.1.0"
edition = "2021"
[profile.release]
panic = "abort"
[profile.dev]
panic = "abort"
[dependencies]
unwinding = { version = "0.2.3", default-features = false, features = [ "unwinder" ] } src/main.rs: fn main() {
println!("Hello, world!");
} Build command: cargo +nightly run --release
Compiling gimli v0.31.1
Compiling unwinding v0.2.3
error: this directive must appear between .cfi_startproc and .cfi_endproc directives
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unwinding-0.2.3/src/unwinder/arch/x86_64.rs:66:13
|
66 | .cfi_def_cfa_offset 0xA0
| ^
|
note: instantiated into assembly here
--> <inline asm>:4:13
|
4 | .cfi_def_cfa_offset 0xA0
| ^
error: this directive must appear between .cfi_startproc and .cfi_endproc directives
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/unwinding-0.2.3/src/unwinder/arch/x86_64.rs:90:13
|
90 | .cfi_def_cfa_offset 8
| ^
|
note: instantiated into assembly here
--> <inline asm>:28:13
|
28 | .cfi_def_cfa_offset 8
| ^
error: could not compile `unwinding` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish... |
The interesting thing from origin's perspective is that changing the |
I'll make the debug CFI instructions optional. |
This is mostly notes for myself (and others that land here), summarizing what they should do 👍
I demonstrated that with my reproduction comment, except I didn't check if the
Proper opt-out of
|
I recently started getting failures when doing builds with basic projects using
eyra
which internally brings inunwinding
.The errors initially were lacking information about the crate producing the error but I've identified it's a recent change to
unwinding
.When using nightly to build with
-Z build-std=std,panic_abort
paired with-C panic=abort
I am getting this failure:The failure cause when used indirectly via
eyra
seemed to not trigger provided I didn't have-C panic=abort
or did not do-Z build-std
(which requires=std,panic_abort
if abort is set).However with
unwinding
directly I noticed that it would fail like above with only-C panic=abort
present:Previously it working with
unwinding=0.2.2
on nightly before thenaked_asm
failure was introduced which0.2.3
fixed and presumably introduced this regression?:The prior cargo commands for the
0.2.2
release on that nightly all avoid the reported error.The text was updated successfully, but these errors were encountered: