From patchwork Sat Nov 13 03:16:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stafford Horne X-Patchwork-Id: 47588 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 829223857C43 for ; Sat, 13 Nov 2021 03:20:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 829223857C43 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1636773604; bh=OWA/aCHcBE9Ba8s6Suq9EtBtF64v23XK1168F6as4kU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=XTTUu/2GsGLzAEDAIblL1BGCUYwMQPMKHV/vfbrXE/2NbmmZmKFV8l2Y+86zVcAsD 50s08qSaQPd0M3ZF0QkNA8Pa3nFb6bR9wlNiigtT/xBeHrfHWuOM9MaMLQ6kaEle8q f4wx7RtI975wM6X4mVLKca80bI/0yOKz2zotdm7w= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 759EE3858038 for ; Sat, 13 Nov 2021 03:16:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 759EE3858038 Received: by mail-pf1-x42b.google.com with SMTP id c4so10050370pfj.2 for ; Fri, 12 Nov 2021 19:16:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OWA/aCHcBE9Ba8s6Suq9EtBtF64v23XK1168F6as4kU=; b=qBhHI8ZqBYzZAUI4NMLeJeVHp2pM3QQ4VjKnSnL8TLUzlSXBd8pXW1HP97NuYrLU+J 93nGmbXnED7r4MUswnQZWrMqzGXwIJQszb7bRPB1zOKfYKzrTnBPJJGJYymbONIwzv36 jHykrwvXEppbmUYIsF6Xj0J4EmhA1zabVPUcGFC8L6lzZDUZPv4dRrljHdxcTyEzXAtv i9PvoewjCMnuSnNPh8yHFiBxc1nDN8dqkhVwAtG+nDP54PZ6nR0D7cdlVajXncnmZuGP ktmjBcjI8QFdIFx2K9MDu/ozmtJfuFWtTq9I6d+r8eXwH27CRmFsQVO/XwTVYb914KBK BwXQ== X-Gm-Message-State: AOAM531Iiy3aVlCsNGpwyyWIGrs+FZPNKOL+gQjCT191/ITCdemaFeYG Yc8w/jLyQgJCCaCDL1GtlRykhoSLDok= X-Google-Smtp-Source: ABdhPJxJrTELo6jv1THyII0t9MJ//WTg+CjCTUIO7kb9BnF2yszepAxA5x0jafLCByheE6Uo7xXzjg== X-Received: by 2002:aa7:8149:0:b0:44c:916c:1fdb with SMTP id d9-20020aa78149000000b0044c916c1fdbmr18458828pfn.34.1636773415935; Fri, 12 Nov 2021 19:16:55 -0800 (PST) Received: from localhost ([2409:10:24a0:4700:e8ad:216a:2a9d:6d0c]) by smtp.gmail.com with ESMTPSA id q11sm8289615pfk.192.2021.11.12.19.16.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Nov 2021 19:16:55 -0800 (PST) To: GLIBC patches Subject: [PATCH v2 04/13] or1k: startup and dynamic linking code Date: Sat, 13 Nov 2021 12:16:30 +0900 Message-Id: <20211113031639.2402161-5-shorne@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211113031639.2402161-1-shorne@gmail.com> References: <20211113031639.2402161-1-shorne@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Stafford Horne via Libc-alpha From: Stafford Horne Reply-To: Stafford Horne Cc: Openrisc Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Code for C runtime startup and dynamic loading including PLT layout. --- sysdeps/or1k/bits/link.h | 50 ++++++ 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, 685 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 diff --git a/sysdeps/or1k/bits/link.h b/sysdeps/or1k/bits/link.h new file mode 100644 index 0000000000..76dc1a1b35 --- /dev/null +++ b/sysdeps/or1k/bits/link.h @@ -0,0 +1,50 @@ +/* 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 + . */ + +#ifndef _LINK_H +# error "Never include directly; use 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 diff --git a/sysdeps/or1k/dl-machine.h b/sysdeps/or1k/dl-machine.h new file mode 100644 index 0000000000..f93ae768d4 --- /dev/null +++ b/sysdeps/or1k/dl-machine.h @@ -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 + . */ + +#ifndef dl_machine_h +#define dl_machine_h + +#define ELF_MACHINE_NAME "or1k" + +#include +#include +#include +#include +#include +#include + +/* 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) +{ + Elf32_Addr *got; + register long int linkreg asm ("r9"); + 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; +} + +/* 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(); + 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(); + + 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 C function `_dl_start' is the real entry point; + its 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 + started. */ + GL(dl_profile_map) = l; + } + else +#endif + { + /* 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 ?: "", + 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 */ diff --git a/sysdeps/or1k/dl-start.S b/sysdeps/or1k/dl-start.S new file mode 100644 index 0000000000..cafa512b7c --- /dev/null +++ b/sysdeps/or1k/dl-start.S @@ -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 + . */ + +#include + +/* Initial entry point code for the dynamic linker. + The C 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) diff --git a/sysdeps/or1k/ldsodefs.h b/sysdeps/or1k/ldsodefs.h new file mode 100644 index 0000000000..89713fcc70 --- /dev/null +++ b/sysdeps/or1k/ldsodefs.h @@ -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 + . */ + +#ifndef _OR1K_LDSODEFS_H +#define _OR1K_LDSODEFS_H 1 + +#include + +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 + +#endif diff --git a/sysdeps/or1k/sotruss-lib.c b/sysdeps/or1k/sotruss-lib.c new file mode 100644 index 0000000000..ee16f84456 --- /dev/null +++ b/sysdeps/or1k/sotruss-lib.c @@ -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 + . */ + +#define HAVE_ARCH_PLTENTER +#define HAVE_ARCH_PLTEXIT + +#include + +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; +} diff --git a/sysdeps/or1k/start.S b/sysdeps/or1k/start.S new file mode 100644 index 0000000000..0424355f36 --- /dev/null +++ b/sysdeps/or1k/start.S @@ -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 +#include + +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_start diff --git a/sysdeps/or1k/tst-audit.h b/sysdeps/or1k/tst-audit.h new file mode 100644 index 0000000000..79ee1b7b02 --- /dev/null +++ b/sysdeps/or1k/tst-audit.h @@ -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 + . */ + +#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