Skip to content

Overeager warning for clashing external declarations in different wasm import modules #79581

Closed
@pchickey

Description

@pchickey

Rustc 1.48.0 gives an incorrect warning about an external symbol being redeclared with a different signature, when the external symbols are in different wasm_import_module namespaces.

I tried this code:

pub mod a {
    #[link(wasm_import_module = "a")]
    extern "C" {
        pub fn foo();
    }
}

pub mod b {
    #[link(wasm_import_module = "b")]
    extern "C" {
        pub fn foo() -> usize;
    }
}

I expected to see this happen: Compile without warnings

Instead, this happened:

warning: `foo` redeclared with a different signature
  --> src/lib.rs:11:9
   |
4  |         pub fn foo();
   |         ------------- `foo` previously declared here
...
11 |         pub fn foo() -> usize;
   |         ^^^^^^^^^^^^^^^^^^^^^^ this signature doesn't match the previous declaration
   |
   = note: `#[warn(clashing_extern_declarations)]` on by default
   = note: expected `unsafe extern "C" fn()`
              found `unsafe extern "C" fn() -> usize`

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-unknown-linux-gnu
release: 1.48.0
LLVM version: 11.0

The same behavior exists on nightly as well:

rustc 1.50.0-nightly (825637983 2020-11-18)
binary: rustc
commit-hash: 8256379832b5ecb7f71e8c5e2018446482223c12
commit-date: 2020-11-18
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
Backtrace

<backtrace>

Activity

pchickey

pchickey commented on Nov 30, 2020

@pchickey
Author
alexcrichton

alexcrichton commented on Nov 30, 2020

@alexcrichton
Member

cc @jumbatm, would you be willing to help take a look at this? (it looks like you added this way-back-when in #70946)

On wasm targets there's special logic for symbol mangling which is why this should work but not actually generate a warning. Do you know if it's possible to call that logic from here perhaps? (would be able to consolidate "what's the name of this symbol" logic too!)

jumbatm

jumbatm commented on Nov 30, 2020

@jumbatm
Contributor

Sure thing! I'm currently in the process of moving, but will be able to get onto this on the weekend :)

@rustbot claim

alexcrichton

alexcrichton commented on Dec 1, 2020

@alexcrichton
Member

No worries, and thanks! If you run out of time/steam I'm happy to look into this as well

added
O-wasmTarget: WASM (WebAssembly), http://webassembly.org/
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
on Dec 2, 2020
added a commit that references this issue on Jan 12, 2021

Auto merge of rust-lang#80009 - jumbatm:issue79581-overeager-clashing…

7a9b552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @alexcrichton@pchickey@nagisa@jumbatm

    Issue actions

      Overeager warning for clashing external declarations in different wasm import modules · Issue #79581 · rust-lang/rust