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

rust-lld.exe is not compatible with (kernel-mode) driver #182

Open
seritools opened this issue Jul 3, 2024 · 1 comment
Open

rust-lld.exe is not compatible with (kernel-mode) driver #182

seritools opened this issue Jul 3, 2024 · 1 comment

Comments

@seritools
Copy link

Not sure if this would be in scope for the repo, but would be nice to have documented somewhere.

I wasn't able to get a valid kernel driver binary going. Even the minimal return 0 DriverEntry example resulted in:

PS C:\driver> sc start drivertest
[SC] StartService FAILED 998:

Invalid access to memory location.

It turns out I had a linker override set in my .cargo\config.toml:

[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"

This which works fine for user-mode rust application, but apparently doesn't support all the linker args for kernel drivers correctly.

@DropDemBits
Copy link

I believe this is because lld-link (and rust-lld by extension) doesn't discard the .retplne section and instead retains it in the final binary without any attributes set. Merging the section with e.g. INIT or .rdata fixes issue.

You'll also need to manually specify sections as non-pageable since the /kernel flag in lld-link doesn't do anything yet (see https://github.com/DropDemBits/rust-ndis-examples/blob/c09e42f87c749be338305223f7ebf832a3e4d57b/driver/wdf-kmdf-build/src/lib.rs#L43 for an example).

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

No branches or pull requests

2 participants