This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] RISC-V: Disable -msave-restore for shared libraries.


This was noticed while trying to test -msave-restore support.  The
save/restore routines use the alternate return register t0/x5 which is
clobbered by the PLT header, so we can't use them in shared libraries.
This patch disables -msave-restore when -fpic (and -mplt), and emits a
warning if the user explicitly turned on -msave-restore.

Tested with a riscv64-linux cross compiler build and make check with the
option -msave-restore hardwired on.  There are thousands of failures without
the patch.  With the patch I get a reasonable number of failures.  Also
tested by hand to verify I get the warning when the user specifies the option.

Committed.

Jim

	gcc/
	* config/riscv/riscv.c (riscv_option_override): If -msave-restore
	and -fpic and -mplt then disable -msave-restore and warn.
---
 gcc/config/riscv/riscv.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 9b16a1eb9c2..1e7528f1cb9 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -4636,6 +4636,16 @@ riscv_option_override (void)
     error ("%<-mriscv-attribute%> RISC-V ELF attribute requires GNU as 2.32"
 	   " [%<-mriscv-attribute%>]");
 #endif
+
+  /* The save-restore routines use t0 which is clobbered by the plt header,
+     so we can't use them when building shared libraries.  */
+  if (TARGET_SAVE_RESTORE && flag_pic && TARGET_PLT)
+    {
+      target_flags &= ~MASK_SAVE_RESTORE;
+      if (target_flags_explicit & MASK_SAVE_RESTORE)
+	warning (0, "%<-msave-restore%> disabled; not supported with PLT "
+		 "based shared libraries");
+    }
 }
 
 /* Implement TARGET_CONDITIONAL_REGISTER_USAGE.  */
-- 
2.17.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]