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

#[link(kind="raw-dylib")] mis-compiles if cdylib export has the same name #113050

Open
mon opened this issue Jun 26, 2023 · 0 comments
Open

#[link(kind="raw-dylib")] mis-compiles if cdylib export has the same name #113050

mon opened this issue Jun 26, 2023 · 0 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-raw_dylib `#![feature(raw_dylib)]` O-windows Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mon
Copy link

mon commented Jun 26, 2023

When importing a function via raw-dylib, if an exported function has the same name, the compiler will use the exported version in all cases.

mod user32 {
    #[link(name = "user32", kind="raw-dylib")]
    extern "C" {
        pub fn MessageBoxA();
    }
}

#[no_mangle]
pub unsafe extern "C" fn MessageBoxA()  {
    user32::MessageBoxA()
}

I would expect my exported MessageBoxA function to compile to a jmp or a call to the one imported via IAT.

Instead, in Debug mode it compiles to a call of my function, and in Release mode, an infinite loop (x64 assembly eb fe: jmp 0x0).
The DLL does not even have an IAT entry for user32.dll.

If I name my function my_MessageBoxA and then rename it using a .def file during linking, the behaviour is as expected.

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (8084f397c 2023-06-25)
binary: rustc
commit-hash: 8084f397c6710e4748994dd1488b1f399283d469
commit-date: 2023-06-25
host: x86_64-pc-windows-msvc
release: 1.72.0-nightly
LLVM version: 16.0.5

Relates to: #58713

@mon mon added the C-bug Category: This is a bug. label Jun 26, 2023
@Noratrieb Noratrieb added A-linkage Area: linking into static, shared libraries and binaries O-windows Operating system: Windows F-raw_dylib `#![feature(raw_dylib)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. F-raw_dylib `#![feature(raw_dylib)]` O-windows Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants