This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Avoid hot/cold partitioning in naked functions (PR target/85984)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Biener <rguenther at suse dot de>, Jeff Law <law at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 31 May 2018 08:51:59 +0200
- Subject: [PATCH] Avoid hot/cold partitioning in naked functions (PR target/85984)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
We say in the documentation only supported body of naked functions
is basic asm, anything else may but might not work. On the following
testcase we end up with ICE, because the missing epilogue means the first
partition is not separated from the second partition with a barrier and
something before that.
I think easiest is just not to partition such functions, for the really
supported case it shouldn't make a difference anyway.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2018-05-31 Jakub Jelinek <jakub@redhat.com>
PR target/85984
* bb-reorder.c (pass_partition_blocks::gate): Return false for
functions with naked attribute.
* gcc.target/i386/pr85984.c: New test.
--- gcc/bb-reorder.c.jj 2018-05-09 20:12:28.399260557 +0200
+++ gcc/bb-reorder.c 2018-05-30 16:01:12.113006870 +0200
@@ -2928,8 +2928,8 @@ pass_partition_blocks::gate (function *f
{
/* The optimization to partition hot/cold basic blocks into separate
sections of the .o file does not work well with linkonce or with
- user defined section attributes. Don't call it if either case
- arises. */
+ user defined section attributes or with naked attribute. Don't call
+ it if either case arises. */
return (flag_reorder_blocks_and_partition
&& optimize
/* See pass_reorder_blocks::gate. We should not partition if
@@ -2937,6 +2937,7 @@ pass_partition_blocks::gate (function *f
&& optimize_function_for_speed_p (fun)
&& !DECL_COMDAT_GROUP (current_function_decl)
&& !lookup_attribute ("section", DECL_ATTRIBUTES (fun->decl))
+ && !lookup_attribute ("naked", DECL_ATTRIBUTES (fun->decl))
/* Workaround a bug in GDB where read_partial_die doesn't cope
with DIEs with DW_AT_ranges, see PR81115. */
&& !(in_lto_p && MAIN_NAME_P (DECL_NAME (fun->decl))));
--- gcc/testsuite/gcc.target/i386/pr85984.c.jj 2018-05-30 16:08:24.951523398 +0200
+++ gcc/testsuite/gcc.target/i386/pr85984.c 2018-05-30 16:08:12.184508165 +0200
@@ -0,0 +1,18 @@
+/* PR target/85984 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+int foo (void);
+
+void __attribute__((naked))
+bar (void)
+{
+ if (!foo ())
+ __builtin_abort ();
+}
+
+void
+baz (void)
+{
+ bar ();
+}
Jakub