Skip to contentSkip to conversation

OpenRISC GCC Fixes for Glibc Support

PATCH Superseded Stafford Horne 1 participant 6 messages May 19, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover OpenRISC GCC Fixes for Glibc Support

Hello,

I am currently working on the glibc port for OpenRISC. This is a series of patches that fix issues and add features that were missing in GCC causing glibc testsuite failures.

Pretty much all of these changes are just adding macros.

These changes have been tested via the glibc test suite.

-Stafford

Stafford Horne (5):
or1k: Implement profile hook calling _mcount
or1k: Add builtin define to detect hard float
or1k: Support for softfloat to emulate hw exceptions
or1k: Add note to indicate execstack
or1k: Fixup exception header data encodings

 gcc/config/or1k/linux.h          |  2 ++
 gcc/config/or1k/or1k.h           | 21 ++++++++++++++--
 libgcc/config/or1k/sfp-machine.h | 41 +++++++++++++++++++++++++++++++-
 3 files changed, 61 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/5 or1k: Implement profile hook calling _mcount

Defining this to not abort as found when working on running tests in the glibc test suite.

We implement this with a call to _mcount with no arguments. The required return address's will be pulled from the stack. Passing the LR (r9) as an argument had problems as sometimes r9 is clobbered by the GOT logic in the prologue before the call to _mcount.

gcc/ChangeLog:

* config/or1k/or1k.h (NO_PROFILE_COUNTERS): Define as 1. (PROFILE_HOOK): Define to call _mcount. (FUNCTION_PROFILER): Change from abort to no-op.

---
 gcc/config/or1k/or1k.h | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
gcc/config/or1k/or1k.h +13 -2
index 23db771d8fb..be089900fd4 100644
@@ -379,8 +379,19 @@ do {                                                    \
 /* Always pass the SYMBOL_REF for direct calls to the expanders.  */
 #define NO_FUNCTION_CSE 1
 
-/* Profiling */
-#define FUNCTION_PROFILER(FILE,LABELNO) (abort (), 0)
+#define NO_PROFILE_COUNTERS 1
+
+/* Emit rtl for profiling.  Output assembler code to call "_mcount" for
+   profiling a function entry.  */
+#define PROFILE_HOOK(LABEL)						\
+  {									\
+    rtx fun;								\
+    fun = gen_rtx_SYMBOL_REF (Pmode, "_mcount");			\
+    emit_library_call (fun, LCT_NORMAL, VOIDmode);			\
+  }
+
+/* All the work is done in PROFILE_HOOK, but this is still required.  */
+#define FUNCTION_PROFILER(STREAM, LABELNO) do { } while (0)
 
 /* Dwarf 2 Support */
 #define DWARF2_DEBUGGING_INFO 1
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/5 or1k: Add builtin define to detect hard float

In reply to Stafford Horne

This is used in libgcc and now glibc to detect when hardware floating point operations are supported by the target.

gcc/ChangeLog:

	* config/or1k/or1k.h (TARGET_CPU_CPP_BUILTINS): Add builtin
	  define for __or1k_hard_float__.
---
 gcc/config/or1k/or1k.h | 2 ++
 1 file changed, 2 insertions(+)
gcc/config/or1k/or1k.h +2 -0
index be089900fd4..0d6fed5f4ca 100644
@@ -30,6 +30,8 @@
       builtin_define ("__or1k__");		\
       if (TARGET_CMOV)				\
 	builtin_define ("__or1k_cmov__");	\
+      if (TARGET_HARD_FLOAT)			\
+	builtin_define ("__or1k_hard_float__");	\
       builtin_assert ("cpu=or1k");		\
       builtin_assert ("machine=or1k");		\
     }						\
Signature · 1 line
2.26.2
#3 lore raw

PATCH 3/5 or1k: Support for softfloat to emulate hw exceptions

In reply to Stafford Horne

This allows the openrisc softfloat implementation to set exceptions. This also sets the correct tininess after rounding value to be consistent with hardware and simulator implementations.

libgcc/ChangeLog:

* config/or1k/sfp-machine.h (FP_RND_NEAREST, FP_RND_ZERO, FP_RND_PINF, FP_RND_MINF, FP_RND_MASK, FP_EX_OVERFLOW, FP_EX_UNDERFLOW, FP_EX_INEXACT, FP_EX_INVALID, FP_EX_DIVZERO, FP_EX_ALL): New constant macros.
(_FP_DECL_EX, FP_ROUNDMODE, FP_INIT_ROUNDMODE, FP_HANDLE_EXCEPTIONS): New macros. (_FP_TININESS_AFTER_ROUNDING): Change to 1.

---
 libgcc/config/or1k/sfp-machine.h | 41 +++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)
libgcc/config/or1k/sfp-machine.h +40 -1
index 5da9e84990d..eebe5b0578e 100644
@@ -41,12 +41,51 @@
     R##_c = FP_CLS_NAN;						\
   } while (0)
 
