From 3a656462ef59a5d5288e0eb9651060d640c975ed Mon Sep 17 00:00:00 2001 From: Oneirical Date: Thu, 27 Jun 2024 11:08:49 -0400 Subject: [PATCH] rewrite and rename issue-47384 to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - .../lib.rs | 0 .../linker.ld | 0 .../main.rs | 0 .../include-all-symbols-linking/rmake.rs | 29 +++++++++++++++++++ tests/run-make/issue-47384/Makefile | 12 -------- 6 files changed, 29 insertions(+), 13 deletions(-) rename tests/run-make/{issue-47384 => include-all-symbols-linking}/lib.rs (100%) rename tests/run-make/{issue-47384 => include-all-symbols-linking}/linker.ld (100%) rename tests/run-make/{issue-47384 => include-all-symbols-linking}/main.rs (100%) create mode 100644 tests/run-make/include-all-symbols-linking/rmake.rs delete mode 100644 tests/run-make/issue-47384/Makefile diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 1e213eabab5..6ef68509f10 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -65,7 +65,6 @@ run-make/issue-35164/Makefile run-make/issue-36710/Makefile run-make/issue-37839/Makefile run-make/issue-40535/Makefile -run-make/issue-47384/Makefile run-make/issue-47551/Makefile run-make/issue-69368/Makefile run-make/issue-83045/Makefile diff --git a/tests/run-make/issue-47384/lib.rs b/tests/run-make/include-all-symbols-linking/lib.rs similarity index 100% rename from tests/run-make/issue-47384/lib.rs rename to tests/run-make/include-all-symbols-linking/lib.rs diff --git a/tests/run-make/issue-47384/linker.ld b/tests/run-make/include-all-symbols-linking/linker.ld similarity index 100% rename from tests/run-make/issue-47384/linker.ld rename to tests/run-make/include-all-symbols-linking/linker.ld diff --git a/tests/run-make/issue-47384/main.rs b/tests/run-make/include-all-symbols-linking/main.rs similarity index 100% rename from tests/run-make/issue-47384/main.rs rename to tests/run-make/include-all-symbols-linking/main.rs diff --git a/tests/run-make/include-all-symbols-linking/rmake.rs b/tests/run-make/include-all-symbols-linking/rmake.rs new file mode 100644 index 00000000000..a443fc0a5c4 --- /dev/null +++ b/tests/run-make/include-all-symbols-linking/rmake.rs @@ -0,0 +1,29 @@ +// Linkers treat archives differently from object files: all object files participate in linking, +// while archives will only participate in linking if they can satisfy at least one undefined +// reference (version scripts doesn't count). This causes `#[no_mangle]` or `#[used]` items to +// be ignored by the linker, and since they never participate in the linking, using `KEEP` in the +// linker scripts can't keep them either. This causes #47384. After the fix in #95604, this test +// checks that these symbols and sections successfully appear in the output dynamic library. +// See https://github.com/rust-lang/rust/pull/95604 +// See https://github.com/rust-lang/rust/issues/47384 + +//FIXME(Oneirical): ignore flags: only linux and cross compile + +use run_make_support::{dynamic_lib_name, llvm_objdump, llvm_readobj, rustc}; + +fn main() { + rustc().crate_type("lib").input("lib.rs").run(); + rustc().crate_type("cdylib").link_args("-Tlinker.ld").input("main.rs").run(); + // Ensure `#[used]` and `KEEP`-ed section is there + llvm_objdump() + .arg("--full-contents") + .arg("--section=.static") + .input(dynamic_lib_name("main")) + .run(); + // Ensure `#[no_mangle]` symbol is there + llvm_readobj() + .arg("--symbols") + .input(dynamic_lib_name("main")) + .run() + .assert_stdout_contains("bar"); +} diff --git a/tests/run-make/issue-47384/Makefile b/tests/run-make/issue-47384/Makefile deleted file mode 100644 index afc77cb275a..00000000000 --- a/tests/run-make/issue-47384/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../tools.mk - -# only-linux -# ignore-cross-compile - -all: main.rs - $(RUSTC) --crate-type lib lib.rs - $(RUSTC) --crate-type cdylib -Clink-args="-Tlinker.ld" main.rs - # Ensure `#[used]` and `KEEP`-ed section is there - objdump -s -j".static" $(TMPDIR)/libmain.so - # Ensure `#[no_mangle]` symbol is there - nm $(TMPDIR)/libmain.so | $(CGREP) bar