[gcc r11-9532] IBM Z: fix `section type conflict` with -mindirect-branch-table

Ilya Leoshkevich iii@gcc.gnu.org
Wed Feb 2 12:27:37 GMT 2022


https://gcc.gnu.org/g:f9b49f9da2258b2e17564d4fa253cc9db3a28a82

commit r11-9532-gf9b49f9da2258b2e17564d4fa253cc9db3a28a82
Author: Ilya Leoshkevich <iii@linux.ibm.com>
Date:   Fri Jan 28 13:34:24 2022 +0100

    IBM Z: fix `section type conflict` with -mindirect-branch-table
    
    s390_code_end () puts indirect branch tables into separate sections and
    tries to switch back to wherever it was in the beginning by calling
    switch_to_section (current_function_section ()).
    
    First of all, this is unnecessary - the other backends don't do it.
    
    Furthermore, at this time there is no current function, but if the
    last processed function was cold, in_cold_section_p remains set.  This
    causes targetm.asm_out.function_section () to call
    targetm.section_type_flags (), which in absence of current function
    decl classifies the section as SECTION_WRITE.  This causes a section
    type conflict with the existing SECTION_CODE.
    
    gcc/ChangeLog:
    
            * config/s390/s390.c (s390_code_end): Do not switch back to
            code section.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/s390/nobp-section-type-conflict.c: New test.
    
    (cherry picked from commit 8753b13a31c777cdab0265dae0b68534247908f7)

Diff:
---
 gcc/config/s390/s390.c                             |  1 -
 .../gcc.target/s390/nobp-section-type-conflict.c   | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 8895dd7cc76..2d2e6522eb4 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -16700,7 +16700,6 @@ s390_code_end (void)
 	      assemble_name_raw (asm_out_file, label_start);
 	      fputs ("-.\n", asm_out_file);
 	    }
-	  switch_to_section (current_function_section ());
 	}
     }
 }
diff --git a/gcc/testsuite/gcc.target/s390/nobp-section-type-conflict.c b/gcc/testsuite/gcc.target/s390/nobp-section-type-conflict.c
new file mode 100644
index 00000000000..5d78bc99bb5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/nobp-section-type-conflict.c
@@ -0,0 +1,22 @@
+/* Checks that we don't get error: section type conflict with ‘put_page’.  */
+
+/* { dg-do compile } */
+/* { dg-options "-mindirect-branch=thunk-extern -mfunction-return=thunk-extern -mindirect-branch-table -O2" } */
+
+int a;
+int b (void);
+void c (int);
+
+static void
+put_page (void)
+{
+  if (b ())
+    c (a);
+}
+
+__attribute__ ((__section__ (".init.text"), __cold__)) void
+d (void)
+{
+  put_page ();
+  put_page ();
+}


More information about the Gcc-cvs mailing list