All of lore.kernel.org
 help / color / mirror / Atom feed
* [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support
@ 2020-05-19 20:37 Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 1/5] or1k: Implement profile hook calling _mcount Stafford Horne
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Stafford Horne @ 2020-05-19 20:37 UTC (permalink / raw)
  To: openrisc

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(-)

-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [OpenRISC] [PATCH 1/5] or1k: Implement profile hook calling _mcount
  2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
@ 2020-05-19 20:37 ` Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 2/5] or1k: Add builtin define to detect hard float Stafford Horne
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stafford Horne @ 2020-05-19 20:37 UTC (permalink / raw)
  To: openrisc

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(-)

diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index 23db771d8fb..be089900fd4 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -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
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [OpenRISC] [PATCH 2/5] or1k: Add builtin define to detect hard float
  2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 1/5] or1k: Implement profile hook calling _mcount Stafford Horne
@ 2020-05-19 20:37 ` Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 3/5] or1k: Support for softfloat to emulate hw exceptions Stafford Horne
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Stafford Horne @ 2020-05-19 20:37 UTC (permalink / raw)
  To: openrisc

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(+)

diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index be089900fd4..0d6fed5f4ca 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -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");		\
     }						\
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [OpenRISC] [PATCH 3/5] or1k: Support for softfloat to emulate hw exceptions
  2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 1/5] or1k: Implement profile hook calling _mcount Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 2/5] or1k: Add builtin define to detect hard float Stafford Horne
@ 2020-05-19 20:37 ` Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 4/5] or1k: Add note to indicate execstack Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 5/5] or1k: Fixup exception header data encodings Stafford Horne
  4 siblings, 0 replies; 6+ messages in thread
From: Stafford Horne @ 2020-05-19 20:37 UTC (permalink / raw)
  To: openrisc

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(-)

diff --git a/libgcc/config/or1k/sfp-machine.h b/libgcc/config/or1k/sfp-machine.h
index 5da9e84990d..eebe5b0578e 100644
--- a/libgcc/config/or1k/sfp-machine.h
+++ b/libgcc/config/or1k/sfp-machine.h
@@ -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)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [OpenRISC] [PATCH 4/5] or1k: Add note to indicate execstack
  2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
                   ` (2 preceding siblings ...)
  2020-05-19 20:37 ` [OpenRISC] [PATCH 3/5] or1k: Support for softfloat to emulate hw exceptions Stafford Horne
@ 2020-05-19 20:37 ` Stafford Horne
  2020-05-19 20:37 ` [OpenRISC] [PATCH 5/5] or1k: Fixup exception header data encodings Stafford Horne
  4 siblings, 0 replies; 6+ messages in thread
From: Stafford Horne @ 2020-05-19 20:37 UTC (permalink / raw)
  To: openrisc

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(+)

diff --git a/gcc/config/or1k/linux.h b/gcc/config/or1k/linux.h
index 21cef067dda..8693e884e2a 100644
--- a/gcc/config/or1k/linux.h
+++ b/gcc/config/or1k/linux.h
@@ -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 */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [OpenRISC] [PATCH 5/5] or1k: Fixup exception header data encodings
  2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
                   ` (3 preceding siblings ...)
  2020-05-19 20:37 ` [OpenRISC] [PATCH 4/5] or1k: Add note to indicate execstack Stafford Horne
@ 2020-05-19 20:37 ` Stafford Horne
  4 siblings, 0 replies; 6+ messages in thread
From: Stafford Horne @ 2020-05-19 20:37 UTC (permalink / raw)
  To: openrisc

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(+)

diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index 0d6fed5f4ca..2fe62f0b90c 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -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 */
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-19 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 20:37 [OpenRISC] [PATCH 0/5] OpenRISC GCC Fixes for Glibc Support Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 1/5] or1k: Implement profile hook calling _mcount Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 2/5] or1k: Add builtin define to detect hard float Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 3/5] or1k: Support for softfloat to emulate hw exceptions Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 4/5] or1k: Add note to indicate execstack Stafford Horne
2020-05-19 20:37 ` [OpenRISC] [PATCH 5/5] or1k: Fixup exception header data encodings Stafford Horne

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.