Re: [PATCH] or1k: Do not clear existing FPU exceptions before updating

2023-03-18 Thread Stafford Horne via Gcc-patches
Hello,

I pushed this upstream.

On Sat, Mar 18, 2023 at 05:04:05PM +0900, Stafford Horne wrote:
> We should always carry the exceptions forward.  This bug was found when
> working on testing glibc math tests, many tests were failing with
> Overflow and Underflow flags not set.  This was traced to here.
> 
> libgcc/ChangeLog:
> 
>   * config/or1k/sfp-machine.h (FP_HANDLE_EXCEPTIONS): Remove
>   statement clearing existing exceptions.
> ---
>  libgcc/config/or1k/sfp-machine.h | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/libgcc/config/or1k/sfp-machine.h 
> b/libgcc/config/or1k/sfp-machine.h
> index 162c6bc5326..c804270fb3c 100644
> --- a/libgcc/config/or1k/sfp-machine.h
> +++ b/libgcc/config/or1k/sfp-machine.h
> @@ -73,7 +73,6 @@ do {
> \
>  do { \
>if (__builtin_expect (_fex, 0))\
>  {\
> -  _fpcsr &= ~FP_EX_ALL;  \
>_fpcsr |= _fex;\
>__asm__ volatile ("l.mtspr r0,%0,20" : : "r" (_fpcsr));\
>  }\
> -- 
> 2.39.1
> 


[PATCH] or1k: Do not clear existing FPU exceptions before updating

2023-03-18 Thread Stafford Horne via Gcc-patches
We should always carry the exceptions forward.  This bug was found when
working on testing glibc math tests, many tests were failing with
Overflow and Underflow flags not set.  This was traced to here.

libgcc/ChangeLog:

* config/or1k/sfp-machine.h (FP_HANDLE_EXCEPTIONS): Remove
statement clearing existing exceptions.
---
 libgcc/config/or1k/sfp-machine.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libgcc/config/or1k/sfp-machine.h b/libgcc/config/or1k/sfp-machine.h
index 162c6bc5326..c804270fb3c 100644
--- a/libgcc/config/or1k/sfp-machine.h
+++ b/libgcc/config/or1k/sfp-machine.h
@@ -73,7 +73,6 @@ do {  
\
 do {   \
   if (__builtin_expect (_fex, 0))  \
 {  \
-  _fpcsr &= ~FP_EX_ALL;\
   _fpcsr |= _fex;  \
   __asm__ volatile ("l.mtspr r0,%0,20" : : "r" (_fpcsr));  \
 }  \
-- 
2.39.1



Re: [PATCH] or1k: Only define TARGET_HAVE_TLS when HAVE_AS_TLS

2022-10-01 Thread Stafford Horne via Gcc-patches
On Thu, Sep 29, 2022 at 03:57:40PM +0100, Stafford Horne wrote:
> This was found when testing buildroot with linuxthreads enabled.  In
> this case, the build passes --disable-tls to the toolchain during
> configuration.  After building the OpenRISC toolchain it was still
> generating TLS code sequences and causing linker failures such as:
> 
>  /or1k-buildroot-linux-uclibc-gcc -o gpsd-3.24/gpsctl  -lusb-1.0 -lm 
> -lrt -lnsl
>  /ld: /sysroot/usr/lib/libusb-1.0.so: undefined reference to 
> `__tls_get_addr'
> 
> This patch fixes this by disabling tls for the OpenRISC target when requested
> via --disable-tls.
> 
> Tested-by: Yann E. MORIN 
> 
> gcc/ChangeLog:
> 
>   * config/or1k/or1k.cc (TARGET_HAVE_TLS): Only define if
>   HAVE_AS_TLS is defined.

I have pushed this upstream now.  Adding buildroot patches should be easy to do
now.

-Stafford


[PATCH] or1k: Only define TARGET_HAVE_TLS when HAVE_AS_TLS

2022-09-29 Thread Stafford Horne via Gcc-patches
This was found when testing buildroot with linuxthreads enabled.  In
this case, the build passes --disable-tls to the toolchain during
configuration.  After building the OpenRISC toolchain it was still
generating TLS code sequences and causing linker failures such as:

 /or1k-buildroot-linux-uclibc-gcc -o gpsd-3.24/gpsctl  -lusb-1.0 -lm 
-lrt -lnsl
 /ld: /sysroot/usr/lib/libusb-1.0.so: undefined reference to 
`__tls_get_addr'

This patch fixes this by disabling tls for the OpenRISC target when requested
via --disable-tls.

Tested-by: Yann E. MORIN 

gcc/ChangeLog:

* config/or1k/or1k.cc (TARGET_HAVE_TLS): Only define if
HAVE_AS_TLS is defined.
---
 gcc/config/or1k/or1k.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/gcc/config/or1k/or1k.cc b/gcc/config/or1k/or1k.cc
index da2f59062ba..0ce7b234417 100644
--- a/gcc/config/or1k/or1k.cc
+++ b/gcc/config/or1k/or1k.cc
@@ -2206,8 +2206,10 @@ or1k_output_mi_thunk (FILE *file, tree thunk_fndecl,
 #undef  TARGET_LEGITIMATE_ADDRESS_P
 #define TARGET_LEGITIMATE_ADDRESS_P or1k_legitimate_address_p
 
+#ifdef HAVE_AS_TLS
 #undef  TARGET_HAVE_TLS
 #define TARGET_HAVE_TLS true
+#endif
 
 #undef  TARGET_HAVE_SPECULATION_SAFE_VALUE
 #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
-- 
2.37.2



Re: [PATCH] or1k: Add support for a little-endian target variant

2022-06-09 Thread Stafford Horne via Gcc-patches
> diff --git a/gcc/config.gcc b/gcc/config.gcc
> index c5064dd37666..0c3a09dfe810 100644
> --- a/gcc/config.gcc
> +++ b/gcc/config.gcc
> @@ -2866,6 +2866,11 @@ or1k*-*-*)
>   done
>   TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
>  
> + case ${target} in
> + or1k*le*-*)

Should this be just or1kle*-*?

> + tm_defines="${tm_defines} TARGET_LITTLE_ENDIAN_DEFAULT=1"
> + ;;
> + esac
>   case ${target} in
>   or1k*-*-linux*)
>   tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h"


> diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
> index 8a66832a99b1..497f259faae9 100644
> --- a/gcc/config/or1k/or1k.opt
> +++ b/gcc/config/or1k/or1k.opt
> @@ -24,6 +24,14 @@
>  HeaderInclude
>  config/or1k/or1k-opts.h
>  
> +mbig-endian
> +Target Report RejectNegative Mask(BIG_ENDIAN)
> +Use big-endian byte order.
> +
> +mlittle-endian
> +Target Report RejectNegative InverseMask(BIG_ENDIAN, LITTLE_ENDIAN)
> +Use little-endian byte order.
> +

We should explain what is the default int he doc's.

Can you also document in: gcc/doc/invoke.texi

This looks good, thank you.

-Stafford


[PATCH] gcc: define _REENTRANT for OpenRISC when -pthread is passed

2022-01-31 Thread Stafford Horne via Gcc-patches
From: Bernd Kuhls 

The detection of pthread support fails on OpenRISC unless _REENTRANT
is defined. Added the CPP_SPEC definition to correct this.

gcc/ChangeLog:

PR target/94372
* config/or1k/linux.h (CPP_SPEC): Define.

Signed-off-by: Bernd Kuhls 
---
This was brought up on the buildroot list and somehow I missed it.  Sending it
now.  I plan to commit soon.

 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 52909af41a6..80f77c72232 100644
--- a/gcc/config/or1k/linux.h
+++ b/gcc/config/or1k/linux.h
@@ -32,6 +32,8 @@
 #undef MUSL_DYNAMIC_LINKER
 #define MUSL_DYNAMIC_LINKER  "/lib/ld-musl-or1k.so.1"
 
+#define CPP_SPEC "%{pthread:-D_REENTRANT}"
+
 #undef LINK_SPEC
 #define LINK_SPEC "%{h*}   \
%{static:-Bstatic}  \
-- 
2.31.1



Re: [RFC PATCH] or1k: Fix clobbering of _mcount argument if fPIC is enabled

2021-11-12 Thread Stafford Horne via Gcc-patches
I have committed this as is.

-Stafford

On Tue, Nov 09, 2021 at 09:13:08PM +0900, Stafford Horne wrote:
> Recently we changed the PROFILE_HOOK _mcount call to pass in the link
> register as an argument.  This actually does not work when the _mcount
> call uses a PLT because the GOT register setup code ends up getting
> inserted before the PROFILE_HOOK and clobbers the link register
> argument.
> 
> These glibc tests are failing:
>   gmon/tst-gmon-pie-gprof
>   gmon/tst-gmon-static-gprof
> 
> This patch fixes this by saving the instruction that stores the Link
> Register to the _mcount argument and then inserts the GOT register setup
> instructions after that.
> 
> For example:
> 
> main.c:
> 
> extern int e;
> 
> int f2(int a) {
>   return a + e;
> }
> 
> int f1(int a) {
>   return f2 (a + a);
> }
> 
> int main(int argc, char ** argv) {
>   return f1 (argc);
> }
> 
> Compiled:
> 
> or1k-smh-linux-gnu-gcc -Wall -c -O2 -fPIC -pg -S main.c
> 
> Before Fix:
> 
> main:
> l.addi  r1, r1, -16
> l.sw8(r1), r2
> l.sw0(r1), r16
> l.addi  r2, r1, 16   # Keeping FP, but not needed
> l.sw4(r1), r18
> l.sw12(r1), r9
> l.jal   8# GOT Setup clobbers r9 (Link Register)
>  l.movhir16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
> l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
> l.add   r16, r16, r9
> l.orr18, r3, r3
> l.orr3, r9, r9# This is not the original LR
> l.jal   plt(_mcount)
>  l.nop
> 
> l.jal   plt(f1)
>  l.orr3, r18, r18
> l.lwz   r9, 12(r1)
> l.lwz   r16, 0(r1)
> l.lwz   r18, 4(r1)
> l.lwz   r2, 8(r1)
> l.jrr9
>  l.addi  r1, r1, 16
> 
> After the fix:
> 
> main:
> l.addi  r1, r1, -12
> l.sw0(r1), r16
> l.sw4(r1), r18
> l.sw8(r1), r9
> l.orr18, r3, r3
> l.orr3, r9, r9# We now have r9 (LR) set early
> l.jal   8 # Clobbers r9 (Link Register)
>  l.movhir16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
> l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
> l.add   r16, r16, r9
> l.jal   plt(_mcount)
>  l.nop
> 
> l.jal   plt(f1)
>  l.orr3, r18, r18
> l.lwz   r9, 8(r1)
> l.lwz   r16, 0(r1)
> l.lwz   r18, 4(r1)
> l.jrr9
>  l.addi  r1, r1, 12
> 
> Fixes: 308531d148a ("or1k: Add return address argument to _mcount call")
> 
> gcc/ChangeLog:
>   * config/or1k/or1k-protos.h (or1k_profile_hook): New function.
>   * config/or1k/or1k.h (PROFILE_HOOK): Change macro to reference
>   new function or1k_profile_hook.
>   * config/or1k/or1k.c (struct machine_function): Add new field
>   set_mcount_arg_insn.
>   (or1k_profile_hook): New function.
>   (or1k_init_pic_reg): Update to inject pic rtx after _mcount arg
>   when profiling.
>   (or1k_frame_pointer_required): Frame pointer no longer needed
>   when profiling.
> ---
> I am sending this as RFC as I think there should be a better way to handle
> this but I am not sure how that would be.
> 
> An earlier patch I tried was to store the link register to a temporary 
> register
> then pass the temporary register as an argument to _mcount, however
> optimizations caused the link register to still get clobbered.
> 
> Any thoughts will be helpful.
> 
> -Stafford
> 
>  gcc/config/or1k/or1k-protos.h |  1 +
>  gcc/config/or1k/or1k.c| 49 ---
>  gcc/config/or1k/or1k.h|  8 +-
>  3 files changed, 42 insertions(+), 16 deletions(-)
> 
> diff --git a/gcc/config/or1k/or1k-protos.h b/gcc/config/or1k/or1k-protos.h
> index bbb54c8f790..56554f2937f 100644
> --- a/gcc/config/or1k/or1k-protos.h
> +++ b/gcc/config/or1k/or1k-protos.h
> @@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
>  extern HOST_WIDE_INT or1k_initial_elimination_offset (int, int);
>  extern void or1k_expand_prologue (void);
>  extern void or1k_expand_epilogue (void);
> +extern void or1k_profile_hook (void);
>  extern void or1k_expand_eh_return (rtx);
>  extern rtx  or1k_initial_frame_addr (void);
>  extern rtx  or1k_dynamic_chain_addr (rtx);
> diff --git a/gcc/config/or1k/or1k.c b/gcc/config/or1k/or1k.c
> index e772a7addea..335c4c5decf 100644
> --- a/gcc/config/or1k/or1k.c
> +++ b/gcc/config/or1k/or1k.c
> @@ -73,6 +73,10 @@ struct GTY(()) machine_function
>  
>/* Remember where the set_got_placeholder is located.  */
>rtx_insn *set_got_insn;
> +
> +  /* Remember where mcount args are stored so we can insert set_got_insn
> + after.  */
> +  rtx_insn *set_mcount_arg_insn;
>  };
>  
>  /* Zero initialization is OK for all current fields.  */
> @@ -415,6 +419,25 @@ or1k_expand_epilogue (void)
>  EH_RETURN_STACKADJ_RTX));
>  }
>  
> 

[RFC PATCH] or1k: Fix clobbering of _mcount argument if fPIC is enabled

2021-11-09 Thread Stafford Horne via Gcc-patches
Recently we changed the PROFILE_HOOK _mcount call to pass in the link
register as an argument.  This actually does not work when the _mcount
call uses a PLT because the GOT register setup code ends up getting
inserted before the PROFILE_HOOK and clobbers the link register
argument.

These glibc tests are failing:
  gmon/tst-gmon-pie-gprof
  gmon/tst-gmon-static-gprof

This patch fixes this by saving the instruction that stores the Link
Register to the _mcount argument and then inserts the GOT register setup
instructions after that.

For example:

main.c:

extern int e;

int f2(int a) {
  return a + e;
}

int f1(int a) {
  return f2 (a + a);
}

int main(int argc, char ** argv) {
  return f1 (argc);
}

Compiled:

or1k-smh-linux-gnu-gcc -Wall -c -O2 -fPIC -pg -S main.c

Before Fix:

main:
l.addi  r1, r1, -16
l.sw8(r1), r2
l.sw0(r1), r16
l.addi  r2, r1, 16   # Keeping FP, but not needed
l.sw4(r1), r18
l.sw12(r1), r9
l.jal   8# GOT Setup clobbers r9 (Link Register)
 l.movhir16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
l.add   r16, r16, r9
l.orr18, r3, r3
l.orr3, r9, r9# This is not the original LR
l.jal   plt(_mcount)
 l.nop

l.jal   plt(f1)
 l.orr3, r18, r18
l.lwz   r9, 12(r1)
l.lwz   r16, 0(r1)
l.lwz   r18, 4(r1)
l.lwz   r2, 8(r1)
l.jrr9
 l.addi  r1, r1, 16

After the fix:

main:
l.addi  r1, r1, -12
l.sw0(r1), r16
l.sw4(r1), r18
l.sw8(r1), r9
l.orr18, r3, r3
l.orr3, r9, r9# We now have r9 (LR) set early
l.jal   8 # Clobbers r9 (Link Register)
 l.movhir16, gotpchi(_GLOBAL_OFFSET_TABLE_-4)
l.ori   r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0)
l.add   r16, r16, r9
l.jal   plt(_mcount)
 l.nop

l.jal   plt(f1)
 l.orr3, r18, r18
l.lwz   r9, 8(r1)
l.lwz   r16, 0(r1)
l.lwz   r18, 4(r1)
l.jrr9
 l.addi  r1, r1, 12

Fixes: 308531d148a ("or1k: Add return address argument to _mcount call")

gcc/ChangeLog:
* config/or1k/or1k-protos.h (or1k_profile_hook): New function.
* config/or1k/or1k.h (PROFILE_HOOK): Change macro to reference
new function or1k_profile_hook.
* config/or1k/or1k.c (struct machine_function): Add new field
set_mcount_arg_insn.
(or1k_profile_hook): New function.
(or1k_init_pic_reg): Update to inject pic rtx after _mcount arg
when profiling.
(or1k_frame_pointer_required): Frame pointer no longer needed
when profiling.
---
I am sending this as RFC as I think there should be a better way to handle
this but I am not sure how that would be.

An earlier patch I tried was to store the link register to a temporary register
then pass the temporary register as an argument to _mcount, however
optimizations caused the link register to still get clobbered.

Any thoughts will be helpful.

-Stafford

 gcc/config/or1k/or1k-protos.h |  1 +
 gcc/config/or1k/or1k.c| 49 ---
 gcc/config/or1k/or1k.h|  8 +-
 3 files changed, 42 insertions(+), 16 deletions(-)

diff --git a/gcc/config/or1k/or1k-protos.h b/gcc/config/or1k/or1k-protos.h
index bbb54c8f790..56554f2937f 100644
--- a/gcc/config/or1k/or1k-protos.h
+++ b/gcc/config/or1k/or1k-protos.h
@@ -20,6 +20,7 @@ along with GCC; see the file COPYING3.  If not see
 extern HOST_WIDE_INT or1k_initial_elimination_offset (int, int);
 extern void or1k_expand_prologue (void);
 extern void or1k_expand_epilogue (void);
+extern void or1k_profile_hook (void);
 extern void or1k_expand_eh_return (rtx);
 extern rtx  or1k_initial_frame_addr (void);
 extern rtx  or1k_dynamic_chain_addr (rtx);
diff --git a/gcc/config/or1k/or1k.c b/gcc/config/or1k/or1k.c
index e772a7addea..335c4c5decf 100644
--- a/gcc/config/or1k/or1k.c
+++ b/gcc/config/or1k/or1k.c
@@ -73,6 +73,10 @@ struct GTY(()) machine_function
 
   /* Remember where the set_got_placeholder is located.  */
   rtx_insn *set_got_insn;
+
+  /* Remember where mcount args are stored so we can insert set_got_insn
+ after.  */
+  rtx_insn *set_mcount_arg_insn;
 };
 
 /* Zero initialization is OK for all current fields.  */
@@ -415,6 +419,25 @@ or1k_expand_epilogue (void)
   EH_RETURN_STACKADJ_RTX));
 }
 
+/* Worker for PROFILE_HOOK.
+   The OpenRISC profile hook uses the link register which will get clobbered by
+   the GOT setup RTX.  This sets up a placeholder to allow injecting of the GOT
+   setup RTX to avoid clobbering.  */
+
+void
+or1k_profile_hook (void)
+{
+  rtx a1 = gen_rtx_REG (Pmode, 3);
+  rtx ra = get_hard_reg_initial_val (Pmode, LR_REGNUM);
+  rtx fun = gen_rtx_SYM

[PATCH] or1k: Add return address argument to _mcount call

2021-10-27 Thread Stafford Horne via Gcc-patches
This fixes an issue in the glibc port I am working on where the build
fails due to the warning:

  error: calling ‘__builtin_return_address’ with a nonzero argument is unsafe 
[-Werror=frame-address]

This is due to how the current implementation of _mcount in glibc uses
__builtin_return_address with a count argument of 1.

Fix that by passing the value of LR_REGNUM to the _mcount function,
effectivtly providing the value _mcount is after.

This is an ABI change, but I think it's OK because the glibc port for
or1k is not yet upstreamed.  Also, I think just adding an argument
should not break anything anyway.

gcc/ChangeLog:

* config/or1k/or1k.h (PROFILE_HOOK): Add return address argument
to _mcount.
---
 gcc/config/or1k/or1k.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index fe01ab81ead..4603cb67160 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -387,9 +387,10 @@ do {\
profiling a function entry.  */
 #define PROFILE_HOOK(LABEL)\
   {\
-rtx fun;   \
+rtx fun, ra;   \
+ra = get_hard_reg_initial_val (Pmode, LR_REGNUM);  \
 fun = gen_rtx_SYMBOL_REF (Pmode, "_mcount");   \
-emit_library_call (fun, LCT_NORMAL, VOIDmode); \
+emit_library_call (fun, LCT_NORMAL, VOIDmode, ra, Pmode);  \
   }
 
 /* All the work is done in PROFILE_HOOK, but this is still required.  */
-- 
2.31.1



[PATCH] or1k: Update FPU to specify detect tininess before rounding

2021-10-21 Thread Stafford Horne via Gcc-patches
This was not defined in the spec and not consistent in the
implementation causing incosistent behavior.  After review we have
updated the CPU implementations and proposed the spec be updated to
specific that FPU tininess checks check for tininess before roudning.

Architecture change draft:

https://openrisc.io/proposals/p18-fpu-tininess

libgcc/ChangeLog:

* config/or1k/sfp-machine.h (_FP_TININESS_AFTER_ROUNDING):
Change to 0.
---
 libgcc/config/or1k/sfp-machine.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libgcc/config/or1k/sfp-machine.h b/libgcc/config/or1k/sfp-machine.h
index eebe5b0578e..162c6bc5326 100644
--- a/libgcc/config/or1k/sfp-machine.h
+++ b/libgcc/config/or1k/sfp-machine.h
@@ -85,7 +85,7 @@ do {  
\
 
 #define __BYTE_ORDER __BIG_ENDIAN
 
-#define _FP_TININESS_AFTER_ROUNDING 1
+#define _FP_TININESS_AFTER_ROUNDING 0
 
 /* Define ALIASNAME as a strong alias for NAME.  */
 # define strong_alias(name, aliasname) _strong_alias(name, aliasname)
-- 
2.31.1



Re: [PATCH v2 0/2] OpenRISC support for cmodel=large

2021-08-14 Thread Stafford Horne via Gcc-patches
On Sun, Aug 15, 2021 at 12:05:37AM +0200, Giulio Benetti wrote:
> On 8/15/21 12:03 AM, Stafford Horne wrote:
> > On Sat, Aug 14, 2021 at 11:01:16PM +0200, Giulio Benetti wrote:
> > > Hi All,
> > > 
> > > On 5/1/21 11:11 PM, Stafford Horne wrote:
> > > > Changes from v1:
> > > >- Added patch to enabled cmodle=large on crtstuff
> > > > 
> > > > This series fixes some bugs found when linking large binaries, both in 
> > > > buildroot
> > > > and glibc testing.
> > > > 
> > > > Stafford Horne (2):
> > > > or1k: Add mcmodel option to handle large GOTs
> > > > or1k: Use cmodel=large when building crtstuff
> > > > 
> > > >gcc/config/or1k/or1k-opts.h   | 30 ++
> > > >gcc/config/or1k/or1k.c| 11 +--
> > > >gcc/config/or1k/or1k.h|  7 +++
> > > >gcc/config/or1k/or1k.opt  | 19 +++
> > > >gcc/doc/invoke.texi   | 12 +++-
> > > >libgcc/config.host|  4 ++--
> > > >libgcc/config/or1k/t-crtstuff |  2 ++
> > > >7 files changed, 80 insertions(+), 5 deletions(-)
> > > >create mode 100644 gcc/config/or1k/or1k-opts.h
> > > >create mode 100644 libgcc/config/or1k/t-crtstuff
> > > > 
> > > 
> > > I've tested this patchset and works as expected.
> > > It fixed libgeos build failure in conjunction with:
> > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3c3de29b048bca6b4aa4235c647b9328e71801b6
> > > 
> > > Hope this helps to commit it upstream since I still don't see it, or am I
> > > wrong?
> > 
> > You are not wrong, I did not push the changed to GCC yet.  I will do soon.
> 
> Ah ok, you're the maintainer :-) I thought there was someone else who needed
> to push it :-)

Yeah, I pushed it now.


Re: [PATCH v2 0/2] OpenRISC support for cmodel=large

2021-08-14 Thread Stafford Horne via Gcc-patches
On Sat, Aug 14, 2021 at 11:01:16PM +0200, Giulio Benetti wrote:
> Hi All,
> 
> On 5/1/21 11:11 PM, Stafford Horne wrote:
> > Changes from v1:
> >   - Added patch to enabled cmodle=large on crtstuff
> > 
> > This series fixes some bugs found when linking large binaries, both in 
> > buildroot
> > and glibc testing.
> > 
> > Stafford Horne (2):
> >or1k: Add mcmodel option to handle large GOTs
> >or1k: Use cmodel=large when building crtstuff
> > 
> >   gcc/config/or1k/or1k-opts.h   | 30 ++
> >   gcc/config/or1k/or1k.c| 11 +--
> >   gcc/config/or1k/or1k.h|  7 +++
> >   gcc/config/or1k/or1k.opt  | 19 +++
> >   gcc/doc/invoke.texi   | 12 +++-
> >   libgcc/config.host|  4 ++--
> >   libgcc/config/or1k/t-crtstuff |  2 ++
> >   7 files changed, 80 insertions(+), 5 deletions(-)
> >   create mode 100644 gcc/config/or1k/or1k-opts.h
> >   create mode 100644 libgcc/config/or1k/t-crtstuff
> > 
> 
> I've tested this patchset and works as expected.
> It fixed libgeos build failure in conjunction with:
> https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3c3de29b048bca6b4aa4235c647b9328e71801b6
> 
> Hope this helps to commit it upstream since I still don't see it, or am I
> wrong?

You are not wrong, I did not push the changed to GCC yet.  I will do soon.

-Stafford


Re: [PATCH v2 0/2] OpenRISC support for cmodel=large

2021-05-04 Thread Stafford Horne via Gcc-patches
On Mon, May 03, 2021 at 12:34:22PM +0200, Giulio Benetti wrote:
> Hi Stafford, All,
> 
> I've backported this patchset for Buildroot to versions:
> - 9.3.0
> - 10.3.0
> 
> Does it make sense to send them? I don't know if those version will have
> minor versions where these backported patches can be applied.

Do you mean for me/you to send the backported GCC patches for GCC or buildroot?

I don't need backported versions of the toolchains and usually work off the
latest release/master.  If someone wants them let me know.

-Stafford

> Best regards
> -- 
> Giulio Benetti
> Benetti Engineering sas
> 
> On 5/1/21 11:11 PM, Stafford Horne wrote:
> > Changes from v1:
> >   - Added patch to enabled cmodle=large on crtstuff
> > 
> > This series fixes some bugs found when linking large binaries, both in 
> > buildroot
> > and glibc testing.
> > 
> > Stafford Horne (2):
> >or1k: Add mcmodel option to handle large GOTs
> >or1k: Use cmodel=large when building crtstuff
> > 
> >   gcc/config/or1k/or1k-opts.h   | 30 ++
> >   gcc/config/or1k/or1k.c| 11 +--
> >   gcc/config/or1k/or1k.h|  7 +++
> >   gcc/config/or1k/or1k.opt  | 19 +++
> >   gcc/doc/invoke.texi   | 12 +++-
> >   libgcc/config.host|  4 ++--
> >   libgcc/config/or1k/t-crtstuff |  2 ++
> >   7 files changed, 80 insertions(+), 5 deletions(-)
> >   create mode 100644 gcc/config/or1k/or1k-opts.h
> >   create mode 100644 libgcc/config/or1k/t-crtstuff
> > 


[PATCH v2 2/2] or1k: Use cmodel=large when building crtstuff

2021-05-01 Thread Stafford Horne via Gcc-patches
When linking gcc runtime objects into large binaries the link may fail
with the below errors.  This will happen even if we are building with
-mcmodel=large.


/home/shorne/work/openrisc/output/host/lib/gcc/or1k-buildroot-linux-uclibc/10.3.0/crtbeginS.o:
 in function `deregister_tm_clones':
crtstuff.c:(.text+0x3c): relocation truncated to fit: R_OR1K_GOT16 against 
undefined symbol `_ITM_deregisterTMCloneTable'

/home/shorne/work/openrisc/output/host/lib/gcc/or1k-buildroot-linux-uclibc/10.3.0/crtbeginS.o:
 in function `register_tm_clones':
crtstuff.c:(.text+0xc0): relocation truncated to fit: R_OR1K_GOT16 against 
undefined symbol `_ITM_registerTMCloneTable'

This patch builds the gcc crtstuff binaries always with the
-mcmodel=large option to ensure they can be linked into large binaries.

libgcc/ChangeLog:

PR 99783
* config.host (or1k-*, tmake_file): Add or1k/t-crtstuff.
* config/or1k/t-crtstuff: New file.
---
 libgcc/config.host| 4 ++--
 libgcc/config/or1k/t-crtstuff | 2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
 create mode 100644 libgcc/config/or1k/t-crtstuff

diff --git a/libgcc/config.host b/libgcc/config.host
index f808b61be70..9e40d4560a3 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1119,12 +1119,12 @@ nios2-*-*)
extra_parts="$extra_parts crti.o crtn.o"
;;
 or1k-*-linux*)
-   tmake_file="$tmake_file or1k/t-or1k"
+   tmake_file="$tmake_file or1k/t-or1k or1k/t-crtstuff"
tmake_file="$tmake_file t-softfp-sfdf t-softfp"
md_unwind_header=or1k/linux-unwind.h
;;
 or1k-*-*)
-   tmake_file="$tmake_file or1k/t-or1k"
+   tmake_file="$tmake_file or1k/t-or1k or1k/t-crtstuff"
tmake_file="$tmake_file t-softfp-sfdf t-softfp"
;;
 pdp11-*-*)
diff --git a/libgcc/config/or1k/t-crtstuff b/libgcc/config/or1k/t-crtstuff
new file mode 100644
index 000..dcae7f3498e
--- /dev/null
+++ b/libgcc/config/or1k/t-crtstuff
@@ -0,0 +1,2 @@
+# Compile crtbeginS.o and crtendS.o with -mcmodel=large
+CRTSTUFF_T_CFLAGS_S += -mcmodel=large
-- 
2.26.2



[PATCH v2 1/2] or1k: Add mcmodel option to handle large GOTs

2021-05-01 Thread Stafford Horne via Gcc-patches
When building libgeos we get an error with:

linux-uclibc/9.3.0/crtbeginS.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x118): relocation truncated to fit: R_OR1K_GOT16 against 
symbol `__cxa_finalize' defined in .text section in

/home/shorne/work/openrisc/3eb9f9d0f6d8274b2d19753c006bd83f7d536e3c/output/host/or1k-buildroot-linux-uclibc/sysroot/lib/libc.so.

This is caused by GOT code having a limit of 64k.  In OpenRISC this
looks to be the only relocation code pattern to be limited to 64k.

This patch allows specifying a new option -mcmodel=large which can be
used to generate 2 more instructions to construct 32-bit addresses for
up to 4G GOTs.

gcc/ChangeLog:

PR 99783
* config/or1k/or1k-opts.h: New file.
* config/or1k/or1k.c (or1k_legitimize_address_1, print_reloc):
Support generating gotha relocations if -mcmodel=large is
specified.
* config/or1k/or1k.h (TARGET_CMODEL_SMALL, TARGET_CMODEL_LARGE):
New macros.
* config/or1k/or1k.opt (mcmodel=): New option.
* doc/invoke.text (OpenRISC Options): Document mcmodel.
---
 gcc/config/or1k/or1k-opts.h | 30 ++
 gcc/config/or1k/or1k.c  | 11 +--
 gcc/config/or1k/or1k.h  |  7 +++
 gcc/config/or1k/or1k.opt| 19 +++
 gcc/doc/invoke.texi | 12 +++-
 5 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 gcc/config/or1k/or1k-opts.h

diff --git a/gcc/config/or1k/or1k-opts.h b/gcc/config/or1k/or1k-opts.h
new file mode 100644
index 000..f791b894fdd
--- /dev/null
+++ b/gcc/config/or1k/or1k-opts.h
@@ -0,0 +1,30 @@
+/* Definitions for option handling for OpenRISC.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   Contributed by Stafford Horne.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   .  */
+
+#ifndef GCC_OR1K_OPTS_H
+#define GCC_OR1K_OPTS_H
+
+/* The OpenRISC code generation models available.  */
+enum or1k_cmodel_type {
+  CMODEL_SMALL,
+  CMODEL_LARGE
+};
+
+#endif /* GCC_OR1K_OPTS_H */
diff --git a/gcc/config/or1k/or1k.c b/gcc/config/or1k/or1k.c
index e772a7addea..27d3fa17995 100644
--- a/gcc/config/or1k/or1k.c
+++ b/gcc/config/or1k/or1k.c
@@ -750,7 +750,14 @@ or1k_legitimize_address_1 (rtx x, rtx scratch)
{
  base = gen_sym_unspec (base, UNSPEC_GOT);
  crtl->uses_pic_offset_table = 1;
- t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
+ if (TARGET_CMODEL_LARGE)
+   {
+ emit_insn (gen_rtx_SET (t1, gen_rtx_HIGH (Pmode, base)));
+ emit_insn (gen_add3_insn (t1, t1, pic_offset_table_rtx));
+ t2 = gen_rtx_LO_SUM (Pmode, t1, base);
+   }
+ else
+   t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
  t2 = gen_const_mem (Pmode, t2);
  emit_insn (gen_rtx_SET (t1, t2));
  base = t1;
@@ -1089,7 +1096,7 @@ print_reloc (FILE *stream, rtx x, HOST_WIDE_INT add, 
reloc_kind kind)
  no special markup.  */
   static const char * const relocs[RKIND_MAX][RTYPE_MAX] = {
 { "lo", "got", "gotofflo", "tpofflo", "gottpofflo", "tlsgdlo" },
-{ "ha", NULL,  "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
+{ "ha", "gotha", "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
   };
   reloc_type type = RTYPE_DIRECT;
 
diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index fe01ab81ead..669907e7e74 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -21,6 +21,8 @@
 #ifndef GCC_OR1K_H
 #define GCC_OR1K_H
 
+#include "config/or1k/or1k-opts.h"
+
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_CPU_CPP_BUILTINS()  \
   do   \
@@ -37,6 +39,11 @@
 }  \
   while (0)
 
+#define TARGET_CMODEL_SMALL \
+  (or1k_code_model == CMODEL_SMALL)
+#define TARGET_CMODEL_LARGE \
+  (or1k_code_model == CMODEL_LARGE)
+
 /* Storage layout.  */
 
 #define DEFAULT_SIGNED_CHAR 1
diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
index 6bd0f3eee6d..cc23e3b8856 100644
--- a/gcc/config/or1k/or1k.opt
+++ b/gcc/config/or1k/or1k.opt
@@ -21,6 +21,9 @@
 ; See the GCC internals manual (options.texi) for a description of
 ; thi

[PATCH v2 0/2] OpenRISC support for cmodel=large

2021-05-01 Thread Stafford Horne via Gcc-patches
Changes from v1:
 - Added patch to enabled cmodle=large on crtstuff

This series fixes some bugs found when linking large binaries, both in buildroot
and glibc testing.

Stafford Horne (2):
  or1k: Add mcmodel option to handle large GOTs
  or1k: Use cmodel=large when building crtstuff

 gcc/config/or1k/or1k-opts.h   | 30 ++
 gcc/config/or1k/or1k.c| 11 +--
 gcc/config/or1k/or1k.h|  7 +++
 gcc/config/or1k/or1k.opt  | 19 +++
 gcc/doc/invoke.texi   | 12 +++-
 libgcc/config.host|  4 ++--
 libgcc/config/or1k/t-crtstuff |  2 ++
 7 files changed, 80 insertions(+), 5 deletions(-)
 create mode 100644 gcc/config/or1k/or1k-opts.h
 create mode 100644 libgcc/config/or1k/t-crtstuff

-- 
2.26.2



Re: [PATCH] or1k: Add mcmodel option to handle large GOTs

2021-04-20 Thread Stafford Horne via Gcc-patches
On Tue, Apr 20, 2021 at 05:20:39PM -0600, Jeff Law wrote:
> 
> On 4/18/2021 6:10 PM, Stafford Horne via Gcc-patches wrote:
> > When building libgeos we get an error with:
> > 
> >  linux-uclibc/9.3.0/crtbeginS.o: in function `__do_global_dtors_aux':
> >  crtstuff.c:(.text+0x118): relocation truncated to fit: R_OR1K_GOT16 
> > against symbol `__cxa_finalize' defined in .text section in
> >  
> > /home/shorne/work/openrisc/3eb9f9d0f6d8274b2d19753c006bd83f7d536e3c/output/host/or1k-buildroot-linux-uclibc/sysroot/lib/libc.so.
> > 
> > This is caused by GOT code having a limit of 64k.  In OpenRISC this
> > looks to be the only relocation code pattern to be limited to 64k.
> > 
> > This patch allows specifying a new option -mcmodel=large which can be
> > used to generate 2 more instructions to construct 32-bit addresses for
> > up to 4G GOTs.
> > 
> > gcc/ChangeLog:
> > 
> > PR 99783
> > * config/or1k/or1k-opts.h: New file.
> > * config/or1k/or1k.c (or1k_legitimize_address_1, print_reloc):
> > Support generating gotha relocations if -mcmodel=large is
> > specified.
> > * config/or1k/or1k.h (TARGET_CMODEL_SMALL, TARGET_CMODEL_LARGE):
> > New macros.
> > * config/or1k/or1k.opt (mcmodel=): New option.
> > * doc/invoke.text (OpenRISC Options): Document mcmodel.
> 
> Note you're the port maintainer, so you don't need approval to commit this
> to GCC.

Thanks for confirming, I know that after Segher told me with some previous
patches. :)

For this series Giulio picked it up and tested it.  We found some issues and I
am going to fix with a V2.  I should commit that version, after the binutils
changes are in.

-Stafford


[PATCH] or1k: Add mcmodel option to handle large GOTs

2021-04-18 Thread Stafford Horne via Gcc-patches
When building libgeos we get an error with:

linux-uclibc/9.3.0/crtbeginS.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x118): relocation truncated to fit: R_OR1K_GOT16 against 
symbol `__cxa_finalize' defined in .text section in

/home/shorne/work/openrisc/3eb9f9d0f6d8274b2d19753c006bd83f7d536e3c/output/host/or1k-buildroot-linux-uclibc/sysroot/lib/libc.so.

This is caused by GOT code having a limit of 64k.  In OpenRISC this
looks to be the only relocation code pattern to be limited to 64k.

This patch allows specifying a new option -mcmodel=large which can be
used to generate 2 more instructions to construct 32-bit addresses for
up to 4G GOTs.

gcc/ChangeLog:

PR 99783
* config/or1k/or1k-opts.h: New file.
* config/or1k/or1k.c (or1k_legitimize_address_1, print_reloc):
Support generating gotha relocations if -mcmodel=large is
specified.
* config/or1k/or1k.h (TARGET_CMODEL_SMALL, TARGET_CMODEL_LARGE):
New macros.
* config/or1k/or1k.opt (mcmodel=): New option.
* doc/invoke.text (OpenRISC Options): Document mcmodel.
---

This depends on the binutils-gdb patch sent here:
 - https://sourceware.org/pipermail/binutils/2021-April/116155.html

 gcc/config/or1k/or1k-opts.h | 30 ++
 gcc/config/or1k/or1k.c  | 11 +--
 gcc/config/or1k/or1k.h  |  7 +++
 gcc/config/or1k/or1k.opt| 19 +++
 gcc/doc/invoke.texi | 12 +++-
 5 files changed, 76 insertions(+), 3 deletions(-)
 create mode 100644 gcc/config/or1k/or1k-opts.h

