rust-lang / rust-lang/rust

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

Open Beginner friendly
#155,434 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkers A-testsuite C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in tests/run-make/used-proc-macro, especially rmake.rs where the missing-symbol check is reported. Run ./x test --stage 1 tests/run-make/used-proc-macro --force-rerun to reproduce the behavior on the affected target. Done means the proc-macro accesses VERY_IMPORTANT_SYMBOL through FFI and the test reliably finds it in the final dylib.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
73/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.