Skip to content

Commit c28084a

Browse files
committed
Auto merge of #61005 - michaelwoerister:error-pgo-windows-unwind, r=zackmdavis
Emit error when trying to use PGO in conjunction with unwinding on Windows. This PR makes `rustc` emit an error when trying use PGO in conjunction with `-Cpanic=unwind` on Windows, isn't supported by LLVM yet. The error messages points to #61002, which documents this known limitation.
2 parents 19e0ddb + a19a9e9 commit c28084a

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

src/librustc/session/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,18 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12851285
path.display()));
12861286
}
12871287
}
1288+
1289+
// PGO does not work reliably with panic=unwind on Windows. Let's make it
1290+
// an error to combine the two for now. It always runs into an assertions
1291+
// if LLVM is built with assertions, but without assertions it sometimes
1292+
// does not crash and will probably generate a corrupted binary.
1293+
if sess.opts.debugging_opts.pgo_gen.enabled() &&
1294+
sess.target.target.options.is_like_msvc &&
1295+
sess.panic_strategy() == PanicStrategy::Unwind {
1296+
sess.err("Profile-guided optimization does not yet work in conjunction \
1297+
with `-Cpanic=unwind` on Windows when targeting MSVC. \
1298+
See https://github.com/rust-lang/rust/issues/61002 for details.");
1299+
}
12881300
}
12891301

12901302
/// Hash value constructed out of all the `-C metadata` arguments passed to the
+7-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
// Test that `-Zpgo-gen` creates expected instrumentation artifacts in LLVM IR.
2+
// Compiling with `-Cpanic=abort` because PGO+unwinding isn't supported on all platforms.
23

34
// needs-profiler-support
4-
// compile-flags: -Z pgo-gen -Ccodegen-units=1
5+
// compile-flags: -Z pgo-gen -Ccodegen-units=1 -Cpanic=abort
56

67
// CHECK: @__llvm_profile_raw_version =
78
// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = private global
89
// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}some_function{{.*}} = private global
9-
// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}main{{.*}} = private global
10-
// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}main{{.*}} = private global
10+
// CHECK: @__profc_{{.*}}pgo_instrumentation{{.*}}some_other_function{{.*}} = private global
11+
// CHECK: @__profd_{{.*}}pgo_instrumentation{{.*}}some_other_function{{.*}} = private global
1112
// CHECK: @__llvm_profile_filename = {{.*}}"default_%m.profraw\00"{{.*}}
1213

14+
#![crate_type="lib"]
15+
1316
#[inline(never)]
1417
fn some_function() {
1518

1619
}
1720

18-
fn main() {
21+
pub fn some_other_function() {
1922
some_function();
2023
}

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
-include ../tools.mk
44

5+
COMPILE_FLAGS=-Copt-level=3 -Clto=fat -Z pgo-gen="$(TMPDIR)"
6+
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+
515
all:
6-
$(RUSTC) -Copt-level=3 -Clto=fat -Z pgo-gen="$(TMPDIR)" test.rs
16+
$(RUSTC) $(COMPILE_FLAGS) test.rs
717
$(call RUN,test) || exit 1
818
[ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1)

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,18 @@
22

33
-include ../tools.mk
44

5+
COMPILE_FLAGS=-O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)"
6+
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+
515
all:
6-
$(RUSTC) -O -Ccodegen-units=1 -Z pgo-gen="$(TMPDIR)" --emit=llvm-ir test.rs
16+
$(RUSTC) $(COMPILE_FLAGS) --emit=llvm-ir test.rs
717
# We expect symbols starting with "__llvm_profile_".
818
$(CGREP) "__llvm_profile_" < $(TMPDIR)/test.ll
919
# We do NOT expect the "__imp_" version of these symbols.

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
-include ../tools.mk
44

5+
COMPILE_FLAGS=-g -Z pgo-gen="$(TMPDIR)"
6+
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+
515
all:
6-
$(RUSTC) -g -Z pgo-gen="$(TMPDIR)" test.rs
16+
$(RUSTC) $(COMPILE_FLAGS) test.rs
717
$(call RUN,test) || exit 1
818
[ -e "$(TMPDIR)"/default_*.profraw ] || (echo "No .profraw file"; exit 1)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
COMMON_FLAGS=-Copt-level=s -Ccodegen-units=1
1717

1818
# LLVM doesn't support instrumenting binaries that use SEH:
19-
# https://bugs.llvm.org/show_bug.cgi?id=41279
19+
# https://github.com/rust-lang/rust/issues/61002
2020
#
2121
# Things work fine with -Cpanic=abort though.
2222
ifdef IS_MSVC

0 commit comments

Comments
 (0)