[committed] Move non-PIC jump table to rodata on 32-bit linux

Message ID 5c36b97c-068a-37e9-830b-3d4815838fbf@bell.net
State New
Headers show
Series
  • [committed] Move non-PIC jump table to rodata on 32-bit linux
Related show

Commit Message

John David Anglin July 29, 2018, 4:38 p.m.
The attached patch fixes a problem noted by Helge Deller.  When a 
non-PIC jump table is
placed in the text section, the local label marking the head of the 
table ends up in the
unwind data.  This is due to the R_PARISC_DIR21L and R_PARISC_DIR14R 
relocations needed
to load the address of the table.  This breaks the unwind data.

On the 32-bit Linux target, we can simply put non-PIC jump tables in 
rodata.  This has the
added benefit that it shortens the text section and avoids potential 
issues in calculating
branch distances.

We should also do this for the HP-UX SOM target.  However, this requires 
deferring the output
of branch tables to final.

When generating PIC code, the references are relative and the label is 
removed by the assembler.

Tested change on hppa-unknown-linux-gnu.  Committed change to active 
branches.

Dave

-- 
John David Anglin  dave.anglin@bell.net
2018-07-29  John David Anglin  <danglin@gcc.gnu.org>

	* config/pa/pa.c (pa_output_addr_vec): Align address table.
	* config/pa/pa.h (JUMP_TABLES_IN_TEXT_SECTION): Revise comment.
	* config/pa/pa32-linux.h (JUMP_TABLES_IN_TEXT_SECTION): Define.

Patch

Index: config/pa/pa.c
===================================================================
--- config/pa/pa.c	(revision 263009)
+++ config/pa/pa.c	(working copy)
@@ -10680,6 +10680,8 @@ 
 {
   int idx, vlen = XVECLEN (body, 0);
 
+  if (!TARGET_SOM)
+    fputs ("\t.align 4\n", asm_out_file);
   targetm.asm_out.internal_label (asm_out_file, "L", CODE_LABEL_NUMBER (lab));
   if (TARGET_GAS)
     fputs ("\t.begin_brtab\n", asm_out_file);
Index: config/pa/pa.h
===================================================================
--- config/pa/pa.h	(revision 263009)
+++ config/pa/pa.h	(working copy)
@@ -1143,22 +1143,24 @@ 
 #define ASM_OUTPUT_ASCII(FILE, P, SIZE)  \
   pa_output_ascii ((FILE), (P), (SIZE))
 
-/* Jump tables are always placed in the text section.  Technically, it
-   is possible to put them in the readonly data section.  This has the
-   benefit of getting the table out of .text and reducing branch lengths
-   as a result.
+/* Jump tables are always placed in the text section.  We have to do
+   this for the HP-UX SOM target as we can't switch sections in the
+   middle of a function.
 
-   The downside is that an additional insn (addil) is needed to access
+   On ELF targets, it is possible to put them in the readonly-data section.
+   This would get the table out of .text and reduce branch lengths.
+
+   A downside is that an additional insn (addil) is needed to access
    the table when generating PIC code.  The address difference table
-   also has to use 32-bit pc-relative relocations.  Currently, GAS does
-   not support these relocations, although it is easily modified to do
-   this operation.
+   also has to use 32-bit pc-relative relocations.
 
    The table entries need to look like "$L1+(.+8-$L0)-$PIC_pcrel$0"
    when using ELF GAS.  A simple difference can be used when using
-   SOM GAS or the HP assembler.  The final downside is GDB complains
-   about the nesting of the label for the table when debugging.  */
+   the HP assembler.
 
+   The final downside is GDB complains about the nesting of the label
+   for the table.  */
+
 #define JUMP_TABLES_IN_TEXT_SECTION 1
 
 /* This is how to output an element of a case-vector that is absolute.  */
Index: config/pa/pa32-linux.h
===================================================================
--- config/pa/pa32-linux.h	(revision 263009)
+++ config/pa/pa32-linux.h	(working copy)
@@ -67,3 +67,12 @@ 
    layout compatibility with the original linux thread implementation.  */
 #undef MALLOC_ABI_ALIGNMENT
 #define MALLOC_ABI_ALIGNMENT 128
+
+/* Place jump tables in the text section except when generating non-PIC
+   code.  When generating non-PIC code, the relocations needed to load the
+   address of the jump table result in a text label in the final executable
+   if the jump table is placed in the text section.  This breaks the unwind
+   data for the function.  Thus, the jump table needs to be placed in
+   rodata when generating non-PIC code.  */
+#undef JUMP_TABLES_IN_TEXT_SECTION
+#define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)