From 9f92668ce1ae2d4634a0a04024b316ba8b6939a2 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Tue, 21 May 2019 12:11:23 +0200 Subject: [PATCH 1/3] Emit error when trying to use PGO in conjunction with unwinding on Windows. --- src/librustc/session/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 3d8092f6e0070..275df6d9f822b 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -1281,6 +1281,18 @@ fn validate_commandline_args_with_session_available(sess: &Session) { path.display())); } } + + // PGO does not work reliably with panic=unwind on Windows. Let's make it + // an error to combine the two for now. It always runs into an assertions + // if LLVM is built with assertions, but without assertions it sometimes + // does not crash and will probably generate a corrupted binary. + if sess.opts.debugging_opts.pgo_gen.enabled() && + sess.target.target.options.is_like_msvc && + sess.panic_strategy() == PanicStrategy::Unwind { + sess.err("Profile-guided optimization does not yet work in conjunction \ + with `-Cpanic=unwind` on Windows when targeting MSVC. \ + See https://github.com/rust-lang/rust/issues/61002 for details."); + } } /// Hash value constructed out of all the `-C metadata` arguments passed to the From ebabcf710515fb2b24907cf90fe02410ad675829 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 22 May 2019 10:35:14 +0200 Subject: [PATCH 2/3] Make test/codegen/pgo-instrumentation.rs work reliably on Windows. --- src/test/codegen/pgo-instrumentation.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/test/codegen/pgo-instrumentation.rs b/src/test/codegen/pgo-instrumentation.rs index 8493ef565d888..e94365058862a 100644 --- a/src/test/codegen/pgo-instrumentation.rs +++ b/src/test/codegen/pgo-instrumentation.rs @@ -1,20 +1,23 @@ // Test that `-Zpgo-gen` creates expected instrumentation artifacts in LLVM IR. +// Compiling with `-Cpanic=abort` because PGO+unwinding isn't supported on all platforms. // needs-profiler-support -// compile-flags: -Z pgo-gen -Ccodegen-units=1 +// compile-flags: -Z pgo-gen -Ccodegen-units=1 -Cpanic=abort // CHECK: @__llvm_profile_raw_version = // CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = private global // CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = private global -// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}main{{.*}} = private global -// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}main{{.*}} = private global +// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}some_other_function{{.*}} = private global +// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}some_other_function{{.*}} = private global // CHECK: @__llvm_profile_filename = {{.*}}"default_%m.profraw\00"{{.*}} +#![crate_type="lib"] + #[inline(never)] fn some_function() { } -fn main() { +pub fn some_other_function() { some_function(); } From a19a9e9194a03add87cd10aacfe518a61487cf0d Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Wed, 29 May 2019 14:32:38 +0200 Subject: [PATCH 3/3] Make run-make PGO tests work on MSVC. --- src/test/run-make-fulldeps/pgo-gen-lto/Makefile | 12 +++++++++++- .../pgo-gen-no-imp-symbols/Makefile | 12 +++++++++++- src/test/run-make-fulldeps/pgo-gen/Makefile | 12 +++++++++++- src/test/run-make-fulldeps/pgo-use/Makefile | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/test/run-make-fulldeps/pgo-gen-lto/Makefile b/src/test/run-make-fulldeps/pgo-gen-lto/Makefile index 48181bcbdc6d3..56f31434adee4 100644 --- a/src/test/run-make-fulldeps/pgo-gen-lto/Makefile +++ b/src/test/run-make-fulldeps/pgo-gen-lto/Makefile @@ -2,7 +2,17 @@ -include ../tools.mk +COMPILE_FLAGS=-Copt-level=3 -Clto=fat -Z pgo-gen="$(TMPDIR)" + +# LLVM doesn't yet support instrumenting binaries that use unwinding on MSVC: +# https://github.com/rust-lang/rust/issues/61002 +# +# Things work fine with -Cpanic=abort though. +ifdef IS_MSVC +COMPILE_FLAGS+= -Cpanic=abort +endif + all: - $(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen="$(TMPDIR)" test.rs + $(RUSTC) $(COMPILE_FLAGS) test.rs $(call RUN,test) || exit 1 [ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1) diff --git a/src/test/run-make-fulldeps/pgo-gen-no-imp-symbols/Makefile b/src/test/run-make-fulldeps/pgo-gen-no-imp-symbols/Makefile index 20977edb88e87..bb86160d2dfdf 100644 --- a/src/test/run-make-fulldeps/pgo-gen-no-imp-symbols/Makefile +++ b/src/test/run-make-fulldeps/pgo-gen-no-imp-symbols/Makefile @@ -2,8 +2,18 @@ -include ../tools.mk +COMPILE_FLAGS=-O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)" + +# LLVM doesn't yet support instrumenting binaries that use unwinding on MSVC: +# https://github.com/rust-lang/rust/issues/61002 +# +# Things work fine with -Cpanic=abort though. +ifdef IS_MSVC +COMPILE_FLAGS+= -Cpanic=abort +endif + all: - $(RUSTC) -O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)" --emit=llvm-ir test.rs + $(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. diff --git a/src/test/run-make-fulldeps/pgo-gen/Makefile b/src/test/run-make-fulldeps/pgo-gen/Makefile index ce44c10a7c2d2..f0ab3b7d13d27 100644 --- a/src/test/run-make-fulldeps/pgo-gen/Makefile +++ b/src/test/run-make-fulldeps/pgo-gen/Makefile @@ -2,7 +2,17 @@ -include ../tools.mk +COMPILE_FLAGS=-g -Z pgo-gen="$(TMPDIR)" + +# LLVM doesn't yet support instrumenting binaries that use unwinding on MSVC: +# https://github.com/rust-lang/rust/issues/61002 +# +# Things work fine with -Cpanic=abort though. +ifdef IS_MSVC +COMPILE_FLAGS+= -Cpanic=abort +endif + all: - $(RUSTC) -g -Z pgo-gen="$(TMPDIR)" test.rs + $(RUSTC) $(COMPILE_FLAGS) test.rs $(call RUN,test) || exit 1 [ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1) diff --git a/src/test/run-make-fulldeps/pgo-use/Makefile b/src/test/run-make-fulldeps/pgo-use/Makefile index ababd45d33e2e..72c3c34ee3741 100644 --- a/src/test/run-make-fulldeps/pgo-use/Makefile +++ b/src/test/run-make-fulldeps/pgo-use/Makefile @@ -16,7 +16,7 @@ COMMON_FLAGS=-Copt-level=s -Ccodegen-units=1 # LLVM doesn't support instrumenting binaries that use SEH: -# https://bugs.llvm.org/show_bug.cgi?id=41279 +# https://github.com/rust-lang/rust/issues/61002 # # Things work fine with -Cpanic=abort though. ifdef IS_MSVC