Skip to content

impls containing static defined in private modules cause linking errors #20201

Closed
@nagisa

Description

@nagisa

Yesterday on IRC @kmcguire3413 asked about interesting link issue which stems from the use of panic! macro. Sadly we couldn’t quite pinpoint the exact issue or produce more minimal test case than a full repository of code.

The repository in question is water.rs. When debugging be sure to use this exact commit linked by previous link since the next commit introduces a workaroud. Steps to reproduce:

$ git checkout e4638ff
$ cargo test
…
error: linking with `cc` failed: exit code: 1
…
safesync.0.rs:(.text._ZN7message11SyncMessage11get_payload21h13055894943565378597E+0x17b): undefined reference to `message::SyncMessage::get_payload::_FILE_LINE::hfe26c9c1d4aeb16dNgb'

Now the funny thing is, that the symbol exists in the rlib, that’s linked to the test (though it’s type should probably be D, rather than d):

$ nm -C target/libwater-6db6f607792c73a1.rlib | grep hfe26c9c1d4aeb16dNgb
0000000000000000 d message::SyncMessage::get_payload::_FILE_LINE::hfe26c9c1d4aeb16dNgb

Commenting the panic or call to the relevant function fixes the issue as well as moving SyncMessage implementation to a different file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions