Skip to content

Commit 90d6d33

Browse files
Rollup merge of #87307 - michaelwoerister:pgo-unwind-msvc, r=nagisa
Allow combining -Cprofile-generate and -Cpanic=unwind when targeting MSVC. The LLVM limitation that previously prevented this has been fixed in LLVM 9 which is older than the oldest LLVM version we currently support. Fixes #61002. r? ``@nagisa`` (or anyone else from ``@rust-lang/wg-llvm)``
2 parents 8dba898 + d56c02d commit 90d6d33

File tree

8 files changed

+2
-81
lines changed

8 files changed

+2
-81
lines changed

compiler/rustc_session/src/session.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::cgu_reuse_tracker::CguReuseTracker;
22
use crate::code_stats::CodeStats;
33
pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo};
4-
use crate::config::{self, CrateType, OutputType, PrintRequest, SwitchWithOptPath};
4+
use crate::config::{self, CrateType, OutputType, SwitchWithOptPath};
55
use crate::filesearch;
66
use crate::lint::{self, LintId};
77
use crate::parse::ParseSess;
@@ -1440,25 +1440,6 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
14401440
}
14411441
}
14421442

1443-
// PGO does not work reliably with panic=unwind on Windows. Let's make it
1444-
// an error to combine the two for now. It always runs into an assertions
1445-
// if LLVM is built with assertions, but without assertions it sometimes
1446-
// does not crash and will probably generate a corrupted binary.
1447-
// We should only display this error if we're actually going to run PGO.
1448-
// If we're just supposed to print out some data, don't show the error (#61002).
1449-
if sess.opts.cg.profile_generate.enabled()
1450-
&& sess.target.is_like_msvc
1451-
&& sess.panic_strategy() == PanicStrategy::Unwind
1452-
&& sess.opts.prints.iter().all(|&p| p == PrintRequest::NativeStaticLibs)
1453-
{
1454-
sess.err(
1455-
"Profile-guided optimization does not yet work in conjunction \
1456-
with `-Cpanic=unwind` on Windows when targeting MSVC. \
1457-
See issue #61002 <https://github.com/rust-lang/rust/issues/61002> \
1458-
for more information.",
1459-
);
1460-
}
1461-
14621443
// Sanitizers can only be used on platforms that we know have working sanitizer codegen.
14631444
let supported_sanitizers = sess.target.options.supported_sanitizers;
14641445
let unsupported_sanitizers = sess.opts.debugging_opts.sanitizer - supported_sanitizers;

src/test/codegen/pgo-instrumentation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Test that `-Cprofile-generate` creates expected instrumentation artifacts in LLVM IR.
2-
// Compiling with `-Cpanic=abort` because PGO+unwinding isn't supported on all platforms.
32

43
// needs-profiler-support
5-
// compile-flags: -Cprofile-generate -Ccodegen-units=1 -Cpanic=abort
4+
// compile-flags: -Cprofile-generate -Ccodegen-units=1
65

76
// CHECK: @__llvm_profile_raw_version =
87
// CHECK-DAG: @__profc_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = {{.*}}global

src/test/run-make-fulldeps/pgo-branch-weights/Makefile

-13
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,6 @@
66

77
-include ../tools.mk
88

9-
# This test makes sure that instrumented binaries record the right counts for
10-
# functions being called and branches being taken. We run an instrumented binary
11-
# with an argument that causes a know path through the program and then check
12-
# that the expected counts get added to the use-phase LLVM IR.
13-
14-
# LLVM doesn't support instrumenting binaries that use SEH:
15-
# https://github.com/rust-lang/rust/issues/61002
16-
#
17-
# Things work fine with -Cpanic=abort though.
18-
ifdef IS_MSVC
19-
COMMON_FLAGS=-Cpanic=abort
20-
endif
21-
229
# For some very small programs GNU ld seems to not properly handle
2310
# instrumentation sections correctly. Neither Gold nor LLD have that problem.
2411
ifeq ($(UNAME),Linux)

src/test/run-make-fulldeps/pgo-gen-lto/Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
COMPILE_FLAGS=-Copt-level=3 -Clto=fat -Cprofile-generate="$(TMPDIR)"
1010

11-
# LLVM doesn't yet support instrumenting binaries that use unwinding on MSVC:
12-
# https://github.com/rust-lang/rust/issues/61002
13-
#
14-
# Things work fine with -Cpanic=abort though.
15-
ifdef IS_MSVC
16-
COMPILE_FLAGS+= -Cpanic=abort
17-
endif
18-
1911
all:
2012
$(RUSTC) $(COMPILE_FLAGS) test.rs
2113
$(call RUN,test) || exit 1

src/test/run-make-fulldeps/pgo-gen-no-imp-symbols/Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44

55
COMPILE_FLAGS=-O -Ccodegen-units=1 -Cprofile-generate="$(TMPDIR)"
66

7-
# LLVM doesn't yet support instrumenting binaries that use unwinding on MSVC:
8-
# https://github.com/rust-lang/rust/issues/61002
9-
#
10-
# Things work fine with -Cpanic=abort though.
11-
ifdef IS_MSVC
12-
COMPILE_FLAGS+= -Cpanic=abort
13-
endif
14-
157
all:
168
$(RUSTC) $(COMPILE_FLAGS) --emit=llvm-ir test.rs
179
# We expect symbols starting with "__llvm_profile_".

src/test/run-make-fulldeps/pgo-gen/Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
COMPILE_FLAGS=-g -Cprofile-generate="$(TMPDIR)"
1010

11-
# LLVM doesn't yet support instrumenting binaries that use unwinding on MSVC:
12-
# https://github.com/rust-lang/rust/issues/61002
13-
#
14-
# Things work fine with -Cpanic=abort though.
15-
ifdef IS_MSVC
16-
COMPILE_FLAGS+= -Cpanic=abort
17-
endif
18-
1911
all:
2012
$(RUSTC) $(COMPILE_FLAGS) test.rs
2113
$(call RUN,test) || exit 1

src/test/run-make-fulldeps/pgo-indirect-call-promotion/Makefile

-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@
66

77
-include ../tools.mk
88

9-
# This test makes sure that indirect call promotion is performed. The test
10-
# programs calls the same function a thousand times through a function pointer.
11-
# Only PGO data provides the information that it actually always is the same
12-
# function. We verify that the indirect call promotion pass inserts a check
13-
# whether it can make a direct call instead of the indirect call.
14-
15-
# LLVM doesn't support instrumenting binaries that use SEH:
16-
# https://github.com/rust-lang/rust/issues/61002
17-
#
18-
# Things work fine with -Cpanic=abort though.
19-
ifdef IS_MSVC
20-
COMMON_FLAGS=-Cpanic=abort
21-
endif
22-
239
all:
2410
# We don't compile `opaque` with either optimizations or instrumentation.
2511
# We don't compile `opaque` with either optimizations or instrumentation.

src/test/run-make-fulldeps/pgo-use/Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818

1919
COMMON_FLAGS=-Copt-level=2 -Ccodegen-units=1 -Cllvm-args=-disable-preinline
2020

21-
# LLVM doesn't support instrumenting binaries that use SEH:
22-
# https://github.com/rust-lang/rust/issues/61002
23-
#
24-
# Things work fine with -Cpanic=abort though.
25-
ifdef IS_MSVC
26-
COMMON_FLAGS+= -Cpanic=abort
27-
endif
28-
2921
ifeq ($(UNAME),Darwin)
3022
# macOS does not have the `tac` command, but `tail -r` does the same thing
3123
TAC := tail -r

0 commit comments

Comments
 (0)