From: Kyrylo Tkachov <[email protected]>
Parallel LTRANS emits make targets without prerequisites. With
-save-temps, a later link can select the same output name. Make then
accepts the old object as current. Profile generation followed by
profile use can therefore link an instrumented LTRANS object without
libgcov.
Mark each persistent non-cache LTRANS output as phony in the generated
makefile. Make then runs its recipe for the current link. Temporary
outputs and LTRANS cache entries keep their current behavior.
Add a tree-profile test that forces parallel LTRANS with -flto=2 and
reuses the saved output name between profile generation and profile use.
The test reproduced the stale object failure on x86_64 before the change
and passed after it. On AArch64, this test and the six affected LTO
profile tests passed in both PGO and AutoFDO modes.
Bootstrapped and tested on aarch64-none-linux-gnu.
Ok for trunk?
Thanks,
Kyrill
gcc/ChangeLog:
* lto-wrapper.cc (run_gcc): Make saved parallel LTRANS outputs phony.
gcc/testsuite/ChangeLog:
* gcc.dg/tree-prof/lto-save-temps-profile-use.c: New test.
Signed-off-by: Kyrylo Tkachov <[email protected]>
---
gcc/lto-wrapper.cc | 3 +++
.../tree-prof/lto-save-temps-profile-use.c | 27 +++++++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/tree-prof/lto-save-temps-profile-use.c
diff --git a/gcc/lto-wrapper.cc b/gcc/lto-wrapper.cc
index bd25185c218..333f0ad1d1d 100644
--- a/gcc/lto-wrapper.cc
+++ b/gcc/lto-wrapper.cc
@@ -2149,6 +2149,9 @@ cont:
argv_ptr[6] = NULL;
if (parallel)
{
+ /* Saved LTRANS outputs can exist from an earlier link. */
+ if (save_temps && !ltrans_cache)
+ fprintf (mstream, ".PHONY: %s\n", output_name);
fprintf (mstream, "%s:\n\t@%s ", output_name, new_argv[0]);
for (j = 1; new_argv[j] != NULL; ++j)
fprintf (mstream, " '%s'", new_argv[j]);
diff --git a/gcc/testsuite/gcc.dg/tree-prof/lto-save-temps-profile-use.c
b/gcc/testsuite/gcc.dg/tree-prof/lto-save-temps-profile-use.c
new file mode 100644
index 00000000000..760dd7cfe73
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/lto-save-temps-profile-use.c
@@ -0,0 +1,27 @@
+/* { dg-require-effective-target lto } */
+/* { dg-options "-O2 -flto=2 -flto-partition=one -save-temps" } */
+
+static int __attribute__ ((noinline, noipa))
+identity (int value)
+{
+ return value;
+}
+
+static int (*volatile indirect_call) (int) = identity;
+
+int
+main (void)
+{
+ int result = 0;
+
+#ifdef FOR_AUTOFDO_TESTING
+ const int iterations = 1000000;
+#else
+ const int iterations = 1;
+#endif
+
+ for (int i = 0; i < iterations; ++i)
+ result |= indirect_call (0);
+
+ return result;
+}
--
2.50.1 (Apple Git-155)