Skip to content

Issues linking __rust_probestack when cross compiling for UEFI on 0.1.23 #333

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

Closed
ALSchwalm opened this issue Dec 20, 2019 · 3 comments · Fixed by #335
Closed

Issues linking __rust_probestack when cross compiling for UEFI on 0.1.23 #333

ALSchwalm opened this issue Dec 20, 2019 · 3 comments · Fixed by #335

Comments

@ALSchwalm
Copy link
Contributor

Cross compiling a simple example crate (containing a function with sufficiently large stack allocation) with compiler_builtins v0.1.23 produces the following error:

error: linking with `rust-lld` failed: exit code: 1
  |
  = note: "rust-lld" "rust-lld" "-flavor" "link" "/NOLOGO" "/NXCOMPAT" "/nodefaultlib" "/entry:efi_main" "/subsystem:efi_application" "/LIBPATH:/home/adam/test/uefi-example/target/sysroot/lib/rustlib/x86_64-unknown-uefi/lib" "/home/adam/test/uefi-example/target/x86_64-unknown-uefi/debug/deps/uefi_example-33d6ce04242a6b68.1j5mfhubop672qu0.rcgu.o" "/OUT:/home/adam/test/uefi-example/target/x86_64-unknown-uefi/debug/deps/uefi_example-33d6ce04242a6b68.efi" "/OPT:REF,NOICF" "/DEBUG" "/LIBPATH:/home/adam/test/uefi-example/target/x86_64-unknown-uefi/debug/deps" "/LIBPATH:/home/adam/test/uefi-example/target/debug/deps" "/LIBPATH:/home/adam/test/uefi-example/target/sysroot/lib/rustlib/x86_64-unknown-uefi/lib" "/home/adam/test/uefi-example/target/sysroot/lib/rustlib/x86_64-unknown-uefi/lib/libcore-9d5e0b6ad79711be.rlib" "/home/adam/test/uefi-example/target/x86_64-unknown-uefi/debug/deps/libcompiler_builtins-e6a828d72c47e9cb.rlib"
  = note: rust-lld: error: undefined symbol: __rust_probestack
          >>> referenced by /home/adam/test/uefi-example/target/x86_64-unknown-uefi/debug/deps/uefi_example-33d6ce04242a6b68.1j5mfhubop672qu0.rcgu.o:(efi_main)

Produced using this crate with cargo +nightly xbuild --target x86_64-unknown-uefi on the current nightly.

Reverting to 0.1.21 resolves the issue (0.1.22 produces the expected issue with invalid assembly). Looking at the object files it seems the the symbol is present and defined but maybe not in a way the linker expects? I tried a bit to fix this but I don't know enough about COFF/UEFI linkage. I can only speculate it is not sufficient to just use .globl ___rust_probestack.

@IsaacWoods
Copy link

IsaacWoods commented Dec 22, 2019

I wonder if this is because, for UEFI, __rust_probestack is defined using this:

// Same as above, but for Mach-O.
#[cfg(any(target_vendor = "apple", target_os = "uefi"))]
macro_rules! define_rust_probestack {
    ($body: expr) => {
        concat!(
            "
            .globl ___rust_probestack
        ___rust_probestack:
            ",
            $body
        )
    };
}

(notice that ___rust_probestack has three underscores, whereas the linker error refers to __rust_probestack (with two underscores))

I'm not sure if this is a typo, or if Mach-O requires a ___rust_probestack symbol but UEFI needs a __rust_probestack.

cc @tmandry who seemed to introduce the three-underscore version?

@ALSchwalm
Copy link
Contributor Author

Nice catch! Changing it to two underscores seems to fix the issue on UEFI. I'll hold off on making a PR though as I'm not sure about Mach-O.

@tmandry
Copy link
Member

tmandry commented Dec 31, 2019

Ah nice catch indeed. Yes, Mach-O does require an extra underscore, so we'll need to leave it as-is for apple targets. You can simply make a copy of this definition with two underscores for uefi targets. (And other non-ELF non-Mach-O targets that might get introduced in the future.)

It would also be good to add a comment somewhere pointing out the difference in underscores 😅

tgross35 added a commit to tgross35/compiler-builtins that referenced this issue Feb 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants