Skip to content

rustc --test ignores static:-whole-archive link modifiers #100066

Closed
@dcsommer

Description

@dcsommer

I am attempting to use the (now stabilized) RFC 2951 syntax to control how my test binary is compiled. I have created a repro at https://github.com/dcsommer/rustc-linking

git clone https://github.com/dcsommer/rustc-linking.git
cd rustc-linking
./run.sh

In run.sh, I tell rustc to link 2 static libraries, one with (+whole-archive) and one without (-whole-archive). I add a nonsense link argument so I can inspect the produced link line.

I expect to see libbar.a linked without whole archive.

Instead, I see both foo and bar libraries linked with --whole-archive:

-l static:+whole-archive=foo -l static:-whole-archive=bar
# linker line yields ...
"-Wl,-Bstatic" "-Wl,--whole-archive" "-lfoo" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "-lbar" "-Wl,--no-whole-archive"

This may be related to the default +bundle documented here. When I use nightly and specify -bundle it works as expected:

-l static:+whole-archive,-bundle=foo -l static:-whole-archive,-bundle=bar
# linker line yields ...
"-Wl,-Bstatic" "-Wl,--whole-archive" "-lfoo" "-Wl,--no-whole-archive" "-lbar"

However, I cannot use the nightly toolchain, so I cannot use -bundle, and +bundle seems inappropriate for a final binary crate types like cdylib, staticlib, and executables anyway.

Tested with 1.62.1 stable and 1.64 nightly.

Possibly related issues: #99429, #73632

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions