diff options
40 files changed, 2819 insertions, 2 deletions
diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 5166efbf0..a9c01f130 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -34,6 +34,7 @@ choice default TARGET_mips if DESIRED_TARGET_ARCH = "mips" default TARGET_nios if DESIRED_TARGET_ARCH = "nios" default TARGET_nios2 if DESIRED_TARGET_ARCH = "nios2" + default TARGET_or1k if DESIRED_TARGET_ARCH = "or1k" default TARGET_powerpc if DESIRED_TARGET_ARCH = "powerpc" default TARGET_sh if DESIRED_TARGET_ARCH = "sh" default TARGET_sh64 if DESIRED_TARGET_ARCH = "sh64" @@ -107,6 +108,9 @@ config TARGET_mips config TARGET_nios2 bool "nios2" +config TARGET_or1k + bool "or1k" + config TARGET_powerpc bool "powerpc" @@ -208,6 +212,10 @@ if TARGET_mips source "extra/Configs/Config.mips" endif +if TARGET_or1k +source "extra/Configs/Config.or1k" +endif + if TARGET_powerpc source "extra/Configs/Config.powerpc" endif @@ -474,7 +482,7 @@ config LDSO_NO_CLEANUP Unless you know you need this, you should answer N. config UCLIBC_CTOR_DTOR - boolean + bool default y help If you wish to build uClibc with support for global constructor @@ -576,6 +584,7 @@ config UCLIBC_HAS_THREADS_NATIVE !TARGET_m68k && \ !TARGET_microblaze && \ !TARGET_nios2 && \ + !TARGET_or1k && \ !TARGET_vax help If you want to compile uClibc with NPTL support, then answer Y. diff --git a/extra/Configs/Config.or1k b/extra/Configs/Config.or1k new file mode 100644 index 000000000..45e6f0a57 --- /dev/null +++ b/extra/Configs/Config.or1k @@ -0,0 +1,35 @@ +# +# For a description of the syntax of this configuration file, +# see extra/config/Kconfig-language.txt +# + +config TARGET_ARCH + default "or1k" + +config ARCH_CFLAGS + string + +config ARCH_LDFLAGS + string + +config LIBGCC_CFLAGS + string + +choice + prompt "Target Architecture Type" + default CONFIG_OR1K + help + This is the architecture type of your CPU. This information is used for + optimizing purposes. + + These are the possible settings: + - or1k Generic support for OpenCores OpenRISC/or1k architecture. + +config CONFIG_OR1K + select ARCH_HAS_MMU + select UCLIBC_HAS_FPU + select ARCH_BIG_ENDIAN + select HAS_NO_THREADS + bool "or1k" + +endchoice diff --git a/extra/Configs/defconfigs/or1k/defconfig b/extra/Configs/defconfigs/or1k/defconfig new file mode 100644 index 000000000..f8b8d2b33 --- /dev/null +++ b/extra/Configs/defconfigs/or1k/defconfig @@ -0,0 +1,245 @@ +# +# Automatically generated make config: don't edit +# Version: 0.9.34-git +# Wed Oct 10 16:27:15 2012 +# +# TARGET_alpha is not set +# TARGET_arm is not set +# TARGET_avr32 is not set +# TARGET_bfin is not set +# TARGET_c6x is not set +# TARGET_cris is not set +# TARGET_e1 is not set +# TARGET_frv is not set +# TARGET_h8300 is not set +# TARGET_hppa is not set +# TARGET_i386 is not set +# TARGET_i960 is not set +# TARGET_ia64 is not set +# TARGET_m68k is not set +# TARGET_microblaze is not set +# TARGET_mips is not set +# TARGET_nios is not set +# TARGET_nios2 is not set +TARGET_or1k=y +# TARGET_powerpc is not set +# TARGET_sh is not set +# TARGET_sh64 is not set +# TARGET_sparc is not set +# TARGET_v850 is not set +# TARGET_vax is not set +# TARGET_x86_64 is not set +# TARGET_xtensa is not set + +# +# Target Architecture Features and Options +# +TARGET_ARCH="or1k" +CONFIG_OR1K=y +TARGET_SUBARCH="" + +# +# Using ELF file format +# +ARCH_BIG_ENDIAN=y + +# +# Using Big Endian +# +ARCH_HAS_MMU=y +ARCH_USE_MMU=y +UCLIBC_HAS_FLOATS=y +UCLIBC_HAS_FPU=y +DO_C99_MATH=y +# DO_XSI_MATH is not set +# UCLIBC_HAS_FENV is not set +KERNEL_HEADERS="${SYSROOT}/usr/include" +HAVE_DOT_CONFIG=y + +# +# General Library Settings +# +DOPIC=y +HAVE_SHARED=y +# FORCE_SHAREABLE_TEXT_SEGMENTS is not set +LDSO_LDD_SUPPORT=y +LDSO_CACHE_SUPPORT=y +LDSO_PRELOAD_ENV_SUPPORT=y +# LDSO_PRELOAD_FILE_SUPPORT is not set +LDSO_BASE_FILENAME="ld.so" +# LDSO_STANDALONE_SUPPORT is not set +# LDSO_PRELINK_SUPPORT is not set +UCLIBC_STATIC_LDCONFIG=y +LDSO_RUNPATH=y +LDSO_SEARCH_INTERP_PATH=y +LDSO_LD_LIBRARY_PATH=y +# LDSO_NO_CLEANUP is not set +UCLIBC_CTOR_DTOR=y +# LDSO_GNU_HASH_SUPPORT is not set +# HAS_NO_THREADS is not set +LINUXTHREADS_OLD=y +# LINUXTHREADS_NEW is not set +# UCLIBC_HAS_THREADS_NATIVE is not set +UCLIBC_HAS_THREADS=y +# PTHREADS_DEBUG_SUPPORT is not set +UCLIBC_HAS_SYSLOG=y +UCLIBC_HAS_LFS=y +# MALLOC is not set +# MALLOC_SIMPLE is not set +MALLOC_STANDARD=y +# MALLOC_GLIBC_COMPAT is not set +# UCLIBC_DYNAMIC_ATEXIT is not set +COMPAT_ATEXIT=y +UCLIBC_SUSV3_LEGACY=y +# UCLIBC_SUSV3_LEGACY_MACROS is not set +UCLIBC_SUSV4_LEGACY=y +# UCLIBC_STRICT_HEADERS is not set +# UCLIBC_HAS_STUBS is not set +UCLIBC_HAS_SHADOW=y +UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y +UCLIBC_HAS___PROGNAME=y +UCLIBC_HAS_PTY=y +ASSUME_DEVPTS=y +UNIX98PTY_ONLY=y +# UCLIBC_HAS_GETPT is not set +# UCLIBC_HAS_LIBUTIL is not set +UCLIBC_HAS_TM_EXTENSIONS=y +UCLIBC_HAS_TZ_CACHING=y +UCLIBC_HAS_TZ_FILE=y +UCLIBC_HAS_TZ_FILE_READ_MANY=y +UCLIBC_TZ_FILE_PATH="/etc/TZ" +UCLIBC_FALLBACK_TO_ETC_LOCALTIME=y + +# +# Advanced Library Settings +# +UCLIBC_PWD_BUFFER_SIZE=256 +UCLIBC_GRP_BUFFER_SIZE=256 + +# +# Support various families of functions +# +UCLIBC_LINUX_MODULE_26=y +UCLIBC_LINUX_MODULE_24=y +UCLIBC_LINUX_SPECIFIC=y +UCLIBC_HAS_GNU_ERROR=y +UCLIBC_BSD_SPECIFIC=y +UCLIBC_HAS_BSD_ERR=y +# UCLIBC_HAS_OBSOLETE_BSD_SIGNAL is not set +# UCLIBC_HAS_OBSOLETE_SYSV_SIGNAL is not set +# UCLIBC_NTP_LEGACY is not set +# UCLIBC_SV4_DEPRECATED is not set +UCLIBC_HAS_REALTIME=y +UCLIBC_HAS_ADVANCED_REALTIME=y +UCLIBC_HAS_EPOLL=y +UCLIBC_HAS_XATTR=y +UCLIBC_HAS_PROFILING=y +UCLIBC_HAS_CRYPT_IMPL=y +# UCLIBC_HAS_SHA256_CRYPT_IMPL is not set +# UCLIBC_HAS_SHA512_CRYPT_IMPL is not set +UCLIBC_HAS_CRYPT=y +UCLIBC_HAS_NETWORK_SUPPORT=y +UCLIBC_HAS_SOCKET=y +UCLIBC_HAS_IPV4=y +UCLIBC_HAS_IPV6=y +UCLIBC_HAS_RPC=y +UCLIBC_HAS_FULL_RPC=y +UCLIBC_HAS_REENTRANT_RPC=y +# UCLIBC_USE_NETLINK is not set +# UCLIBC_HAS_BSD_RES_CLOSE is not set +UCLIBC_HAS_COMPAT_RES_STATE=y +# UCLIBC_HAS_EXTRA_COMPAT_RES_STATE is not set +# UCLIBC_HAS_RESOLVER_SUPPORT is not set +# UCLIBC_HAS_LIBRESOLV_STUB is not set +# UCLIBC_HAS_LIBNSL_STUB is not set + +# +# String and Stdio Support +# +UCLIBC_HAS_STRING_GENERIC_OPT=y +UCLIBC_HAS_STRING_ARCH_OPT=y +UCLIBC_HAS_CTYPE_TABLES=y +UCLIBC_HAS_CTYPE_SIGNED=y +UCLIBC_HAS_CTYPE_UNSAFE=y +# UCLIBC_HAS_CTYPE_CHECKED is not set +# UCLIBC_HAS_CTYPE_ENFORCED is not set +UCLIBC_HAS_WCHAR=y +# UCLIBC_HAS_LOCALE is not set +# UCLIBC_HAS_HEXADECIMAL_FLOATS is not set +# UCLIBC_HAS_GLIBC_CUSTOM_PRINTF is not set +UCLIBC_PRINTF_SCANF_POSITIONAL_ARGS=9 +# UCLIBC_HAS_STDIO_BUFSIZ_NONE is not set +# UCLIBC_HAS_STDIO_BUFSIZ_256 is not set +# UCLIBC_HAS_STDIO_BUFSIZ_512 is not set +# UCLIBC_HAS_STDIO_BUFSIZ_1024 is not set +# UCLIBC_HAS_STDIO_BUFSIZ_2048 is not set +UCLIBC_HAS_STDIO_BUFSIZ_4096=y +# UCLIBC_HAS_STDIO_BUFSIZ_8192 is not set +UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE=y +# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4 is not set +# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8 is not set +# UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT is not set +UCLIBC_HAS_STDIO_GETC_MACRO=y +UCLIBC_HAS_STDIO_PUTC_MACRO=y +UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION=y +# UCLIBC_HAS_FOPEN_LARGEFILE_MODE is not set +# UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE is not set +# UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE is not set +# UCLIBC_HAS_GLIBC_CUSTOM_STREAMS is not set +# UCLIBC_HAS_PRINTF_M_SPEC is not set +UCLIBC_HAS_ERRNO_MESSAGES=y +# UCLIBC_HAS_SYS_ERRLIST is not set +UCLIBC_HAS_SIGNUM_MESSAGES=y +# UCLIBC_HAS_SYS_SIGLIST is not set +UCLIBC_HAS_GNU_GETOPT=y +UCLIBC_HAS_GNU_GETSUBOPT=y + +# +# Big and Tall +# +UCLIBC_HAS_REGEX=y +UCLIBC_HAS_REGEX_OLD=y +UCLIBC_HAS_FNMATCH=y +UCLIBC_HAS_FNMATCH_OLD=y +# UCLIBC_HAS_WORDEXP is not set +# UCLIBC_HAS_NFTW is not set +# UCLIBC_HAS_FTW is not set +# UCLIBC_HAS_FTS is not set +UCLIBC_HAS_GLOB=y +# UCLIBC_HAS_GNU_GLOB is not set +# UCLIBC_HAS_UTMPX is not set + +# +# Library Installation Options +# +RUNTIME_PREFIX="/" +DEVEL_PREFIX="/usr" +MULTILIB_DIR="lib" +HARDWIRED_ABSPATH=y + +# +# Security options +# +# UCLIBC_HAS_ARC4RANDOM is not set +# UCLIBC_HAS_SSP is not set +UCLIBC_BUILD_RELRO=y +# UCLIBC_BUILD_NOW is not set +UCLIBC_BUILD_NOEXECSTACK=y + +# +# Development/debugging options +# +CROSS_COMPILER_PREFIX="or1k-linux-uclibc-" +UCLIBC_EXTRA_CFLAGS="" +# DODEBUG is not set +# DODEBUG_PT is not set +# DOSTRIP is not set +# DOASSERTS is not set +# SUPPORT_LD_DEBUG is not set +# SUPPORT_LD_DEBUG_EARLY is not set +# UCLIBC_MALLOC_DEBUGGING is not set +# UCLIBC_HAS_BACKTRACE is not set +WARNINGS="-Wall" +# EXTRA_WARNINGS is not set +# DOMULTI is not set +# UCLIBC_MJN3_ONLY is not set diff --git a/include/elf.h b/include/elf.h index 18d286b03..ed952664f 100644 --- a/include/elf.h +++ b/include/elf.h @@ -257,7 +257,7 @@ typedef struct #define EM_MN10300 89 /* Matsushita MN10300 */ #define EM_MN10200 90 /* Matsushita MN10200 */ #define EM_PJ 91 /* picoJava */ -#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ +#define EM_OR1K 92 /* OpenRISC 32-bit embedded processor */ #define EM_ARCOMPACT 93 /* ARCompact ISA based Cores: ARC 700 */ #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_IP2K 101 /* Ubicom IP2022 micro controller */ @@ -3188,6 +3188,30 @@ typedef Elf32_Addr Elf32_Conflict; #define R_METAG_TLS_DTPMOD 57 #define R_METAG_TLS_DTPOFF 58 +/* 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 + /* ARCompact specific relocs */ #define R_ARC_NONE 0x0 #define R_ARC_8 0x1 diff --git a/ldso/ldso/or1k/dl-debug.h b/ldso/ldso/or1k/dl-debug.h new file mode 100644 index 000000000..d925577cd --- /dev/null +++ b/ldso/ldso/or1k/dl-debug.h @@ -0,0 +1,53 @@ +/* OpenRISC 1000 shared library loader suppport + * + * Copyright (C) 2012 Stefan Kristansson + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +static const char * const _dl_reltypes_tab[] = + { + "R_OR1K_NONE", + "R_OR1K_32", + "R_OR1K_16", + "R_OR1K_8", + "R_OR1K_LO_16_IN_INSN", + "R_OR1K_HI_16_IN_INSN", + "R_OR1K_INSN_REL_26", + "R_OR1K_GNU_VTENTRY", + "R_OR1K_GNU_VTINHERIT", + "R_OR1K_32_PCREL", + "R_OR1K_16_PCREL", + "R_OR1K_8_PCREL", + "R_OR1K_GOTPC_HI16", + "R_OR1K_GOTPC_LO16", + "R_OR1K_GOT16", + "R_OR1K_PLT26", + "R_OR1K_GOTOFF_HI16", + "R_OR1K_GOTOFF_LO16", + "R_OR1K_COPY", + "R_OR1K_GLOB_DAT", + "R_OR1K_JMP_SLOT", + "R_OR1K_RELATIVE", + }; diff --git a/ldso/ldso/or1k/dl-startup.h b/ldso/ldso/or1k/dl-startup.h new file mode 100644 index 000000000..3c99bcd5c --- /dev/null +++ b/ldso/ldso/or1k/dl-startup.h @@ -0,0 +1,106 @@ +/* Startup code for the OpenRISC 1000 platform, + based on microblaze implementation */ +/* + 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. */ + +__asm__ ("\ + .text\n\ + .globl _start\n\ + .type _start,@function\n\ + .hidden _start\n\ +_start:\n\ + l.ori r3, r9, 0\n\ + l.ori r3, r1, 0\n\ + l.movhi r11, 0\n\ +1:\n\ + l.addi r3, r3, 4\n\ + l.lwz r12, 0(r3)\n\ + l.sfnei r12, 0\n\ + l.addi r11, r11, 1\n\ + l.bf 1b\n\ + l.nop\n\ + l.ori r3, r11, 0\n\ + l.ori r3, r1, 0\n\ + l.addi r11, r11, -1\n\ + /* store argument counter to stack */\n\ + l.sw 0(r3), r11\n\ + l.addi r1, r1, -24\n\ + l.sw 0(r1), r9\n\ +\n\ + l.jal .LPC0\n\ +#ifndef __OR1K_NODELAY__\n\ + l.nop\n\ +#endif\n\ + /* Load the PIC register */\n\ +.LPC0:\n\ + l.movhi r16, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC0))\n\ + l.ori r16, r16, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC0))\n\ + l.add r16, r16, r9\n\ +\n\ + l.jal _dl_start\n\ + l.nop\n\ + /* FALLTHRU */\n\ +\n\ + .globl _dl_start_user\n\ + .type _dl_start_user,@function\n\ +_dl_start_user:\n\ + l.movhi r12, gotoffhi(_dl_skip_args)\n\ + l.ori r12, r12, gotofflo(_dl_skip_args)\n\ + l.add r12, r12, r16\n\ + l.lwz r12, 0(r12)\n\ + l.lwz r3, 24(r1)\n\ +\n\ + l.movhi r9, gotoffhi(_dl_fini)\n\ + l.ori r9, r9, gotofflo(_dl_fini)\n\ + l.add r9, r9, r16\n\ +\n\ + l.addi r9, r9, -8\n\ + l.addi r1, r1, 24\n\ + l.jr r11\n\ + l.nop\n\ + .size _dl_start_user, . - _dl_start_user\n\ + .previous\n\ +"); +/* + * Get a pointer to the argv array. On many platforms this can be just + * the address of the first argument, on other platforms we need to + * do something a little more subtle here. + */ +#define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long*) ARGS)+1) + +/* The ld.so library requires relocations */ +#define ARCH_NEEDS_BOOTSTRAP_RELOCS + +static __always_inline +void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, + unsigned long symbol_addr, unsigned long load_addr, + attribute_unused Elf32_Sym *symtab) +{ + + switch (ELF_R_TYPE(rpnt->r_info)) + { + case R_OR1K_RELATIVE: + + *reloc_addr = load_addr + rpnt->r_addend; + break; + + default: + _dl_exit(1); + break; + + } + +} diff --git a/ldso/ldso/or1k/dl-syscalls.h b/ldso/ldso/or1k/dl-syscalls.h new file mode 100644 index 000000000..f40c4fd31 --- /dev/null +++ b/ldso/ldso/or1k/dl-syscalls.h @@ -0,0 +1 @@ +/* stub for arch-specific syscall issues */ diff --git a/ldso/ldso/or1k/dl-sysdep.h b/ldso/ldso/or1k/dl-sysdep.h new file mode 100644 index 000000000..21ca028c8 --- /dev/null +++ b/ldso/ldso/or1k/dl-sysdep.h @@ -0,0 +1,105 @@ +/* elf reloc code for the or1k platform, based on glibc 2.3.6, dl-machine.h */ + +/* + 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. */ + +/* Use reloca */ +#define ELF_USES_RELOCA + +#include <elf.h> + + +/* Initialise the GOT */ +#define INIT_GOT(GOT_BASE,MODULE) \ +do { \ + GOT_BASE[2] = (unsigned long) _dl_linux_resolve; \ + GOT_BASE[1] = (unsigned long) MODULE; \ +} while(0) + +/* Here we define the magic numbers that this dynamic loader should accept */ + +#define MAGIC1 EM_OR1K +#undef MAGIC2 +/* Used for error messages */ +#define ELF_TARGET "or1k" + +#define elf_machine_type_class(type) \ + (((type) == R_OR1K_JMP_SLOT) * ELF_RTYPE_CLASS_PLT \ + | ((type) == R_OR1K_COPY) * ELF_RTYPE_CLASS_COPY) + +static inline Elf32_Addr * +or1k_get_got (void) +{ + Elf32_Addr *got; + Elf32_Addr linkreg; + __asm__("l.ori %0, r9, 0\n" + "l.jal .LPC1\n" +#ifndef __OR1K_NODELAY__ + "l.nop\n" +#endif + ".LPC1:\n" + "l.movhi %1, gotpchi(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n" + "l.ori %1, %1, gotpclo(_GLOBAL_OFFSET_TABLE_+(.-.LPC1))\n" + "l.add %1, %1, r9\n" + "l.ori r9, %0, 0\n" + : "=r" (linkreg), "=r" (got)); + 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__ __volatile__ ( + "l.movhi %0, gotoffhi(_DYNAMIC);" + "l.ori %0, %0, gotofflo(_DYNAMIC);" + "l.add %0, %0, %1;" + : "=r"(dyn), "=r"(got) + ); + return dyn - *got; +} + + + +static __always_inline void +elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr, + Elf32_Word relative_count) +{ + Elf32_Rela * rpnt = (void *) rel_addr; + --rpnt; + do { + Elf32_Addr *const reloc_addr = (void *) (load_off + + (++rpnt)->r_offset); + + *reloc_addr += load_off; + } while (--relative_count); +} diff --git a/ldso/ldso/or1k/elfinterp.c b/ldso/ldso/or1k/elfinterp.c new file mode 100644 index 000000000..928e95ba1 --- /dev/null +++ b/ldso/ldso/or1k/elfinterp.c @@ -0,0 +1,333 @@ +/* vi: set sw=4 ts=4: */ +/* OpenRISC 1000 ELF shared library loader suppport + * + * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald, + * David Engel, Hongjiu Lu and Mitch D'Souza + * Copyright (C) 2001-2004 Erik Andersen + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. The name of the above contributors may not be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "ldso.h" + +/* Program to load an ELF binary on a linux system, and run it. + References to symbols in sharable libraries can be resolved by either + an ELF sharable library or a linux style of shared library. */ + +/* Disclaimer: I have never seen any AT&T source code for SVr4, nor have + I ever taken any courses on internals. This program was developed using + information available through the book "UNIX SYSTEM V RELEASE 4, + Programmers guide: Ansi C and Programming Support Tools", which did + a more than adequate job of explaining everything required to get this + working. */ + +extern int _dl_linux_resolve(void); + +unsigned long +_dl_linux_resolver(struct elf_resolve *tpnt, int reloc_entry) +{ + ELF_RELOC *this_reloc; + char *strtab; + ElfW(Sym) *symtab; + int symtab_index; + char *rel_addr; + char *new_addr; + char **got_addr; + ElfW(Addr) instr_addr; + char *symname; + + rel_addr = (char *)tpnt->dynamic_info[DT_JMPREL]; + this_reloc = (ELF_RELOC *)(rel_addr + reloc_entry); + symtab_index = ELF_R_SYM(this_reloc->r_info); + + symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + symname = strtab + symtab[symtab_index].st_name; + + /* Address of the jump instruction to fix up. */ + instr_addr = (this_reloc->r_offset + tpnt->loadaddr); + got_addr = (char **)instr_addr; + + /* Get the address of the GOT entry. */ + new_addr = _dl_find_hash(symname, &_dl_loaded_modules->symbol_scope, tpnt, ELF_RTYPE_CLASS_PLT, NULL); + if (unlikely(!new_addr)) { + _dl_dprintf(2, "%s: can't resolve symbol '%s' in lib '%s'.\n", + _dl_progname, symname, tpnt->libname); + _dl_exit(1); + } + +#if defined (__SUPPORT_LD_DEBUG__) + if ((unsigned long)got_addr < 0x40000000) { + if (_dl_debug_bindings) { + _dl_dprintf(_dl_debug_file, "\nresolve function: %s", symname); + if (_dl_debug_detail) + _dl_dprintf(_dl_debug_file, + "\tpatched: %x ==> %x @ %x\n", + *got_addr, new_addr, got_addr); + } + } + if (!_dl_debug_nofixups) +#endif + *got_addr = new_addr; + + return (unsigned long)new_addr; +} + +static int +_dl_parse(struct elf_resolve *tpnt, struct r_scope_elem *scope, + unsigned long rel_addr, unsigned long rel_size, + int (*reloc_fnc)(struct elf_resolve *tpnt, struct r_scope_elem *scope, + ELF_RELOC *rpnt, ElfW(Sym) *symtab, char *strtab)) +{ + unsigned int i; + char *strtab; + ElfW(Sym) *symtab; + ELF_RELOC *rpnt; + int symtab_index; + + /* Parse the relocation information. */ + rpnt = (ELF_RELOC *)rel_addr; + rel_size /= sizeof(ELF_RELOC); + + symtab = (ElfW(Sym) *)tpnt->dynamic_info[DT_SYMTAB]; + strtab = (char *)tpnt->dynamic_info[DT_STRTAB]; + + for (i = 0; i < rel_size; i++, rpnt++) { + int res; + + symtab_index = ELF_R_SYM(rpnt->r_info); + + debug_sym(symtab, strtab, symtab_index); + debug_reloc(symtab, strtab, rpnt); + + res = reloc_fnc(tpnt, scope, rpnt, symtab, strtab); + + if (res == 0) + continue; + + _dl_dprintf(2, "\n%s: ", _dl_progname); + + if (symtab_index) + _dl_dprintf(2, "symbol '%s': ", + strtab + symtab[symtab_index].st_name); + + if (unlikely(res < 0)) { + int reloc_type = ELF_R_TYPE(rpnt->r_info); + + _dl_dprintf(2, "can't handle reloc type " +#if defined (__SUPPORT_LD_DEBUG__) + "%s\n", _dl_reltypes(reloc_type)); +#else + "%x\n", reloc_type); +#endif + _dl_exit(-res); |