Glibc OpenRISC port
v3 cover Glibc OpenRISC port
This is the OpenRISC port for glibc that I have been working on.
Changes since v2:
- Fixed suggestions from Joseph Myers:
- Fix comment style, and description on top of each file
- Make sure macros have parentheses when needed,
- Bump required kernel down to 5.4.0 and document
- Regenerate arch-syscall.h
- Fixed suggestions from Adhemerval:
- Remove kernel_stat.h
- Just set MMAP2_PAGE_UNIT to 8K
- Remove ioctl.c and syscall.c files
- Update TCB alignment to 32 bytes
Changes since v1:
- Update api's as suggested by Florian
- Remove hard float support
- Updates to get all tests passing
- Split patch into managable bits similar to recent ARC port
Documentation:
Architecture / ABI docs:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdf
Test Results:
build-many-glibcs.py:
PASS with mainline ang gcc-11.
Full test suite:
The full suite is running using the gcc-11 branch of GCC, mainline shows issues with math soft-fp.
Note, there are a few more failures compared to before, this is due to me running with a timeout of 30 vs usual 300. It allows the tests to complete faster, but I get a few more timeouts. There were 15 timeouts which I confirm do work if I increase the timeoutfactor. The 2 real failures marked with * below.
# test start: 2021-12-08T19:59:00+09:00
# failures
FAIL:*elf/tst-bz15311
FAIL: locale/tst-localedef-path-norm
FAIL: malloc/tst-dynarray-fail
FAIL: malloc/tst-dynarray-fail-mem
FAIL: nptl/tst-mutex10
FAIL: nss/tst-nss-files-hosts-getent
FAIL: nss/tst-nss-files-hosts-multi
FAIL: posix/tst-regcomp-truncated
FAIL: stdio-common/tst-vfprintf-width-prec
FAIL: stdio-common/tst-vfprintf-width-prec-alloc
FAIL: stdio-common/tst-vfprintf-width-prec-mem
FAIL: string/test-memcpy
FAIL: string/test-memcpy-large
FAIL: string/test-mempcpy
FAIL: string/tst-cmp
FAIL: support/tst-support_blob_repeat
FAIL:*timezone/tst-tzset # test finish: 2021-12-10T22:04:56+09:00
# test duration: 2 days 2 hours 5 minutes and 56 seconds
# test for file: tests.sum
# test wrapper: /home/shorne/work/gnu-toolchain/glibc/scripts/cross-test-ssh.sh --timeoutfactor 30 10.0.0.5 # summary
17 FAIL
4063 PASS
28 UNSUPPORTED
18 XFAILtst-bz15311.out: https://gist.github.com/5a5dacaeef1eac1f2f5d89701d14c0ad tst-tzset.out: https://gist.github.com/b3a548d82cfc9367905e115821a52754 tests.sum: https://gist.github.com/f85a81012c8329b9a95370a30c7b27fe
Stafford Horne (13):
elf: Add reloc for OpenRISC
linux/syscalls: Add or1k_atomic syscall for OpenRISC
or1k: ABI Implementation
or1k: startup and dynamic linking code
or1k: Thread Local Storage support
or1k: Atomics and Locking primitives
or1k: math soft float support
or1k: Linux Syscall Interface
or1k: Linux ABI
or1k: ABI lists
or1k: Build Infrastructure build-many-glibcs.py: add OpenRISC support Documentation for OpenRISC port
NEWS | 4 + README | 1 + elf/elf.h | 37 + scripts/build-many-glibcs.py | 5 + sysdeps/or1k/Implies | 3 + sysdeps/or1k/Makefile | 7 + sysdeps/or1k/__longjmp.S | 55 + sysdeps/or1k/atomic-machine.h | 79 + sysdeps/or1k/bits/endianness.h | 11 + sysdeps/or1k/bits/fenv.h | 69 + sysdeps/or1k/bits/link.h | 51 + sysdeps/or1k/bits/setjmp.h | 32 + sysdeps/or1k/bsd-_setjmp.S | 1 + sysdeps/or1k/bsd-setjmp.S | 1 + sysdeps/or1k/dl-machine.h | 323 +++ sysdeps/or1k/dl-start.S | 98 + sysdeps/or1k/dl-tls.h | 27 + sysdeps/or1k/dl-trampoline.S | 79 + sysdeps/or1k/jmpbuf-offsets.h | 23 + sysdeps/or1k/jmpbuf-unwind.h | 36 + sysdeps/or1k/ldsodefs.h | 40 + sysdeps/or1k/libc-tls.c | 34 + sysdeps/or1k/libm-test-ulps | 1112 +++++++++ sysdeps/or1k/libm-test-ulps-name | 1 + sysdeps/or1k/machine-gmon.h | 35 + sysdeps/or1k/memusage.h | 21 + sysdeps/or1k/nofpu/Implies | 1 + sysdeps/or1k/nofpu/math-tests-exceptions.h | 29 + sysdeps/or1k/nofpu/math-tests-rounding.h | 28 + sysdeps/or1k/nptl/Makefile | 21 + sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 + sysdeps/or1k/nptl/pthreaddef.h | 36 + sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++ sysdeps/or1k/preconfigure | 34 + sysdeps/or1k/setjmp.S | 56 + sysdeps/or1k/sfp-machine.h | 93 + sysdeps/or1k/sotruss-lib.c | 51 + sysdeps/or1k/stackinfo.h | 34 + sysdeps/or1k/start.S | 99 + sysdeps/or1k/sysdep.h | 83 + sysdeps/or1k/tininess.h | 1 + sysdeps/or1k/tst-audit.h | 24 + sysdeps/unix/sysv/linux/or1k/Implies | 3 + sysdeps/unix/sysv/linux/or1k/Makefile | 12 + sysdeps/unix/sysv/linux/or1k/arch-syscall.h | 325 +++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 + sysdeps/unix/sysv/linux/or1k/bits/timesize.h | 19 + sysdeps/unix/sysv/linux/or1k/c++-types.data | 67 + sysdeps/unix/sysv/linux/or1k/clone.c | 61 + sysdeps/unix/sysv/linux/or1k/configure | 4 + sysdeps/unix/sysv/linux/or1k/configure.ac | 4 + sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 + sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h | 41 + sysdeps/unix/sysv/linux/or1k/ld.abilist | 5 + .../sysv/linux/or1k/libBrokenLocale.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libanl.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libc.abilist | 2122 +++++++++++++++++ .../sysv/linux/or1k/libc_malloc_debug.abilist | 26 + sysdeps/unix/sysv/linux/or1k/libcrypt.abilist | 2 + sysdeps/unix/sysv/linux/or1k/libdl.abilist | 0 sysdeps/unix/sysv/linux/or1k/libm.abilist | 759 ++++++ sysdeps/unix/sysv/linux/or1k/libnsl.abilist | 121 + .../unix/sysv/linux/or1k/libpthread.abilist | 0 .../unix/sysv/linux/or1k/libresolv.abilist | 55 + sysdeps/unix/sysv/linux/or1k/librt.abilist | 0 .../unix/sysv/linux/or1k/libthread_db.abilist | 40 + sysdeps/unix/sysv/linux/or1k/libutil.abilist | 1 + sysdeps/unix/sysv/linux/or1k/localplt.data | 14 + sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 + sysdeps/unix/sysv/linux/or1k/mmap_internal.h | 28 + sysdeps/unix/sysv/linux/or1k/or1k_clone.S | 89 + sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 + sysdeps/unix/sysv/linux/or1k/shlib-versions | 2 + sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 + sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 + sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 + sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/sysdep.c | 34 + sysdeps/unix/sysv/linux/or1k/sysdep.h | 201 ++ sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 + sysdeps/unix/sysv/linux/syscall-names.list | 1 + 82 files changed, 7575 insertions(+) create mode 100644 sysdeps/or1k/Implies create mode 100644 sysdeps/or1k/Makefile create mode 100644 sysdeps/or1k/__longjmp.S create mode 100644 sysdeps/or1k/atomic-machine.h create mode 100644 sysdeps/or1k/bits/endianness.h create mode 100644 sysdeps/or1k/bits/fenv.h create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/bits/setjmp.h create mode 100644 sysdeps/or1k/bsd-_setjmp.S create mode 100644 sysdeps/or1k/bsd-setjmp.S create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/dl-trampoline.S create mode 100644 sysdeps/or1k/jmpbuf-offsets.h create mode 100644 sysdeps/or1k/jmpbuf-unwind.h create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/libm-test-ulps create mode 100644 sysdeps/or1k/libm-test-ulps-name create mode 100644 sysdeps/or1k/machine-gmon.h create mode 100644 sysdeps/or1k/memusage.h create mode 100644 sysdeps/or1k/nofpu/Implies create mode 100644 sysdeps/or1k/nofpu/math-tests-exceptions.h create mode 100644 sysdeps/or1k/nofpu/math-tests-rounding.h create mode 100644 sysdeps/or1k/nptl/Makefile create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/preconfigure create mode 100644 sysdeps/or1k/setjmp.S create mode 100644 sysdeps/or1k/sfp-machine.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/stackinfo.h create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/sysdep.h create mode 100644 sysdeps/or1k/tininess.h create mode 100644 sysdeps/or1k/tst-audit.h create mode 100644 sysdeps/unix/sysv/linux/or1k/Implies create mode 100644 sysdeps/unix/sysv/linux/or1k/Makefile create mode 100644 sysdeps/unix/sysv/linux/or1k/arch-syscall.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/timesize.h create mode 100644 sysdeps/unix/sysv/linux/or1k/c++-types.data create mode 100644 sysdeps/unix/sysv/linux/or1k/clone.c create mode 100644 sysdeps/unix/sysv/linux/or1k/configure create mode 100644 sysdeps/unix/sysv/linux/or1k/configure.ac create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ld.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libanl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc_malloc_debug.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libcrypt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libdl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libm.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libnsl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libpthread.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libresolv.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/librt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libthread_db.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libutil.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/localplt.data create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/mmap_internal.h create mode 100644 sysdeps/unix/sysv/linux/or1k/or1k_clone.S create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/shlib-versions create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.c create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.sym
Signature · 1 line
2.31.1
PATCH v3 1/13 elf: Add reloc for OpenRISC
--- elf/elf.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
elf/elf.h +37 -0
@@ -4125,4 +4125,41 @@ enum#define R_ARC_TLS_LE_S9 0x4a#define R_ARC_TLS_LE_32 0x4b +/* OpenRISC 1000 specific relocs. */ +#define R_OR1K_NONE 0 +#define R_OR1K_32 1 +#define R_OR1K_16 2 +#define R_OR1K_8 3 +#define R_OR1K_LO_16_IN_INSN 4 +#define R_OR1K_HI_16_IN_INSN 5 +#define R_OR1K_INSN_REL_26 6 +#define R_OR1K_GNU_VTENTRY 7 +#define R_OR1K_GNU_VTINHERIT 8 +#define R_OR1K_32_PCREL 9 +#define R_OR1K_16_PCREL 10 +#define R_OR1K_8_PCREL 11 +#define R_OR1K_GOTPC_HI16 12 +#define R_OR1K_GOTPC_LO16 13 +#define R_OR1K_GOT16 14 +#define R_OR1K_PLT26 15 +#define R_OR1K_GOTOFF_HI16 16 +#define R_OR1K_GOTOFF_LO16 17 +#define R_OR1K_COPY 18 +#define R_OR1K_GLOB_DAT 19 +#define R_OR1K_JMP_SLOT 20 +#define R_OR1K_RELATIVE 21 +#define R_OR1K_TLS_GD_HI16 22 +#define R_OR1K_TLS_GD_LO16 23 +#define R_OR1K_TLS_LDM_HI16 24 +#define R_OR1K_TLS_LDM_LO16 25 +#define R_OR1K_TLS_LDO_HI16 26 +#define R_OR1K_TLS_LDO_LO16 27 +#define R_OR1K_TLS_IE_HI16 28 +#define R_OR1K_TLS_IE_LO16 29 +#define R_OR1K_TLS_LE_HI16 30 +#define R_OR1K_TLS_LE_LO16 31 +#define R_OR1K_TLS_TPOFF 32 +#define R_OR1K_TLS_DTPOFF 33 +#define R_OR1K_TLS_DTPMOD 34 +#endif /* elf.h */
Signature · 1 line
2.31.1
PATCH v3 1/13 elf: Add reloc for OpenRISC
The values match binutils ones.
LGTM, thanks.
Quoted 50 lines · Stafford Horne via Libc-alpha
--- elf/elf.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)elf/elf.h +37
-0@@ -4125,4 +4125,41 @@ enum#define R_ARC_TLS_LE_S9 0x4a#define R_ARC_TLS_LE_32 0x4b +/* OpenRISC 1000 specific relocs. */ +#define R_OR1K_NONE 0 +#define R_OR1K_32 1 +#define R_OR1K_16 2 +#define R_OR1K_8 3 +#define R_OR1K_LO_16_IN_INSN 4 +#define R_OR1K_HI_16_IN_INSN 5 +#define R_OR1K_INSN_REL_26 6 +#define R_OR1K_GNU_VTENTRY 7 +#define R_OR1K_GNU_VTINHERIT 8 +#define R_OR1K_32_PCREL 9 +#define R_OR1K_16_PCREL 10 +#define R_OR1K_8_PCREL 11 +#define R_OR1K_GOTPC_HI16 12 +#define R_OR1K_GOTPC_LO16 13 +#define R_OR1K_GOT16 14 +#define R_OR1K_PLT26 15 +#define R_OR1K_GOTOFF_HI16 16 +#define R_OR1K_GOTOFF_LO16 17 +#define R_OR1K_COPY 18 +#define R_OR1K_GLOB_DAT 19 +#define R_OR1K_JMP_SLOT 20 +#define R_OR1K_RELATIVE 21 +#define R_OR1K_TLS_GD_HI16 22 +#define R_OR1K_TLS_GD_LO16 23 +#define R_OR1K_TLS_LDM_HI16 24 +#define R_OR1K_TLS_LDM_LO16 25 +#define R_OR1K_TLS_LDO_HI16 26 +#define R_OR1K_TLS_LDO_LO16 27 +#define R_OR1K_TLS_IE_HI16 28 +#define R_OR1K_TLS_IE_LO16 29 +#define R_OR1K_TLS_LE_HI16 30 +#define R_OR1K_TLS_LE_LO16 31 +#define R_OR1K_TLS_TPOFF 32 +#define R_OR1K_TLS_DTPOFF 33 +#define R_OR1K_TLS_DTPMOD 34 +#endif /* elf.h */
PATCH v3 2/13 linux/syscalls: Add or1k_atomic syscall for OpenRISC
In reply to Stafford Horne--- sysdeps/unix/sysv/linux/syscall-names.list | 1 + 1 file changed, 1 insertion(+)
sysdeps/unix/sysv/linux/syscall-names.list +1 -0
@@ -304,6 +304,7 @@ open_by_handle_at open_tree openat openat2 +or1k_atomic osf_adjtime osf_afs_syscall osf_alt_plock
Signature · 1 line
2.31.1
PATCH v3 2/13 linux/syscalls: Add or1k_atomic syscall for OpenRISC
It matches kernel definition.
LGTM, thanks.
Quoted 16 lines · Stafford Horne via Libc-alpha
--- sysdeps/unix/sysv/linux/syscall-names.list | 1 + 1 file changed, 1 insertion(+)sysdeps/unix/sysv/linux/syscall-names.list +1
-0@@ -304,6 +304,7 @@ open_by_handle_at open_tree openat openat2 +or1k_atomic osf_adjtime osf_afs_syscall osf_alt_plock
PATCH v3 3/13 or1k: ABI Implementation
In reply to Stafford HorneThis code deals with the OpenRISC ABI.
--- sysdeps/or1k/__longjmp.S | 55 ++++++++++++++++++++++ sysdeps/or1k/bits/endianness.h | 11 +++++ sysdeps/or1k/bits/setjmp.h | 32 +++++++++++++ sysdeps/or1k/bsd-_setjmp.S | 1 + sysdeps/or1k/bsd-setjmp.S | 1 + sysdeps/or1k/dl-trampoline.S | 79 ++++++++++++++++++++++++++++++++ sysdeps/or1k/jmpbuf-offsets.h | 23 ++++++++++ sysdeps/or1k/jmpbuf-unwind.h | 36 +++++++++++++++ sysdeps/or1k/machine-gmon.h | 35 ++++++++++++++ sysdeps/or1k/memusage.h | 21 +++++++++ sysdeps/or1k/setjmp.S | 56 +++++++++++++++++++++++ sysdeps/or1k/sysdep.h | 83 ++++++++++++++++++++++++++++++++++ 12 files changed, 433 insertions(+) create mode 100644 sysdeps/or1k/__longjmp.S create mode 100644 sysdeps/or1k/bits/endianness.h create mode 100644 sysdeps/or1k/bits/setjmp.h create mode 100644 sysdeps/or1k/bsd-_setjmp.S create mode 100644 sysdeps/or1k/bsd-setjmp.S create mode 100644 sysdeps/or1k/dl-trampoline.S create mode 100644 sysdeps/or1k/jmpbuf-offsets.h create mode 100644 sysdeps/or1k/jmpbuf-unwind.h create mode 100644 sysdeps/or1k/machine-gmon.h create mode 100644 sysdeps/or1k/memusage.h create mode 100644 sysdeps/or1k/setjmp.S create mode 100644 sysdeps/or1k/sysdep.h
sysdeps/or1k/__longjmp.S new file +55 -0
@@ -0,0 +1,55 @@ +/* longjmp, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <features.h> +#define _ASM +#define _SETJMP_H +#include <bits/setjmp.h> + + .globl __longjmp; + .type __longjmp, @function; + .align 4; + +__longjmp: + l.lwz r1, 0(r3) + l.lwz r2, 4(r3) + + /* if r4 is 0, something wrong, so set it to 1 */ + l.sfeqi r4, 0x0 + l.bnf 1f /* r4 != 0, longjmp value sensible */ + l.nop + l.ori r4, r0, 0x1 /* make nonzero */ +1: + l.addi r11, r4, 0 + l.lwz r9, 8(r3) + l.lwz r10, 12(r3) + l.lwz r14, 16(r3) + l.lwz r16, 20(r3) + l.lwz r18, 24(r3) + l.lwz r20, 28(r3) + l.lwz r22, 32(r3) + l.lwz r24, 36(r3) + l.lwz r26, 40(r3) + l.lwz r28, 44(r3) + l.lwz r30, 48(r3) + l.jr r9 + l.nop + .size __longjmp, . - __longjmp + +libc_hidden_def(__longjmp)
sysdeps/or1k/bits/endianness.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _BITS_ENDIANNESS_H +#define _BITS_ENDIANNESS_H 1 + +#ifndef _BITS_ENDIAN_H +# error "Never use <bits/endianness.h> directly; include <endian.h> instead." +#endif + +/* OpenRISC is big-endian. */ +#define __BYTE_ORDER __BIG_ENDIAN + +#endif /* bits/endianness.h */
sysdeps/or1k/bits/setjmp.h new file +32 -0
@@ -0,0 +1,32 @@ +/* Define the machine-dependent type `jmp_buf'. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + + +#ifndef _OR1K_BITS_SETJMP_H +#define _OR1K_BITS_SETJMP_H 1 + +#if !defined _SETJMP_H && !defined _PTHREAD_H +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead." +#endif + +#ifndef _ASM +typedef long int __jmp_buf [13 ]; +#endif + +#endif /* _OR1K_BITS_SETJMP_H */
sysdeps/or1k/bsd-_setjmp.S new file +1 -0
@@ -0,0 +1 @@ +/* _setjmp is in setjmp.S */
sysdeps/or1k/bsd-setjmp.S new file +1 -0
@@ -0,0 +1 @@ +/* setjmp is in setjmp.S */
sysdeps/or1k/dl-trampoline.S new file +79 -0
79 lines not on this page · raw message
sysdeps/or1k/jmpbuf-offsets.h new file +23 -0
@@ -0,0 +1,23 @@ +/* Private macros for accessing __jmp_buf contents. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define __JMP_BUF_SP 0 + +/* Helper for generic function ____longjmp_chk. */ +#define JB_FRAME_ADDRESS (buf) \ + ((void *) (unsigned long) (buf[__JMP_BUF_SP]))
sysdeps/or1k/jmpbuf-unwind.h new file +36 -0
@@ -0,0 +1,36 @@ +/* Macros to help frame unwinding using jmpbuf. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <setjmp.h> +#include <jmpbuf-offsets.h> +#include <stdint.h> +#include <unwind.h> + +/* Test if longjmp to JMPBUF would unwind the frame +containing a local variable at ADDRESS. */ +#define _JMPBUF_UNWINDS (jmpbuf, address, demangle) \ + ((void *) (address) < (void *) demangle (jmpbuf[__JMP_BUF_SP])) + +#define _JMPBUF_CFA_UNWINDS_ADJ (_jmpbuf, _context, _adj) \ + _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj) + +#define _JMPBUF_UNWINDS_ADJ (_jmpbuf, _address, _adj) \ + ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf)[__JMP_BUF_SP] - (_adj)) + +/* We use the normal longjmp for unwinding. */ +#define __libc_unwind_longjmp (buf, val) __libc_longjmp (buf, val)
sysdeps/or1k/machine-gmon.h new file +35 -0
@@ -0,0 +1,35 @@ +/* Machine-dependent definitions for profiling support. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> + +#define _MCOUNT_DECL (frompc, selfpc) \ +static void \ +__mcount_internal (unsigned long int frompc, unsigned long int selfpc) + +/* This is very simple as gcc does all the heavy lifting at the _mcount +call site. GCC passes in the return address of the function calling +_mcount. */ + +#define MCOUNT \ +void \ +_mcount (void *frompc) \ +{ \ + __mcount_internal ((unsigned long int) frompc, \ + (unsigned long int) __builtin_return_address (0)); \ +}
sysdeps/or1k/memusage.h new file +21 -0
@@ -0,0 +1,21 @@ +/* Definitions for memory usage profiling. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#define GETSP () ({ register uintptr_t stack_ptr asm ("r1"); stack_ptr; }) + +#include <sysdeps/generic/memusage.h>
sysdeps/or1k/setjmp.S new file +56 -0
56 lines not on this page · raw message
sysdeps/or1k/sysdep.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 3/13 or1k: ABI Implementation
Quoted 1 line · Stafford Horne via Libc-alpha
This code deals with the OpenRISC ABI.
Some comments below.
Quoted 52 lines
--- sysdeps/or1k/__longjmp.S | 55 ++++++++++++++++++++++ sysdeps/or1k/bits/endianness.h | 11 +++++ sysdeps/or1k/bits/setjmp.h | 32 +++++++++++++ sysdeps/or1k/bsd-_setjmp.S | 1 + sysdeps/or1k/bsd-setjmp.S | 1 + sysdeps/or1k/dl-trampoline.S | 79 ++++++++++++++++++++++++++++++++ sysdeps/or1k/jmpbuf-offsets.h | 23 ++++++++++ sysdeps/or1k/jmpbuf-unwind.h | 36 +++++++++++++++ sysdeps/or1k/machine-gmon.h | 35 ++++++++++++++ sysdeps/or1k/memusage.h | 21 +++++++++ sysdeps/or1k/setjmp.S | 56 +++++++++++++++++++++++ sysdeps/or1k/sysdep.h | 83 ++++++++++++++++++++++++++++++++++ 12 files changed, 433 insertions(+) create mode 100644 sysdeps/or1k/__longjmp.S create mode 100644 sysdeps/or1k/bits/endianness.h create mode 100644 sysdeps/or1k/bits/setjmp.h create mode 100644 sysdeps/or1k/bsd-_setjmp.S create mode 100644 sysdeps/or1k/bsd-setjmp.S create mode 100644 sysdeps/or1k/dl-trampoline.S create mode 100644 sysdeps/or1k/jmpbuf-offsets.h create mode 100644 sysdeps/or1k/jmpbuf-unwind.h create mode 100644 sysdeps/or1k/machine-gmon.h create mode 100644 sysdeps/or1k/memusage.h create mode 100644 sysdeps/or1k/setjmp.S create mode 100644 sysdeps/or1k/sysdep.hsysdeps/or1k/__longjmp.S new file +19
-0@@ -0,0 +1,55 @@ +/* longjmp, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ +
sysdeps/or1k/__longjmp.S line 29
Quoted 10 lines
sysdeps/or1k/__longjmp.S new file +10
-0+#include <features.h> +#define _ASM +#define _SETJMP_H +#include <bits/setjmp.h> + + .globl __longjmp; + .type __longjmp, @function; + .align 4; + +__longjmp:
Use ENTRY/END here, as other setjmp functions are doing.
Quoted 33 lines
sysdeps/or1k/__longjmp.S new file +26
-0+ l.lwz r1, 0(r3) + l.lwz r2, 4(r3) + + /* if r4 is 0, something wrong, so set it to 1 */ + l.sfeqi r4, 0x0 + l.bnf 1f /* r4 != 0, longjmp value sensible */ + l.nop + l.ori r4, r0, 0x1 /* make nonzero */ +1: + l.addi r11, r4, 0 + l.lwz r9, 8(r3) + l.lwz r10, 12(r3) + l.lwz r14, 16(r3) + l.lwz r16, 20(r3) + l.lwz r18, 24(r3) + l.lwz r20, 28(r3) + l.lwz r22, 32(r3) + l.lwz r24, 36(r3) + l.lwz r26, 40(r3) + l.lwz r28, 44(r3) + l.lwz r30, 48(r3) + l.jr r9 + l.nop + .size __longjmp, . - __longjmp + +libc_hidden_def(__longjmp)sysdeps/or1k/bits/endianness.h new file +1
-0@@ -0,0 +1,11 @@ +#ifndef _BITS_ENDIANNESS_H
sysdeps/or1k/bits/endianness.h line 11
Quoted 10 lines
sysdeps/or1k/bits/endianness.h new file +10
-0+#define _BITS_ENDIANNESS_H 1 + +#ifndef _BITS_ENDIAN_H +# error "Never use <bits/endianness.h> directly; include <endian.h> instead." +#endif + +/* OpenRISC is big-endian. */ +#define __BYTE_ORDER __BIG_ENDIAN + +#endif /* bits/endianness.h */
Ok.
Quoted 28 lines
sysdeps/or1k/bits/setjmp.h new file +22
-0@@ -0,0 +1,32 @@ +/* Define the machine-dependent type `jmp_buf'. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + + +#ifndef _OR1K_BITS_SETJMP_H +#define _OR1K_BITS_SETJMP_H 1
sysdeps/or1k/bits/setjmp.h line 32
Quoted 10 lines
sysdeps/or1k/bits/setjmp.h new file +10
-0+ +#if !defined _SETJMP_H && !defined _PTHREAD_H +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead." +#endif + +#ifndef _ASM +typedef long int __jmp_buf [13 ]; +#endif + +#endif /* _OR1K_BITS_SETJMP_H */
Ok.
Quoted 89 lines
sysdeps/or1k/bsd-_setjmp.S new file +1
-0@@ -0,0 +1 @@ +/* _setjmp is in setjmp.S */sysdeps/or1k/bsd-setjmp.S new file +1
-0@@ -0,0 +1 @@ +/* setjmp is in setjmp.S */sysdeps/or1k/dl-trampoline.S new file +69
-0@@ -0,0 +1,79 @@ +/* Machine-dependent ELF runtime symbol resolution, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This code is used to call _dl_linux_resolver (dl-runtime.c). + + We assume that R11 contains the relocation offset and R12 contains + link_map (_DYNAMIC). This must be consistent with the JUMP_SLOT + layout generated by binutils. */ + + .section .text + .align 4 + + .global _dl_runtime_resolve + .type _dl_runtime_resolve, @function + +_dl_runtime_resolve: + .cfi_startproc + l.sw -4(r1), r9 + l.sw -8(r1), r1 + + /* save function arguments. */ + l.sw -12(r1), r3 + l.sw -16(r1), r4 + l.sw -20(r1), r5 + l.sw -24(r1), r6 + l.sw -28(r1), r7 + l.sw -32(r1), r8 + + .cfi_offset 9, -4 + .cfi_offset 1, -8 + .cfi_offset 3, -12 + .cfi_offset 4, -16 + .cfi_offset 5, -20 + .cfi_offset 6, -24 + .cfi_offset 7, -28 + .cfi_offset 8, -32 + + l.addi r1,r1, -32 + .cfi_def_cfa_offset 32 + + l.ori r3, r12, 0 + l.ori r4, r11, 0 + + l.jal _dl_fixup + l.nop + + /* Restore function arguments. */ + l.addi r1,r1, 32 + l.lwz r8, -32(r1) + l.lwz r7, -28(r1) + l.lwz r6, -24(r1) + l.lwz r5, -20(r1) + l.lwz r4, -16(r1)
sysdeps/or1k/dl-trampoline.S line 79
Quoted 10 lines
sysdeps/or1k/dl-trampoline.S new file +10
-0+ l.lwz r3, -12(r1) + + /* restore return address. */ + l.lwz r9, -4(r1) + + l.jr r11 + l.nop + + .cfi_endproc + .size _dl_runtime_resolve, . - _dl_runtime_resolve
It seems that _dl_runtime_profile is not implemented and explicit disabled on sysdeps/or1k/dl-machine.h. In this case I think it would be better to explicit disable it on configure:
configure.ac +9 -0
@@ -525,6 +525,9 @@ libc_config_ok=no # whether to use such directories. with_fp_cond=1 +# A preconfigure script may disable profile support +with_profile=yes + dnl Let sysdeps/*/preconfigure act here. LIBC_PRECONFIGURE([$srcdir], [for sysdeps])
@@ -1891,6 +1894,12 @@ LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie]) libc_cv_multidir=`${CC-cc} $CFLAGS $CPPFLAGS -print-multi-directory` AC_SUBST(libc_cv_multidir) +if test "x$profile" != xno; then + if test "x$with_profile" == xno; then + AC_MSG_ERROR([ABI does not support profiling]) + fi +fi + AC_SUBST(profile) AC_SUBST(static_nss)
sysdeps/or1k/preconfigure +1 -0
@@ -32,3 +32,4 @@ or1k*) ;; esac +with_profile=no
Quoted 290 lines
sysdeps/or1k/jmpbuf-offsets.h new file +23
-0@@ -0,0 +1,23 @@ +/* Private macros for accessing __jmp_buf contents. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define __JMP_BUF_SP 0 + +/* Helper for generic function ____longjmp_chk. */ +#define JB_FRAME_ADDRESS (buf) \ + ((void *) (unsigned long) (buf[__JMP_BUF_SP]))sysdeps/or1k/jmpbuf-unwind.h new file +36
-0@@ -0,0 +1,36 @@ +/* Macros to help frame unwinding using jmpbuf. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <setjmp.h> +#include <jmpbuf-offsets.h> +#include <stdint.h> +#include <unwind.h> + +/* Test if longjmp to JMPBUF would unwind the frame +containing a local variable at ADDRESS. */ +#define _JMPBUF_UNWINDS (jmpbuf, address, demangle) \ + ((void *) (address) < (void *) demangle (jmpbuf[__JMP_BUF_SP])) + +#define _JMPBUF_CFA_UNWINDS_ADJ (_jmpbuf, _context, _adj) \ + _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj) + +#define _JMPBUF_UNWINDS_ADJ (_jmpbuf, _address, _adj) \ + ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf)[__JMP_BUF_SP] - (_adj)) + +/* We use the normal longjmp for unwinding. */ +#define __libc_unwind_longjmp (buf, val) __libc_longjmp (buf, val)sysdeps/or1k/machine-gmon.h new file +35
-0@@ -0,0 +1,35 @@ +/* Machine-dependent definitions for profiling support. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> + +#define _MCOUNT_DECL (frompc, selfpc) \ +static void \ +__mcount_internal (unsigned long int frompc, unsigned long int selfpc) + +/* This is very simple as gcc does all the heavy lifting at the _mcount +call site. GCC passes in the return address of the function calling +_mcount. */ + +#define MCOUNT \ +void \ +_mcount (void *frompc) \ +{ \ + __mcount_internal ((unsigned long int) frompc, \ + (unsigned long int) __builtin_return_address (0)); \ +}sysdeps/or1k/memusage.h new file +21
-0@@ -0,0 +1,21 @@ +/* Definitions for memory usage profiling. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#define GETSP () ({ register uintptr_t stack_ptr asm ("r1"); stack_ptr; }) + +#include <sysdeps/generic/memusage.h> sysdeps/or1k/setjmp.S new file +56
-0@@ -0,0 +1,56 @@ +/* setjmp, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep.h> +#define _ASM +#define _SETJMP_H +#include <bits/setjmp.h> + +ENTRY (_setjmp) + l.addi r4, r0, 0 /* Set second argument to 0. */ + l.j .Local__sigsetjmp + l.nop +END (_setjmp) +libc_hidden_def (_setjmp) + +ENTRY (setjmp) + l.addi r4, r0, 1 /* Set second argument to 1. */ + l.j .Local__sigsetjmp + l.nop +END (setjmp) + +ENTRY (__sigsetjmp) +.Local__sigsetjmp: + l.sw 0(r3), r1 + l.sw 4(r3), r2 + l.sw 8(r3), r9 + l.sw 12(r3), r10 + l.sw 16(r3), r14 + l.sw 20(r3), r16 + l.sw 24(r3), r18 + l.sw 28(r3), r20 + l.sw 32(r3), r22 + l.sw 36(r3), r24 + l.sw 40(r3), r26 + l.sw 44(r3), r28 + l.sw 48(r3), r30 + l.j __sigjmp_save + l.nop +END (__sigsetjmp) +hidden_def (__sigsetjmp)sysdeps/or1k/sysdep.h new file +83
-0@@ -0,0 +1,83 @@ +/* Assembler macro definitions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdeps/generic/sysdep.h> +#include <features.h> + +#if defined __ASSEMBLER__ || definedREQUEST_ASSEMBLER_MACROS + +/* Make use of .size directive. */ +#define ASM_SIZE_DIRECTIVE (name) .size name,.-name; + +/* Define an entry point visible from C. */ +#define ENTRY (name) \ + .globl C_SYMBOL_NAME(name); \ + .type C_SYMBOL_NAME(name), at function; \ + .align 4; \ + C_LABEL(name) \ + cfi_startproc; \ + CALL_MCOUNT + +#undef END +#define END (name) \ + cfi_endproc; \ + ASM_SIZE_DIRECTIVE(name) + +/* Since C identifiers are not normally prefixed with an underscore +on this system, the asm identifier `syscall_error' intrudes on the +C name space. Make sure we use an innocuous name. */ +#define syscall_error __syscall_error + +/* If compiled for profiling, call `mcount' at the start of each function. */ +#ifdef PROF +# ifdef __PIC__ +# define CALL_MCOUNT \ + l.addi r1, r1, -8; \ + l.sw 0(r1), r9; \ + l.sw 4(r1), r3; \ + l.ori r3, r9, 0; \ + l.j plt(_mcount); \ + l.nop; \ + l.lwz r9, 0(r1); \ + l.lwz r3, 4(r1); \ + l.addi r1, r1, 8; +# else +# define CALL_MCOUNT \ + l.addi r1, r1, -8; \ + l.sw 0(r1), r9; \ + l.sw 4(r1), r3; \ + l.ori r3, r9, 0; \ + l.movhi r15, hi(_mcount); \ + l.ori r15, r15, lo(_mcount); \ + l.jr r15; \ + l.nop; \ + l.lwz r9, 0(r1); \ + l.lwz r3, 4(r1); \ + l.addi r1, r1, 8; +# endif +#else +# define CALL_MCOUNT /* Do nothing. */ +#endif + +/* Local label name for asm code. */ +#define L (name) .L##name + +/* Specify the size in bytes of a machine register. */ +#define REGSIZE 4 + +#endif /* __ASSEMBLER__ */
PATCH v3 3/13 or1k: ABI Implementation
configure.ac LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie]) · line 1899
Quoted 3 lines · Adhemerval Zanella via Libc-alpha
configure.ac +3
-0+if test "x$profile" != xno; then + if test "x$with_profile" == xno; then + AC_MSG_ERROR([ABI does not support profiling])
Using == in test is a bashism.
I'd expect such a change to require the build-many-glibcs.py configuration for OpenRISC to use --disable-profile.
Signature · 2 lines
Joseph S. Myers joseph at codesourcery.com
PATCH v3 3/13 or1k: ABI Implementation
Quoted 11 lines · Joseph Myers
configure.ac LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie]) · line 1899
Quoted 3 lines · Adhemerval Zanella via Libc-alpha
configure.ac +3
-0+if test "x$profile" != xno; then + if test "x$with_profile" == xno; then + AC_MSG_ERROR([ABI does not support profiling])Using == in test is a bashism.
I'd expect such a change to require the
build-many-glibcs.pyconfiguration for OpenRISC to use --disable-profile.
I ended up mixing up things and what or1k does not support is LD_PROFILE instead of --enable-profile. In this case I am not sure if it would be better to just not enable it (by ignoring the LD_PROFILE handling in rtld.c or dl-support.c) and emitting a warning or by just dumping and error at process initialization.
PATCH v3 3/13 or1k: ABI Implementation
Quoted 13 lines · Adhemerval Zanella
Quoted 9 lines · Joseph Myers
configure.ac LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie]) · line 1899
Quoted 3 lines · Adhemerval Zanella via Libc-alpha
configure.ac +3
-0+if test "x$profile" != xno; then + if test "x$with_profile" == xno; then + AC_MSG_ERROR([ABI does not support profiling])Using == in test is a bashism.
I'd expect such a change to require the
build-many-glibcs.pyconfiguration
Quoted 9 lines
Quoted 2 lines
for OpenRISC to use --disable-profile.
I ended up mixing up things and what or1k does not support is
LD_PROFILEinstead of --enable-profile. In this case I am not sure if it would be better to just not enable it (by ignoring theLD_PROFILEhandling inrtld.cordl-support.c) and emitting a warning or by just dumping and error at process initialization.
I checked, new ports like csky and arc also do not seem to support LD_PROFILE. They choose not to leave a placeholder block in dl-machine.h like I did in or1k.
I could remove the comment, or replace it with an abort, but I prefer to keep it as it makes it clear where to add the dynamic linker profile hook.
-Stafford
Quoted 1 line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.librecores.org/pipermail/openrisc/attachments/20211216/34746710/attachment.htm>
PATCH v3 3/13 or1k: ABI Implementation
Quoted 26 lines · Stafford Horne
On Wed, Dec 15, 2021, 10:15 AM Adhemerval Zanella <adhemerval.zanella at linaro.org <mailto:[email protected]>> wrote:
On 14/12/2021 19:43, Joseph Myers wrote:
> On Tue, 14 Dec 2021, Adhemerval Zanella via Libc-alpha wrote:
>
>> +if test "x$profile" != xno; then
>> + if test "x$with_profile" == xno; then
>> +AC_MSG_ERROR([ABI does not support profiling])
>
> Using == in test is a bashism.
>
> I'd expect such a change to require thebuild-many-glibcs.pyconfiguration > for OpenRISC to use --disable-profile.
>I ended up mixing up things and what or1k does not support is
LD_PROFILEinstead of --enable-profile. In this case I am not sure if it would be better to just not enable it (by ignoring theLD_PROFILEhandling inrtld.cordl-support.c) and emitting a warning or by just dumping and error at process initialization.
Quoted 3 lines
I checked, new ports like csky and arc also do not seem to support LD_PROFILE. They choose not to leave a placeholder block in
dl-machine.hlike I did in or1k.I could remove the comment, or replace it with an abort, but I prefer to keep it as it makes it clear where to add the dynamic linker profile hook.
I think we should remove the comments, the code might ended up being not updated.
LD_PROFILE seems to be not a really used feature, I will try to clean this up by adding an internal option that if the port that does not support we, rtld at least disable all the required code and not start the profile process (like preparing the file, etc).
PATCH v3 3/13 or1k: ABI Implementation
In reply to Adhemerval ZanellaQuoted 63 lines · Adhemerval Zanella
Quoted 1 line · Stafford Horne via Libc-alpha
This code deals with the OpenRISC ABI.
Some comments below.
Quoted 56 lines
--- sysdeps/or1k/__longjmp.S | 55 ++++++++++++++++++++++ sysdeps/or1k/bits/endianness.h | 11 +++++ sysdeps/or1k/bits/setjmp.h | 32 +++++++++++++ sysdeps/or1k/bsd-_setjmp.S | 1 + sysdeps/or1k/bsd-setjmp.S | 1 + sysdeps/or1k/dl-trampoline.S | 79 ++++++++++++++++++++++++++++++++ sysdeps/or1k/jmpbuf-offsets.h | 23 ++++++++++ sysdeps/or1k/jmpbuf-unwind.h | 36 +++++++++++++++ sysdeps/or1k/machine-gmon.h | 35 ++++++++++++++ sysdeps/or1k/memusage.h | 21 +++++++++ sysdeps/or1k/setjmp.S | 56 +++++++++++++++++++++++ sysdeps/or1k/sysdep.h | 83 ++++++++++++++++++++++++++++++++++ 12 files changed, 433 insertions(+) create mode 100644 sysdeps/or1k/__longjmp.S create mode 100644 sysdeps/or1k/bits/endianness.h create mode 100644 sysdeps/or1k/bits/setjmp.h create mode 100644 sysdeps/or1k/bsd-_setjmp.S create mode 100644 sysdeps/or1k/bsd-setjmp.S create mode 100644 sysdeps/or1k/dl-trampoline.S create mode 100644 sysdeps/or1k/jmpbuf-offsets.h create mode 100644 sysdeps/or1k/jmpbuf-unwind.h create mode 100644 sysdeps/or1k/machine-gmon.h create mode 100644 sysdeps/or1k/memusage.h create mode 100644 sysdeps/or1k/setjmp.S create mode 100644 sysdeps/or1k/sysdep.hsysdeps/or1k/__longjmp.S new file +23
-0@@ -0,0 +1,55 @@ +/* longjmp, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <features.h> +#define _ASM +#define _SETJMP_H +#include <bits/setjmp.h>
Quoted 8 lines
sysdeps/or1k/__longjmp.S line 29
Quoted 6 lines
sysdeps/or1k/__longjmp.S new file +6
-0+ + .globl __longjmp; + .type __longjmp, @function; + .align 4; + +__longjmp:Use ENTRY/END here, as other setjmp functions are doing.
OK.
Quoted 178 lines
Quoted 33 lines
sysdeps/or1k/__longjmp.S new file +26
-0+ l.lwz r1, 0(r3) + l.lwz r2, 4(r3) + + /* if r4 is 0, something wrong, so set it to 1 */ + l.sfeqi r4, 0x0 + l.bnf 1f /* r4 != 0, longjmp value sensible */ + l.nop + l.ori r4, r0, 0x1 /* make nonzero */ +1: + l.addi r11, r4, 0 + l.lwz r9, 8(r3) + l.lwz r10, 12(r3) + l.lwz r14, 16(r3) + l.lwz r16, 20(r3) + l.lwz r18, 24(r3) + l.lwz r20, 28(r3) + l.lwz r22, 32(r3) + l.lwz r24, 36(r3) + l.lwz r26, 40(r3) + l.lwz r28, 44(r3) + l.lwz r30, 48(r3) + l.jr r9 + l.nop + .size __longjmp, . - __longjmp + +libc_hidden_def(__longjmp)sysdeps/or1k/bits/endianness.h new file +1
-0@@ -0,0 +1,11 @@ +#ifndef _BITS_ENDIANNESS_Hsysdeps/or1k/bits/endianness.h line 11
Quoted 10 lines
sysdeps/or1k/bits/endianness.h new file +10
-0+#define _BITS_ENDIANNESS_H 1 + +#ifndef _BITS_ENDIAN_H +# error "Never use <bits/endianness.h> directly; include <endian.h> instead." +#endif + +/* OpenRISC is big-endian. */ +#define __BYTE_ORDER __BIG_ENDIAN + +#endif /* bits/endianness.h */ Ok.
Quoted 28 lines
sysdeps/or1k/bits/setjmp.h new file +22
-0@@ -0,0 +1,32 @@ +/* Define the machine-dependent type `jmp_buf'. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +02111-1307 USA. */ + + +#ifndef _OR1K_BITS_SETJMP_H +#define _OR1K_BITS_SETJMP_H 1sysdeps/or1k/bits/setjmp.h line 32
Quoted 10 lines
sysdeps/or1k/bits/setjmp.h new file +10
-0+ +#if !defined _SETJMP_H && !defined _PTHREAD_H +# error "Never include <bits/setjmp.h> directly; use <setjmp.h> instead." +#endif + +#ifndef _ASM +typedef long int __jmp_buf [13 ]; +#endif + +#endif /* _OR1K_BITS_SETJMP_H */ Ok.
Quoted 91 lines
sysdeps/or1k/bsd-_setjmp.S new file +1
-0@@ -0,0 +1 @@ +/* _setjmp is in setjmp.S */sysdeps/or1k/bsd-setjmp.S new file +1
-0@@ -0,0 +1 @@ +/* setjmp is in setjmp.S */sysdeps/or1k/dl-trampoline.S new file +71
-0@@ -0,0 +1,79 @@ +/* Machine-dependent ELF runtime symbol resolution, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This code is used to call _dl_linux_resolver (dl-runtime.c). + + We assume that R11 contains the relocation offset and R12 contains + link_map (_DYNAMIC). This must be consistent with the JUMP_SLOT + layout generated by binutils. */ + + .section .text + .align 4 + + .global _dl_runtime_resolve + .type _dl_runtime_resolve, @function + +_dl_runtime_resolve: + .cfi_startproc + l.sw -4(r1), r9 + l.sw -8(r1), r1 + + /* save function arguments. */ + l.sw -12(r1), r3 + l.sw -16(r1), r4 + l.sw -20(r1), r5 + l.sw -24(r1), r6 + l.sw -28(r1), r7 + l.sw -32(r1), r8 + + .cfi_offset 9, -4 + .cfi_offset 1, -8 + .cfi_offset 3, -12 + .cfi_offset 4, -16 + .cfi_offset 5, -20 + .cfi_offset 6, -24 + .cfi_offset 7, -28 + .cfi_offset 8, -32 + + l.addi r1,r1, -32 + .cfi_def_cfa_offset 32 + + l.ori r3, r12, 0 + l.ori r4, r11, 0 + + l.jal _dl_fixup + l.nop + + /* Restore function arguments. */ + l.addi r1,r1, 32 + l.lwz r8, -32(r1) + l.lwz r7, -28(r1) + l.lwz r6, -24(r1) + l.lwz r5, -20(r1) + l.lwz r4, -16(r1) + l.lwz r3, -12(r1) +
Quoted 8 lines
sysdeps/or1k/dl-trampoline.S line 79
Quoted 8 lines
sysdeps/or1k/dl-trampoline.S new file +8
-0+ /* restore return address. */ + l.lwz r9, -4(r1) + + l.jr r11 + l.nop + + .cfi_endproc + .size _dl_runtime_resolve, . - _dl_runtime_resolve
Fixed ENTRY/END here too.
Quoted 3 lines
It seems that
_dl_runtime_profileis not implemented and explicit disabled onsysdeps/or1k/dl-machine.h. In this case I think it would be better to explicit disable it on configure... [snip]
As discussed further on, I will remove the commented code.
Quoted 290 lines
Quoted 290 lines
sysdeps/or1k/jmpbuf-offsets.h new file +23
-0@@ -0,0 +1,23 @@ +/* Private macros for accessing __jmp_buf contents. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define __JMP_BUF_SP 0 + +/* Helper for generic function ____longjmp_chk. */ +#define JB_FRAME_ADDRESS (buf) \ + ((void *) (unsigned long) (buf[__JMP_BUF_SP]))sysdeps/or1k/jmpbuf-unwind.h new file +36
-0@@ -0,0 +1,36 @@ +/* Macros to help frame unwinding using jmpbuf. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <setjmp.h> +#include <jmpbuf-offsets.h> +#include <stdint.h> +#include <unwind.h> + +/* Test if longjmp to JMPBUF would unwind the frame +containing a local variable at ADDRESS. */ +#define _JMPBUF_UNWINDS (jmpbuf, address, demangle) \ + ((void *) (address) < (void *) demangle (jmpbuf[__JMP_BUF_SP])) + +#define _JMPBUF_CFA_UNWINDS_ADJ (_jmpbuf, _context, _adj) \ + _JMPBUF_UNWINDS_ADJ (_jmpbuf, (void *) _Unwind_GetCFA (_context), _adj) + +#define _JMPBUF_UNWINDS_ADJ (_jmpbuf, _address, _adj) \ + ((uintptr_t) (_address) - (_adj) < (uintptr_t) (_jmpbuf)[__JMP_BUF_SP] - (_adj)) + +/* We use the normal longjmp for unwinding. */ +#define __libc_unwind_longjmp (buf, val) __libc_longjmp (buf, val)sysdeps/or1k/machine-gmon.h new file +35
-0@@ -0,0 +1,35 @@ +/* Machine-dependent definitions for profiling support. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> + +#define _MCOUNT_DECL (frompc, selfpc) \ +static void \ +__mcount_internal (unsigned long int frompc, unsigned long int selfpc) + +/* This is very simple as gcc does all the heavy lifting at the _mcount +call site. GCC passes in the return address of the function calling +_mcount. */ + +#define MCOUNT \ +void \ +_mcount (void *frompc) \ +{ \ + __mcount_internal ((unsigned long int) frompc, \ + (unsigned long int) __builtin_return_address (0)); \ +}sysdeps/or1k/memusage.h new file +21
-0@@ -0,0 +1,21 @@ +/* Definitions for memory usage profiling. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#define GETSP () ({ register uintptr_t stack_ptr asm ("r1"); stack_ptr; }) + +#include <sysdeps/generic/memusage.h> sysdeps/or1k/setjmp.S new file +56
-0@@ -0,0 +1,56 @@ +/* setjmp, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep.h> +#define _ASM +#define _SETJMP_H +#include <bits/setjmp.h> + +ENTRY (_setjmp) + l.addi r4, r0, 0 /* Set second argument to 0. */ + l.j .Local__sigsetjmp + l.nop +END (_setjmp) +libc_hidden_def (_setjmp) + +ENTRY (setjmp) + l.addi r4, r0, 1 /* Set second argument to 1. */ + l.j .Local__sigsetjmp + l.nop +END (setjmp) + +ENTRY (__sigsetjmp) +.Local__sigsetjmp: + l.sw 0(r3), r1 + l.sw 4(r3), r2 + l.sw 8(r3), r9 + l.sw 12(r3), r10 + l.sw 16(r3), r14 + l.sw 20(r3), r16 + l.sw 24(r3), r18 + l.sw 28(r3), r20 + l.sw 32(r3), r22 + l.sw 36(r3), r24 + l.sw 40(r3), r26 + l.sw 44(r3), r28 + l.sw 48(r3), r30 + l.j __sigjmp_save + l.nop +END (__sigsetjmp) +hidden_def (__sigsetjmp)sysdeps/or1k/sysdep.h new file +83
-0@@ -0,0 +1,83 @@ +/* Assembler macro definitions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdeps/generic/sysdep.h> +#include <features.h> + +#if defined __ASSEMBLER__ || definedREQUEST_ASSEMBLER_MACROS + +/* Make use of .size directive. */ +#define ASM_SIZE_DIRECTIVE (name) .size name,.-name; + +/* Define an entry point visible from C. */ +#define ENTRY (name) \ + .globl C_SYMBOL_NAME(name); \ + .type C_SYMBOL_NAME(name), at function; \ + .align 4; \ + C_LABEL(name) \ + cfi_startproc; \ + CALL_MCOUNT + +#undef END +#define END (name) \ + cfi_endproc; \ + ASM_SIZE_DIRECTIVE(name) + +/* Since C identifiers are not normally prefixed with an underscore +on this system, the asm identifier `syscall_error' intrudes on the +C name space. Make sure we use an innocuous name. */ +#define syscall_error __syscall_error + +/* If compiled for profiling, call `mcount' at the start of each function. */ +#ifdef PROF +# ifdef __PIC__ +# define CALL_MCOUNT \ + l.addi r1, r1, -8; \ + l.sw 0(r1), r9; \ + l.sw 4(r1), r3; \ + l.ori r3, r9, 0; \ + l.j plt(_mcount); \ + l.nop; \ + l.lwz r9, 0(r1); \ + l.lwz r3, 4(r1); \ + l.addi r1, r1, 8; +# else +# define CALL_MCOUNT \ + l.addi r1, r1, -8; \ + l.sw 0(r1), r9; \ + l.sw 4(r1), r3; \ + l.ori r3, r9, 0; \ + l.movhi r15, hi(_mcount); \ + l.ori r15, r15, lo(_mcount); \ + l.jr r15; \ + l.nop; \ + l.lwz r9, 0(r1); \ + l.lwz r3, 4(r1); \ + l.addi r1, r1, 8; +# endif +#else +# define CALL_MCOUNT /* Do nothing. */ +#endif + +/* Local label name for asm code. */ +#define L (name) .L##name + +/* Specify the size in bytes of a machine register. */ +#define REGSIZE 4 + +#endif /* __ASSEMBLER__ */
PATCH v3 4/13 or1k: startup and dynamic linking code
In reply to Stafford HorneCode for C runtime startup and dynamic loading including PLT layout.
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.h
sysdeps/or1k/bits/link.h new file +51 -0
@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */ +typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; + +/* Return values for calls from PLT. */ +typedef struct La_or1k_retval +{ +uint32_t lrv_r3; +}La_or1k_retval ; + +__BEGIN_DECLS + +extern ElfW(Addr) la_or1k_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx, + uintptr_t *__refcook, + uintptr_t *__defcook, + La_or1k_regs *__regs, + unsigned int *__flags, + const char *__symname, + long int *__framesizep); +extern unsigned int la_or1k_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx, +uintptr_t *__refcook, +uintptr_t *__defcook, +const La_or1k_regs *__inregs, +La_or1k_retval *__outregs, +const char *__symname); + +__END_DECLS
sysdeps/or1k/dl-machine.h new file +323 -0
323 lines not on this page · raw message
sysdeps/or1k/dl-start.S new file +98 -0
98 lines not on this page · raw message
sysdeps/or1k/ldsodefs.h new file +40 -0
@@ -0,0 +1,40 @@ +/* Run-time dynamic linker data structures for loaded ELF shared objects. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _OR1K_LDSODEFS_H +#define _OR1K_LDSODEFS_H 1 + +#include <elf.h> + +struct La_or1k_regs ; +struct La_or1k_retval ; + +#define ARCH_PLTENTER_MEMBERS \ + uintptr_t (*or1k_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *, \ + uintptr_t *, struct La_or1k_regs *, \ + unsigned int *, const char *name, \ + long int *framesizep) + +#define ARCH_PLTEXIT_MEMBERS \ + unsigned int (*or1k_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *, \ + uintptr_t *, const struct La_or1k_regs *, \ + struct La_or1k_retval *, const char *) + +#include_next <ldsodefs.h> + +#endif
sysdeps/or1k/sotruss-lib.c new file +51 -0
51 lines not on this page · raw message
sysdeps/or1k/start.S new file +99 -0
99 lines not on this page · raw message
sysdeps/or1k/tst-audit.h new file +24 -0
@@ -0,0 +1,24 @@ +/* Definitions for testing PLT entry/exit auditing. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define pltenter la_or1k_gnu_pltenter +#define pltexit la_or1k_gnu_pltexit +#define La_regs La_or1k_regs +#define La_retval La_or1k_retval +#define int_retval lrv_r3
Signature · 1 line
2.31.1
PATCH v3 4/13 or1k: startup and dynamic linking code
Quoted 1 line · Stafford Horne via Libc-alpha
Code for C runtime startup and dynamic loading including PLT layout.
Patch looks ok, although I comment much on ABI and assembly code. Some comments below.
Quoted 41 lines
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.hsysdeps/or1k/bits/link.h new file +18
-0@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ +
sysdeps/or1k/bits/link.h line 28
Quoted 10 lines
sysdeps/or1k/bits/link.h new file +10
-0+#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */ +typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; +
So is the intent is to provide caller all the register, no only the caller-saved registers?
Quoted 61 lines
sysdeps/or1k/bits/link.h new file +23
-0+/* Return values for calls from PLT. */ +typedef struct La_or1k_retval +{ +uint32_t lrv_r3; +}La_or1k_retval ; + +__BEGIN_DECLS + +extern ElfW(Addr) la_or1k_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx, + uintptr_t *__refcook, + uintptr_t *__defcook, + La_or1k_regs *__regs, + unsigned int *__flags, + const char *__symname, + long int *__framesizep); +extern unsigned int la_or1k_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx, +uintptr_t *__refcook, +uintptr_t *__defcook, +const La_or1k_regs *__inregs, +La_or1k_retval *__outregs, +const char *__symname); + +__END_DECLSsysdeps/or1k/dl-machine.h new file +32
-0@@ -0,0 +1,323 @@ +/* Machine-dependent ELF dynamic relocation inline functions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "or1k" + +#include <sys/cdefs.h> +#include <sys/param.h> +#include <tls.h> +#include <dl-irel.h> +#include <dl-static-tls.h> +#include <dl-machine-rel.h> + +/* Return nonzero iff ELF header is compatible with the running host. */ +static inline int __attribute__ ((unused))
sysdeps/or1k/dl-machine.h line 42
Quoted 10 lines
sysdeps/or1k/dl-machine.h new file +10
-0+elf_machine_matches_host (const Elf32_Ehdr *ehdr) +{ +return ehdr->e_machine ==EM_OPENRISC ; +} + +static inline Elf32_Addr * +or1k_get_got (void ) +{ +Elf32_Addr *got; + registerlong int linkreg asm ("r9" );
Is the 'r9' a required register by the ABI to use on this assembly snippet? I am asking because local name 'registers' are only a hint to gcc, as we found recently [1], if you really need 'r9' you will probably need to use a global name resgister.
Quoted 5 lines
sysdeps/or1k/dl-machine.h new file +5
-0+ asm ("l.jal 0x8\n" +" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" +"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" +"l.add %0, %0, %1\n" + :"=r" (got),"=r" (linkreg));
sysdeps/or1k/dl-machine.h line 57
Quoted 10 lines
sysdeps/or1k/dl-machine.h new file +10
-0+ +return got; +} + +/* Return the link-time address of _DYNAMIC. Conveniently, this is the +first element of the GOT. */ +static inline Elf32_Addr +elf_machine_dynamic (void ) +{ +Elf32_Addr *got =or1k_get_got ();
Space before '('.
sysdeps/or1k/dl-machine.h line 70
Quoted 13 lines
sysdeps/or1k/dl-machine.h new file +13
-0+return *got; +} + + +/* Return the run-time load address of the shared object. */ +static inline Elf32_Addr +elf_machine_load_address (void ) +{ +/* Compute the difference between the runtime address of _DYNAMIC as seen +by a GOTOFF reference, and the link-time address found in the special +unrelocated first GOT entry. */ +Elf32_Addr dyn; +Elf32_Addr *got =or1k_get_got ();
Space before '('.
Quoted 67 lines
sysdeps/or1k/dl-machine.h new file +67
-0+ + asm ("l.movhi %0, gotoffhi(_DYNAMIC);" +"l.ori %0, %0, gotofflo(_DYNAMIC);" +"l.add %0, %0, %1;" + :"=&r" (dyn) :"r" (got)); + +return dyn - *got; +} + +/* Initial entry point code for the dynamic linker. The function _dl_start +is the real entry point; it's return value is the user program's entry +point. + +Code is really located in dl-start.S, just tell the linker that it +exists. */ +#define RTLD_START asm (".globl _dl_start"); + +/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or +TLS variable, so undefined references should not be allowed to +define the value. +ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one +of the main executable's symbols, as for a COPY reloc. */ + +#define elf_machine_type_class (type) \ + (((type) == R_OR1K_JMP_SLOT \ + || (type) == R_OR1K_TLS_DTPMOD \ + || (type) == R_OR1K_TLS_DTPOFF \ + || (type) == R_OR1K_TLS_TPOFF) * ELF_RTYPE_CLASS_PLT \ + | ((type) == R_OR1K_COPY) * ELF_RTYPE_CLASS_COPY) + +/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */ +#define ELF_MACHINE_JMP_SLOT R_OR1K_JMP_SLOT + +#define ARCH_LA_PLTENTER or1k_gnu_pltenter +#define ARCH_LA_PLTEXIT or1k_gnu_pltexit + +/* Set up the loaded object described by L so its unrelocated PLT +entries will jump to the on-demand fixup code in dl-runtime.c. */ +static inline int __attribute__ ((unused, always_inline)) +elf_machine_runtime_setup (struct link_map *l,struct r_scope_elem *scope[], +int lazy,int profile) +{ +ElfW (Addr) *pltgot; +extern void _dl_runtime_resolve (ElfW (Word )); +extern void _dl_runtime_profile (ElfW (Word )); + +if (l->l_info[DT_JMPREL ] && lazy) + { + pltgot = (ElfW (Addr) *)D_PTR (l, l_info[DT_PLTGOT ]); + +/* Fill in initial entrys of the plt */ + +/* Register the link_map address in the plt at pltgot[1]. +This will also be used in the resolver for accessing the +link_map structure. */ + pltgot[1 ] = (ElfW (Addr )) l; + +/* The pltgot[2] entry contains the address of a function which gets +called to get the address of a so far unresolved function and +jump to it. The profiling extension of the dynamic linker allows +to intercept the calls to collect information. In this case we +don't store the address in the GOT so that all future calls also +end in this function. */ +#if 0 /* Profiling not supported in OpenRISC yet (need to implement +_dl_runtime_profile). */ +if ( profile) + {
sysdeps/or1k/dl-machine.h line 147
Quoted 10 lines
sysdeps/or1k/dl-machine.h new file +10
-0+ pltgot[2 ] = (ElfW (Addr)) &_dl_runtime_profile; + +if (GLRO (dl_profile) !=NULL + &&_dl_name_match_p (GLRO (dl_profile), l)) +/* Say that we really want profiling and the timers are +started. */ +GL (dl_profile_map) = l; + } + else +#endif
I think it would be better to remove the commented code and add a comment stating LD_PROFILE is not currently supported.
Quoted 508 lines
sysdeps/or1k/dl-machine.h new file +176
-0+ { +/* This function will get called to fix up the GOT entry +indicated by the offset on the stack, and then jump to +the resolved address. */ + pltgot[2 ] = (ElfW (Addr)) &_dl_runtime_resolve; + } + + } + +return lazy; +} + +/* Mask identifying addresses reserved for the user program, +where the dynamic linker should not map anything. */ +#define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL + +/* We define an initialization functions. This is called very early in +_dl_sysdep_start. */ +#define DL_PLATFORM_INIT dl_platform_init () + +static inline void __attribute__ ((unused)) +dl_platform_init (void ) +{ +if (GLRO (dl_platform) !=NULL && *GLRO (dl_platform) =='\0' ) +/* Avoid an empty string which would disturb us. */ +GLRO (dl_platform) =NULL ; +} + +static inline ElfW (Addr) +elf_machine_fixup_plt (struct link_map *map,lookup_t t, +const ElfW (Sym) *refsym,const ElfW (Sym) *sym, +const ElfW (Rela) *reloc, +ElfW (Addr) *reloc_addr,ElfW (Addr) value) +{ +return *reloc_addr = value; +} + +/* Return the final value of a plt relocation. */ +static inline Elf32_Addr +elf_machine_plt_value (struct link_map *map,const Elf32_Rela *reloc, +Elf32_Addr value) +{ +return value + reloc->r_addend; +} + + +#endif /* !dl_machine_h */ + +#ifdef RESOLVE_MAP + +/* Perform the relocation specified by RELOC and SYM (which is fully resolved). +MAP is the object containing the reloc. */ + +static inline void +__attribute ((always_inline)) +elf_machine_rela (struct link_map *map,struct r_scope_elem *scope[], +const ElfW (Rela) *reloc,const ElfW (Sym) *sym, +const struct r_found_version *version, +void *const reloc_addr_arg,int skip_ifunc) +{ +Elf32_Addr *const reloc_addr = reloc_addr_arg; +const unsigned int r_type =ELF32_R_TYPE (reloc->r_info); + +if (__glibc_unlikely (r_type ==R_OR1K_NONE )) +return ; +else + { +# ifndef RESOLVE_CONFLICT_FIND_MAP +const Elf32_Sym *const refsym = sym; +# endif +struct link_map *sym_map =RESOLVE_MAP (map, scope, &sym, version, + r_type); +Elf32_Addr value =SYMBOL_ADDRESS (sym_map, sym, true); + +if (sym !=NULL + &&__glibc_unlikely (ELFW (ST_TYPE ) (sym->st_info) ==STT_GNU_IFUNC ) + &&__glibc_likely (sym->st_shndx !=SHN_UNDEF ) + &&__glibc_likely (!skip_ifunc)) + value =elf_ifunc_invoke (value); + +switch (r_type) + { +# ifndef RESOLVE_CONFLICT_FIND_MAP +case R_OR1K_COPY : +if (sym ==NULL ) +/* This can happen in trace mode if an object could not be +found. */ +break ; +if (__glibc_unlikely (sym->st_size > refsym->st_size) + || (__glibc_unlikely (sym->st_size < refsym->st_size) + &&GLRO (dl_verbose))) + { +const char *strtab; + + strtab = (const char *)D_PTR (map, l_info[DT_STRTAB ]); +_dl_error_printf ("\ +%s: Symbol `%s' has different size in shared object, consider re-linking\n" , + rtld_progname ?:"<program name unknown>" , + strtab + refsym->st_name); + } +memcpy (reloc_addr_arg, (void *) value, +MIN (sym->st_size, refsym->st_size)); +break ; +# endif /* !RESOLVE_CONFLICT_FIND_MAP */ +case R_OR1K_32 : +/* Support relocations on mis-aligned offsets. */ + value += reloc->r_addend; +memcpy (reloc_addr_arg, &value,4 ); +break ; +case R_OR1K_GLOB_DAT : +case R_OR1K_JMP_SLOT : + *reloc_addr = value + reloc->r_addend; +break ; +case R_OR1K_TLS_DTPMOD : +# ifdef RTLD_BOOTSTRAP +/* During startup the dynamic linker is always the module +with index 1. */ + *reloc_addr =1 ; +# else +if (sym_map !=NULL ) + *reloc_addr = sym_map->l_tls_modid; +# endif +break ; +case R_OR1K_TLS_DTPOFF : +# ifndef RTLD_BOOTSTRAP + *reloc_addr = (sym ==NULL ?0 : sym->st_value) + reloc->r_addend; +# endif +break ; + +case R_OR1K_TLS_TPOFF : +# ifdef RTLD_BOOTSTRAP + *reloc_addr = sym->st_value + reloc->r_addend + + map->l_tls_offset -TLS_TCB_SIZE ; +# else +if (sym_map !=NULL ) + { +CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym->st_value + reloc->r_addend + + sym_map->l_tls_offset -TLS_TCB_SIZE ; + } +# endif +break ; +default : +_dl_reloc_bad_type (map, r_type,0 ); +break ; + } + } +} + +static inline void +__attribute__ ((always_inline)) +elf_machine_rela_relative (Elf32_Addr l_addr,const Elf32_Rela *reloc, +void *const reloc_addr_arg) +{ +Elf32_Addr *const reloc_addr = reloc_addr_arg; + *reloc_addr = l_addr + reloc->r_addend; +} + +static inline void +__attribute__ ((always_inline)) +elf_machine_lazy_rel (struct link_map *map,struct r_scope_elem *scope[], +ElfW (Addr) l_addr,const ElfW (Rela) *reloc, +int skip_ifunc) +{ +Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset); +const unsigned int r_type =ELF32_R_TYPE (reloc->r_info); + +if (__glibc_likely (r_type ==R_OR1K_JMP_SLOT )) + *reloc_addr += l_addr; +else if (__glibc_unlikely (r_type ==R_OR1K_NONE )) +return ; +else +_dl_reloc_bad_type (map, r_type,1 ); +} + +#endif /* RESOLVE_MAP */ sysdeps/or1k/dl-start.S new file +98
-0@@ -0,0 +1,98 @@ +/* Machine-dependent ELF startup code. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> + +/* Initial entry point code for the dynamic linker. + The function _dl_start is the real entry point; + it's return value is the user program's entry point. */ +ENTRY (_start) + /* Count arguments in r11 */ + l.ori r3, r1, 0 + l.movhi r11, 0 +1: + l.addi r3, r3, 4 + l.lwz r12, 0(r3) + l.sfnei r12, 0 + l.addi r11, r11, 1 + l.bf 1b + l.nop + l.addi r11, r11, -1 + /* store argument counter to stack. */ + l.sw 0(r1), r11 + + /* Load the PIC register. */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + + l.ori r3, r1, 0 + + l.jal _dl_start + l.nop + /* Save user entry in a call saved reg. */ + l.ori r22, r11, 0 + /* Fall through to _dl_start_user. */ + +_dl_start_user: + /* Set up for _dl_init. */ + + /* Load _rtld_local (a.k.a _dl_loaded). */ + l.lwz r12, got(_rtld_local)(r16) + l.lwz r3, 0(r12) + + /* Load argc */ + l.lwz r18, got(_dl_argc)(r16) + l.lwz r4, 0(r18) + + /* Load argv */ + l.lwz r20, got(_dl_argv)(r16) + l.lwz r5, 0(r20) + + /* Load envp = &argv[argc + 1]. */ + l.slli r6, r4, 2 + l.addi r6, r6, 4 + l.add r6, r6, r5 + + l.jal plt(_dl_init) + l.nop + + /* Now set up for user entry. + The already defined ABI loads argc and argv from the stack. + + argc = 0(r1) + argv = r1 + 4 + */ + + /* Load SP as argv - 4. */ + l.lwz r3, 0(r20) + l.addi r1, r3, -4 + + /* Save argc. */ + l.lwz r3, 0(r18) + l.sw 0(r1), r3 + + /* Pass _dl_fini function address to _start. + Next start.S will then pass this as rtld_fini to __libc_start_main. */ + l.lwz r3, got(_dl_fini)(r16) + + l.jr r22 + l.nop + +END (_start)sysdeps/or1k/ldsodefs.h new file +40
-0@@ -0,0 +1,40 @@ +/* Run-time dynamic linker data structures for loaded ELF shared objects. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _OR1K_LDSODEFS_H +#define _OR1K_LDSODEFS_H 1 + +#include <elf.h> + +struct La_or1k_regs ; +struct La_or1k_retval ; + +#define ARCH_PLTENTER_MEMBERS \ + uintptr_t (*or1k_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *, \ + uintptr_t *, struct La_or1k_regs *, \ + unsigned int *, const char *name, \ + long int *framesizep) + +#define ARCH_PLTEXIT_MEMBERS \ + unsigned int (*or1k_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *, \ + uintptr_t *, const struct La_or1k_regs *, \ + struct La_or1k_retval *, const char *) + +#include_next <ldsodefs.h> + +#endif sysdeps/or1k/sotruss-lib.c new file +51
-0@@ -0,0 +1,51 @@ +/* Override generic sotruss-lib.c to define actual functions for OpenRISC. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define HAVE_ARCH_PLTENTER +#define HAVE_ARCH_PLTEXIT + +#include <elf/sotruss-lib.c> + +ElfW (Addr) +la_or1k_gnu_pltenter (ElfW (Sym) *sym __attribute__ ((unused)), +unsigned int ndx __attribute__ ((unused)), +uintptr_t *refcook,uintptr_t *defcook, +La_or1k_regs *regs,unsigned int *flags, +const char *symname,long int *framesizep) +{ +print_enter (refcook, defcook, symname, + regs->lr_reg[0 ], regs->lr_reg[1 ], regs->lr_reg[2 ], + *flags); + +/* No need to copy anything, we will not need the parameters in any case. */ + *framesizep =0 ; + +return sym->st_value; +} + +unsigned int +la_or1k_gnu_pltexit (ElfW (Sym) *sym,unsigned int ndx,uintptr_t *refcook, +uintptr_t *defcook, +const struct La_or1k_regs *inregs, +struct La_or1k_retval *outregs, +const char *symname) +{ +print_exit (refcook, defcook, symname, outregs->lrv_r3); + +return 0 ; +}sysdeps/or1k/start.S new file +99
-0@@ -0,0 +1,99 @@ +/* start, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This is the canonical entry point, usually the first thing in the text + segment. + + sp The stack contains the arguments and environment: + 0(sp) argc + 4(sp) argv[0] + ... + (4*argc)(sp) NULL + (4*(argc+1))(sp) envp[0] + ... + NULL + */ + +#define __ASSEMBLY__ +#include <sysdep.h> +#include <entry.h> + +ENTRY (ENTRY_POINT) + + /* Setup Arguments to the __libc_start_main function. */ + + /* Take values for argc and argv off the stack. + These will be passed as arguments two and three to main + and thus go in registers r4 and r5, respectively. */ + l.lwz r4, 0(r1) + l.addi r5, r1, 4 + + /* Pass in rtld_fini from dl-start.S. */ + l.or r8, r3, r3 + +#ifdef PIC + /* Obtain a pointer to .got in r16 */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + + /* Pass in the the main symbol. */ + l.lwz r3, got(main)(r16) +#else + /* Pass in the the main symbol. */ + l.movhi r3, hi(main) + l.ori r3, r3, lo(main) +#endif + /* Used to be init and fini. */ + l.movhi r6, 0x0 + l.movhi r7, 0x0 + + /* Push stack limit onto the stack. + This provides the highest stack address to user code (as stack grows + downwards. + This is the seventh argument to __libc_start_main and thus needs to + be passed on the stack. */ + l.sw -4(r1), r1 + + /* Adjust stack to account for a total of 7 args (i.e. the last one is + on the stack. */ + l.addi r1, r1, -4 + + /* Clear the frame pointer and link register since this is the + outermost frame. */ + l.movhi r2, 0x0 + l.movhi r9, 0x0 + + /* Let the libc call main and exit with its return code. */ +#ifdef PIC + l.j plt(__libc_start_main) +#else + l.j __libc_start_main +#endif + l.nop +END (ENTRY_POINT) + + /* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_startsysdeps/or1k/tst-audit.h new file +14
-0@@ -0,0 +1,24 @@ +/* Definitions for testing PLT entry/exit auditing. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details.
sysdeps/or1k/tst-audit.h line 24
Quoted 10 lines
sysdeps/or1k/tst-audit.h new file +10
-0+ + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library. If not, see + <https://www.gnu.org/licenses/>. */ + +#define pltenter la_or1k_gnu_pltenter +#define pltexit la_or1k_gnu_pltexit +#define La_regs La_or1k_regs +#define La_retval La_or1k_retval +#define int_retval lrv_r3
[1] https://sourceware.org/pipermail/libc-alpha/2021-December/134176.html
PATCH v3 4/13 or1k: startup and dynamic linking code
Quoted 54 lines · Adhemerval Zanella
Quoted 1 line · Stafford Horne via Libc-alpha
Code for C runtime startup and dynamic loading including PLT layout.
Patch looks ok, although I comment much on ABI and assembly code. Some comments below.
Quoted 46 lines
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.hsysdeps/or1k/bits/link.h new file +23
-0@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */
Quoted 8 lines
sysdeps/or1k/bits/link.h line 28
Quoted 5 lines
sysdeps/or1k/bits/link.h new file +5
-0+typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; +So is the intent is to provide caller all the register, no only the caller-saved registers?
As I see it...
Shouldn't these usually be the argument registers used in la_pltenter to print our the function call? i.e.
print_enter (refcook, defcook, symname,
regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2],
*flags);These registers get setup in sysdeps/{arch}/dl-trampoline.S by _dl_runtime_profile, which then pass them to _dl_profile_fixup.
The problem is openrisc doesn't implement _dl_runtime_profile so we haven't defined what the registers are.
I noticed the same for arc, csky, riscv.
These are needed to be defined for sotruss, but I dont seem them being used.
Is that correct?
Quoted 68 lines
Quoted 68 lines
sysdeps/or1k/bits/link.h new file +23
-0+/* Return values for calls from PLT. */ +typedef struct La_or1k_retval +{ +uint32_t lrv_r3; +}La_or1k_retval ; + +__BEGIN_DECLS + +extern ElfW(Addr) la_or1k_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx, + uintptr_t *__refcook, + uintptr_t *__defcook, + La_or1k_regs *__regs, + unsigned int *__flags, + const char *__symname, + long int *__framesizep); +extern unsigned int la_or1k_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx, +uintptr_t *__refcook, +uintptr_t *__defcook, +const La_or1k_regs *__inregs, +La_or1k_retval *__outregs, +const char *__symname); + +__END_DECLSsysdeps/or1k/dl-machine.h new file +39
-0@@ -0,0 +1,323 @@ +/* Machine-dependent ELF dynamic relocation inline functions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "or1k" + +#include <sys/cdefs.h> +#include <sys/param.h> +#include <tls.h> +#include <dl-irel.h> +#include <dl-static-tls.h> +#include <dl-machine-rel.h> + +/* Return nonzero iff ELF header is compatible with the running host. */ +static inline int __attribute__ ((unused)) +elf_machine_matches_host (const Elf32_Ehdr *ehdr) +{ +return ehdr->e_machine ==EM_OPENRISC ; +} + +static inline Elf32_Addr * +or1k_get_got (void )
Quoted 8 lines
sysdeps/or1k/dl-machine.h line 42
Quoted 3 lines
sysdeps/or1k/dl-machine.h new file +3
-0+{ +Elf32_Addr *got; + registerlong int linkreg asm ("r9" );Is the 'r9' a required register by the ABI to use on this assembly snippet? I am asking because local name 'registers' are only a hint to gcc, as we found recently [1], if you really need 'r9' you will probably need to use a global name resgister.
The r9 is to avoid the snippet from clobbering r9. The result of l.jal will update r9 (link register) we want to make sure that is what we used for %1.
I think there were issues with other ways I tried.
Let me look into it more.
Quoted 9 lines
Quoted 9 lines
sysdeps/or1k/dl-machine.h new file +9
-0+ asm ("l.jal 0x8\n" +" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" +"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" +"l.add %0, %0, %1\n" + :"=r" (got),"=r" (linkreg)); + +return got; +} +
Quoted 8 lines
sysdeps/or1k/dl-machine.h line 57
Quoted 6 lines
sysdeps/or1k/dl-machine.h new file +6
-0+/* Return the link-time address of _DYNAMIC. Conveniently, this is the +first element of the GOT. */ +static inline Elf32_Addr +elf_machine_dynamic (void ) +{ +Elf32_Addr *got =or1k_get_got ();Space before '('.
OK.
Quoted 7 lines
Quoted 7 lines
sysdeps/or1k/dl-machine.h new file +7
-0+return *got; +} + + +/* Return the run-time load address of the shared object. */ +static inline Elf32_Addr +elf_machine_load_address (void )
Quoted 8 lines
sysdeps/or1k/dl-machine.h line 70
Quoted 6 lines
sysdeps/or1k/dl-machine.h new file +6
-0+{ +/* Compute the difference between the runtime address of _DYNAMIC as seen +by a GOTOFF reference, and the link-time address found in the special +unrelocated first GOT entry. */ +Elf32_Addr dyn; +Elf32_Addr *got =or1k_get_got ();Space before '('.
OK.
Quoted 72 lines
Quoted 72 lines
sysdeps/or1k/dl-machine.h new file +72
-0+ + asm ("l.movhi %0, gotoffhi(_DYNAMIC);" +"l.ori %0, %0, gotofflo(_DYNAMIC);" +"l.add %0, %0, %1;" + :"=&r" (dyn) :"r" (got)); + +return dyn - *got; +} + +/* Initial entry point code for the dynamic linker. The function _dl_start +is the real entry point; it's return value is the user program's entry +point. + +Code is really located in dl-start.S, just tell the linker that it +exists. */ +#define RTLD_START asm (".globl _dl_start"); + +/* ELF_RTYPE_CLASS_PLT iff TYPE describes relocation of a PLT entry or +TLS variable, so undefined references should not be allowed to +define the value. +ELF_RTYPE_CLASS_NOCOPY iff TYPE should not be allowed to resolve to one +of the main executable's symbols, as for a COPY reloc. */ + +#define elf_machine_type_class (type) \ + (((type) == R_OR1K_JMP_SLOT \ + || (type) == R_OR1K_TLS_DTPMOD \ + || (type) == R_OR1K_TLS_DTPOFF \ + || (type) == R_OR1K_TLS_TPOFF) * ELF_RTYPE_CLASS_PLT \ + | ((type) == R_OR1K_COPY) * ELF_RTYPE_CLASS_COPY) + +/* A reloc type used for ld.so cmdline arg lookups to reject PLT entries. */ +#define ELF_MACHINE_JMP_SLOT R_OR1K_JMP_SLOT + +#define ARCH_LA_PLTENTER or1k_gnu_pltenter +#define ARCH_LA_PLTEXIT or1k_gnu_pltexit + +/* Set up the loaded object described by L so its unrelocated PLT +entries will jump to the on-demand fixup code in dl-runtime.c. */ +static inline int __attribute__ ((unused, always_inline)) +elf_machine_runtime_setup (struct link_map *l,struct r_scope_elem *scope[], +int lazy,int profile) +{ +ElfW (Addr) *pltgot; +extern void _dl_runtime_resolve (ElfW (Word )); +extern void _dl_runtime_profile (ElfW (Word )); + +if (l->l_info[DT_JMPREL ] && lazy) + { + pltgot = (ElfW (Addr) *)D_PTR (l, l_info[DT_PLTGOT ]); + +/* Fill in initial entrys of the plt */ + +/* Register the link_map address in the plt at pltgot[1]. +This will also be used in the resolver for accessing the +link_map structure. */ + pltgot[1 ] = (ElfW (Addr )) l; + +/* The pltgot[2] entry contains the address of a function which gets +called to get the address of a so far unresolved function and +jump to it. The profiling extension of the dynamic linker allows +to intercept the calls to collect information. In this case we +don't store the address in the GOT so that all future calls also +end in this function. */ +#if 0 /* Profiling not supported in OpenRISC yet (need to implement +_dl_runtime_profile). */ +if ( profile) + { + pltgot[2 ] = (ElfW (Addr)) &_dl_runtime_profile; + +if (GLRO (dl_profile) !=NULL + &&_dl_name_match_p (GLRO (dl_profile), l)) +/* Say that we really want profiling and the timers are
Quoted 8 lines
sysdeps/or1k/dl-machine.h line 147
Quoted 5 lines
sysdeps/or1k/dl-machine.h new file +5
-0+started. */ + GL(dl_profile_map) = l; + } + else +#endif I think it would be better to remove the commented code and add a comment stating
LD_PROFILEis not currently supported.
OK.
Quoted 512 lines
Quoted 512 lines
sysdeps/or1k/dl-machine.h new file +176
-0+ { +/* This function will get called to fix up the GOT entry +indicated by the offset on the stack, and then jump to +the resolved address. */ + pltgot[2 ] = (ElfW (Addr)) &_dl_runtime_resolve; + } + + } + +return lazy; +} + +/* Mask identifying addresses reserved for the user program, +where the dynamic linker should not map anything. */ +#define ELF_MACHINE_USER_ADDRESS_MASK 0xf8000000UL + +/* We define an initialization functions. This is called very early in +_dl_sysdep_start. */ +#define DL_PLATFORM_INIT dl_platform_init () + +static inline void __attribute__ ((unused)) +dl_platform_init (void ) +{ +if (GLRO (dl_platform) !=NULL && *GLRO (dl_platform) =='\0' ) +/* Avoid an empty string which would disturb us. */ +GLRO (dl_platform) =NULL ; +} + +static inline ElfW (Addr) +elf_machine_fixup_plt (struct link_map *map,lookup_t t, +const ElfW (Sym) *refsym,const ElfW (Sym) *sym, +const ElfW (Rela) *reloc, +ElfW (Addr) *reloc_addr,ElfW (Addr) value) +{ +return *reloc_addr = value; +} + +/* Return the final value of a plt relocation. */ +static inline Elf32_Addr +elf_machine_plt_value (struct link_map *map,const Elf32_Rela *reloc, +Elf32_Addr value) +{ +return value + reloc->r_addend; +} + + +#endif /* !dl_machine_h */ + +#ifdef RESOLVE_MAP + +/* Perform the relocation specified by RELOC and SYM (which is fully resolved). +MAP is the object containing the reloc. */ + +static inline void +__attribute ((always_inline)) +elf_machine_rela (struct link_map *map,struct r_scope_elem *scope[], +const ElfW (Rela) *reloc,const ElfW (Sym) *sym, +const struct r_found_version *version, +void *const reloc_addr_arg,int skip_ifunc) +{ +Elf32_Addr *const reloc_addr = reloc_addr_arg; +const unsigned int r_type =ELF32_R_TYPE (reloc->r_info); + +if (__glibc_unlikely (r_type ==R_OR1K_NONE )) +return ; +else + { +# ifndef RESOLVE_CONFLICT_FIND_MAP +const Elf32_Sym *const refsym = sym; +# endif +struct link_map *sym_map =RESOLVE_MAP (map, scope, &sym, version, + r_type); +Elf32_Addr value =SYMBOL_ADDRESS (sym_map, sym, true); + +if (sym !=NULL + &&__glibc_unlikely (ELFW (ST_TYPE ) (sym->st_info) ==STT_GNU_IFUNC ) + &&__glibc_likely (sym->st_shndx !=SHN_UNDEF ) + &&__glibc_likely (!skip_ifunc)) + value =elf_ifunc_invoke (value); + +switch (r_type) + { +# ifndef RESOLVE_CONFLICT_FIND_MAP +case R_OR1K_COPY : +if (sym ==NULL ) +/* This can happen in trace mode if an object could not be +found. */ +break ; +if (__glibc_unlikely (sym->st_size > refsym->st_size) + || (__glibc_unlikely (sym->st_size < refsym->st_size) + &&GLRO (dl_verbose))) + { +const char *strtab; + + strtab = (const char *)D_PTR (map, l_info[DT_STRTAB ]); +_dl_error_printf ("\ +%s: Symbol `%s' has different size in shared object, consider re-linking\n" , + rtld_progname ?:"<program name unknown>" , + strtab + refsym->st_name); + } +memcpy (reloc_addr_arg, (void *) value, +MIN (sym->st_size, refsym->st_size)); +break ; +# endif /* !RESOLVE_CONFLICT_FIND_MAP */ +case R_OR1K_32 : +/* Support relocations on mis-aligned offsets. */ + value += reloc->r_addend; +memcpy (reloc_addr_arg, &value,4 ); +break ; +case R_OR1K_GLOB_DAT : +case R_OR1K_JMP_SLOT : + *reloc_addr = value + reloc->r_addend; +break ; +case R_OR1K_TLS_DTPMOD : +# ifdef RTLD_BOOTSTRAP +/* During startup the dynamic linker is always the module +with index 1. */ + *reloc_addr =1 ; +# else +if (sym_map !=NULL ) + *reloc_addr = sym_map->l_tls_modid; +# endif +break ; +case R_OR1K_TLS_DTPOFF : +# ifndef RTLD_BOOTSTRAP + *reloc_addr = (sym ==NULL ?0 : sym->st_value) + reloc->r_addend; +# endif +break ; + +case R_OR1K_TLS_TPOFF : +# ifdef RTLD_BOOTSTRAP + *reloc_addr = sym->st_value + reloc->r_addend + + map->l_tls_offset -TLS_TCB_SIZE ; +# else +if (sym_map !=NULL ) + { +CHECK_STATIC_TLS (map, sym_map); + *reloc_addr = sym->st_value + reloc->r_addend + + sym_map->l_tls_offset -TLS_TCB_SIZE ; + } +# endif +break ; +default : +_dl_reloc_bad_type (map, r_type,0 ); +break ; + } + } +} + +static inline void +__attribute__ ((always_inline)) +elf_machine_rela_relative (Elf32_Addr l_addr,const Elf32_Rela *reloc, +void *const reloc_addr_arg) +{ +Elf32_Addr *const reloc_addr = reloc_addr_arg; + *reloc_addr = l_addr + reloc->r_addend; +} + +static inline void +__attribute__ ((always_inline)) +elf_machine_lazy_rel (struct link_map *map,struct r_scope_elem *scope[], +ElfW (Addr) l_addr,const ElfW (Rela) *reloc, +int skip_ifunc) +{ +Elf32_Addr *const reloc_addr = (void *) (l_addr + reloc->r_offset); +const unsigned int r_type =ELF32_R_TYPE (reloc->r_info); + +if (__glibc_likely (r_type ==R_OR1K_JMP_SLOT )) + *reloc_addr += l_addr; +else if (__glibc_unlikely (r_type ==R_OR1K_NONE )) +return ; +else +_dl_reloc_bad_type (map, r_type,1 ); +} + +#endif /* RESOLVE_MAP */ sysdeps/or1k/dl-start.S new file +98
-0@@ -0,0 +1,98 @@ +/* Machine-dependent ELF startup code. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> + +/* Initial entry point code for the dynamic linker. + The function _dl_start is the real entry point; + it's return value is the user program's entry point. */ +ENTRY (_start) + /* Count arguments in r11 */ + l.ori r3, r1, 0 + l.movhi r11, 0 +1: + l.addi r3, r3, 4 + l.lwz r12, 0(r3) + l.sfnei r12, 0 + l.addi r11, r11, 1 + l.bf 1b + l.nop + l.addi r11, r11, -1 + /* store argument counter to stack. */ + l.sw 0(r1), r11 + + /* Load the PIC register. */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + + l.ori r3, r1, 0 + + l.jal _dl_start + l.nop + /* Save user entry in a call saved reg. */ + l.ori r22, r11, 0 + /* Fall through to _dl_start_user. */ + +_dl_start_user: + /* Set up for _dl_init. */ + + /* Load _rtld_local (a.k.a _dl_loaded). */ + l.lwz r12, got(_rtld_local)(r16) + l.lwz r3, 0(r12) + + /* Load argc */ + l.lwz r18, got(_dl_argc)(r16) + l.lwz r4, 0(r18) + + /* Load argv */ + l.lwz r20, got(_dl_argv)(r16) + l.lwz r5, 0(r20) + + /* Load envp = &argv[argc + 1]. */ + l.slli r6, r4, 2 + l.addi r6, r6, 4 + l.add r6, r6, r5 + + l.jal plt(_dl_init) + l.nop + + /* Now set up for user entry. + The already defined ABI loads argc and argv from the stack. + + argc = 0(r1) + argv = r1 + 4 + */ + + /* Load SP as argv - 4. */ + l.lwz r3, 0(r20) + l.addi r1, r3, -4 + + /* Save argc. */ + l.lwz r3, 0(r18) + l.sw 0(r1), r3 + + /* Pass _dl_fini function address to _start. + Next start.S will then pass this as rtld_fini to __libc_start_main. */ + l.lwz r3, got(_dl_fini)(r16) + + l.jr r22 + l.nop + +END (_start)sysdeps/or1k/ldsodefs.h new file +40
-0@@ -0,0 +1,40 @@ +/* Run-time dynamic linker data structures for loaded ELF shared objects. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _OR1K_LDSODEFS_H +#define _OR1K_LDSODEFS_H 1 + +#include <elf.h> + +struct La_or1k_regs ; +struct La_or1k_retval ; + +#define ARCH_PLTENTER_MEMBERS \ + uintptr_t (*or1k_gnu_pltenter) (Elf32_Sym *, unsigned int, uintptr_t *, \ + uintptr_t *, struct La_or1k_regs *, \ + unsigned int *, const char *name, \ + long int *framesizep) + +#define ARCH_PLTEXIT_MEMBERS \ + unsigned int (*or1k_gnu_pltexit) (Elf32_Sym *, unsigned int, uintptr_t *, \ + uintptr_t *, const struct La_or1k_regs *, \ + struct La_or1k_retval *, const char *) + +#include_next <ldsodefs.h> + +#endif sysdeps/or1k/sotruss-lib.c new file +51
-0@@ -0,0 +1,51 @@ +/* Override generic sotruss-lib.c to define actual functions for OpenRISC. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define HAVE_ARCH_PLTENTER +#define HAVE_ARCH_PLTEXIT + +#include <elf/sotruss-lib.c> + +ElfW (Addr) +la_or1k_gnu_pltenter (ElfW (Sym) *sym __attribute__ ((unused)), +unsigned int ndx __attribute__ ((unused)), +uintptr_t *refcook,uintptr_t *defcook, +La_or1k_regs *regs,unsigned int *flags, +const char *symname,long int *framesizep) +{ +print_enter (refcook, defcook, symname, + regs->lr_reg[0 ], regs->lr_reg[1 ], regs->lr_reg[2 ], + *flags); + +/* No need to copy anything, we will not need the parameters in any case. */ + *framesizep =0 ; + +return sym->st_value; +} + +unsigned int +la_or1k_gnu_pltexit (ElfW (Sym) *sym,unsigned int ndx,uintptr_t *refcook, +uintptr_t *defcook, +const struct La_or1k_regs *inregs, +struct La_or1k_retval *outregs, +const char *symname) +{ +print_exit (refcook, defcook, symname, outregs->lrv_r3); + +return 0 ; +}sysdeps/or1k/start.S new file +99
-0@@ -0,0 +1,99 @@ +/* start, OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This is the canonical entry point, usually the first thing in the text + segment. + + sp The stack contains the arguments and environment: + 0(sp) argc + 4(sp) argv[0] + ... + (4*argc)(sp) NULL + (4*(argc+1))(sp) envp[0] + ... + NULL + */ + +#define __ASSEMBLY__ +#include <sysdep.h> +#include <entry.h> + +ENTRY (ENTRY_POINT) + + /* Setup Arguments to the __libc_start_main function. */ + + /* Take values for argc and argv off the stack. + These will be passed as arguments two and three to main + and thus go in registers r4 and r5, respectively. */ + l.lwz r4, 0(r1) + l.addi r5, r1, 4 + + /* Pass in rtld_fini from dl-start.S. */ + l.or r8, r3, r3 + +#ifdef PIC + /* Obtain a pointer to .got in r16 */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + + /* Pass in the the main symbol. */ + l.lwz r3, got(main)(r16) +#else + /* Pass in the the main symbol. */ + l.movhi r3, hi(main) + l.ori r3, r3, lo(main) +#endif + /* Used to be init and fini. */ + l.movhi r6, 0x0 + l.movhi r7, 0x0 + + /* Push stack limit onto the stack. + This provides the highest stack address to user code (as stack grows + downwards. + This is the seventh argument to __libc_start_main and thus needs to + be passed on the stack. */ + l.sw -4(r1), r1 + + /* Adjust stack to account for a total of 7 args (i.e. the last one is + on the stack. */ + l.addi r1, r1, -4 + + /* Clear the frame pointer and link register since this is the + outermost frame. */ + l.movhi r2, 0x0 + l.movhi r9, 0x0 + + /* Let the libc call main and exit with its return code. */ +#ifdef PIC + l.j plt(__libc_start_main) +#else + l.j __libc_start_main +#endif + l.nop +END (ENTRY_POINT) + + /* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_startsysdeps/or1k/tst-audit.h new file +18
-0@@ -0,0 +1,24 @@ +/* Definitions for testing PLT entry/exit auditing. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */
Quoted 8 lines
sysdeps/or1k/tst-audit.h line 24
Quoted 6 lines
sysdeps/or1k/tst-audit.h new file +6
-0+ +#define pltenter la_or1k_gnu_pltenter +#define pltexit la_or1k_gnu_pltexit +#define La_regs La_or1k_regs +#define La_retval La_or1k_retval +#define int_retval lrv_r3[1] https://sourceware.org/pipermail/libc-alpha/2021-December/134176.html
Ill try to change it and test.
Thanks for the comments.
-Stafford
PATCH v3 4/13 or1k: startup and dynamic linking code
Quoted 76 lines · Stafford Horne
Quoted 54 lines · Adhemerval Zanella
Quoted 1 line · Stafford Horne via Libc-alpha
Code for C runtime startup and dynamic loading including PLT layout.
Patch looks ok, although I comment much on ABI and assembly code. Some comments below.
Quoted 46 lines
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.hsysdeps/or1k/bits/link.h new file +23
-0@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */ Quoted 8 lines
sysdeps/or1k/bits/link.h line 28
Quoted 5 lines
sysdeps/or1k/bits/link.h new file +5
-0+typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; +So is the intent is to provide caller all the register, no only the caller-saved registers?
As I see it...
Shouldn't these usually be the argument registers used in
la_pltenterto print our the function call? i.e.
print_enter(refcook, defcook, symname,regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2], *flags);These registers get setup in
sysdeps/{arch}/dl-trampoline.Sby_dl_runtime_profile, which then pass them to_dl_profile_fixup.
Quoted 8 lines
The problem is openrisc doesn't implement
_dl_runtime_profileso we haven't defined what the registers are.I noticed the same for arc, csky, riscv.
These are needed to be defined for sotruss, but I dont seem them being used.
Is that correct?
The register are really dependend of the function calling ABI of the architecture, if you check other architecture like x86 and powerpc you will see that La_i86_regs and La_ppc64_regs only saves the caller-saved ones. It is mainly because for PLT tracking, as done by audit modules, other register are not really useful (since they are just internal ones to the caller function).
Quoted 78 lines
Quoted 69 lines
Quoted 69 lines
sysdeps/or1k/bits/link.h new file +23
-0+/* Return values for calls from PLT. */ +typedef struct La_or1k_retval +{ +uint32_t lrv_r3; +}La_or1k_retval ; + +__BEGIN_DECLS + +extern ElfW(Addr) la_or1k_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx, + uintptr_t *__refcook, + uintptr_t *__defcook, + La_or1k_regs *__regs, + unsigned int *__flags, + const char *__symname, + long int *__framesizep); +extern unsigned int la_or1k_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx, +uintptr_t *__refcook, +uintptr_t *__defcook, +const La_or1k_regs *__inregs, +La_or1k_retval *__outregs, +const char *__symname); + +__END_DECLSsysdeps/or1k/dl-machine.h new file +39
-0@@ -0,0 +1,323 @@ +/* Machine-dependent ELF dynamic relocation inline functions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "or1k" + +#include <sys/cdefs.h> +#include <sys/param.h> +#include <tls.h> +#include <dl-irel.h> +#include <dl-static-tls.h> +#include <dl-machine-rel.h> + +/* Return nonzero iff ELF header is compatible with the running host. */ +static inline int __attribute__ ((unused)) +elf_machine_matches_host (const Elf32_Ehdr *ehdr) +{ +return ehdr->e_machine ==EM_OPENRISC ; +} + +static inline Elf32_Addr * +or1k_get_got (void )Quoted 8 lines
sysdeps/or1k/dl-machine.h line 42
Quoted 3 lines
sysdeps/or1k/dl-machine.h new file +3
-0+{ +Elf32_Addr *got; + registerlong int linkreg asm ("r9" );Is the 'r9' a required register by the ABI to use on this assembly snippet? I am asking because local name 'registers' are only a hint to gcc, as we found recently [1], if you really need 'r9' you will probably need to use a global name resgister.
Quoted 4 lines
The r9 is to avoid the snippet from clobbering r9. The result of l.jal will update r9 (link register) we want to make sure that is what we used for %1.
I think there were issues with other ways I tried.
Should you add it the clobbered list instead?
Quoted 8 lines
Let me look into it more.
Quoted 5 lines
Quoted 5 lines
sysdeps/or1k/dl-machine.h new file +5
-0+ asm ("l.jal 0x8\n" +" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" +"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" +"l.add %0, %0, %1\n" + :"=r" (got),"=r" (linkreg));
With something like (unstested):
static inline Elf32_Addr *
or1k_get_got (void)
{
Elf32_Addr *got;
asm ("l.jal 0x8\n"
" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n"
"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n"
"l.add %0, %0, %1\n"
: "=r" (got)
:
: "r9");
}PATCH v3 4/13 or1k: startup and dynamic linking code
Quoted 86 lines · Adhemerval Zanella
Quoted 83 lines · Stafford Horne
Quoted 54 lines · Adhemerval Zanella
Quoted 1 line · Stafford Horne via Libc-alpha
Code for C runtime startup and dynamic loading including PLT layout.
Patch looks ok, although I comment much on ABI and assembly code. Some comments below.
Quoted 46 lines
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.hsysdeps/or1k/bits/link.h new file +23
-0@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */ Quoted 8 lines
sysdeps/or1k/bits/link.h line 28
Quoted 5 lines
sysdeps/or1k/bits/link.h new file +5
-0+typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; +So is the intent is to provide caller all the register, no only the caller-saved registers?
As I see it...
Shouldn't these usually be the argument registers used in
la_pltenterto print our the function call? i.e.
print_enter(refcook, defcook, symname,regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2], *flags);These registers get setup in
sysdeps/{arch}/dl-trampoline.Sby_dl_runtime_profile, which then pass them to_dl_profile_fixup.The problem is openrisc doesn't implement
_dl_runtime_profileso we haven't defined what the registers are.I noticed the same for arc, csky, riscv.
These are needed to be defined for sotruss, but I dont seem them being used.
Quoted 7 lines
Quoted 1 line
Is that correct?
The register are really dependend of the function calling ABI of the architecture, if you check other architecture like x86 and powerpc you will see that
La_i86_regsandLa_ppc64_regsonly saves the caller-saved ones. It is mainly because for PLT tracking, as done by audit modules, other register are not really useful (since they are just internal ones to the caller function).
I see, but isn't this register saving done in _dl_profile_resolve?
OpenRISC doesn't define _dl_profile_resolve.
I can change the definition of La_or1k_regs, but as I see it it is currently not used other than building sotruss-lib and audit modules. But I don't see how pltenter will be called without implementing _dl_profile_resolve.
Quoted 97 lines
Quoted 78 lines
Quoted 69 lines
Quoted 69 lines
sysdeps/or1k/bits/link.h new file +23
-0+/* Return values for calls from PLT. */ +typedef struct La_or1k_retval +{ +uint32_t lrv_r3; +}La_or1k_retval ; + +__BEGIN_DECLS + +extern ElfW(Addr) la_or1k_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx, + uintptr_t *__refcook, + uintptr_t *__defcook, + La_or1k_regs *__regs, + unsigned int *__flags, + const char *__symname, + long int *__framesizep); +extern unsigned int la_or1k_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx, +uintptr_t *__refcook, +uintptr_t *__defcook, +const La_or1k_regs *__inregs, +La_or1k_retval *__outregs, +const char *__symname); + +__END_DECLSsysdeps/or1k/dl-machine.h new file +39
-0@@ -0,0 +1,323 @@ +/* Machine-dependent ELF dynamic relocation inline functions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "or1k" + +#include <sys/cdefs.h> +#include <sys/param.h> +#include <tls.h> +#include <dl-irel.h> +#include <dl-static-tls.h> +#include <dl-machine-rel.h> + +/* Return nonzero iff ELF header is compatible with the running host. */ +static inline int __attribute__ ((unused)) +elf_machine_matches_host (const Elf32_Ehdr *ehdr) +{ +return ehdr->e_machine ==EM_OPENRISC ; +} + +static inline Elf32_Addr * +or1k_get_got (void )Quoted 8 lines
sysdeps/or1k/dl-machine.h line 42
Quoted 3 lines
sysdeps/or1k/dl-machine.h new file +3
-0+{ +Elf32_Addr *got; + registerlong int linkreg asm ("r9" );Is the 'r9' a required register by the ABI to use on this assembly snippet? I am asking because local name 'registers' are only a hint to gcc, as we found recently [1], if you really need 'r9' you will probably need to use a global name resgister.
Quoted 4 lines
The r9 is to avoid the snippet from clobbering r9. The result of l.jal will update r9 (link register) we want to make sure that is what we used for %1.
I think there were issues with other ways I tried.
Should you add it the clobbered list instead?
Quoted 8 lines
Let me look into it more.
Quoted 5 lines
Quoted 5 lines
sysdeps/or1k/dl-machine.h new file +5
-0+ asm ("l.jal 0x8\n" +" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" +"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" +"l.add %0, %0, %1\n" + :"=r" (got),"=r" (linkreg));With something like (unstested):
Quoted 12 lines
static inline Elf32_Addr *
or1k_get_got (void)
{
Elf32_Addr *got;
asm ("l.jal 0x8\n"
" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n"
"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n"
"l.add %0, %0, %1\n"
: "=r" (got)
:
: "r9");
}Yes, this is what I ended up changing it to.
Is the indentation important here? I had it as:
static inline Elf32_Addr *
or1k_get_got (void)
{
Elf32_Addr *got;
asm ("l.jal 0x8\n"
" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n"
"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n"
"l.add %0, %0, r9\n"
: "=r" (got) : : "r9");
return got;
}-Stafford
PATCH v3 4/13 or1k: startup and dynamic linking code
Quoted 95 lines · Stafford Horne
Quoted 86 lines · Adhemerval Zanella
Quoted 83 lines · Stafford Horne
Quoted 54 lines · Adhemerval Zanella
Quoted 1 line · Stafford Horne via Libc-alpha
Code for C runtime startup and dynamic loading including PLT layout.
Patch looks ok, although I comment much on ABI and assembly code. Some comments below.
Quoted 46 lines
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.hsysdeps/or1k/bits/link.h new file +23
-0@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */ Quoted 8 lines
sysdeps/or1k/bits/link.h line 28
Quoted 5 lines
sysdeps/or1k/bits/link.h new file +5
-0+typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; +So is the intent is to provide caller all the register, no only the caller-saved registers?
As I see it...
Shouldn't these usually be the argument registers used in
la_pltenterto print our the function call? i.e.
print_enter(refcook, defcook, symname,regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2], *flags);These registers get setup in
sysdeps/{arch}/dl-trampoline.Sby_dl_runtime_profile, which then pass them to_dl_profile_fixup.The problem is openrisc doesn't implement
_dl_runtime_profileso we haven't defined what the registers are.I noticed the same for arc, csky, riscv.
These are needed to be defined for sotruss, but I dont seem them being used.
Quoted 7 lines
Quoted 1 line
Is that correct?
The register are really dependend of the function calling ABI of the architecture, if you check other architecture like x86 and powerpc you will see that
La_i86_regsandLa_ppc64_regsonly saves the caller-saved ones. It is mainly because for PLT tracking, as done by audit modules, other register are not really useful (since they are just internal ones to the caller function).
Quoted 7 lines
I see, but isn't this register saving done in
_dl_profile_resolve?OpenRISC doesn't define
_dl_profile_resolve.I can change the definition of
La_or1k_regs, but as I see it it is currently not used other than building sotruss-lib and audit modules. But I don't see how pltenter will be called without implementing_dl_profile_resolve.
The issue is the definition you set now will define the current audit ABI (LAV_CURRENT), which means if you eventually implement _dl_profile_resolve support for or1k you will need to either save/restore all registers or zero the non calles-saved ones.
That's why modeling the audit PLT register structure over the ABI calling functions makes more sense.
Quoted 111 lines
Quoted 98 lines
Quoted 79 lines
Quoted 70 lines
Quoted 70 lines
sysdeps/or1k/bits/link.h new file +23
-0+/* Return values for calls from PLT. */ +typedef struct La_or1k_retval +{ +uint32_t lrv_r3; +}La_or1k_retval ; + +__BEGIN_DECLS + +extern ElfW(Addr) la_or1k_gnu_pltenter (ElfW(Sym) *__sym, unsigned int __ndx, + uintptr_t *__refcook, + uintptr_t *__defcook, + La_or1k_regs *__regs, + unsigned int *__flags, + const char *__symname, + long int *__framesizep); +extern unsigned int la_or1k_gnu_pltexit (ElfW(Sym) *__sym, unsigned int __ndx, +uintptr_t *__refcook, +uintptr_t *__defcook, +const La_or1k_regs *__inregs, +La_or1k_retval *__outregs, +const char *__symname); + +__END_DECLSsysdeps/or1k/dl-machine.h new file +39
-0@@ -0,0 +1,323 @@ +/* Machine-dependent ELF dynamic relocation inline functions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "or1k" + +#include <sys/cdefs.h> +#include <sys/param.h> +#include <tls.h> +#include <dl-irel.h> +#include <dl-static-tls.h> +#include <dl-machine-rel.h> + +/* Return nonzero iff ELF header is compatible with the running host. */ +static inline int __attribute__ ((unused)) +elf_machine_matches_host (const Elf32_Ehdr *ehdr) +{ +return ehdr->e_machine ==EM_OPENRISC ; +} + +static inline Elf32_Addr * +or1k_get_got (void )Quoted 8 lines
sysdeps/or1k/dl-machine.h line 42
Quoted 3 lines
sysdeps/or1k/dl-machine.h new file +3
-0+{ +Elf32_Addr *got; + registerlong int linkreg asm ("r9" );Is the 'r9' a required register by the ABI to use on this assembly snippet? I am asking because local name 'registers' are only a hint to gcc, as we found recently [1], if you really need 'r9' you will probably need to use a global name resgister.
Quoted 4 lines
The r9 is to avoid the snippet from clobbering r9. The result of l.jal will update r9 (link register) we want to make sure that is what we used for %1.
I think there were issues with other ways I tried.
Should you add it the clobbered list instead?
Quoted 8 lines
Let me look into it more.
Quoted 5 lines
Quoted 5 lines
sysdeps/or1k/dl-machine.h new file +5
-0+ asm ("l.jal 0x8\n" +" l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" +"l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" +"l.add %0, %0, %1\n" + :"=r" (got),"=r" (linkreg));With something like (unstested):
Quoted 12 lines
static inline Elf32_Addr * or1k_get_got (void) { Elf32_Addr *got; asm ("l.jal 0x8\n" " l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" "l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" "l.add %0, %0, %1\n" : "=r" (got) : : "r9"); }
Quoted 3 lines
Yes, this is what I ended up changing it to.
Is the indentation important here? I had it as:
I think either one is fine.
Quoted 16 lines
static inline Elf32_Addr * or1k_get_got (void) { Elf32_Addr *got; asm ("l.jal 0x8\n" " l.movhi %0, gotpchi(_GLOBAL_OFFSET_TABLE_-4)\n" "l.ori %0, %0, gotpclo(_GLOBAL_OFFSET_TABLE_+0)\n" "l.add %0, %0, r9\n" : "=r" (got) : : "r9"); return got; }-Stafford
PATCH v3 4/13 or1k: startup and dynamic linking code
Quoted 106 lines · Adhemerval Zanella
Quoted 95 lines · Stafford Horne
Quoted 86 lines · Adhemerval Zanella
Quoted 83 lines · Stafford Horne
Quoted 54 lines · Adhemerval Zanella
Quoted 1 line · Stafford Horne via Libc-alpha
Code for C runtime startup and dynamic loading including PLT layout.
Patch looks ok, although I comment much on ABI and assembly code. Some comments below.
Quoted 46 lines
--- sysdeps/or1k/bits/link.h | 51 ++++++ sysdeps/or1k/dl-machine.h | 323 +++++++++++++++++++++++++++++++++++++ sysdeps/or1k/dl-start.S | 98 +++++++++++ sysdeps/or1k/ldsodefs.h | 40 +++++ sysdeps/or1k/sotruss-lib.c | 51 ++++++ sysdeps/or1k/start.S | 99 ++++++++++++ sysdeps/or1k/tst-audit.h | 24 +++ 7 files changed, 686 insertions(+) create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/tst-audit.hsysdeps/or1k/bits/link.h new file +23
-0@@ -0,0 +1,51 @@ +/* Declarations for dynamic linker interface. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINK_H +# error "Never include <bits/link.h> directly; use <link.h> instead." +#endif + +/* Registers for entry into PLT. */ Quoted 8 lines
sysdeps/or1k/bits/link.h line 28
Quoted 5 lines
sysdeps/or1k/bits/link.h new file +5
-0+typedef struct La_or1k_regs +{ +uint32_t lr_reg[31 ]; +}La_or1k_regs ; +So is the intent is to provide caller all the register, no only the caller-saved registers?
As I see it...
Shouldn't these usually be the argument registers used in
la_pltenterto print our the function call? i.e.
print_enter(refcook, defcook, symname,regs->lr_reg[0], regs->lr_reg[1], regs->lr_reg[2], *flags);These registers get setup in
sysdeps/{arch}/dl-trampoline.Sby_dl_runtime_profile, which then pass them to_dl_profile_fixup.The problem is openrisc doesn't implement
_dl_runtime_profileso we haven't defined what the registers are.I noticed the same for arc, csky, riscv.
These are needed to be defined for sotruss, but I dont seem them being used.
Quoted 7 lines
Quoted 1 line
Is that correct?
The register are really dependend of the function calling ABI of the architecture, if you check other architecture like x86 and powerpc you will see that
La_i86_regsandLa_ppc64_regsonly saves the caller-saved ones. It is mainly because for PLT tracking, as done by audit modules, other register are not really useful (since they are just internal ones to the caller function).Quoted 7 lines
I see, but isn't this register saving done in
_dl_profile_resolve?OpenRISC doesn't define
_dl_profile_resolve.I can change the definition of
La_or1k_regs, but as I see it it is currently not used other than building sotruss-lib and audit modules. But I don't see how pltenter will be called without implementing_dl_profile_resolve.
Quoted 7 lines
The issue is the definition you set now will define the current audit ABI (
LAV_CURRENT), which means if you eventually implement_dl_profile_resolvesupport for or1k you will need to either save/restore all registers or zero the non calles-saved ones.That's why modeling the audit PLT register structure over the ABI calling functions makes more sense.
Understood, that makes it clear. I will make updates.
-Stafford
PATCH v3 5/13 or1k: Thread Local Storage support
In reply to Stafford HorneOpenRISC includes 3 TLS addressing models. Local Dynamic optimizations are not done in the linker and therefore use the same code sequences as Global Dynamic.
--- sysdeps/or1k/dl-tls.h | 27 +++++ sysdeps/or1k/libc-tls.c | 34 ++++++ sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++++++++++++++++++++++++++++++ sysdeps/or1k/stackinfo.h | 34 ++++++ 5 files changed, 290 insertions(+) create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/stackinfo.h
sysdeps/or1k/dl-tls.h new file +27 -0
@@ -0,0 +1,27 @@ +/* TLS definitions for the ELF dynamic linker. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Type used for the representation of TLS information in the GOT. */ +typedef struct +{ +unsigned long int ti_module; +unsigned long int ti_offset; +}tls_index ; + +extern void *__tls_get_addr (tls_index *ti);
sysdeps/or1k/libc-tls.c new file +34 -0
@@ -0,0 +1,34 @@ +/* Thread-local storage handling in the ELF dynamic linker. +OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <csu/libc-tls.c> +#include <dl-tls.h> + +/* On OpenRISC, linker optimizations are not required, so __tls_get_addr +can be called even in statically linked binaries. In this case module +must be always 1 and PT_TLS segment exist in the binary, otherwise it +would not link. */ + +void * +__tls_get_addr (tls_index *ti) +{ +dtv_t *dtv =THREAD_DTV (); +return (char *) dtv[1 ].pointer.val + ti->ti_offset; +}
sysdeps/or1k/nptl/tcb-offsets.sym new file +6 -0
@@ -0,0 +1,6 @@ +#include <sysdep.h> +#include <tls.h> + +MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) +TID_OFFSET offsetof (struct pthread, tid) +TP_TO_PTHREAD_OFFSET -(sizeof (struct pthread) + sizeof (tcbhead_t))
sysdeps/or1k/nptl/tls.h new file +189 -0
189 lines not on this page · raw message
sysdeps/or1k/stackinfo.h new file +34 -0
@@ -0,0 +1,34 @@ +/* Stack definitions for OpenRISC. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +/* This file contains a bit of information about the stack allocation +of the processor. */ + +#ifndef _STACKINFO_H +#define _STACKINFO_H 1 + +#include <elf.h> + +/* On or1k the stack grows down. */ +#define _STACK_GROWS_DOWN 1 + +/* Default to an executable stack. PF_X can be overridden if PT_GNU_STACK is +present, but it is presumed absent. */ +#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X) + +#endif /* stackinfo.h */
Signature · 1 line
2.31.1
PATCH v3 5/13 or1k: Thread Local Storage support
Quoted 95 lines · Stafford Horne via Libc-alpha
OpenRISC includes 3 TLS addressing models. Local Dynamic optimizations are not done in the linker and therefore use the same code sequences as Global Dynamic.
--- sysdeps/or1k/dl-tls.h | 27 +++++ sysdeps/or1k/libc-tls.c | 34 ++++++ sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++++++++++++++++++++++++++++++ sysdeps/or1k/stackinfo.h | 34 ++++++ 5 files changed, 290 insertions(+) create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/stackinfo.hsysdeps/or1k/dl-tls.h new file +27
-0@@ -0,0 +1,27 @@ +/* TLS definitions for the ELF dynamic linker. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Type used for the representation of TLS information in the GOT. */ +typedef struct +{ +unsigned long int ti_module; +unsigned long int ti_offset; +}tls_index ; + +extern void *__tls_get_addr (tls_index *ti);sysdeps/or1k/libc-tls.c new file +34
-0@@ -0,0 +1,34 @@ +/* Thread-local storage handling in the ELF dynamic linker. +OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <csu/libc-tls.c> +#include <dl-tls.h> + +/* On OpenRISC, linker optimizations are not required, so __tls_get_addr +can be called even in statically linked binaries. In this case module +must be always 1 and PT_TLS segment exist in the binary, otherwise it +would not link. */ + +void * +__tls_get_addr (tls_index *ti) +{ +dtv_t *dtv =THREAD_DTV (); +return (char *) dtv[1 ].pointer.val + ti->ti_offset; +}sysdeps/or1k/nptl/tcb-offsets.sym new file +0
-0
sysdeps/or1k/nptl/tcb-offsets.sym line 6
Quoted 6 lines
sysdeps/or1k/nptl/tcb-offsets.sym new file +6
-0@@ -0,0 +1,6 @@ +#include <sysdep.h> +#include <tls.h> + +MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) +TID_OFFSET offsetof (struct pthread, tid) +TP_TO_PTHREAD_OFFSET -(sizeof (struct pthread) + sizeof (tcbhead_t))
There are not used anywhere, so you can use an empty file for now. And I think these definitions are not used in most architectures, if any.
Quoted 235 lines
sysdeps/or1k/nptl/tls.h new file +189
-0@@ -0,0 +1,189 @@ +/* Definition for thread-local data handling. NPTL/OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _TLS_H +#define _TLS_H 1 + +#include <dl-sysdep.h> + +#ifndef __ASSEMBLER__ +# include <stdbool.h> +# include <stddef.h> +# include <stdint.h> +# include <dl-dtv.h> + +typedef struct +{ +dtv_t *dtv; +void *__padding[3 ];/* To maintain 16 byte padding, needed by STACK_ALIGN. */ +}tcbhead_t ; + +registertcbhead_t *__thread_self __asm__("r10" ); + +# define TLS_MULTIPLE_THREADS_IN_TCB 1 + +#else /* __ASSEMBLER__ */ +# include <tcb-offsets.h> +#endif /* __ASSEMBLER__ */ + +#ifndef __ASSEMBLER__ + +/* Get system call information. */ +# include <sysdep.h> + +/* The TP points to the start of the TLS block. +As I understand it, this isn't strictly that "TP points to DTV" - it's +more where to place the TCB in the TLS block. This will place it in +the beginning. + +Layout: ++-----+-----+----------------------+ +| PRE | TCB | TLS MEMORY .. | ++-----+-----+----------------------+ +^ r10 / TP + +PRE is the struct pthread described below +TCB is tcbhead_t +TLS memory is where the TLS program sections are loaded + +See _dl_allocate_tls_storage and __libc_setup_tls for more information. */ + +# define TLS_DTV_AT_TP 1 +# define TLS_TCB_AT_TP 0 + +/* Get the thread descriptor definition. */ +# include <nptl/descr.h> + +/* Requirements for the TCB. */ +# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) +# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) + +# define TLS_TCB_SIZE sizeof (tcbhead_t) +# define TLS_TCB_ALIGN __alignof__ (struct pthread) + +/* This is the size of the TCB. */ + +/* This is the size we need before TCB. +To support THREAD_GETMEM with friends we want to have a +struct pthread available. +Yank it in infront of everything, I'm sure nobody will mind. + +This memory is really allocated PRE the TLS block, so it's possible +to do ((char*)tlsblock) - TLS_PRE_TCB_SIZE to access it. +This is done for THREAD_SELF. */ + +# define TLS_PRE_TCB_SIZE sizeof (struct pthread) + + +/* Install the dtv pointer. +When called, dtvp is a pointer not the DTV per say (which should start +with the generation counter) but to the length of the DTV. +We can always index with -1, so we store dtvp[1]. */ + +# define INSTALL_DTV (tcbp, dtvp) \ + (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1) + +/* Install new dtv for current thread +In a logicial world dtv here would also point to the length of the DTV. +However it does not, this time it points to the generation counter, +so just store it. + +Note: -1 is still valid and contains the length. */ + +# define INSTALL_NEW_DTV (dtv) (THREAD_DTV() = (dtv)) + +/* Return dtv of given thread descriptor. */ +# define GET_DTV (tcbp) (((tcbhead_t *) (tcbp))->dtv) + +/* Code to initially initialize the thread pointer. + +Set TP to the address _after_ tcbhead_t. This will allow us +to change the size of tcbhead_t without having to re-link everything. + +This has to return NULL on success (or a string with the failure text). +It's hard to fail this, so return NULL always. */ + +# define TLS_INIT_TP (tcbp) \ + ({__thread_self = ((tcbhead_t *)tcbp + 1); NULL;}) + +/* Value passed to 'clone' for initialization of the thread register. */ +# define TLS_DEFINE_INIT_TP (tp, pd) \ + void *tp = ((char *) pd + TLS_PRE_TCB_SIZE + TLS_INIT_TCB_SIZE) + +/* Return the address of the dtv for the current thread. + +Dereference TP, offset to dtv - really straightforward. +Remember that we made TP point to after tcb, so we need to reverse that. */ + +# define THREAD_DTV () \ + ((((tcbhead_t *)__thread_self)-1)->dtv) + +/* Return the thread descriptor for the current thread. + +Return a pointer to the TLS_PRE area where we allocated space for +a struct pthread. Again, TP points to after tcbhead_t, compensate with +TLS_INIT_TCB_SIZE. + +I regard this is a seperate system from the "normal" TLS. */ + +# define THREAD_SELF \ + ((struct pthread *) ((char *) __thread_self - TLS_INIT_TCB_SIZE \ + - TLS_PRE_TCB_SIZE)) + +/* Magic for libthread_db to know how to do THREAD_SELF. */ + +# define DB_THREAD_SELF \ + REGISTER (32, 32, 10 * 4, - TLS_INIT_TCB_SIZE - TLS_PRE_TCB_SIZE) + +/* Access to data in the thread descriptor is easy. */ + +#define THREAD_GETMEM (descr, member) \ + descr->member +#define THREAD_GETMEM_NC (descr, member, idx) \ + descr->member[idx] +#define THREAD_SETMEM (descr, member, value) \ + descr->member = (value) +#define THREAD_SETMEM_NC (descr, member, idx, value) \ + descr->member[idx] = (value) + +/* Get and set the global scope generation counter in struct pthread. */ + +#define THREAD_GSCOPE_FLAG_UNUSED 0 +#define THREAD_GSCOPE_FLAG_USED 1 +#define THREAD_GSCOPE_FLAG_WAIT 2 +#define THREAD_GSCOPE_RESET_FLAG () \ + do \ + { \ + int __res = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag,\ + THREAD_GSCOPE_FLAG_UNUSED); \ + if (__res == THREAD_GSCOPE_FLAG_WAIT) \ + lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, \ + LLL_PRIVATE); \ + } \ + while (0) +#define THREAD_GSCOPE_SET_FLAG () \ + do \ + { \ + THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \ + atomic_write_barrier (); \ + } \ + while (0) + +#endif /* __ASSEMBLER__ */ + +#endif /* tls.h */ sysdeps/or1k/stackinfo.h new file +34
-0@@ -0,0 +1,34 @@ +/* Stack definitions for OpenRISC. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +/* This file contains a bit of information about the stack allocation +of the processor. */ + +#ifndef _STACKINFO_H +#define _STACKINFO_H 1 + +#include <elf.h> + +/* On or1k the stack grows down. */ +#define _STACK_GROWS_DOWN 1 + +/* Default to an executable stack. PF_X can be overridden if PT_GNU_STACK is +present, but it is presumed absent. */ +#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X) + +#endif /* stackinfo.h */
PATCH v3 5/13 or1k: Thread Local Storage support
In reply to Stafford Horne(resending because I hit send button too soon).
Quoted 95 lines · Stafford Horne via Libc-alpha
OpenRISC includes 3 TLS addressing models. Local Dynamic optimizations are not done in the linker and therefore use the same code sequences as Global Dynamic.
--- sysdeps/or1k/dl-tls.h | 27 +++++ sysdeps/or1k/libc-tls.c | 34 ++++++ sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++++++++++++++++++++++++++++++ sysdeps/or1k/stackinfo.h | 34 ++++++ 5 files changed, 290 insertions(+) create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/stackinfo.hsysdeps/or1k/dl-tls.h new file +27
-0@@ -0,0 +1,27 @@ +/* TLS definitions for the ELF dynamic linker. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Type used for the representation of TLS information in the GOT. */ +typedef struct +{ +unsigned long int ti_module; +unsigned long int ti_offset; +}tls_index ; + +extern void *__tls_get_addr (tls_index *ti);sysdeps/or1k/libc-tls.c new file +34
-0@@ -0,0 +1,34 @@ +/* Thread-local storage handling in the ELF dynamic linker. +OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <csu/libc-tls.c> +#include <dl-tls.h> + +/* On OpenRISC, linker optimizations are not required, so __tls_get_addr +can be called even in statically linked binaries. In this case module +must be always 1 and PT_TLS segment exist in the binary, otherwise it +would not link. */ + +void * +__tls_get_addr (tls_index *ti) +{ +dtv_t *dtv =THREAD_DTV (); +return (char *) dtv[1 ].pointer.val + ti->ti_offset; +}sysdeps/or1k/nptl/tcb-offsets.sym new file +0
-0
sysdeps/or1k/nptl/tcb-offsets.sym line 6
Quoted 6 lines
sysdeps/or1k/nptl/tcb-offsets.sym new file +6
-0@@ -0,0 +1,6 @@ +#include <sysdep.h> +#include <tls.h> + +MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) +TID_OFFSET offsetof (struct pthread, tid) +TP_TO_PTHREAD_OFFSET -(sizeof (struct pthread) + sizeof (tcbhead_t))
There are not used anywhere, so you can remove the file along with sysdeps/or1k/nptl/Makefile.
And I think these definitions are not used in most architectures, I will remove from the architectures that do not use it.
Quoted 37 lines
sysdeps/or1k/nptl/tls.h new file +31
-0@@ -0,0 +1,189 @@ +/* Definition for thread-local data handling. NPTL/OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _TLS_H +#define _TLS_H 1 + +#include <dl-sysdep.h> + +#ifndef __ASSEMBLER__ +# include <stdbool.h> +# include <stddef.h> +# include <stdint.h> +# include <dl-dtv.h> + +typedef struct +{
sysdeps/or1k/nptl/tls.h line 41
Quoted 10 lines
sysdeps/or1k/nptl/tls.h new file +10
-0+dtv_t *dtv; + void *__padding[3]; /* To maintain 16 byte padding, needed by STACK_ALIGN. */ +} tcbhead_t; + +registertcbhead_t *__thread_self __asm__("r10" ); + +# define TLS_MULTIPLE_THREADS_IN_TCB 1 + +#else /* __ASSEMBLER__ */ +# include <tcb-offsets.h>
Remove the include, or1k currently does not use it.
Quoted 176 lines
sysdeps/or1k/nptl/tls.h new file +148
-0+#endif /* __ASSEMBLER__ */ + +#ifndef __ASSEMBLER__ + +/* Get system call information. */ +# include <sysdep.h> + +/* The TP points to the start of the TLS block. +As I understand it, this isn't strictly that "TP points to DTV" - it's +more where to place the TCB in the TLS block. This will place it in +the beginning. + +Layout: ++-----+-----+----------------------+ +| PRE | TCB | TLS MEMORY .. | ++-----+-----+----------------------+ +^ r10 / TP + +PRE is the struct pthread described below +TCB is tcbhead_t +TLS memory is where the TLS program sections are loaded + +See _dl_allocate_tls_storage and __libc_setup_tls for more information. */ + +# define TLS_DTV_AT_TP 1 +# define TLS_TCB_AT_TP 0 + +/* Get the thread descriptor definition. */ +# include <nptl/descr.h> + +/* Requirements for the TCB. */ +# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) +# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) + +# define TLS_TCB_SIZE sizeof (tcbhead_t) +# define TLS_TCB_ALIGN __alignof__ (struct pthread) + +/* This is the size of the TCB. */ + +/* This is the size we need before TCB. +To support THREAD_GETMEM with friends we want to have a +struct pthread available. +Yank it in infront of everything, I'm sure nobody will mind. + +This memory is really allocated PRE the TLS block, so it's possible +to do ((char*)tlsblock) - TLS_PRE_TCB_SIZE to access it. +This is done for THREAD_SELF. */ + +# define TLS_PRE_TCB_SIZE sizeof (struct pthread) + + +/* Install the dtv pointer. +When called, dtvp is a pointer not the DTV per say (which should start +with the generation counter) but to the length of the DTV. +We can always index with -1, so we store dtvp[1]. */ + +# define INSTALL_DTV (tcbp, dtvp) \ + (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1) + +/* Install new dtv for current thread +In a logicial world dtv here would also point to the length of the DTV. +However it does not, this time it points to the generation counter, +so just store it. + +Note: -1 is still valid and contains the length. */ + +# define INSTALL_NEW_DTV (dtv) (THREAD_DTV() = (dtv)) + +/* Return dtv of given thread descriptor. */ +# define GET_DTV (tcbp) (((tcbhead_t *) (tcbp))->dtv) + +/* Code to initially initialize the thread pointer. + +Set TP to the address _after_ tcbhead_t. This will allow us +to change the size of tcbhead_t without having to re-link everything. + +This has to return NULL on success (or a string with the failure text). +It's hard to fail this, so return NULL always. */ + +# define TLS_INIT_TP (tcbp) \ + ({__thread_self = ((tcbhead_t *)tcbp + 1); NULL;}) + +/* Value passed to 'clone' for initialization of the thread register. */ +# define TLS_DEFINE_INIT_TP (tp, pd) \ + void *tp = ((char *) pd + TLS_PRE_TCB_SIZE + TLS_INIT_TCB_SIZE) + +/* Return the address of the dtv for the current thread. + +Dereference TP, offset to dtv - really straightforward. +Remember that we made TP point to after tcb, so we need to reverse that. */ + +# define THREAD_DTV () \ + ((((tcbhead_t *)__thread_self)-1)->dtv) + +/* Return the thread descriptor for the current thread. + +Return a pointer to the TLS_PRE area where we allocated space for +a struct pthread. Again, TP points to after tcbhead_t, compensate with +TLS_INIT_TCB_SIZE. + +I regard this is a seperate system from the "normal" TLS. */ + +# define THREAD_SELF \ + ((struct pthread *) ((char *) __thread_self - TLS_INIT_TCB_SIZE \ + - TLS_PRE_TCB_SIZE)) + +/* Magic for libthread_db to know how to do THREAD_SELF. */ + +# define DB_THREAD_SELF \ + REGISTER (32, 32, 10 * 4, - TLS_INIT_TCB_SIZE - TLS_PRE_TCB_SIZE) + +/* Access to data in the thread descriptor is easy. */ + +#define THREAD_GETMEM (descr, member) \ + descr->member +#define THREAD_GETMEM_NC (descr, member, idx) \ + descr->member[idx] +#define THREAD_SETMEM (descr, member, value) \ + descr->member = (value) +#define THREAD_SETMEM_NC (descr, member, idx, value) \ + descr->member[idx] = (value) + +/* Get and set the global scope generation counter in struct pthread. */ + +#define THREAD_GSCOPE_FLAG_UNUSED 0 +#define THREAD_GSCOPE_FLAG_USED 1 +#define THREAD_GSCOPE_FLAG_WAIT 2 +#define THREAD_GSCOPE_RESET_FLAG () \ + do \ + { \ + int __res = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag,\ + THREAD_GSCOPE_FLAG_UNUSED); \ + if (__res == THREAD_GSCOPE_FLAG_WAIT) \ + lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, \ + LLL_PRIVATE); \ + } \ + while (0) +#define THREAD_GSCOPE_SET_FLAG () \ + do \ + { \ + THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \ + atomic_write_barrier (); \ + } \ + while (0) + +#endif /* __ASSEMBLER__ */ + +#endif /* tls.h */ sysdeps/or1k/stackinfo.h new file +22
-0@@ -0,0 +1,34 @@ +/* Stack definitions for OpenRISC. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +/* This file contains a bit of information about the stack allocation +of the processor. */ + +#ifndef _STACKINFO_H
sysdeps/or1k/stackinfo.h line 32
Quoted 10 lines
sysdeps/or1k/stackinfo.h new file +10
-0+#define _STACKINFO_H 1 + +#include <elf.h> + +/* On or1k the stack grows down. */ +#define _STACK_GROWS_DOWN 1 + +/* Default to an executable stack. PF_X can be overridden if PT_GNU_STACK is +present, but it is presumed absent. */ +#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X)
Do you really a default stack executable? It is only done for older ABIs and that's why PT_GNU_STACK was created. Newer ports, like arc and csky assumes otherwise.
Quoted 2 lines
sysdeps/or1k/stackinfo.h new file +2
-0+ +#endif /* stackinfo.h */
PATCH v3 5/13 or1k: Thread Local Storage support
Quoted 7 lines · Adhemerval Zanella via Libc-alpha
sysdeps/or1k/stackinfo.h line 32
Quoted 3 lines
sysdeps/or1k/stackinfo.h new file +3
-0+/* Default to an executable stack. PF_X can be overridden if PT_GNU_STACK is +present, but it is presumed absent. */ +#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X)Do you really a default stack executable? It is only done for older ABIs and that's why
PT_GNU_STACKwas created. Newer ports, like arc and csky assumes otherwise.
I think this reflects what the kernel does (the relevant definitions being elf_read_implies_exec and VM_STACK_DEFAULT_FLAGS / VM_DATA_DEFAULT_FLAGS, none of which are overridden for openrisc, so the default VM_DATA_DEFAULT_FLAGS definition of VM_DATA_FLAGS_EXEC applies).
Signature · 2 lines
Joseph S. Myers joseph at codesourcery.com
PATCH v3 5/13 or1k: Thread Local Storage support
Quoted 10 lines · Joseph Myers
Quoted 7 lines · Adhemerval Zanella via Libc-alpha
sysdeps/or1k/stackinfo.h line 32
Quoted 3 lines
sysdeps/or1k/stackinfo.h new file +3
-0+/* Default to an executable stack. PF_X can be overridden if PT_GNU_STACK is +present, but it is presumed absent. */ +#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X)Do you really a default stack executable? It is only done for older ABIs and that's why
PT_GNU_STACKwas created. Newer ports, like arc and csky assumes otherwise.
Quoted 5 lines
I think this reflects what the kernel does (the relevant definitions being
elf_read_implies_execandVM_STACK_DEFAULT_FLAGS/VM_DATA_DEFAULT_FLAGS, none of which are overridden for openrisc, so the defaultVM_DATA_DEFAULT_FLAGSdefinition ofVM_DATA_FLAGS_EXECapplies).
Fair enough, this part is correct then.
PATCH v3 5/13 or1k: Thread Local Storage support
In reply to Adhemerval ZanellaQuoted 99 lines · Adhemerval Zanella
(resending because I hit send button too soon).
Quoted 96 lines · Stafford Horne via Libc-alpha
OpenRISC includes 3 TLS addressing models. Local Dynamic optimizations are not done in the linker and therefore use the same code sequences as Global Dynamic.
--- sysdeps/or1k/dl-tls.h | 27 +++++ sysdeps/or1k/libc-tls.c | 34 ++++++ sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++++++++++++++++++++++++++++++ sysdeps/or1k/stackinfo.h | 34 ++++++ 5 files changed, 290 insertions(+) create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/stackinfo.hsysdeps/or1k/dl-tls.h new file +27
-0@@ -0,0 +1,27 @@ +/* TLS definitions for the ELF dynamic linker. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Type used for the representation of TLS information in the GOT. */ +typedef struct +{ +unsigned long int ti_module; +unsigned long int ti_offset; +}tls_index ; + +extern void *__tls_get_addr (tls_index *ti);sysdeps/or1k/libc-tls.c new file +34
-0@@ -0,0 +1,34 @@ +/* Thread-local storage handling in the ELF dynamic linker. +OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <csu/libc-tls.c> +#include <dl-tls.h> + +/* On OpenRISC, linker optimizations are not required, so __tls_get_addr +can be called even in statically linked binaries. In this case module +must be always 1 and PT_TLS segment exist in the binary, otherwise it +would not link. */ + +void * +__tls_get_addr (tls_index *ti) +{ +dtv_t *dtv =THREAD_DTV (); +return (char *) dtv[1 ].pointer.val + ti->ti_offset; +}sysdeps/or1k/nptl/tcb-offsets.sym new file +1
-0@@ -0,0 +1,6 @@ +#include <sysdep.h>
Quoted 8 lines
sysdeps/or1k/nptl/tcb-offsets.sym line 6
Quoted 5 lines
sysdeps/or1k/nptl/tcb-offsets.sym new file +5
-0+#include <tls.h> + +MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) +TID_OFFSET offsetof (struct pthread, tid) +TP_TO_PTHREAD_OFFSET -(sizeof (struct pthread) + sizeof (tcbhead_t))There are not used anywhere, so you can remove the file along with sysdeps/or1k/nptl/Makefile.
OK.
Quoted 2 lines
And I think these definitions are not used in most architectures, I will remove from the architectures that do not use it.
Yes, nice cleanup.
Quoted 41 lines
Quoted 41 lines
sysdeps/or1k/nptl/tls.h new file +35
-0@@ -0,0 +1,189 @@ +/* Definition for thread-local data handling. NPTL/OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _TLS_H +#define _TLS_H 1 + +#include <dl-sysdep.h> + +#ifndef __ASSEMBLER__ +# include <stdbool.h> +# include <stddef.h> +# include <stdint.h> +# include <dl-dtv.h> + +typedef struct +{ +dtv_t *dtv; +void *__padding[3 ];/* To maintain 16 byte padding, needed by STACK_ALIGN. */ +}tcbhead_t ; +
Quoted 8 lines
sysdeps/or1k/nptl/tls.h line 41
Quoted 6 lines
sysdeps/or1k/nptl/tls.h new file +6
-0+registertcbhead_t *__thread_self __asm__("r10" ); + +# define TLS_MULTIPLE_THREADS_IN_TCB 1 + +#else /* __ASSEMBLER__ */ +# include <tcb-offsets.h> Remove the include, or1k currently does not use it.
OK.
Quoted 192 lines
Quoted 176 lines
sysdeps/or1k/nptl/tls.h new file +148
-0+#endif /* __ASSEMBLER__ */ + +#ifndef __ASSEMBLER__ + +/* Get system call information. */ +# include <sysdep.h> + +/* The TP points to the start of the TLS block. +As I understand it, this isn't strictly that "TP points to DTV" - it's +more where to place the TCB in the TLS block. This will place it in +the beginning. + +Layout: ++-----+-----+----------------------+ +| PRE | TCB | TLS MEMORY .. | ++-----+-----+----------------------+ +^ r10 / TP + +PRE is the struct pthread described below +TCB is tcbhead_t +TLS memory is where the TLS program sections are loaded + +See _dl_allocate_tls_storage and __libc_setup_tls for more information. */ + +# define TLS_DTV_AT_TP 1 +# define TLS_TCB_AT_TP 0 + +/* Get the thread descriptor definition. */ +# include <nptl/descr.h> + +/* Requirements for the TCB. */ +# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) +# define TLS_INIT_TCB_ALIGN __alignof__ (struct pthread) + +# define TLS_TCB_SIZE sizeof (tcbhead_t) +# define TLS_TCB_ALIGN __alignof__ (struct pthread) + +/* This is the size of the TCB. */ + +/* This is the size we need before TCB. +To support THREAD_GETMEM with friends we want to have a +struct pthread available. +Yank it in infront of everything, I'm sure nobody will mind. + +This memory is really allocated PRE the TLS block, so it's possible +to do ((char*)tlsblock) - TLS_PRE_TCB_SIZE to access it. +This is done for THREAD_SELF. */ + +# define TLS_PRE_TCB_SIZE sizeof (struct pthread) + + +/* Install the dtv pointer. +When called, dtvp is a pointer not the DTV per say (which should start +with the generation counter) but to the length of the DTV. +We can always index with -1, so we store dtvp[1]. */ + +# define INSTALL_DTV (tcbp, dtvp) \ + (((tcbhead_t *) (tcbp))->dtv = (dtvp) + 1) + +/* Install new dtv for current thread +In a logicial world dtv here would also point to the length of the DTV. +However it does not, this time it points to the generation counter, +so just store it. + +Note: -1 is still valid and contains the length. */ + +# define INSTALL_NEW_DTV (dtv) (THREAD_DTV() = (dtv)) + +/* Return dtv of given thread descriptor. */ +# define GET_DTV (tcbp) (((tcbhead_t *) (tcbp))->dtv) + +/* Code to initially initialize the thread pointer. + +Set TP to the address _after_ tcbhead_t. This will allow us +to change the size of tcbhead_t without having to re-link everything. + +This has to return NULL on success (or a string with the failure text). +It's hard to fail this, so return NULL always. */ + +# define TLS_INIT_TP (tcbp) \ + ({__thread_self = ((tcbhead_t *)tcbp + 1); NULL;}) + +/* Value passed to 'clone' for initialization of the thread register. */ +# define TLS_DEFINE_INIT_TP (tp, pd) \ + void *tp = ((char *) pd + TLS_PRE_TCB_SIZE + TLS_INIT_TCB_SIZE) + +/* Return the address of the dtv for the current thread. + +Dereference TP, offset to dtv - really straightforward. +Remember that we made TP point to after tcb, so we need to reverse that. */ + +# define THREAD_DTV () \ + ((((tcbhead_t *)__thread_self)-1)->dtv) + +/* Return the thread descriptor for the current thread. + +Return a pointer to the TLS_PRE area where we allocated space for +a struct pthread. Again, TP points to after tcbhead_t, compensate with +TLS_INIT_TCB_SIZE. + +I regard this is a seperate system from the "normal" TLS. */ + +# define THREAD_SELF \ + ((struct pthread *) ((char *) __thread_self - TLS_INIT_TCB_SIZE \ + - TLS_PRE_TCB_SIZE)) + +/* Magic for libthread_db to know how to do THREAD_SELF. */ + +# define DB_THREAD_SELF \ + REGISTER (32, 32, 10 * 4, - TLS_INIT_TCB_SIZE - TLS_PRE_TCB_SIZE) + +/* Access to data in the thread descriptor is easy. */ + +#define THREAD_GETMEM (descr, member) \ + descr->member +#define THREAD_GETMEM_NC (descr, member, idx) \ + descr->member[idx] +#define THREAD_SETMEM (descr, member, value) \ + descr->member = (value) +#define THREAD_SETMEM_NC (descr, member, idx, value) \ + descr->member[idx] = (value) + +/* Get and set the global scope generation counter in struct pthread. */ + +#define THREAD_GSCOPE_FLAG_UNUSED 0 +#define THREAD_GSCOPE_FLAG_USED 1 +#define THREAD_GSCOPE_FLAG_WAIT 2 +#define THREAD_GSCOPE_RESET_FLAG () \ + do \ + { \ + int __res = atomic_exchange_rel (&THREAD_SELF->header.gscope_flag,\ + THREAD_GSCOPE_FLAG_UNUSED); \ + if (__res == THREAD_GSCOPE_FLAG_WAIT) \ + lll_futex_wake (&THREAD_SELF->header.gscope_flag, 1, \ + LLL_PRIVATE); \ + } \ + while (0) +#define THREAD_GSCOPE_SET_FLAG () \ + do \ + { \ + THREAD_SELF->header.gscope_flag = THREAD_GSCOPE_FLAG_USED; \ + atomic_write_barrier (); \ + } \ + while (0) + +#endif /* __ASSEMBLER__ */ + +#endif /* tls.h */ sysdeps/or1k/stackinfo.h new file +22
-0@@ -0,0 +1,34 @@ +/* Stack definitions for OpenRISC. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +/* This file contains a bit of information about the stack allocation +of the processor. */ + +#ifndef _STACKINFO_Hsysdeps/or1k/stackinfo.h line 32
Quoted 10 lines
sysdeps/or1k/stackinfo.h new file +10
-0+#define _STACKINFO_H 1 + +#include <elf.h> + +/* On or1k the stack grows down. */ +#define _STACK_GROWS_DOWN 1 + +/* Default to an executable stack. PF_X can be overridden if PT_GNU_STACK is +present, but it is presumed absent. */ +#define DEFAULT_STACK_PERMS (PF_R | PF_W | PF_X)Do you really a default stack executable? It is only done for older ABIs and that's why
PT_GNU_STACKwas created. Newer ports, like arc and csky assumes otherwise.Quoted 2 lines
sysdeps/or1k/stackinfo.h new file +2
-0+ +#endif /* stackinfo.h */
PATCH v3 6/13 or1k: Atomics and Locking primitives
In reply to Stafford Horne--- sysdeps/or1k/atomic-machine.h | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sysdeps/or1k/atomic-machine.h
sysdeps/or1k/atomic-machine.h new file +79 -0
@@ -0,0 +1,79 @@ +/* Atomic operations. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef __OR1K_ATOMIC_H_ +#define __OR1K_ATOMIC_H_ + +#include <stdint.h> + +typedef int32_t atomic32_t ; +typedef uint32_t uatomic32_t ; + +typedef intptr_t atomicptr_t ; +typedef uintptr_t uatomicptr_t ; +typedef intmax_t atomic_max_t ; +typedef uintmax_t uatomic_max_t ; + +#define __HAVE_64B_ATOMICS 0 +#define USE_ATOMIC_COMPILER_BUILTINS 1 +#define ATOMIC_EXCHANGE_USES_CAS 1 + +#define __arch_compare_and_exchange_bool_8_int (mem, newval, oldval, model) \ + (abort (), 0) + +#define __arch_compare_and_exchange_bool_16_int (mem, newval, oldval, model) \ + (abort (), 0) + +#define __arch_compare_and_exchange_bool_32_int (mem, newval, oldval, model) \ + ({ \ + typeof (*mem) __oldval = (oldval); \ + !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ + model, __ATOMIC_RELAXED); \ + }) + +#define __arch_compare_and_exchange_bool_64_int (mem, newval, oldval, model) \ + (abort (), 0) + +#define __arch_compare_and_exchange_val_8_int (mem, newval, oldval, model) \ + (abort (), (__typeof (*mem)) 0) + +#define __arch_compare_and_exchange_val_16_int (mem, newval, oldval, model) \ + (abort (), (__typeof (*mem)) 0) + +#define __arch_compare_and_exchange_val_32_int (mem, newval, oldval, model) \ + ({ \ + typeof (*mem) __oldval = (oldval); \ + __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ + model, __ATOMIC_RELAXED); \ + __oldval; \ + }) + +#define __arch_compare_and_exchange_val_64_int (mem, newval, oldval, model) \ + (abort (), (__typeof (*mem)) 0) + +#define atomic_compare_and_exchange_bool_acq (mem, new, old) \ + __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \ + mem, new, old, __ATOMIC_ACQUIRE) + +#define atomic_compare_and_exchange_val_acq (mem, new, old) \ + __atomic_val_bysize (__arch_compare_and_exchange_val, int, \ + mem, new, old, __ATOMIC_ACQUIRE) + +#define atomic_full_barrier () ({ asm volatile ("l.msync" ::: "memory"); }) + +#endif /* atomic-machine.h */
Signature · 1 line
2.31.1
PATCH v3 6/13 or1k: Atomics and Locking primitives
LGTM, thanks.
Quoted 31 lines · Stafford Horne via Libc-alpha
--- sysdeps/or1k/atomic-machine.h | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sysdeps/or1k/atomic-machine.hsysdeps/or1k/atomic-machine.h new file +20
-0@@ -0,0 +1,79 @@ +/* Atomic operations. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef __OR1K_ATOMIC_H_ +#define __OR1K_ATOMIC_H_
sysdeps/or1k/atomic-machine.h line 30
Quoted 10 lines
sysdeps/or1k/atomic-machine.h new file +10
-0+ +#include <stdint.h> + +typedef int32_t atomic32_t ; +typedef uint32_t uatomic32_t ; + +typedef intptr_t atomicptr_t ; +typedef uintptr_t uatomicptr_t ; +typedef intmax_t atomic_max_t ; +typedef uintmax_t uatomic_max_t ;
Sigh, these definition are used solely in only file, memusage.c. Another thing I will cleanup.
Quoted 37 lines
sysdeps/or1k/atomic-machine.h new file +37
-0+ +#define __HAVE_64B_ATOMICS 0 +#define USE_ATOMIC_COMPILER_BUILTINS 1 +#define ATOMIC_EXCHANGE_USES_CAS 1 + +#define __arch_compare_and_exchange_bool_8_int (mem, newval, oldval, model) \ + (abort (), 0) + +#define __arch_compare_and_exchange_bool_16_int (mem, newval, oldval, model) \ + (abort (), 0) + +#define __arch_compare_and_exchange_bool_32_int (mem, newval, oldval, model) \ + ({ \ + typeof (*mem) __oldval = (oldval); \ + !__atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ + model, __ATOMIC_RELAXED); \ + }) + +#define __arch_compare_and_exchange_bool_64_int (mem, newval, oldval, model) \ + (abort (), 0) + +#define __arch_compare_and_exchange_val_8_int (mem, newval, oldval, model) \ + (abort (), (__typeof (*mem)) 0) + +#define __arch_compare_and_exchange_val_16_int (mem, newval, oldval, model) \ + (abort (), (__typeof (*mem)) 0) + +#define __arch_compare_and_exchange_val_32_int (mem, newval, oldval, model) \ + ({ \ + typeof (*mem) __oldval = (oldval); \ + __atomic_compare_exchange_n (mem, (void *) &__oldval, newval, 0, \ + model, __ATOMIC_RELAXED); \ + __oldval; \ + }) + +#define __arch_compare_and_exchange_val_64_int (mem, newval, oldval, model) \ + (abort (), (__typeof (*mem)) 0)
sysdeps/or1k/atomic-machine.h line 77
Quoted 10 lines
sysdeps/or1k/atomic-machine.h new file +10
-0+ +#define atomic_compare_and_exchange_bool_acq (mem, new, old) \ + __atomic_bool_bysize (__arch_compare_and_exchange_bool, int, \ + mem, new, old, __ATOMIC_ACQUIRE) + +#define atomic_compare_and_exchange_val_acq (mem, new, old) \ + __atomic_val_bysize (__arch_compare_and_exchange_val, int, \ + mem, new, old, __ATOMIC_ACQUIRE) + +#define atomic_full_barrier () ({ asm volatile ("l.msync" ::: "memory"); })
And I think we can also clean this up as well.
Quoted 2 lines
sysdeps/or1k/atomic-machine.h new file +2
-0+ +#endif /* atomic-machine.h */
PATCH v3 6/13 or1k: Atomics and Locking primitives
Quoted 39 lines · Adhemerval Zanella
LGTM, thanks.
Quoted 36 lines · Stafford Horne via Libc-alpha
--- sysdeps/or1k/atomic-machine.h | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sysdeps/or1k/atomic-machine.hsysdeps/or1k/atomic-machine.h new file +25
-0@@ -0,0 +1,79 @@ +/* Atomic operations. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef __OR1K_ATOMIC_H_ +#define __OR1K_ATOMIC_H_ + +#include <stdint.h> + +typedef int32_t atomic32_t ; +typedef uint32_t uatomic32_t ;
Quoted 8 lines
sysdeps/or1k/atomic-machine.h line 30
Quoted 5 lines
sysdeps/or1k/atomic-machine.h new file +5
-0+ +typedef intptr_t atomicptr_t ; +typedef uintptr_t uatomicptr_t ; +typedef intmax_t atomic_max_t ; +typedef uintmax_t uatomic_max_t ;Sigh, these definition are used solely in only file,
memusage.c. Another thing I will cleanup.
I just send a patchset that aims to simplify this boilerplate [1]. It should also simplify other parts of OpenRISC submission.
[1] https://sourceware.org/pipermail/libc-alpha/2021-December/134285.html
PATCH v3 6/13 or1k: Atomics and Locking primitives
Quoted 51 lines · Adhemerval Zanella
Quoted 39 lines · Adhemerval Zanella
LGTM, thanks.
Quoted 36 lines · Stafford Horne via Libc-alpha
--- sysdeps/or1k/atomic-machine.h | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 sysdeps/or1k/atomic-machine.hsysdeps/or1k/atomic-machine.h new file +25
-0@@ -0,0 +1,79 @@ +/* Atomic operations. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef __OR1K_ATOMIC_H_ +#define __OR1K_ATOMIC_H_ + +#include <stdint.h> + +typedef int32_t atomic32_t ; +typedef uint32_t uatomic32_t ;Quoted 8 lines
sysdeps/or1k/atomic-machine.h line 30
Quoted 5 lines
sysdeps/or1k/atomic-machine.h new file +5
-0+ +typedef intptr_t atomicptr_t ; +typedef uintptr_t uatomicptr_t ; +typedef intmax_t atomic_max_t ; +typedef uintmax_t uatomic_max_t ;Sigh, these definition are used solely in only file,
memusage.c. Another thing I will cleanup.
Quoted 4 lines
I just send a patchset that aims to simplify this boilerplate [1]. It should also simplify other parts of OpenRISC submission.
[1] https://sourceware.org/pipermail/libc-alpha/2021-December/134285.html
Thanks, I have seen it.
PATCH v3 7/13 or1k: math soft float support
In reply to Stafford HorneOpenRISC support hard float but I will like to submit that after glibc soft float goes upstream. The hard float support depends on adding user access to the FPCSR, which is not supported by the kernel yet.
--- sysdeps/or1k/bits/fenv.h | 69 ++ sysdeps/or1k/libm-test-ulps | 1112 ++++++++++++++++++++ sysdeps/or1k/libm-test-ulps-name | 1 + sysdeps/or1k/nofpu/math-tests-exceptions.h | 29 + sysdeps/or1k/nofpu/math-tests-rounding.h | 28 + sysdeps/or1k/sfp-machine.h | 93 ++ sysdeps/or1k/tininess.h | 1 + 7 files changed, 1333 insertions(+) create mode 100644 sysdeps/or1k/bits/fenv.h create mode 100644 sysdeps/or1k/libm-test-ulps create mode 100644 sysdeps/or1k/libm-test-ulps-name create mode 100644 sysdeps/or1k/nofpu/math-tests-exceptions.h create mode 100644 sysdeps/or1k/nofpu/math-tests-rounding.h create mode 100644 sysdeps/or1k/sfp-machine.h create mode 100644 sysdeps/or1k/tininess.h
sysdeps/or1k/bits/fenv.h new file +69 -0
@@ -0,0 +1,69 @@ +/* Floating point environment, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _FENV_H +# error "Never use <bits/fenv.h> directly; include <fenv.h> instead." +#endif + +/* Define bits representing exceptions in the FPCSR status word. */ +enum + { +FE_OVERFLOW = +#define FE_OVERFLOW (1 << 3) +FE_OVERFLOW , +FE_UNDERFLOW = +#define FE_UNDERFLOW (1 << 4) +FE_UNDERFLOW , +FE_INEXACT = +#define FE_INEXACT (1 << 8) +FE_INEXACT , +FE_INVALID = +#define FE_INVALID (1 << 9) +FE_INVALID , +FE_DIVBYZERO = +#define FE_DIVBYZERO (1 << 11) +FE_DIVBYZERO , + }; + +/* All supported exceptions. */ +#define FE_ALL_EXCEPT \ + (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) + +/* Define bits representing rounding modes in the FPCSR Rmode field. */ +#define FE_TONEAREST (0x0 << 1) +#define FE_TOWARDZERO (0x1 << 1) +#define FE_UPWARD (0x2 << 1) +#define FE_DOWNWARD (0x3 << 1) + +/* Type representing exception flags. */ +typedef unsigned int fexcept_t ; + +/* Type representing floating-point environment. */ +typedef unsigned int fenv_t ; + +/* If the default argument is used we use this value. */ +#define FE_DFL_ENV ((const fenv_t *) -1l) + +#if __GLIBC_USE (IEC_60559_BFP_EXT ) +/* Type representing floating-point control modes. */ +typedef unsigned int femode_t ; + +/* Default floating-point control modes. */ +# define FE_DFL_MODE ((const femode_t *) -1L) +#endif
sysdeps/or1k/libm-test-ulps new file +1112 -0
1,112 lines not on this page · raw message
sysdeps/or1k/libm-test-ulps-name new file +1 -0
@@ -0,0 +1 @@ +OpenRISC
sysdeps/or1k/nofpu/math-tests-exceptions.h new file +29 -0
@@ -0,0 +1,29 @@ +/* Configuration for math tests: support for exceptions. OpenRISC no-FPU +version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef OR1K_NOFPU_MATH_TESTS_EXCEPTIONS_H +#define OR1K_NOFPU_MATH_TESTS_EXCEPTIONS_H 1 + +/* We support setting floating-point exception flags on hard-float +targets. These are not supported on soft-float targets. */ +#define EXCEPTION_TESTS_float 0 +#define EXCEPTION_TESTS_double 0 +#define EXCEPTION_TESTS_long_double 0 + +#endif /* math-tests-exceptions.h. */
sysdeps/or1k/nofpu/math-tests-rounding.h new file +28 -0
@@ -0,0 +1,28 @@ +/* Configuration for math tests: rounding mode support. OpenRISC no-FPU +version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef OR1K_NOFPU_MATH_TESTS_ROUNDING_H +#define OR1K_NOFPU_MATH_TESTS_ROUNDING_H 1 + +/* On soft-float targets we only support the "to nearest" rounding mode. */ +#define ROUNDING_TESTS_float (MODE ) ((MODE) == FE_TONEAREST) +#define ROUNDING_TESTS_double (MODE ) ((MODE) == FE_TONEAREST) +#define ROUNDING_TESTS_long_double (MODE ) ((MODE) == FE_TONEAREST) + +#endif /* math-tests-rounding.h. */
sysdeps/or1k/sfp-machine.h new file +93 -0
93 lines not on this page · raw message
sysdeps/or1k/tininess.h new file +1 -0
@@ -0,0 +1 @@ +#define TININESS_AFTER_ROUNDING 0
Signature · 1 line
2.31.1
PATCH v3 7/13 or1k: math soft float support
Quoted 3 lines · Stafford Horne via Libc-alpha
OpenRISC support hard float but I will like to submit that after glibc soft float goes upstream. The hard float support depends on adding user access to the FPCSR, which is not supported by the kernel yet.
The patch looks ok in general, the fenv bits matches the documentation.
Quoted 56 lines
--- sysdeps/or1k/bits/fenv.h | 69 ++ sysdeps/or1k/libm-test-ulps | 1112 ++++++++++++++++++++ sysdeps/or1k/libm-test-ulps-name | 1 + sysdeps/or1k/nofpu/math-tests-exceptions.h | 29 + sysdeps/or1k/nofpu/math-tests-rounding.h | 28 + sysdeps/or1k/sfp-machine.h | 93 ++ sysdeps/or1k/tininess.h | 1 + 7 files changed, 1333 insertions(+) create mode 100644 sysdeps/or1k/bits/fenv.h create mode 100644 sysdeps/or1k/libm-test-ulps create mode 100644 sysdeps/or1k/libm-test-ulps-name create mode 100644 sysdeps/or1k/nofpu/math-tests-exceptions.h create mode 100644 sysdeps/or1k/nofpu/math-tests-rounding.h create mode 100644 sysdeps/or1k/sfp-machine.h create mode 100644 sysdeps/or1k/tininess.hsysdeps/or1k/bits/fenv.h new file +33
-0@@ -0,0 +1,69 @@ +/* Floating point environment, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _FENV_H +# error "Never use <bits/fenv.h> directly; include <fenv.h> instead." +#endif + +/* Define bits representing exceptions in the FPCSR status word. */ +enum + { +FE_OVERFLOW = +#define FE_OVERFLOW (1 << 3) +FE_OVERFLOW , +FE_UNDERFLOW = +#define FE_UNDERFLOW (1 << 4) +FE_UNDERFLOW , + FE_INEXACT =
sysdeps/or1k/bits/fenv.h line 43
Quoted 10 lines
sysdeps/or1k/bits/fenv.h new file +10
-0+#define FE_INEXACT (1 << 8) + FE_INEXACT, + FE_INVALID = +#define FE_INVALID (1 << 9) + FE_INVALID, + FE_DIVBYZERO = +#define FE_DIVBYZERO (1 << 11) + FE_DIVBYZERO, + }; +
Ok, these match the recv 1.3 documentation.
sysdeps/or1k/bits/fenv.h line 53
Quoted 10 lines
sysdeps/or1k/bits/fenv.h new file +10
-0+/* All supported exceptions. */ +#define FE_ALL_EXCEPT \ + (FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) + +/* Define bits representing rounding modes in the FPCSR Rmode field. */ +#define FE_TONEAREST (0x0 << 1) +#define FE_TOWARDZERO (0x1 << 1) +#define FE_UPWARD (0x2 << 1) +#define FE_DOWNWARD (0x3 << 1) +
Same.
Quoted 1,316 lines
sysdeps/or1k/bits/fenv.h new file +16
-0+/* Type representing exception flags. */ +typedef unsigned int fexcept_t ; + +/* Type representing floating-point environment. */ +typedef unsigned int fenv_t ; + +/* If the default argument is used we use this value. */ +#define FE_DFL_ENV ((const fenv_t *) -1l) + +#if __GLIBC_USE (IEC_60559_BFP_EXT ) +/* Type representing floating-point control modes. */ +typedef unsigned int femode_t ; + +/* Default floating-point control modes. */ +# define FE_DFL_MODE ((const femode_t *) -1L) +#endif sysdeps/or1k/libm-test-ulps new file +1112
-0@@ -0,0 +1,1112 @@ +# Begin of automatic generation + +# Maximal error of functions: +Function: "acos": +double: 1 +float: 1 + +Function: "acos_downward": +double: 1 +float: 1 + +Function: "acos_towardzero": +double: 1 +float: 1 + +Function: "acos_upward": +double: 1 +float: 1 + +Function: "acosh": +double: 2 +float: 2 + +Function: "acosh_downward": +double: 2 +float: 2 + +Function: "acosh_towardzero": +double: 2 +float: 2 + +Function: "acosh_upward": +double: 2 +float: 2 + +Function: "asin": +double: 1 +float: 1 + +Function: "asin_downward": +double: 1 +float: 1 + +Function: "asin_towardzero": +double: 1 +float: 1 + +Function: "asin_upward": +double: 1 +float: 1 + +Function: "asinh": +double: 2 +float: 2 + +Function: "asinh_downward": +double: 3 +float: 3 + +Function: "asinh_towardzero": +double: 2 +float: 2 + +Function: "asinh_upward": +double: 3 +float: 3 + +Function: "atan": +double: 1 +float: 1 + +Function: "atan2": +float: 2 + +Function: "atan2_downward": +double: 5 +float: 2 + +Function: "atan2_towardzero": +double: 5 +float: 2 + +Function: "atan2_upward": +double: 8 +float: 2 + +Function: "atan_downward": +double: 1 +float: 2 + +Function: "atan_towardzero": +double: 1 +float: 1 + +Function: "atan_upward": +double: 1 +float: 2 + +Function: "atanh": +double: 2 +float: 2 + +Function: "atanh_downward": +double: 3 +float: 3 + +Function: "atanh_towardzero": +double: 2 +float: 2 + +Function: "atanh_upward": +double: 3 +float: 3 + +Function: "cabs": +double: 1 + +Function: "cabs_downward": +double: 1 + +Function: "cabs_towardzero": +double: 1 + +Function: "cabs_upward": +double: 1 + +Function: Real part of "cacos": +double: 1 +float: 2 + +Function: Imaginary part of "cacos": +double: 2 +float: 2 + +Function: Real part of "cacos_downward": +double: 3 +float: 2 + +Function: Imaginary part of "cacos_downward": +double: 5 +float: 3 + +Function: Real part of "cacos_towardzero": +double: 3 +float: 2 + +Function: Imaginary part of "cacos_towardzero": +double: 4 +float: 2 + +Function: Real part of "cacos_upward": +double: 2 +float: 2 + +Function: Imaginary part of "cacos_upward": +double: 5 +float: 7 + +Function: Real part of "cacosh": +double: 2 +float: 2 + +Function: Imaginary part of "cacosh": +double: 1 +float: 2 + +Function: Real part of "cacosh_downward": +double: 4 +float: 2 + +Function: Imaginary part of "cacosh_downward": +double: 3 +float: 3 + +Function: Real part of "cacosh_towardzero": +double: 4 +float: 2 + +Function: Imaginary part of "cacosh_towardzero": +double: 3 +float: 2 + +Function: Real part of "cacosh_upward": +double: 4 +float: 3 + +Function: Imaginary part of "cacosh_upward": +double: 3 +float: 2 + +Function: "carg": +float: 1 + +Function: "carg_downward": +double: 5 +float: 2 + +Function: "carg_towardzero": +double: 5 +float: 2 + +Function: "carg_upward": +double: 8 +float: 2 + +Function: Real part of "casin": +double: 1 +float: 1 + +Function: Imaginary part of "casin": +double: 2 +float: 2 + +Function: Real part of "casin_downward": +double: 3 +float: 2 + +Function: Imaginary part of "casin_downward": +double: 5 +float: 3 + +Function: Real part of "casin_towardzero": +double: 3 +float: 1 + +Function: Imaginary part of "casin_towardzero": +double: 4 +float: 2 + +Function: Real part of "casin_upward": +double: 3 +float: 2 + +Function: Imaginary part of "casin_upward": +double: 5 +float: 7 + +Function: Real part of "casinh": +double: 2 +float: 2 + +Function: Imaginary part of "casinh": +double: 1 +float: 1 + +Function: Real part of "casinh_downward": +double: 5 +float: 3 + +Function: Imaginary part of "casinh_downward": +double: 3 +float: 2 + +Function: Real part of "casinh_towardzero": +double: 4 +float: 2 + +Function: Imaginary part of "casinh_towardzero": +double: 3 +float: 1 + +Function: Real part of "casinh_upward": +double: 5 +float: 7 + +Function: Imaginary part of "casinh_upward": +double: 3 +float: 2 + +Function: Real part of "catan": +double: 1 +float: 1 + +Function: Imaginary part of "catan": +double: 1 +float: 1 + +Function: Real part of "catan_downward": +double: 1 +float: 2 + +Function: Imaginary part of "catan_downward": +double: 2 +float: 2 + +Function: Real part of "catan_towardzero": +double: 1 +float: 2 + +Function: Imaginary part of "catan_towardzero": +double: 2 +float: 2 + +Function: Real part of "catan_upward": +double: 2 +float: 1 + +Function: Imaginary part of "catan_upward": +double: 2 +float: 2 + +Function: Real part of "catanh": +double: 1 +float: 1 + +Function: Imaginary part of "catanh": +double: 1 +float: 1 + +Function: Real part of "catanh_downward": +double: 2 +float: 2 + +Function: Imaginary part of "catanh_downward": +double: 1 +float: 2 + +Function: Real part of "catanh_towardzero": +double: 2 +float: 2 + +Function: Imaginary part of "catanh_towardzero": +double: 1 +float: 2 + +Function: Real part of "catanh_upward": +double: 4 +float: 4 + +Function: Imaginary part of "catanh_upward": +double: 2 +float: 1 + +Function: "cbrt": +double: 4 +float: 1 + +Function: "cbrt_downward": +double: 4 +float: 1 + +Function: "cbrt_towardzero": +double: 3 +float: 1 + +Function: "cbrt_upward": +double: 5 +float: 1 + +Function: Real part of "ccos": +double: 1 +float: 1 + +Function: Imaginary part of "ccos": +double: 1 +float: 1 + +Function: Real part of "ccos_downward": +double: 3 +float: 1 + +Function: Imaginary part of "ccos_downward": +double: 3 +float: 3 + +Function: Real part of "ccos_towardzero": +double: 3 +float: 2 + +Function: Imaginary part of "ccos_towardzero": +double: 3 +float: 3 + +Function: Real part of "ccos_upward": +double: 1 +float: 2 + +Function: Imaginary part of "ccos_upward": +double: 2 +float: 2 + +Function: Real part of "ccosh": +double: 2 +float: 1 + +Function: Imaginary part of "ccosh": +double: 1 +float: 1 + +Function: Real part of "ccosh_downward": +double: 3 +float: 2 + +Function: Imaginary part of "ccosh_downward": +double: 3 +float: 3 + +Function: Real part of "ccosh_towardzero": +double: 3 +float: 3 + +Function: Imaginary part of "ccosh_towardzero": +double: 3 +float: 3 + +Function: Real part of "ccosh_upward": +double: 1 +float: 2 + +Function: Imaginary part of "ccosh_upward": +double: 2 +float: 2 + +Function: Real part of "cexp": +double: 2 +float: 1 + +Function: Imaginary part of "cexp": +double: 1 +float: 2 + +Function: Real part of "cexp_downward": +double: 4 +float: 2 + +Function: Imaginary part of "cexp_downward": +double: 3 +float: 3 + +Function: Real part of "cexp_towardzero": +double: 4 +float: 2 + +Function: Imaginary part of "cexp_towardzero": +double: 3 +float: 3 + +Function: Real part of "cexp_upward": +double: 2 +float: 2 + +Function: Imaginary part of "cexp_upward": +double: 3 +float: 2 + +Function: Real part of "clog": +double: 3 +float: 3 + +Function: Imaginary part of "clog": +double: 1 +float: 1 + +Function: Real part of "clog10": +double: 3 +float: 4 + +Function: Imaginary part of "clog10": +double: 2 +float: 2 + +Function: Real part of "clog10_downward": +double: 7 +float: 5 + +Function: Imaginary part of "clog10_downward": +double: 8 +float: 4 + +Function: Real part of "clog10_towardzero": +double: 5 +float: 5 + +Function: Imaginary part of "clog10_towardzero": +double: 8 +float: 4 + +Function: Real part of "clog10_upward": +double: 6 +float: 5 + +Function: Imaginary part of "clog10_upward": +double: 5 +float: 4 + +Function: Real part of "clog_downward": +double: 4 +float: 3 + +Function: Imaginary part of "clog_downward": +double: 5 +float: 2 + +Function: Real part of "clog_towardzero": +double: 8 +float: 4 + +Function: Imaginary part of "clog_towardzero": +double: 5 +float: 3 + +Function: Real part of "clog_upward": +double: 8 +float: 3 + +Function: Imaginary part of "clog_upward": +double: 8 +float: 2 + +Function: "cos": +double: 1 +float: 1 + +Function: "cos_downward": +double: 1 +float: 1 + +Function: "cos_towardzero": +double: 4 +float: 1 + +Function: "cos_upward": +double: 4 +float: 1 + +Function: "cosh": +double: 2 +float: 2 + +Function: "cosh_downward": +double: 2 +float: 1 + +Function: "cosh_towardzero": +double: 2 +float: 1 + +Function: "cosh_upward": +double: 2 +float: 2 + +Function: Real part of "cpow": +double: 2 +float: 5 + +Function: Imaginary part of "cpow": +float: 2 + +Function: Real part of "cpow_downward": +double: 5 +float: 8 + +Function: Imaginary part of "cpow_downward": +double: 2 +float: 2 + +Function: Real part of "cpow_towardzero": +double: 5 +float: 8 + +Function: Imaginary part of "cpow_towardzero": +double: 2 +float: 2 + +Function: Real part of "cpow_upward": +double: 4 +float: 1 + +Function: Imaginary part of "cpow_upward": +double: 2 +float: 2 + +Function: Real part of "csin": +double: 1 +float: 1 + +Function: Real part of "csin_downward": +double: 3 +float: 3 + +Function: Imaginary part of "csin_downward": +double: 3 +float: 1 + +Function: Real part of "csin_towardzero": +double: 3 +float: 3 + +Function: Imaginary part of "csin_towardzero": +double: 3 +float: 1 + +Function: Real part of "csin_upward": +double: 2 +float: 2 + +Function: Imaginary part of "csin_upward": +double: 1 +float: 2 + +Function: Real part of "csinh": +float: 1 + +Function: Imaginary part of "csinh": +double: 1 +float: 1 + +Function: Real part of "csinh_downward": +double: 3 +float: 1 + +Function: Imaginary part of "csinh_downward": +double: 3 +float: 3 + +Function: Real part of "csinh_towardzero": +double: 3 +float: 2 + +Function: Imaginary part of "csinh_towardzero": +double: 3 +float: 3 + +Function: Real part of "csinh_upward": +double: 1 +float: 2 + +Function: Imaginary part of "csinh_upward": +double: 2 +float: 2 + +Function: Real part of "csqrt": +double: 2 +float: 2 + +Function: Imaginary part of "csqrt": +double: 2 +float: 2 + +Function: Real part of "csqrt_downward": +double: 5 +float: 4 + +Function: Imaginary part of "csqrt_downward": +double: 4 +float: 3 + +Function: Real part of "csqrt_towardzero": +double: 4 +float: 3 + +Function: Imaginary part of "csqrt_towardzero": +double: 4 +float: 3 + +Function: Real part of "csqrt_upward": +double: 5 +float: 4 + +Function: Imaginary part of "csqrt_upward": +double: 3 +float: 3 + +Function: Real part of "ctan": +double: 1 +float: 1 + +Function: Imaginary part of "ctan": +double: 2 +float: 2 + +Function: Real part of "ctan_downward": +double: 6 +float: 5 + +Function: Imaginary part of "ctan_downward": +double: 3 +float: 2 + +Function: Real part of "ctan_towardzero": +double: 5 +float: 3 + +Function: Imaginary part of "ctan_towardzero": +double: 3 +float: 2 + +Function: Real part of "ctan_upward": +double: 2 +float: 4 + +Function: Imaginary part of "ctan_upward": +double: 2 +float: 1 + +Function: Real part of "ctanh": +double: 2 +float: 2 + +Function: Imaginary part of "ctanh": +double: 2 +float: 2 + +Function: Real part of "ctanh_downward": +double: 3 +float: 2 + +Function: Imaginary part of "ctanh_downward": +double: 6 +float: 5 + +Function: Real part of "ctanh_towardzero": +double: 3 +float: 2 + +Function: Imaginary part of "ctanh_towardzero": +double: 5 +float: 3 + +Function: Real part of "ctanh_upward": +double: 2 +float: 2 + +Function: Imaginary part of "ctanh_upward": +double: 2 +float: 3 + +Function: "erf": +double: 1 +float: 1 + +Function: "erf_downward": +double: 1 +float: 1 + +Function: "erf_towardzero": +double: 1 +float: 1 + +Function: "erf_upward": +double: 1 +float: 1 + +Function: "erfc": +double: 5 +float: 3 + +Function: "erfc_downward": +double: 5 +float: 6 + +Function: "erfc_towardzero": +double: 3 +float: 4 + +Function: "erfc_upward": +double: 5 +float: 6 + +Function: "exp": +double: 1 +float: 1 + +Function: "exp10": +double: 2 +float: 1 + +Function: "exp10_downward": +double: 3 + +Function: "exp10_towardzero": +double: 3 + +Function: "exp10_upward": +double: 2 +float: 1 + +Function: "exp2": +double: 1 + +Function: "exp2_downward": +double: 1 + +Function: "exp2_towardzero": +double: 1 + +Function: "exp2_upward": +double: 1 +float: 1 + +Function: "exp_downward": +double: 1 +float: 1 + +Function: "exp_towardzero": +double: 1 +float: 1 + +Function: "exp_upward": +double: 1 +float: 1 + +Function: "expm1": +double: 1 +float: 1 + +Function: "expm1_downward": +double: 1 +float: 1 + +Function: "expm1_towardzero": +double: 1 +float: 2 + +Function: "expm1_upward": +double: 1 +float: 1 + +Function: "gamma": +double: 4 +float: 7 + +Function: "gamma_downward": +double: 7 +float: 7 + +Function: "gamma_towardzero": +double: 7 +float: 7 + +Function: "gamma_upward": +double: 5 +float: 6 + +Function: "hypot": +double: 1 + +Function: "hypot_downward": +double: 1 + +Function: "hypot_towardzero": +double: 1 + +Function: "hypot_upward": +double: 1 + +Function: "j0": +double: 2 +float: 9 + +Function: "j0_downward": +double: 2 +float: 4 + +Function: "j0_towardzero": +double: 4 +float: 5 + +Function: "j0_upward": +double: 4 +float: 5 + +Function: "j1": +double: 4 +float: 9 + +Function: "j1_downward": +double: 4 +float: 5 + +Function: "j1_towardzero": +double: 4 +float: 2 + +Function: "j1_upward": +double: 3 +float: 5 + +Function: "jn": +double: 4 +float: 4 + +Function: "jn_downward": +double: 7 +float: 9 + +Function: "jn_towardzero": +double: 7 +float: 9 + +Function: "jn_upward": +double: 7 +float: 9 + +Function: "lgamma": +double: 4 +float: 7 + +Function: "lgamma_downward": +double: 7 +float: 7 + +Function: "lgamma_towardzero": +double: 7 +float: 7 + +Function: "lgamma_upward": +double: 5 +float: 6 + +Function: "log10": +double: 2 +float: 2 + +Function: "log10_downward": +double: 2 +float: 3 + +Function: "log10_towardzero": +double: 2 +float: 1 + +Function: "log10_upward": +double: 2 +float: 2 + +Function: "log1p": +double: 1 +float: 1 + +Function: "log1p_downward": +double: 2 +float: 2 + +Function: "log1p_towardzero": +double: 2 +float: 2 + +Function: "log1p_upward": +double: 2 +float: 2 + +Function: "log2": +float: 1 + +Function: "log2_downward": +double: 1 + +Function: "log2_towardzero": +double: 1 + +Function: "log2_upward": +double: 1 + +Function: "pow": +double: 1 + +Function: "pow_downward": +double: 1 +float: 1 + +Function: "pow_towardzero": +double: 1 +float: 1 + +Function: "pow_upward": +double: 1 +float: 1 + +Function: "sin": +double: 1 +float: 1 + +Function: "sin_downward": +double: 4 +float: 1 + +Function: "sin_towardzero": +double: 3 +float: 1 + +Function: "sin_upward": +double: 7 +float: 1 + +Function: "sincos": +double: 1 + +Function: "sincos_downward": +double: 1 +float: 1 + +Function: "sincos_towardzero": +double: 4 +float: 1 + +Function: "sincos_upward": +double: 1 +float: 1 + +Function: "sinh": +double: 2 +float: 2 + +Function: "sinh_downward": +double: 3 +float: 3 + +Function: "sinh_towardzero": +double: 2 +float: 2 + +Function: "sinh_upward": +double: 3 +float: 3 + +Function: "tan": +float: 1 + +Function: "tan_downward": +double: 1 +float: 2 + +Function: "tan_towardzero": +double: 1 +float: 1 + +Function: "tan_upward": +double: 1 +float: 1 + +Function: "tanh": +double: 2 +float: 2 + +Function: "tanh_downward": +double: 3 +float: 3 + +Function: "tanh_towardzero": +double: 2 +float: 2 + +Function: "tanh_upward": +double: 3 +float: 3 + +Function: "tgamma": +double: 9 +float: 8 + +Function: "tgamma_downward": +double: 9 +float: 9 + +Function: "tgamma_towardzero": +double: 9 +float: 8 + +Function: "tgamma_upward": +double: 9 +float: 8 + +Function: "y0": +double: 3 +float: 9 + +Function: "y0_downward": +double: 3 +float: 6 + +Function: "y0_towardzero": +double: 3 +float: 3 + +Function: "y0_upward": +double: 3 +float: 6 + +Function: "y1": +double: 3 +float: 9 + +Function: "y1_downward": +double: 6 +float: 7 + +Function: "y1_towardzero": +double: 3 +float: 3 + +Function: "y1_upward": +double: 7 +float: 5 + +Function: "yn": +double: 3 +float: 3 + +Function: "yn_downward": +double: 6 +float: 8 + +Function: "yn_towardzero": +double: 8 +float: 8 + +Function: "yn_upward": +double: 8 +float: 8 + +# end of automatic generationsysdeps/or1k/libm-test-ulps-name new file +1
-0@@ -0,0 +1 @@ +OpenRISCsysdeps/or1k/nofpu/math-tests-exceptions.h new file +29
-0@@ -0,0 +1,29 @@ +/* Configuration for math tests: support for exceptions. OpenRISC no-FPU +version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef OR1K_NOFPU_MATH_TESTS_EXCEPTIONS_H +#define OR1K_NOFPU_MATH_TESTS_EXCEPTIONS_H 1 + +/* We support setting floating-point exception flags on hard-float +targets. These are not supported on soft-float targets. */ +#define EXCEPTION_TESTS_float 0 +#define EXCEPTION_TESTS_double 0 +#define EXCEPTION_TESTS_long_double 0 + +#endif /* math-tests-exceptions.h. */ sysdeps/or1k/nofpu/math-tests-rounding.h new file +28
-0@@ -0,0 +1,28 @@ +/* Configuration for math tests: rounding mode support. OpenRISC no-FPU +version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef OR1K_NOFPU_MATH_TESTS_ROUNDING_H +#define OR1K_NOFPU_MATH_TESTS_ROUNDING_H 1 + +/* On soft-float targets we only support the "to nearest" rounding mode. */ +#define ROUNDING_TESTS_float (MODE ) ((MODE) == FE_TONEAREST) +#define ROUNDING_TESTS_double (MODE ) ((MODE) == FE_TONEAREST) +#define ROUNDING_TESTS_long_double (MODE ) ((MODE) == FE_TONEAREST) + +#endif /* math-tests-rounding.h. */ sysdeps/or1k/sfp-machine.h new file +93
-0@@ -0,0 +1,93 @@ +/* OpenRISC softfloat definitions. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#define _FP_W_TYPE_SIZE 32 +#define _FP_W_TYPE unsigned long +#define _FP_WS_TYPE signed long +#define _FP_I_TYPE long + +#define _FP_MUL_MEAT_S (R ,X ,Y ) \ + _FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm) +#define _FP_MUL_MEAT_D (R ,X ,Y ) \ + _FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) +#define _FP_MUL_MEAT_Q (R ,X ,Y ) \ + _FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm) + +#define _FP_MUL_MEAT_DW_S (R ,X ,Y ) \ + _FP_MUL_MEAT_DW_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm) +#define _FP_MUL_MEAT_DW_D (R ,X ,Y ) \ + _FP_MUL_MEAT_DW_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm) +#define _FP_MUL_MEAT_DW_Q (R ,X ,Y ) \ + _FP_MUL_MEAT_DW_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm) + + +#define _FP_DIV_MEAT_S (R ,X ,Y ) _FP_DIV_MEAT_1_loop(S,R,X,Y) +#define _FP_DIV_MEAT_D (R ,X ,Y ) _FP_DIV_MEAT_2_udiv(D,R,X,Y) +#define _FP_DIV_MEAT_Q (R ,X ,Y ) _FP_DIV_MEAT_4_udiv(Q,R,X,Y) + +#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1) +#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1 +#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1 +#define _FP_NANSIGN_S 0 +#define _FP_NANSIGN_D 0 +#define _FP_NANSIGN_Q 0 + +#define _FP_KEEPNANFRACP 1 +#define _FP_QNANNEGATEDP 0 + +/* Someone please check this. */ +#define _FP_CHOOSENAN (fs, wc,R ,X ,Y ,OP ) \ + do { \ + if ((_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs) \ + && !(_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs)) \ + { \ + R##_s = Y##_s; \ + _FP_FRAC_COPY_##wc(R,Y); \ + } \ + else \ + { \ + R##_s = X##_s; \ + _FP_FRAC_COPY_##wc(R,X); \ + } \ + R##_c = FP_CLS_NAN; \ + } while (0) + +/* Handle getting and setting rounding mode for soft fp operations. */ + +#define FP_RND_NEAREST (0x0 << 1) +#define FP_RND_ZERO (0x1 << 1) +#define FP_RND_PINF (0x2 << 1) +#define FP_RND_MINF (0x3 << 1) +#define FP_RND_MASK (0x3 << 1) + +#define FP_EX_OVERFLOW (1 << 3) +#define FP_EX_UNDERFLOW (1 << 4) +#define FP_EX_INEXACT (1 << 8) +#define FP_EX_INVALID (1 << 9) +#define FP_EX_DIVZERO (1 << 11) +#define FP_EX_ALL \ + (FP_EX_INVALID | FP_EX_DIVZERO | FP_EX_OVERFLOW | FP_EX_UNDERFLOW \ + | FP_EX_INEXACT) + +#define _FP_DECL_EX \ + unsigned int _fpcsr __attribute__ ((unused)) = FP_RND_NEAREST + +#define FP_ROUNDMODE (_fpcsr & FP_RND_MASK) + +#define _FP_TININESS_AFTER_ROUNDING 0sysdeps/or1k/tininess.h new file +1
-0@@ -0,0 +1 @@ +#define TININESS_AFTER_ROUNDING 0
PATCH v3 7/13 or1k: math soft float support
Quoted 8 lines · Adhemerval Zanella
Quoted 3 lines · Stafford Horne via Libc-alpha
OpenRISC support hard float but I will like to submit that after glibc soft float goes upstream. The hard float support depends on adding user access to the FPCSR, which is not supported by the kernel yet.
The patch looks ok in general, the fenv bits matches the documentation.
Thank you.
PATCH v3 8/13 or1k: Linux Syscall Interface
In reply to Stafford Horne--- sysdeps/unix/sysv/linux/or1k/arch-syscall.h | 325 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/bits/timesize.h | 19 + sysdeps/unix/sysv/linux/or1k/clone.c | 61 ++++ sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h | 41 +++ sysdeps/unix/sysv/linux/or1k/mmap_internal.h | 28 ++ sysdeps/unix/sysv/linux/or1k/or1k_clone.S | 89 +++++ sysdeps/unix/sysv/linux/or1k/sysdep.c | 34 ++ sysdeps/unix/sysv/linux/or1k/sysdep.h | 201 +++++++++++ 8 files changed, 798 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/or1k/arch-syscall.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/timesize.h create mode 100644 sysdeps/unix/sysv/linux/or1k/clone.c create mode 100644 sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h create mode 100644 sysdeps/unix/sysv/linux/or1k/mmap_internal.h create mode 100644 sysdeps/unix/sysv/linux/or1k/or1k_clone.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.c create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.h
sysdeps/unix/sysv/linux/or1k/arch-syscall.h new file +325 -0
@@ -0,0 +1,325 @@ +/* AUTOGENERATED by update-syscall-lists.py. */ +#define __NR_accept 202 +#define __NR_accept4 242 +#define __NR_acct 89 +#define __NR_add_key 217 +#define __NR_adjtimex 171 +#define __NR_bind 200 +#define __NR_bpf 280 +#define __NR_brk 214 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_chdir 49 +#define __NR_chroot 51 +#define __NR_clock_adjtime 266 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres 114 +#define __NR_clock_getres_time64 406 +#define __NR_clock_gettime 113 +#define __NR_clock_gettime64 403 +#define __NR_clock_nanosleep 115 +#define __NR_clock_nanosleep_time64 407 +#define __NR_clock_settime 112 +#define __NR_clock_settime64 404 +#define __NR_clone 220 +#define __NR_clone3 435 +#define __NR_close 57 +#define __NR_close_range 436 +#define __NR_connect 203 +#define __NR_copy_file_range 285 +#define __NR_delete_module 106 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_epoll_pwait2 441 +#define __NR_eventfd2 19 +#define __NR_execve 221 +#define __NR_execveat 281 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_faccessat 48 +#define __NR_faccessat2 439 +#define __NR_fadvise64_64 223 +#define __NR_fallocate 47 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_fchdir 50 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchown 55 +#define __NR_fchownat 54 +#define __NR_fcntl64 25 +#define __NR_fdatasync 83 +#define __NR_fgetxattr 10 +#define __NR_finit_module 273 +#define __NR_flistxattr 13 +#define __NR_flock 32 +#define __NR_fremovexattr 16 +#define __NR_fsconfig 431 +#define __NR_fsetxattr 7 +#define __NR_fsmount 432 +#define __NR_fsopen 430 +#define __NR_fspick 433 +#define __NR_fstat64 80 +#define __NR_fstatat64 79 +#define __NR_fstatfs64 44 +#define __NR_fsync 82 +#define __NR_ftruncate64 46 +#define __NR_futex 98 +#define __NR_futex_time64 422 +#define __NR_get_mempolicy 236 +#define __NR_get_robust_list 100 +#define __NR_getcpu 168 +#define __NR_getcwd 17 +#define __NR_getdents64 61 +#define __NR_getegid 177 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getgroups 158 +#define __NR_getitimer 102 +#define __NR_getpeername 205 +#define __NR_getpgid 155 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getpriority 141 +#define __NR_getrandom 278 +#define __NR_getresgid 150 +#define __NR_getresuid 148 +#define __NR_getrlimit 163 +#define __NR_getrusage 165 +#define __NR_getsid 156 +#define __NR_getsockname 204 +#define __NR_getsockopt 209 +#define __NR_gettid 178 +#define __NR_gettimeofday 169 +#define __NR_getuid 174 +#define __NR_getxattr 8 +#define __NR_init_module 105 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_init1 26 +#define __NR_inotify_rm_watch 28 +#define __NR_io_cancel 3 +#define __NR_io_destroy 1 +#define __NR_io_getevents 4 +#define __NR_io_pgetevents 292 +#define __NR_io_pgetevents_time64 416 +#define __NR_io_setup 0 +#define __NR_io_submit 2 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_io_uring_setup 425 +#define __NR_ioctl 29 +#define __NR_ioprio_get 31 +#define __NR_ioprio_set 30 +#define __NR_kcmp 272 +#define __NR_kexec_file_load 294 +#define __NR_kexec_load 104 +#define __NR_keyctl 219 +#define __NR_kill 129 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_restrict_self 446 +#define __NR_lgetxattr 9 +#define __NR_linkat 37 +#define __NR_listen 201 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_llseek 62 +#define __NR_lookup_dcookie 18 +#define __NR_lremovexattr 15 +#define __NR_lsetxattr 6 +#define __NR_madvise 233 +#define __NR_mbind 235 +#define __NR_membarrier 283 +#define __NR_memfd_create 279 +#define __NR_migrate_pages 238 +#define __NR_mincore 232 +#define __NR_mkdirat 34 +#define __NR_mknodat 33 +#define __NR_mlock 228 +#define __NR_mlock2 284 +#define __NR_mlockall 230 +#define __NR_mmap2 222 +#define __NR_mount 40 +#define __NR_mount_setattr 442 +#define __NR_move_mount 429 +#define __NR_move_pages 239 +#define __NR_mprotect 226 +#define __NR_mq_getsetattr 185 +#define __NR_mq_notify 184 +#define __NR_mq_open 180 +#define __NR_mq_timedreceive 183 +#define __NR_mq_timedreceive_time64 419 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_unlink 181 +#define __NR_mremap 216 +#define __NR_msgctl 187 +#define __NR_msgget 186 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_msync 227 +#define __NR_munlock 229 +#define __NR_munlockall 231 +#define __NR_munmap 215 +#define __NR_name_to_handle_at 264 +#define __NR_nanosleep 101 +#define __NR_nfsservctl 42 +#define __NR_open_by_handle_at 265 +#define __NR_open_tree 428 +#define __NR_openat 56 +#define __NR_openat2 437 +#define __NR_or1k_atomic 244 +#define __NR_perf_event_open 241 +#define __NR_personality 92 +#define __NR_pidfd_getfd 438 +#define __NR_pidfd_open 434 +#define __NR_pidfd_send_signal 424 +#define __NR_pipe2 59 +#define __NR_pivot_root 41 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_pkey_mprotect 288 +#define __NR_ppoll 73 +#define __NR_ppoll_time64 414 +#define __NR_prctl 167 +#define __NR_pread64 67 +#define __NR_preadv 69 +#define __NR_preadv2 286 +#define __NR_prlimit64 261 +#define __NR_process_madvise 440 +#define __NR_process_mrelease 448 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_pselect6 72 +#define __NR_pselect6_time64 413 +#define __NR_ptrace 117 +#define __NR_pwrite64 68 +#define __NR_pwritev 70 +#define __NR_pwritev2 287 +#define __NR_quotactl 60 +#define __NR_quotactl_fd 443 +#define __NR_read 63 +#define __NR_readahead 213 +#define __NR_readlinkat 78 +#define __NR_readv 65 +#define __NR_reboot 142 +#define __NR_recvfrom 207 +#define __NR_recvmmsg 243 +#define __NR_recvmmsg_time64 417 +#define __NR_recvmsg 212 +#define __NR_remap_file_pages 234 +#define __NR_removexattr 14 +#define __NR_renameat 38 +#define __NR_renameat2 276 +#define __NR_request_key 218 +#define __NR_restart_syscall 128 +#define __NR_rseq 293 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_getaffinity 123 +#define __NR_sched_getattr 275 +#define __NR_sched_getparam 121 +#define __NR_sched_getscheduler 120 +#define __NR_sched_rr_get_interval 127 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_sched_setaffinity 122 +#define __NR_sched_setattr 274 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_yield 124 +#define __NR_seccomp 277 +#define __NR_semctl 191 +#define __NR_semget 190 +#define __NR_semop 193 +#define __NR_semtimedop 192 +#define __NR_semtimedop_time64 420 +#define __NR_sendfile64 71 +#define __NR_sendmmsg 269 +#define __NR_sendmsg 211 +#define __NR_sendto 206 +#define __NR_set_mempolicy 237 +#define __NR_set_robust_list 99 +#define __NR_set_tid_address 96 +#define __NR_setdomainname 162 +#define __NR_setfsgid 152 +#define __NR_setfsuid 151 +#define __NR_setgid 144 +#define __NR_setgroups 159 +#define __NR_sethostname 161 +#define __NR_setitimer 103 +#define __NR_setns 268 +#define __NR_setpgid 154 +#define __NR_setpriority 140 +#define __NR_setregid 143 +#define __NR_setresgid 149 +#define __NR_setresuid 147 +#define __NR_setreuid 145 +#define __NR_setrlimit 164 +#define __NR_setsid 157 +#define __NR_setsockopt 208 +#define __NR_settimeofday 170 +#define __NR_setuid 146 +#define __NR_setxattr 5 +#define __NR_shmat 196 +#define __NR_shmctl 195 +#define __NR_shmdt 197 +#define __NR_shmget 194 +#define __NR_shutdown 210 +#define __NR_sigaltstack 132 +#define __NR_signalfd4 74 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_splice 76 +#define __NR_statfs64 43 +#define __NR_statx 291 +#define __NR_swapoff 225 +#define __NR_swapon 224 +#define __NR_symlinkat 36 +#define __NR_sync 81 +#define __NR_sync_file_range 84 +#define __NR_syncfs 267 +#define __NR_sysinfo 179 +#define __NR_syslog 116 +#define __NR_tee 77 +#define __NR_tgkill 131 +#define __NR_timer_create 107 +#define __NR_timer_delete 111 +#define __NR_timer_getoverrun 109 +#define __NR_timer_gettime 108 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime 110 +#define __NR_timer_settime64 409 +#define __NR_timerfd_create 85 +#define __NR_timerfd_gettime 87 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_settime64 411 +#define __NR_times 153 +#define __NR_tkill 130 +#define __NR_truncate64 45 +#define __NR_umask 166 +#define __NR_umount2 39 +#define __NR_uname 160 +#define __NR_unlinkat 35 +#define __NR_unshare 97 +#define __NR_userfaultfd 282 +#define __NR_utimensat 88 +#define __NR_utimensat_time64 412 +#define __NR_vhangup 58 +#define __NR_vmsplice 75 +#define __NR_wait4 260 +#define __NR_waitid 95 +#define __NR_write 64 +#define __NR_writev 66
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +19 -0
@@ -0,0 +1,19 @@ +/* Bit size of the time_t type at glibc build time, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#define __TIMESIZE 64
sysdeps/unix/sysv/linux/or1k/clone.c new file +61 -0
61 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h new file +41 -0
41 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/mmap_internal.h new file +28 -0
@@ -0,0 +1,28 @@ +/* Common mmap definition for Linux implementation. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef MMAP_OR1K_INTERNAL_LINUX_H +#define MMAP_OR1K_INTERNAL_LINUX_H + +/* OpenRISC Linux sets the page shift to 13 and mmap2 expects +offsets to be provided in 8K pages. */ +#define MMAP2_PAGE_UNIT 8192ULL + +#include_next <mmap_internal.h> + +#endif
sysdeps/unix/sysv/linux/or1k/or1k_clone.S new file +89 -0
89 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/sysdep.c new file +34 -0
@@ -0,0 +1,34 @@ +/* OpenRISC wrapper for setting errno. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include <errno.h> + +long int __syscall_error (long int err); +hidden_proto (__syscall_error) + +/* This routine is jumped to by all the syscall handlers, to stash +an error number into errno. */ +long int +__syscall_error (long int err) +{ +__set_errno (- err); +return -1 ; +} +hidden_def (__syscall_error)
sysdeps/unix/sysv/linux/or1k/sysdep.h new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH v3 8/13 or1k: Linux Syscall Interface
Some comments below.
Quoted 365 lines · Stafford Horne via Libc-alpha
--- sysdeps/unix/sysv/linux/or1k/arch-syscall.h | 325 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/bits/timesize.h | 19 + sysdeps/unix/sysv/linux/or1k/clone.c | 61 ++++ sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h | 41 +++ sysdeps/unix/sysv/linux/or1k/mmap_internal.h | 28 ++ sysdeps/unix/sysv/linux/or1k/or1k_clone.S | 89 +++++ sysdeps/unix/sysv/linux/or1k/sysdep.c | 34 ++ sysdeps/unix/sysv/linux/or1k/sysdep.h | 201 +++++++++++ 8 files changed, 798 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/or1k/arch-syscall.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/timesize.h create mode 100644 sysdeps/unix/sysv/linux/or1k/clone.c create mode 100644 sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h create mode 100644 sysdeps/unix/sysv/linux/or1k/mmap_internal.h create mode 100644 sysdeps/unix/sysv/linux/or1k/or1k_clone.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.c create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.hsysdeps/unix/sysv/linux/or1k/arch-syscall.h new file +325
-0@@ -0,0 +1,325 @@ +/* AUTOGENERATED by update-syscall-lists.py. */ +#define __NR_accept 202 +#define __NR_accept4 242 +#define __NR_acct 89 +#define __NR_add_key 217 +#define __NR_adjtimex 171 +#define __NR_bind 200 +#define __NR_bpf 280 +#define __NR_brk 214 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_chdir 49 +#define __NR_chroot 51 +#define __NR_clock_adjtime 266 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres 114 +#define __NR_clock_getres_time64 406 +#define __NR_clock_gettime 113 +#define __NR_clock_gettime64 403 +#define __NR_clock_nanosleep 115 +#define __NR_clock_nanosleep_time64 407 +#define __NR_clock_settime 112 +#define __NR_clock_settime64 404 +#define __NR_clone 220 +#define __NR_clone3 435 +#define __NR_close 57 +#define __NR_close_range 436 +#define __NR_connect 203 +#define __NR_copy_file_range 285 +#define __NR_delete_module 106 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_epoll_pwait2 441 +#define __NR_eventfd2 19 +#define __NR_execve 221 +#define __NR_execveat 281 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_faccessat 48 +#define __NR_faccessat2 439 +#define __NR_fadvise64_64 223 +#define __NR_fallocate 47 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_fchdir 50 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchown 55 +#define __NR_fchownat 54 +#define __NR_fcntl64 25 +#define __NR_fdatasync 83 +#define __NR_fgetxattr 10 +#define __NR_finit_module 273 +#define __NR_flistxattr 13 +#define __NR_flock 32 +#define __NR_fremovexattr 16 +#define __NR_fsconfig 431 +#define __NR_fsetxattr 7 +#define __NR_fsmount 432 +#define __NR_fsopen 430 +#define __NR_fspick 433 +#define __NR_fstat64 80 +#define __NR_fstatat64 79 +#define __NR_fstatfs64 44 +#define __NR_fsync 82 +#define __NR_ftruncate64 46 +#define __NR_futex 98 +#define __NR_futex_time64 422 +#define __NR_get_mempolicy 236 +#define __NR_get_robust_list 100 +#define __NR_getcpu 168 +#define __NR_getcwd 17 +#define __NR_getdents64 61 +#define __NR_getegid 177 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getgroups 158 +#define __NR_getitimer 102 +#define __NR_getpeername 205 +#define __NR_getpgid 155 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getpriority 141 +#define __NR_getrandom 278 +#define __NR_getresgid 150 +#define __NR_getresuid 148 +#define __NR_getrlimit 163 +#define __NR_getrusage 165 +#define __NR_getsid 156 +#define __NR_getsockname 204 +#define __NR_getsockopt 209 +#define __NR_gettid 178 +#define __NR_gettimeofday 169 +#define __NR_getuid 174 +#define __NR_getxattr 8 +#define __NR_init_module 105 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_init1 26 +#define __NR_inotify_rm_watch 28 +#define __NR_io_cancel 3 +#define __NR_io_destroy 1 +#define __NR_io_getevents 4 +#define __NR_io_pgetevents 292 +#define __NR_io_pgetevents_time64 416 +#define __NR_io_setup 0 +#define __NR_io_submit 2 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_io_uring_setup 425 +#define __NR_ioctl 29 +#define __NR_ioprio_get 31 +#define __NR_ioprio_set 30 +#define __NR_kcmp 272 +#define __NR_kexec_file_load 294 +#define __NR_kexec_load 104 +#define __NR_keyctl 219 +#define __NR_kill 129 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_restrict_self 446 +#define __NR_lgetxattr 9 +#define __NR_linkat 37 +#define __NR_listen 201 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_llseek 62 +#define __NR_lookup_dcookie 18 +#define __NR_lremovexattr 15 +#define __NR_lsetxattr 6 +#define __NR_madvise 233 +#define __NR_mbind 235 +#define __NR_membarrier 283 +#define __NR_memfd_create 279 +#define __NR_migrate_pages 238 +#define __NR_mincore 232 +#define __NR_mkdirat 34 +#define __NR_mknodat 33 +#define __NR_mlock 228 +#define __NR_mlock2 284 +#define __NR_mlockall 230 +#define __NR_mmap2 222 +#define __NR_mount 40 +#define __NR_mount_setattr 442 +#define __NR_move_mount 429 +#define __NR_move_pages 239 +#define __NR_mprotect 226 +#define __NR_mq_getsetattr 185 +#define __NR_mq_notify 184 +#define __NR_mq_open 180 +#define __NR_mq_timedreceive 183 +#define __NR_mq_timedreceive_time64 419 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_unlink 181 +#define __NR_mremap 216 +#define __NR_msgctl 187 +#define __NR_msgget 186 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_msync 227 +#define __NR_munlock 229 +#define __NR_munlockall 231 +#define __NR_munmap 215 +#define __NR_name_to_handle_at 264 +#define __NR_nanosleep 101 +#define __NR_nfsservctl 42 +#define __NR_open_by_handle_at 265 +#define __NR_open_tree 428 +#define __NR_openat 56 +#define __NR_openat2 437 +#define __NR_or1k_atomic 244 +#define __NR_perf_event_open 241 +#define __NR_personality 92 +#define __NR_pidfd_getfd 438 +#define __NR_pidfd_open 434 +#define __NR_pidfd_send_signal 424 +#define __NR_pipe2 59 +#define __NR_pivot_root 41 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_pkey_mprotect 288 +#define __NR_ppoll 73 +#define __NR_ppoll_time64 414 +#define __NR_prctl 167 +#define __NR_pread64 67 +#define __NR_preadv 69 +#define __NR_preadv2 286 +#define __NR_prlimit64 261 +#define __NR_process_madvise 440 +#define __NR_process_mrelease 448 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_pselect6 72 +#define __NR_pselect6_time64 413 +#define __NR_ptrace 117 +#define __NR_pwrite64 68 +#define __NR_pwritev 70 +#define __NR_pwritev2 287 +#define __NR_quotactl 60 +#define __NR_quotactl_fd 443 +#define __NR_read 63 +#define __NR_readahead 213 +#define __NR_readlinkat 78 +#define __NR_readv 65 +#define __NR_reboot 142 +#define __NR_recvfrom 207 +#define __NR_recvmmsg 243 +#define __NR_recvmmsg_time64 417 +#define __NR_recvmsg 212 +#define __NR_remap_file_pages 234 +#define __NR_removexattr 14 +#define __NR_renameat 38 +#define __NR_renameat2 276 +#define __NR_request_key 218 +#define __NR_restart_syscall 128 +#define __NR_rseq 293 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_getaffinity 123 +#define __NR_sched_getattr 275 +#define __NR_sched_getparam 121 +#define __NR_sched_getscheduler 120 +#define __NR_sched_rr_get_interval 127 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_sched_setaffinity 122 +#define __NR_sched_setattr 274 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_yield 124 +#define __NR_seccomp 277 +#define __NR_semctl 191 +#define __NR_semget 190 +#define __NR_semop 193 +#define __NR_semtimedop 192 +#define __NR_semtimedop_time64 420 +#define __NR_sendfile64 71 +#define __NR_sendmmsg 269 +#define __NR_sendmsg 211 +#define __NR_sendto 206 +#define __NR_set_mempolicy 237 +#define __NR_set_robust_list 99 +#define __NR_set_tid_address 96 +#define __NR_setdomainname 162 +#define __NR_setfsgid 152 +#define __NR_setfsuid 151 +#define __NR_setgid 144 +#define __NR_setgroups 159 +#define __NR_sethostname 161 +#define __NR_setitimer 103 +#define __NR_setns 268 +#define __NR_setpgid 154 +#define __NR_setpriority 140 +#define __NR_setregid 143 +#define __NR_setresgid 149 +#define __NR_setresuid 147 +#define __NR_setreuid 145 +#define __NR_setrlimit 164 +#define __NR_setsid 157 +#define __NR_setsockopt 208 +#define __NR_settimeofday 170 +#define __NR_setuid 146 +#define __NR_setxattr 5 +#define __NR_shmat 196 +#define __NR_shmctl 195 +#define __NR_shmdt 197 +#define __NR_shmget 194 +#define __NR_shutdown 210 +#define __NR_sigaltstack 132 +#define __NR_signalfd4 74 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_splice 76 +#define __NR_statfs64 43 +#define __NR_statx 291 +#define __NR_swapoff 225 +#define __NR_swapon 224 +#define __NR_symlinkat 36 +#define __NR_sync 81 +#define __NR_sync_file_range 84 +#define __NR_syncfs 267 +#define __NR_sysinfo 179 +#define __NR_syslog 116 +#define __NR_tee 77 +#define __NR_tgkill 131 +#define __NR_timer_create 107 +#define __NR_timer_delete 111 +#define __NR_timer_getoverrun 109 +#define __NR_timer_gettime 108 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime 110 +#define __NR_timer_settime64 409 +#define __NR_timerfd_create 85 +#define __NR_timerfd_gettime 87 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_settime64 411 +#define __NR_times 153 +#define __NR_tkill 130 +#define __NR_truncate64 45 +#define __NR_umask 166 +#define __NR_umount2 39 +#define __NR_uname 160 +#define __NR_unlinkat 35 +#define __NR_unshare 97 +#define __NR_userfaultfd 282 +#define __NR_utimensat 88 +#define __NR_utimensat_time64 412 +#define __NR_vhangup 58 +#define __NR_vmsplice 75 +#define __NR_wait4 260 +#define __NR_waitid 95 +#define __NR_write 64 +#define __NR_writev 66sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +9
-0@@ -0,0 +1,19 @@ +/* Bit size of the time_t type at glibc build time, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. +
sysdeps/unix/sysv/linux/or1k/bits/timesize.h line 19
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +10
-0+ The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#define __TIMESIZE 64
Ok, although I think we should flip the default to 64 bits make old ports to override to 32.
Quoted 57 lines
sysdeps/unix/sysv/linux/or1k/clone.c new file +51
-0@@ -0,0 +1,61 @@ +/* OpenRISC helper for the clone syscall. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <stdarg.h> +#include <sysdep.h> + +extern int __or1k_clone (int (*fn)(void *),void *child_stack, +int flags,void *arg,pid_t *ptid, +void *tls,pid_t *ctid); + + +/* The OpenRISC ABI uses the stack for varargs like those using in clone +but the linux syscall ABI uses registers. +This function moves from varargs to regs. */ +int +__clone (int (*fn)(void *),void *child_stack, +int flags,void *arg, ... +/* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ ) +{ +void *ptid; +void *tls; +void *ctid; +va_list ap; +int err; + +va_start (ap, arg); + ptid = va_arg (ap, void *); + tls = va_arg (ap, void *); + ctid = va_arg (ap, void *); +va_end (ap); + +/* Sanity check the arguments */ + err = -EINVAL ; +if (!fn) + goto syscall_error; +if (!child_stack)
sysdeps/unix/sysv/linux/or1k/clone.c line 61
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/clone.c new file +10
-0+ goto syscall_error; + +return __or1k_clone (fn, child_stack, flags, arg, ptid, tls, ctid); + +syscall_error: +__set_errno (-err); +return -1 ; +} +libc_hidden_def (__clone) +weak_alias (__clone, clone)
Ok, I take that implementing it solely on __or1k_clone is more complex than using a C wrapper.
Quoted 37 lines
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h new file +31
-0@@ -0,0 +1,41 @@ +/* jump buffer constants, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +/* Produced by this program: + +#include <stdio.h> +#include <unistd.h> +#include <setjmp.h> +#include <stddef.h> + +int main (int argc, char **argv) +{ +printf ("#define JMP_BUF_SIZE %d\n", sizeof (jmp_buf)); +printf ("#define JMP_BUF_ALIGN %d\n", __alignof__ (jmp_buf)); +printf ("#define SIGJMP_BUF_SIZE %d\n", sizeof (sigjmp_buf)); +printf ("#define SIGJMP_BUF_ALIGN %d\n", __alignof__ (sigjmp_buf));
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h line 41
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h new file +10
-0+printf ("#define MASK_WAS_SAVED_OFFSET %d\n", offsetof (struct __jmp_buf_tag, __mask_was_saved)); +printf ("#define SAVED_MASK_OFFSET %d\n", offsetof (struct __jmp_buf_tag, __saved_mask)); +} */ + +#define JMP_BUF_SIZE 184 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_SIZE 184 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 52 +#define SAVED_MASK_OFFSET 56
You don't need this file since bc801b3a40f3a9bc8f24f1d0fdc39413874c3172.
Quoted 24 lines
sysdeps/unix/sysv/linux/or1k/mmap_internal.h new file +18
-0@@ -0,0 +1,28 @@ +/* Common mmap definition for Linux implementation. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ +
sysdeps/unix/sysv/linux/or1k/mmap_internal.h line 28
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/mmap_internal.h new file +10
-0+#ifndef MMAP_OR1K_INTERNAL_LINUX_H +#define MMAP_OR1K_INTERNAL_LINUX_H + +/* OpenRISC Linux sets the page shift to 13 and mmap2 expects +offsets to be provided in 8K pages. */ +#define MMAP2_PAGE_UNIT 8192ULL + +#include_next <mmap_internal.h> + +#endif
Ok.
Quoted 342 lines
sysdeps/unix/sysv/linux/or1k/or1k_clone.S new file +89
-0@@ -0,0 +1,89 @@ +/* clone helper __or1k_clone for OpenRISC. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep.h> +#include <tls.h> +#define __ASSEMBLY__ +#include <linux/sched.h> + + .text +ENTRY(__or1k_clone) + + /* To handle GCC varargs we need to use our __clone wrapper to pop + everything from the stack for us. + Now everything is placed in the registers which saves us a lot + of trouble. + + The userland implementation is: + + int clone (int (*fn)(void *), void *child_stack, + int flags, void *arg, pid_t *ptid, + struct user_desc *tls, pid_t *ctid); + The kernel entry is: + + int clone (long flags, void *child_stack, int *parent_tid, + int *child_tid, struct void *tls) + + NB: tls isn't really an argument, it is read from r7 directly. */ + + /* First, align the stack to 4 bytes. */ + l.xori r11, r0, -4 + l.and r4, r4, r11 + + /* Put 'fn', 'arg' and 'flags' on the child stack. */ + l.addi r4, r4, -12 + l.sw 8(r4), r3 + l.sw 4(r4), r6 + l.sw 0(r4), r5 + + l.ori r3, r5, 0 + /* The child_stack is already in r4. */ + l.ori r5, r7, 0 + l.lwz r6, 0(r1) + l.ori r7, r8, 0 + + DO_CALL (clone) + + l.sfgeui r11, 0xf001 + l.bf L(error) + l.nop + + /* If we are not the child, return the pid. */ + l.sfeqi r11, 0 + l.bf L(thread_start) + l.nop + + l.jr r9 + l.nop + +L(thread_start): + /* Load function from stack. */ + l.lwz r11, 8(r1) + l.jalr r11 + l.lwz r3, 4(r1) + + /* Exit the child thread. */ + l.ori r3, r11, 0 + DO_CALL (exit) + +L(error): + l.j SYSCALL_ERROR_NAME + l.ori r3, r11, 0 + +PSEUDO_END (__or1k_clone)sysdeps/unix/sysv/linux/or1k/sysdep.c new file +34
-0@@ -0,0 +1,34 @@ +/* OpenRISC wrapper for setting errno. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include <errno.h> + +long int __syscall_error (long int err); +hidden_proto (__syscall_error) + +/* This routine is jumped to by all the syscall handlers, to stash +an error number into errno. */ +long int +__syscall_error (long int err) +{ +__set_errno (- err); +return -1 ; +} +hidden_def (__syscall_error)sysdeps/unix/sysv/linux/or1k/sysdep.h new file +201
-0@@ -0,0 +1,201 @@ +/* Assembler and syscall macros. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINUX_OR1K_SYSDEP_H +#define _LINUX_OR1K_SYSDEP_H 1 + +#include <sysdeps/or1k/sysdep.h> +#include <sysdeps/unix/sysv/linux/generic/sysdep.h> +#include <tls.h> + +/* "workarounds" for generic code needing to handle 64-bit time_t. */ + +#undef __NR_clock_getres +#undef __NR_futex +#undef __NR_ppoll +#undef __NR_pselect6 +#undef __NR_recvmmsg +#undef __NR_rt_sigtimedwait +#undef __NR_semtimedop +#undef __NR_utimensat + +/* Fix sysdeps/unix/sysv/linux/clock_getcpuclockid.c. */ +#define __NR_clock_getres __NR_clock_getres_time64 +/* Fix sysdeps/nptl/lowlevellock-futex.h. */ +#define __NR_futex __NR_futex_time64 +/* Fix sysdeps/unix/sysv/linux/pause.c. */ +#define __NR_ppoll __NR_ppoll_time64 +/* Fix sysdeps/unix/sysv/linux/select.c. */ +#define __NR_pselect6 __NR_pselect6_time64 +/* Fix sysdeps/unix/sysv/linux/recvmmsg.c. */ +#define __NR_recvmmsg __NR_recvmmsg_time64 +/* Fix sysdeps/unix/sysv/linux/sigtimedwait.c. */ +#define __NR_rt_sigtimedwait __NR_rt_sigtimedwait_time64 +/* Fix sysdeps/unix/sysv/linux/semtimedop.c. */ +#define __NR_semtimedop __NR_semtimedop_time64 +/* Hack sysdeps/unix/sysv/linux/generic/utimes.c. */ +#define __NR_utimensat __NR_utimensat_time64 + +#undef SYS_ify +#define SYS_ify (syscall_name) (__NR_##syscall_name) + +/* Linux uses a negative return value to indicate syscall errors, +unlike most Unices, which use the condition codes' carry flag. + +Since version 2.1 the return value of a system call might be +negative even if the call succeeded. E.g., the lseek system call +might return a large offset. Therefore we must not anymore test +for < 0, but test for a real error by making sure the value in R0 +is a real error number. Linus said he will make sure the no syscall +returns a value in -1 .. -4095 as a valid result so we can safely +test with -4095. */ + +#ifdef __ASSEMBLER__ + +/* Macros used in syscall-template.S */ +#define ret l.jr r9; l.nop +#define ret_NOERRNO l.jr r9; l.nop + +#undef DO_CALL +#define DO_CALL (syscall_name) \ + l.addi r11, r0, SYS_ify (syscall_name); \ + l.sys 1; \ + l.nop + +#undef PSEUDO +#define PSEUDO(name, syscall_name, args) \ + ENTRY (name); \ + DO_CALL(syscall_name); \ + /* if -4096 < ret < 0 holds, it's an error */ \ + l.sfgeui r11, 0xf001; \ + l.bf L(pseudo_end); \ + l.nop + +#undef PSEUDO_NOERRNO +#define PSEUDO_NOERRNO (name, syscall_name, args) \ + ENTRY (name); \ + DO_CALL(syscall_name) + +#undef PSEUDO_END +#define PSEUDO_END (name) \ +L(pseudo_end): \ + l.j SYSCALL_ERROR_NAME; \ + l.ori r3,r11,0; \ + END (name) + +#undef PSEUDO_END_NOERRNO +#define PSEUDO_END_NOERRNO (name) \ + END (name) + +#ifndef PIC +/* For static code, on error jump to __syscall_error directly. */ +# define SYSCALL_ERROR_NAME __syscall_error +#elif !IS_IN (libc) +/* Use the internal name for libc shared objects. */ +# define SYSCALL_ERROR_NAME __GI___syscall_error +#else +/* Otherwise, on error do a full PLT jump. */ +# define SYSCALL_ERROR_NAME plt(__syscall_error) +#endif + +#else /* not __ASSEMBLER__ */ + +#include <errno.h> + +extern long int __syscall_error (long int neg_errno); + +/* Pointer mangling is not yet supported for or1k. */ +#define PTR_MANGLE (var) (void) (var) +#define PTR_DEMANGLE (var) (void) (var) + +#undef INTERNAL_SYSCALL +#define INTERNAL_SYSCALL(name, nr, args...) \ + INTERNAL_SYSCALL_NCS (SYS_ify (name), nr, args) + +/* The _NCS variant allows non-constant syscall numbers. */ +#undef INTERNAL_SYSCALL_NCS +#define INTERNAL_SYSCALL_NCS(number, nr, args...) \ + ({ unsigned long int __sys_result; \ + { \ + long int _sc_ret = (long int) number; \ + LOAD_ARGS_##nr (args) \ + register long int __sc_ret __asm__ ("r11") = _sc_ret; \ + __asm__ __volatile__ ("l.sys 1\n\t" \ + " l.nop\n\t" \ + : "+r" (__sc_ret) \ + : ASM_ARGS_##nr \ + : ASM_CLOBBERS_##nr \ + "r12", "r13", "r15", "r17", "r19", \ + "r21", "r23", "r25", "r27", "r29", \ + "r31", "memory"); \ + __sys_result = __sc_ret; \ + } \ + (long int) __sys_result; }) + +/* From here on we have nested macros that generate code for +setting up syscall arguments. */ + +#define LOAD_ARGS_0 () + +#define ASM_ARGS_0 +#define ASM_CLOBBERS_0 "r3", ASM_CLOBBERS_1 + +#define LOAD_ARGS_1 (a) \ + long int _a = (long int)(a); \ + register long int __a __asm__ ("r3") = _a; +#define ASM_ARGS_1 "r" (__a) +#define ASM_CLOBBERS_1 "r4", ASM_CLOBBERS_2 + +#define LOAD_ARGS_2 (a, b) \ + long int _b = (long int)(b); \ + LOAD_ARGS_1 (a) \ + register long int __b __asm__ ("r4") = _b; +#define ASM_ARGS_2 ASM_ARGS_1, "r" (__b) +#define ASM_CLOBBERS_2 "r5", ASM_CLOBBERS_3 + +#define LOAD_ARGS_3 (a, b, c) \ + long int _c = (long int)(c); \ + LOAD_ARGS_2 (a, b) \ + register long int __c __asm__ ("r5") = _c; +#define ASM_ARGS_3 ASM_ARGS_2, "r" (__c) +#define ASM_CLOBBERS_3 "r6", ASM_CLOBBERS_4 + +#define LOAD_ARGS_4 (a, b, c, d) \ + LOAD_ARGS_3 (a, b, c) \ + long int _d = (long int)(d); \ + register long int __d __asm__ ("r6") = _d; +#define ASM_ARGS_4 ASM_ARGS_3, "r" (__d) +#define ASM_CLOBBERS_4 "r7", ASM_CLOBBERS_5 + +#define LOAD_ARGS_5 (a, b, c, d, e) \ + long int _e = (long int)(e); \ + LOAD_ARGS_4 (a, b, c, d) \ + register long int __e __asm__ ("r7") = _e; +#define ASM_ARGS_5 ASM_ARGS_4, "r" (__e) +#define ASM_CLOBBERS_5 "r8", ASM_CLOBBERS_6 + +#define LOAD_ARGS_6 (a, b, c, d, e, f) \ + long int _f = (long int)(f); \ + LOAD_ARGS_5 (a, b, c, d, e) \ + register long int __f __asm__ ("r8") = _f; +#define ASM_ARGS_6 ASM_ARGS_5, "r" (__f) +#define ASM_CLOBBERS_6 + +#endif /* not __ASSEMBLER__ */ + +#endif /* linux/or1k/sysdep.h */
PATCH v3 8/13 or1k: Linux Syscall Interface
Quoted 373 lines · Adhemerval Zanella
Some comments below.
Quoted 370 lines · Stafford Horne via Libc-alpha
--- sysdeps/unix/sysv/linux/or1k/arch-syscall.h | 325 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/bits/timesize.h | 19 + sysdeps/unix/sysv/linux/or1k/clone.c | 61 ++++ sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h | 41 +++ sysdeps/unix/sysv/linux/or1k/mmap_internal.h | 28 ++ sysdeps/unix/sysv/linux/or1k/or1k_clone.S | 89 +++++ sysdeps/unix/sysv/linux/or1k/sysdep.c | 34 ++ sysdeps/unix/sysv/linux/or1k/sysdep.h | 201 +++++++++++ 8 files changed, 798 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/or1k/arch-syscall.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/timesize.h create mode 100644 sysdeps/unix/sysv/linux/or1k/clone.c create mode 100644 sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h create mode 100644 sysdeps/unix/sysv/linux/or1k/mmap_internal.h create mode 100644 sysdeps/unix/sysv/linux/or1k/or1k_clone.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.c create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.hsysdeps/unix/sysv/linux/or1k/arch-syscall.h new file +325
-0@@ -0,0 +1,325 @@ +/* AUTOGENERATED by update-syscall-lists.py. */ +#define __NR_accept 202 +#define __NR_accept4 242 +#define __NR_acct 89 +#define __NR_add_key 217 +#define __NR_adjtimex 171 +#define __NR_bind 200 +#define __NR_bpf 280 +#define __NR_brk 214 +#define __NR_capget 90 +#define __NR_capset 91 +#define __NR_chdir 49 +#define __NR_chroot 51 +#define __NR_clock_adjtime 266 +#define __NR_clock_adjtime64 405 +#define __NR_clock_getres 114 +#define __NR_clock_getres_time64 406 +#define __NR_clock_gettime 113 +#define __NR_clock_gettime64 403 +#define __NR_clock_nanosleep 115 +#define __NR_clock_nanosleep_time64 407 +#define __NR_clock_settime 112 +#define __NR_clock_settime64 404 +#define __NR_clone 220 +#define __NR_clone3 435 +#define __NR_close 57 +#define __NR_close_range 436 +#define __NR_connect 203 +#define __NR_copy_file_range 285 +#define __NR_delete_module 106 +#define __NR_dup 23 +#define __NR_dup3 24 +#define __NR_epoll_create1 20 +#define __NR_epoll_ctl 21 +#define __NR_epoll_pwait 22 +#define __NR_epoll_pwait2 441 +#define __NR_eventfd2 19 +#define __NR_execve 221 +#define __NR_execveat 281 +#define __NR_exit 93 +#define __NR_exit_group 94 +#define __NR_faccessat 48 +#define __NR_faccessat2 439 +#define __NR_fadvise64_64 223 +#define __NR_fallocate 47 +#define __NR_fanotify_init 262 +#define __NR_fanotify_mark 263 +#define __NR_fchdir 50 +#define __NR_fchmod 52 +#define __NR_fchmodat 53 +#define __NR_fchown 55 +#define __NR_fchownat 54 +#define __NR_fcntl64 25 +#define __NR_fdatasync 83 +#define __NR_fgetxattr 10 +#define __NR_finit_module 273 +#define __NR_flistxattr 13 +#define __NR_flock 32 +#define __NR_fremovexattr 16 +#define __NR_fsconfig 431 +#define __NR_fsetxattr 7 +#define __NR_fsmount 432 +#define __NR_fsopen 430 +#define __NR_fspick 433 +#define __NR_fstat64 80 +#define __NR_fstatat64 79 +#define __NR_fstatfs64 44 +#define __NR_fsync 82 +#define __NR_ftruncate64 46 +#define __NR_futex 98 +#define __NR_futex_time64 422 +#define __NR_get_mempolicy 236 +#define __NR_get_robust_list 100 +#define __NR_getcpu 168 +#define __NR_getcwd 17 +#define __NR_getdents64 61 +#define __NR_getegid 177 +#define __NR_geteuid 175 +#define __NR_getgid 176 +#define __NR_getgroups 158 +#define __NR_getitimer 102 +#define __NR_getpeername 205 +#define __NR_getpgid 155 +#define __NR_getpid 172 +#define __NR_getppid 173 +#define __NR_getpriority 141 +#define __NR_getrandom 278 +#define __NR_getresgid 150 +#define __NR_getresuid 148 +#define __NR_getrlimit 163 +#define __NR_getrusage 165 +#define __NR_getsid 156 +#define __NR_getsockname 204 +#define __NR_getsockopt 209 +#define __NR_gettid 178 +#define __NR_gettimeofday 169 +#define __NR_getuid 174 +#define __NR_getxattr 8 +#define __NR_init_module 105 +#define __NR_inotify_add_watch 27 +#define __NR_inotify_init1 26 +#define __NR_inotify_rm_watch 28 +#define __NR_io_cancel 3 +#define __NR_io_destroy 1 +#define __NR_io_getevents 4 +#define __NR_io_pgetevents 292 +#define __NR_io_pgetevents_time64 416 +#define __NR_io_setup 0 +#define __NR_io_submit 2 +#define __NR_io_uring_enter 426 +#define __NR_io_uring_register 427 +#define __NR_io_uring_setup 425 +#define __NR_ioctl 29 +#define __NR_ioprio_get 31 +#define __NR_ioprio_set 30 +#define __NR_kcmp 272 +#define __NR_kexec_file_load 294 +#define __NR_kexec_load 104 +#define __NR_keyctl 219 +#define __NR_kill 129 +#define __NR_landlock_add_rule 445 +#define __NR_landlock_create_ruleset 444 +#define __NR_landlock_restrict_self 446 +#define __NR_lgetxattr 9 +#define __NR_linkat 37 +#define __NR_listen 201 +#define __NR_listxattr 11 +#define __NR_llistxattr 12 +#define __NR_llseek 62 +#define __NR_lookup_dcookie 18 +#define __NR_lremovexattr 15 +#define __NR_lsetxattr 6 +#define __NR_madvise 233 +#define __NR_mbind 235 +#define __NR_membarrier 283 +#define __NR_memfd_create 279 +#define __NR_migrate_pages 238 +#define __NR_mincore 232 +#define __NR_mkdirat 34 +#define __NR_mknodat 33 +#define __NR_mlock 228 +#define __NR_mlock2 284 +#define __NR_mlockall 230 +#define __NR_mmap2 222 +#define __NR_mount 40 +#define __NR_mount_setattr 442 +#define __NR_move_mount 429 +#define __NR_move_pages 239 +#define __NR_mprotect 226 +#define __NR_mq_getsetattr 185 +#define __NR_mq_notify 184 +#define __NR_mq_open 180 +#define __NR_mq_timedreceive 183 +#define __NR_mq_timedreceive_time64 419 +#define __NR_mq_timedsend 182 +#define __NR_mq_timedsend_time64 418 +#define __NR_mq_unlink 181 +#define __NR_mremap 216 +#define __NR_msgctl 187 +#define __NR_msgget 186 +#define __NR_msgrcv 188 +#define __NR_msgsnd 189 +#define __NR_msync 227 +#define __NR_munlock 229 +#define __NR_munlockall 231 +#define __NR_munmap 215 +#define __NR_name_to_handle_at 264 +#define __NR_nanosleep 101 +#define __NR_nfsservctl 42 +#define __NR_open_by_handle_at 265 +#define __NR_open_tree 428 +#define __NR_openat 56 +#define __NR_openat2 437 +#define __NR_or1k_atomic 244 +#define __NR_perf_event_open 241 +#define __NR_personality 92 +#define __NR_pidfd_getfd 438 +#define __NR_pidfd_open 434 +#define __NR_pidfd_send_signal 424 +#define __NR_pipe2 59 +#define __NR_pivot_root 41 +#define __NR_pkey_alloc 289 +#define __NR_pkey_free 290 +#define __NR_pkey_mprotect 288 +#define __NR_ppoll 73 +#define __NR_ppoll_time64 414 +#define __NR_prctl 167 +#define __NR_pread64 67 +#define __NR_preadv 69 +#define __NR_preadv2 286 +#define __NR_prlimit64 261 +#define __NR_process_madvise 440 +#define __NR_process_mrelease 448 +#define __NR_process_vm_readv 270 +#define __NR_process_vm_writev 271 +#define __NR_pselect6 72 +#define __NR_pselect6_time64 413 +#define __NR_ptrace 117 +#define __NR_pwrite64 68 +#define __NR_pwritev 70 +#define __NR_pwritev2 287 +#define __NR_quotactl 60 +#define __NR_quotactl_fd 443 +#define __NR_read 63 +#define __NR_readahead 213 +#define __NR_readlinkat 78 +#define __NR_readv 65 +#define __NR_reboot 142 +#define __NR_recvfrom 207 +#define __NR_recvmmsg 243 +#define __NR_recvmmsg_time64 417 +#define __NR_recvmsg 212 +#define __NR_remap_file_pages 234 +#define __NR_removexattr 14 +#define __NR_renameat 38 +#define __NR_renameat2 276 +#define __NR_request_key 218 +#define __NR_restart_syscall 128 +#define __NR_rseq 293 +#define __NR_rt_sigaction 134 +#define __NR_rt_sigpending 136 +#define __NR_rt_sigprocmask 135 +#define __NR_rt_sigqueueinfo 138 +#define __NR_rt_sigreturn 139 +#define __NR_rt_sigsuspend 133 +#define __NR_rt_sigtimedwait 137 +#define __NR_rt_sigtimedwait_time64 421 +#define __NR_rt_tgsigqueueinfo 240 +#define __NR_sched_get_priority_max 125 +#define __NR_sched_get_priority_min 126 +#define __NR_sched_getaffinity 123 +#define __NR_sched_getattr 275 +#define __NR_sched_getparam 121 +#define __NR_sched_getscheduler 120 +#define __NR_sched_rr_get_interval 127 +#define __NR_sched_rr_get_interval_time64 423 +#define __NR_sched_setaffinity 122 +#define __NR_sched_setattr 274 +#define __NR_sched_setparam 118 +#define __NR_sched_setscheduler 119 +#define __NR_sched_yield 124 +#define __NR_seccomp 277 +#define __NR_semctl 191 +#define __NR_semget 190 +#define __NR_semop 193 +#define __NR_semtimedop 192 +#define __NR_semtimedop_time64 420 +#define __NR_sendfile64 71 +#define __NR_sendmmsg 269 +#define __NR_sendmsg 211 +#define __NR_sendto 206 +#define __NR_set_mempolicy 237 +#define __NR_set_robust_list 99 +#define __NR_set_tid_address 96 +#define __NR_setdomainname 162 +#define __NR_setfsgid 152 +#define __NR_setfsuid 151 +#define __NR_setgid 144 +#define __NR_setgroups 159 +#define __NR_sethostname 161 +#define __NR_setitimer 103 +#define __NR_setns 268 +#define __NR_setpgid 154 +#define __NR_setpriority 140 +#define __NR_setregid 143 +#define __NR_setresgid 149 +#define __NR_setresuid 147 +#define __NR_setreuid 145 +#define __NR_setrlimit 164 +#define __NR_setsid 157 +#define __NR_setsockopt 208 +#define __NR_settimeofday 170 +#define __NR_setuid 146 +#define __NR_setxattr 5 +#define __NR_shmat 196 +#define __NR_shmctl 195 +#define __NR_shmdt 197 +#define __NR_shmget 194 +#define __NR_shutdown 210 +#define __NR_sigaltstack 132 +#define __NR_signalfd4 74 +#define __NR_socket 198 +#define __NR_socketpair 199 +#define __NR_splice 76 +#define __NR_statfs64 43 +#define __NR_statx 291 +#define __NR_swapoff 225 +#define __NR_swapon 224 +#define __NR_symlinkat 36 +#define __NR_sync 81 +#define __NR_sync_file_range 84 +#define __NR_syncfs 267 +#define __NR_sysinfo 179 +#define __NR_syslog 116 +#define __NR_tee 77 +#define __NR_tgkill 131 +#define __NR_timer_create 107 +#define __NR_timer_delete 111 +#define __NR_timer_getoverrun 109 +#define __NR_timer_gettime 108 +#define __NR_timer_gettime64 408 +#define __NR_timer_settime 110 +#define __NR_timer_settime64 409 +#define __NR_timerfd_create 85 +#define __NR_timerfd_gettime 87 +#define __NR_timerfd_gettime64 410 +#define __NR_timerfd_settime 86 +#define __NR_timerfd_settime64 411 +#define __NR_times 153 +#define __NR_tkill 130 +#define __NR_truncate64 45 +#define __NR_umask 166 +#define __NR_umount2 39 +#define __NR_uname 160 +#define __NR_unlinkat 35 +#define __NR_unshare 97 +#define __NR_userfaultfd 282 +#define __NR_utimensat 88 +#define __NR_utimensat_time64 412 +#define __NR_vhangup 58 +#define __NR_vmsplice 75 +#define __NR_wait4 260 +#define __NR_waitid 95 +#define __NR_write 64 +#define __NR_writev 66sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +14
-0@@ -0,0 +1,19 @@ +/* Bit size of the time_t type at glibc build time, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. +
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h line 19
Quoted 5 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +5
-0+ You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#define __TIMESIZE 64Ok, although I think we should flip the default to 64 bits make old ports to override to 32.
It makes sense. It might be a bit tricky as currently __TIMESIZE default is __WORDSIZE. I see a few old ports which have __WORDSIZE 32 and 64 like sparc.
Quoted 62 lines
Quoted 62 lines
sysdeps/unix/sysv/linux/or1k/clone.c new file +56
-0@@ -0,0 +1,61 @@ +/* OpenRISC helper for the clone syscall. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <stdarg.h> +#include <sysdep.h> + +extern int __or1k_clone (int (*fn)(void *),void *child_stack, +int flags,void *arg,pid_t *ptid, +void *tls,pid_t *ctid); + + +/* The OpenRISC ABI uses the stack for varargs like those using in clone +but the linux syscall ABI uses registers. +This function moves from varargs to regs. */ +int +__clone (int (*fn)(void *),void *child_stack, +int flags,void *arg, ... +/* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ ) +{ +void *ptid; +void *tls; +void *ctid; +va_list ap; +int err; + +va_start (ap, arg); + ptid = va_arg (ap, void *); + tls = va_arg (ap, void *); + ctid = va_arg (ap, void *); +va_end (ap); + +/* Sanity check the arguments */ + err = -EINVAL ; +if (!fn) + goto syscall_error; +if (!child_stack) + goto syscall_error; + +return __or1k_clone (fn, child_stack, flags, arg, ptid, tls, ctid); + +syscall_error:
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/clone.c line 61
Quoted 5 lines
sysdeps/unix/sysv/linux/or1k/clone.c new file +5
-0+__set_errno (-err); +return -1 ; +} +libc_hidden_def (__clone) +weak_alias (__clone, clone)Ok, I take that implementing it solely on
__or1k_cloneis more complex than using a C wrapper.
I am not to clear what you mean here, I take you are asking why we keep __or1k_clone in assembly rather than implement __or1k_clone in C too.
There are some stack setup bits in __or1k_clone which require assembly.
Quoted 41 lines
Quoted 41 lines
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h new file +35
-0@@ -0,0 +1,41 @@ +/* jump buffer constants, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +/* Produced by this program: + +#include <stdio.h> +#include <unistd.h> +#include <setjmp.h> +#include <stddef.h> + +int main (int argc, char **argv) +{ +printf ("#define JMP_BUF_SIZE %d\n", sizeof (jmp_buf)); +printf ("#define JMP_BUF_ALIGN %d\n", __alignof__ (jmp_buf)); +printf ("#define SIGJMP_BUF_SIZE %d\n", sizeof (sigjmp_buf)); +printf ("#define SIGJMP_BUF_ALIGN %d\n", __alignof__ (sigjmp_buf)); +printf ("#define MASK_WAS_SAVED_OFFSET %d\n", offsetof (struct __jmp_buf_tag, __mask_was_saved)); +printf ("#define SAVED_MASK_OFFSET %d\n", offsetof (struct __jmp_buf_tag, __saved_mask)); +} */ +
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h line 41
Quoted 6 lines
sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h new file +6
-0+#define JMP_BUF_SIZE 184 +#define JMP_BUF_ALIGN 4 +#define SIGJMP_BUF_SIZE 184 +#define SIGJMP_BUF_ALIGN 4 +#define MASK_WAS_SAVED_OFFSET 52 +#define SAVED_MASK_OFFSET 56You don't need this file since
bc801b3a40f3a9bc8f24f1d0fdc39413874c3172.
OK. I think I forgot to remove them.
Quoted 124 lines
Quoted 24 lines
sysdeps/unix/sysv/linux/or1k/mmap_internal.h new file +18
-0@@ -0,0 +1,28 @@ +/* Common mmap definition for Linux implementation. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ +sysdeps/unix/sysv/linux/or1k/mmap_internal.h line 28
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/mmap_internal.h new file +10
-0+#ifndef MMAP_OR1K_INTERNAL_LINUX_H +#define MMAP_OR1K_INTERNAL_LINUX_H + +/* OpenRISC Linux sets the page shift to 13 and mmap2 expects +offsets to be provided in 8K pages. */ +#define MMAP2_PAGE_UNIT 8192ULL + +#include_next <mmap_internal.h> + +#endif Ok.
Quoted 87 lines
sysdeps/unix/sysv/linux/or1k/or1k_clone.S new file +81
-0@@ -0,0 +1,89 @@ +/* clone helper __or1k_clone for OpenRISC. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sysdep.h> +#include <tls.h> +#define __ASSEMBLY__ +#include <linux/sched.h> + + .text +ENTRY(__or1k_clone) + + /* To handle GCC varargs we need to use our __clone wrapper to pop + everything from the stack for us. + Now everything is placed in the registers which saves us a lot + of trouble. + + The userland implementation is: + + int clone (int (*fn)(void *), void *child_stack, + int flags, void *arg, pid_t *ptid, + struct user_desc *tls, pid_t *ctid); + The kernel entry is: + + int clone (long flags, void *child_stack, int *parent_tid, + int *child_tid, struct void *tls) + + NB: tls isn't really an argument, it is read from r7 directly. */ + + /* First, align the stack to 4 bytes. */ + l.xori r11, r0, -4 + l.and r4, r4, r11 + + /* Put 'fn', 'arg' and 'flags' on the child stack. */ + l.addi r4, r4, -12 + l.sw 8(r4), r3 + l.sw 4(r4), r6 + l.sw 0(r4), r5 + + l.ori r3, r5, 0 + /* The child_stack is already in r4. */ + l.ori r5, r7, 0 + l.lwz r6, 0(r1) + l.ori r7, r8, 0 + + DO_CALL (clone) + + l.sfgeui r11, 0xf001 + l.bf L(error) + l.nop + + /* If we are not the child, return the pid. */ + l.sfeqi r11, 0 + l.bf L(thread_start) + l.nop + + l.jr r9 + l.nop + +L(thread_start): + /* Load function from stack. */ + l.lwz r11, 8(r1) + l.jalr r11 + l.lwz r3, 4(r1) + + /* Exit the child thread. */
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/or1k_clone.S line 89
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/or1k_clone.S new file +8
-0+ l.ori r3, r11, 0 + DO_CALL (exit) + +L(error): + l.j SYSCALL_ERROR_NAME + l.ori r3, r11, 0 + +PSEUDO_END (__or1k_clone)
Using PSEUDO_END is wrong here, I switched to END.
Quoted 247 lines
Quoted 247 lines
sysdeps/unix/sysv/linux/or1k/sysdep.c new file +34
-0@@ -0,0 +1,34 @@ +/* OpenRISC wrapper for setting errno. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include <errno.h> + +long int __syscall_error (long int err); +hidden_proto (__syscall_error) + +/* This routine is jumped to by all the syscall handlers, to stash +an error number into errno. */ +long int +__syscall_error (long int err) +{ +__set_errno (- err); +return -1 ; +} +hidden_def (__syscall_error)sysdeps/unix/sysv/linux/or1k/sysdep.h new file +201
-0@@ -0,0 +1,201 @@ +/* Assembler and syscall macros. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library. If not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _LINUX_OR1K_SYSDEP_H +#define _LINUX_OR1K_SYSDEP_H 1 + +#include <sysdeps/or1k/sysdep.h> +#include <sysdeps/unix/sysv/linux/generic/sysdep.h> +#include <tls.h> + +/* "workarounds" for generic code needing to handle 64-bit time_t. */ + +#undef __NR_clock_getres +#undef __NR_futex +#undef __NR_ppoll +#undef __NR_pselect6 +#undef __NR_recvmmsg +#undef __NR_rt_sigtimedwait +#undef __NR_semtimedop +#undef __NR_utimensat + +/* Fix sysdeps/unix/sysv/linux/clock_getcpuclockid.c. */ +#define __NR_clock_getres __NR_clock_getres_time64 +/* Fix sysdeps/nptl/lowlevellock-futex.h. */ +#define __NR_futex __NR_futex_time64 +/* Fix sysdeps/unix/sysv/linux/pause.c. */ +#define __NR_ppoll __NR_ppoll_time64 +/* Fix sysdeps/unix/sysv/linux/select.c. */ +#define __NR_pselect6 __NR_pselect6_time64 +/* Fix sysdeps/unix/sysv/linux/recvmmsg.c. */ +#define __NR_recvmmsg __NR_recvmmsg_time64 +/* Fix sysdeps/unix/sysv/linux/sigtimedwait.c. */ +#define __NR_rt_sigtimedwait __NR_rt_sigtimedwait_time64 +/* Fix sysdeps/unix/sysv/linux/semtimedop.c. */ +#define __NR_semtimedop __NR_semtimedop_time64 +/* Hack sysdeps/unix/sysv/linux/generic/utimes.c. */ +#define __NR_utimensat __NR_utimensat_time64 + +#undef SYS_ify +#define SYS_ify (syscall_name) (__NR_##syscall_name) + +/* Linux uses a negative return value to indicate syscall errors, +unlike most Unices, which use the condition codes' carry flag. + +Since version 2.1 the return value of a system call might be +negative even if the call succeeded. E.g., the lseek system call +might return a large offset. Therefore we must not anymore test +for < 0, but test for a real error by making sure the value in R0 +is a real error number. Linus said he will make sure the no syscall +returns a value in -1 .. -4095 as a valid result so we can safely +test with -4095. */ + +#ifdef __ASSEMBLER__ + +/* Macros used in syscall-template.S */ +#define ret l.jr r9; l.nop +#define ret_NOERRNO l.jr r9; l.nop + +#undef DO_CALL +#define DO_CALL (syscall_name) \ + l.addi r11, r0, SYS_ify (syscall_name); \ + l.sys 1; \ + l.nop + +#undef PSEUDO +#define PSEUDO(name, syscall_name, args) \ + ENTRY (name); \ + DO_CALL(syscall_name); \ + /* if -4096 < ret < 0 holds, it's an error */ \ + l.sfgeui r11, 0xf001; \ + l.bf L(pseudo_end); \ + l.nop + +#undef PSEUDO_NOERRNO +#define PSEUDO_NOERRNO (name, syscall_name, args) \ + ENTRY (name); \ + DO_CALL(syscall_name) + +#undef PSEUDO_END +#define PSEUDO_END (name) \ +L(pseudo_end): \ + l.j SYSCALL_ERROR_NAME; \ + l.ori r3,r11,0; \ + END (name) + +#undef PSEUDO_END_NOERRNO +#define PSEUDO_END_NOERRNO (name) \ + END (name) + +#ifndef PIC +/* For static code, on error jump to __syscall_error directly. */ +# define SYSCALL_ERROR_NAME __syscall_error +#elif !IS_IN (libc) +/* Use the internal name for libc shared objects. */ +# define SYSCALL_ERROR_NAME __GI___syscall_error +#else +/* Otherwise, on error do a full PLT jump. */ +# define SYSCALL_ERROR_NAME plt(__syscall_error) +#endif + +#else /* not __ASSEMBLER__ */ + +#include <errno.h> + +extern long int __syscall_error (long int neg_errno); + +/* Pointer mangling is not yet supported for or1k. */ +#define PTR_MANGLE (var) (void) (var) +#define PTR_DEMANGLE (var) (void) (var) + +#undef INTERNAL_SYSCALL +#define INTERNAL_SYSCALL(name, nr, args...) \ + INTERNAL_SYSCALL_NCS (SYS_ify (name), nr, args) + +/* The _NCS variant allows non-constant syscall numbers. */ +#undef INTERNAL_SYSCALL_NCS +#define INTERNAL_SYSCALL_NCS(number, nr, args...) \ + ({ unsigned long int __sys_result; \ + { \ + long int _sc_ret = (long int) number; \ + LOAD_ARGS_##nr (args) \ + register long int __sc_ret __asm__ ("r11") = _sc_ret; \ + __asm__ __volatile__ ("l.sys 1\n\t" \ + " l.nop\n\t" \ + : "+r" (__sc_ret) \ + : ASM_ARGS_##nr \ + : ASM_CLOBBERS_##nr \ + "r12", "r13", "r15", "r17", "r19", \ + "r21", "r23", "r25", "r27", "r29", \ + "r31", "memory"); \ + __sys_result = __sc_ret; \ + } \ + (long int) __sys_result; }) + +/* From here on we have nested macros that generate code for +setting up syscall arguments. */ + +#define LOAD_ARGS_0 () + +#define ASM_ARGS_0 +#define ASM_CLOBBERS_0 "r3", ASM_CLOBBERS_1 + +#define LOAD_ARGS_1 (a) \ + long int _a = (long int)(a); \ + register long int __a __asm__ ("r3") = _a; +#define ASM_ARGS_1 "r" (__a) +#define ASM_CLOBBERS_1 "r4", ASM_CLOBBERS_2 + +#define LOAD_ARGS_2 (a, b) \ + long int _b = (long int)(b); \ + LOAD_ARGS_1 (a) \ + register long int __b __asm__ ("r4") = _b; +#define ASM_ARGS_2 ASM_ARGS_1, "r" (__b) +#define ASM_CLOBBERS_2 "r5", ASM_CLOBBERS_3 + +#define LOAD_ARGS_3 (a, b, c) \ + long int _c = (long int)(c); \ + LOAD_ARGS_2 (a, b) \ + register long int __c __asm__ ("r5") = _c; +#define ASM_ARGS_3 ASM_ARGS_2, "r" (__c) +#define ASM_CLOBBERS_3 "r6", ASM_CLOBBERS_4 + +#define LOAD_ARGS_4 (a, b, c, d) \ + LOAD_ARGS_3 (a, b, c) \ + long int _d = (long int)(d); \ + register long int __d __asm__ ("r6") = _d; +#define ASM_ARGS_4 ASM_ARGS_3, "r" (__d) +#define ASM_CLOBBERS_4 "r7", ASM_CLOBBERS_5 + +#define LOAD_ARGS_5 (a, b, c, d, e) \ + long int _e = (long int)(e); \ + LOAD_ARGS_4 (a, b, c, d) \ + register long int __e __asm__ ("r7") = _e; +#define ASM_ARGS_5 ASM_ARGS_4, "r" (__e) +#define ASM_CLOBBERS_5 "r8", ASM_CLOBBERS_6 + +#define LOAD_ARGS_6 (a, b, c, d, e, f) \ + long int _f = (long int)(f); \ + LOAD_ARGS_5 (a, b, c, d, e) \ + register long int __f __asm__ ("r8") = _f; +#define ASM_ARGS_6 ASM_ARGS_5, "r" (__f) +#define ASM_CLOBBERS_6 + +#endif /* not __ASSEMBLER__ */ + +#endif /* linux/or1k/sysdep.h */
PATCH v3 8/13 or1k: Linux Syscall Interface
Quoted 30 lines · Stafford Horne
Quoted 20 lines · Adhemerval Zanella
Quoted 20 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +14
-0@@ -0,0 +1,19 @@ +/* Bit size of the time_t type at glibc build time, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. +Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h line 19
Quoted 5 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +5
-0+ You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#define __TIMESIZE 64Ok, although I think we should flip the default to 64 bits make old ports to override to 32.
Quoted 2 lines
It makes sense. It might be a bit tricky as currently
__TIMESIZEdefault is__WORDSIZE. I see a few old ports which have__WORDSIZE32 and 64 like sparc.
I will fix this upstream, it is just a matter to override to 32 for older ports.
Quoted 9 lines
Quoted 3 lines
Ok, I take that implementing it solely on
__or1k_cloneis more complex than using a C wrapper.I am not to clear what you mean here, I take you are asking why we keep
__or1k_clonein assembly rather than implement__or1k_clonein C too.There are some stack setup bits in
__or1k_clonewhich require assembly.
I meant otherwise in fact, why not implement clone for or1k purely in assembly.
PATCH v3 8/13 or1k: Linux Syscall Interface
Quoted 42 lines · Adhemerval Zanella
Quoted 30 lines · Stafford Horne
Quoted 20 lines · Adhemerval Zanella
Quoted 20 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +14
-0@@ -0,0 +1,19 @@ +/* Bit size of the time_t type at glibc build time, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. +Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h line 19
Quoted 5 lines
sysdeps/unix/sysv/linux/or1k/bits/timesize.h new file +5
-0+ You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#define __TIMESIZE 64Ok, although I think we should flip the default to 64 bits make old ports to override to 32.
Quoted 2 lines
It makes sense. It might be a bit tricky as currently
__TIMESIZEdefault is__WORDSIZE. I see a few old ports which have__WORDSIZE32 and 64 like sparc.I will fix this upstream, it is just a matter to override to 32 for older ports.
Quoted 4 lines
Quoted 3 lines
Ok, I take that implementing it solely on
__or1k_cloneis more complex than using a C wrapper.
Quoted 7 lines
Quoted 5 lines
I am not to clear what you mean here, I take you are asking why we keep
__or1k_clonein assembly rather than implement__or1k_clonein C too.There are some stack setup bits in
__or1k_clonewhich require assembly.I meant otherwise in fact, why not implement clone for or1k purely in assembly.
I see, it could be done but I think it's easier to maintain with the va_arg parsing and generic set_errno handling being in C.
-Staffford
PATCH v3 9/13 or1k: Linux ABI
In reply to Stafford Horne--- sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 ++++++++ sysdeps/or1k/nptl/pthreaddef.h | 36 ++++++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 ++++++ sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 +++++++++++ sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 ++++++++++++ sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 ++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 +++++ sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 ++++++++ sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 ++++ 11 files changed, 603 insertions(+) create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.sym
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +48 -0
@@ -0,0 +1,48 @@ +/* Machine-specific pthread type layouts. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _BITS_PTHREADTYPES_H +#define _BITS_PTHREADTYPES_H 1 + +#include <bits/wordsize.h> + +/* Opaque union sizes for: +pthread_attr_t - internally pthread_attr +pthread_mutex_t - internally __pthread_mutex_s +pthread_mutexattr_t - internally pthread_mutexattr +pthread_cond_t - internally __pthread_cond_s +pthread_condattr_t - internally pthread_condattr +pthread_rwlock_t - internally __pthread_rwlock_arch_t +pthread_rwlockattr_t - internally pthread_rwlockattr +pthread_barrier_t - internally pthread_barrier +pthread_barrierattr_t - internally pthread_barrierattr */ + +#define __SIZEOF_PTHREAD_ATTR_T 32 +#define __SIZEOF_PTHREAD_MUTEX_T 32 +#define __SIZEOF_PTHREAD_MUTEXATTR_T 4 +#define __SIZEOF_PTHREAD_COND_T 48 +#define __SIZEOF_PTHREAD_CONDATTR_T 4 +#define __SIZEOF_PTHREAD_RWLOCK_T 44 +#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 +#define __SIZEOF_PTHREAD_BARRIER_T 20 +#define __SIZEOF_PTHREAD_BARRIERATTR_T 4 + +#define __LOCK_ALIGNMENT +#define __ONCE_ALIGNMENT + +#endif /* bits/pthreadtypes.h */
sysdeps/or1k/nptl/pthreaddef.h new file +36 -0
@@ -0,0 +1,36 @@ +/* pthread machine parameter definitions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Default stack size. */ +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) + +/* Minimum guard size. */ +#define ARCH_MIN_GUARD_SIZE 0 + +/* Required stack pointer alignment at beginning. */ +#define STACK_ALIGN 16 + +/* Minimal stack size after allocating thread descriptor and guard size. */ +#define MINIMAL_REST_STACK 2048 + +/* Alignment requirement for TCB. Needs to be >= to STACK_ALIGN. */ +#define TCB_ALIGNMENT 32 + +/* Location of current stack frame. */ +#define CURRENT_STACK_FRAME __builtin_frame_address (0)
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +38 -0
@@ -0,0 +1,38 @@ +/* Types for registers for sys/procfs.h. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SYS_PROCFS_H +# error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead." +#endif + +#include <sys/ucontext.h> + +#define ELF_NGREG __NGREG + +/* Type for a general-purpose register. */ +typedef unsigned long int elf_greg_t ; + +/* And the array of general-purpose registers. We could have used `struct +user_regs' directly, but tradition says that the register set is an array, +which does have some peculiar semantics, so leave it that way. +GDB uses this for prtrace GETREGSET, on OpenRISC the regset contains 32 +gprs the PC and the SR, 34 longs. */ +typedef elf_greg_t elf_gregset_t [34 ]; + +/* Register set for the floating-point registers. */ +typedef elf_greg_t elf_fpregset_t [32 ];
sysdeps/unix/sysv/linux/or1k/getcontext.S new file +72 -0
72 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +77 -0
77 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/setcontext.S new file +108 -0
108 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h new file +28 -0
@@ -0,0 +1,28 @@ +/* Profile counter helper to get PC from sigcontext. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +static inline uintptr_t +sigcontext_get_pc (const ucontext_t *ctx) +{ +return ctx->uc_mcontext.__pc; +} + +#endif /* _SIGCONTEXTINFO_H */
sysdeps/unix/sysv/linux/or1k/swapcontext.S new file +116 -0
116 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/sys/ucontext.h new file +53 -0
53 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/sys/user.h new file +1 -0
@@ -0,0 +1 @@ +/* This file is not needed, but in practice gdb might try to include it. */
sysdeps/unix/sysv/linux/or1k/ucontext_i.sym new file +26 -0
@@ -0,0 +1,26 @@ +#include <inttypes.h> +#include <signal.h> +#include <stddef.h> +#include <sys/ucontext.h> + +-- Constants used by the rt_sigprocmask call. + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +-- Offsets of the fields in the ucontext_t structure. +#define ucontext(member) offsetof (ucontext_t, member) +#define stack(member) ucontext (uc_stack.member) + +UCONTEXT_LINK ucontext (uc_link) +UCONTEXT_STACK ucontext (uc_stack) +UCONTEXT_MCONTEXT ucontext (uc_mcontext) +UCONTEXT_SIGMASK ucontext (uc_sigmask) + +STACK_SP stack (ss_sp) +STACK_SIZE stack (ss_size) +STACK_FLAGS stack (ss_flags) + +UCONTEXT_SIZE sizeof (ucontext_t)
Signature · 1 line
2.31.1
PATCH v3 9/13 or1k: Linux ABI
Some comments below.
Quoted 69 lines · Stafford Horne via Libc-alpha
--- sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 ++++++++ sysdeps/or1k/nptl/pthreaddef.h | 36 ++++++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 ++++++ sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 +++++++++++ sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 ++++++++++++ sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 ++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 +++++ sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 ++++++++ sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 ++++ 11 files changed, 603 insertions(+) create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.symsysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +38
-0@@ -0,0 +1,48 @@ +/* Machine-specific pthread type layouts. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _BITS_PTHREADTYPES_H +#define _BITS_PTHREADTYPES_H 1 + +#include <bits/wordsize.h> + +/* Opaque union sizes for: +pthread_attr_t - internally pthread_attr +pthread_mutex_t - internally __pthread_mutex_s +pthread_mutexattr_t - internally pthread_mutexattr +pthread_cond_t - internally __pthread_cond_s +pthread_condattr_t - internally pthread_condattr +pthread_rwlock_t - internally __pthread_rwlock_arch_t +pthread_rwlockattr_t - internally pthread_rwlockattr +pthread_barrier_t - internally pthread_barrier +pthread_barrierattr_t - internally pthread_barrierattr */ + +#define __SIZEOF_PTHREAD_ATTR_T 32 +#define __SIZEOF_PTHREAD_MUTEX_T 32 +#define __SIZEOF_PTHREAD_MUTEXATTR_T 4 +#define __SIZEOF_PTHREAD_COND_T 48
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h line 48
Quoted 10 lines
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +10
-0+#define __SIZEOF_PTHREAD_CONDATTR_T 4 +#define __SIZEOF_PTHREAD_RWLOCK_T 44 +#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 +#define __SIZEOF_PTHREAD_BARRIER_T 20 +#define __SIZEOF_PTHREAD_BARRIERATTR_T 4 + +#define __LOCK_ALIGNMENT +#define __ONCE_ALIGNMENT + +#endif /* bits/pthreadtypes.h */
Why can't use the default values on sysdeps/nptl/bits/pthreadtypes-arch.h ?
Quoted 32 lines
sysdeps/or1k/nptl/pthreaddef.h new file +26
-0@@ -0,0 +1,36 @@ +/* pthread machine parameter definitions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Default stack size. */ +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) + +/* Minimum guard size. */ +#define ARCH_MIN_GUARD_SIZE 0 + +/* Required stack pointer alignment at beginning. */
sysdeps/or1k/nptl/pthreaddef.h line 36
Quoted 10 lines
sysdeps/or1k/nptl/pthreaddef.h new file +10
-0+#define STACK_ALIGN 16 + +/* Minimal stack size after allocating thread descriptor and guard size. */ +#define MINIMAL_REST_STACK 2048 + +/* Alignment requirement for TCB. Needs to be >= to STACK_ALIGN. */ +#define TCB_ALIGNMENT 32 + +/* Location of current stack frame. */ +#define CURRENT_STACK_FRAME __builtin_frame_address (0)
Ok. As a side note, maybe we could provide a default header with this exact definitions.
Quoted 34 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +28
-0@@ -0,0 +1,38 @@ +/* Types for registers for sys/procfs.h. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SYS_PROCFS_H +# error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead." +#endif + +#include <sys/ucontext.h> + +#define ELF_NGREG __NGREG + +/* Type for a general-purpose register. */ +typedef unsigned long int elf_greg_t ;
sysdeps/unix/sysv/linux/or1k/bits/procfs.h line 38
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +10
-0+ +/* And the array of general-purpose registers. We could have used `struct +user_regs' directly, but tradition says that the register set is an array, +which does have some peculiar semantics, so leave it that way. +GDB uses this for prtrace GETREGSET, on OpenRISC the regset contains 32 +gprs the PC and the SR, 34 longs. */ +typedef elf_greg_t elf_gregset_t [34 ]; + +/* Register set for the floating-point registers. */ +typedef elf_greg_t elf_fpregset_t [32 ];
It indicates that that or1k would only support float32, is that correct?
Quoted 128 lines
sysdeps/unix/sysv/linux/or1k/getcontext.S new file +72
-0@@ -0,0 +1,72 @@ +/* Save current context. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int getcontext (ucontext_t *ucp) + + Returns 0 on success -1 and errno on failure. + */ + .text +ENTRY(__getcontext) + /* Store r1, the stack pointer. */ + l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1 + /* Store r2, the frame pointer. */ + l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2 + /* Store r9, the link register. */ + l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9 + /* Store r9 to reg[11] too, as we need two links for makecontext. */ + l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9 + /* Store r10, the TLS register. */ + l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10 + /* Store r14-r30 even, callee saved registers. */ + l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14 + l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16 + l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18 + l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20 + l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22 + l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24 + l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26 + l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28 + l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.addi r5, r3, UCONTEXT_SIGMASK + l.ori r4, r0, 0 + l.ori r3, r0, SIG_BLOCK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + l.jr r9 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END(__getcontext) +weak_alias(__getcontext, getcontext)sysdeps/unix/sysv/linux/or1k/makecontext.c new file +44
-0@@ -0,0 +1,77 @@ +/* Create new context. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include <stdarg.h> +#include <stdint.h> +#include <ucontext.h> + +/* makecontext sets up a stack and the registers for the +user context. The stack looks like this: + ++-----------------------+ +| padding as required | ++-----------------------+ +sp -> | parameters 7 to n | ++-----------------------+ + +The registers are set up like this: +r3-r8 : parameters 1 to 6 +r14 : uc_link +r1 : stack pointer +r2 : frame pointer, set to NULL +*/ +void +__makecontext (ucontext_t *ucp,void (*func) (void ),int argc, ...) +{ +extern void __startcontext (void ); +unsigned long int *sp; +va_list ap;
sysdeps/unix/sysv/linux/or1k/makecontext.c line 54
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +10
-0+int i; + + sp = (unsigned long int *) + ((uintptr_t ) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size); + +/* Allocate stack arguments. */ + sp -= argc <6 ?0 : argc -6 ; + +/* Keep the stack aligned. */ + sp = (unsigned long int *) (((uintptr_t ) sp) &-4L );
Is stack required to be 4 or 16 (STACK_ALIGN from pthreaddef.h)?
Quoted 391 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +23
-0+ +/* Keep uc_link in r14. */ + ucp->uc_mcontext.__gprs[14 ] = (uintptr_t ) ucp->uc_link; +/* Return address points to function __startcontext. */ + ucp->uc_mcontext.__gprs[9 ] = (uintptr_t ) &__startcontext; +/* Frame pointer is null. */ + ucp->uc_mcontext.__gprs[2 ] = (uintptr_t )0 ; +/* Restart in user-space starting at 'func'. */ + ucp->uc_mcontext.__gprs[11 ] = (uintptr_t ) func; +/* Set stack pointer. */ + ucp->uc_mcontext.__gprs[1 ] = (uintptr_t ) sp; + +va_start (ap, argc); +for (i =0 ; i < argc; ++i) +if (i <6 ) + ucp->uc_mcontext.__gprs[i + 3] = va_arg (ap, unsigned long int); +else + sp[i - 6] = va_arg (ap, unsigned long int); + +va_end (ap); +} + +weak_alias (__makecontext, makecontext)sysdeps/unix/sysv/linux/or1k/setcontext.S new file +108
-0@@ -0,0 +1,108 @@ +/* Set current context. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int setcontext (const ucontext_t *ucp) */ + .text +ENTRY(__setcontext) + l.ori r30, r3, 0 + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.ori r5, r0, 0 + l.addi r4, r3, UCONTEXT_SIGMASK + l.ori r3, r0, SIG_SETMASK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Restore argument registers, for the makecontext case. */ + l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30) + l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30) + l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30) + l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30) + l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30) + l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30) + + /* Restore registers stored in getcontext. */ + l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30) + l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30) + l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30) + l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30) + l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30) + /* Restore r14-r30 even, callee saved registers. */ + l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30) + l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30) + l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30) + l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30) + l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30) + l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30) + l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30) + l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30) + l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30) + + l.jr r11 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END (__setcontext) +weak_alias (__setcontext, setcontext) + + /* We add a NOP here because when the unwinder is looking for the + enclosing function of the link register (r9) address FDE lookup will + use '$r9 - 1' finding setcontext which is wrong. This is because in + makecontext we have set r9 to the start of &__startcontext. + + If this NOP did not exist the unwinder would repeatedly find + __setcontext's FDE in an infinite loop. Modifiying/deleting the below + __startcontext's FDE has no help on this. */ + l.nop + +ENTRY(__startcontext) + + l.ori r3, r14, 0 + l.sfeq r3, r0 + /* If uc_link is not 0 resume there, otherwise exit. */ + l.bnf __setcontext + l.nop + +#ifdef SHARED + /* Obtain a pointer to .got in r16 */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + l.lwz r16, got(exit)(r16) + l.jr r16 +#else + l.j exit +#endif + l.nop + +END(__startcontext)sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h new file +28
-0@@ -0,0 +1,28 @@ +/* Profile counter helper to get PC from sigcontext. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +static inline uintptr_t +sigcontext_get_pc (const ucontext_t *ctx) +{ +return ctx->uc_mcontext.__pc; +} + +#endif /* _SIGCONTEXTINFO_H */ sysdeps/unix/sysv/linux/or1k/swapcontext.S new file +116
-0@@ -0,0 +1,116 @@ +/* Swap two contexts. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */ + .text +ENTRY(__swapcontext) + + /* Same as getcontext. */ + /* Store r1, the stack pointer. */ + l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1 + /* Store r2, the frame pointer. */ + l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2 + /* Store r9, the link register. */ + l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9 + /* Store r9 to reg[11] too, as we need two links for makecontext. */ + l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9 + /* Store r10, the TLS register. */ + l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10 + /* Store r14-r30 even, callee saved registers. */ + l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14 + l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16 + l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18 + l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20 + l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22 + l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24 + l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26 + l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28 + l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30 + + /* Store ucp to non-argument syscall preserved register. */ + l.ori r30, r4, 0 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.addi r5, r3, UCONTEXT_SIGMASK + l.ori r4, r0, 0 + l.ori r3, r0, SIG_BLOCK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Same as setcontext. */ + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.ori r5, r0, 0 + l.addi r4, r30, UCONTEXT_SIGMASK + l.ori r3, r0, SIG_SETMASK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Restore argument registers, for the makecontext case. */ + l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30) + l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30) + l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30) + l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30) + l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30) + l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30) + + /* Restore registers stored in getcontext. */ + l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30) + l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30) + l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30) + l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30) + l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30) + l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30) + l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30) + l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30) + l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30) + l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30) + l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30) + l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30) + l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30) + l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30) + + l.jr r11 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END (__swapcontext) +weak_alias (__swapcontext, swapcontext)sysdeps/unix/sysv/linux/or1k/sys/ucontext.h new file +53
-0@@ -0,0 +1,53 @@ +/* ucontext_t definition, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* System V/OpenRISC compliant context switching support. */ + +#ifndef _SYS_UCONTEXT_H +#define _SYS_UCONTEXT_H 1 + +#include <features.h> + +#include <bits/types/sigset_t.h> +#include <bits/types/stack_t.h> + +/* Number of general registers. */ +#define __NGREG 32 +#ifdef __USE_MISC +# define NGREG __NGREG +#endif + +/* Context to describe whole processor state. */ +typedef struct + { +unsigned long int __gprs[__NGREG]; +unsigned long int __pc; +unsigned long int __sr; + }mcontext_t ; + +/* Userlevel context. */ +typedef struct ucontext_t + { +unsigned long int __uc_flags; +struct ucontext_t *uc_link; +stack_t uc_stack; +mcontext_t uc_mcontext; +sigset_t uc_sigmask; + }ucontext_t ; + +#endif /* sys/ucontext.h */ sysdeps/unix/sysv/linux/or1k/sys/user.h new file +1
-0@@ -0,0 +1 @@ +/* This file is not needed, but in practice gdb might try to include it. */ sysdeps/unix/sysv/linux/or1k/ucontext_i.sym new file +26
-0@@ -0,0 +1,26 @@ +#include <inttypes.h> +#include <signal.h> +#include <stddef.h> +#include <sys/ucontext.h> + +-- Constants used by the rt_sigprocmask call. + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +-- Offsets of the fields in the ucontext_t structure. +#define ucontext(member) offsetof (ucontext_t, member) +#define stack(member) ucontext (uc_stack.member) + +UCONTEXT_LINK ucontext (uc_link) +UCONTEXT_STACK ucontext (uc_stack) +UCONTEXT_MCONTEXT ucontext (uc_mcontext) +UCONTEXT_SIGMASK ucontext (uc_sigmask) + +STACK_SP stack (ss_sp) +STACK_SIZE stack (ss_size) +STACK_FLAGS stack (ss_flags) + +UCONTEXT_SIZE sizeof (ucontext_t)
PATCH v3 9/13 or1k: Linux ABI
Quoted 76 lines · Adhemerval Zanella
Some comments below.
Quoted 73 lines · Stafford Horne via Libc-alpha
--- sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 ++++++++ sysdeps/or1k/nptl/pthreaddef.h | 36 ++++++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 ++++++ sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 +++++++++++ sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 ++++++++++++ sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 ++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 +++++ sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 ++++++++ sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 ++++ 11 files changed, 603 insertions(+) create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.symsysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +42
-0@@ -0,0 +1,48 @@ +/* Machine-specific pthread type layouts. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _BITS_PTHREADTYPES_H +#define _BITS_PTHREADTYPES_H 1 + +#include <bits/wordsize.h> + +/* Opaque union sizes for: +pthread_attr_t - internally pthread_attr +pthread_mutex_t - internally __pthread_mutex_s +pthread_mutexattr_t - internally pthread_mutexattr +pthread_cond_t - internally __pthread_cond_s +pthread_condattr_t - internally pthread_condattr +pthread_rwlock_t - internally __pthread_rwlock_arch_t +pthread_rwlockattr_t - internally pthread_rwlockattr +pthread_barrier_t - internally pthread_barrier +pthread_barrierattr_t - internally pthread_barrierattr */ + +#define __SIZEOF_PTHREAD_ATTR_T 32 +#define __SIZEOF_PTHREAD_MUTEX_T 32 +#define __SIZEOF_PTHREAD_MUTEXATTR_T 4 +#define __SIZEOF_PTHREAD_COND_T 48 +#define __SIZEOF_PTHREAD_CONDATTR_T 4 +#define __SIZEOF_PTHREAD_RWLOCK_T 44 +#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 +#define __SIZEOF_PTHREAD_BARRIER_T 20
Quoted 8 lines
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h line 48
Quoted 6 lines
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +6
-0+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4 + +#define __LOCK_ALIGNMENT +#define __ONCE_ALIGNMENT + +#endif /* bits/pthreadtypes.h */ Why can't use the default values on
sysdeps/nptl/bits/pthreadtypes-arch.h?
I think it can, let me test.
Quoted 84 lines
Quoted 32 lines
sysdeps/or1k/nptl/pthreaddef.h new file +26
-0@@ -0,0 +1,36 @@ +/* pthread machine parameter definitions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Default stack size. */ +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) + +/* Minimum guard size. */ +#define ARCH_MIN_GUARD_SIZE 0 + +/* Required stack pointer alignment at beginning. */ sysdeps/or1k/nptl/pthreaddef.h line 36
Quoted 10 lines
sysdeps/or1k/nptl/pthreaddef.h new file +10
-0+#define STACK_ALIGN 16 + +/* Minimal stack size after allocating thread descriptor and guard size. */ +#define MINIMAL_REST_STACK 2048 + +/* Alignment requirement for TCB. Needs to be >= to STACK_ALIGN. */ +#define TCB_ALIGNMENT 32 + +/* Location of current stack frame. */ +#define CURRENT_STACK_FRAME __builtin_frame_address (0)Ok. As a side note, maybe we could provide a default header with this exact definitions.
Quoted 38 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +32
-0@@ -0,0 +1,38 @@ +/* Types for registers for sys/procfs.h. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SYS_PROCFS_H +# error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead." +#endif + +#include <sys/ucontext.h> + +#define ELF_NGREG __NGREG + +/* Type for a general-purpose register. */ +typedef unsigned long int elf_greg_t ; + +/* And the array of general-purpose registers. We could have used `struct +user_regs' directly, but tradition says that the register set is an array, +which does have some peculiar semantics, so leave it that way.
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h line 38
Quoted 6 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +6
-0+GDB uses this for prtrace GETREGSET, on OpenRISC the regset contains 32 +gprs the PC and the SR, 34 longs. */ +typedef elf_greg_t elf_gregset_t [34 ]; + +/* Register set for the floating-point registers. */ +typedef elf_greg_t elf_fpregset_t [32 ];It indicates that that or1k would only support float32, is that correct?
OpenRISC support 64-bit double's by using register pairs. i.e. r16,r17 + r18,r19. The floating point and genral purpose registers actually are the same 32 registers.
Quoted 132 lines
Quoted 132 lines
sysdeps/unix/sysv/linux/or1k/getcontext.S new file +72
-0@@ -0,0 +1,72 @@ +/* Save current context. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int getcontext (ucontext_t *ucp) + + Returns 0 on success -1 and errno on failure. + */ + .text +ENTRY(__getcontext) + /* Store r1, the stack pointer. */ + l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1 + /* Store r2, the frame pointer. */ + l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2 + /* Store r9, the link register. */ + l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9 + /* Store r9 to reg[11] too, as we need two links for makecontext. */ + l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9 + /* Store r10, the TLS register. */ + l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10 + /* Store r14-r30 even, callee saved registers. */ + l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14 + l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16 + l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18 + l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20 + l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22 + l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24 + l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26 + l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28 + l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.addi r5, r3, UCONTEXT_SIGMASK + l.ori r4, r0, 0 + l.ori r3, r0, SIG_BLOCK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + l.jr r9 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END(__getcontext) +weak_alias(__getcontext, getcontext)sysdeps/unix/sysv/linux/or1k/makecontext.c new file +48
-0@@ -0,0 +1,77 @@ +/* Create new context. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include <stdarg.h> +#include <stdint.h> +#include <ucontext.h> + +/* makecontext sets up a stack and the registers for the +user context. The stack looks like this: + ++-----------------------+ +| padding as required | ++-----------------------+ +sp -> | parameters 7 to n | ++-----------------------+ + +The registers are set up like this: +r3-r8 : parameters 1 to 6 +r14 : uc_link +r1 : stack pointer +r2 : frame pointer, set to NULL +*/ +void +__makecontext (ucontext_t *ucp,void (*func) (void ),int argc, ...) +{ +extern void __startcontext (void ); +unsigned long int *sp; +va_list ap; +int i; + + sp = (unsigned long int *) + ((uintptr_t ) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c line 54
Quoted 6 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +6
-0+ +/* Allocate stack arguments. */ + sp -= argc <6 ?0 : argc -6 ; + +/* Keep the stack aligned. */ + sp = (unsigned long int *) (((uintptr_t ) sp) &-4L );Is stack required to be 4 or 16 (
STACK_ALIGNfrompthreaddef.h)?
Is STACK_ALIGN used for anything other than asserts now?
I cannot recall why the alignment was set to 16 bytes, it may be copy and paste or it may be due to our cache lines being either 16bytes or 32bytes (usually 32).
Do you see any issue changing STACK_ALIGN to 4 bytes?
-Stafford
Quoted 391 lines
Quoted 391 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +23
-0+ +/* Keep uc_link in r14. */ + ucp->uc_mcontext.__gprs[14 ] = (uintptr_t ) ucp->uc_link; +/* Return address points to function __startcontext. */ + ucp->uc_mcontext.__gprs[9 ] = (uintptr_t ) &__startcontext; +/* Frame pointer is null. */ + ucp->uc_mcontext.__gprs[2 ] = (uintptr_t )0 ; +/* Restart in user-space starting at 'func'. */ + ucp->uc_mcontext.__gprs[11 ] = (uintptr_t ) func; +/* Set stack pointer. */ + ucp->uc_mcontext.__gprs[1 ] = (uintptr_t ) sp; + +va_start (ap, argc); +for (i =0 ; i < argc; ++i) +if (i <6 ) + ucp->uc_mcontext.__gprs[i + 3] = va_arg (ap, unsigned long int); +else + sp[i - 6] = va_arg (ap, unsigned long int); + +va_end (ap); +} + +weak_alias (__makecontext, makecontext)sysdeps/unix/sysv/linux/or1k/setcontext.S new file +108
-0@@ -0,0 +1,108 @@ +/* Set current context. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int setcontext (const ucontext_t *ucp) */ + .text +ENTRY(__setcontext) + l.ori r30, r3, 0 + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.ori r5, r0, 0 + l.addi r4, r3, UCONTEXT_SIGMASK + l.ori r3, r0, SIG_SETMASK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Restore argument registers, for the makecontext case. */ + l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30) + l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30) + l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30) + l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30) + l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30) + l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30) + + /* Restore registers stored in getcontext. */ + l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30) + l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30) + l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30) + l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30) + l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30) + /* Restore r14-r30 even, callee saved registers. */ + l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30) + l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30) + l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30) + l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30) + l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30) + l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30) + l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30) + l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30) + l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30) + + l.jr r11 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END (__setcontext) +weak_alias (__setcontext, setcontext) + + /* We add a NOP here because when the unwinder is looking for the + enclosing function of the link register (r9) address FDE lookup will + use '$r9 - 1' finding setcontext which is wrong. This is because in + makecontext we have set r9 to the start of &__startcontext. + + If this NOP did not exist the unwinder would repeatedly find + __setcontext's FDE in an infinite loop. Modifiying/deleting the below + __startcontext's FDE has no help on this. */ + l.nop + +ENTRY(__startcontext) + + l.ori r3, r14, 0 + l.sfeq r3, r0 + /* If uc_link is not 0 resume there, otherwise exit. */ + l.bnf __setcontext + l.nop + +#ifdef SHARED + /* Obtain a pointer to .got in r16 */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + l.lwz r16, got(exit)(r16) + l.jr r16 +#else + l.j exit +#endif + l.nop + +END(__startcontext)sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h new file +28
-0@@ -0,0 +1,28 @@ +/* Profile counter helper to get PC from sigcontext. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +static inline uintptr_t +sigcontext_get_pc (const ucontext_t *ctx) +{ +return ctx->uc_mcontext.__pc; +} + +#endif /* _SIGCONTEXTINFO_H */ sysdeps/unix/sysv/linux/or1k/swapcontext.S new file +116
-0@@ -0,0 +1,116 @@ +/* Swap two contexts. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */ + .text +ENTRY(__swapcontext) + + /* Same as getcontext. */ + /* Store r1, the stack pointer. */ + l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1 + /* Store r2, the frame pointer. */ + l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2 + /* Store r9, the link register. */ + l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9 + /* Store r9 to reg[11] too, as we need two links for makecontext. */ + l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9 + /* Store r10, the TLS register. */ + l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10 + /* Store r14-r30 even, callee saved registers. */ + l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14 + l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16 + l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18 + l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20 + l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22 + l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24 + l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26 + l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28 + l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30 + + /* Store ucp to non-argument syscall preserved register. */ + l.ori r30, r4, 0 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.addi r5, r3, UCONTEXT_SIGMASK + l.ori r4, r0, 0 + l.ori r3, r0, SIG_BLOCK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Same as setcontext. */ + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.ori r5, r0, 0 + l.addi r4, r30, UCONTEXT_SIGMASK + l.ori r3, r0, SIG_SETMASK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Restore argument registers, for the makecontext case. */ + l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30) + l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30) + l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30) + l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30) + l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30) + l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30) + + /* Restore registers stored in getcontext. */ + l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30) + l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30) + l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30) + l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30) + l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30) + l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30) + l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30) + l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30) + l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30) + l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30) + l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30) + l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30) + l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30) + l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30) + + l.jr r11 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END (__swapcontext) +weak_alias (__swapcontext, swapcontext)sysdeps/unix/sysv/linux/or1k/sys/ucontext.h new file +53
-0@@ -0,0 +1,53 @@ +/* ucontext_t definition, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* System V/OpenRISC compliant context switching support. */ + +#ifndef _SYS_UCONTEXT_H +#define _SYS_UCONTEXT_H 1 + +#include <features.h> + +#include <bits/types/sigset_t.h> +#include <bits/types/stack_t.h> + +/* Number of general registers. */ +#define __NGREG 32 +#ifdef __USE_MISC +# define NGREG __NGREG +#endif + +/* Context to describe whole processor state. */ +typedef struct + { +unsigned long int __gprs[__NGREG]; +unsigned long int __pc; +unsigned long int __sr; + }mcontext_t ; + +/* Userlevel context. */ +typedef struct ucontext_t + { +unsigned long int __uc_flags; +struct ucontext_t *uc_link; +stack_t uc_stack; +mcontext_t uc_mcontext; +sigset_t uc_sigmask; + }ucontext_t ; + +#endif /* sys/ucontext.h */ sysdeps/unix/sysv/linux/or1k/sys/user.h new file +1
-0@@ -0,0 +1 @@ +/* This file is not needed, but in practice gdb might try to include it. */ sysdeps/unix/sysv/linux/or1k/ucontext_i.sym new file +26
-0@@ -0,0 +1,26 @@ +#include <inttypes.h> +#include <signal.h> +#include <stddef.h> +#include <sys/ucontext.h> + +-- Constants used by the rt_sigprocmask call. + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +-- Offsets of the fields in the ucontext_t structure. +#define ucontext(member) offsetof (ucontext_t, member) +#define stack(member) ucontext (uc_stack.member) + +UCONTEXT_LINK ucontext (uc_link) +UCONTEXT_STACK ucontext (uc_stack) +UCONTEXT_MCONTEXT ucontext (uc_mcontext) +UCONTEXT_SIGMASK ucontext (uc_sigmask) + +STACK_SP stack (ss_sp) +STACK_SIZE stack (ss_size) +STACK_FLAGS stack (ss_flags) + +UCONTEXT_SIZE sizeof (ucontext_t)
PATCH v3 9/13 or1k: Linux ABI
Quoted 326 lines · Stafford Horne
Quoted 76 lines · Adhemerval Zanella
Some comments below.
Quoted 73 lines · Stafford Horne via Libc-alpha
--- sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 ++++++++ sysdeps/or1k/nptl/pthreaddef.h | 36 ++++++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 ++++++ sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 +++++++++++ sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 ++++++++++++ sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 ++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 +++++ sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 ++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 ++++++++ sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 ++++ 11 files changed, 603 insertions(+) create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.symsysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +42
-0@@ -0,0 +1,48 @@ +/* Machine-specific pthread type layouts. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _BITS_PTHREADTYPES_H +#define _BITS_PTHREADTYPES_H 1 + +#include <bits/wordsize.h> + +/* Opaque union sizes for: +pthread_attr_t - internally pthread_attr +pthread_mutex_t - internally __pthread_mutex_s +pthread_mutexattr_t - internally pthread_mutexattr +pthread_cond_t - internally __pthread_cond_s +pthread_condattr_t - internally pthread_condattr +pthread_rwlock_t - internally __pthread_rwlock_arch_t +pthread_rwlockattr_t - internally pthread_rwlockattr +pthread_barrier_t - internally pthread_barrier +pthread_barrierattr_t - internally pthread_barrierattr */ + +#define __SIZEOF_PTHREAD_ATTR_T 32 +#define __SIZEOF_PTHREAD_MUTEX_T 32 +#define __SIZEOF_PTHREAD_MUTEXATTR_T 4 +#define __SIZEOF_PTHREAD_COND_T 48 +#define __SIZEOF_PTHREAD_CONDATTR_T 4 +#define __SIZEOF_PTHREAD_RWLOCK_T 44 +#define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 +#define __SIZEOF_PTHREAD_BARRIER_T 20Quoted 8 lines
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h line 48
Quoted 6 lines
sysdeps/or1k/nptl/bits/pthreadtypes-arch.h new file +6
-0+#define __SIZEOF_PTHREAD_BARRIERATTR_T 4 + +#define __LOCK_ALIGNMENT +#define __ONCE_ALIGNMENT + +#endif /* bits/pthreadtypes.h */ Why can't use the default values on
sysdeps/nptl/bits/pthreadtypes-arch.h?I think it can, let me test.
Quoted 84 lines
Quoted 32 lines
sysdeps/or1k/nptl/pthreaddef.h new file +26
-0@@ -0,0 +1,36 @@ +/* pthread machine parameter definitions. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. + +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2.1 of the +License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* Default stack size. */ +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) + +/* Minimum guard size. */ +#define ARCH_MIN_GUARD_SIZE 0 + +/* Required stack pointer alignment at beginning. */ sysdeps/or1k/nptl/pthreaddef.h line 36
Quoted 10 lines
sysdeps/or1k/nptl/pthreaddef.h new file +10
-0+#define STACK_ALIGN 16 + +/* Minimal stack size after allocating thread descriptor and guard size. */ +#define MINIMAL_REST_STACK 2048 + +/* Alignment requirement for TCB. Needs to be >= to STACK_ALIGN. */ +#define TCB_ALIGNMENT 32 + +/* Location of current stack frame. */ +#define CURRENT_STACK_FRAME __builtin_frame_address (0)Ok. As a side note, maybe we could provide a default header with this exact definitions.
Quoted 38 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +32
-0@@ -0,0 +1,38 @@ +/* Types for registers for sys/procfs.h. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SYS_PROCFS_H +# error "Never include <bits/procfs.h> directly; use <sys/procfs.h> instead." +#endif + +#include <sys/ucontext.h> + +#define ELF_NGREG __NGREG + +/* Type for a general-purpose register. */ +typedef unsigned long int elf_greg_t ; + +/* And the array of general-purpose registers. We could have used `struct +user_regs' directly, but tradition says that the register set is an array, +which does have some peculiar semantics, so leave it that way. Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h line 38
Quoted 6 lines
sysdeps/unix/sysv/linux/or1k/bits/procfs.h new file +6
-0+GDB uses this for prtrace GETREGSET, on OpenRISC the regset contains 32 +gprs the PC and the SR, 34 longs. */ +typedef elf_greg_t elf_gregset_t [34 ]; + +/* Register set for the floating-point registers. */ +typedef elf_greg_t elf_fpregset_t [32 ];It indicates that that or1k would only support float32, is that correct?
OpenRISC support 64-bit double's by using register pairs. i.e. r16,r17 + r18,r19. The floating point and genral purpose registers actually are the same 32 registers.
Quoted 132 lines
Quoted 132 lines
sysdeps/unix/sysv/linux/or1k/getcontext.S new file +72
-0@@ -0,0 +1,72 @@ +/* Save current context. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int getcontext (ucontext_t *ucp) + + Returns 0 on success -1 and errno on failure. + */ + .text +ENTRY(__getcontext) + /* Store r1, the stack pointer. */ + l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1 + /* Store r2, the frame pointer. */ + l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2 + /* Store r9, the link register. */ + l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9 + /* Store r9 to reg[11] too, as we need two links for makecontext. */ + l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9 + /* Store r10, the TLS register. */ + l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10 + /* Store r14-r30 even, callee saved registers. */ + l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14 + l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16 + l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18 + l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20 + l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22 + l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24 + l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26 + l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28 + l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.addi r5, r3, UCONTEXT_SIGMASK + l.ori r4, r0, 0 + l.ori r3, r0, SIG_BLOCK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + l.jr r9 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END(__getcontext) +weak_alias(__getcontext, getcontext)sysdeps/unix/sysv/linux/or1k/makecontext.c new file +48
-0@@ -0,0 +1,77 @@ +/* Create new context. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include <stdarg.h> +#include <stdint.h> +#include <ucontext.h> + +/* makecontext sets up a stack and the registers for the +user context. The stack looks like this: + ++-----------------------+ +| padding as required | ++-----------------------+ +sp -> | parameters 7 to n | ++-----------------------+ + +The registers are set up like this: +r3-r8 : parameters 1 to 6 +r14 : uc_link +r1 : stack pointer +r2 : frame pointer, set to NULL +*/ +void +__makecontext (ucontext_t *ucp,void (*func) (void ),int argc, ...) +{ +extern void __startcontext (void ); +unsigned long int *sp; +va_list ap; +int i; + + sp = (unsigned long int *) + ((uintptr_t ) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c line 54
Quoted 6 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +6
-0+ +/* Allocate stack arguments. */ + sp -= argc <6 ?0 : argc -6 ; + +/* Keep the stack aligned. */ + sp = (unsigned long int *) (((uintptr_t ) sp) &-4L );Is stack required to be 4 or 16 (
STACK_ALIGNfrompthreaddef.h)?
Quoted 7 lines
Is
STACK_ALIGNused for anything other than asserts now?I cannot recall why the alignment was set to 16 bytes, it may be copy and paste or it may be due to our cache lines being either 16bytes or 32bytes (usually 32).
Do you see any issue changing
STACK_ALIGNto 4 bytes?
Nevermind, this should be in the OpenRISC spec. And it is, it specifies 4 byte alignment.
Also, GCC and GDB define it as 4.
-Stafford
Quoted 393 lines
-Stafford
Quoted 391 lines
Quoted 391 lines
sysdeps/unix/sysv/linux/or1k/makecontext.c new file +23
-0+ +/* Keep uc_link in r14. */ + ucp->uc_mcontext.__gprs[14 ] = (uintptr_t ) ucp->uc_link; +/* Return address points to function __startcontext. */ + ucp->uc_mcontext.__gprs[9 ] = (uintptr_t ) &__startcontext; +/* Frame pointer is null. */ + ucp->uc_mcontext.__gprs[2 ] = (uintptr_t )0 ; +/* Restart in user-space starting at 'func'. */ + ucp->uc_mcontext.__gprs[11 ] = (uintptr_t ) func; +/* Set stack pointer. */ + ucp->uc_mcontext.__gprs[1 ] = (uintptr_t ) sp; + +va_start (ap, argc); +for (i =0 ; i < argc; ++i) +if (i <6 ) + ucp->uc_mcontext.__gprs[i + 3] = va_arg (ap, unsigned long int); +else + sp[i - 6] = va_arg (ap, unsigned long int); + +va_end (ap); +} + +weak_alias (__makecontext, makecontext)sysdeps/unix/sysv/linux/or1k/setcontext.S new file +108
-0@@ -0,0 +1,108 @@ +/* Set current context. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int setcontext (const ucontext_t *ucp) */ + .text +ENTRY(__setcontext) + l.ori r30, r3, 0 + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.ori r5, r0, 0 + l.addi r4, r3, UCONTEXT_SIGMASK + l.ori r3, r0, SIG_SETMASK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Restore argument registers, for the makecontext case. */ + l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30) + l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30) + l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30) + l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30) + l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30) + l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30) + + /* Restore registers stored in getcontext. */ + l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30) + l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30) + l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30) + l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30) + l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30) + /* Restore r14-r30 even, callee saved registers. */ + l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30) + l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30) + l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30) + l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30) + l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30) + l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30) + l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30) + l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30) + l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30) + + l.jr r11 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END (__setcontext) +weak_alias (__setcontext, setcontext) + + /* We add a NOP here because when the unwinder is looking for the + enclosing function of the link register (r9) address FDE lookup will + use '$r9 - 1' finding setcontext which is wrong. This is because in + makecontext we have set r9 to the start of &__startcontext. + + If this NOP did not exist the unwinder would repeatedly find + __setcontext's FDE in an infinite loop. Modifiying/deleting the below + __startcontext's FDE has no help on this. */ + l.nop + +ENTRY(__startcontext) + + l.ori r3, r14, 0 + l.sfeq r3, r0 + /* If uc_link is not 0 resume there, otherwise exit. */ + l.bnf __setcontext + l.nop + +#ifdef SHARED + /* Obtain a pointer to .got in r16 */ + l.jal 0x8 + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_-4) + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+0) + l.add r16, r16, r9 + l.lwz r16, got(exit)(r16) + l.jr r16 +#else + l.j exit +#endif + l.nop + +END(__startcontext)sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h new file +28
-0@@ -0,0 +1,28 @@ +/* Profile counter helper to get PC from sigcontext. OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +#ifndef _SIGCONTEXTINFO_H +#define _SIGCONTEXTINFO_H + +static inline uintptr_t +sigcontext_get_pc (const ucontext_t *ctx) +{ +return ctx->uc_mcontext.__pc; +} + +#endif /* _SIGCONTEXTINFO_H */ sysdeps/unix/sysv/linux/or1k/swapcontext.S new file +116
-0@@ -0,0 +1,116 @@ +/* Swap two contexts. OpenRISC version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <https://www.gnu.org/licenses/>. */ + +#include <sysdep.h> +#include "ucontext_i.h" + +/* int swapcontext (ucontext_t *oucp, const ucontext_t *ucp) */ + .text +ENTRY(__swapcontext) + + /* Same as getcontext. */ + /* Store r1, the stack pointer. */ + l.sw (UCONTEXT_MCONTEXT + 1*4)(r3), r1 + /* Store r2, the frame pointer. */ + l.sw (UCONTEXT_MCONTEXT + 2*4)(r3), r2 + /* Store r9, the link register. */ + l.sw (UCONTEXT_MCONTEXT + 9*4)(r3), r9 + /* Store r9 to reg[11] too, as we need two links for makecontext. */ + l.sw (UCONTEXT_MCONTEXT + 11*4)(r3), r9 + /* Store r10, the TLS register. */ + l.sw (UCONTEXT_MCONTEXT + 10*4)(r3), r10 + /* Store r14-r30 even, callee saved registers. */ + l.sw (UCONTEXT_MCONTEXT + 14*4)(r3), r14 + l.sw (UCONTEXT_MCONTEXT + 16*4)(r3), r16 + l.sw (UCONTEXT_MCONTEXT + 18*4)(r3), r18 + l.sw (UCONTEXT_MCONTEXT + 20*4)(r3), r20 + l.sw (UCONTEXT_MCONTEXT + 22*4)(r3), r22 + l.sw (UCONTEXT_MCONTEXT + 24*4)(r3), r24 + l.sw (UCONTEXT_MCONTEXT + 26*4)(r3), r26 + l.sw (UCONTEXT_MCONTEXT + 28*4)(r3), r28 + l.sw (UCONTEXT_MCONTEXT + 30*4)(r3), r30 + + /* Store ucp to non-argument syscall preserved register. */ + l.ori r30, r4, 0 + + /* Get signal mask. */ + /* rt_sigprocmask (SIG_BLOCK, NULL, &ucp->uc_sigmask, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.addi r5, r3, UCONTEXT_SIGMASK + l.ori r4, r0, 0 + l.ori r3, r0, SIG_BLOCK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Same as setcontext. */ + + /* Restore signal mask. */ + /* rt_sigprocmask (SIG_SETMASK, &ucp->uc_sigmask, NULL, _NSIG8) */ + l.ori r6, r0, _NSIG8 + l.ori r5, r0, 0 + l.addi r4, r30, UCONTEXT_SIGMASK + l.ori r3, r0, SIG_SETMASK + l.ori r11, r0, SYS_ify (rt_sigprocmask) + /* Do the syscall. */ + l.sys 1 + l.nop + + /* if -4096 < ret < 0 holds, it's an error */ + l.sfgeui r11, 0xf001 + l.bf 1f + l.nop + + /* Restore argument registers, for the makecontext case. */ + l.lwz r3, (UCONTEXT_MCONTEXT + 3*4)(r30) + l.lwz r4, (UCONTEXT_MCONTEXT + 4*4)(r30) + l.lwz r5, (UCONTEXT_MCONTEXT + 5*4)(r30) + l.lwz r6, (UCONTEXT_MCONTEXT + 6*4)(r30) + l.lwz r7, (UCONTEXT_MCONTEXT + 7*4)(r30) + l.lwz r8, (UCONTEXT_MCONTEXT + 8*4)(r30) + + /* Restore registers stored in getcontext. */ + l.lwz r1, (UCONTEXT_MCONTEXT + 1*4)(r30) + l.lwz r2, (UCONTEXT_MCONTEXT + 2*4)(r30) + l.lwz r9, (UCONTEXT_MCONTEXT + 9*4)(r30) + l.lwz r10, (UCONTEXT_MCONTEXT + 10*4)(r30) + l.lwz r11, (UCONTEXT_MCONTEXT + 11*4)(r30) + l.lwz r14, (UCONTEXT_MCONTEXT + 14*4)(r30) + l.lwz r16, (UCONTEXT_MCONTEXT + 16*4)(r30) + l.lwz r18, (UCONTEXT_MCONTEXT + 18*4)(r30) + l.lwz r20, (UCONTEXT_MCONTEXT + 20*4)(r30) + l.lwz r22, (UCONTEXT_MCONTEXT + 22*4)(r30) + l.lwz r24, (UCONTEXT_MCONTEXT + 24*4)(r30) + l.lwz r26, (UCONTEXT_MCONTEXT + 26*4)(r30) + l.lwz r28, (UCONTEXT_MCONTEXT + 28*4)(r30) + l.lwz r30, (UCONTEXT_MCONTEXT + 30*4)(r30) + + l.jr r11 + l.ori r11, r0, 0 + +1: l.j __syscall_error + l.ori r3, r11, 0 + +END (__swapcontext) +weak_alias (__swapcontext, swapcontext)sysdeps/unix/sysv/linux/or1k/sys/ucontext.h new file +53
-0@@ -0,0 +1,53 @@ +/* ucontext_t definition, OpenRISC version. +Copyright (C) 2021 Free Software Foundation, Inc. +This file is part of the GNU C Library. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +The GNU C Library 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 +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with the GNU C Library; if not, see +<https://www.gnu.org/licenses/>. */ + +/* System V/OpenRISC compliant context switching support. */ + +#ifndef _SYS_UCONTEXT_H +#define _SYS_UCONTEXT_H 1 + +#include <features.h> + +#include <bits/types/sigset_t.h> +#include <bits/types/stack_t.h> + +/* Number of general registers. */ +#define __NGREG 32 +#ifdef __USE_MISC +# define NGREG __NGREG +#endif + +/* Context to describe whole processor state. */ +typedef struct + { +unsigned long int __gprs[__NGREG]; +unsigned long int __pc; +unsigned long int __sr; + }mcontext_t ; + +/* Userlevel context. */ +typedef struct ucontext_t + { +unsigned long int __uc_flags; +struct ucontext_t *uc_link; +stack_t uc_stack; +mcontext_t uc_mcontext; +sigset_t uc_sigmask; + }ucontext_t ; + +#endif /* sys/ucontext.h */ sysdeps/unix/sysv/linux/or1k/sys/user.h new file +1
-0@@ -0,0 +1 @@ +/* This file is not needed, but in practice gdb might try to include it. */ sysdeps/unix/sysv/linux/or1k/ucontext_i.sym new file +26
-0@@ -0,0 +1,26 @@ +#include <inttypes.h> +#include <signal.h> +#include <stddef.h> +#include <sys/ucontext.h> + +-- Constants used by the rt_sigprocmask call. + +SIG_BLOCK +SIG_SETMASK + +_NSIG8 (_NSIG / 8) + +-- Offsets of the fields in the ucontext_t structure. +#define ucontext(member) offsetof (ucontext_t, member) +#define stack(member) ucontext (uc_stack.member) + +UCONTEXT_LINK ucontext (uc_link) +UCONTEXT_STACK ucontext (uc_stack) +UCONTEXT_MCONTEXT ucontext (uc_mcontext) +UCONTEXT_SIGMASK ucontext (uc_sigmask) + +STACK_SP stack (ss_sp) +STACK_SIZE stack (ss_size) +STACK_FLAGS stack (ss_flags) + +UCONTEXT_SIZE sizeof (ucontext_t)
PATCH v3 10/13 or1k: ABI lists
In reply to Stafford Horne--- sysdeps/unix/sysv/linux/or1k/c++-types.data | 67 + sysdeps/unix/sysv/linux/or1k/ld.abilist | 5 + .../sysv/linux/or1k/libBrokenLocale.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libanl.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libc.abilist | 2122 +++++++++++++++++ .../sysv/linux/or1k/libc_malloc_debug.abilist | 26 + sysdeps/unix/sysv/linux/or1k/libcrypt.abilist | 2 + sysdeps/unix/sysv/linux/or1k/libdl.abilist | 0 sysdeps/unix/sysv/linux/or1k/libm.abilist | 759 ++++++ sysdeps/unix/sysv/linux/or1k/libnsl.abilist | 121 + .../unix/sysv/linux/or1k/libpthread.abilist | 0 .../unix/sysv/linux/or1k/libresolv.abilist | 55 + sysdeps/unix/sysv/linux/or1k/librt.abilist | 0 .../unix/sysv/linux/or1k/libthread_db.abilist | 40 + sysdeps/unix/sysv/linux/or1k/libutil.abilist | 1 + sysdeps/unix/sysv/linux/or1k/localplt.data | 14 + 16 files changed, 3214 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/or1k/c++-types.data create mode 100644 sysdeps/unix/sysv/linux/or1k/ld.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libanl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc_malloc_debug.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libcrypt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libdl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libm.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libnsl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libpthread.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libresolv.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/librt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libthread_db.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libutil.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/localplt.data
sysdeps/unix/sysv/linux/or1k/c++-types.data new file +67 -0
@@ -0,0 +1,67 @@ +blkcnt64_t:x +blkcnt_t:x +blksize_t:i +caddr_t:Pc +clockid_t:i +clock_t:l +daddr_t:i +dev_t:y +fd_mask:l +fsblkcnt64_t:y +fsblkcnt_t:y +fsfilcnt64_t:y +fsfilcnt_t:y +fsid_t:8__fsid_t +gid_t:j +id_t:j +ino64_t:y +ino_t:y +int16_t:s +int32_t:i +int64_t:x +int8_t:a +intptr_t:i +key_t:i +loff_t:x +mode_t:j +nlink_t:j +off64_t:x +off_t:x +pid_t:i +pthread_attr_t:14pthread_attr_t +pthread_barrier_t:17pthread_barrier_t +pthread_barrierattr_t:21pthread_barrierattr_t +pthread_cond_t:14pthread_cond_t +pthread_condattr_t:18pthread_condattr_t +pthread_key_t:j +pthread_mutex_t:15pthread_mutex_t +pthread_mutexattr_t:19pthread_mutexattr_t +pthread_once_t:i +pthread_rwlock_t:16pthread_rwlock_t +pthread_rwlockattr_t:20pthread_rwlockattr_t +pthread_spinlock_t:i +pthread_t:m +quad_t:x +register_t:i +rlim64_t:y +rlim_t:y +sigset_t:10__sigset_t +size_t:j +socklen_t:j +ssize_t:i +suseconds_t:x +time_t:x +u_char:h +uid_t:j +uint:j +u_int:j +u_int16_t:t +u_int32_t:j +u_int64_t:y +u_int8_t:h +ulong:m +u_long:m +u_quad_t:y +useconds_t:j +ushort:t +u_short:t
sysdeps/unix/sysv/linux/or1k/ld.abilist new file +5 -0
@@ -0,0 +1,5 @@ +GLIBC_2.35 __libc_stack_end D 0x4 +GLIBC_2.35 __stack_chk_guard D 0x4 +GLIBC_2.35 __tls_get_addr F +GLIBC_2.35 _dl_mcount F +GLIBC_2.35 _r_debug D 0x14
sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist new file +1 -0
@@ -0,0 +1 @@ +GLIBC_2.35 __ctype_get_mb_cur_max F
sysdeps/unix/sysv/linux/or1k/libanl.abilist new file +1 -0
@@ -0,0 +1 @@ +GLIBC_2.35 __libanl_version_placeholder F
sysdeps/unix/sysv/linux/or1k/libc.abilist new file +2122 -0
2,122 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/libc_malloc_debug.abilist new file +26 -0
@@ -0,0 +1,26 @@ +GLIBC_2.35 __free_hook D 0x4 +GLIBC_2.35 __malloc_hook D 0x4 +GLIBC_2.35 __memalign_hook D 0x4 +GLIBC_2.35 __realloc_hook D 0x4 +GLIBC_2.35 aligned_alloc F +GLIBC_2.35 calloc F +GLIBC_2.35 free F +GLIBC_2.35 mallinfo F +GLIBC_2.35 mallinfo2 F +GLIBC_2.35 malloc F +GLIBC_2.35 malloc_info F +GLIBC_2.35 malloc_stats F +GLIBC_2.35 malloc_trim F +GLIBC_2.35 malloc_usable_size F +GLIBC_2.35 mallopt F +GLIBC_2.35 mcheck F +GLIBC_2.35 mcheck_check_all F +GLIBC_2.35 mcheck_pedantic F +GLIBC_2.35 memalign F +GLIBC_2.35 mprobe F +GLIBC_2.35 mtrace F +GLIBC_2.35 muntrace F +GLIBC_2.35 posix_memalign F +GLIBC_2.35 pvalloc F +GLIBC_2.35 realloc F +GLIBC_2.35 valloc F
sysdeps/unix/sysv/linux/or1k/libcrypt.abilist new file +2 -0
@@ -0,0 +1,2 @@ +GLIBC_2.35 crypt F +GLIBC_2.35 crypt_r F
sysdeps/unix/sysv/linux/or1k/libdl.abilist new file +0 -0
sysdeps/unix/sysv/linux/or1k/libm.abilist new file +759 -0
759 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/libnsl.abilist new file +121 -0
17 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/libpthread.abilist new file +0 -0
sysdeps/unix/sysv/linux/or1k/libresolv.abilist new file +55 -0
55 lines not on this page · raw message
sysdeps/unix/sysv/linux/or1k/librt.abilist new file +0 -0
sysdeps/unix/sysv/linux/or1k/libthread_db.abilist new file +40 -0
Lines of this file are not shown. View the raw message.
sysdeps/unix/sysv/linux/or1k/libutil.abilist new file +1 -0
Lines of this file are not shown. View the raw message.
sysdeps/unix/sysv/linux/or1k/localplt.data new file +14 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.31.1
Part of the diff is not shown here. View the raw message.
PATCH v3 10/13 or1k: ABI lists
sysdeps/unix/sysv/linux/or1k/ld.abilist line 5
Quoted 11 lines · Stafford Horne via Libc-alpha
sysdeps/unix/sysv/linux/or1k/ld.abilist new file +5
-0@@ -0,0 +1,5 @@ +GLIBC_2.35 __libc_stack_end D 0x4 +GLIBC_2.35 __stack_chk_guard D 0x4 +GLIBC_2.35 __tls_get_addr F +GLIBC_2.35 _dl_mcount F +GLIBC_2.35 _r_debug D 0x14
You will need to regenerate it to include the rseq symbols:
GLIBC_2.35 __rseq_flags D 0x4
GLIBC_2.35 __rseq_offset D 0x4
GLIBC_2.35 __rseq_size D 0x4
Quoted 13 lines
sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist new file +1
-0@@ -0,0 +1 @@ +GLIBC_2.35 __ctype_get_mb_cur_max Fsysdeps/unix/sysv/linux/or1k/libanl.abilist new file +0
-0
sysdeps/unix/sysv/linux/or1k/libanl.abilist line 1
Quoted 1 line
sysdeps/unix/sysv/linux/or1k/libanl.abilist new file +1
-0@@ -0,0 +1 @@ +GLIBC_2.35 __libanl_version_placeholder F
This does seems right, or1k should not require the placeholder. I think we are missing a SHLIB_COMPAT on resolv/libanl-compat.c:
resolv/libanl-compat.c +2 -0
@@ -30,6 +30,8 @@ __libanl_version_placeholder_1 (void) { } +# if SHLIB_COMPAT (libanl,GLIBC_2_2_3 ,GLIBC_2_34 )compat_symbol (libanl, __libanl_version_placeholder_1, __libanl_version_placeholder,GLIBC_2_2_3 ); +# endif #endif
sysdeps/unix/sysv/linux/or1k/libutil.abilist line 1
Quoted 7 lines
sysdeps/unix/sysv/linux/or1k/libutil.abilist new file +1
-0@@ -0,0 +1 @@ +GLIBC_2.35 __libutil_version_placeholder F
This also does not seems right, libutil-compat will only built for have-GLIBC_2.33, which is not the case.
PATCH v3 10/13 or1k: ABI lists
Quoted 18 lines · Adhemerval Zanella
sysdeps/unix/sysv/linux/or1k/ld.abilist line 5
Quoted 11 lines · Stafford Horne via Libc-alpha
sysdeps/unix/sysv/linux/or1k/ld.abilist new file +5
-0@@ -0,0 +1,5 @@ +GLIBC_2.35 __libc_stack_end D 0x4 +GLIBC_2.35 __stack_chk_guard D 0x4 +GLIBC_2.35 __tls_get_addr F +GLIBC_2.35 _dl_mcount F +GLIBC_2.35 _r_debug D 0x14You will need to regenerate it to include the rseq symbols:
Quoted 3 lines
GLIBC_2.35
__rseq_flagsD0x4
GLIBC_2.35__rseq_offsetD0x4
GLIBC_2.35__rseq_sizeD0x4
OK, I will regenerate, this patch series was generated from before these symbols were introduced.
Quoted 23 lines
Quoted 13 lines
sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist new file +1
-0@@ -0,0 +1 @@ +GLIBC_2.35 __ctype_get_mb_cur_max Fsysdeps/unix/sysv/linux/or1k/libanl.abilist new file +0
-0sysdeps/unix/sysv/linux/or1k/libanl.abilist line 1
Quoted 1 line
sysdeps/unix/sysv/linux/or1k/libanl.abilist new file +1
-0@@ -0,0 +1 @@ +GLIBC_2.35 __libanl_version_placeholder FThis does seems right, or1k should not require the placeholder. I think we are missing a
SHLIB_COMPATonresolv/libanl-compat.c:resolv/libanl-compat.c +0
-0
resolv/libanl-compat.c __libanl_version_placeholder_1 (void) · line 37
Quoted 8 lines
resolv/libanl-compat.c +2
-0@@ -30,6 +30,8 @@ __libanl_version_placeholder_1 (void) { } +# if SHLIB_COMPAT (libanl,GLIBC_2_2_3 ,GLIBC_2_34 )compat_symbol (libanl, __libanl_version_placeholder_1, __libanl_version_placeholder,GLIBC_2_2_3 ); +# endif #endif
I confirm this fixes the issue.
Quoted 10 lines
sysdeps/unix/sysv/linux/or1k/libutil.abilist line 1
Quoted 7 lines
sysdeps/unix/sysv/linux/or1k/libutil.abilist new file +1
-0@@ -0,0 +1 @@ +GLIBC_2.35 __libutil_version_placeholder FThis also does not seems right, libutil-compat will only built for have-GLIBC_2.33, which is not the case.
I think this file is leftover now that libutil is just an libutil.a update-abi generates nothing.
I have just deleted the file. check-abi seems to work ok.
Note, I aldo delete the other blank abilist files. So:
deleted: sysdeps/unix/sysv/linux/or1k/libanl.abilist
deleted: sysdeps/unix/sysv/linux/or1k/libdl.abilist
deleted: sysdeps/unix/sysv/linux/or1k/libpthread.abilist
deleted: sysdeps/unix/sysv/linux/or1k/librt.abilist
deleted: sysdeps/unix/sysv/linux/or1k/libutil.abilist-Stafford
PATCH v3 11/13 or1k: Build Infrastructure
In reply to Stafford HorneHere we define the minumum linux kernel version at 5.4.0, as that is the long term support version where 32-bit architectures start to support 64-bit time API's. The OpenRISC kernel had some bugs up until version 5.8 which caused issues with glibc fork/clone, they have been backported to 5.4 but not previous versions.
--- sysdeps/or1k/Implies | 3 ++ sysdeps/or1k/Makefile | 7 +++++ sysdeps/or1k/nofpu/Implies | 1 + sysdeps/or1k/nptl/Makefile | 21 +++++++++++++ sysdeps/or1k/preconfigure | 34 +++++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/Implies | 3 ++ sysdeps/unix/sysv/linux/or1k/Makefile | 12 ++++++++ sysdeps/unix/sysv/linux/or1k/configure | 4 +++ sysdeps/unix/sysv/linux/or1k/configure.ac | 4 +++ sysdeps/unix/sysv/linux/or1k/shlib-versions | 2 ++ 10 files changed, 91 insertions(+) create mode 100644 sysdeps/or1k/Implies create mode 100644 sysdeps/or1k/Makefile create mode 100644 sysdeps/or1k/nofpu/Implies create mode 100644 sysdeps/or1k/nptl/Makefile create mode 100644 sysdeps/or1k/preconfigure create mode 100644 sysdeps/unix/sysv/linux/or1k/Implies create mode 100644 sysdeps/unix/sysv/linux/or1k/Makefile create mode 100644 sysdeps/unix/sysv/linux/or1k/configure create mode 100644 sysdeps/unix/sysv/linux/or1k/configure.ac create mode 100644 sysdeps/unix/sysv/linux/or1k/shlib-versions
sysdeps/or1k/Implies new file +3 -0
@@ -0,0 +1,3 @@ +wordsize-32 +ieee754/dbl-64 +ieee754/flt-32
sysdeps/or1k/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +ASFLAGS-.os += -fPIC + +ifeq ($(subdir),elf) +# Extra shared linker files to link only into dl-allobjs.so. +sysdep-rtld-routines += dl-start +endif +
sysdeps/or1k/nofpu/Implies new file +1 -0
@@ -0,0 +1 @@ +ieee754/soft-fp
sysdeps/or1k/nptl/Makefile new file +21 -0
@@ -0,0 +1,21 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library. If not, see +# <https://www.gnu.org/licenses/>. + +ifeq ($(subdir),csu) +gen-as-const-headers += tcb-offsets.sym +endif
sysdeps/or1k/preconfigure new file +34 -0
@@ -0,0 +1,34 @@ +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +case "$machine" in +or1k*) + base_machine=or1k + machine=or1k + + with_fp_cond="defined __or1k_hard_float__" + ;; +esac +
sysdeps/unix/sysv/linux/or1k/Implies new file +3 -0
@@ -0,0 +1,3 @@ +or1k/nptl +unix/sysv/linux/generic/wordsize-32 +unix/sysv/linux/generic
sysdeps/unix/sysv/linux/or1k/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +ifeq ($(subdir),misc) + sysdep_routines += prctl or1k_clone +endif + +ifeq ($(subdir),stdlib) +gen-as-const-headers += ucontext_i.sym +endif + +# pull in __syscall_error routine +libpthread-routines += sysdep +librt-routines += sysdep +
sysdeps/unix/sysv/linux/or1k/configure new file +4 -0
@@ -0,0 +1,4 @@ +# This file is generated from configure.ac by Autoconf. DO NOT EDIT! + # Local configure fragment for sysdeps/unix/sysv/linux/or1k. + +arch_minimum_kernel=5.4.0
sysdeps/unix/sysv/linux/or1k/configure.ac new file +4 -0
@@ -0,0 +1,4 @@ +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. +# Local configure fragment for sysdeps/unix/sysv/linux/or1k. + +arch_minimum_kernel=5.4.0
sysdeps/unix/sysv/linux/or1k/shlib-versions new file +2 -0
@@ -0,0 +1,2 @@ +DEFAULT GLIBC_2.35 +ld=ld-linux-or1k.so.1
Signature · 1 line
2.31.1
PATCH v3 11/13 or1k: Build Infrastructure
Quoted 5 lines · Stafford Horne via Libc-alpha
Here we define the minumum linux kernel version at 5.4.0, as that is the long term support version where 32-bit architectures start to support 64-bit time API's. The OpenRISC kernel had some bugs up until version 5.8 which caused issues with glibc fork/clone, they have been backported to 5.4 but not previous versions.
Some comments below, the rest looks ok.
Quoted 69 lines
--- sysdeps/or1k/Implies | 3 ++ sysdeps/or1k/Makefile | 7 +++++ sysdeps/or1k/nofpu/Implies | 1 + sysdeps/or1k/nptl/Makefile | 21 +++++++++++++ sysdeps/or1k/preconfigure | 34 +++++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/Implies | 3 ++ sysdeps/unix/sysv/linux/or1k/Makefile | 12 ++++++++ sysdeps/unix/sysv/linux/or1k/configure | 4 +++ sysdeps/unix/sysv/linux/or1k/configure.ac | 4 +++ sysdeps/unix/sysv/linux/or1k/shlib-versions | 2 ++ 10 files changed, 91 insertions(+) create mode 100644 sysdeps/or1k/Implies create mode 100644 sysdeps/or1k/Makefile create mode 100644 sysdeps/or1k/nofpu/Implies create mode 100644 sysdeps/or1k/nptl/Makefile create mode 100644 sysdeps/or1k/preconfigure create mode 100644 sysdeps/unix/sysv/linux/or1k/Implies create mode 100644 sysdeps/unix/sysv/linux/or1k/Makefile create mode 100644 sysdeps/unix/sysv/linux/or1k/configure create mode 100644 sysdeps/unix/sysv/linux/or1k/configure.ac create mode 100644 sysdeps/unix/sysv/linux/or1k/shlib-versionssysdeps/or1k/Implies new file +3
-0@@ -0,0 +1,3 @@ +wordsize-32 +ieee754/dbl-64 +ieee754/flt-32sysdeps/or1k/Makefile new file +7
-0@@ -0,0 +1,7 @@ +ASFLAGS-.os += -fPIC + +ifeq ($(subdir),elf) +# Extra shared linker files to link only into dl-allobjs.so. +sysdep-rtld-routines += dl-start +endif +sysdeps/or1k/nofpu/Implies new file +1
-0@@ -0,0 +1 @@ +ieee754/soft-fpsysdeps/or1k/nptl/Makefile new file +11
-0@@ -0,0 +1,21 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of
sysdeps/or1k/nptl/Makefile line 21
Quoted 10 lines
sysdeps/or1k/nptl/Makefile new file +10
-0+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library. If not, see +# <https://www.gnu.org/licenses/>. + +ifeq ($(subdir),csu) +gen-as-const-headers += tcb-offsets.sym +endif
I think you do not need this anymore since 691d9ae9e6f3bcb.
Quoted 55 lines
sysdeps/or1k/preconfigure new file +34
-0@@ -0,0 +1,34 @@ +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +case "$machine" in +or1k*) + base_machine=or1k + machine=or1k + + with_fp_cond="defined __or1k_hard_float__" + ;; +esac +sysdeps/unix/sysv/linux/or1k/Implies new file +3
-0@@ -0,0 +1,3 @@ +or1k/nptl +unix/sysv/linux/generic/wordsize-32 +unix/sysv/linux/genericsysdeps/unix/sysv/linux/or1k/Makefile new file +0
-0
sysdeps/unix/sysv/linux/or1k/Makefile line 2
Quoted 2 lines
sysdeps/unix/sysv/linux/or1k/Makefile new file +2
-0@@ -0,0 +1,12 @@ +ifeq ($(subdir),misc) + sysdep_routines += prctl or1k_clone
The indentations seems off here and I think there is no need of prctl.
Quoted 38 lines
sysdeps/unix/sysv/linux/or1k/Makefile new file +10
-0+endif + +ifeq ($(subdir),stdlib) +gen-as-const-headers += ucontext_i.sym +endif + +# pull in __syscall_error routine +libpthread-routines += sysdep +librt-routines += sysdep +sysdeps/unix/sysv/linux/or1k/configure new file +4
-0@@ -0,0 +1,4 @@ +# This file is generated from configure.ac by Autoconf. DO NOT EDIT! + # Local configure fragment for sysdeps/unix/sysv/linux/or1k. + +arch_minimum_kernel=5.4.0sysdeps/unix/sysv/linux/or1k/configure.ac new file +4
-0@@ -0,0 +1,4 @@ +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. +# Local configure fragment for sysdeps/unix/sysv/linux/or1k. + +arch_minimum_kernel=5.4.0sysdeps/unix/sysv/linux/or1k/shlib-versions new file +2
-0@@ -0,0 +1,2 @@ +DEFAULT GLIBC_2.35 +ld=ld-linux-or1k.so.1
PATCH v3 11/13 or1k: Build Infrastructure
Quoted 84 lines · Adhemerval Zanella
Quoted 5 lines · Stafford Horne via Libc-alpha
Here we define the minumum linux kernel version at 5.4.0, as that is the long term support version where 32-bit architectures start to support 64-bit time API's. The OpenRISC kernel had some bugs up until version 5.8 which caused issues with glibc fork/clone, they have been backported to 5.4 but not previous versions.
Some comments below, the rest looks ok.
Quoted 73 lines
--- sysdeps/or1k/Implies | 3 ++ sysdeps/or1k/Makefile | 7 +++++ sysdeps/or1k/nofpu/Implies | 1 + sysdeps/or1k/nptl/Makefile | 21 +++++++++++++ sysdeps/or1k/preconfigure | 34 +++++++++++++++++++++ sysdeps/unix/sysv/linux/or1k/Implies | 3 ++ sysdeps/unix/sysv/linux/or1k/Makefile | 12 ++++++++ sysdeps/unix/sysv/linux/or1k/configure | 4 +++ sysdeps/unix/sysv/linux/or1k/configure.ac | 4 +++ sysdeps/unix/sysv/linux/or1k/shlib-versions | 2 ++ 10 files changed, 91 insertions(+) create mode 100644 sysdeps/or1k/Implies create mode 100644 sysdeps/or1k/Makefile create mode 100644 sysdeps/or1k/nofpu/Implies create mode 100644 sysdeps/or1k/nptl/Makefile create mode 100644 sysdeps/or1k/preconfigure create mode 100644 sysdeps/unix/sysv/linux/or1k/Implies create mode 100644 sysdeps/unix/sysv/linux/or1k/Makefile create mode 100644 sysdeps/unix/sysv/linux/or1k/configure create mode 100644 sysdeps/unix/sysv/linux/or1k/configure.ac create mode 100644 sysdeps/unix/sysv/linux/or1k/shlib-versionssysdeps/or1k/Implies new file +3
-0@@ -0,0 +1,3 @@ +wordsize-32 +ieee754/dbl-64 +ieee754/flt-32sysdeps/or1k/Makefile new file +7
-0@@ -0,0 +1,7 @@ +ASFLAGS-.os += -fPIC + +ifeq ($(subdir),elf) +# Extra shared linker files to link only into dl-allobjs.so. +sysdep-rtld-routines += dl-start +endif +sysdeps/or1k/nofpu/Implies new file +1
-0@@ -0,0 +1 @@ +ieee754/soft-fpsysdeps/or1k/nptl/Makefile new file +15
-0@@ -0,0 +1,21 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library 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 +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public
Quoted 8 lines
sysdeps/or1k/nptl/Makefile line 21
Quoted 6 lines
sysdeps/or1k/nptl/Makefile new file +6
-0+# License along with the GNU C Library. If not, see +# <https://www.gnu.org/licenses/>. + +ifeq ($(subdir),csu) +gen-as-const-headers += tcb-offsets.sym +endifI think you do not need this anymore since
691d9ae9e6f3bcb.
Yes, I have removed it locally already.
Quoted 51 lines
Quoted 51 lines
sysdeps/or1k/preconfigure new file +34
-0@@ -0,0 +1,34 @@ +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# + +case "$machine" in +or1k*) + base_machine=or1k + machine=or1k + + with_fp_cond="defined __or1k_hard_float__" + ;; +esac +sysdeps/unix/sysv/linux/or1k/Implies new file +3
-0@@ -0,0 +1,3 @@ +or1k/nptl +unix/sysv/linux/generic/wordsize-32 +unix/sysv/linux/genericsysdeps/unix/sysv/linux/or1k/Makefile new file +0
-0
Quoted 8 lines
sysdeps/unix/sysv/linux/or1k/Makefile line 2
Quoted 6 lines
index 0000000000..be20320b2f
sysdeps/unix/sysv/linux/or1k/Makefile new file +2
-0@@ -0,0 +1,12 @@ +ifeq ($(subdir),misc) + sysdep_routines += prctl or1k_cloneThe indentations seems off here and I think there is no need of prctl.
OK.
Quoted 9 lines
sysdeps/unix/sysv/linux/or1k/Makefile line 11
Quoted 9 lines
sysdeps/unix/sysv/linux/or1k/Makefile new file +9
-0+endif + +ifeq ($(subdir),stdlib) +gen-as-const-headers += ucontext_i.sym +endif + +# pull in __syscall_error routine +libpthread-routines += sysdep +librt-routines += sysdep
Also, I don't think these are needed. I don't see them on new ports.
I think its after moving libpthread and librt into libc.
Quoted 28 lines
Quoted 28 lines
sysdeps/unix/sysv/linux/or1k/configure new file +4
-0@@ -0,0 +1,4 @@ +# This file is generated from configure.ac by Autoconf. DO NOT EDIT! + # Local configure fragment for sysdeps/unix/sysv/linux/or1k. + +arch_minimum_kernel=5.4.0sysdeps/unix/sysv/linux/or1k/configure.ac new file +4
-0@@ -0,0 +1,4 @@ +GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory. +# Local configure fragment for sysdeps/unix/sysv/linux/or1k. + +arch_minimum_kernel=5.4.0sysdeps/unix/sysv/linux/or1k/shlib-versions new file +2
-0@@ -0,0 +1,2 @@ +DEFAULT GLIBC_2.35 +ld=ld-linux-or1k.so.1
PATCH v3 12/13 build-many-glibcs.py: add OpenRISC support
In reply to Stafford Horne--- scripts/build-many-glibcs.py | 5 +++++ 1 file changed, 5 insertions(+)
scripts/build-many-glibcs.py +5 -0
@@ -334,6 +334,10 @@ class Context(object): 'ccopts': '-mabi=64'}]) self.add_config(arch='nios2', os_name='linux-gnu') + self.add_config(arch='or1k', + os_name='linux-gnu', + variant='soft', + gcc_cfg=['--with-multilib-list=mcmov']) self.add_config(arch='powerpc', os_name='linux-gnu', gcc_cfg=['--disable-multilib', '--enable-secureplt'],
@@ -1270,6 +1274,7 @@ def install_linux_headers(policy, cmdlist): 'microblaze': 'microblaze', 'mips': 'mips', 'nios2': 'nios2', + 'or1k': 'openrisc', 'powerpc': 'powerpc', 's390': 's390', 'riscv32': 'riscv',
Signature · 1 line
2.31.1
PATCH v3 12/13 build-many-glibcs.py: add OpenRISC support
Quoted 9 lines · Stafford Horne via Libc-alpha
--- scripts/build-many-glibcs.py | 5 +++++ 1 file changed, 5 insertions(+)scripts/build-many-glibcs.py +0
-0
scripts/build-many-glibcs.py class Context(object): · line 340
Quoted 7 lines
scripts/build-many-glibcs.py +4
-0@@ -334,6 +334,10 @@ class Context(object): 'ccopts': '-mabi=64'}]) self.add_config(arch='nios2', os_name='linux-gnu') + self.add_config(arch='or1k', + os_name='linux-gnu', + variant='soft', + gcc_cfg=['--with-multilib-list=mcmov'])
Why is this option required?
Quoted 11 lines
scripts/build-many-glibcs.py +1
-0self.add_config(arch='powerpc', os_name='linux-gnu', gcc_cfg=['--disable-multilib', '--enable-secureplt'],@@ -1270,6 +1274,7 @@ def install_linux_headers(policy, cmdlist): 'microblaze': 'microblaze', 'mips': 'mips', 'nios2': 'nios2', + 'or1k': 'openrisc', 'powerpc': 'powerpc', 's390': 's390', 'riscv32': 'riscv',
PATCH v3 12/13 build-many-glibcs.py: add OpenRISC support
Quoted 7 lines · Adhemerval Zanella
Quoted 4 lines · Stafford Horne via Libc-alpha
--- scripts/build-many-glibcs.py | 5 +++++ 1 file changed, 5 insertions(+)
Quoted 14 lines
scripts/build-many-glibcs.py class Context(object): · line 340
Quoted 12 lines
scripts/build-many-glibcs.py +4
-0@@ -334,6 +334,10 @@ class Context(object): 'ccopts': '-mabi=64'}]) self.add_config(arch='nios2', os_name='linux-gnu') + self.add_config(arch='or1k', + os_name='linux-gnu', + variant='soft', + gcc_cfg=['--with-multilib-list=mcmov'])Why is this option required?
The default is to build with multilib-list mcmov,msoft-mul,msoft-div. Which would generate 3 toolchains.
To make the build faster I reduced it to the mcmov (support conditional move instructions).
I could change to run with --disable-multilib, but enabling cmov is usually always wanted.
Quoted 11 lines
Quoted 11 lines
scripts/build-many-glibcs.py +1
-0self.add_config(arch='powerpc', os_name='linux-gnu', gcc_cfg=['--disable-multilib', '--enable-secureplt'],@@ -1270,6 +1274,7 @@ def install_linux_headers(policy, cmdlist): 'microblaze': 'microblaze', 'mips': 'mips', 'nios2': 'nios2', + 'or1k': 'openrisc', 'powerpc': 'powerpc', 's390': 's390', 'riscv32': 'riscv',
PATCH v3 13/13 Documentation for OpenRISC port
In reply to Stafford HorneOpenRISC architecture specification:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdf
Currently the port as of the 2021-12-07 rebasing has the following test failures:
FAIL: timezone/tst-tzset # Not enough space to create 4GiB file
FAIL: elf/tst-bz15311 # dynamic ld sort order diff
Writing credits for the port are:
Stafford Horne <[email protected]>
Christian Svensson <[email protected]>
--- NEWS | 4 ++++ README | 1 + 2 files changed, 5 insertions(+)
NEWS +4 -0
@@ -485,6 +485,10 @@ Major new features: The latest GCC available at this time (10.2) does not support this level of fortification. +* Support for OpenRISC on Linux has been added. + + The OpenRISC pore requires at least Linux 5.4, GCC 11 and binutils 2.35. + Deprecated and removed features, and other changes affecting compatibility: * The mallinfo function is marked deprecated. Callers should call
README +1 -0
@@ -35,6 +35,7 @@ The GNU C Library supports these configurations for using Linux kernels: microblaze*-*-linux-gnu mips-*-linux-gnu mips64-*-linux-gnu + or1k-*-linux-gnu powerpc-*-linux-gnu Hardware or software floating point, BE only. powerpc64*-*-linux-gnu Big-endian and little-endian. s390-*-linux-gnu
Signature · 1 line
2.31.1
PATCH v3 13/13 Documentation for OpenRISC port
Quoted 23 lines · Stafford Horne via Libc-alpha
OpenRISC architecture specification:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdf
Currently the port as of the 2021-12-07 rebasing has the following test failures:
FAIL: timezone/tst-tzset # Not enough space to create 4GiB file
FAIL: elf/tst-bz15311 # dynamic ld sort order diffWriting credits for the port are:
Stafford Horne <[email protected]>
Christian Svensson <[email protected]>> ---NEWS | 4 ++++ README | 1 + 2 files changed, 5 insertions(+)NEWS +0
-0
NEWS Major new features: · line 488
Quoted 4 lines
NEWS +1
-0@@ -485,6 +485,10 @@ Major new features: The latest GCC available at this time (10.2) does not support this level of fortification. +* Support for OpenRISC on Linux has been added.
I think it would be useful to add only soft-float is currently supported.
Quoted 17 lines
NEWS +3
-0+ + The OpenRISC pore requires at least Linux 5.4, GCC 11 and binutils 2.35. +> Deprecated and removed features, and other changes affecting compatibility: * The mallinfo function is marked deprecated. Callers should callREADME +1
-0@@ -35,6 +35,7 @@ The GNU C Library supports these configurations for using Linux kernels: microblaze*-*-linux-gnu mips-*-linux-gnu mips64-*-linux-gnu + or1k-*-linux-gnu powerpc-*-linux-gnu Hardware or software floating point, BE only. powerpc64*-*-linux-gnu Big-endian and little-endian. s390-*-linux-gnu
v3 cover Glibc OpenRISC port
In reply to Stafford HorneQuoted 42 lines · Stafford Horne via Libc-alpha
This is the OpenRISC port for glibc that I have been working on.
Changes since v2:
- Fixed suggestions from Joseph Myers:
- Fix comment style, and description on top of each file
- Make sure macros have parentheses when needed,
- Bump required kernel down to 5.4.0 and document
- Regeneratearch-syscall.h
- Fixed suggestions from Adhemerval:
- Removekernel_stat.h
- Just setMMAP2_PAGE_UNITto 8K
- Removeioctl.candsyscall.cfiles
- Update TCB alignment to 32 bytesChanges since v1:
- Update api's as suggested by Florian
- Remove hard float support
- Updates to get all tests passing
- Split patch into managable bits similar to recent ARC portDocumentation:
Architecture / ABI docs:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdfTest Results:
build-many-glibcs.py:PASS with mainline ang gcc-11.
Full test suite:
The full suite is running using the gcc-11 branch of GCC, mainline shows issues with math soft-fp.
Note, there are a few more failures compared to before, this is due to me running with a timeout of 30 vs usual 300. It allows the tests to complete faster, but I get a few more timeouts. There were 15 timeouts which I confirm do work if I increase the timeoutfactor. The 2 real failures marked with * below.
Quoted 4 lines
# test start: 2021-12-08T19:59:00+09:00# failures FAIL:*elf/tst-bz15311
This seems to be a real issue, the output shows the new sorting algorithm seems not be enabled (the output shows the destructor order for dynamic_sort=1). We need to figure out what is happening here.
Quoted 8 lines
FAIL: locale/tst-localedef-path-norm
FAIL: malloc/tst-dynarray-fail
FAIL: malloc/tst-dynarray-fail-mem
FAIL: nptl/tst-mutex10
FAIL: nss/tst-nss-files-hosts-getent
FAIL: nss/tst-nss-files-hosts-multi
FAIL: posix/tst-regcomp-truncated
FAIL: stdio-common/tst-vfprintf-width-prec
Quoted 8 lines
FAIL: stdio-common/tst-vfprintf-width-prec-alloc
FAIL: stdio-common/tst-vfprintf-width-prec-mem
FAIL: string/test-memcpy
FAIL: string/test-memcpy-large
FAIL: string/test-mempcpy
FAIL: string/tst-cmp
FAIL: support/tst-support_blob_repeat FAIL:*timezone/tst-tzset
It seems the testing file system does not support sparse files or at least has some limits of the file size and support_descriptor_supports_holes is no deteting it.
I think we should use a large write_offset and block_headroom, maybe something larger than 32-bit offset to actually check it. Could you check if increasing both values does make the test unsupported.
Quoted 12 lines
# test finish: 2021-12-10T22:04:56+09:00 # test duration: 2 days 2 hours 5 minutes and 56 seconds # test for file: tests.sum # test wrapper: /home/shorne/work/gnu-toolchain/glibc/scripts/cross-test-ssh.sh --timeoutfactor 30 10.0.0.5# summary 17 FAIL 4063 PASS 28 UNSUPPORTED 18 XFAIL
Quoted 3 lines
tst-bz15311.out: https://gist.github.com/5a5dacaeef1eac1f2f5d89701d14c0ad tst-tzset.out: https://gist.github.com/b3a548d82cfc9367905e115821a52754 tests.sum: https://gist.github.com/f85a81012c8329b9a95370a30c7b27fe
Since 8d1927d8dc5aad0f01c929123086be3a5b799d18 it will need an additional fix to correctly build glibc:
sysdeps/or1k/nptl/tls.h +2 -0
@@ -150,6 +150,8 @@ register tcbhead_t *__thread_self __asm__("r10");# define DB_THREAD_SELF \ REGISTER (32, 32, 10 * 4, - TLS_INIT_TCB_SIZE - TLS_PRE_TCB_SIZE) +# include <tcb-access.h> +/* Access to data in the thread descriptor is easy. */ #define THREAD_GETMEM (descr, member) \
With the above fix I can bootstrap a compiler with build-many-glibcs.py.
Quoted 177 lines
Stafford Horne (13):
elf: Add reloc for OpenRISC
linux/syscalls: Addor1k_atomicsyscall for OpenRISC
or1k: ABI Implementation
or1k: startup and dynamic linking code
or1k: Thread Local Storage support
or1k: Atomics and Locking primitives
or1k: math soft float support
or1k: Linux Syscall Interface
or1k: Linux ABI
or1k: ABI lists
or1k: Build Infrastructurebuild-many-glibcs.py: add OpenRISC support Documentation for OpenRISC portNEWS | 4 + README | 1 + elf/elf.h | 37 + scripts/build-many-glibcs.py | 5 + sysdeps/or1k/Implies | 3 + sysdeps/or1k/Makefile | 7 + sysdeps/or1k/__longjmp.S | 55 + sysdeps/or1k/atomic-machine.h | 79 + sysdeps/or1k/bits/endianness.h | 11 + sysdeps/or1k/bits/fenv.h | 69 + sysdeps/or1k/bits/link.h | 51 + sysdeps/or1k/bits/setjmp.h | 32 + sysdeps/or1k/bsd-_setjmp.S | 1 + sysdeps/or1k/bsd-setjmp.S | 1 + sysdeps/or1k/dl-machine.h | 323 +++ sysdeps/or1k/dl-start.S | 98 + sysdeps/or1k/dl-tls.h | 27 + sysdeps/or1k/dl-trampoline.S | 79 + sysdeps/or1k/jmpbuf-offsets.h | 23 + sysdeps/or1k/jmpbuf-unwind.h | 36 + sysdeps/or1k/ldsodefs.h | 40 + sysdeps/or1k/libc-tls.c | 34 + sysdeps/or1k/libm-test-ulps | 1112 +++++++++ sysdeps/or1k/libm-test-ulps-name | 1 + sysdeps/or1k/machine-gmon.h | 35 + sysdeps/or1k/memusage.h | 21 + sysdeps/or1k/nofpu/Implies | 1 + sysdeps/or1k/nofpu/math-tests-exceptions.h | 29 + sysdeps/or1k/nofpu/math-tests-rounding.h | 28 + sysdeps/or1k/nptl/Makefile | 21 + sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 + sysdeps/or1k/nptl/pthreaddef.h | 36 + sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++ sysdeps/or1k/preconfigure | 34 + sysdeps/or1k/setjmp.S | 56 + sysdeps/or1k/sfp-machine.h | 93 + sysdeps/or1k/sotruss-lib.c | 51 + sysdeps/or1k/stackinfo.h | 34 + sysdeps/or1k/start.S | 99 + sysdeps/or1k/sysdep.h | 83 + sysdeps/or1k/tininess.h | 1 + sysdeps/or1k/tst-audit.h | 24 + sysdeps/unix/sysv/linux/or1k/Implies | 3 + sysdeps/unix/sysv/linux/or1k/Makefile | 12 + sysdeps/unix/sysv/linux/or1k/arch-syscall.h | 325 +++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 + sysdeps/unix/sysv/linux/or1k/bits/timesize.h | 19 + sysdeps/unix/sysv/linux/or1k/c++-types.data | 67 + sysdeps/unix/sysv/linux/or1k/clone.c | 61 + sysdeps/unix/sysv/linux/or1k/configure | 4 + sysdeps/unix/sysv/linux/or1k/configure.ac | 4 + sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 + sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h | 41 + sysdeps/unix/sysv/linux/or1k/ld.abilist | 5 + .../sysv/linux/or1k/libBrokenLocale.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libanl.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libc.abilist | 2122 +++++++++++++++++ .../sysv/linux/or1k/libc_malloc_debug.abilist | 26 + sysdeps/unix/sysv/linux/or1k/libcrypt.abilist | 2 + sysdeps/unix/sysv/linux/or1k/libdl.abilist | 0 sysdeps/unix/sysv/linux/or1k/libm.abilist | 759 ++++++ sysdeps/unix/sysv/linux/or1k/libnsl.abilist | 121 + .../unix/sysv/linux/or1k/libpthread.abilist | 0 .../unix/sysv/linux/or1k/libresolv.abilist | 55 + sysdeps/unix/sysv/linux/or1k/librt.abilist | 0 .../unix/sysv/linux/or1k/libthread_db.abilist | 40 + sysdeps/unix/sysv/linux/or1k/libutil.abilist | 1 + sysdeps/unix/sysv/linux/or1k/localplt.data | 14 + sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 + sysdeps/unix/sysv/linux/or1k/mmap_internal.h | 28 + sysdeps/unix/sysv/linux/or1k/or1k_clone.S | 89 + sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 + sysdeps/unix/sysv/linux/or1k/shlib-versions | 2 + sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 + sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 + sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 + sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/sysdep.c | 34 + sysdeps/unix/sysv/linux/or1k/sysdep.h | 201 ++ sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 + sysdeps/unix/sysv/linux/syscall-names.list | 1 + 82 files changed, 7575 insertions(+) create mode 100644 sysdeps/or1k/Implies create mode 100644 sysdeps/or1k/Makefile create mode 100644 sysdeps/or1k/__longjmp.S create mode 100644 sysdeps/or1k/atomic-machine.h create mode 100644 sysdeps/or1k/bits/endianness.h create mode 100644 sysdeps/or1k/bits/fenv.h create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/bits/setjmp.h create mode 100644 sysdeps/or1k/bsd-_setjmp.S create mode 100644 sysdeps/or1k/bsd-setjmp.S create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/dl-trampoline.S create mode 100644 sysdeps/or1k/jmpbuf-offsets.h create mode 100644 sysdeps/or1k/jmpbuf-unwind.h create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/libm-test-ulps create mode 100644 sysdeps/or1k/libm-test-ulps-name create mode 100644 sysdeps/or1k/machine-gmon.h create mode 100644 sysdeps/or1k/memusage.h create mode 100644 sysdeps/or1k/nofpu/Implies create mode 100644 sysdeps/or1k/nofpu/math-tests-exceptions.h create mode 100644 sysdeps/or1k/nofpu/math-tests-rounding.h create mode 100644 sysdeps/or1k/nptl/Makefile create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/preconfigure create mode 100644 sysdeps/or1k/setjmp.S create mode 100644 sysdeps/or1k/sfp-machine.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/stackinfo.h create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/sysdep.h create mode 100644 sysdeps/or1k/tininess.h create mode 100644 sysdeps/or1k/tst-audit.h create mode 100644 sysdeps/unix/sysv/linux/or1k/Implies create mode 100644 sysdeps/unix/sysv/linux/or1k/Makefile create mode 100644 sysdeps/unix/sysv/linux/or1k/arch-syscall.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/timesize.h create mode 100644 sysdeps/unix/sysv/linux/or1k/c++-types.data create mode 100644 sysdeps/unix/sysv/linux/or1k/clone.c create mode 100644 sysdeps/unix/sysv/linux/or1k/configure create mode 100644 sysdeps/unix/sysv/linux/or1k/configure.ac create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ld.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libanl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc_malloc_debug.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libcrypt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libdl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libm.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libnsl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libpthread.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libresolv.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/librt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libthread_db.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libutil.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/localplt.data create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/mmap_internal.h create mode 100644 sysdeps/unix/sysv/linux/or1k/or1k_clone.S create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/shlib-versions create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.c create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.sym
v3 cover Glibc OpenRISC port
Quoted 45 lines · Adhemerval Zanella
Quoted 42 lines · Stafford Horne via Libc-alpha
This is the OpenRISC port for glibc that I have been working on.
Changes since v2:
- Fixed suggestions from Joseph Myers:
- Fix comment style, and description on top of each file
- Make sure macros have parentheses when needed,
- Bump required kernel down to 5.4.0 and document
- Regeneratearch-syscall.h
- Fixed suggestions from Adhemerval:
- Removekernel_stat.h
- Just setMMAP2_PAGE_UNITto 8K
- Removeioctl.candsyscall.cfiles
- Update TCB alignment to 32 bytesChanges since v1:
- Update api's as suggested by Florian
- Remove hard float support
- Updates to get all tests passing
- Split patch into managable bits similar to recent ARC portDocumentation:
Architecture / ABI docs:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdfTest Results:
build-many-glibcs.py:PASS with mainline ang gcc-11.
Full test suite:
The full suite is running using the gcc-11 branch of GCC, mainline shows issues with math soft-fp.
Note, there are a few more failures compared to before, this is due to me running with a timeout of 30 vs usual 300. It allows the tests to complete faster, but I get a few more timeouts. There were 15 timeouts which I confirm do work if I increase the timeoutfactor. The 2 real failures marked with * below.
Quoted 8 lines
Quoted 4 lines
# test start: 2021-12-08T19:59:00+09:00# failures FAIL:*elf/tst-bz15311This seems to be a real issue, the output shows the new sorting algorithm seems not be enabled (the output shows the destructor order for dynamic_sort=1). We need to figure out what is happening here.
It does like the destructor ordering issue Florian has posted a patch [1].
[1] https://sourceware.org/pipermail/libc-alpha/2021-December/134165.html
Quoted 238 lines
Quoted 17 lines
FAIL: locale/tst-localedef-path-norm
FAIL: malloc/tst-dynarray-fail
FAIL: malloc/tst-dynarray-fail-mem
FAIL: nptl/tst-mutex10
FAIL: nss/tst-nss-files-hosts-getent
FAIL: nss/tst-nss-files-hosts-multi
FAIL: posix/tst-regcomp-truncated
FAIL: stdio-common/tst-vfprintf-width-prec
FAIL: stdio-common/tst-vfprintf-width-prec-alloc
FAIL: stdio-common/tst-vfprintf-width-prec-mem
FAIL: string/test-memcpy
FAIL: string/test-memcpy-large
FAIL: string/test-mempcpy
FAIL: string/tst-cmp
FAIL: support/tst-support_blob_repeat FAIL:*timezone/tst-tzsetIt seems the testing file system does not support sparse files or at least has some limits of the file size and
support_descriptor_supports_holesis no deteting it.I think we should use a large
write_offsetandblock_headroom, maybe something larger than 32-bit offset to actually check it. Could you check if increasing both values does make the test unsupported.Quoted 12 lines
# test finish: 2021-12-10T22:04:56+09:00 # test duration: 2 days 2 hours 5 minutes and 56 seconds # test for file: tests.sum # test wrapper: /home/shorne/work/gnu-toolchain/glibc/scripts/cross-test-ssh.sh --timeoutfactor 30 10.0.0.5# summary 17 FAIL 4063 PASS 28 UNSUPPORTED 18 XFAILQuoted 3 lines
tst-bz15311.out: https://gist.github.com/5a5dacaeef1eac1f2f5d89701d14c0ad tst-tzset.out: https://gist.github.com/b3a548d82cfc9367905e115821a52754 tests.sum: https://gist.github.com/f85a81012c8329b9a95370a30c7b27feSince
8d1927d8dc5aad0f01c929123086be3a5b799d18it will need an additional fix to correctly build glibc:sysdeps/or1k/nptl/tls.h +2
-0@@ -150,6 +150,8 @@ register tcbhead_t *__thread_self __asm__("r10");# define DB_THREAD_SELF \ REGISTER (32, 32, 10 * 4, - TLS_INIT_TCB_SIZE - TLS_PRE_TCB_SIZE) +# include <tcb-access.h> +/* Access to data in the thread descriptor is easy. */ #define THREAD_GETMEM (descr, member) \With the above fix I can bootstrap a compiler with
build-many-glibcs.py.Quoted 177 lines
Stafford Horne (13):
elf: Add reloc for OpenRISC
linux/syscalls: Addor1k_atomicsyscall for OpenRISC
or1k: ABI Implementation
or1k: startup and dynamic linking code
or1k: Thread Local Storage support
or1k: Atomics and Locking primitives
or1k: math soft float support
or1k: Linux Syscall Interface
or1k: Linux ABI
or1k: ABI lists
or1k: Build Infrastructurebuild-many-glibcs.py: add OpenRISC support Documentation for OpenRISC portNEWS | 4 + README | 1 + elf/elf.h | 37 + scripts/build-many-glibcs.py | 5 + sysdeps/or1k/Implies | 3 + sysdeps/or1k/Makefile | 7 + sysdeps/or1k/__longjmp.S | 55 + sysdeps/or1k/atomic-machine.h | 79 + sysdeps/or1k/bits/endianness.h | 11 + sysdeps/or1k/bits/fenv.h | 69 + sysdeps/or1k/bits/link.h | 51 + sysdeps/or1k/bits/setjmp.h | 32 + sysdeps/or1k/bsd-_setjmp.S | 1 + sysdeps/or1k/bsd-setjmp.S | 1 + sysdeps/or1k/dl-machine.h | 323 +++ sysdeps/or1k/dl-start.S | 98 + sysdeps/or1k/dl-tls.h | 27 + sysdeps/or1k/dl-trampoline.S | 79 + sysdeps/or1k/jmpbuf-offsets.h | 23 + sysdeps/or1k/jmpbuf-unwind.h | 36 + sysdeps/or1k/ldsodefs.h | 40 + sysdeps/or1k/libc-tls.c | 34 + sysdeps/or1k/libm-test-ulps | 1112 +++++++++ sysdeps/or1k/libm-test-ulps-name | 1 + sysdeps/or1k/machine-gmon.h | 35 + sysdeps/or1k/memusage.h | 21 + sysdeps/or1k/nofpu/Implies | 1 + sysdeps/or1k/nofpu/math-tests-exceptions.h | 29 + sysdeps/or1k/nofpu/math-tests-rounding.h | 28 + sysdeps/or1k/nptl/Makefile | 21 + sysdeps/or1k/nptl/bits/pthreadtypes-arch.h | 48 + sysdeps/or1k/nptl/pthreaddef.h | 36 + sysdeps/or1k/nptl/tcb-offsets.sym | 6 + sysdeps/or1k/nptl/tls.h | 189 ++ sysdeps/or1k/preconfigure | 34 + sysdeps/or1k/setjmp.S | 56 + sysdeps/or1k/sfp-machine.h | 93 + sysdeps/or1k/sotruss-lib.c | 51 + sysdeps/or1k/stackinfo.h | 34 + sysdeps/or1k/start.S | 99 + sysdeps/or1k/sysdep.h | 83 + sysdeps/or1k/tininess.h | 1 + sysdeps/or1k/tst-audit.h | 24 + sysdeps/unix/sysv/linux/or1k/Implies | 3 + sysdeps/unix/sysv/linux/or1k/Makefile | 12 + sysdeps/unix/sysv/linux/or1k/arch-syscall.h | 325 +++ sysdeps/unix/sysv/linux/or1k/bits/procfs.h | 38 + sysdeps/unix/sysv/linux/or1k/bits/timesize.h | 19 + sysdeps/unix/sysv/linux/or1k/c++-types.data | 67 + sysdeps/unix/sysv/linux/or1k/clone.c | 61 + sysdeps/unix/sysv/linux/or1k/configure | 4 + sysdeps/unix/sysv/linux/or1k/configure.ac | 4 + sysdeps/unix/sysv/linux/or1k/getcontext.S | 72 + sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h | 41 + sysdeps/unix/sysv/linux/or1k/ld.abilist | 5 + .../sysv/linux/or1k/libBrokenLocale.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libanl.abilist | 1 + sysdeps/unix/sysv/linux/or1k/libc.abilist | 2122 +++++++++++++++++ .../sysv/linux/or1k/libc_malloc_debug.abilist | 26 + sysdeps/unix/sysv/linux/or1k/libcrypt.abilist | 2 + sysdeps/unix/sysv/linux/or1k/libdl.abilist | 0 sysdeps/unix/sysv/linux/or1k/libm.abilist | 759 ++++++ sysdeps/unix/sysv/linux/or1k/libnsl.abilist | 121 + .../unix/sysv/linux/or1k/libpthread.abilist | 0 .../unix/sysv/linux/or1k/libresolv.abilist | 55 + sysdeps/unix/sysv/linux/or1k/librt.abilist | 0 .../unix/sysv/linux/or1k/libthread_db.abilist | 40 + sysdeps/unix/sysv/linux/or1k/libutil.abilist | 1 + sysdeps/unix/sysv/linux/or1k/localplt.data | 14 + sysdeps/unix/sysv/linux/or1k/makecontext.c | 77 + sysdeps/unix/sysv/linux/or1k/mmap_internal.h | 28 + sysdeps/unix/sysv/linux/or1k/or1k_clone.S | 89 + sysdeps/unix/sysv/linux/or1k/setcontext.S | 108 + sysdeps/unix/sysv/linux/or1k/shlib-versions | 2 + sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h | 28 + sysdeps/unix/sysv/linux/or1k/swapcontext.S | 116 + sysdeps/unix/sysv/linux/or1k/sys/ucontext.h | 53 + sysdeps/unix/sysv/linux/or1k/sys/user.h | 1 + sysdeps/unix/sysv/linux/or1k/sysdep.c | 34 + sysdeps/unix/sysv/linux/or1k/sysdep.h | 201 ++ sysdeps/unix/sysv/linux/or1k/ucontext_i.sym | 26 + sysdeps/unix/sysv/linux/syscall-names.list | 1 + 82 files changed, 7575 insertions(+) create mode 100644 sysdeps/or1k/Implies create mode 100644 sysdeps/or1k/Makefile create mode 100644 sysdeps/or1k/__longjmp.S create mode 100644 sysdeps/or1k/atomic-machine.h create mode 100644 sysdeps/or1k/bits/endianness.h create mode 100644 sysdeps/or1k/bits/fenv.h create mode 100644 sysdeps/or1k/bits/link.h create mode 100644 sysdeps/or1k/bits/setjmp.h create mode 100644 sysdeps/or1k/bsd-_setjmp.S create mode 100644 sysdeps/or1k/bsd-setjmp.S create mode 100644 sysdeps/or1k/dl-machine.h create mode 100644 sysdeps/or1k/dl-start.S create mode 100644 sysdeps/or1k/dl-tls.h create mode 100644 sysdeps/or1k/dl-trampoline.S create mode 100644 sysdeps/or1k/jmpbuf-offsets.h create mode 100644 sysdeps/or1k/jmpbuf-unwind.h create mode 100644 sysdeps/or1k/ldsodefs.h create mode 100644 sysdeps/or1k/libc-tls.c create mode 100644 sysdeps/or1k/libm-test-ulps create mode 100644 sysdeps/or1k/libm-test-ulps-name create mode 100644 sysdeps/or1k/machine-gmon.h create mode 100644 sysdeps/or1k/memusage.h create mode 100644 sysdeps/or1k/nofpu/Implies create mode 100644 sysdeps/or1k/nofpu/math-tests-exceptions.h create mode 100644 sysdeps/or1k/nofpu/math-tests-rounding.h create mode 100644 sysdeps/or1k/nptl/Makefile create mode 100644 sysdeps/or1k/nptl/bits/pthreadtypes-arch.h create mode 100644 sysdeps/or1k/nptl/pthreaddef.h create mode 100644 sysdeps/or1k/nptl/tcb-offsets.sym create mode 100644 sysdeps/or1k/nptl/tls.h create mode 100644 sysdeps/or1k/preconfigure create mode 100644 sysdeps/or1k/setjmp.S create mode 100644 sysdeps/or1k/sfp-machine.h create mode 100644 sysdeps/or1k/sotruss-lib.c create mode 100644 sysdeps/or1k/stackinfo.h create mode 100644 sysdeps/or1k/start.S create mode 100644 sysdeps/or1k/sysdep.h create mode 100644 sysdeps/or1k/tininess.h create mode 100644 sysdeps/or1k/tst-audit.h create mode 100644 sysdeps/unix/sysv/linux/or1k/Implies create mode 100644 sysdeps/unix/sysv/linux/or1k/Makefile create mode 100644 sysdeps/unix/sysv/linux/or1k/arch-syscall.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/procfs.h create mode 100644 sysdeps/unix/sysv/linux/or1k/bits/timesize.h create mode 100644 sysdeps/unix/sysv/linux/or1k/c++-types.data create mode 100644 sysdeps/unix/sysv/linux/or1k/clone.c create mode 100644 sysdeps/unix/sysv/linux/or1k/configure create mode 100644 sysdeps/unix/sysv/linux/or1k/configure.ac create mode 100644 sysdeps/unix/sysv/linux/or1k/getcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/jmp_buf-macros.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ld.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libBrokenLocale.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libanl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libc_malloc_debug.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libcrypt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libdl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libm.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libnsl.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libpthread.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libresolv.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/librt.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libthread_db.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/libutil.abilist create mode 100644 sysdeps/unix/sysv/linux/or1k/localplt.data create mode 100644 sysdeps/unix/sysv/linux/or1k/makecontext.c create mode 100644 sysdeps/unix/sysv/linux/or1k/mmap_internal.h create mode 100644 sysdeps/unix/sysv/linux/or1k/or1k_clone.S create mode 100644 sysdeps/unix/sysv/linux/or1k/setcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/shlib-versions create mode 100644 sysdeps/unix/sysv/linux/or1k/sigcontextinfo.h create mode 100644 sysdeps/unix/sysv/linux/or1k/swapcontext.S create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/ucontext.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sys/user.h create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.c create mode 100644 sysdeps/unix/sysv/linux/or1k/sysdep.h create mode 100644 sysdeps/unix/sysv/linux/or1k/ucontext_i.sym
v3 cover Glibc OpenRISC port
Quoted 53 lines · Adhemerval Zanella
Quoted 50 lines · Adhemerval Zanella
Quoted 46 lines · Stafford Horne via Libc-alpha
This is the OpenRISC port for glibc that I have been working on.
Changes since v2:
- Fixed suggestions from Joseph Myers:
- Fix comment style, and description on top of each file
- Make sure macros have parentheses when needed,
- Bump required kernel down to 5.4.0 and document
- Regeneratearch-syscall.h
- Fixed suggestions from Adhemerval:
- Removekernel_stat.h
- Just setMMAP2_PAGE_UNITto 8K
- Removeioctl.candsyscall.cfiles
- Update TCB alignment to 32 bytesChanges since v1:
- Update api's as suggested by Florian
- Remove hard float support
- Updates to get all tests passing
- Split patch into managable bits similar to recent ARC portDocumentation:
Architecture / ABI docs:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdfTest Results:
build-many-glibcs.py:PASS with mainline ang gcc-11.
Full test suite:
The full suite is running using the gcc-11 branch of GCC, mainline shows issues with math soft-fp.
Note, there are a few more failures compared to before, this is due to me running with a timeout of 30 vs usual 300. It allows the tests to complete faster, but I get a few more timeouts. There were 15 timeouts which I confirm do work if I increase the timeoutfactor. The 2 real failures marked with * below.
# test start: 2021-12-08T19:59:00+09:00# failures FAIL:*elf/tst-bz15311
Quoted 7 lines
Quoted 3 lines
This seems to be a real issue, the output shows the new sorting algorithm seems not be enabled (the output shows the destructor order for dynamic_sort=1). We need to figure out what is happening here.
It does like the destructor ordering issue Florian has posted a patch [1].
[1] https://sourceware.org/pipermail/libc-alpha/2021-December/134165.html
I confirm applying these 2 patches from Florian does fix elf/tst-bz15311 for me. Thanks for the heads up.
-Stafford
v3 cover Glibc OpenRISC port
In reply to Adhemerval ZanellaQuoted 71 lines · Adhemerval Zanella
Quoted 42 lines · Stafford Horne via Libc-alpha
This is the OpenRISC port for glibc that I have been working on.
Changes since v2:
- Fixed suggestions from Joseph Myers:
- Fix comment style, and description on top of each file
- Make sure macros have parentheses when needed,
- Bump required kernel down to 5.4.0 and document
- Regeneratearch-syscall.h
- Fixed suggestions from Adhemerval:
- Removekernel_stat.h
- Just setMMAP2_PAGE_UNITto 8K
- Removeioctl.candsyscall.cfiles
- Update TCB alignment to 32 bytesChanges since v1:
- Update api's as suggested by Florian
- Remove hard float support
- Updates to get all tests passing
- Split patch into managable bits similar to recent ARC portDocumentation:
Architecture / ABI docs:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdfTest Results:
build-many-glibcs.py:PASS with mainline ang gcc-11.
Full test suite:
The full suite is running using the gcc-11 branch of GCC, mainline shows issues with math soft-fp.
Note, there are a few more failures compared to before, this is due to me running with a timeout of 30 vs usual 300. It allows the tests to complete faster, but I get a few more timeouts. There were 15 timeouts which I confirm do work if I increase the timeoutfactor. The 2 real failures marked with * below.
Quoted 4 lines
# test start: 2021-12-08T19:59:00+09:00# failures FAIL:*elf/tst-bz15311This seems to be a real issue, the output shows the new sorting algorithm seems not be enabled (the output shows the destructor order for dynamic_sort=1). We need to figure out what is happening here.
Quoted 8 lines
FAIL: locale/tst-localedef-path-norm
FAIL: malloc/tst-dynarray-fail
FAIL: malloc/tst-dynarray-fail-mem
FAIL: nptl/tst-mutex10
FAIL: nss/tst-nss-files-hosts-getent
FAIL: nss/tst-nss-files-hosts-multi
FAIL: posix/tst-regcomp-truncated
FAIL: stdio-common/tst-vfprintf-width-precQuoted 8 lines
FAIL: stdio-common/tst-vfprintf-width-prec-alloc
FAIL: stdio-common/tst-vfprintf-width-prec-mem
FAIL: string/test-memcpy
FAIL: string/test-memcpy-large
FAIL: string/test-mempcpy
FAIL: string/tst-cmp
FAIL: support/tst-support_blob_repeat FAIL:*timezone/tst-tzset
Quoted 3 lines
It seems the testing file system does not support sparse files or at least has some limits of the file size and
support_descriptor_supports_holesis no deteting it.
Let me see if I can figure out the sparse file support. If that can work then it would be good. The filesystem I am using is:
tmpfs on /tmp type tmpfs (rw,relatime)
Quoted 3 lines
I think we should use a large
write_offsetandblock_headroom, maybe something larger than 32-bit offset to actually check it. Could you check if increasing both values does make the test unsupported.
I will check.
-Stafford
v3 cover Glibc OpenRISC port
Quoted 79 lines · Stafford Horne
Quoted 71 lines · Adhemerval Zanella
Quoted 42 lines · Stafford Horne via Libc-alpha
This is the OpenRISC port for glibc that I have been working on.
Changes since v2:
- Fixed suggestions from Joseph Myers:
- Fix comment style, and description on top of each file
- Make sure macros have parentheses when needed,
- Bump required kernel down to 5.4.0 and document
- Regeneratearch-syscall.h
- Fixed suggestions from Adhemerval:
- Removekernel_stat.h
- Just setMMAP2_PAGE_UNITto 8K
- Removeioctl.candsyscall.cfiles
- Update TCB alignment to 32 bytesChanges since v1:
- Update api's as suggested by Florian
- Remove hard float support
- Updates to get all tests passing
- Split patch into managable bits similar to recent ARC portDocumentation:
Architecture / ABI docs:
https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.3-rev1.pdfTest Results:
build-many-glibcs.py:PASS with mainline ang gcc-11.
Full test suite:
The full suite is running using the gcc-11 branch of GCC, mainline shows issues with math soft-fp.
Note, there are a few more failures compared to before, this is due to me running with a timeout of 30 vs usual 300. It allows the tests to complete faster, but I get a few more timeouts. There were 15 timeouts which I confirm do work if I increase the timeoutfactor. The 2 real failures marked with * below.
Quoted 4 lines
# test start: 2021-12-08T19:59:00+09:00# failures FAIL:*elf/tst-bz15311This seems to be a real issue, the output shows the new sorting algorithm seems not be enabled (the output shows the destructor order for dynamic_sort=1). We need to figure out what is happening here.
Quoted 8 lines
FAIL: locale/tst-localedef-path-norm
FAIL: malloc/tst-dynarray-fail
FAIL: malloc/tst-dynarray-fail-mem
FAIL: nptl/tst-mutex10
FAIL: nss/tst-nss-files-hosts-getent
FAIL: nss/tst-nss-files-hosts-multi
FAIL: posix/tst-regcomp-truncated
FAIL: stdio-common/tst-vfprintf-width-precQuoted 8 lines
FAIL: stdio-common/tst-vfprintf-width-prec-alloc
FAIL: stdio-common/tst-vfprintf-width-prec-mem
FAIL: string/test-memcpy
FAIL: string/test-memcpy-large
FAIL: string/test-mempcpy
FAIL: string/tst-cmp
FAIL: support/tst-support_blob_repeat FAIL:*timezone/tst-tzsetQuoted 3 lines
It seems the testing file system does not support sparse files or at least has some limits of the file size and
support_descriptor_supports_holesis no deteting it.Let me see if I can figure out the sparse file support. If that can work then it would be good. The filesystem I am using is:
Quoted 7 lines
tmpfs on /tmp type tmpfs (rw,relatime)
Quoted 3 lines
I think we should use a large
write_offsetandblock_headroom, maybe something larger than 32-bit offset to actually check it. Could you check if increasing both values does make the test unsupported.I will check.
I looked into this, the following patch seems to help. Below are some notes I was keeping as I debugged it.
It seems the write to the tmp file was failing due the re-open not passing O_LARGEFILE. I am running with this patch now, and instead of failing it is working on creating the file, but taking a long time. I will let it run, but need to step away now.
timezone/tst-tzset.c +1 -1
@@ -44,7 +44,7 @@ create_tz_file (off64_t size)// Reopen for large-file support. close (fd); - fd =open64 (path,O_WRONLY ); + fd =open64 (path,O_WRONLY |O_LARGEFILE );if (fd <0 ) {printf ("open64 (%s) failed: %m\n" , path);
Debugging
The patch below and notes are how I got to the conclusion.
- tmsfs does support sparse files, but I am not able to write files larger
than 4GiB. But also as per below 2GiB seems to be a boundary.
- We get an write error 'File too large'
- Looking@ther kernel code I see two paths that generate this error
but it doesn't look like I should be hitting them.
* write size exceeds RLIMIT - though I have it set to unlimited
* write size exceeds fs_maxbytes - on tmpfs sb->s_maxbytes = MAX_LFS_FILESIZE on 32-bit MAX_LFS_FILESIZE ((loff_t)ULONG_MAX << PAGE_SHIFT)
- support_descriptor_supports_holes will not fail unless we run it on files re-opened with open64.
- This is where I noticed that open64 was missing O_LARGEFILE.
Output with write_offset = 2LL * 1024 * 1024 * 1024 - 2;
File size : 16 limit 160
1x: File size : 32/2147483646 limit 160
2x: File size : 32/4294967292 limit 160 File size : 16 limit 160
1x: File size : 32/2147483646 limit 160
2x: File size : 32/4294967292 limit 160 Single-byte write failed
creating timezone file of size: 4095MiB failed.
Output with write_offset = 2LL * 1024 * 1024 * 1024 - 1;
File size : 16 limit 160
error: xwrite.c:32: write of 1 bytes failed after 0: File too large
error: 1 test failures
Strace of running the patch, we see no O_LARGEFILE after re-open.
[pid 11318] openat(AT_FDCWD, "/tmp/tst-tzset-v0uEVn", O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE, 0600) = 3
[pid 11318] getpid() = 11318
[pid 11318] close(3) = 0
[pid 11318] openat(AT_FDCWD, "/tmp/tst-tzset-v0uEVn", O_WRONLY) = 3
[pid 11318] statx(3, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0600, stx_size=0, ...}) = 0 [pid 11318] _llseek(3, 0, [0], SEEK_SET) = 0
[pid 11318] write(3, "@", 1) = 1
[pid 11318] fsync(3) = 0
[pid 11318] statx(3, "", AT_STATX_SYNC_AS_STAT|AT_NO_AUTOMOUNT|AT_EMPTY_PATH, STATX_BASIC_STATS, {stx_mask=STATX_BASIC_STATS|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0600, stx_size=1, ...}) = 0 [pid 11318] write(1, "File size : 16 limit 160\n", 25File size : 16 limit 160
) = 25
[pid 11318] _llseek(3, 2147483647, [2147483647], SEEK_SET) = 0
[pid 11318] write(3, "@", 1) = -1 EFBIG (File too large)
support/support_descriptor_supports_holes.c +9 -2
@@ -31,15 +31,17 @@ support_descriptor_supports_holes (int fd)and hopefully large enough to trigger the creation of holes. We cannot use the file system block size as a reference here because it is incorrect for network file systems. */ - write_offset =16 *1024 *1024 , +// write_offset = 125 * 1024 * 1024, /* Our write may add this number of additional blocks (see block_limit below): writing at offset 16M can require two data block indirections, each of which can be as large as 8KB on ext2, thus 32 512B sectors. */ - block_headroom = 32, + block_headroom = 128, }; +unsigned long long int write_offset =2LL *1024 *1024 *1024 -1 ; +struct stat64 st;xfstat (fd, &st);if (!S_ISREG (st.st_mode))
@@ -66,6 +68,7 @@ support_descriptor_supports_holes (int fd)the write offset. */ unsigned long long int block_limit =2 * st.st_blocks + block_headroom; +printf ("File size : %lld limit %lld\n" , (long long int ) st.st_blocks, block_limit);/* Write a single byte@16 megabytes. */ xlseek (fd, write_offset,SEEK_SET );xwrite (fd, &b,1 );
@@ -74,6 +77,8 @@ support_descriptor_supports_holes (int fd)xfstat (fd, &st);bool supports_holes = st.st_blocks <= block_limit; +printf ("1x: File size : %lld/%lld limit %lld\n" , (long long int ) st.st_blocks, write_offset, block_limit); +/* Also check that extending the file does not fill up holes. */ xftruncate (fd,2 * write_offset);/* Attempt to bypass delayed allocation. */
@@ -81,6 +86,8 @@ support_descriptor_supports_holes (int fd)xfstat (fd, &st); supports_holes = supports_holes && st.st_blocks <= block_limit; +printf ("2x: File size : %lld/%lld limit %lld\n" , (long long int ) st.st_blocks,2 * write_offset, block_limit); +/* Return to a zero-length file. */ xftruncate (fd,0 );xlseek (fd,0 ,SEEK_SET );
timezone/tst-tzset.c +3 -2
@@ -39,8 +39,6 @@ create_tz_file (off64_t size)int fd =create_temp_file ("tst-tzset-" , &path);if (fd <0 )exit (1 ); -if (!support_descriptor_supports_holes (fd)) -FAIL_UNSUPPORTED ("File %s does not support holes" , path);// Reopen for large-file support. close (fd);
@@ -51,6 +49,9 @@ create_tz_file (off64_t size)exit (1 ); } +if (!support_descriptor_supports_holes (fd)) +FAIL_UNSUPPORTED ("File %s does not support holes" , path); +static const char data[] = {0x54 ,0x5a ,0x69 ,0x66 ,0x32 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,
v3 cover Glibc OpenRISC port
Quoted 2 lines · Stafford Horne via Libc-alpha
It seems the write to the tmp file was failing due the re-open not passing
O_LARGEFILE.
open64 implies O_LARGEFILE, so if that is making a difference, then your open64 is broken.
Signature · 3 lines
Andreas Schwab, schwab at linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
v3 cover Glibc OpenRISC port
Quoted 7 lines · Andreas Schwab
Quoted 2 lines · Stafford Horne via Libc-alpha
It seems the write to the tmp file was failing due the re-open not passing
O_LARGEFILE.open64 implies
O_LARGEFILE, so if that is making a difference, then your open64 is broken.
Right, that is what the docs say. This architecuture is 32-bits.
And the open64 path is generic.
Possibly this bit removing O_LARGEFILE is wrong?
In sysdeps/unix/sysv/linux/open64.c:
27 #ifdef __OFF_T_MATCHES_OFF64_T
28 # define EXTRA_OPEN_FLAGS 0
29 #else
30 # define EXTRA_OPEN_FLAGS O_LARGEFILE
31 #endif
Otherwise there is something is wrong on linux. It is explicitly checking for the precense of O_LARGEFILE.
in fs/read_write.c in generic_write_check_limits:
if (!(file->f_flags & O_LARGEFILE))
max_size = MAX_NON_LFS;Quoted 4 lines
Signature · 3 lines
Andreas Schwab, schwab at linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
v3 cover Glibc OpenRISC port
Quoted 24 lines · Stafford Horne
Quoted 3 lines · Andreas Schwab
Quoted 1 line · Stafford Horne via Libc-alpha
It seems the write to the tmp file was failing due the re-open not
passing
Quoted 4 lines
Quoted 1 line
O_LARGEFILE.open64 implies
O_LARGEFILE, so if that is making a difference, then your open64 is broken.Right, that is what the docs say. This architecuture is 32-bits.
And the open64 path is generic.
Possibly this bit removing
O_LARGEFILEis wrong?In
sysdeps/unix/sysv/linux/open64.c:27 #ifdef
__OFF_T_MATCHES_OFF64_T
28 # defineEXTRA_OPEN_FLAGS0
29 #else
30 # defineEXTRA_OPEN_FLAGSO_LARGEFILE
31 #endif
Quoted 8 lines
Otherwise there is something is wrong on linux. It is explicitly checking for the precense of
O_LARGEFILE.in
fs/read_write.cingeneric_write_check_limits:if (!(file->f_flags & O_LARGEFILE)) max_size = MAX_NON_LFS;
There's something wrong with __OFF_T_MATCHES_OFF64_T in this port. We have 32-bit off_t in Linux. So __OFF_T_MATCHES_OFF64_T should be undefined I think. I'll look into.
-Stafford
Quoted 1 line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.librecores.org/pipermail/openrisc/attachments/20211225/f9454c1f/attachment.htm>
v3 cover Glibc OpenRISC port
Quoted 31 lines · Stafford Horne
Quoted 29 lines · Stafford Horne
Quoted 3 lines · Andreas Schwab
Quoted 1 line · Stafford Horne via Libc-alpha
It seems the write to the tmp file was failing due the re-open not
passing
Quoted 4 lines
Quoted 1 line
O_LARGEFILE.open64 implies
O_LARGEFILE, so if that is making a difference, then your open64 is broken.Right, that is what the docs say. This architecuture is 32-bits.
And the open64 path is generic.
Possibly this bit removing
O_LARGEFILEis wrong?In
sysdeps/unix/sysv/linux/open64.c:27 #ifdef
__OFF_T_MATCHES_OFF64_T
28 # defineEXTRA_OPEN_FLAGS0
29 #else
30 # defineEXTRA_OPEN_FLAGSO_LARGEFILE
31 #endifOtherwise there is something is wrong on linux. It is explicitly checking for the precense of
O_LARGEFILE.in
fs/read_write.cingeneric_write_check_limits:
Quoted 7 lines
Quoted 3 lines
if (!(file->f_flags & O_LARGEFILE)) max_size = MAX_NON_LFS;There's something wrong with
__OFF_T_MATCHES_OFF64_Tin this port. We have 32-bitoff_tin Linux. So__OFF_T_MATCHES_OFF64_Tshould be undefined I think. I'll look into.
So, __OFF_T_MATCHES_OFF64_T if defined if TIMESIZE==64 && WORDSIZE==32, and it's correct from glibc's perspective as off_t is 64-bits in the user API. However, it is not correct for use for setting O_LARGEFILE.
In linux the O_LARGEFILE flag is forced based on architecture configuration ARCH_32BIT_OFF_T.
#define force_o_largefile() (!IS_ENABLED(CONFIG_ARCH_32BIT_OFF_T))
Then it is used in syscalls:
SYSCALL_DEFINE4(openat, int, dfd, const char __user *, filename, int, flags,
umode_t, mode)
{
if (force_o_largefile())
flags |= O_LARGEFILE;
return do_sys_open(dfd, filename, flags, mode);
}On most 32-bit architectures ARCH_32BIT_OFF_T is configured. SO I think there is something wrong with how we are setting up EXTRA_OPEN_FLAGS based on __OFF_T_MATCHES_OFF64_T only. Maybe it should be changed to WORDSIZE==32 or a combination. I will send a separate patch to discuss.
-Stafford