Skip to content

tests/run-make/used-proc-macro is flaky as it relies on linker behavior #155434

@japaric

Description

@japaric

The stated expectation of the test is:

Test that #[used] statics are included in the final dylib for proc-macros too.

However, the #[used] attribute only guarantees that a static variable will be preserved in the compiler's output object file (see the Rust reference). The linker is completely free to discard such symbols as it's unaware of the presence of the #[used] attribute in the Rust source code.

Dylibs are partially linked ("relocatable") objects so the compiler will invoke the linker to perform the partially linking. The process of partially linking the dylib can discard the VERY_IMPORTANT_SYMBOL static which this test then checks it's present in the final dylib artifact (.so file). Therefore, as written this test is flaky as it relies on the linker not discarding the symbol.

In Ferrocene CI, we have observed this test fail on an aarch64-unknown-linux-gnu host running the test natively (compilation target is the host tuple). The Ferrocene CI environment for that host tuple uses GCC 10 as the linker which may be different from the version that the Rust project uses and that could explain the different outcome.

$ grep DESCRIPTION /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 20.04.6 LTS"

$ gcc --version | head -n1
gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0

$ uname -m
aarch64

$ ./x test --stage 1 tests/run-make/used-proc-macro --force-rerun
(..)
=== NEEDLE ===
VERY_IMPORTANT_SYMBOL

thread 'main' (100848) panicked at /home/ci/project/tests/run-make/used-proc-macro/rmake.rs:17:10:
needle was not found in haystack
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------------------------------------------

---- [run-make] tests/run-make/used-proc-macro stdout end ----

failures:
    [run-make] tests/run-make/used-proc-macro

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 488 filtered out; finished in 608.77ms

Some tests failed in compiletest suite=run-make mode=run-make host=aarch64-unknown-linux-gnu target=aarch64-unknown-linux-gnu

As this is the Ferrocene source code, the git revision is different but the closest rust-lang/rust revision is e8e4541

To make this test more reliable, the proc-macro crate should access the VERY_IMPORTANT_SYMBOL variable via FFI to prevent it from being discarded by the linker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkersArea: linkers... you gotta love linkersA-testsuiteArea: The testsuite used to check the correctness of rustcC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions