Skip to content

Compiling to Shared Library doesn't always expose reexported symbols #50007

Closed

Description

@CryZe

Consider the following:

We have 2 crates, rlib helper and the shared library foo that depends on the helper crate. The helper crate's lib.rs looks like this:

#[no_mangle]
pub extern fn bla() -> i32 {
    5
}

The shared library's lib.rs looks like this:

extern crate helper;

pub use helper::bla;

The code is then compiled to a shared library. The bla symbol is not exported. That does not seem intentional.

Activity

  1. dbrgn commented on May 15, 2018

    @dbrgn
    Contributor

    Maybe a duplicate of #36342?

  2. added
    A-linkageArea: linking into static, shared libraries and binaries
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Aug 27, 2018
  3. thomcc commented on Nov 8, 2018

    @thomcc
    Member

    It's not a duplicate of #36342, which is about reexporting functions defined in C AFAICT. We've been struggling with this in https://github.com/mozilla/application-services.

    This doesn't seem to happen with all targets. In particular, x86_64-apple-darwin seems unaffected, while i686-linux-android is effected (really all android targets seem to be affected).

    I have a simple reproducable case at https://github.com/thomcc/megazord/tree/simple-bug-repro (e.g. the simple-bug-repro branch of that repository). An explanation for how to use it to reproduce the issue is in the README.md.

    It's worth noting that if you turn on LTO, the issue does not manifest (all symbols are present), presumably due to it being a single compilation unit at that point (thanks to the reporter for pointing this out to me, I did not realize it initially).

  4. ncalexan commented on Nov 8, 2018

    @ncalexan

    This doesn't seem to happen with all targets. In particular, x86_64-apple-darwin seems unaffected, while i686-linux-android is effected (really all android targets seem to be affected).

    For more context: the Android toolchains are all specifying a stand-alone Android NDK toolchain, in particular a clang-based toolchain. I believe our Desktop targets (like x86_64-apple-darwin) are GCC based. So we may just be seeing a clang-ism as it passes linking through to an Android NDK toolchain GNU ld. I haven't tried lld to get to the bottom of this.

  5. Mark-Simulacrum commented on Aug 10, 2019

    @Mark-Simulacrum
    Member

    The right fix here might be that the relevant extern blocks should get kind = "static" on the link attributes, per #62088 (comment).

  6. thomcc commented on Aug 10, 2019

    @thomcc
    Member

    @Mark-Simulacrum This issue is about no_mangle symbols from another crate that get brought in by use. There are no extern blocks.

  7. kvark commented on Feb 12, 2020

    @kvark
    Contributor

    Heads up - this hits us in https://github.com/gfx-rs/wgpu as well. Very annoying and inconvenient, would very much appreciate any progress here!

  8. hansihe commented on May 14, 2020

    @hansihe

    Hitting this issue as well.

    My use-case is exporting some functions from my executable, then loading a dynamic library that needs to link to those symbols.

  9. 18 remaining items

  10. added 2 commits that reference this issue on Apr 17, 2022
    96d2ec9
    7f6d83e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-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