Skip to content

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

Open
@mon

Description

@mon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.F-raw_dylib`#![feature(raw_dylib)]`O-windowsOperating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions