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

error: undefined symbol: __chkstk on aarch64-unknown-uefi #98254

Open
hyperswine opened this issue Jun 19, 2022 · 3 comments
Open

error: undefined symbol: __chkstk on aarch64-unknown-uefi #98254

hyperswine opened this issue Jun 19, 2022 · 3 comments
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: Writing correctness tests. O-AArch64 Armv8-A or later processors in AArch64 mode

Comments

@hyperswine
Copy link

I tried this code:

// in #[entry] fn main()
let memory_map = get_mem_map(bt);

// in library
pub fn get_mem_map(bt: &BootServices) -> AlignToMemoryDescriptor {
    let mut memory_map = AlignToMemoryDescriptor {
        0: [0 as u8; MAX_MEMORY_MAP_SIZE],
    };
    {
        let res = bt.memory_map(&mut memory_map.0);

        match res {
            Ok(r) => {
                info!("Retrieved Memory Map!");
                info!("Memory Map Key = {:?}", &r.0);
                let iterator_item = r.1;
                iterator_item.for_each(|i| info!("Memory Descriptor = {i:?}"));
            }
            Err(err) => panic!("Could not get memory map. Error: {err:?}"),
        }
    }

    memory_map
}

I expected to see this happen: No link error cause it is sound code.

Instead, this happened: I got an undefined symbol error, which seems to be a problem with the compiler/linker being unable to know if Im going to overflow the stack

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (60e50fc1c 2022-04-04)
binary: rustc
commit-hash: 60e50fc1cfe0bb693a5f4f93eb83ef70854531e3
commit-date: 2022-04-04
host: aarch64-apple-darwin
release: 1.62.0-nightly
LLVM version: 14.0.0
Backtrace

error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "link" "/NOLOGO" "/entry:efi_main" "/subsystem:efi_application" "/machine:arm64" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.10860la7lg9m5zn1.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.12gi8jn8zywdxv6h.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.12mds7eapchfjvfh.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.1ikw55eou1bf3eg1.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.1mx424kmmbsalcic.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.1t9doq35s6sx7lcj.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.237grgsvhid7fpts.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.23hlvne6yrypuu9l.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.2ek71ldjh4fw9mnr.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.2p1np39se4rg1en1.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.35qfhcfezhjjhjq8.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.3bki6fhvzt8tce2g.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.3hssll7pzpq4wngd.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.3iq51mcpjmgqqxcp.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.474t401uuawr9pjp.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.4f2py4q0c58oopcl.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.4l0fy6cj8w3oiywi.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.4r9nhovccm037jyi.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.51j5lxe7enjgraji.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.5a7llcm4ivz0mg9m.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.ap4qa7cl5w7xkk4.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.hj8i0u6yntu4dkf.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.hnpm1zs9s81xv4g.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.jy7nxdsjlj6pv75.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.qh1nrbt29xb0vkn.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.zs6cy23jktqio5w.rcgu.o" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.4lgs7981ret5znjw.rcgu.o" "/LIBPATH:/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps" "/LIBPATH:/Users/jasonq/Documents/GitHub/Arcboot/target/debug/deps" "/LIBPATH:/Users/jasonq/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-unknown-uefi/lib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libarcboot-3b698ac8d3c398e2.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/liblinked_list_allocator-75bb8ba81fc768db.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libspinning_top-2aa0acbdfe0c659c.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libaarch64-705062cb4f6b687d.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libcortex_a-39e702517f9b69f2.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libtock_registers-57c8d8f19f0b66ee.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libqemu_exit-c7972f030686e4ec.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/liblazy_static-6ca79388e5285dbe.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libspin-1d4a8bf93c0fa00f.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libspin-60f5af8ab53b5555.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/liblock_api-9f9389295b3faafd.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libscopeguard-2bd0414a3c1a160c.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libacpi-e04bf978a602b9e2.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/librsdp-3ca0eea8681ddda1.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libuefi-668ad71a18d6f50e.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libbitflags-39e5d6ea55f39b47.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libucs2-ffe6747d48dde65d.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libbit_field-6814482675aaa2e6.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/liballoc-ec155d3e116d2a14.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/liblog-bbb3b5c8bc5d1d68.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libcfg_if-8866ce721cb8a40e.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/librustc_std_workspace_core-dc84e73fe987a0ca.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libcore-a8ff4b8ed128c50e.rlib" "/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/libcompiler_builtins-42e14f5c94945cb2.rlib" "/NXCOMPAT" "/LIBPATH:/Users/jasonq/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-unknown-uefi/lib" "/OUT:/Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.efi" "/OPT:REF,NOICF" "/DEBUG" "/NODEFAULTLIB"
  = note: rust-lld: error: undefined symbol: __chkstk
          >>> referenced by /Users/jasonq/Documents/GitHub/Arcboot/src/main.rs:56
          >>>               /Users/jasonq/Documents/GitHub/Arcboot/target/aarch64-unknown-uefi/debug/deps/arcboot_main-3791f8b9a1c81533.3iq51mcpjmgqqxcp.rcgu.o:(efi_main)
          

warning: `arcboot_main` (bin "arcboot_main") generated 12 warnings
error: could not compile `arcboot_main` due to previous error; 12 warnings emitted

@hyperswine hyperswine added the C-bug Category: This is a bug. label Jun 19, 2022
@joboet
Copy link
Contributor

joboet commented Jun 19, 2022

See also #57983. There are two possible solutions:

  • we could change the target specification value for "stack_probes" to "inline" so LLVM tries to generate the function itself, omitting the check if it can't (you can do this locally for your project, but I think it should be the default, so this line should be set to Inline and the x86_64 target should change it back to Call, so stack checking works there)
  • we could implement __rust_probestack for Aarch64 in a crate like compiler_builtins

@workingjubilee workingjubilee added the O-AArch64 Armv8-A or later processors in AArch64 mode label Jul 18, 2022
@benpye
Copy link

benpye commented Aug 21, 2022

I'm not sure I totally understand why the link failure is for __chkstk rather than __rust_probestack?

If I borrow the implementation of __chkstk from LLVM's compiler-rt it seems to behave correctly. Unfortunately setting the target's "stack_probes" to "inline" doesn't seem to make any difference either.

Edit: Actually looking at LLVM this is pretty obvious. It will only ever emit a stack probe using __chkstk on aarch64 - and there is no support for inline probes, or even omitting the probes entirely.

@nicholasbishop
Copy link
Contributor

nicholasbishop commented Nov 4, 2023

I believe this is fixed now, see rust-lang/compiler-builtins#544

Minimal repro:

// src/main.rs:
#![no_std]
#![no_main]
#[panic_handler]
fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}
#[export_name = "efi_main"]
fn main() {
    let b = [0; 1024];
}
$ cargo +1.72 build --target=aarch64-unknown-uefi
# Fails with:
[...]
  = note: rust-lld: error: undefined symbol: __chkstk
[...]

$ cargo +1.73 build --target=aarch64-unknown-uefi
# Succeeds

@fee1-dead fee1-dead added the E-needs-test Call for participation: Writing correctness tests. label Feb 1, 2024
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. E-needs-test Call for participation: Writing correctness tests. O-AArch64 Armv8-A or later processors in AArch64 mode
Projects
None yet
Development

No branches or pull requests

6 participants