Skip to content

Wrong symbols are referenced for raw-dylib on i686-pc-windows-gnu #138963

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

Open
glandium opened this issue Mar 26, 2025 · 0 comments
Open

Wrong symbols are referenced for raw-dylib on i686-pc-windows-gnu #138963

glandium opened this issue Mar 26, 2025 · 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-gnu Toolchain: GNU, Operating system: Windows O-x86_32 Target: x86 processors, 32 bit (like i686-*) (IA-32) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@glandium
Copy link
Contributor

The following code:

#[no_mangle]
pub extern "C" fn foo() {
    unsafe {
        windows_sys::Win32::System::Com::CoInitializeEx(std::ptr::null(), 0);
    }
}

With the following dependency:

windows-sys = { version = "0.59", features=["Win32_System_Com"] }

Also add the following to Cargo.toml:

[lib]
crate-type = ["staticlib"]

Building with RUSTFLAGS=--cfg=windows_raw_dylib cargo build --target i686-pc-windows-gnu (enabling raw-dylibs) produces a .a file that contains an ole32.dll import with the following references (as per llvm-readobj --symbols):

  Symbol {
    Name: CoInitializeEx
    Value: 0
    Section: .text (1)
    BaseType: Null (0x0)
    ComplexType: Null (0x0)
    StorageClass: External (0x2)
    AuxSymbolCount: 0
  }
  Symbol {
    Name: __imp_CoInitializeEx
    Value: 0
    Section: .idata$5 (5)
    BaseType: Null (0x0)
    ComplexType: Null (0x0)
    StorageClass: External (0x2)
    AuxSymbolCount: 0
  }

The real libole32.a from mingw contains:

  Symbol {
    Name: _CoInitializeEx@8
    Value: 0
    Section: .text (1)
    BaseType: Null (0x0)
    ComplexType: Null (0x0)
    StorageClass: External (0x2)
    AuxSymbolCount: 0
  }
  Symbol {
    Name: __imp__CoInitializeEx@8
    Value: 0
    Section: .idata$5 (5)
    BaseType: Null (0x0)
    ComplexType: Null (0x0)
    StorageClass: External (0x2)
    AuxSymbolCount: 0
  }

IOW, the symbol is decorated in the real library, but is not in the raw-dylib. This can cause problems downstream e.g. when linking with delayload.

See #130586 for a similar problem on i686-pc-windows-msvc that was fixed in 1.84.0.

Cc: @dpaoliello @kennykerr

@glandium glandium added the C-bug Category: This is a bug. label Mar 26, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2025
@Noratrieb Noratrieb added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-windows-gnu Toolchain: GNU, Operating system: Windows F-raw_dylib `#![feature(raw_dylib)]` O-x86_32 Target: x86 processors, 32 bit (like i686-*) (IA-32) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 26, 2025
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-gnu Toolchain: GNU, Operating system: Windows O-x86_32 Target: x86 processors, 32 bit (like i686-*) (IA-32) 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

3 participants