diff --git a/gcc/config/or1k/or1k-opts.h b/gcc/config/or1k/or1k-opts.h
new file mode 100644
index 000..f791b894fdd
--- /dev/null
+++ b/gcc/config/or1k/or1k-opts.h
@@ -0,0 +1,30 @@
+/* Definitions for option handling for OpenRISC.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   Contributed by Stafford Horne.
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify it
+   under the terms of the GNU General Public License as published
+   by the Free Software Foundation; either version 3, or (at your
+   option) any later version.
+
+   GCC is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   .  */
+
+#ifndef GCC_OR1K_OPTS_H
+#define GCC_OR1K_OPTS_H
+
+/* The OpenRISC code generation models available.  */
+enum or1k_cmodel_type {
+  CMODEL_SMALL,
+  CMODEL_LARGE
+};
+
+#endif /* GCC_OR1K_OPTS_H */
diff --git a/gcc/config/or1k/or1k.c b/gcc/config/or1k/or1k.c
index e772a7addea..27d3fa17995 100644
--- a/gcc/config/or1k/or1k.c
+++ b/gcc/config/or1k/or1k.c
@@ -750,7 +750,14 @@ or1k_legitimize_address_1 (rtx x, rtx scratch)
{
  base = gen_sym_unspec (base, UNSPEC_GOT);
  crtl->uses_pic_offset_table = 1;
- t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
+ if (TARGET_CMODEL_LARGE)
+   {
+ emit_insn (gen_rtx_SET (t1, gen_rtx_HIGH (Pmode, base)));
+ emit_insn (gen_add3_insn (t1, t1, pic_offset_table_rtx));
+ t2 = gen_rtx_LO_SUM (Pmode, t1, base);
+   }
+ else
+   t2 = gen_rtx_LO_SUM (Pmode, pic_offset_table_rtx, base);
  t2 = gen_const_mem (Pmode, t2);
  emit_insn (gen_rtx_SET (t1, t2));
  base = t1;
@@ -1089,7 +1096,7 @@ print_reloc (FILE *stream, rtx x, HOST_WIDE_INT add, 
reloc_kind kind)
  no special markup.  */
   static const char * const relocs[RKIND_MAX][RTYPE_MAX] = {
 { "lo", "got", "gotofflo", "tpofflo", "gottpofflo", "tlsgdlo" },
-{ "ha", NULL,  "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
+{ "ha", "gotha", "gotoffha", "tpoffha", "gottpoffha", "tlsgdhi" },
   };
   reloc_type type = RTYPE_DIRECT;
 
diff --git a/gcc/config/or1k/or1k.h b/gcc/config/or1k/or1k.h
index fe01ab81ead..669907e7e74 100644
--- a/gcc/config/or1k/or1k.h
+++ b/gcc/config/or1k/or1k.h
@@ -21,6 +21,8 @@
 #ifndef GCC_OR1K_H
 #define GCC_OR1K_H
 
+#include "config/or1k/or1k-opts.h"
+
 /* Names to predefine in the preprocessor for this target machine.  */
 #define TARGET_CPU_CPP_BUILTINS()  \
   do   \
@@ -37,6 +39,11 @@
 }  \
   while (0)
 
+#define TARGET_CMODEL_SMALL \
+  (or1k_code_model == CMODEL_SMALL)
+#define TARGET_CMODEL_LARGE \
+  (or1k_code_model == CMODEL_LARGE)
+
 /* Storage layout.  */
 
 #define DEFAULT_SIGNED_CHAR 1
diff --git a/gcc/config/or1k/or1k.opt b/gcc/config/or1k/or1k.opt
index 6bd0f3eee6d..cc23e3b8856 100644
--- a/gcc/config/or1k/or1k.opt
+++

[PATCH v2 5/5] or1k: Fixup exception header data encodings

2021-01-13 Thread Stafford Horne via Gcc-patches
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 b686f1bd159..fe01ab81ead 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



[PATCH v2 4/5] or1k: Add note to indicate execstack

2021-01-13 Thread Stafford Horne via Gcc-patches
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 74fbe082103..196f3f3c8f0 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



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

2021-01-13 Thread Stafford Horne via Gcc-patches
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_UNDERFLOW1 << 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_ENDIAN4321
 
 #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



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

2021-01-13 Thread Stafford Horne via Gcc-patches
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 dc579e4a388..b686f1bd159 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



[PATCH v2 1/5] or1k: Implement profile hook calling _mcount

2021-01-13 Thread Stafford Horne via Gcc-patches
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 ab1c4bbd2a7..dc579e4a388 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



[RESEND PATCH 0/5] OpenRISC GCC Fixes for Glibc Support

2021-01-13 Thread Stafford Horne via Gcc-patches
Hello,

Changes since v1:
 - Rebase

This just a resend of v1 with no changes from when I sent it last year.  I
hadn't committed it because I had not completed all testing in glibc.  Now that
I have done that and it all seems to work I will commit it.

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



Re: [PATCH 4/6] contrib: Add or1k-elf, or1k-linux-*, and or1k-rtems to config-list.mk

2020-05-31 Thread Stafford Horne via Gcc-patches
On Sun, May 31, 2020 at 12:19:16PM +0200, Iain Buclaw wrote:
> Support for OpenRISC target was added in SVN r265963.
> 
> The target configurations were taken from the list of supported
> toolchains[1], so seems sensible to include them all.
> 
> OK?
> 
> Regards
> Iain
> 
> [1]: https://www.openrisc.io/software
> 
> ---
> contrib/ChangeLog:
> 
>   * config-list.mk (LIST): Add or1k-elf, or1k-linux-*, and or1k-rtems.

This looks good to me.  Can you apply it or do you want me to do it?

-Stafford


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

2020-05-19 Thread Stafford Horne via Gcc-patches
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_UNDERFLOW1 << 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_ENDIAN4321
 
 #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



[PATCH 1/5] or1k: Implement profile hook calling _mcount

2020-05-19 Thread Stafford Horne via Gcc-patches
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



[PATCH 5/5] or1k: Fixup exception header data encodings

2020-05-19 Thread Stafford Horne via Gcc-patches
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



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

2020-05-19 Thread Stafford Horne via Gcc-patches
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



[PATCH 0/5] OpenRISC GCC Fixes for Glibc Support

2020-05-19 Thread Stafford Horne via Gcc-patches
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



[PATCH 4/5] or1k: Add note to indicate execstack

2020-05-19 Thread Stafford Horne via Gcc-patches
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