This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix gcc.c-torture/execute/20030928-1.c for ARM VxWorks
- From: Richard Sandiford <richard at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: paul at codesourcery dot com, nathan at codesourcery dot com
- Date: Wed, 04 Jul 2007 10:55:09 +0100
- Subject: Fix gcc.c-torture/execute/20030928-1.c for ARM VxWorks
This patch fixes gcc.c-torture/execute/20030928-1.c for ARM VxWorks
kernels. We tried to create "symbol + big offset" constants, which
runs into the problems described in the patch.
The fix is along the same lines as that used for ColdFire uClinux.
I think it would come in useful for ARM uClinux too.
Richard
gcc/
* config/arm/arm-protos.h (arm_cannot_force_const_mem): Declare.
* config/arm/arm.c (TARGET_CANNOT_FORCE_CONST_MEM): Redefine to
arm_cannot_force_const_mem.
(arm_cannot_force_const_mem): New function.
* config/arm/arm.h (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P): New macro.
(LEGITIMATE_CONSTANT_P): Test arm_cannot_force_const_mem instead
of arm_tls_referenced_p.
* config/arm/arm.md (movsi): Split out-of-section constants when
ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P.
* config/arm/vxworks.h (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P): Define.
Index: gcc/config/arm/arm-protos.h
===================================================================
--- gcc/config/arm/arm-protos.h 2007-07-04 02:07:24.000000000 -0700
+++ gcc/config/arm/arm-protos.h 2007-07-04 02:47:40.000000000 -0700
@@ -70,6 +70,7 @@ extern int neg_const_double_rtx_ok_for_f
extern enum reg_class coproc_secondary_reload_class (enum machine_mode, rtx,
bool);
extern bool arm_tls_referenced_p (rtx);
+extern bool arm_cannot_force_const_mem (rtx);
extern int cirrus_memory_offset (rtx);
extern int arm_coproc_mem_operand (rtx, bool);
Index: gcc/config/arm/arm.c
===================================================================
--- gcc/config/arm/arm.c 2007-07-04 02:07:24.000000000 -0700
+++ gcc/config/arm/arm.c 2007-07-04 02:47:40.000000000 -0700
@@ -377,7 +377,7 @@ #define TARGET_HAVE_TLS true
#endif
#undef TARGET_CANNOT_FORCE_CONST_MEM
-#define TARGET_CANNOT_FORCE_CONST_MEM arm_tls_referenced_p
+#define TARGET_CANNOT_FORCE_CONST_MEM arm_cannot_force_const_mem
#ifdef HAVE_AS_TLS
#undef TARGET_ASM_OUTPUT_DWARF_DTPREL
@@ -4580,6 +4580,23 @@ arm_tls_referenced_p (rtx x)
return for_each_rtx (&x, arm_tls_operand_p_1, NULL);
}
+
+/* Implement TARGET_CANNOT_FORCE_CONST_MEM. */
+
+bool
+arm_cannot_force_const_mem (rtx x)
+{
+ rtx base, offset;
+
+ if (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
+ {
+ split_const (x, &base, &offset);
+ if (GET_CODE (base) == SYMBOL_REF
+ && !offset_within_block_p (base, INTVAL (offset)))
+ return true;
+ }
+ return arm_tls_referenced_p (x);
+}
#define REG_OR_SUBREG_REG(X) \
(GET_CODE (X) == REG \
Index: gcc/config/arm/arm.h
===================================================================
--- gcc/config/arm/arm.h 2007-07-04 02:07:24.000000000 -0700
+++ gcc/config/arm/arm.h 2007-07-04 02:47:40.000000000 -0700
@@ -1827,6 +1827,10 @@ #define CONSTANT_ADDRESS_P(X) \
#endif /* AOF_ASSEMBLER */
+/* True if SYMBOL + OFFSET constants must refer to something within
+ SYMBOL's section. */
+#define ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P 0
+
/* Nonzero if the constant value X is a legitimate general operand.
It is given that X satisfies CONSTANT_P or is a CONST_DOUBLE.
@@ -1844,7 +1848,7 @@ #define THUMB_LEGITIMATE_CONSTANT_P(X) \
|| flag_pic)
#define LEGITIMATE_CONSTANT_P(X) \
- (!arm_tls_referenced_p (X) \
+ (!arm_cannot_force_const_mem (X) \
&& (TARGET_32BIT ? ARM_LEGITIMATE_CONSTANT_P (X) \
: THUMB_LEGITIMATE_CONSTANT_P (X)))
Index: gcc/config/arm/arm.md
===================================================================
--- gcc/config/arm/arm.md 2007-07-04 02:07:24.000000000 -0700
+++ gcc/config/arm/arm.md 2007-07-04 02:47:40.000000000 -0700
@@ -4649,6 +4649,8 @@ (define_expand "movsi"
(match_operand:SI 1 "general_operand" ""))]
"TARGET_EITHER"
"
+ rtx base, offset, tmp;
+
if (TARGET_32BIT)
{
/* Everything except mem = const or mem = mem can be done easily. */
@@ -4674,6 +4676,19 @@ (define_expand "movsi"
}
}
+ if (ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P)
+ {
+ split_const (operands[1], &base, &offset);
+ if (GET_CODE (base) == SYMBOL_REF
+ && !offset_within_block_p (base, INTVAL (offset)))
+ {
+ tmp = no_new_pseudos ? operands[0] : gen_reg_rtx (SImode);
+ emit_move_insn (tmp, base);
+ emit_insn (gen_addsi3 (operands[0], tmp, offset));
+ DONE;
+ }
+ }
+
/* Recognize the case where operand[1] is a reference to thread-local
data and load its address to a register. */
if (arm_tls_referenced_p (operands[1]))
Index: gcc/config/arm/vxworks.h
===================================================================
--- gcc/config/arm/vxworks.h 2007-07-04 02:32:40.000000000 -0700
+++ gcc/config/arm/vxworks.h 2007-07-04 02:53:12.000000000 -0700
@@ -106,3 +106,11 @@ #define FUNCTION_PROFILER VXWORKS_FUNCTI
the past before this macro was changed. */
#undef DEFAULT_STRUCTURE_SIZE_BOUNDARY
#define DEFAULT_STRUCTURE_SIZE_BOUNDARY 8
+
+/* The kernel loader does not allow relocations to overflow, so we
+ cannot allow arbitrary relocation addends in kernel modules or RTP
+ executables. Also, the dynamic loader uses the resolved relocation
+ value to distinguish references to the text and data segments, so we
+ cannot allow arbitrary offsets for shared libraries either. */
+#undef ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P
+#define ARM_OFFSETS_MUST_BE_WITHIN_SECTIONS_P 1