Skip to content
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

Missing rust_begin_unwind symbol for msp430 (debug-only?) builds #102290

Closed
cr1901 opened this issue Sep 25, 2022 · 4 comments · Fixed by #103240
Closed

Missing rust_begin_unwind symbol for msp430 (debug-only?) builds #102290

cr1901 opened this issue Sep 25, 2022 · 4 comments · Fixed by #103240
Labels
C-bug Category: This is a bug. O-msp430 P-medium Medium priority regression-untriaged Untriaged performance or correctness regression.

Comments

@cr1901
Copy link
Contributor

cr1901 commented Sep 25, 2022

Code

Instructions

  1. Make sure the msp430-elf-gcc toolchain is installed. Optionally install just for convenience.
  2. git clone https://github.com/cr1901/msp430-size. Use commit 036da7a specifically.
  3. Install any rust nightly after 2022-09-08 (I am using 2022-09-21/9062b780b32d2eab060b4432863e085d9504ca5c for the error below).
  4. Run the following command:
    cargo +override-name rustc --manifest-path=./test-cases/Cargo.toml --target=msp430-none-elf -Zbuild-std=core --features=unsafe -- --emit=obj=target/msp430-none-elf/debug/test-cases.o,llvm-ir=target/msp430-none-elf/debug/test-cases.ll,asm=target/msp430-none-elf/debug/test-cases.s

With a working compiler (I used 2022-08-10/34a6cae28e7013ff0e640026a8e46f315426829d for this example), I expect compilation to succeed:

   Compiling test-cases v0.1.0 (/home/william/Projects/embedded/msp430/msp430-size/test-cases)
warning: unused import: `interrupt as mspint`
  --> test-cases/src/main.rs:10:15
   |
10 | use msp430::{{interrupt as mspint}, interrupt::CriticalSection};
   |               ^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: `test-cases` (bin "test-cases") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.20s

Instead, I get a link error about a missing rust_begin_unwind symbol, and cannot link any code that doesn't optimize it out (so everything with opt-level=0 and sometimes higher opt-levels?):

Compiling test-cases v0.1.0 (/home/william/Projects/embedded/msp430/msp430-size/test-cases)
warning: unused import: `interrupt as mspint`
  --> test-cases/src/main.rs:10:15
   |
10 | use msp430::{{interrupt as mspint}, interrupt::CriticalSection};
   |               ^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error: linking with `msp430-elf-gcc` failed: exit status: 1
  |
  = note: "msp430-elf-gcc" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/test_cases-77e7fc9bffc4f0a7.s693teeolgqnrfj.rcgu.o" "-L" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps" "-L" "/home/william/Projects/embedded/msp430/msp430-size/target/debug/deps" "-L" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/build/test-cases-3f682f73842f7eb2/out" "-L" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/build/msp430-rt-b95e8a1acafa0902/out" "-L" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/build/msp430g2553-3b2ab7604a829bcc/out" "-L" "/home/william/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/msp430-none-elf/lib" "-Wl,-Bstatic" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libmsp430g2553-ffaf04726949f42c.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libvcell-d1c6da43e237512b.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libmsp430_rt-10b834e6ef56ed17.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libcfg_if-092783056b17116d.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libpanic_msp430-f198507bed824f51.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libmsp430-e970b409efe93be8.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libcritical_section-7116d7524c9bc4b8.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/librustc_std_workspace_core-a9d0ab60345003e9.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libcore-7b26ee1f55864a47.rlib" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libcompiler_builtins-3594f08dc3904fc7.rlib" "-Wl,-Bdynamic" "-L" "/home/william/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/msp430-none-elf/lib" "-o" "/home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/test_cases-77e7fc9bffc4f0a7" "-nodefaultlibs" "-Tlink.x" "-nostartfiles" "-mcpu=msp430" "-lmul_none" "-lgcc"
  = note: /home/william/.local/bin/../lib/gcc/msp430-elf/9.2.0/../../../../msp430-elf/bin/ld: /home/william/Projects/embedded/msp430/msp430-size/target/msp430-none-elf/debug/deps/libcore-7b26ee1f55864a47.rlib(core-7b26ee1f55864a47.core.a947c771-cgu.0.rcgu.o): in function `core::panicking::panic_fmt':
          /home/william/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:142: undefined reference to `rust_begin_unwind'
          collect2: error: ld returned 1 exit status
          
  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

warning: `test-cases` (bin "test-cases") generated 1 warning
error: could not compile `test-cases` due to previous error; 1 warning emitted
error: Recipe `build-example` failed with exit code 101

The msp430-none-elf target doesn't support unwinding (and I don't imagine it ever will), only aborting panics. So I'm not sure why rust_begin_unwind is being linked in in the first place (or how compilation should be fixed).

cargo-bisect-rustc output (Version it worked on/Version with regression)

searched nightlies: from nightly-2022-08-07 to nightly-2022-09-21
regressed nightly: nightly-2022-09-08
searched commits: from 78a891d to c2804e6
regressed commit: 699bfa8

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --preserve-target --preserve --start=2022-08-07 --end=2022-09-21 --with-src -- build -Zbuild-std=core --target=msp430-none-elf --features=unsafe 
@cr1901 cr1901 added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Sep 25, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 25, 2022
@apiraino
Copy link
Contributor

apiraino commented Sep 26, 2022

WG-prioritization assigning priority (Zulip discussion).

thanks @cr1901 for the bisection. It leads to #100404 cc: @belovdv

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Sep 26, 2022
@petrochenkov
Copy link
Contributor

petrochenkov commented Oct 19, 2022

This issue should be fixed by #103092.
Could you test it once that PR lands into nightly?

This is a different issue.

@petrochenkov
Copy link
Contributor

This should be fixed by #103240.

@cr1901
Copy link
Contributor Author

cr1901 commented Oct 22, 2022

I rebuilt Rust w/ #103240 and then tested against the code I linked in the initial post, and linking in debug mode succeeded; #103240 will indeed fix the issue.

@bors bors closed this as completed in 6e95b6d Oct 22, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
Add architectures to fn create_object_file

Fixes rust-lang#102290

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-msp430 P-medium Medium priority regression-untriaged Untriaged performance or correctness regression.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants