gcc/ChangeLog:
* config/rx/linux.h (TARGET_CPU_CPP_BUILTINS): Add FDPIC macros.
(STARTFILE_SPEC): Add FDPIC support.
(ENDFILE_SPEC): Likewise.
(ASM_SPEC): Likewise.
(LIB_SPEC): New.
(LINK_SPEC): New.
(PREFERRED_DEBUGGING_TYPE): New.
(PIC_REG): New.
(GOT_SYMBOL_NAME): New.
(PIC_OFFSET_TABLE_REGNUM): New.
(PIC_OFFSET_TABLE_REG_CALL_CLOBBERED): New.
(TARGET_ASM_FILE_END): New.
(NO_FUNCTION_CSE): New.
(LEGITIMATE_PIC_OPERAND_P): New macro.
(SYMBOLIC_CONST_P): Likewise.
(EPILOGUE_USES): Likewise.
* config/rx/rx-protos.h (rx_maybe_legitimize_pi_operand):
Rename from rx_maybe_pidify_operand
(nonpic_symbol_mentioned_p): New prototype.
(legitimize_pic_address): Likewise.
(rx_legitimate_pic_operand_p): Likewiae.
(rx_get_fdpic_reg_initial_val): Likewise.
(rx_is_unspec_offset): Likewise.
(rx_expand_pcrel): Likewise.
* config/rx/rx.h (LINK_SPEC): Add shared.
* config/rx/rx.opt: Add mfdpic option.
Signed-off-by: Yoshinori Sato <[email protected]>
---
gcc/config/rx/linux.h | 58 +++++++++++++++++++++++++++++++++++++++
gcc/config/rx/rx-protos.h | 8 +++++-
gcc/config/rx/rx.h | 3 +-
gcc/config/rx/rx.opt | 6 ++++
4 files changed, 73 insertions(+), 2 deletions(-)
diff --git a/gcc/config/rx/linux.h b/gcc/config/rx/linux.h
index 9ee484af886..2a5eb262d07 100644
--- a/gcc/config/rx/linux.h
+++ b/gcc/config/rx/linux.h
@@ -45,6 +45,11 @@
if (ALLOW_RX_FPU_INSNS) \
builtin_define ("__RX_FPU_INSNS__"); \
\
+ if (TARGET_FDPIC) \
+ { \
+ builtin_define ("__FDPIC__"); \
+ builtin_define ("__RX_FDPIC__"); \
+ } \
} \
while (0)
@@ -52,6 +57,12 @@
#define CC1_SPEC "\
%{mcpu=rx200:%{fpu:%erx200 cpu does not have FPU hardware}}"
+#undef STARTFILE_SPEC
+#define STARTFILE_SPEC "%{mfdpic:crtreloc.o%s} %{!shared: crt1.o%s} crti.o%s "
+
+#undef ENDFILE_SPEC
+#define ENDFILE_SPEC "crtn.o%s"
+
#undef ASM_SPEC
#define ASM_SPEC "\
%{mbig-endian-data:-mbig-endian-data} \
@@ -59,8 +70,25 @@
%{!m64bit-doubles:-m32bit-doubles} \
%{msmall-data-limit*:-msmall-data-limit} \
%{mrelax:-relax} \
+%{mfdpic:--fdpic} \
+"
+
+#undef LIB_SPEC
+#define LIB_SPEC " \
+--start-group \
+-lc \
+--end-group \
"
+#undef LINK_SPEC
+#define LINK_SPEC \
+ "%{!shared: %{!static: \
+ %{rdynamic:-export-dynamic} \
+ %{!dynamic-linker:-dynamic-linker " UCLIBC_DYNAMIC_LINKER "}} \
+ %{static}} \
+ %{mfdpic:%{!shared:-pie}} \
+ %{shared:-shared}"
+
#undef DATA_SECTION_ASM_OP
#define DATA_SECTION_ASM_OP \
"\t.section .data,\"aw\",@progbits\n\t.p2align 2"
@@ -226,6 +254,36 @@
while (0)
#undef PREFERRED_DEBUGGING_TYPE
+#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
#undef TARGET_AS100_SYNTAX
#define TARGET_AS100_SYNTAX 0
+
+#define PIC_REG 13
+#define GOT_SYMBOL_NAME "*_GLOBAL_OFFSET_TABLE_"
+
+/* Register to hold the addressing base for position independent
+ code access to data items. */
+#define PIC_OFFSET_TABLE_REGNUM (flag_pic ? PIC_REG : INVALID_REGNUM)
+
+/* For FDPIC, the FDPIC register is call-clobbered (otherwise PLT
+ entries would need to handle saving and restoring it). */
+#define PIC_OFFSET_TABLE_REG_CALL_CLOBBERED TARGET_FDPIC
+
+#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+
+#define NO_FUNCTION_CSE (flag_pic)
+
+/* Position Independent Code. */
+
+/* We can't directly access anything that contains a symbol,
+ nor can we indirect via the constant pool. */
+#define LEGITIMATE_PIC_OPERAND_P(X) \
+ rx_legitimate_pic_operand_p (X)
+
+#define SYMBOLIC_CONST_P(X) \
+((GET_CODE (X) == SYMBOL_REF || GET_CODE (X) == LABEL_REF) \
+ && nonpic_symbol_mentioned_p (X))
+
+#define EPILOGUE_USES(REGNO) \
+ (TARGET_FDPIC ? ((REGNO) == PIC_OFFSET_TABLE_REGNUM) : 0)
diff --git a/gcc/config/rx/rx-protos.h b/gcc/config/rx/rx-protos.h
index 5a36ef26948..1a8926fb0db 100644
--- a/gcc/config/rx/rx-protos.h
+++ b/gcc/config/rx/rx-protos.h
@@ -58,7 +58,7 @@ extern bool rx_is_legitimate_constant
(machine_mode, rtx);
extern bool rx_is_restricted_memory_address (rtx,
machine_mode);
extern bool rx_match_ccmode (rtx, machine_mode);
-extern rtx rx_maybe_pidify_operand (rtx, int);
+extern rtx rx_maybe_legitimize_pi_operand (rtx, int);
extern void rx_notice_update_cc (rtx, rtx);
extern void rx_split_cbranch (machine_mode, enum rtx_code,
rtx, rtx, rtx);
@@ -173,4 +173,10 @@ rx_find_use_of_reg (rtx reg, rtx_insn* insn, F stepfunc)
#endif
+bool nonpic_symbol_mentioned_p (rtx x);
+bool rx_legitimate_pic_operand_p (rtx x);
+rtx rx_get_fdpic_reg_initial_val (void);
+bool rx_is_unspec_offset (rtx x);
+bool rx_expand_pcrel (rtx operands[], int sidx);
+
#endif /* GCC_RX_PROTOS_H */
diff --git a/gcc/config/rx/rx.h b/gcc/config/rx/rx.h
index f78c103fcb2..8b18d675702 100644
--- a/gcc/config/rx/rx.h
+++ b/gcc/config/rx/rx.h
@@ -119,7 +119,8 @@
"
#undef LINK_SPEC
-#define LINK_SPEC "%{mbig-endian-data:--oformat elf32-rx-be} %{mrelax:-relax}"
+#define LINK_SPEC "%{mbig-endian-data:--oformat elf32-rx-be} \
+ %{mrelax:-relax} %{shared:-shared}"
#define BITS_BIG_ENDIAN 0
diff --git a/gcc/config/rx/rx.opt b/gcc/config/rx/rx.opt
index 5caad487389..0d2e31056b2 100644
--- a/gcc/config/rx/rx.opt
+++ b/gcc/config/rx/rx.opt
@@ -143,3 +143,9 @@ Enables or disables the use of the SMOVF, SMOVB, SMOVU,
SUNTIL, SWHILE and RMPA
mjsr
Target Mask(JSR)
Always use JSR, never BSR, for calls.
+
+;---------------------------------------------------
+
+mfdpic
+Target Var(TARGET_FDPIC) Init(0)
+Generate ELF FDPIC code.
--
2.47.3