From 632f01306b2a5b7f47e554cf1280f5ef8fc9f710 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 16:23:29 -0400 Subject: [PATCH 1/3] rewrite lto-linkage-used-attr to rmake --- src/tools/tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/lto-linkage-used-attr/Makefile | 8 -------- tests/run-make/lto-linkage-used-attr/rmake.rs | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 9 deletions(-) delete mode 100644 tests/run-make/lto-linkage-used-attr/Makefile create mode 100644 tests/run-make/lto-linkage-used-attr/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 6b3533c25785f..5cb580e9f799d 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -47,7 +47,6 @@ run-make/link-cfg/Makefile run-make/link-framework/Makefile run-make/long-linker-command-lines-cmd-exe/Makefile run-make/long-linker-command-lines/Makefile -run-make/lto-linkage-used-attr/Makefile run-make/macos-deployment-target/Makefile run-make/min-global-align/Makefile run-make/native-link-modifier-bundle/Makefile diff --git a/tests/run-make/lto-linkage-used-attr/Makefile b/tests/run-make/lto-linkage-used-attr/Makefile deleted file mode 100644 index fed41a00f84b3..0000000000000 --- a/tests/run-make/lto-linkage-used-attr/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -include ../tools.mk - -# Verify that the impl_* symbols are preserved. #108030 -# only-x86_64-unknown-linux-gnu - -all: - $(RUSTC) -Cdebuginfo=0 -Copt-level=3 lib.rs - $(RUSTC) -Clto=fat -Cdebuginfo=0 -Copt-level=3 main.rs diff --git a/tests/run-make/lto-linkage-used-attr/rmake.rs b/tests/run-make/lto-linkage-used-attr/rmake.rs new file mode 100644 index 0000000000000..114c5dcf5212d --- /dev/null +++ b/tests/run-make/lto-linkage-used-attr/rmake.rs @@ -0,0 +1,14 @@ +// Link time optimizations (LTO) used to snip away some important symbols +// when setting optimization level to 3 or higher. +// This is an LLVM, not a rustc bug, fixed here: https://reviews.llvm.org/D145293 +// This test checks that the impl_* symbols are preserved as they should. +// See https://github.com/rust-lang/rust/issues/108030 + +//FIXME(Oneirical): try it on more than only-x86_64-unknown-linux-gnu + +use run_make_support::rustc; + +fn main() { + rustc().arg("-Cdebuginfo=0").opt_level("3").input("lib.rs").run(); + rustc().arg("-Clto=fat").arg("-Cdebuginfo=0").opt_level("3").input("main.rs").run(); +} From f307287659b8492d6baec07bb2a5902a6b487052 Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 16:35:37 -0400 Subject: [PATCH 2/3] rewrite no-duplicate-libs to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/no-duplicate-libs/Makefile | 11 ---------- tests/run-make/no-duplicate-libs/rmake.rs | 21 +++++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) delete mode 100644 tests/run-make/no-duplicate-libs/Makefile create mode 100644 tests/run-make/no-duplicate-libs/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 5cb580e9f799d..bc3da81fa5224 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -53,7 +53,6 @@ run-make/native-link-modifier-bundle/Makefile run-make/native-link-modifier-whole-archive/Makefile run-make/no-alloc-shim/Makefile run-make/no-builtins-attribute/Makefile -run-make/no-duplicate-libs/Makefile run-make/panic-abort-eh_frame/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile diff --git a/tests/run-make/no-duplicate-libs/Makefile b/tests/run-make/no-duplicate-libs/Makefile deleted file mode 100644 index 4be8c0262941a..0000000000000 --- a/tests/run-make/no-duplicate-libs/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -ifdef IS_MSVC -# FIXME(#27979) -all: -else -all: $(call STATICLIB,foo) $(call STATICLIB,bar) - $(RUSTC) main.rs - $(call RUN,main) -endif diff --git a/tests/run-make/no-duplicate-libs/rmake.rs b/tests/run-make/no-duplicate-libs/rmake.rs new file mode 100644 index 0000000000000..35b1234ef3484 --- /dev/null +++ b/tests/run-make/no-duplicate-libs/rmake.rs @@ -0,0 +1,21 @@ +// The rust compiler used to try to detect duplicated libraries in +// the linking order and remove the duplicates... but certain edge cases, +// such as the one presented in `foo` and `bar` in this test, demand precise +// control over the link order, including duplicates. As the anti-duplication +// filter was removed, this test should now successfully see main be compiled +// and executed. +// See https://github.com/rust-lang/rust/pull/12688 + +//@ ignore-cross-compile +// Reason: the compiled binary is executed + +// FIXME(Oneirical): try on msvc because of #27979 + +use run_make_support::{build_native_static_lib, run, rustc}; + +fn main() { + build_native_static_lib("foo"); + build_native_static_lib("bar"); + rustc().input("main.rs").run(); + run("main"); +} From 6d9d605fcac79ad8180f2368c69fd2eb3c18988d Mon Sep 17 00:00:00 2001 From: Oneirical Date: Fri, 19 Jul 2024 16:43:06 -0400 Subject: [PATCH 3/3] rewrite pgo-gen-no-imp-symbols to rmake --- .../tidy/src/allowed_run_make_makefiles.txt | 1 - tests/run-make/lto-linkage-used-attr/rmake.rs | 3 ++- tests/run-make/no-duplicate-libs/rmake.rs | 3 ++- .../run-make/pgo-gen-no-imp-symbols/Makefile | 11 -------- .../run-make/pgo-gen-no-imp-symbols/rmake.rs | 27 +++++++++++++++++++ 5 files changed, 31 insertions(+), 14 deletions(-) delete mode 100644 tests/run-make/pgo-gen-no-imp-symbols/Makefile create mode 100644 tests/run-make/pgo-gen-no-imp-symbols/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 bc3da81fa5224..5f0a953bc2bbd 100644 --- a/src/tools/tidy/src/allowed_run_make_makefiles.txt +++ b/src/tools/tidy/src/allowed_run_make_makefiles.txt @@ -56,7 +56,6 @@ run-make/no-builtins-attribute/Makefile run-make/panic-abort-eh_frame/Makefile run-make/pdb-buildinfo-cl-cmd/Makefile run-make/pgo-gen-lto/Makefile -run-make/pgo-gen-no-imp-symbols/Makefile run-make/pgo-indirect-call-promotion/Makefile run-make/pointer-auth-link-with-c/Makefile run-make/print-calling-conventions/Makefile diff --git a/tests/run-make/lto-linkage-used-attr/rmake.rs b/tests/run-make/lto-linkage-used-attr/rmake.rs index 114c5dcf5212d..12463b79a754b 100644 --- a/tests/run-make/lto-linkage-used-attr/rmake.rs +++ b/tests/run-make/lto-linkage-used-attr/rmake.rs @@ -4,7 +4,8 @@ // This test checks that the impl_* symbols are preserved as they should. // See https://github.com/rust-lang/rust/issues/108030 -//FIXME(Oneirical): try it on more than only-x86_64-unknown-linux-gnu +//@ only-x86_64-unknown-linux-gnu +// Reason: some of the inline assembly directives are architecture-specific. use run_make_support::rustc; diff --git a/tests/run-make/no-duplicate-libs/rmake.rs b/tests/run-make/no-duplicate-libs/rmake.rs index 35b1234ef3484..469348e266cb8 100644 --- a/tests/run-make/no-duplicate-libs/rmake.rs +++ b/tests/run-make/no-duplicate-libs/rmake.rs @@ -9,7 +9,8 @@ //@ ignore-cross-compile // Reason: the compiled binary is executed -// FIXME(Oneirical): try on msvc because of #27979 +//@ ignore-msvc +// Reason: native compilation results in an unresolved external symbol use run_make_support::{build_native_static_lib, run, rustc}; diff --git a/tests/run-make/pgo-gen-no-imp-symbols/Makefile b/tests/run-make/pgo-gen-no-imp-symbols/Makefile deleted file mode 100644 index d2baa145ba506..0000000000000 --- a/tests/run-make/pgo-gen-no-imp-symbols/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../tools.mk - -COMPILE_FLAGS=-O -Ccodegen-units=1 -Cprofile-generate="$(TMPDIR)" -Zno-profiler-runtime - -all: - $(RUSTC) $(COMPILE_FLAGS) --emit=llvm-ir test.rs - # We expect symbols starting with "__llvm_profile_". - $(CGREP) "__llvm_profile_" < $(TMPDIR)/test.ll - # We do NOT expect the "__imp_" version of these symbols. - $(CGREP) -v "__imp___llvm_profile_" < $(TMPDIR)/test.ll # 64 bit - $(CGREP) -v "__imp____llvm_profile_" < $(TMPDIR)/test.ll # 32 bit diff --git a/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs b/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs new file mode 100644 index 0000000000000..85ade7885ce7e --- /dev/null +++ b/tests/run-make/pgo-gen-no-imp-symbols/rmake.rs @@ -0,0 +1,27 @@ +// LLVM's profiling instrumentation adds a few symbols that are used by the profiler runtime. +// Since these show up as globals in the LLVM IR, the compiler generates dllimport-related +// __imp_ stubs for them. This can lead to linker errors because the instrumentation +// symbols have weak linkage or are in a comdat section, but the __imp_ stubs aren't. +// Since profiler-related symbols were excluded from stub-generation in #59812, this has +// been fixed, and this test checks that the llvm profile symbol appear, but without the +// anomalous __imp_ stubs. +// See https://github.com/rust-lang/rust/pull/59812 + +use run_make_support::{cwd, rfs, rustc}; + +fn main() { + rustc() + .input("test.rs") + .emit("llvm-ir") + .opt() + .codegen_units(1) + .profile_generate(cwd()) + .arg("-Zno-profiler-runtime") + .run(); + let out = rfs::read_to_string("test.ll"); + // We expect symbols starting with "__llvm_profile_". + assert!(out.contains("__llvm_profile_")); + // We do NOT expect the "__imp_" version of these symbols. + assert!(!out.contains("__imp___llvm_profile_")); // 64 bit + assert!(!out.contains("__imp____llvm_profile_")); // 32 bit +}