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

binaries built in debug mode want to import __CxxFrameHandler3 #45492

Closed
Trolldemorted opened this issue Oct 24, 2017 · 8 comments
Closed

binaries built in debug mode want to import __CxxFrameHandler3 #45492

Trolldemorted opened this issue Oct 24, 2017 · 8 comments
Labels
O-windows Operating system: Windows

Comments

@Trolldemorted
Copy link
Contributor

Trolldemorted commented Oct 24, 2017

I am building windows kernel drivers with rust (no_std and no libc), and debug builds fail because the linker can't find __CxxFrameHandler3 in the kernel libraries (which makes sense).

However, when building with --release the function apparently is optimized out, and linking is successfull.

My target.json:

{
  "_": "Inspired by https://github.com/ryanbreen/breenix/blob/master/x86_64-unknown-none-gnu.json",
  "_note": "`is_like_mcvc` works since #32823, nightly 2016-04-12",
  "_note": "`data-layout` became mandatory since rust-lang/rust#32939, nightly 2016-04-20",

  "llvm-target": "x86_64-pc-windows-msvc",
  "target-endian": "little",
  "target-pointer-width": "64",
  "target-c-int-width": "32",
  "linker-flavor": "msvc",
  "data-layout": "e-m:w-i64:64-f80:128-n8:16:32:64-S128",

  "cpu": "x86-64",
  "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float",

  "arch": "x86_64",
  "vendor": "pc",
  "os": "windows",
  "env": "msvc",

  "executables": true,
  "dynamic-linking": true,

  "is-like-windows": true,
  "is-like-msvc": true,

  "dll-prefix": "",
  "dll-suffix": ".sys",
  "exe-prefix": "",
  "exe-suffix": ".exe",
  "staticlib-prefix": "lib",
  "staticlib-suffix": ".lib",

  "no-default-libraries":     true,
  "no-compiler-rt":           true,
  "has-rpath":                false,

  "function-sections": true,
  "has-elf-tls":              false,
  "disable-redzone":          true,
  "custom-unwind-resume":     false,
  "eliminate-frame-pointer":  false,
  "position-independent-executables": false,

  "code-model":              "kernel",
  "relocation-model":        "dynamic-no-pic",

  "pre-link-args": ["/NOLOGO", "/NODEFAULTLIB", "/SUBSYSTEM:NATIVE", "/DRIVER", "/RELEASE", "/NXCOMPAT", "/DYNAMICBASE",
    "/INCREMENTAL:NO", "/MANIFEST:NO"],

  "post-link-args": ["/OPT:REF,ICF", "ntoskrnl.lib", "hal.lib",
    "/noimplib", "/ENTRY:DriverEntry", "/DEF:exports.def", "/MERGE:.edata=.rdata", "/MERGE:.rustc=.data"],

  "_end" : false
}

Maybe related: #38641

@TimNN TimNN added the O-windows Operating system: Windows label Oct 24, 2017
@alexcrichton
Copy link
Member

Fascinating! Out of curiosity, are you compiling with panic=abort or panic=unwind?

@Trolldemorted
Copy link
Contributor Author

Trolldemorted commented Oct 24, 2017

Nothing explicitly, i just added

#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] extern fn panic_fmt() -> ! { loop {} }

for now.

After adding

[profile.dev]
panic = "abort"

to Cargo.toml it works, thanks for the hint!

Shall i close this issue or is this unwanted behaviour nevertheless? Do non-abort no-std crates make sense?

@alexcrichton
Copy link
Member

Ah thanks for testing!

Yeah this is being referenced because of panic = "unwind" referencing panicking machinery (which references this function on MSVC). If it works now I think that's intended behavior so let's close, but we could certainly of course document this better :)

@Trolldemorted
Copy link
Contributor Author

Imho this is not a documentation issue, but a rustc one: If we build a no_std crate without panic = "abort", the compiler should print a meaningful error message stating that this is impossible.

@alexcrichton
Copy link
Member

Perhaps yeah! It's technically not impossible but certainly quite hard to get working

@Trolldemorted
Copy link
Contributor Author

It would indeed be nice to get it working, but until it does I really recommend a decisive error message.

Should I create a seperate issue for that?

@alexcrichton
Copy link
Member

Sure!

@MauriceKayser
Copy link

This issue is not resolved by adding panic = "abort" to the crate, because the precompiled libcore is compiled with panic = "unwind". Would it be possible to provide a precompiled libcore with panic = "abort"? That would be really useful for no_std on Windows.

References:
No-std Windows DLL linker error
Missing symbol in no_std application on panic (windows-msvc) #54137
Other modules extern functions can currently be redefined #47449
rustc: assertion failiure in llvm when defining __CxxFrameHandler3 #38641

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-windows Operating system: Windows
Projects
None yet
Development

No branches or pull requests

4 participants