fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #71868 - Mark-Simulacrum:stable-1.43.1, r=pietroalbini8d69840ab92

1.43.1
1.7 KiB43 linesraw
1# needs-profiler-support
2
3-include ../tools.mk
4
5# This test makes sure that instrumented binaries record the right counts for
6# functions being called and branches being taken. We run an instrumented binary
7# with an argument that causes a know path through the program and then check
8# that the expected counts get added to the use-phase LLVM IR.
9
10# LLVM doesn't support instrumenting binaries that use SEH:
11# https://github.com/rust-lang/rust/issues/61002
12#
13# Things work fine with -Cpanic=abort though.
14ifdef IS_MSVC
15COMMON_FLAGS=-Cpanic=abort
16endif
17
18# For some very small programs GNU ld seems to not properly handle
19# instrumentation sections correctly. Neither Gold nor LLD have that problem.
20ifeq ($(UNAME),Linux)
21ifneq (,$(findstring x86,$(TARGET)))
22COMMON_FLAGS=-Clink-args=-fuse-ld=gold
23endif
24endif
25
26
27all:
28	# We don't compile `opaque` with either optimizations or instrumentation.
29	$(RUSTC) $(COMMON_FLAGS) opaque.rs || exit 1
30	# Compile the test program with instrumentation
31	mkdir -p "$(TMPDIR)/prof_data_dir" || exit 1
32	$(RUSTC) $(COMMON_FLAGS) interesting.rs \
33		-Cprofile-generate="$(TMPDIR)/prof_data_dir" -O -Ccodegen-units=1 || exit 1
34	$(RUSTC) $(COMMON_FLAGS) main.rs -Cprofile-generate="$(TMPDIR)/prof_data_dir" -O || exit 1
35	# The argument below generates to the expected branch weights
36	$(call RUN,main aaaaaaaaaaaa2bbbbbbbbbbbb2bbbbbbbbbbbbbbbbcc) || exit 1
37	"$(LLVM_BIN_DIR)/llvm-profdata" merge \
38		-o "$(TMPDIR)/prof_data_dir/merged.profdata" \
39		"$(TMPDIR)/prof_data_dir" || exit 1
40	$(RUSTC) $(COMMON_FLAGS) interesting.rs \
41		-Cprofile-use="$(TMPDIR)/prof_data_dir/merged.profdata" -O \
42		-Ccodegen-units=1 --emit=llvm-ir || exit 1
43	cat "$(TMPDIR)/interesting.ll" | "$(LLVM_FILECHECK)" filecheck-patterns.txt