OpenRISC port
v3 cover OpenRISC port
Hello,
Changes Since v2:
- Add RTEMS patches from Joel Sherrill
- Disable t-softfp-excl as suggsted by Joseph Myers
- Add new architecture flags needed to run on real FPGA's found in testing
* -mror - enable l.ror (rotate right)
* -mshftimm - enable shift/rorate by immediate instructions
- Binutils requirements are now in upstream git
Changes Since v1:
- Document options in invoke.texi suggested by Joseph Myers
- Remove obsolete/incorrect macros suggested by Joseph Myers
- Documented or1k.c functions as requested by Jeff Law
- Add epilogue barriers suggested by Jeff Law
- Define SPECULATION_SAFE_VALUE suggested by Jeff Law
- Switch to init/fini array suggested by Richard Henderson
- Define and document multilib flags to enable disable instructions only available on some CPU cores as requested on OpenRISC mailing list.
Since February this year I have been working on an OpenRISC clean room rewrite.
http://stffrdhrn.github.io/software/embedded/openrisc/2018/02/03/openrisc_gcc_rewrite.html
As per the article, the old port had issues with some of the owners signing over FSF copyright. To get around this I discussed options with the group and in the end I opted for a clean room rewrite.
The new code base has been written by me with lots of help from Richard Henderson. I trust that both of us have our FSF GCC copyright's in place.
# Testing
We have been running the GCC testsuite with newlib and musl libc. The results are good. See results published in a test build/release here:
- https://github.com/stffrdhrn/gcc/releases/tag/or1k-9.0.0-20181027
# Building
To build this requires the latest binutils upstream master i.e. 2.31.52.
-Stafford
Stafford Horne (3):
or1k: libgcc: initial support for openrisc
or1k: testsuite: initial support for openrisc
or1k: gcc: initial support for openrisc
gcc/common/config/or1k/or1k-common.c | 41 + gcc/config.gcc | 45 + gcc/config/or1k/constraints.md | 55 + gcc/config/or1k/elf.h | 42 + gcc/config/or1k/elf.opt | 33 + gcc/config/or1k/linux.h | 44 + gcc/config/or1k/or1k-protos.h | 38 + gcc/config/or1k/or1k.c | 2186 +++++++++++++++++ gcc/config/or1k/or1k.h | 392 +++ gcc/config/or1k/or1k.md | 907 +++++++ gcc/config/or1k/or1k.opt | 67 + gcc/config/or1k/predicates.md | 84 + gcc/config/or1k/rtems.h | 30 + gcc/config/or1k/t-or1k | 22 + gcc/config/or1k/t-rtems | 3 + gcc/configure | 12 + gcc/configure.ac | 12 + gcc/doc/install.texi | 19 + gcc/doc/invoke.texi | 68 + gcc/doc/md.texi | 25 + .../gcc.c-torture/execute/20101011-1.c | 3 + gcc/testsuite/gcc.dg/20020312-2.c | 2 + gcc/testsuite/gcc.dg/attr-alloc_size-11.c | 4 +- gcc/testsuite/gcc.dg/builtin-apply2.c | 2 +- gcc/testsuite/gcc.dg/nop.h | 2 + .../torture/stackalign/builtin-apply-2.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-33.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-34.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-35.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-36.c | 2 +- gcc/testsuite/gcc.target/or1k/args-1.c | 19 + gcc/testsuite/gcc.target/or1k/args-2.c | 15 + gcc/testsuite/gcc.target/or1k/cmov-1.c | 8 + gcc/testsuite/gcc.target/or1k/cmov-2.c | 9 + gcc/testsuite/gcc.target/or1k/div-mul-1.c | 9 + gcc/testsuite/gcc.target/or1k/div-mul-2.c | 9 + gcc/testsuite/gcc.target/or1k/or1k.exp | 41 + gcc/testsuite/gcc.target/or1k/return-1.c | 10 + gcc/testsuite/gcc.target/or1k/return-2.c | 19 + gcc/testsuite/gcc.target/or1k/return-3.c | 19 + gcc/testsuite/gcc.target/or1k/return-4.c | 19 + gcc/testsuite/gcc.target/or1k/ror-1.c | 8 + gcc/testsuite/gcc.target/or1k/ror-2.c | 9 + gcc/testsuite/gcc.target/or1k/ror-3.c | 8 + gcc/testsuite/gcc.target/or1k/shftimm-1.c | 8 + gcc/testsuite/gcc.target/or1k/shftimm-2.c | 8 + gcc/testsuite/gcc.target/or1k/sibcall-1.c | 18 + gcc/testsuite/lib/target-supports.exp | 1 + libgcc/config.host | 13 + libgcc/config/or1k/crti.S | 33 + libgcc/config/or1k/crtn.S | 1 + libgcc/config/or1k/lib1funcs.S | 223 ++ libgcc/config/or1k/linux-unwind.h | 87 + libgcc/config/or1k/sfp-machine.h | 54 + libgcc/config/or1k/t-or1k | 22 + 56 files changed, 4811 insertions(+), 9 deletions(-) create mode 100644 gcc/common/config/or1k/or1k-common.c create mode 100644 gcc/config/or1k/constraints.md create mode 100644 gcc/config/or1k/elf.h create mode 100644 gcc/config/or1k/elf.opt create mode 100644 gcc/config/or1k/linux.h create mode 100644 gcc/config/or1k/or1k-protos.h create mode 100644 gcc/config/or1k/or1k.c create mode 100644 gcc/config/or1k/or1k.h create mode 100644 gcc/config/or1k/or1k.md create mode 100644 gcc/config/or1k/or1k.opt create mode 100644 gcc/config/or1k/predicates.md create mode 100644 gcc/config/or1k/rtems.h create mode 100644 gcc/config/or1k/t-or1k create mode 100644 gcc/config/or1k/t-rtems create mode 100644 gcc/testsuite/gcc.target/or1k/args-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/args-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/cmov-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/cmov-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/or1k.exp create mode 100644 gcc/testsuite/gcc.target/or1k/return-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/return-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/return-3.c create mode 100644 gcc/testsuite/gcc.target/or1k/return-4.c create mode 100644 gcc/testsuite/gcc.target/or1k/ror-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/ror-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/ror-3.c create mode 100644 gcc/testsuite/gcc.target/or1k/shftimm-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/shftimm-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/sibcall-1.c create mode 100644 libgcc/config/or1k/crti.S create mode 100644 libgcc/config/or1k/crtn.S create mode 100644 libgcc/config/or1k/lib1funcs.S create mode 100644 libgcc/config/or1k/linux-unwind.h create mode 100644 libgcc/config/or1k/sfp-machine.h create mode 100644 libgcc/config/or1k/t-or1k
Signature · 1 line
2.17.1
PATCH v3 1/3 or1k: libgcc: initial support for openrisc
yyyy-mm-dd Stafford Horne <[email protected]>
Richard Henderson <[email protected]>
libgcc/ChangeLog:
* config.host: Add OpenRISC support.
* config/or1k/*: New.
--- libgcc/config.host | 13 ++ libgcc/config/or1k/crti.S | 33 +++++ libgcc/config/or1k/crtn.S | 1 + libgcc/config/or1k/lib1funcs.S | 223 ++++++++++++++++++++++++++++++ libgcc/config/or1k/linux-unwind.h | 87 ++++++++++++ libgcc/config/or1k/sfp-machine.h | 54 ++++++++ libgcc/config/or1k/t-or1k | 22 +++ 7 files changed, 433 insertions(+) create mode 100644 libgcc/config/or1k/crti.S create mode 100644 libgcc/config/or1k/crtn.S create mode 100644 libgcc/config/or1k/lib1funcs.S create mode 100644 libgcc/config/or1k/linux-unwind.h create mode 100644 libgcc/config/or1k/sfp-machine.h create mode 100644 libgcc/config/or1k/t-or1k
libgcc/config.host +13 -0
@@ -165,6 +165,9 @@ nds32*-*) nios2*-*-*) cpu_type=nios2 ;; +or1k*-*-*) + cpu_type=or1k + ;; powerpc*-*-*) cpu_type=rs6000 ;;
@@ -1039,6 +1042,16 @@ nios2-*-*) tmake_file="$tmake_file nios2/t-nios2 t-softfp-sfdf t-softfp-excl t-softfp" extra_parts="$extra_parts crti.o crtn.o" ;; +or1k-*-linux*) + tmake_file="$tmake_file or1k/t-or1k" + 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 t-softfp-sfdf t-softfp" + extra_parts="$extra_parts crti.o crtn.o" + ;; pdp11-*-*) tmake_file="pdp11/t-pdp11 t-fdpbit" ;;
libgcc/config/or1k/crti.S new file +33 -0
@@ -0,0 +1,33 @@ +/* Copyright (C) 2012-2018 Free Software Foundation, Inc. + +This file 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. + +This file 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. + +Under Section 7 of GPL version 3, you are granted additional +permissions described in the GCC Runtime Library Exception, version +3.1, as published by the Free Software Foundation. + +You should have received a copy of the GNU General Public License and +a copy of the GCC Runtime Library Exception along with this program; +see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +<http://www.gnu.org/licenses/>. */ + +/* Here _init and _fini are empty because .init_array/.fini_array are used + exclusively. However, the functions are still needed as required when + linking. */ + .align 4 + .global _init + .type _init, at function +_init: + .global _fini + .type _fini, at function +_fini: + l.jr r9 + l.nop
libgcc/config/or1k/crtn.S new file +1 -0
@@ -0,0 +1 @@ +/* crtn.S is empty because .init_array/.fini_array are used exclusively. */
libgcc/config/or1k/lib1funcs.S new file +223 -0
223 lines not on this page · raw message
libgcc/config/or1k/linux-unwind.h new file +87 -0
87 lines not on this page · raw message
libgcc/config/or1k/sfp-machine.h new file +54 -0
54 lines not on this page · raw message
libgcc/config/or1k/t-or1k new file +22 -0
@@ -0,0 +1,22 @@ +# Libgcc Makefile fragment for OpenRISC +# Copyright (C) 2018 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 +# <http://www.gnu.org/licenses/>. + +LIB1ASMSRC = or1k/lib1funcs.S +LIB1ASMFUNCS = __mulsi3 __udivsi3 __divsi3 __umodsi3 __modsi3
Signature · 1 line
2.17.1
PATCH v3 1/3 or1k: libgcc: initial support for openrisc
Hi!
libgcc/config/or1k/lib1funcs.S line 33
Quoted 4 lines · Stafford Horne
libgcc/config/or1k/lib1funcs.S new file +4
-0+ /* Given R = X * Y ... */ +1: l.sfeq r4, r0 /* while (y != 0) */ + l.bf 2f + l.andi r5, r4, 1 /* if (y & 1) ... */
Do the extra leading spaces mean something?
Quoted 1 line
+ l.sfeqi r4, 0 /* division by zero; return 0. */
In some places (like here) you ident with 8 spaces instead of a tab.
Quoted 8 lines
+/* For signed division we do:
+ *+ * -x / y = x / -y = -(x / y) + * -x % y = -(x % y) + * x % -y = x % b+ *
+ * which has the property that (x/y)*y + (x%y) = x.
+ */
You mean "y" instead of "b" I think.
Segher
PATCH v3 1/3 or1k: libgcc: initial support for openrisc
Hi,
Thanks for the review.
Quoted 9 lines · Segher Boessenkool
Hi!
libgcc/config/or1k/lib1funcs.S line 33
Quoted 4 lines · Stafford Horne
libgcc/config/or1k/lib1funcs.S new file +4
-0+ /* Given R = X * Y ... */ +1: l.sfeq r4, r0 /* while (y != 0) */ + l.bf 2f + l.andi r5, r4, 1 /* if (y & 1) ... */Do the extra leading spaces mean something?
Yes, we put those to indicate a branch delay slot instruction.
Quoted 3 lines
Quoted 1 line
+ l.sfeqi r4, 0 /* division by zero; return 0. */
In some places (like here) you ident with 8 spaces instead of a tab.
Thanks, I will fix those, it should be tab.
Quoted 10 lines
Quoted 8 lines
+/* For signed division we do:
+ *+ * -x / y = x / -y = -(x / y) + * -x % y = -(x % y) + * x % -y = x % b+ *
+ * which has the property that (x/y)*y + (x%y) = x.
+ */You mean "y" instead of "b" I think.
I believe so, I will read through it. This part was done by Richard I should have reviewed it better.
-Stafford
PATCH v3 1/3 or1k: libgcc: initial support for openrisc
In reply to Stafford Hornelibgcc/config/or1k/crti.S line 33
Quoted 12 lines · Stafford Horne
libgcc/config/or1k/crti.S new file +12
-0+/* Here _init and _fini are empty because .init_array/.fini_array are used + exclusively. However, the functions are still needed as required when + linking. */ + .align 4 + .global _init + .type _init, at function +_init: + .global _fini + .type _fini, at function +_fini: + l.jr r9 + l.nop
Where are they referenced from? Perhaps just a binutils bug, in that the linker script needs adjustment?
libgcc/config/or1k/lib1funcs.S line 42
Quoted 13 lines
libgcc/config/or1k/lib1funcs.S new file +13
-0+ /* Given R = X * Y ... */ +1: l.sfeq r4, r0 /* while (y != 0) */ + l.bf 2f + l.andi r5, r4, 1 /* if (y & 1) ... */ + l.add r12, r11, r3 + l.sfne r5, r0 +#if defined(__or1k_cmov__) + l.cmov r11, r12, r11 /* ... r += x. */ + l.srli r4, r4, 1 /* y >>= 1 */ +#else + l.bnf 3f + l.srli r4, r4, 1 /* y >>= 1 */ + l.ori r11, r12, 0
This move could be the add to save 1 cycle in the !cmov case.
Quoted 4 lines
libgcc/config/or1k/lib1funcs.S new file +4
-0+ /* Shift Y back to the right again, subtracting from X. */ +2: l.add r7, r11, r6 /* tmp1 = quot + mask */ +3: l.srli r6, r6, 1 /* mask >>= 1 */ + l.sub r8, r12, r4 /* tmp2 = x - y */
libgcc/config/or1k/lib1funcs.S line 98
Quoted 10 lines
libgcc/config/or1k/lib1funcs.S new file +10
-0+ l.sfleu r4, r12 /* y <= x */ + l.srli r4, r4, 1 /* y >>= 1 */ +#if defined(__or1k_cmov__) + l.cmov r11, r7, r11 /* if (y <= x) quot = tmp1 */ + l.cmov r12, r8, r12 /* if (y <= x) x = tmp2 */ +#else + l.bnf 4f + l.nop + l.ori r11, r7, 0 + l.ori r12, r8, 0
Simiarly.
Although both mul nor div are correct as-is, and need not be fixed immediately.
I'm only concerned about _init and _fini.
r~
PATCH v3 1/3 or1k: libgcc: initial support for openrisc
Quoted 16 lines · Richard Henderson
libgcc/config/or1k/crti.S line 33
Quoted 12 lines · Stafford Horne
libgcc/config/or1k/crti.S new file +12
-0+/* Here _init and _fini are empty because .init_array/.fini_array are used + exclusively. However, the functions are still needed as required when + linking. */ + .align 4 + .global _init + .type _init, at function +_init: + .global _fini + .type _fini, at function +_fini: + l.jr r9 + l.nopWhere are they referenced from? Perhaps just a binutils bug, in that the linker script needs adjustment?
I was getting the issue with newlib. Here:
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/misc/init.c
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libc/misc/fini.c
The HAVE_INIT_FINI was not there when I last checked. Now, thanks to risc-v, we can turn off the need for _init/_fini see:
I guess thats what you were referring to before though, I just missed it.
Quoted 33 lines
libgcc/config/or1k/lib1funcs.S line 42
Quoted 13 lines
libgcc/config/or1k/lib1funcs.S new file +13
-0+ /* Given R = X * Y ... */ +1: l.sfeq r4, r0 /* while (y != 0) */ + l.bf 2f + l.andi r5, r4, 1 /* if (y & 1) ... */ + l.add r12, r11, r3 + l.sfne r5, r0 +#if defined(__or1k_cmov__) + l.cmov r11, r12, r11 /* ... r += x. */ + l.srli r4, r4, 1 /* y >>= 1 */ +#else + l.bnf 3f + l.srli r4, r4, 1 /* y >>= 1 */ + l.ori r11, r12, 0This move could be the add to save 1 cycle in the !cmov case.
Quoted 4 lines
libgcc/config/or1k/lib1funcs.S new file +4
-0+ /* Shift Y back to the right again, subtracting from X. */ +2: l.add r7, r11, r6 /* tmp1 = quot + mask */ +3: l.srli r6, r6, 1 /* mask >>= 1 */ + l.sub r8, r12, r4 /* tmp2 = x - y */libgcc/config/or1k/lib1funcs.S line 98
Quoted 10 lines
libgcc/config/or1k/lib1funcs.S new file +10
-0+ l.sfleu r4, r12 /* y <= x */ + l.srli r4, r4, 1 /* y >>= 1 */ +#if defined(__or1k_cmov__) + l.cmov r11, r7, r11 /* if (y <= x) quot = tmp1 */ + l.cmov r12, r8, r12 /* if (y <= x) x = tmp2 */ +#else + l.bnf 4f + l.nop + l.ori r11, r7, 0 + l.ori r12, r8, 0Simiarly.
Quoted 2 lines
Although both mul nor div are correct as-is, and need not be fixed immediately.
I'm only concerned about_initand_fini.
Sure, let me look into them.
-Stafford
PATCH v3 2/3 or1k: testsuite: initial support for openrisc
In reply to Stafford Horneyyyy-mm-dd Stafford Horne <[email protected]>
Richard Henderson <[email protected]>
gcc/testsuite/ChangeLog:
* gcc.c-torture/execute/20101011-1.c: Adjust for OpenRISC.
* gcc.dg/20020312-2.c: Likewise.
* gcc.dg/attr-alloc_size-11.c: Likewise.
* gcc.dg/builtin-apply2.c: Likewise.
* gcc.dg/nop.h: Likewise.
* gcc.dg/torture/stackalign/builtin-apply-2.c: Likewise.
* gcc.dg/tree-ssa/20040204-1.c: Likewise.
* gcc.dg/tree-ssa/reassoc-33.c: Likewise.
* gcc.dg/tree-ssa/reassoc-34.c: Likewise.
* gcc.dg/tree-ssa/reassoc-35.c: Likewise.
* gcc.dg/tree-ssa/reassoc-36.c: Likewise.
* lib/target-supports.exp (check_effective_target_logical_op_short_circuit): Add or1k*-*-*.
* gcc.target/or1k/*: New.
--- .../gcc.c-torture/execute/20101011-1.c | 3 ++ gcc/testsuite/gcc.dg/20020312-2.c | 2 + gcc/testsuite/gcc.dg/attr-alloc_size-11.c | 4 +- gcc/testsuite/gcc.dg/builtin-apply2.c | 2 +- gcc/testsuite/gcc.dg/nop.h | 2 + .../torture/stackalign/builtin-apply-2.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-33.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-34.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-35.c | 2 +- gcc/testsuite/gcc.dg/tree-ssa/reassoc-36.c | 2 +- gcc/testsuite/gcc.target/or1k/args-1.c | 19 +++++++++ gcc/testsuite/gcc.target/or1k/args-2.c | 15 +++++++ gcc/testsuite/gcc.target/or1k/cmov-1.c | 8 ++++ gcc/testsuite/gcc.target/or1k/cmov-2.c | 9 ++++ gcc/testsuite/gcc.target/or1k/div-mul-1.c | 9 ++++ gcc/testsuite/gcc.target/or1k/div-mul-2.c | 9 ++++ gcc/testsuite/gcc.target/or1k/or1k.exp | 41 +++++++++++++++++++ gcc/testsuite/gcc.target/or1k/return-1.c | 10 +++++ gcc/testsuite/gcc.target/or1k/return-2.c | 19 +++++++++ gcc/testsuite/gcc.target/or1k/return-3.c | 19 +++++++++ gcc/testsuite/gcc.target/or1k/return-4.c | 19 +++++++++ gcc/testsuite/gcc.target/or1k/ror-1.c | 8 ++++ gcc/testsuite/gcc.target/or1k/ror-2.c | 9 ++++ gcc/testsuite/gcc.target/or1k/ror-3.c | 8 ++++ gcc/testsuite/gcc.target/or1k/shftimm-1.c | 8 ++++ gcc/testsuite/gcc.target/or1k/shftimm-2.c | 8 ++++ gcc/testsuite/gcc.target/or1k/sibcall-1.c | 18 ++++++++ gcc/testsuite/lib/target-supports.exp | 1 + 29 files changed, 253 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.target/or1k/args-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/args-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/cmov-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/cmov-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/div-mul-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/or1k.exp create mode 100644 gcc/testsuite/gcc.target/or1k/return-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/return-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/return-3.c create mode 100644 gcc/testsuite/gcc.target/or1k/return-4.c create mode 100644 gcc/testsuite/gcc.target/or1k/ror-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/ror-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/ror-3.c create mode 100644 gcc/testsuite/gcc.target/or1k/shftimm-1.c create mode 100644 gcc/testsuite/gcc.target/or1k/shftimm-2.c create mode 100644 gcc/testsuite/gcc.target/or1k/sibcall-1.c
gcc/testsuite/gcc.c-torture/execute/20101011-1.c +3 -0
@@ -100,6 +100,9 @@ __aeabi_idiv0 (int return_value)#elif defined (__moxie__)/* Not all moxie configurations may raise exceptions. */ # define DO_TEST 0 +#elif defined (__or1k__) +/* On OpenRISC division by zero does not trap. */ +# define DO_TEST 0#else # define DO_TEST 1#endif
gcc/testsuite/gcc.dg/20020312-2.c +2 -0
@@ -117,6 +117,8 @@ extern void abort (void);# if defined (__CK807__) || defined (__CK810__)# define PIC_REG "r28"# endif +#elif defined (__or1k__) +/* No pic register. */ #else # error "Modify the test for your target."#endif
gcc/testsuite/gcc.dg/attr-alloc_size-11.c +2 -2
@@ -47,8 +47,8 @@ typedef __SIZE_TYPE__ size_t;/* The following tests fail because of missing range information. The xfail exclusions are PR79356. */ -TEST (signed char, SCHAR_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for signed char" { xfail { ! { aarch64*-*-* arm*-*-* avr-*-* alpha*-*-* ia64-*-* mips*-*-* powerpc*-*-* sparc*-*-* s390*-*-* visium-*-* } } } } */ -TEST (short,SHRT_MIN +2 ,ALLOC_MAX );/* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for short" { xfail { ! { aarch64*-*-* arm*-*-* alpha*-*-* avr-*-* ia64-*-* mips*-*-* powerpc*-*-* sparc*-*-* s390x-*-* visium-*-* } } } } */ +TEST (signed char, SCHAR_MIN + 2, ALLOC_MAX); /* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for signed char" { xfail { ! { aarch64*-*-* arm*-*-* avr-*-* alpha*-*-* ia64-*-* mips*-*-* powerpc*-*-* sparc*-*-* s390*-*-* visium-*-* or1k*-*-* } } } } */ +TEST (short,SHRT_MIN +2 ,ALLOC_MAX );/* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" "missing range info for short" { xfail { ! { aarch64*-*-* arm*-*-* alpha*-*-* avr-*-* ia64-*-* mips*-*-* powerpc*-*-* sparc*-*-* s390x-*-* visium-*-* or1k*-*-* } } } } */ TEST (int,INT_MIN +2 ,ALLOC_MAX );/* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */ TEST (int,-3 ,ALLOC_MAX );/* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */ TEST (int,-2 ,ALLOC_MAX );/* { dg-warning "argument 1 range \\\[13, \[0-9\]+\\\] exceeds maximum object size 12" } */
gcc/testsuite/gcc.dg/builtin-apply2.c +1 -1
@@ -1,7 +1,7 @@/* { dg-do run } */ /* { dg-require-effective-target untyped_assembly } */ /* { dg-skip-if "Variadic funcs have all args on stack. Normal funcs have args in registers." { "avr-*-* nds32*-*-*" } } */ -/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs." { "riscv*-*-*" } } */ +/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs." { "riscv*-*-* or1k*-*-*" } } */ /* { dg-skip-if "Variadic funcs use Base AAPCS. Normal funcs use VFP variant." { arm*-*-* && arm_hf_eabi } } */ /* PR target/12503 */
gcc/testsuite/gcc.dg/nop.h +2 -0
@@ -2,6 +2,8 @@#define NOP "nop 0"#elif defined (__MMIX__)#define NOP "swym 0" +#elif defined (__or1k__) +#define NOP "l.nop"#else #define NOP "nop"#endif
gcc/testsuite/gcc.dg/torture/stackalign/builtin-apply-2.c +1 -1
@@ -9,7 +9,7 @@/* arm_hf_eabi: Variadic funcs use Base AAPCS. Normal funcs use VFP variant. avr: Variadic funcs don't pass arguments in registers, while normal funcs do. */ -/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs" { arm_hf_eabi || { avr-*-* riscv*-*-* } } } */ +/* { dg-skip-if "Variadic funcs use different argument passing from normal funcs" { arm_hf_eabi || { avr-*-* riscv*-*-* or1k*-*-* } } } */ /* { dg-skip-if "Variadic funcs have all args on stack. Normal funcs have args in registers." { nds32*-*-* } } */ /* { dg-require-effective-target untyped_assembly } */
gcc/testsuite/gcc.dg/tree-ssa/20040204-1.c +1 -1
@@ -33,4 +33,4 @@ void test55 (int x, int y)that the && should be emitted (based on BRANCH_COST). Fix this by teaching dom to look through && and register all components as true. */ -/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized" { xfail { ! "alpha*-*-* arm*-*-* aarch64*-*-* powerpc*-*-* cris-*-* crisv32-*-* hppa*-*-* i?86-*-* mmix-*-* mips*-*-* m68k*-*-* moxie-*-* nds32*-*-* s390*-*-* sh*-*-* sparc*-*-* spu-*-* visium-*-* x86_64-*-* riscv*-*-*" } } } } */ +/* { dg-final { scan-tree-dump-times "link_error" 0 "optimized" { xfail { ! "alpha*-*-* arm*-*-* aarch64*-*-* powerpc*-*-* cris-*-* crisv32-*-* hppa*-*-* i?86-*-* mmix-*-* mips*-*-* m68k*-*-* moxie-*-* nds32*-*-* s390*-*-* sh*-*-* sparc*-*-* spu-*-* visium-*-* x86_64-*-* riscv*-*-* or1k*-*-*" } } } } */
gcc/testsuite/gcc.dg/tree-ssa/reassoc-33.c +1 -1
@@ -1,4 +1,4 @@ -/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-*"} } } */ +/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-* or1k-*-*-*"} } } */ /* { dg-options "-O2 -fno-inline -fdump-tree-reassoc1-details" } */ /* { dg-additional-options "-mbranch-cost=2" { target branch_cost } } */
gcc/testsuite/gcc.dg/tree-ssa/reassoc-34.c +1 -1
@@ -1,4 +1,4 @@ -/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-*"} } } */ +/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-* or1k*-*-*"} } } */ /* { dg-options "-O2 -fno-inline -fdump-tree-reassoc1-details" } */ /* { dg-additional-options "-mbranch-cost=2" { target branch_cost } } */
gcc/testsuite/gcc.dg/tree-ssa/reassoc-35.c +1 -1
@@ -1,4 +1,4 @@ -/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-*"} } } */ +/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-* or1k*-*-*"} } } */ /* { dg-options "-O2 -fno-inline -fdump-tree-reassoc1-details" } */ /* { dg-additional-options "-mbranch-cost=2" { target branch_cost } } */
gcc/testsuite/gcc.dg/tree-ssa/reassoc-36.c +1 -1
@@ -1,4 +1,4 @@ -/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-*"} } } */ +/* { dg-do run { target { ! "m68k*-*-* mmix*-*-* bfin*-*-* v850*-*-* moxie*-*-* cris*-*-* m32c*-*-* fr30*-*-* mcore*-*-* powerpc*-*-* xtensa*-*-* hppa*-*-* nios2*-*-* or1k*-*-*"} } } */ /* { dg-options "-O2 -fno-inline -fdump-tree-reassoc1-details" } */ /* { dg-additional-options "-mbranch-cost=2" { target branch_cost } } */
gcc/testsuite/gcc.target/or1k/args-1.c new file +19 -0
@@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct a { +long x; +long y; +long z; +}; + +int passlibstruct (int b,struct a aa); + +int main () { +struct a aa = {55 ,66 ,77 }; + +return passlibstruct (-1 , aa); +} + +/* Ensure we pass a stack reference in the second arg. */ +/* { dg-final { scan-assembler-times "r4, r1, " 1 } } */
gcc/testsuite/gcc.target/or1k/args-2.c new file +15 -0
@@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct a { +long x; +long y; +long z; +}; + +int passstruct (int b,struct a aa) { +return aa.z + aa.y + b; +} + +/* Ensure our struct reads are offset from the address in arg 2. */ +/* { dg-final { scan-assembler-times "l.lwz\\s+r\\d+, \\d+.r4." 2 } } */
gcc/testsuite/gcc.target/or1k/cmov-1.c new file +8 -0
@@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-mcmov -O2" } */ + +int cond (int a,int b) { +return a > b; +} + +/* { dg-final { scan-assembler "l.cmov" } } */
gcc/testsuite/gcc.target/or1k/cmov-2.c new file +9 -0
@@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-skip-if "" { *-*-* } { "-mcmov" } { "" } } */ + +int cond (int a,int b) { +return a > b; +} + +/* { dg-final { scan-assembler-not "l.cmov" } } */
gcc/testsuite/gcc.target/or1k/div-mul-1.c new file +9 -0
@@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -msoft-mul -msoft-div" } */ + +int calc (int a,int b,int c) { +return a * b / c; +} + +/* { dg-final { scan-assembler-not "l.mul" } } */ +/* { dg-final { scan-assembler-not "l.div" } } */
gcc/testsuite/gcc.target/or1k/div-mul-2.c new file +9 -0
@@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -msoft-div" } */ + +int calc (int a,int b,int c) { +return a * b / c; +} + +/* { dg-final { scan-assembler "l.mul" } } */ +/* { dg-final { scan-assembler-not "l.div" } } */
gcc/testsuite/gcc.target/or1k/or1k.exp new file +41 -0
41 lines not on this page · raw message
gcc/testsuite/gcc.target/or1k/return-1.c new file +10 -0
@@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +long long calc (long long a,long long b) { +return a * b +5 ; +} + +/* Ensure our return value is set in the r11, r12 pair. */ +/* { dg-final { scan-assembler "r11," } } */ +/* { dg-final { scan-assembler "r12," } } */
gcc/testsuite/gcc.target/or1k/return-2.c new file +19 -0
@@ -0,0 +1,19 @@ +/* Large structs are returned at a memory address passed in r3. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct a { +long x; +long y; +long z; +}; + +struct a getstruct (long aa) { +struct a as = {22 , aa,-5 }; +return as; +} + +/* Ensure our return value is returned on stack. */ +/* { dg-final { scan-assembler-not "r12," } } */ +/* { dg-final { scan-assembler "l.or\\s+r11, r3, r3" } } */ +/* { dg-final { scan-assembler-times "l.sw\\s+\\d+.r3.," 3 } } */
gcc/testsuite/gcc.target/or1k/return-3.c new file +19 -0
@@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct a { +long x; +long y; +long z; +}; + +struct a getlibstruct (long aa); + +int main () { +struct a rs =getlibstruct (123 ); + +return rs.x; +} + +/* Ensure our return value is read from memory. */ +/* { dg-final { scan-assembler "l.lwz\\s+r11," } } */
gcc/testsuite/gcc.target/or1k/return-4.c new file +19 -0
@@ -0,0 +1,19 @@ +/* Test to ensure small structs are returned in memory too. */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +struct a { +long x; +long y; +}; + +struct a getlibstruct (long aa); + +int main () { +struct a rs =getlibstruct (123 ); + +return rs.x; +} + +/* Ensure our return value is read from memory. */ +/* { dg-final { scan-assembler "l.lwz\\s+r11," } } */
gcc/testsuite/gcc.target/or1k/ror-1.c new file +8 -0
@@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-mror -O2" } */ + +unsigned int rotate (unsigned int a,int b) { +return ( a >> b ) | ( a << (32 - b ) ); +} + +/* { dg-final { scan-assembler "l.ror" } } */
gcc/testsuite/gcc.target/or1k/ror-2.c new file +9 -0
@@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-skip-if "" { *-*-* } { "-mror" } { "" } } */ + +unsigned int rotate (unsigned int a,int b) { +return ( a >> b ) | ( a << (32 - b ) ); +} + +/* { dg-final { scan-assembler-not "l.ror" } } */
gcc/testsuite/gcc.target/or1k/ror-3.c new file +8 -0
@@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-mror -O2" } */ + +unsigned int rotate6 (unsigned int a) { +return ( a >>6 ) | ( a << (32 -6 ) ); +} + +/* { dg-final { scan-assembler-not "l.rori" } } */
gcc/testsuite/gcc.target/or1k/shftimm-1.c new file +8 -0
@@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-mror -mshftimm -O2" } */ + +unsigned int rotate6 (unsigned int a) { +return ( a >>6 ) | ( a << (32 -6 ) ); +} + +/* { dg-final { scan-assembler "l.rori" } } */
gcc/testsuite/gcc.target/or1k/shftimm-2.c new file +8 -0
@@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-mshftimm -O2" } */ + +unsigned int shift6 (unsigned int a) { +return a >>6 ; +} + +/* { dg-final { scan-assembler "l.srli" } } */
gcc/testsuite/gcc.target/or1k/sibcall-1.c new file +18 -0
@@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +/* Just create some dummy call that should trigger sibcall, no +stack logic. */ +int calc (int a,int b,int c) { +if (c <=0 )return a; +return calc (a * b, b, --c); +} + +int main () { +return calc (4 ,3 ,4 ); +} + +/* Ensure sibcalls do not need to manipulate the stack. */ +/* { dg-final { scan-assembler-not "r1," } } */ +/* Ensure sibcall maintains the body of the function. */ +/* { dg-final { scan-assembler "l.mul" } } */
gcc/testsuite/lib/target-supports.exp +1 -0
@@ -8394,6 +8394,7 @@ proc check_effective_target_logical_op_short_circuit {} { || [istarget riscv*-*-*] || [istarget v850*-*-*] || [istarget visium-*-*] + || [istarget or1k*-*-*] || [check_effective_target_arm_cortex_m] } { return 1 }
Signature · 1 line
2.17.1
PATCH v3 2/3 or1k: testsuite: initial support for openrisc
Quoted 5 lines · Stafford Horne
yyyy-mm-dd Stafford Horne <[email protected]>
Richard Henderson <[email protected]>gcc/testsuite/ChangeLog:
Quoted 15 lines
* gcc.c-torture/execute/20101011-1.c: Adjust for OpenRISC.
* gcc.dg/20020312-2.c: Likewise.
*gcc.dg/attr-alloc_size-11.c: Likewise.
*gcc.dg/builtin-apply2.c: Likewise.
*gcc.dg/nop.h: Likewise.
*gcc.dg/torture/stackalign/builtin-apply-2.c: Likewise.
* gcc.dg/tree-ssa/20040204-1.c: Likewise.
*gcc.dg/tree-ssa/reassoc-33.c: Likewise.
*gcc.dg/tree-ssa/reassoc-34.c: Likewise.
*gcc.dg/tree-ssa/reassoc-35.c: Likewise.
*gcc.dg/tree-ssa/reassoc-36.c: Likewise.
*lib/target-supports.exp(check_effective_target_logical_op_short_circuit): Add or1k*-*-*.
* gcc.target/or1k/*: New.
---
Ok.
r~
PATCH v3 3/3 or1k: gcc: initial support for openrisc
In reply to Stafford Horneyyyy-mm-dd Stafford Horne <[email protected]>
Richard Henderson <[email protected]>
Joel Sherrill <[email protected]>
gcc/ChangeLog:
* common/config/or1k/or1k-common.c: New file.
* config/or1k/*: New.
* config.gcc (or1k*-*-*): New.
* configure.ac (or1k*-*-*): New test for openrisc tls.
* configure: Regenerated.
* doc/install.texi: Document OpenRISC triplets.
* doc/invoke.texi: Document OpenRISC arguments.
* doc/md.texi: Document OpenRISC.
--- gcc/common/config/or1k/or1k-common.c | 41 + gcc/config.gcc | 45 + gcc/config/or1k/constraints.md | 55 + gcc/config/or1k/elf.h | 42 + gcc/config/or1k/elf.opt | 33 + gcc/config/or1k/linux.h | 44 + gcc/config/or1k/or1k-protos.h | 38 + gcc/config/or1k/or1k.c | 2186 ++++++++++++++++++++++++++ gcc/config/or1k/or1k.h | 392 +++++ gcc/config/or1k/or1k.md | 907 +++++++++++ gcc/config/or1k/or1k.opt | 67 + gcc/config/or1k/predicates.md | 84 + gcc/config/or1k/rtems.h | 30 + gcc/config/or1k/t-or1k | 22 + gcc/config/or1k/t-rtems | 3 + gcc/configure | 12 + gcc/configure.ac | 12 + gcc/doc/install.texi | 19 + gcc/doc/invoke.texi | 68 + gcc/doc/md.texi | 25 + 20 files changed, 4125 insertions(+) create mode 100644 gcc/common/config/or1k/or1k-common.c create mode 100644 gcc/config/or1k/constraints.md create mode 100644 gcc/config/or1k/elf.h create mode 100644 gcc/config/or1k/elf.opt create mode 100644 gcc/config/or1k/linux.h create mode 100644 gcc/config/or1k/or1k-protos.h create mode 100644 gcc/config/or1k/or1k.c create mode 100644 gcc/config/or1k/or1k.h create mode 100644 gcc/config/or1k/or1k.md create mode 100644 gcc/config/or1k/or1k.opt create mode 100644 gcc/config/or1k/predicates.md create mode 100644 gcc/config/or1k/rtems.h create mode 100644 gcc/config/or1k/t-or1k create mode 100644 gcc/config/or1k/t-rtems
gcc/common/config/or1k/or1k-common.c new file +41 -0
@@ -0,0 +1,41 @@ +/* Common hooks for OpenRISC +Copyright (C) 2018 Free Software Foundation, Inc. + +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 +<http://www.gnu.org/licenses/>. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "diagnostic-core.h" +#include "tm.h" +#include "common/common-target.h" +#include "common/common-target-def.h" +#include "opts.h" +#include "flags.h" + +/* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */ +static const struct default_options or1k_option_optimization_table[] = + { +/* Enable section anchors by default at -O1 or higher. */ + {OPT_LEVELS_1_PLUS , OPT_fsection_anchors,NULL ,1 }, + {OPT_LEVELS_NONE ,0 ,NULL ,0 } + }; + +#undef TARGET_OPTION_OPTIMIZATION_TABLE +#define TARGET_OPTION_OPTIMIZATION_TABLE or1k_option_optimization_table + +struct gcc_targetm_common targetm_common =TARGETM_COMMON_INITIALIZER ;
gcc/config.gcc +45 -0
57 lines not on this page · raw message
gcc/config/or1k/constraints.md new file +55 -0
55 lines not on this page · raw message
gcc/config/or1k/elf.h new file +42 -0
42 lines not on this page · raw message
gcc/config/or1k/elf.opt new file +33 -0
@@ -0,0 +1,33 @@ +; OpenRISC command line options for newlib binaries + +; Copyright (C) 2010-2018 Free Software Foundation, Inc. +; +; 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 +; <http://www.gnu.org/licenses/>. + +; See the GCC internals manual (options.texi) for a description of +; this file's format. + +; Please try to keep this file in ASCII collating order. + +mboard= +Target RejectNegative Joined +Configure board specific runtime. + +mnewlib +Target RejectNegative +For compatibility, it's always newlib for elf now. +
gcc/config/or1k/linux.h new file +44 -0
44 lines not on this page · raw message
gcc/config/or1k/or1k-protos.h new file +38 -0
@@ -0,0 +1,38 @@ +/* Prototypes for OpenRISC functions used in the md file & elsewhere. +Copyright (C) 2018 Free Software Foundation, Inc. + +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 +<http://www.gnu.org/licenses/>. */ + +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_expand_eh_return (rtx ); +extern rtx or1k_initial_frame_addr (void ); +extern rtx or1k_dynamic_chain_addr (rtx ); +extern rtx or1k_return_addr (int ,rtx ); +extern void or1k_expand_move (machine_mode ,rtx ,rtx ); +extern void or1k_expand_compare (rtx *); +extern void or1k_expand_call (rtx ,rtx ,rtx ,bool ); + +#ifdef RTX_CODE +void or1k_expand_atomic_compare_and_swap (rtx operands[]); +void or1k_expand_atomic_compare_and_swap_qihi (rtx operands[]); +void or1k_expand_atomic_exchange (rtx operands[]); +void or1k_expand_atomic_exchange_qihi (rtx operands[]); +void or1k_expand_atomic_op (rtx_code ,rtx ,rtx ,rtx ,rtx ); +void or1k_expand_atomic_op_qihi (rtx_code ,rtx ,rtx ,rtx ,rtx ); +#endif
gcc/config/or1k/or1k.c new file +2186 -0
2,186 lines not on this page · raw message
gcc/config/or1k/or1k.h new file +392 -0
392 lines not on this page · raw message
gcc/config/or1k/or1k.md new file +907 -0
112 lines not on this page · raw message
gcc/config/or1k/or1k.opt new file +67 -0
67 lines not on this page · raw message
gcc/config/or1k/predicates.md new file +84 -0
84 lines not on this page · raw message
gcc/doc/invoke.texi +68 -0
68 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 7 lines · Stafford Horne
gcc/config/or1k/or1k.md new file +7
-0+(define_insn "zero_extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.exthz\t%0, %1 + l.lhz\t%0, %1"
gcc/config/or1k/or1k.md line 346
Quoted 10 lines
gcc/config/or1k/or1k.md new file +10
-0+ [(set_attr "insn_support" "sext,*")]) + +(define_insn "zero_extendqisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.extbz\t%0, %1 + l.lbz\t%0, %1" + [(set_attr "insn_support" "sext,*")])
The !sext r/r case is just l.andi.
Quoted 10 lines
gcc/config/or1k/or1k.md new file +10
-0+;; Sign extension patterns + +;; We can do memory extensions with a single load +(define_insn "extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.exths\t%0, %1 + l.lhs\t%0, %1"
gcc/config/or1k/or1k.md line 367
Quoted 10 lines
gcc/config/or1k/or1k.md new file +10
-0+ [(set_attr "insn_support" "sext,*")]) + +(define_insn "extendqisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.extbs\t%0, %1 + l.lbs\t%0, %1" + [(set_attr "insn_support" "sext,*")])
You don't really want to give the register allocator no choice but to spill to memory in the !sext case. Another r/r case with a splitter that is conditional on !sext would work.
Otherwise, OK.
r~
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 12 lines · Richard Henderson
Quoted 11 lines · Stafford Horne
gcc/config/or1k/or1k.md new file +11
-0+(define_insn "zero_extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.exthz\t%0, %1 + l.lhz\t%0, %1" + [(set_attr "insn_support" "sext,*")]) + +(define_insn "zero_extendqisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r")
Quoted 8 lines
gcc/config/or1k/or1k.md line 346
Quoted 6 lines
gcc/config/or1k/or1k.md new file +6
-0+ (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.extbz\t%0, %1 + l.lbz\t%0, %1" + [(set_attr "insn_support" "sext,*")])The !sext r/r case is just l.andi.
OK.
Quoted 16 lines
Quoted 16 lines
gcc/config/or1k/or1k.md new file +16
-0+;; Sign extension patterns + +;; We can do memory extensions with a single load +(define_insn "extendhisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))] + "" + "@ + l.exths\t%0, %1 + l.lhs\t%0, %1" + [(set_attr "insn_support" "sext,*")]) + +(define_insn "extendqisi2" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))] + ""
Quoted 8 lines
gcc/config/or1k/or1k.md line 367
Quoted 4 lines
gcc/config/or1k/or1k.md new file +4
-0+ "@ + l.extbs\t%0, %1 + l.lbs\t%0, %1" + [(set_attr "insn_support" "sext,*")])You don't really want to give the register allocator no choice but to spill to memory in the !sext case. Another r/r case with a splitter that is conditional on !sext would work.
OK, I was just being lazy allowing the spill. Do you think the split/expand would be an RTL using left shift / right shift? Can you think of something more clever? Since "real" hardware does not usually support shifts with an immediate we will need 1 instruction to load shift amount. i.e.
l.ori %0, r0, 24
l.sll %1, %1, %0
l.sra %0, %1, %0
If we support shift with immediate it would just be:
l.slli %1, %1, 24
l.srai %0, %1, 24
But, I cant think of anything better.
Quoted 1 line
Otherwise, OK.
Thanks,
I am submitting patches on my git branch or1k-port-4. Just in case you want to track progress.
- Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 8 lines · Stafford Horne
OK, I was just being lazy allowing the spill. Do you think the split/expand would be an RTL using left shift / right shift? Can you think of something more clever? Since "real" hardware does not usually support shifts with an immediate we will need 1 instruction to load shift amount. i.e.
l.ori %0, r0, 24
l.sll %1, %1, %0
l.sra %0, %1, %0
This clobbers %1.
So, ouch. I think we will want to avoid creating this particular pattern in the first place unless l.exts exists then. We would use another pattern like
(define_insn "*sign_extend_mem<mode>"
[(set (match_operand:SI 0 "register_operand" "=r")
(sign_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
""
"l.lhs\t%0, %1")
following the TARGET_SEXT pattern. In this way combine can use this pattern without getting us into trouble with the register allocator later.
Quoted 2 lines
I am submitting patches on my git branch or1k-port-4. Just in case you want to track progress.
Will do.
r~
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 11 lines · Richard Henderson
Quoted 8 lines · Stafford Horne
OK, I was just being lazy allowing the spill. Do you think the split/expand would be an RTL using left shift / right shift? Can you think of something more clever? Since "real" hardware does not usually support shifts with an immediate we will need 1 instruction to load shift amount. i.e.
l.ori %0, r0, 24
l.sll %1, %1, %0
l.sra %0, %1, %0This clobbers %1.
Right, it was just a rough idea to create another r/r pattern.
Quoted 5 lines
So, ouch. I think we will want to avoid creating this particular pattern in the first place unless l.exts exists then. We would use another pattern like
(
define_insn"*sign_extend_mem<mode>"
[(set (match_operand:SI 0 "register_operand" "=r")
Quoted 7 lines
(sign_extend:SI (match_operand:HI 1 "memory_operand" "m")))]""
"l.lhs\t%0, %1")following the
TARGET_SEXTpattern. In this way combine can use this pattern without getting us into trouble with the register allocator later.
OK, thats simple enough then. I had thought you were asking for creating another r/r pattern using define_split. That might be better than requiring a memory load/store to do sign extension, but I guess we can optimize that later if needed. (Thats what my original thought was.)
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
In reply to Stafford HorneHi Stafford,
Some minor comments. I didn't read the atomics much, but I did look at everything else, and it looks fine :-)
gcc/config.gcc nvptx-*) · line 2501
Quoted 5 lines · Stafford Horne
gcc/config.gcc +5
-0+ case ${target} in + or1k*-*-linux*) + tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h" + tm_file="${tm_file} or1k/linux.h" + ;;
Spaces instead of tabs.
Quoted 1 line
+ /* Number of bytes saved on the stack for outgoing/sub-fucntion args. */
Typo ("function").
gcc/config/or1k/or1k.c line 71
Quoted 3 lines
gcc/config/or1k/or1k.c new file +3
-0+/* The sum of sizes: locals vars, called saved regs, stack pointer +* and an optional frame pointer. +* Used in expand_prologue () and expand_epilogue(). */
We don't use leading stars in comments (just spaces), normally.
Quoted 1 line
+ /* Set address to volitile to ensure the store doesn't get optimized out. */
"volatile"
gcc/config/or1k/or1k.c line 514
Quoted 9 lines
gcc/config/or1k/or1k.c new file +9
-0+/* Helper for defining INITIAL_ELIMINATION_OFFSET. +We allow the following eliminiations: +FP -> HARD_FP or SP +AP -> HARD_FP or SP + +HFP and AP are the same which is handled below. */ + +HOST_WIDE_INT +or1k_initial_elimination_offset (int from,int to)
You could calculate this as some_offset (from) - some_offset (to) with some_offset a simple helper function. That gives you all possible eliminations :-)
(Each offset is very cheap to compute in your case, so that's not a problem).
gcc/config/or1k/or1k.c line 961
Quoted 4 lines
gcc/config/or1k/or1k.c new file +4
-0+static rtx +or1k_function_value (const_tree valtype, + const_tree fn_decl_or_type ATTRIBUTE_UNUSED, + bool outgoing ATTRIBUTE_UNUSED)
Since we use C++ now you can write this as
bool /*outgoing*/)
or such, for enhanced readability.
Quoted 1 line
+ split. Symbols are lagitimized using split relocations. */
"legitimized"
gcc/config/or1k/or1k.c line 1387
Quoted 6 lines
gcc/config/or1k/or1k.c new file +6
-0+void +or1k_expand_move (machine_mode mode,rtx op0,rtx op1) +{ +if (MEM_P (op0)) + { +if (!const0_operand (op1, mode))
Space before (.
gcc/config/or1k/or1k.c line 1589
Quoted 2 lines
gcc/config/or1k/or1k.c new file +2
-0+#undef TARGET_RTX_COSTS +#define TARGET_RTX_COSTS or1k_rtx_costs
You may want TARGET_INSN_COST as well (it is easier to get (more) correct).
gcc/config/or1k/or1k.c line 2088
Quoted 6 lines
gcc/config/or1k/or1k.c new file +6
-0+if (hi !=0 ) + { +rtx scratch2 =gen_rtx_REG (Pmode,RV_REGNUM ); +emit_move_insn (scratch2,GEN_INT (hi)); +emit_insn (gen_add2_insn (scratch, scratch2)); + }
Tab instead of spaces.
gcc/config/or1k/or1k.c line 2100
Quoted 2 lines
gcc/config/or1k/or1k.c new file +2
-0+/* Generate a tail call to the target function. */ +if (!TREE_USED (function))
No space after !.
gcc/config/or1k/or1k.c line 2164
Quoted 3 lines
gcc/config/or1k/or1k.c new file +2
-0+#define TARGET_RETURN_IN_MEMORY or1k_return_in_memory +#define TARGET_PASS_BY_REFERENCE or1k_pass_by_reference
These two have a tab instead of a space (as the rest do).
Quoted 1 line
+#define
WCHAR_TYPE_SIZE32
And this.
gcc/config/or1k/or1k.h line 126
Quoted 6 lines
gcc/config/or1k/or1k.h new file +6
-0+This ABI has no adjacent call-saved register, which means that +DImode/DFmode pseudos cannot be call-saved and will always be +spilled across calls. To solve this without changing the ABI, +remap the compiler internal register numbers to place the even +call-saved registers r16-r30 in 24-31, and the odd call-clobbered +registers r17-r31 in 16-23. */
Ooh evilness :-)
gcc/config/or1k/or1k.h line 291
Quoted 2 lines
gcc/config/or1k/or1k.h new file +2
-0+#define Pmode SImode +#define FUNCTION_MODE SImode
Some more tabs.
Quoted 1 line
+#define
FUNCTION_ARG_REGNO_P(r)(r >= 3 && r <= 8)
IN_RANGE ?
Quoted 1 line
+ {
ARG_POINTER_REGNUM,STACK_POINTER_REGNUM}, \
Weird tab here, too.
Quoted 1 line
+#define
EH_RETURN_REGNUMHW_TO_GCC_REGNO(23)
And here.
gcc/config/or1k/or1k.md line 206
Quoted 9 lines
gcc/config/or1k/or1k.md new file +9
-0+(define_insn "xorsi3" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (xor:SI + (match_operand:SI 1 "register_operand" "%r,r") + (match_operand:SI 2 "reg_or_s16_operand" " r,I")))] + "" + "@ + l.xor\t%0, %1, %2 + l.xori\t%0, %1, %2")
Is this correct? Should this be unsigned (u16 and K)?
https://sourceware.org/cgen/gen-doc/openrisc-insn.html suggest so, but I don't know how up-to-date or relevant that is. Well. From the atomics much below it seems to be correct, and signed is nice for making a bit inverse. Is there some better documentation? Something to put at
https://gcc.gnu.org/readings.html (this is in the CVS repo, still see
https://gcc.gnu.org/about.html#cvs ).
gcc/config/or1k/or1k.md line 235
Quoted 3 lines
gcc/config/or1k/or1k.md new file +3
-0+(define_expand "mov<I:mode>" + [(set (match_operand:I 0 "nonimmediate_operand" "") + (match_operand:I 1 "general_operand" ""))]
You can completely leave out empty constraint strings, for example in the expanders.
gcc/config/or1k/or1k.opt line 32
Quoted 7 lines
gcc/config/or1k/or1k.opt new file +7
-0+mhard-div +Target RejectNegative InverseMask(SOFT_DIV) +Use hardware divide instructions, use -msoft-div for emulation. + +mhard-mul +Target RejectNegative InverseMask(SOFT_MUL). +Use hardware multiply instructions, use -msoft-mul for emulation.
Maybe put the -msoft-* options near here then?
This was a lovely read. Thank you! Your port looks great.
Segher
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Hi Segher,
Thank you for the review and thank you for all the help up until now.
Quoted 5 lines · Segher Boessenkool
Hi Stafford,
Some minor comments. I didn't read the atomics much, but I did look at everything else, and it looks fine :-)
Quoted 8 lines
gcc/config.gcc nvptx-*) · line 2501
Quoted 5 lines · Stafford Horne
gcc/config.gcc +5
-0+ case ${target} in + or1k*-*-linux*) + tm_file="${tm_file} gnu-user.h linux.h glibc-stdint.h" + tm_file="${tm_file} or1k/linux.h" + ;;Spaces instead of tabs.
OK, I will fix.
Quoted 3 lines
Quoted 1 line
+ /* Number of bytes saved on the stack for outgoing/sub-fucntion args. */
Typo ("function").
OK.
Quoted 5 lines
gcc/config/or1k/or1k.c line 71
Quoted 3 lines
gcc/config/or1k/or1k.c new file +3
-0+/* The sum of sizes: locals vars, called saved regs, stack pointer +* and an optional frame pointer. +* Used in expand_prologue () and expand_epilogue(). */ We don't use leading stars in comments (just spaces), normally.
OK.
Quoted 3 lines
Quoted 1 line
+ /* Set address to volitile to ensure the store doesn't get optimized out. */
"volatile"
OK.
Quoted 14 lines
gcc/config/or1k/or1k.c line 514
Quoted 9 lines
gcc/config/or1k/or1k.c new file +9
-0+/* Helper for defining INITIAL_ELIMINATION_OFFSET. +We allow the following eliminiations: +FP -> HARD_FP or SP +AP -> HARD_FP or SP + +HFP and AP are the same which is handled below. */ + +HOST_WIDE_INT +or1k_initial_elimination_offset (int from,int to)You could calculate this as
some_offset(from) -some_offset(to) withsome_offseta simple helper function. That gives you all possible eliminations :-)
Quoted 1 line
(Each offset is very cheap to compute in your case, so that's not a problem).
Right, Do you mean something like the following? I think it would work, but I am not sure it make the code easier to read. Do you think there would be much benefits supporting all possible eliminations?
/* Helper function for use with INITIAL_ELIMINATION_OFFSET. */
static HOST_WIDE_INTor1k_stack_pointer_offset (int from)
{
HOST_WIDE_INT offset;
/* Set OFFSET to the offset from the stack pointer. */ switch (from)
{
/* Incoming args are all the way up at the previous frame. */
case HARD_FRAME_POINTER_REGNUM:
case ARG_POINTER_REGNUM:
offset = cfun->machine->total_size;
break;
/* Local args grow downward from the saved registers. */
case FRAME_POINTER_REGNUM:
offset = cfun->machine->args_size + cfun->machine->local_vars_size;
break;
default:
gcc_unreachable ();
} return offset;
}
/* Helper for defining INITIAL_ELIMINATION_OFFSET.
We allow the following eliminiations:
FP -> HARD_FP or SP
AP -> HARD_FP or SP HARD_FP and AP are actually the same. */
HOST_WIDE_INTor1k_initial_elimination_offset (int from, int to)
{
return or1k_stack_pointer_offset (from) - or1k_stack_pointer_offset (to);
}
Quoted 8 lines
gcc/config/or1k/or1k.c line 961
Quoted 4 lines
gcc/config/or1k/or1k.c new file +4
-0+static rtx +or1k_function_value (const_tree valtype, + const_tree fn_decl_or_type ATTRIBUTE_UNUSED, + bool outgoing ATTRIBUTE_UNUSED)Since we use C++ now you can write this as
bool /*outgoing*/)or such, for enhanced readability.
Sure, I will remove all ATTRIBUTE_UNUSED instances.
Quoted 3 lines
Quoted 1 line
+ split. Symbols are lagitimized using split relocations. */
"legitimized"
OK.
Quoted 8 lines
gcc/config/or1k/or1k.c line 1387
Quoted 6 lines
gcc/config/or1k/or1k.c new file +6
-0+void +or1k_expand_move (machine_mode mode,rtx op0,rtx op1) +{ +if (MEM_P (op0)) + { +if (!const0_operand (op1, mode))Space before (.
OK. I found a few ore too, thanks.
Quoted 4 lines
gcc/config/or1k/or1k.c line 1589
Quoted 2 lines
gcc/config/or1k/or1k.c new file +2
-0+#undef TARGET_RTX_COSTS +#define TARGET_RTX_COSTS or1k_rtx_costsYou may want
TARGET_INSN_COSTas well (it is easier to get (more) correct).
OK, I was not considering that for the first port. Perhaps after getting this in? I think in general the OpenRISC insruction costs are fairly flat for the ones are using.
Quoted 8 lines
gcc/config/or1k/or1k.c line 2088
Quoted 6 lines
gcc/config/or1k/or1k.c new file +6
-0+if (hi !=0 ) + { +rtx scratch2 =gen_rtx_REG (Pmode,RV_REGNUM ); +emit_move_insn (scratch2,GEN_INT (hi)); +emit_insn (gen_add2_insn (scratch, scratch2)); + }Tab instead of spaces.
OK.
Quoted 4 lines
gcc/config/or1k/or1k.c line 2100
Quoted 2 lines
gcc/config/or1k/or1k.c new file +2
-0+/* Generate a tail call to the target function. */ +if (!TREE_USED (function))No space after !.
Ok.
Quoted 5 lines
gcc/config/or1k/or1k.c line 2164
Quoted 3 lines
gcc/config/or1k/or1k.c new file +2
-0+#define TARGET_RETURN_IN_MEMORY or1k_return_in_memory +#define TARGET_PASS_BY_REFERENCE or1k_pass_by_referenceThese two have a tab instead of a space (as the rest do).
OK, also some TARGET_* are aligned and some not. Will fix.
Quoted 3 lines
Quoted 1 line
+#define
WCHAR_TYPE_SIZE32And this.
OK.
Quoted 8 lines
gcc/config/or1k/or1k.h line 126
Quoted 6 lines
gcc/config/or1k/or1k.h new file +6
-0+This ABI has no adjacent call-saved register, which means that +DImode/DFmode pseudos cannot be call-saved and will always be +spilled across calls. To solve this without changing the ABI, +remap the compiler internal register numbers to place the even +call-saved registers r16-r30 in 24-31, and the odd call-clobbered +registers r17-r31 in 16-23. */ Ooh evilness :-)
Richard did this, I thought it was rather clever. :)
Quoted 4 lines
gcc/config/or1k/or1k.h line 291
Quoted 2 lines
gcc/config/or1k/or1k.h new file +2
-0+#define Pmode SImode +#define FUNCTION_MODE SImodeSome more tabs.
OK.
Quoted 3 lines
Quoted 1 line
+#define
FUNCTION_ARG_REGNO_P(r)(r >= 3 && r <= 8)
IN_RANGE?
OK, I may change it, I think without the macro, its easy to understand that its (inclusive).
Quoted 3 lines
Quoted 1 line
+ {
ARG_POINTER_REGNUM,STACK_POINTER_REGNUM}, \Weird tab here, too.
Oh, weird one, thank you.
Quoted 3 lines
Quoted 1 line
+#define
EH_RETURN_REGNUMHW_TO_GCC_REGNO(23)And here.
OK.
Quoted 10 lines
gcc/config/or1k/or1k.md line 206
Quoted 9 lines
gcc/config/or1k/or1k.md new file +9
-0+(define_insn "xorsi3" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (xor:SI + (match_operand:SI 1 "register_operand" "%r,r") + (match_operand:SI 2 "reg_or_s16_operand" " r,I")))] + "" + "@ + l.xor\t%0, %1, %2 + l.xori\t%0, %1, %2")
Quoted 7 lines
Is this correct? Should this be unsigned (u16 and K)?
https://sourceware.org/cgen/gen-doc/openrisc-insn.html suggest so, but I don't know how up-to-date or relevant that is. Well. From the atomics much below it seems to be correct, and signed is nice for making a bit inverse. Is there some better documentation? Something to put at
https://gcc.gnu.org/readings.html (this is in the CVS repo, still see
https://gcc.gnu.org/about.html#cvs ).
OK, let me have a look at this one and get back. Maybe Richard has a suggestion as he did the Atomics.
Quoted 6 lines
gcc/config/or1k/or1k.md line 235
Quoted 3 lines
gcc/config/or1k/or1k.md new file +3
-0+(define_expand "mov<I:mode>" + [(set (match_operand:I 0 "nonimmediate_operand" "") + (match_operand:I 1 "general_operand" ""))]You can completely leave out empty constraint strings, for example in the expanders.
OK.
Quoted 9 lines
gcc/config/or1k/or1k.opt line 32
Quoted 7 lines
gcc/config/or1k/or1k.opt new file +7
-0+mhard-div +Target RejectNegative InverseMask(SOFT_DIV) +Use hardware divide instructions, use -msoft-div for emulation. + +mhard-mul +Target RejectNegative InverseMask(SOFT_MUL). +Use hardware multiply instructions, use -msoft-mul for emulation.Maybe put the -msoft-* options near here then?
I was trying to keep them in alphabetical order. But I do understand it makes more sense to group these together.
Quoted 1 line
This was a lovely read. Thank you! Your port looks great.
Thanks a lot!
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Hi!
Quoted 15 lines · Stafford Horne
Quoted 14 lines · Segher Boessenkool
gcc/config/or1k/or1k.c line 514
Quoted 9 lines
gcc/config/or1k/or1k.c new file +9
-0+/* Helper for defining INITIAL_ELIMINATION_OFFSET. +We allow the following eliminiations: +FP -> HARD_FP or SP +AP -> HARD_FP or SP + +HFP and AP are the same which is handled below. */ + +HOST_WIDE_INT +or1k_initial_elimination_offset (int from,int to)You could calculate this as
some_offset(from) -some_offset(to) withsome_offseta simple helper function. That gives you all possible eliminations :-)
Quoted 5 lines
Quoted 1 line
(Each offset is very cheap to compute in your case, so that's not a problem).
Right, Do you mean something like the following? I think it would work, but I am not sure it make the code easier to read. Do you think there would be much benefits supporting all possible eliminations?
Yes, like that. It also easily can handle the other combos (those with STACK_POINTER), and it is easier if you have to switch FRAME_GROWS_DOWNWARD ("false" is better on some args, but "true" is required for ssp).
Your code is fine as-is of course.
Quoted 8 lines
Quoted 4 lines
gcc/config/or1k/or1k.c line 1589
Quoted 2 lines
gcc/config/or1k/or1k.c new file +2
-0+#undef TARGET_RTX_COSTS +#define TARGET_RTX_COSTS or1k_rtx_costsYou may want
TARGET_INSN_COSTas well (it is easier to get (more) correct).OK, I was not considering that for the first port. Perhaps after getting this in? I think in general the OpenRISC insruction costs are fairly flat for the ones are using.
Oh, this was just a suggestion for the future :-)
If you compile with -dp you will see the cost and length for every insn annotated; are most/all correct?
Quoted 10 lines
Quoted 8 lines
gcc/config/or1k/or1k.h line 126
Quoted 6 lines
gcc/config/or1k/or1k.h new file +6
-0+This ABI has no adjacent call-saved register, which means that +DImode/DFmode pseudos cannot be call-saved and will always be +spilled across calls. To solve this without changing the ABI, +remap the compiler internal register numbers to place the even +call-saved registers r16-r30 in 24-31, and the odd call-clobbered +registers r17-r31 in 16-23. */ Ooh evilness :-)
Richard did this, I thought it was rather clever. :)
Yes!
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
+#define
FUNCTION_ARG_REGNO_P(r)(r >= 3 && r <= 8)
IN_RANGE?OK, I may change it, I think without the macro, its easy to understand that its (inclusive).
Yeah, you'll have to remember that IN_RANGE always is inclusive too. Maybe if it were used more that woul become second nature to more people :-)
Segher
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Hello,
Quoted 24 lines · Segher Boessenkool
Hi!
Quoted 15 lines · Stafford Horne
Quoted 14 lines · Segher Boessenkool
gcc/config/or1k/or1k.c line 514
Quoted 9 lines
gcc/config/or1k/or1k.c new file +9
-0+/* Helper for defining INITIAL_ELIMINATION_OFFSET. +We allow the following eliminiations: +FP -> HARD_FP or SP +AP -> HARD_FP or SP + +HFP and AP are the same which is handled below. */ + +HOST_WIDE_INT +or1k_initial_elimination_offset (int from,int to)You could calculate this as
some_offset(from) -some_offset(to) withsome_offseta simple helper function. That gives you all possible eliminations :-)Quoted 5 lines
Quoted 1 line
(Each offset is very cheap to compute in your case, so that's not a problem).
Right, Do you mean something like the following? I think it would work, but I am not sure it make the code easier to read. Do you think there would be much benefits supporting all possible eliminations?
Quoted 5 lines
Yes, like that. It also easily can handle the other combos (those with
STACK_POINTER), and it is easier if you have to switchFRAME_GROWS_DOWNWARD("false" is better on some args, but "true" is required for ssp).Your code is fine as-is of course.
Just to be clear, when you say 'as-is' did you mean the original v3 patch? Or are you referring to followup patch I posted with the some_offset (from) - some_offset (to) logic.
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 7 lines · Stafford Horne
Hello,
Quoted 4 lines · Segher Boessenkool
Yes, like that. It also easily can handle the other combos (those with
STACK_POINTER), and it is easier if you have to switchFRAME_GROWS_DOWNWARD("false" is better on some args, but "true" is required for ssp).
Quoted 5 lines
Quoted 1 line
Your code is fine as-is of course.
Just to be clear, when you say 'as-is' did you mean the original v3 patch? Or are you referring to followup patch I posted with the
some_offset(from) -some_offset(to) logic.
Either. Both. I meant the orig big patch, v3 if that's what it was.
I am not a global reviewer; this is all just my opinion :-)
Segher
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 8 lines · Segher Boessenkool
Quoted 7 lines · Stafford Horne
Hello,
Quoted 4 lines · Segher Boessenkool
Yes, like that. It also easily can handle the other combos (those with
STACK_POINTER), and it is easier if you have to switchFRAME_GROWS_DOWNWARD("false" is better on some args, but "true" is required for ssp).
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Your code is fine as-is of course.
Just to be clear, when you say 'as-is' did you mean the original v3 patch? Or are you referring to followup patch I posted with the
some_offset(from) -some_offset(to) logic.Either. Both. I meant the orig big patch, v3 if that's what it was.
Alright, thanks, I just didnt want to misunderstand.
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 11 lines · Stafford Horne
Quoted 10 lines · Segher Boessenkool
Quoted 9 lines · Stafford Horne
Hello,
Quoted 5 lines · Segher Boessenkool
Yes, like that. It also easily can handle the other combos (those with
STACK_POINTER), and it is easier if you have to switchFRAME_GROWS_DOWNWARD("false" is better on some args, but "true" is required for ssp).Your code is fine as-is of course.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Just to be clear, when you say 'as-is' did you mean the original v3 patch? Or are you referring to followup patch I posted with the
some_offset(from) -some_offset(to) logic.Either. Both. I meant the orig big patch, v3 if that's what it was.
Alright, thanks, I just didnt want to misunderstand.
Also note that it's my understanding the issues I raised during my review have been dealt with as have Joseph's. My inclination would be to accept the port when Stafford & rth think it's ready.
Jeff
PATCH v3 3/3 or1k: gcc: initial support for openrisc
In reply to Segher BoessenkoolQuoted 11 lines · Segher Boessenkool
gcc/config/or1k/or1k.md line 206
Quoted 9 lines
gcc/config/or1k/or1k.md new file +9
-0+(define_insn "xorsi3" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (xor:SI + (match_operand:SI 1 "register_operand" "%r,r") + (match_operand:SI 2 "reg_or_s16_operand" " r,I")))] + "" + "@ + l.xor\t%0, %1, %2 + l.xori\t%0, %1, %2")Is this correct? Should this be unsigned (u16 and K)?
No, l.xori is signed.
r~
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 13 lines · Richard Henderson
Quoted 11 lines · Segher Boessenkool
gcc/config/or1k/or1k.md line 206
Quoted 9 lines
gcc/config/or1k/or1k.md new file +9
-0+(define_insn "xorsi3" + [(set (match_operand:SI 0 "register_operand" "=r,r") + (xor:SI + (match_operand:SI 1 "register_operand" "%r,r") + (match_operand:SI 2 "reg_or_s16_operand" " r,I")))] + "" + "@ + l.xor\t%0, %1, %2 + l.xori\t%0, %1, %2")Is this correct? Should this be unsigned (u16 and K)?
Quoted 1 line
No, l.xori is signed.
Right, sorry, I didn't have enough time to look at this at all this morning. It is correct.
It looks like the documentation for this page [1] is generated from the cgen cpu descriptions that were removed from binutils-gdb back in 2014. Ccing cgen who seem to maintain this web page. How can we go about getting it regenerated?
cpu/or1korbis.cpu
(alu-insn-uimm and)
(alu-insn-uimm or)
(alu-insn-simm xor)
(define-pmacro (alu-carry-insn-simm mnemonic)
(begin
(dni (.sym l- mnemonic "i")
(.str "l." mnemonic "i reg/reg/simm16")
((MACH ORBIS-MACHS))
(.str "l." mnemonic "i $rD,$rA,$simm16")
(+ (.sym OPC_ (.upcase mnemonic) "I") rD rA simm16)[1] https://sourceware.org/cgen/gen-doc/openrisc-insn.html#insns
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 4 lines · Stafford Horne
Quoted 3 lines · Richard Henderson
Quoted 1 line · Segher Boessenkool
Is this correct? Should this be unsigned (u16 and K)?
Quoted 8 lines
Quoted 1 line
No, l.xori is signed.
Right, sorry, I didn't have enough time to look at this at all this morning. It is correct.
It looks like the documentation for this page [1] is generated from the cgen cpu descriptions that were removed from binutils-gdb back in 2014. Ccing cgen who seem to maintain this web page. How can we go about getting it regenerated?
Is there some better documentation available? This is what google found for me. I would have like better docs (more compact, etc.) Links to such would be great to have in readings.html :-)
Segher
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 3 lines · Segher Boessenkool
Is there some better documentation available? This is what google found for me. I would have like better docs (more compact, etc.) Links to such would be great to have in readings.html :-)
https://openrisc.io/architecture
and especially the v1.2 pdf linked from there
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.2-rev0.pdf
r~
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 10 lines · Richard Henderson
Quoted 3 lines · Segher Boessenkool
Is there some better documentation available? This is what google found for me. I would have like better docs (more compact, etc.) Links to such would be great to have in readings.html :-)
https://openrisc.io/architecture
and especially the v1.2 pdf linked from there
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.2-rev0.pdf
Thanks,
I meant to point this out during my previous reply. Also, I will send a patch for adding this to wwwdocs.
https://www.gnu.org/software/gcc/readings.html
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 10 lines · Stafford Horne
Quoted 9 lines · Richard Henderson
Quoted 3 lines · Segher Boessenkool
Is there some better documentation available? This is what google found for me. I would have like better docs (more compact, etc.) Links to such would be great to have in readings.html :-)
https://openrisc.io/architecture
and especially the v1.2 pdf linked from there
Quoted 8 lines
Thanks,
I meant to point this out during my previous reply. Also, I will send a patch for adding this to wwwdocs.
I figure out how I most likely found the out-of-date page btw: I googled "openrisc xori" (no quotes).
Segher
PATCH v3 3/3 or1k: gcc: initial support for openrisc
In reply to Stafford HorneQuoted 36 lines · Stafford Horne
+++
b/gcc/config/or1k/linux.hgcc/config/or1k/linux.h new file +34
-0@@ -0,0 +1,44 @@ +/* Linux Definitions for OpenRISC. +Copyright (C) 2018 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 +<http://www.gnu.org/licenses/>. */ + +#ifndef GCC_OR1K_LINUX_H +#define GCC_OR1K_LINUX_H + +/* elfos.h should have already been included. Now just override +any conflicting definitions and add any extras. */ + +#define TARGET_OS_CPP_BUILTINS () \ + GNU_USER_TARGET_OS_CPP_BUILTINS () + +#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-or1k.so.1" + +#undef MUSL_DYNAMIC_LINKER +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-or1k.so.1" +
gcc/config/or1k/linux.h line 44
Quoted 10 lines
gcc/config/or1k/linux.h new file +10
-0+#undef LINK_SPEC +#define LINK_SPEC "%{h*} \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \ + %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +#endif /* GCC_OR1K_LINUX_H */
note that because of the -static-pie mess each target needs a more complicated LINK_SPEC now.
i think there could be a generic LINK_SPEC in config/linux.h or config/gnu-user.h that works for simple targets (the start file spec is already there) so this complex logic is not repeated everywhere.
or even do the -no-dynamic-linker logic in LINK_PIE_SPEC in gcc.c for all targets, not just linux, so backends don't need to do anything to get static-pie to work.
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 42 lines · Szabolcs Nagy
Quoted 41 lines · Stafford Horne
+++
b/gcc/config/or1k/linux.h(quoted diff) +39
-0@@ -0,0 +1,44 @@ +/* Linux Definitions for OpenRISC. + Copyright (C) 2018 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 + <http://www.gnu.org/licenses/>. */ + +#ifndef GCC_OR1K_LINUX_H +#define GCC_OR1K_LINUX_H + +/* elfos.h should have already been included. Now just override + any conflicting definitions and add any extras. */ + +#define TARGET_OS_CPP_BUILTINS() \ + GNU_USER_TARGET_OS_CPP_BUILTINS () + +#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-or1k.so.1" + +#undef MUSL_DYNAMIC_LINKER +#define MUSL_DYNAMIC_LINKER "/lib/ld-musl-or1k.so.1" + +#undef LINK_SPEC +#define LINK_SPEC "%{h*} \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \
Quoted 8 lines
Review line 44
Quoted 5 lines
(quoted diff) +5
-0+ %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +#endif /* GCC_OR1K_LINUX_H */note that because of the -static-pie mess each target needs a more complicated
LINK_SPECnow.
Hello,
Does something like this look better?
gcc/config/or1k/linux.h +3 -2
@@ -37,8 +37,9 @@ %{static:-Bstatic} \ %{shared:-shared} \ %{symbolic:-Bsymbolic} \ - %{!static: \ + %{!static:%{!static-pie: \ %{rdynamic:-export-dynamic} \ - %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \ + %{static-pie:-Bstatic -pie --no-dynamic-linker -z text}" #endif /* GCC_OR1K_LINUX_H */
I have tested this out with or1k-linux-musl, but I get some LD complaints i.e.
.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol __fini_array_end .../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol __fini_array_start
Those are some warnings we recently added to LD, perhaps I need to rebuild the libc.a with PIE as well. I will try it out, but if anyone has some suggestions that would be helpful.
Quoted 10 lines
i think there could be a generic
LINK_SPECinconfig/linux.horconfig/gnu-user.hthat works for simple targets (the start file spec is already there) so this complex logic is not repeated everywhere.or even do the -no-dynamic-linker logic in
LINK_PIE_SPECingcc.cfor all targets, not just linux, so backends don't need to do anything to get static-pie to work.
I see, yeah, it seems this could be made generic. I would defer myself working on making this generic until after or1k port is in. Sorry, I dont have much time to make sure it doesnt break everything/anything. Also, To tell you the truth I haven't heard of anyone ever running OpenRISC with pie, it has always been something on my todo list though. I have had some inqueries into helping bootstrap some linux nommu machines.
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 2 lines · Stafford Horne
Quoted 1 line · Szabolcs Nagy
On 27/10/18 05:37, Stafford Horne wrote:
...
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+#undef LINK_SPEC +#define LINK_SPEC "%{h*} \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +#endif /* GCC_OR1K_LINUX_H */note that because of the -static-pie mess each
target needs a more complicatedLINK_SPECnow.Hello,
Does something like this look better?
gcc/config/or1k/linux.h +0
-0@@ -37,8 +37,9 @@ %{static:-Bstatic} \
gcc/config/or1k/linux.h line 45
Quoted 10 lines
gcc/config/or1k/linux.h +3
-2%{shared:-shared} \ %{symbolic:-Bsymbolic} \ - %{!static: \ + %{!static:%{!static-pie: \ %{rdynamic:-export-dynamic} \ - %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \ + %{static-pie:-Bstatic -pie --no-dynamic-linker -z text}"#endif /* GCC_OR1K_LINUX_H */
looks ok.
Quoted 8 lines
I have tested this out with or1k-linux-musl, but I get some LD complaints i.e.
.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol
__fini_array_end.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol__fini_array_startThose are some warnings we recently added to LD, perhaps I need to rebuild the libc.a with PIE as well. I will try it out, but if anyone has some suggestions that would be helpful.
yes, musl does not build libc.a with pic by default, either use a gcc configured with --enable-default-pie or CC='gcc -fPIC' when building musl.
after that -static-pie linking should work.
(maybe musl should have an --enable-static-pie config option to make this simpler)
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 48 lines · Szabolcs Nagy
Quoted 2 lines · Stafford Horne
Quoted 1 line · Szabolcs Nagy
On 27/10/18 05:37, Stafford Horne wrote:
...
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+#undef LINK_SPEC +#define LINK_SPEC "%{h*} \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +#endif /* GCC_OR1K_LINUX_H */note that because of the -static-pie mess each
target needs a more complicatedLINK_SPECnow.Hello,
Does something like this look better?
gcc/config/or1k/linux.h +0
-0@@ -37,8 +37,9 @@ %{static:-Bstatic} \gcc/config/or1k/linux.h line 45
Quoted 10 lines
gcc/config/or1k/linux.h +3
-2%{shared:-shared} \ %{symbolic:-Bsymbolic} \ - %{!static: \ + %{!static:%{!static-pie: \ %{rdynamic:-export-dynamic} \ - %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \ + %{static-pie:-Bstatic -pie --no-dynamic-linker -z text}"#endif /* GCC_OR1K_LINUX_H */ looks ok.
Quoted 8 lines
I have tested this out with or1k-linux-musl, but I get some LD complaints i.e.
.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol
__fini_array_end.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol__fini_array_startThose are some warnings we recently added to LD, perhaps I need to rebuild the libc.a with PIE as well. I will try it out, but if anyone has some suggestions that would be helpful.
Quoted 8 lines
yes, musl does not build libc.a with pic by default, either use a gcc configured with --enable-default-pie or CC='gcc -fPIC' when building musl.
after that -static-pie linking should work.
(maybe musl should have an --enable-static-pie config option to make this simpler)
For practical purposes, if you want to use static pie, you need a default-pie toolchain. This is because _every_ static lib you might link needs to be built with -fPIE (or -fPIC), and ensuring that happens on a package-by-package basis is largely impractical; at least it's on the same order of magnitude of difficulty as other systems integration/packaging tasks.
However from the musl side it might make sense to produce a libc_pic.a as part of the build process. This would make it easy to replace libc.a with libc_pic.a if desired, and could also be used as the basis for linking libc.so and to allow production of a stripped-down libc.so that only includes symbols a fixed set of binaries depend on. We could discuss something like this on the musl list.
Rich
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 58 lines · Rich Felker
Quoted 48 lines · Szabolcs Nagy
Quoted 2 lines · Stafford Horne
Quoted 1 line · Szabolcs Nagy
On 27/10/18 05:37, Stafford Horne wrote:
...
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+#undef LINK_SPEC +#define LINK_SPEC "%{h*} \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +#endif /* GCC_OR1K_LINUX_H */note that because of the -static-pie mess each
target needs a more complicatedLINK_SPECnow.Hello,
Does something like this look better?
gcc/config/or1k/linux.h +0
-0@@ -37,8 +37,9 @@ %{static:-Bstatic} \gcc/config/or1k/linux.h line 45
Quoted 10 lines
gcc/config/or1k/linux.h +3
-2%{shared:-shared} \ %{symbolic:-Bsymbolic} \ - %{!static: \ + %{!static:%{!static-pie: \ %{rdynamic:-export-dynamic} \ - %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \ + %{static-pie:-Bstatic -pie --no-dynamic-linker -z text}"#endif /* GCC_OR1K_LINUX_H */ looks ok.
Quoted 8 lines
I have tested this out with or1k-linux-musl, but I get some LD complaints i.e.
.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol
__fini_array_end.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol__fini_array_startThose are some warnings we recently added to LD, perhaps I need to rebuild the libc.a with PIE as well. I will try it out, but if anyone has some suggestions that would be helpful.
Quoted 8 lines
yes, musl does not build libc.a with pic by default, either use a gcc configured with --enable-default-pie or CC='gcc -fPIC' when building musl.
after that -static-pie linking should work.
(maybe musl should have an --enable-static-pie config option to make this simpler)
Quoted 6 lines
For practical purposes, if you want to use static pie, you need a default-pie toolchain. This is because _every_ static lib you might link needs to be built with -fPIE (or -fPIC), and ensuring that happens on a package-by-package basis is largely impractical; at least it's on the same order of magnitude of difficulty as other systems integration/packaging tasks.
Thanks, I kind of figured it out, but it was no so clear when I started.
Quoted 6 lines
However from the musl side it might make sense to produce a libc_pic.a as part of the build process. This would make it easy to replace libc.a with libc_pic.a if desired, and could also be used as the basis for linking libc.so and to allow production of a stripped-down libc.so that only includes symbols a fixed set of binaries depend on. We could discuss something like this on the musl list.
That makes sense.
Thanks Rich for your input.
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
In reply to Szabolcs NagyQuoted 48 lines · Szabolcs Nagy
Quoted 2 lines · Stafford Horne
Quoted 1 line · Szabolcs Nagy
On 27/10/18 05:37, Stafford Horne wrote:
...
Quoted 22 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+#undef LINK_SPEC +#define LINK_SPEC "%{h*} \ + %{static:-Bstatic} \ + %{shared:-shared} \ + %{symbolic:-Bsymbolic} \Quoted 8 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ %{!static: \ + %{rdynamic:-export-dynamic} \ + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + +#endif /* GCC_OR1K_LINUX_H */note that because of the -static-pie mess each
target needs a more complicatedLINK_SPECnow.Hello,
Does something like this look better?
gcc/config/or1k/linux.h +0
-0@@ -37,8 +37,9 @@ %{static:-Bstatic} \gcc/config/or1k/linux.h line 45
Quoted 10 lines
gcc/config/or1k/linux.h +3
-2%{shared:-shared} \ %{symbolic:-Bsymbolic} \ - %{!static: \ + %{!static:%{!static-pie: \ %{rdynamic:-export-dynamic} \ - %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}" + %{!shared:-dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}} \ + %{static-pie:-Bstatic -pie --no-dynamic-linker -z text}"#endif /* GCC_OR1K_LINUX_H */ looks ok.
Quoted 8 lines
I have tested this out with or1k-linux-musl, but I get some LD complaints i.e.
.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol
__fini_array_end.../or1k-linux-musl/bin/ld: .../or1k-linux-musl/lib/libc.a(exit.o): non-pic relocation against symbol__fini_array_startThose are some warnings we recently added to LD, perhaps I need to rebuild the libc.a with PIE as well. I will try it out, but if anyone has some suggestions that would be helpful.
Quoted 8 lines
yes, musl does not build libc.a with pic by default, either use a gcc configured with --enable-default-pie or CC='gcc -fPIC' when building musl.
after that -static-pie linking should work.
(maybe musl should have an --enable-static-pie config option to make this simpler)
Thank's for confirming. I tested this out with your tips and it works.
I use musl-cross-make [0] to build musl, all you really need to do is add 'GCC_CONFIG += --enable-default-pie' to your config.mak file.
-Stafford
PATCH v3 3/3 or1k: gcc: initial support for openrisc
In reply to Stafford HorneQuoted 2 lines · Stafford Horne
I have had some inqueries into helping
bootstrap some linux nommu machines.
For nommu, we'd need to implement an FDPIC ABI.
Otherwise, code segments cannot be mapped separately from data segments. I believe that the arm (32bit) port has recently added support for this, so you may be able to find patches from which to crib.
r~
PATCH v3 3/3 or1k: gcc: initial support for openrisc
Quoted 5 lines · Richard Henderson
Quoted 2 lines · Stafford Horne
I have had some inqueries into helping
bootstrap some linux nommu machines.
Quoted 7 lines
For nommu, we'd need to implement an FDPIC ABI.
Otherwise, code segments cannot be mapped separately from data segments. I believe that the arm (32bit) port has recently added support for this, so you may be able to find patches from which to crib.
The arm patches are not committed yet, they are still under discussion. I plan to submit v4 soon.
Quoted 2 lines
r~
v3 cover OpenRISC port
In reply to Stafford HorneQuoted 7 lines · Stafford Horne
Changes Since v2:
- Add RTEMS patches from Joel Sherrill
- Disable t-softfp-excl as suggsted by Joseph Myers
- Add new architecture flags needed to run on real FPGA's found in testing
* -mror - enable l.ror (rotate right)
* -mshftimm - enable shift/rorate by immediate instructions
- Binutils requirements are now in upstream git
I'll just note quickly that you missed gcc-patches in the Cc. ;-)
r~