+/* Handle getting and setting rounding mode for soft fp operations.  */
+
+#define FP_RND_NEAREST		(0x0 << 1)
+#define FP_RND_ZERO		(0x1 << 1)
+#define FP_RND_PINF		(0x2 << 1)
+#define FP_RND_MINF		(0x3 << 1)
+#define FP_RND_MASK		(0x3 << 1)
+
+#define FP_EX_OVERFLOW		1 << 3
+#define FP_EX_UNDERFLOW		1 << 4
+#define FP_EX_INEXACT		1 << 8
+#define FP_EX_INVALID		1 << 9
+#define FP_EX_DIVZERO		1 << 11
+#define FP_EX_ALL \
+	(FP_EX_INVALID | FP_EX_DIVZERO | FP_EX_OVERFLOW | FP_EX_UNDERFLOW \
+	 | FP_EX_INEXACT)
+
+#define _FP_DECL_EX \
+  unsigned int _fpcsr __attribute__ ((unused)) = FP_RND_NEAREST
+
+#define FP_ROUNDMODE (_fpcsr & FP_RND_MASK)
+
+#ifdef __or1k_hard_float__
+#define FP_INIT_ROUNDMODE					\
+do {								\
+  __asm__ volatile ("l.mfspr %0,r0,20" : "=r" (_fpcsr));	\
+} while (0)
+
+#define FP_HANDLE_EXCEPTIONS					\
+do {								\
+  if (__builtin_expect (_fex, 0))				\
+    {								\
+      _fpcsr &= ~FP_EX_ALL;					\
+      _fpcsr |= _fex;						\
+      __asm__ volatile ("l.mtspr r0,%0,20" : : "r" (_fpcsr));	\
+    }								\
+} while (0)
+#endif
+
 #define	__LITTLE_ENDIAN	1234
 #define	__BIG_ENDIAN	4321
 
 #define __BYTE_ORDER __BIG_ENDIAN
 
-#define _FP_TININESS_AFTER_ROUNDING 0
+#define _FP_TININESS_AFTER_ROUNDING 1
 
 /* Define ALIASNAME as a strong alias for NAME.  */
 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
Signature · 1 line
2.26.2
#4 lore raw

PATCH 4/5 or1k: Add note to indicate execstack

In reply to Stafford Horne

Define TARGET_ASM_FILE_END as file_end_indicate_exec_stack to allow generation of the ".note.GNU-stack" section note. This allows binutils to properly set PT_GNU_STACK in the program header.

This fixes a glibc execstack testsuite test failure found while working on the OpenRISC glibc port.

gcc/ChangeLog:

* config/or1k/linux.h (TARGET_ASM_FILE_END): Define macro.

---
 gcc/config/or1k/linux.h | 2 ++
 1 file changed, 2 insertions(+)
gcc/config/or1k/linux.h +2 -0
index 21cef067dda..8693e884e2a 100644
@@ -42,4 +42,6 @@
      %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \
    %{static-pie:-Bstatic -pie --no-dynamic-linker -z text}"
 
+#define TARGET_ASM_FILE_END file_end_indicate_exec_stack
+
 #endif /* GCC_OR1K_LINUX_H */
Signature · 1 line
2.26.2
#5 lore raw

PATCH 5/5 or1k: Fixup exception header data encodings

In reply to Stafford Horne

While running glibc tests several *-textrel tests failed showing that relocations remained against read only sections. It turned out this was related to exception headers data encoding being wrong.

By default pointer encoding will always use the DW_EH_PE_absptr format.

This patch uses format DW_EH_PE_pcrel and DW_EH_PE_sdata4. Optionally DW_EH_PE_indirect is included for global symbols. This eliminates the relocations.

gcc/ChangeLog:

* config/or1k/or1k.h (ASM_PREFERRED_EH_DATA_FORMAT): New macro.

---
 gcc/config/or1k/or1k.h | 4 ++++
 1 file changed, 4 insertions(+)
gcc/config/or1k/or1k.h +4 -0
index 0d6fed5f4ca..2fe62f0b90c 100644
@@ -408,4 +408,8 @@ do {                                                    \
     ((N) < 4 ? HW_TO_GCC_REGNO (25) + (N) : INVALID_REGNUM)
 #define EH_RETURN_STACKADJ_RTX gen_rtx_REG (Pmode, EH_RETURN_REGNUM)
 
+/* Select a format to encode pointers in exception handling data.  */
+#define ASM_PREFERRED_EH_DATA_FORMAT(CODE, GLOBAL) \
+  (((GLOBAL) ? DW_EH_PE_indirect : 0) | DW_EH_PE_pcrel | DW_EH_PE_sdata4)
+
 #endif /* GCC_OR1K_H */
Signature · 1 line
2.26.2