From a9e14668d62b294d8394b7aae08cf552ba2d684e Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Mon, 15 Jul 2024 19:42:45 -0400 Subject: [PATCH 1/2] Add `llvm_components_contain` to `run-make-support` --- src/tools/run-make-support/src/lib.rs | 2 +- src/tools/run-make-support/src/targets.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index b15705e896582..e6a45f57de608 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -61,7 +61,7 @@ pub use env::{env_var, env_var_os}; pub use run::{cmd, run, run_fail, run_with_args}; /// Helpers for checking target information. -pub use targets::{is_darwin, is_msvc, is_windows, target, uname}; +pub use targets::{is_darwin, is_msvc, is_windows, llvm_components_contain, target, uname}; /// Helpers for building names of output artifacts that are potentially target-specific. pub use artifact_names::{ diff --git a/src/tools/run-make-support/src/targets.rs b/src/tools/run-make-support/src/targets.rs index 42d4a45680d16..5dcb0b83430f9 100644 --- a/src/tools/run-make-support/src/targets.rs +++ b/src/tools/run-make-support/src/targets.rs @@ -28,6 +28,13 @@ pub fn is_darwin() -> bool { target().contains("darwin") } +/// Check if `component` is within `LLVM_COMPONENTS` +#[must_use] +pub fn llvm_components_contain(component: &str) -> bool { + // `LLVM_COMPONENTS` is a space-separated list of words + env_var("LLVM_COMPONENTS").split_whitespace().find(|s| s == &component).is_some() +} + /// Run `uname`. This assumes that `uname` is available on the platform! #[track_caller] #[must_use] From a8b6e3f5c9a9addf320f34e33422043ac682aa91 Mon Sep 17 00:00:00 2001 From: Jerry Wang Date: Mon, 15 Jul 2024 19:43:13 -0400 Subject: [PATCH 2/2] Migrate `atomic-lock-free` to `rmake` --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/atomic-lock-free/Makefile | 48 ----------------- tests/run-make/atomic-lock-free/rmake.rs | 52 +++++++++++++++++++ 3 files changed, 52 insertions(+), 49 deletions(-) delete mode 100644 tests/run-make/atomic-lock-free/Makefile create mode 100644 tests/run-make/atomic-lock-free/rmake.rs diff --git a/src/tools/tidy/src/allowed_run_make_makefiles.txt b/src/tools/tidy/src/allowed_run_make_makefiles.txt index 2e26f9344b899..f33cde110a5c4 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -1,5 +1,4 @@ run-make/archive-duplicate-names/Makefile -run-make/atomic-lock-free/Makefile run-make/branch-protection-check-IBT/Makefile run-make/c-dynamic-dylib/Makefile run-make/c-dynamic-rlib/Makefile diff --git a/tests/run-make/atomic-lock-free/Makefile b/tests/run-make/atomic-lock-free/Makefile deleted file mode 100644 index 37e59624a2541..0000000000000 --- a/tests/run-make/atomic-lock-free/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -include ../tools.mk - -# This tests ensure that atomic types are never lowered into runtime library calls that are not -# guaranteed to be lock-free. - -all: -ifeq ($(UNAME),Linux) -ifeq ($(filter x86,$(LLVM_COMPONENTS)),x86) - $(RUSTC) --target=i686-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=x86_64-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add -endif -ifeq ($(filter arm,$(LLVM_COMPONENTS)),arm) - $(RUSTC) --target=arm-unknown-linux-gnueabi atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=arm-unknown-linux-gnueabihf atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=armv7-unknown-linux-gnueabihf atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=thumbv7neon-unknown-linux-gnueabihf atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add -endif -ifeq ($(filter aarch64,$(LLVM_COMPONENTS)),aarch64) - $(RUSTC) --target=aarch64-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add -endif -ifeq ($(filter mips,$(LLVM_COMPONENTS)),mips) - $(RUSTC) --target=mips-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=mipsel-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add -endif -ifeq ($(filter powerpc,$(LLVM_COMPONENTS)),powerpc) - $(RUSTC) --target=powerpc-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=powerpc-unknown-linux-gnuspe atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=powerpc64-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add - $(RUSTC) --target=powerpc64le-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add -endif -ifeq ($(filter systemz,$(LLVM_COMPONENTS)),systemz) - $(RUSTC) --target=s390x-unknown-linux-gnu atomic_lock_free.rs - nm "$(TMPDIR)/libatomic_lock_free.rlib" | $(CGREP) -v __atomic_fetch_add -endif -endif diff --git a/tests/run-make/atomic-lock-free/rmake.rs b/tests/run-make/atomic-lock-free/rmake.rs new file mode 100644 index 0000000000000..77e136e8487f3 --- /dev/null +++ b/tests/run-make/atomic-lock-free/rmake.rs @@ -0,0 +1,52 @@ +// This tests ensure that atomic types are never lowered into runtime library calls that are not +// guaranteed to be lock-free. + +//@ only-linux + +use run_make_support::{llvm_components_contain, llvm_readobj, rustc}; + +fn compile(target: &str) { + rustc().input("atomic_lock_free.rs").target(target).run(); +} + +fn check() { + llvm_readobj() + .symbols() + .input("libatomic_lock_free.rlib") + .run() + .assert_stdout_not_contains("__atomic_fetch_add"); +} + +fn compile_and_check(target: &str) { + compile(target); + check(); +} + +fn main() { + if llvm_components_contain("x86") { + compile_and_check("i686-unknown-linux-gnu"); + compile_and_check("x86_64-unknown-linux-gnu"); + } + if llvm_components_contain("arm") { + compile_and_check("arm-unknown-linux-gnueabi"); + compile_and_check("arm-unknown-linux-gnueabihf"); + compile_and_check("armv7-unknown-linux-gnueabihf"); + compile_and_check("thumbv7neon-unknown-linux-gnueabihf"); + } + if llvm_components_contain("aarch64") { + compile_and_check("aarch64-unknown-linux-gnu"); + } + if llvm_components_contain("mips") { + compile_and_check("mips-unknown-linux-gnu"); + compile_and_check("mipsel-unknown-linux-gnu"); + } + if llvm_components_contain("powerpc") { + compile_and_check("powerpc-unknown-linux-gnu"); + compile_and_check("powerpc-unknown-linux-gnuspe"); + compile_and_check("powerpc64-unknown-linux-gnu"); + compile_and_check("powerpc64le-unknown-linux-gnu"); + } + if llvm_components_contain("systemz") { + compile_and_check("s390x-unknown-linux-gnu"); + } +}