This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: Fix FRV switch table generation in PIC mode
- From: Nick Clifton <nickc at redhat dot com>
- To: aldyh at redhat dot com, aoliva at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 21 Feb 2007 15:27:14 +0000
- Subject: RFA: Fix FRV switch table generation in PIC mode
Hi Aldy, Hi Alex,
We recently ran across a problem with the FRV port's support for
compiling switch tables when running in PIC mode. The original test
case involved ld.so seg-faulting, but I think that the problem can
be demonstrated on a simpler test case:
% frv-elf-gcc -O2 -fPIC -S gcc/testsuite/gcc.c-torture/compile/pr29201.c
% cat pr29201.s
...
sethi.p #gprelhi(.L8), gr4
setlo #gprello(.L8), gr4
add.p gr4,gr17,gr4
slli gr5,#2,gr5
ld @(gr5,gr4), gr6
jmpl @(gr6,gr4)
.section .rodata
.p2align 2
.text
.L8:
.section .rodata
.word .L4-.L8
.word .L6-.L8
.word .L7-.L8
.word .L10-.L8
.word .L7-.L8
.word .L7-.L8
.text
...
The problem is that the switch table is in the .rodata section, but
.L8, the table's label, is in the .text section.
I tracked the problem down to frv.h file where it defines
ASM_OUTPUT_CASE_LABEL in an attempt to work around the problem and
put the switch table into the .text section. The define still
works, but then the switch table generation code in gcc
automatically adds a ".section .rodata" statement afterwards,
negating its effect. Fortunately the answer is simple - the
JUMP_TABLES_IN_TEXT_SECTION macro can now be conditional, so
applying the patch below makes things work.
% frv-elf-gcc-patched -O2 -fPIC -S gcc/testsuite/gcc.c-torture/compile/pr29201.c
% cat pr29201.s
...
sethi.p #gprelhi(.L8), gr4
setlo #gprello(.L8), gr4
add.p gr4,gr17,gr4
slli gr5,#2,gr5
ld @(gr5,gr4), gr6
jmpl @(gr6,gr4)
.p2alignl 2,0x80880000
.p2align 2
.L8:
.word .L4-.L8
.word .L6-.L8
.word .L7-.L8
.word .L10-.L8
.word .L7-.L8
.word .L7-.L8
...
What do you think ? May I apply the patch ? (Mainline and/or 4.2
branch ?)
Cheers
Nick
gcc/ChangeLog
2007-02-21 Nick Clifton <nickc@redhat.com>
* config/frv/frv.h (ASM_OUTPUT_CASE_LABEL): Delete.
(JUMP_TABLES_IN_TEXT_SECTION): Define.
Index: gcc/config/frv/frv.h
===================================================================
--- gcc/config/frv/frv.h (revision 122189)
+++ gcc/config/frv/frv.h (working copy)
@@ -2595,33 +2595,7 @@ fprintf (STREAM, "\t.word .L%d-.L%d\n",
#define ASM_OUTPUT_ADDR_VEC_ELT(STREAM, VALUE) \
fprintf (STREAM, "\t.word .L%d\n", VALUE)
-/* Define this if the label before a jump-table needs to be output specially.
- The first three arguments are the same as for `(*targetm.asm_out.internal_label)';
- the fourth argument is the jump-table which follows (a `jump_insn'
- containing an `addr_vec' or `addr_diff_vec').
-
- This feature is used on system V to output a `swbeg' statement for the
- table.
-
- If this macro is not defined, these labels are output with
- `(*targetm.asm_out.internal_label)'.
-
- Defined in svr4.h. */
-/* When generating embedded PIC or mips16 code we want to put the jump
- table in the .text section. In all other cases, we want to put the
- jump table in the .rdata section. Unfortunately, we can't use
- JUMP_TABLES_IN_TEXT_SECTION, because it is not conditional.
- Instead, we use ASM_OUTPUT_CASE_LABEL to switch back to the .text
- section if appropriate. */
-
-#undef ASM_OUTPUT_CASE_LABEL
-#define ASM_OUTPUT_CASE_LABEL(STREAM, PREFIX, NUM, TABLE) \
-do { \
- if (flag_pic) \
- switch_to_section (function_section (current_function_decl)); \
- (*targetm.asm_out.internal_label) (STREAM, PREFIX, NUM); \
-} while (0)
-
+#define JUMP_TABLES_IN_TEXT_SECTION (flag_pic)
/* Assembler Commands for Exception Regions. */