mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-05 14:38:57 +08:00
cpukit: Add libdl with the Runtime Loader (RTL) code.
This is a merge of the RTL project.
This commit is contained in:
1 parent
513668f6f1
commit
ae5fe7e6bc
91 files changed
+14746
-5
No files matched your search
+19
-1
@@ -11,6 +11,7 @@ SUBDIRS += libi2c
|
||||
SUBDIRS += libmisc
|
||||
SUBDIRS += libmd
|
||||
SUBDIRS += libgnat
|
||||
SUBDIRS += libdl
|
||||
SUBDIRS += wrapup
|
||||
|
||||
SUBDIRS += zlib
|
||||
@@ -41,7 +42,6 @@ include_uuid_HEADERS = libmisc/uuid/uuid.h
|
||||
include_utf8procdir = $(includedir)/utf8proc
|
||||
include_utf8proc_HEADERS = libmisc/utf8proc/utf8proc.h
|
||||
|
||||
if NEWLIB
|
||||
include_sysdir = $(includedir)/sys
|
||||
include_sys_HEADERS =
|
||||
|
||||
@@ -69,6 +69,24 @@ include_rtems_bsdnetdir = $(includedir)/rtems/bsdnet
|
||||
include_rtems_bsdnet_HEADERS = libnetworking/rtems/bsdnet/servers.h
|
||||
include_rtems_bsdnet_HEADERS += libnetworking/rtems/bsdnet/_types.h
|
||||
endif
|
||||
|
||||
if LIBDL
|
||||
include_HEADERS += libdl/dlfcn.h
|
||||
include_HEADERS += libdl/include/link.h
|
||||
include_HEADERS += libdl/include/link_elf.h
|
||||
include_sys_HEADERS += libdl/include/sys/cdefs_elf.h
|
||||
include_sys_HEADERS += libdl/include/sys/exec_elf.h
|
||||
include_arch_machinedir = $(includedir)/machine
|
||||
include_arch_machine_HEADERS =
|
||||
include_arch_machine_HEADERS += libdl/include/arch/@RTEMS_CPU@/machine/elf_machdep.h
|
||||
include_rtems_rtldir = $(includedir)/rtems/rtl
|
||||
include_rtems_rtl_HEADERS =
|
||||
include_rtems_rtl_HEADERS += libdl/dlfcn-shell.h
|
||||
include_rtems_rtl_HEADERS += libdl/rtl.h libdl/rtl-allocator.h libdl/rtl-obj-fwd.h
|
||||
include_rtems_rtl_HEADERS += libdl/rtl-fwd.h libdl/rtl-obj.h libdl/rtl-obj-cache.h
|
||||
include_rtems_rtl_HEADERS += libdl/rtl-obj-comp.h libdl/rtl-unresolved.h
|
||||
include_rtems_rtl_HEADERS += libdl/rtl-indirect-ptr.h libdl/rtl-sym.h
|
||||
include_rtems_rtl_HEADERS += libdl/rap.h libdl/rap-shell.h
|
||||
endif
|
||||
|
||||
include_rtems_HEADERS += include/rtems/bspIo.h
|
||||
|
||||
+16
-2
@@ -298,7 +298,7 @@ AC_ENABLE_MULTILIB([Makefile],[..])
|
||||
AC_MSG_CHECKING([for assignable stdio])
|
||||
AC_COMPILE_IFELSE(
|
||||
[AC_LANG_PROGRAM(
|
||||
[#include <stdio.h>],
|
||||
[#include <stdio.h>],
|
||||
[stdin = fopen("/tmp", "r")])],
|
||||
[HAVE_ASSIGNABLE_STDIO=yes],
|
||||
[HAVE_ASSIGNABLE_STDIO=no])
|
||||
@@ -322,7 +322,7 @@ AC_CHECK_SIZEOF([time_t])
|
||||
|
||||
AC_CHECK_SIZEOF([size_t])
|
||||
|
||||
# FIXME: Mandatory in SUSv4, optional in SUSv3.
|
||||
# FIXME: Mandatory in SUSv4, optional in SUSv3.
|
||||
# Not implemented in GCC/newlib, so far.
|
||||
AC_CHECK_DECLS([WORD_BIT],,,[#include <limits.h>])
|
||||
AC_CHECK_DECLS([LONG_BIT],,,[#include <limits.h>])
|
||||
@@ -372,6 +372,19 @@ AM_CONDITIONAL([RPCTOOLS],[test "$RPCGEN" = rpcgen \
|
||||
&& test -n "$AWK" \
|
||||
&& test "$enable_rpcgen" = yes])
|
||||
|
||||
# Filter dynamic loading to only build for architectures that have
|
||||
# reloc backends
|
||||
AC_MSG_CHECKING([whether CPU supports libdl])
|
||||
case $RTEMS_CPU in
|
||||
arm | bfin | h8300 | i386 | lm32 | m32r | m68k | mips | \
|
||||
moxie | nios2 | powerpc | sparc | v850)
|
||||
HAVE_LIBDL=yes ;;
|
||||
*)
|
||||
HAVE_LIBDL=no ;;
|
||||
esac
|
||||
AM_CONDITIONAL(LIBDL,[test x"$HAVE_LIBDL" = x"yes"])
|
||||
AC_MSG_RESULT([$HAVE_LIBDL])
|
||||
|
||||
RTEMS_AMPOLISH3
|
||||
|
||||
# Explicitly list all Makefiles here
|
||||
@@ -412,6 +425,7 @@ librpc/Makefile
|
||||
libmisc/Makefile
|
||||
libi2c/Makefile
|
||||
libmd/Makefile
|
||||
libdl/Makefile
|
||||
zlib/Makefile
|
||||
ftpd/Makefile
|
||||
telnetd/Makefile
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
if LIBDL
|
||||
|
||||
include $(top_srcdir)/automake/compile.am
|
||||
|
||||
noinst_LIBRARIES = libdl.a
|
||||
libdl_a_SOURCES = \
|
||||
dlfcn-shell.c \
|
||||
dlfcn.c \
|
||||
fastlz.c \
|
||||
rap-shell.c \
|
||||
rap.c \
|
||||
rtl.c \
|
||||
rtl-alloc-heap.c \
|
||||
rtl-allocator.c \
|
||||
rtl-chain-iterator.c \
|
||||
rtl-debugger.c \
|
||||
rtl-elf.c \
|
||||
rtl-error.c \
|
||||
rtl-find-file.c \
|
||||
rtl-obj-cache.c \
|
||||
rtl-obj-comp.c \
|
||||
rtl-obj.c \
|
||||
rtl-rap.c \
|
||||
rtl-shell.c \
|
||||
rtl-string.c \
|
||||
rtl-sym.c \
|
||||
rtl-trace.c \
|
||||
rtl-unresolved.c
|
||||
|
||||
libdl_a_SOURCES += rtl-mdreloc-@RTEMS_CPU@.c
|
||||
libdl_a_CPPFLAGS = $(AM_CPPFLAGS) -DRTEMS_RTL_RAP_LOADER=1 -DRTEMS_RTL_ELF_LOADER=1
|
||||
|
||||
include $(srcdir)/preinstall.am
|
||||
include $(top_srcdir)/automake/local.am
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtld
|
||||
*
|
||||
* @brief RTEMS Run-Time Link Editor Dynamic Loading API Shell Support.
|
||||
*
|
||||
* Shell command wrappers for the Dynamic Loading API.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <rtems/rtl/dlfcn-shell.h>
|
||||
|
||||
static void*
|
||||
convert_ascii_to_voidp (const char* arg)
|
||||
{
|
||||
if (strcmp (arg, "base") == 0)
|
||||
return RTLD_DEFAULT;
|
||||
return (void*) strtoul (arg, NULL, 16);
|
||||
}
|
||||
|
||||
int
|
||||
shell_dlopen (int argc, char* argv[])
|
||||
{
|
||||
int arg;
|
||||
for (arg = 1; arg < argc; arg++)
|
||||
{
|
||||
void* handle = dlopen (argv[arg], RTLD_NOW | RTLD_GLOBAL);
|
||||
if (handle)
|
||||
{
|
||||
int unresolved;
|
||||
char* message = "loaded";
|
||||
if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0)
|
||||
message = "dlinfo error checking unresolved status";
|
||||
else if (unresolved)
|
||||
message = "has unresolved externals";
|
||||
printf ("handle: %p %s\n", handle, message);
|
||||
}
|
||||
else
|
||||
printf ("error: %s\n", dlerror ());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
shell_dlclose (int argc, char* argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool
|
||||
lookup_dlsym (void** value, int argc, char* argv[])
|
||||
{
|
||||
if (argc >= 3)
|
||||
{
|
||||
void* handle = convert_ascii_to_voidp (argv[1]);
|
||||
if (handle)
|
||||
{
|
||||
*value = dlsym (handle, argv[2]);
|
||||
if (*value)
|
||||
return true;
|
||||
else
|
||||
printf ("error: invalid handle or symbol\n");
|
||||
}
|
||||
else
|
||||
printf ("error: invalid handle");
|
||||
}
|
||||
else
|
||||
printf ("error: requires handle and symbol name\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
shell_dlsym (int argc, char* argv[])
|
||||
{
|
||||
void* value;
|
||||
if (lookup_dlsym (&value, argc, argv))
|
||||
{
|
||||
printf ("%s = %p\n", argv[2], value);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
typedef int (*call_t)(int argc, char* argv[]);
|
||||
|
||||
int
|
||||
shell_dlcall (int argc, char* argv[])
|
||||
{
|
||||
void* value;
|
||||
if (lookup_dlsym (&value, argc, argv))
|
||||
{
|
||||
call_t call = value;
|
||||
int r;
|
||||
printf ("(*%p)(%d, ....)\n", value, argc - 3);
|
||||
r = call (argc - 3, argv + 3);
|
||||
printf ("return %d\n", r);
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if !defined(_DLFCN_SHELL_H_)
|
||||
#define _DLFCN_SHELL_H_
|
||||
|
||||
int shell_dlopen (int argc, char* argv[]);
|
||||
int shell_dlclose (int argc, char* argv[]);
|
||||
int shell_dlsym (int argc, char* argv[]);
|
||||
int shell_dlcall (int argc, char* argv[]);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtl
|
||||
*
|
||||
* @brief RTEMS POSIX Dynamic Module Loading Interface.
|
||||
*
|
||||
* This is the POSIX interface to run-time loading of code into RTEMS.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <dlfcn.h>
|
||||
#include <rtems/rtl/rtl.h>
|
||||
|
||||
static rtems_rtl_obj_t*
|
||||
dl_get_obj_from_handle (void* handle)
|
||||
{
|
||||
rtems_rtl_obj_t* obj;
|
||||
|
||||
/*
|
||||
* Handle the special cases provided in NetBSD and Sun documentation.
|
||||
* http://download.oracle.com/docs/cd/E19253-01/816-5168/dlsym-3c/index.html
|
||||
* We currently do not manage the loading dependences in the module mappings
|
||||
* so we cannot handle the searching based on loading order where overriding
|
||||
* can occur.
|
||||
*/
|
||||
|
||||
if ((handle == RTLD_DEFAULT) || (handle == RTLD_SELF))
|
||||
obj = rtems_rtl_baseimage ();
|
||||
else
|
||||
obj = rtems_rtl_check_handle (handle);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
void*
|
||||
dlopen (const char* name, int mode)
|
||||
{
|
||||
rtems_rtl_obj_t* obj = NULL;
|
||||
|
||||
if (!rtems_rtl_lock ())
|
||||
return NULL;
|
||||
|
||||
_rtld_debug.r_state = RT_ADD;
|
||||
_rtld_debug_state ();
|
||||
|
||||
if (name)
|
||||
obj = rtems_rtl_load_object (name, mode);
|
||||
else
|
||||
obj = rtems_rtl_baseimage ();
|
||||
|
||||
_rtld_debug.r_state = RT_CONSISTENT;
|
||||
_rtld_debug_state();
|
||||
|
||||
rtems_rtl_unlock ();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
int
|
||||
dlclose (void* handle)
|
||||
{
|
||||
rtems_rtl_obj_t* obj;
|
||||
int r;
|
||||
|
||||
if (!rtems_rtl_lock ())
|
||||
return -1;
|
||||
|
||||
obj = rtems_rtl_check_handle (handle);
|
||||
if (!obj)
|
||||
{
|
||||
rtems_rtl_unlock ();
|
||||
return -1;
|
||||
}
|
||||
|
||||
_rtld_debug.r_state = RT_DELETE;
|
||||
_rtld_debug_state ();
|
||||
|
||||
r = rtems_rtl_unload_object (obj) ? 0 : -1;
|
||||
|
||||
_rtld_debug.r_state = RT_CONSISTENT;
|
||||
_rtld_debug_state ();
|
||||
|
||||
rtems_rtl_unlock ();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void*
|
||||
dlsym (void* handle, const char *symbol)
|
||||
{
|
||||
rtems_rtl_obj_t* obj;
|
||||
rtems_rtl_obj_sym_t* sym;
|
||||
void* symval = NULL;
|
||||
|
||||
if (!rtems_rtl_lock ())
|
||||
return NULL;
|
||||
|
||||
obj = dl_get_obj_from_handle (handle);
|
||||
if (obj)
|
||||
{
|
||||
sym = rtems_rtl_symbol_obj_find (obj, symbol);
|
||||
if (sym)
|
||||
symval = sym->value;
|
||||
}
|
||||
|
||||
rtems_rtl_unlock ();
|
||||
|
||||
return symval;
|
||||
}
|
||||
|
||||
const char*
|
||||
dlerror (void)
|
||||
{
|
||||
static char msg[64];
|
||||
rtems_rtl_get_error (msg, sizeof (msg));
|
||||
return msg;
|
||||
}
|
||||
|
||||
int
|
||||
dlinfo (void* handle, int request, void* p)
|
||||
{
|
||||
rtems_rtl_obj_t* obj;
|
||||
int rc = -1;
|
||||
|
||||
if (!rtems_rtl_lock () || !p)
|
||||
return -1;
|
||||
|
||||
obj = dl_get_obj_from_handle (handle);
|
||||
if (obj)
|
||||
{
|
||||
switch (request)
|
||||
{
|
||||
case RTLD_DI_UNRESOLVED:
|
||||
*((int*) p) = rtems_rtl_obj_unresolved (obj) ? 1 : 0;
|
||||
rc = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rtems_rtl_unlock ();
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/* $NetBSD: dlfcn.h,v 1.21 2010/01/07 07:35:35 skrll Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Paul Kranenburg.
|
||||
*
|
||||
* 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. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 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 FOUNDATION OR 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.
|
||||
*/
|
||||
|
||||
#ifndef _DLFCN_H_
|
||||
#define _DLFCN_H_
|
||||
|
||||
//#include <sys/featuretest.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
typedef struct _dl_info {
|
||||
const char *dli_fname; /* File defining the symbol */
|
||||
void *dli_fbase; /* Base address */
|
||||
const char *dli_sname; /* Symbol name */
|
||||
const void *dli_saddr; /* Symbol address */
|
||||
} Dl_info;
|
||||
#endif /* defined(_NETBSD_SOURCE) */
|
||||
|
||||
/*
|
||||
* User interface to the run-time linker.
|
||||
*/
|
||||
__BEGIN_DECLS
|
||||
void *dlopen(const char *, int);
|
||||
int dlclose(void *);
|
||||
void *dlsym(void * __restrict, const char * __restrict);
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
int dladdr(void * __restrict, Dl_info * __restrict);
|
||||
int dlctl(void *, int, void *);
|
||||
#endif
|
||||
int dlinfo(void *, int, void *);
|
||||
const char *dlerror(void);
|
||||
__END_DECLS
|
||||
|
||||
/* Values for dlopen `mode'. */
|
||||
#define RTLD_LAZY 1
|
||||
#define RTLD_NOW 2
|
||||
#define RTLD_GLOBAL 0x100 /* Allow global searches in object */
|
||||
#define RTLD_LOCAL 0x200
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
#define DL_LAZY RTLD_LAZY /* Compat */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Special handle arguments for dlsym().
|
||||
*/
|
||||
#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
|
||||
#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
|
||||
#define RTLD_SELF ((void *) -3) /* Search the caller itself. */
|
||||
|
||||
/*
|
||||
* dlctl() commands
|
||||
*/
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
#define DL_GETERRNO 1
|
||||
#define DL_GETSYMBOL 2
|
||||
#if 0
|
||||
#define DL_SETSRCHPATH x
|
||||
#define DL_GETLIST x
|
||||
#define DL_GETREFCNT x
|
||||
#define DL_GETLOADADDR x
|
||||
#endif /* 0 */
|
||||
#endif /* defined(_NETBSD_SOURCE) */
|
||||
|
||||
/*
|
||||
* dlinfo() commands
|
||||
*
|
||||
* From Solaris: http://docs.sun.com/app/docs/doc/816-5168/dlinfo-3c?a=view
|
||||
*/
|
||||
#define RTLD_DI_UNRESOLVED 10
|
||||
#if defined(_NETBSD_SOURCE)
|
||||
#define RTLD_DI_LINKMAP 3
|
||||
#if 0
|
||||
#define RTLD_DI_ARGSINFO 1
|
||||
#define RTLD_DI_CONFIGADDR 2
|
||||
#define RTLD_DI_LMID 4
|
||||
#define RTLD_DI_SERINFO 5
|
||||
#define RTLD_DI_SERINFOSIZE 6
|
||||
#define RTLD_DI_ORIGIN 7
|
||||
#define RTLD_DI_GETSIGNAL 8
|
||||
#define RTLD_DI_SETSIGNAL 9
|
||||
#endif
|
||||
#endif /* _NETBSD_SOURCE */
|
||||
|
||||
#endif /* !defined(_DLFCN_H_) */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
FastLZ - lightning-fast lossless compression library
|
||||
|
||||
Copyright (C) 2007 Ariya Hidayat (ariya@kde.org)
|
||||
Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
|
||||
Copyright (C) 2005 Ariya Hidayat (ariya@kde.org)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
*/
|
||||
|
||||
#ifndef FASTLZ_H
|
||||
#define FASTLZ_H
|
||||
|
||||
#define FASTLZ_VERSION 0x000100
|
||||
|
||||
#define FASTLZ_VERSION_MAJOR 0
|
||||
#define FASTLZ_VERSION_MINOR 0
|
||||
#define FASTLZ_VERSION_REVISION 0
|
||||
|
||||
#define FASTLZ_VERSION_STRING "0.1.0"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
minimum input buffer size is 16.
|
||||
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
and can not be smaller than 66 bytes.
|
||||
|
||||
If the input is not compressible, the return value might be larger than
|
||||
length (input buffer size).
|
||||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
*/
|
||||
|
||||
int fastlz_compress(const void* input, int length, void* output);
|
||||
|
||||
/**
|
||||
Decompress a block of compressed data and returns the size of the
|
||||
decompressed block. If error occurs, e.g. the compressed data is
|
||||
corrupted or the output buffer is not large enough, then 0 (zero)
|
||||
will be returned instead.
|
||||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
|
||||
Decompression is memory safe and guaranteed not to write the output buffer
|
||||
more than what is specified in maxout.
|
||||
*/
|
||||
|
||||
int fastlz_decompress(const void* input, int length, void* output, int maxout);
|
||||
|
||||
/**
|
||||
Compress a block of data in the input buffer and returns the size of
|
||||
compressed block. The size of input buffer is specified by length. The
|
||||
minimum input buffer size is 16.
|
||||
|
||||
The output buffer must be at least 5% larger than the input buffer
|
||||
and can not be smaller than 66 bytes.
|
||||
|
||||
If the input is not compressible, the return value might be larger than
|
||||
length (input buffer size).
|
||||
|
||||
The input buffer and the output buffer can not overlap.
|
||||
|
||||
Compression level can be specified in parameter level. At the moment,
|
||||
only level 1 and level 2 are supported.
|
||||
Level 1 is the fastest compression and generally useful for short data.
|
||||
Level 2 is slightly slower but it gives better compression ratio.
|
||||
|
||||
Note that the compressed data, regardless of the level, can always be
|
||||
decompressed using the function fastlz_decompress above.
|
||||
*/
|
||||
|
||||
int fastlz_compress_level(int level, const void* input, int length, void* output);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FASTLZ_H */
|
||||
@@ -0,0 +1,131 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.8 2009/05/30 05:56:52 skrll Exp $ */
|
||||
|
||||
#if defined(__ARMEB__)
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#else
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
|
||||
#endif
|
||||
|
||||
#define ELF64_MACHDEP_ENDIANNESS XXX /* break compilation */
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
/* no 64-bit ELF machine types supported */
|
||||
|
||||
/* Processor specific flags for the ELF header e_flags field. */
|
||||
#define EF_ARM_RELEXEC 0x00000001
|
||||
#define EF_ARM_HASENTRY 0x00000002
|
||||
#define EF_ARM_INTERWORK 0x00000004 /* GNU binutils 000413 */
|
||||
#define EF_ARM_SYMSARESORTED 0x00000004 /* ARM ELF A08 */
|
||||
#define EF_ARM_APCS_26 0x00000008 /* GNU binutils 000413 */
|
||||
#define EF_ARM_DYNSYMSUSESEGIDX 0x00000008 /* ARM ELF B01 */
|
||||
#define EF_ARM_APCS_FLOAT 0x00000010 /* GNU binutils 000413 */
|
||||
#define EF_ARM_MAPSYMSFIRST 0x00000010 /* ARM ELF B01 */
|
||||
#define EF_ARM_PIC 0x00000020
|
||||
#define EF_ARM_ALIGN8 0x00000040 /* 8-bit structure alignment. */
|
||||
#define EF_ARM_NEW_ABI 0x00000080
|
||||
#define EF_ARM_OLD_ABI 0x00000100
|
||||
#define EF_ARM_SOFT_FLOAT 0x00000200
|
||||
#define EF_ARM_EABIMASK 0xff000000
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_ARM: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_ARM
|
||||
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
|
||||
/* Processor specific relocation types */
|
||||
|
||||
#define R_ARM_NONE 0
|
||||
#define R_ARM_PC24 1
|
||||
#define R_ARM_ABS32 2
|
||||
#define R_ARM_REL32 3
|
||||
#define R_ARM_PC13 4
|
||||
#define R_ARM_ABS16 5
|
||||
#define R_ARM_ABS12 6
|
||||
#define R_ARM_THM_ABS5 7
|
||||
#define R_ARM_ABS8 8
|
||||
#define R_ARM_SBREL32 9
|
||||
#define R_ARM_THM_CALL 10
|
||||
#define R_ARM_THM_PC8 11
|
||||
#define R_ARM_AMP_VCALL9 12
|
||||
#define R_ARM_SWI24 13
|
||||
#define R_ARM_THM_SWI8 14
|
||||
#define R_ARM_XPC25 15
|
||||
#define R_ARM_THM_XPC22 16
|
||||
|
||||
/* TLS relocations */
|
||||
#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */
|
||||
#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */
|
||||
#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */
|
||||
|
||||
/* 20-31 are reserved for ARM Linux. */
|
||||
#define R_ARM_COPY 20
|
||||
#define R_ARM_GLOB_DAT 21
|
||||
#define R_ARM_JUMP_SLOT 22
|
||||
#define R_ARM_RELATIVE 23
|
||||
#define R_ARM_GOTOFF 24
|
||||
#define R_ARM_GOTPC 25
|
||||
#define R_ARM_GOT32 26
|
||||
#define R_ARM_PLT32 27
|
||||
#define R_ARM_CALL 28
|
||||
#define R_ARM_JUMP24 29
|
||||
#define R_ARM_THM_JUMP24 30
|
||||
#define R_ARM_BASE_ABS 31
|
||||
|
||||
#define R_ARM_ALU_PCREL_7_0 32
|
||||
#define R_ARM_ALU_PCREL_15_8 33
|
||||
#define R_ARM_ALU_PCREL_23_15 34
|
||||
#define R_ARM_ALU_SBREL_11_0 35
|
||||
#define R_ARM_ALU_SBREL_19_12 36
|
||||
#define R_ARM_ALU_SBREL_27_20 37
|
||||
#define R_ARM_V4BX 40
|
||||
#define R_ARM_PREL31 41
|
||||
|
||||
#define R_ARM_MOVW_ABS_NC 43
|
||||
#define R_ARM_MOVT_ABS 44
|
||||
|
||||
#define R_ARM_THM_MOVW_ABS_NC 47
|
||||
#define R_ARM_THM_MOVT_ABS 48
|
||||
|
||||
#define R_ARM_THM_JUMP19 51
|
||||
|
||||
/* 96-111 are reserved to G++. */
|
||||
#define R_ARM_GNU_VTENTRY 100
|
||||
#define R_ARM_GNU_VTINHERIT 101
|
||||
#define R_ARM_THM_JUMP11 102
|
||||
#define R_ARM_THM_JUMP8 103
|
||||
|
||||
/* More TLS relocations */
|
||||
#define R_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic */
|
||||
#define R_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic */
|
||||
#define R_ARM_TLS_LDO32 106 /* 32 bit offset relative to TLS */
|
||||
#define R_ARM_TLS_IE32 107 /* PC-rel 32 bit for GOT entry of */
|
||||
#define R_ARM_TLS_LE32 108
|
||||
#define R_ARM_TLS_LDO12 109
|
||||
#define R_ARM_TLS_LE12 110
|
||||
#define R_ARM_TLS_IE12GP 111
|
||||
|
||||
/* 112-127 are reserved for private experiments. */
|
||||
|
||||
#define R_ARM_RXPC25 249
|
||||
#define R_ARM_RSBREL32 250
|
||||
#define R_ARM_THM_RPC22 251
|
||||
#define R_ARM_RREL32 252
|
||||
#define R_ARM_RABS32 253
|
||||
#define R_ARM_RPC24 254
|
||||
#define R_ARM_RBASE 255
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_ARM_,name)
|
||||
|
||||
/* Processor specific program header flags */
|
||||
#define PF_ARM_SB 0x10000000
|
||||
#define PF_ARM_PI 0x20000000
|
||||
#define PF_ARM_ENTRY 0x80000000
|
||||
|
||||
/* Processor specific section header flags */
|
||||
#define SHF_ENTRYSECT 0x10000000
|
||||
#define SHF_COMDEF 0x80000000
|
||||
|
||||
/* Processor specific symbol types */
|
||||
#define STT_ARM_TFUNC STT_LOPROC
|
||||
@@ -0,0 +1,28 @@
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_BLACKFIN: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_BLACKFIN
|
||||
|
||||
#define ARCH_ELFSIZE 32
|
||||
|
||||
#define R_BFIN_UNUSED0 0
|
||||
|
||||
#define R_BFIN_RIMM16 5
|
||||
#define R_BFIN_LUIMM16 6
|
||||
#define R_BFIN_HUIMM16 7
|
||||
#define R_BFIN_PCREL12_JUMP_S 8
|
||||
#define R_BFIN_PCREL24_JUMP_X 9
|
||||
#define R_BFIN_PCREL24 10
|
||||
#define R_BFIN_PCREL24_JU 13
|
||||
#define R_BFIN_PCREL24_CALL_X 14
|
||||
|
||||
#define R_BFIN_BYTE_DATA 16
|
||||
#define R_BFIN_BYTE2_DATA 17
|
||||
#define R_BFIN_BYTE4_DATA 18
|
||||
|
||||
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_BFIN_,name)
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_H8_300: \
|
||||
case EM_H8_300H: \
|
||||
case EM_H8S: \
|
||||
case EM_H8_500: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_H8_300
|
||||
#define ARCH_ELFSIZE 32
|
||||
|
||||
#define R_H8_NONE 0
|
||||
#define R_H8_DIR32 1
|
||||
#define R_H8_DIR32_28 2
|
||||
#define R_H8_DIR32_24 3
|
||||
#define R_H8_DIR32_16 4
|
||||
#define R_H8_DIR32U 6
|
||||
#define R_H8_DIR32U_28 7
|
||||
#define R_H8_DIR32U_24 8
|
||||
#define R_H8_DIR32U_20 9
|
||||
#define R_H8_DIR32U_16 10
|
||||
#define R_H8_DIR24 11
|
||||
#define R_H8_DIR24_20 12
|
||||
#define R_H8_DIR24_16 13
|
||||
#define R_H8_DIR24U 14
|
||||
#define R_H8_DIR24U_20 15
|
||||
#define R_H8_DIR24U_16 16
|
||||
#define R_H8_DIR16 17
|
||||
#define R_H8_DIR16U 18
|
||||
#define R_H8_DIR16S_32 19
|
||||
#define R_H8_DIR16S_28 20
|
||||
#define R_H8_DIR16S_24 21
|
||||
#define R_H8_DIR16S_20 22
|
||||
#define R_H8_DIR16S 23
|
||||
#define R_H8_DIR8 24
|
||||
#define R_H8_DIR8U 25
|
||||
#define R_H8_DIR8Z_32 26
|
||||
#define R_H8_DIR8Z_28 27
|
||||
#define R_H8_DIR8Z_24 28
|
||||
#define R_H8_DIR8Z_20 29
|
||||
#define R_H8_DIR8Z_16 30
|
||||
#define R_H8_PCREL16 31
|
||||
#define R_H8_PCREL8 32
|
||||
#define R_H8_BPOS 33
|
||||
#define R_H8_PCREL32 34
|
||||
#define R_H8_GOT32O 35
|
||||
#define R_H8_GOT16O 36
|
||||
#define R_H8_DIR16A8 59
|
||||
#define R_H8_DIR16R8 60
|
||||
#define R_H8_DIR24A8 61
|
||||
#define R_H8_DIR24R8 62
|
||||
#define R_H8_DIR32A16 63
|
||||
#define R_H8_ABS32 65
|
||||
#define R_H8_ABS32A16 127
|
||||
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_H8_,name)
|
||||
@@ -0,0 +1,63 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.10 2009/05/30 05:56:52 skrll Exp $ */
|
||||
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_386: \
|
||||
case EM_486: \
|
||||
break;
|
||||
|
||||
#define ELF64_MACHDEP_ENDIANNESS XXX /* break compilation */
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
/* no 64-bit ELF machine types supported */
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_386
|
||||
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
|
||||
/* i386 relocations */
|
||||
#define R_386_NONE 0
|
||||
#define R_386_32 1
|
||||
#define R_386_PC32 2
|
||||
#define R_386_GOT32 3
|
||||
#define R_386_PLT32 4
|
||||
#define R_386_COPY 5
|
||||
#define R_386_GLOB_DAT 6
|
||||
#define R_386_JMP_SLOT 7
|
||||
#define R_386_RELATIVE 8
|
||||
#define R_386_GOTOFF 9
|
||||
#define R_386_GOTPC 10
|
||||
|
||||
/* TLS relocations */
|
||||
#define R_386_TLS_TPOFF 14
|
||||
#define R_386_TLS_IE 15
|
||||
#define R_386_TLS_GOTIE 16
|
||||
#define R_386_TLS_LE 17
|
||||
#define R_386_TLS_GD 18
|
||||
#define R_386_TLS_LDM 19
|
||||
|
||||
/* The following relocations are GNU extensions. */
|
||||
#define R_386_16 20
|
||||
#define R_386_PC16 21
|
||||
#define R_386_8 22
|
||||
#define R_386_PC8 23
|
||||
|
||||
/* More TLS relocations */
|
||||
#define R_386_TLS_GD_32 24
|
||||
#define R_386_TLS_GD_PUSH 25
|
||||
#define R_386_TLS_GD_CALL 26
|
||||
#define R_386_TLS_GD_POP 27
|
||||
#define R_386_TLS_LDM_32 28
|
||||
#define R_386_TLS_LDM_PUSH 29
|
||||
#define R_386_TLS_LDM_CALL 30
|
||||
#define R_386_TLS_LDM_POP 31
|
||||
#define R_386_TLS_LDO_32 32
|
||||
#define R_386_TLS_IE_32 33
|
||||
#define R_386_TLS_LE_32 34
|
||||
#define R_386_TLS_DTPMOD32 35
|
||||
#define R_386_TLS_DTPOFF32 36
|
||||
#define R_386_TLS_TPOFF32 37
|
||||
#define R_386_TLS_GOTDESC 39
|
||||
#define R_386_TLS_DESC_CALL 40
|
||||
#define R_386_TLS_DESC 41
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_386_,name)
|
||||
@@ -0,0 +1,34 @@
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_LATTICEMICO32: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_LATTICEMICO32
|
||||
|
||||
#define EF_MACH32_MACH 0x00000001
|
||||
|
||||
//#define EF_BLACKFIN
|
||||
|
||||
#define ARCH_ELFSIZE 32
|
||||
|
||||
#define R_LM32_NONE 0
|
||||
#define R_LM32_8 1
|
||||
#define R_LM32_16 2
|
||||
#define R_LM32_32 3
|
||||
#define R_LM32_HI16 4
|
||||
#define R_LM32_LO16 5
|
||||
#define R_LM32_GPREL16 6
|
||||
#define R_LM32_CALL 7
|
||||
#define R_LM32_BRANCH 8
|
||||
#define R_LM32_GNU_VTINHERIT 9
|
||||
#define R_LM32_GNU_VTENTRY 10
|
||||
#define R_LM32_16_GOT 11
|
||||
#define R_LM32_GOTOFF_HI16 12
|
||||
#define R_LM32_GOTOFF_LO16 13
|
||||
#define R_LM32_COPY 14
|
||||
#define R_LM32_GLOT_DAT 15
|
||||
#define R_LM32_JMP_SLOT 16
|
||||
#define R_LM32_RELATIVE 17
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_LM32_,name)
|
||||
@@ -0,0 +1,39 @@
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_M32R: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_M32R
|
||||
|
||||
#define ARCH_ELFSIZE 32
|
||||
|
||||
#define R_M32R_NONE 0
|
||||
/*-----------OLD TYPE-------------*/
|
||||
#define R_M32R_16 1
|
||||
#define R_M32R_32 2
|
||||
#define R_M32R_24 3
|
||||
#define R_M32R_10_PCREL 4
|
||||
#define R_M32R_18_PCREL 5
|
||||
#define R_M32R_26_PCREL 6
|
||||
#define R_M32R_HI16_ULO 7
|
||||
#define R_M32R_HI16_SLO 8
|
||||
#define R_M32R_LO16 9
|
||||
#define R_M32R_SDA16 10
|
||||
#define R_M32R_GNU_VTINHERIT 11
|
||||
#define R_M32R_GNU_VTENTRY 12
|
||||
/*--------------------------------*/
|
||||
|
||||
#define R_M32R_16_RELA 33
|
||||
#define R_M32R_32_RELA 34
|
||||
#define R_M32R_24_RELA 35
|
||||
#define R_M32R_18_PCREL_RELA 37
|
||||
#define R_M32R_26_PCREL_RELA 38
|
||||
#define R_M32R_HI16_ULO_RELA 39
|
||||
#define R_M32R_HI16_SLO_RELA 40
|
||||
#define R_M32R_LO16_RELA 41
|
||||
#define R_M32R_SDA16_RELA 42
|
||||
#define R_M32R_RELA_GNU_VTINHERIT 43
|
||||
#define R_M32R_RELA_GNU_VTENTRY 44
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_M32R_,name)
|
||||
@@ -0,0 +1,47 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.7 2002/01/28 21:34:48 thorpej Exp $ */
|
||||
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_68K: \
|
||||
break;
|
||||
|
||||
#define ELF64_MACHDEP_ENDIANNESS XXX /* break compilation */
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
/* no 64-bit ELF machine types supported */
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_68K
|
||||
|
||||
/*
|
||||
* Machine-dependent ELF flags. These are defined by the GNU tools.
|
||||
*/
|
||||
#define EF_CPU32 0x00810000
|
||||
#define EF_M68000 0x01000000
|
||||
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
|
||||
/* m68k relocation types */
|
||||
#define R_68K_NONE 0
|
||||
#define R_68K_32 1
|
||||
#define R_68K_16 2
|
||||
#define R_68K_8 3
|
||||
#define R_68K_PC32 4
|
||||
#define R_68K_PC16 5
|
||||
#define R_68K_PC8 6
|
||||
#define R_68K_GOT32 7
|
||||
#define R_68K_GOT16 8
|
||||
#define R_68K_GOT8 9
|
||||
#define R_68K_GOT32O 10
|
||||
#define R_68K_GOT16O 11
|
||||
#define R_68K_GOT8O 12
|
||||
#define R_68K_PLT32 13
|
||||
#define R_68K_PLT16 14
|
||||
#define R_68K_PLT8 15
|
||||
#define R_68K_PLT32O 16
|
||||
#define R_68K_PLT16O 17
|
||||
#define R_68K_PLT8O 18
|
||||
#define R_68K_COPY 19
|
||||
#define R_68K_GLOB_DAT 20
|
||||
#define R_68K_JMP_SLOT 21
|
||||
#define R_68K_RELATIVE 22
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_68K_,name)
|
||||
@@ -0,0 +1,196 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.15 2011/03/15 07:39:22 matt Exp $ */
|
||||
|
||||
#ifndef _MIPS_ELF_MACHDEP_H_
|
||||
#define _MIPS_ELF_MACHDEP_H_
|
||||
|
||||
#ifdef _LP64
|
||||
#define ARCH_ELFSIZE 64 /* MD native binary size */
|
||||
#else
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
#endif
|
||||
|
||||
#if ELFSIZE == 32
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_MIPS: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_MIPS
|
||||
#elif ELFSIZE == 64
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
case EM_MIPS: \
|
||||
break;
|
||||
|
||||
#define ELF64_MACHDEP_ID EM_MIPS
|
||||
#endif
|
||||
|
||||
/* mips relocs. */
|
||||
|
||||
#define R_MIPS_NONE 0
|
||||
#define R_MIPS_16 1
|
||||
#define R_MIPS_32 2
|
||||
#define R_MIPS_REL32 3
|
||||
#define R_MIPS_REL R_MIPS_REL32
|
||||
#define R_MIPS_26 4
|
||||
#define R_MIPS_HI16 5 /* high 16 bits of symbol value */
|
||||
#define R_MIPS_LO16 6 /* low 16 bits of symbol value */
|
||||
#define R_MIPS_GPREL16 7 /* GP-relative reference */
|
||||
#define R_MIPS_LITERAL 8 /* Reference to literal section */
|
||||
#define R_MIPS_GOT16 9 /* Reference to global offset table */
|
||||
#define R_MIPS_GOT R_MIPS_GOT16
|
||||
#define R_MIPS_PC16 10 /* 16 bit PC relative reference */
|
||||
#define R_MIPS_CALL16 11 /* 16 bit call thru glbl offset tbl */
|
||||
#define R_MIPS_CALL R_MIPS_CALL16
|
||||
#define R_MIPS_GPREL32 12
|
||||
|
||||
/* 13, 14, 15 are not defined at this point. */
|
||||
#define R_MIPS_UNUSED1 13
|
||||
#define R_MIPS_UNUSED2 14
|
||||
#define R_MIPS_UNUSED3 15
|
||||
|
||||
/*
|
||||
* The remaining relocs are apparently part of the 64-bit Irix ELF ABI.
|
||||
*/
|
||||
#define R_MIPS_SHIFT5 16
|
||||
#define R_MIPS_SHIFT6 17
|
||||
|
||||
#define R_MIPS_64 18
|
||||
#define R_MIPS_GOT_DISP 19
|
||||
#define R_MIPS_GOT_PAGE 20
|
||||
#define R_MIPS_GOT_OFST 21
|
||||
#define R_MIPS_GOT_HI16 22
|
||||
#define R_MIPS_GOT_LO16 23
|
||||
#define R_MIPS_SUB 24
|
||||
#define R_MIPS_INSERT_A 25
|
||||
#define R_MIPS_INSERT_B 26
|
||||
#define R_MIPS_DELETE 27
|
||||
#define R_MIPS_HIGHER 28
|
||||
#define R_MIPS_HIGHEST 29
|
||||
#define R_MIPS_CALL_HI16 30
|
||||
#define R_MIPS_CALL_LO16 31
|
||||
#define R_MIPS_SCN_DISP 32
|
||||
#define R_MIPS_REL16 33
|
||||
#define R_MIPS_ADD_IMMEDIATE 34
|
||||
#define R_MIPS_PJUMP 35
|
||||
#define R_MIPS_RELGOT 36
|
||||
#define R_MIPS_JALR 37
|
||||
/* TLS relocations */
|
||||
|
||||
#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */
|
||||
#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */
|
||||
#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */
|
||||
#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */
|
||||
#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */
|
||||
#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */
|
||||
#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */
|
||||
#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */
|
||||
#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */
|
||||
#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */
|
||||
#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */
|
||||
#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */
|
||||
#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */
|
||||
|
||||
#define R_MIPS_max 51
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_MIPS_,name)
|
||||
|
||||
#define R_MIPS16_min 100
|
||||
#define R_MIPS16_26 100
|
||||
#define R_MIPS16_GPREL 101
|
||||
#define R_MIPS16_GOT16 102
|
||||
#define R_MIPS16_CALL16 103
|
||||
#define R_MIPS16_HI16 104
|
||||
#define R_MIPS16_LO16 105
|
||||
#define R_MIPS16_max 106
|
||||
|
||||
|
||||
/* mips dynamic tags */
|
||||
|
||||
#define DT_MIPS_RLD_VERSION 0x70000001
|
||||
#define DT_MIPS_TIME_STAMP 0x70000002
|
||||
#define DT_MIPS_ICHECKSUM 0x70000003
|
||||
#define DT_MIPS_IVERSION 0x70000004
|
||||
#define DT_MIPS_FLAGS 0x70000005
|
||||
#define DT_MIPS_BASE_ADDRESS 0x70000006
|
||||
#define DT_MIPS_CONFLICT 0x70000008
|
||||
#define DT_MIPS_LIBLIST 0x70000009
|
||||
#define DT_MIPS_CONFLICTNO 0x7000000b
|
||||
#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* number of local got ents */
|
||||
#define DT_MIPS_LIBLISTNO 0x70000010
|
||||
#define DT_MIPS_SYMTABNO 0x70000011 /* number of .dynsym entries */
|
||||
#define DT_MIPS_UNREFEXTNO 0x70000012
|
||||
#define DT_MIPS_GOTSYM 0x70000013 /* first dynamic sym in got */
|
||||
#define DT_MIPS_HIPAGENO 0x70000014
|
||||
#define DT_MIPS_RLD_MAP 0x70000016 /* address of loader map */
|
||||
|
||||
/*
|
||||
* ELF Flags
|
||||
*/
|
||||
#define EF_MIPS_PIC 0x00000002 /* Contains PIC code */
|
||||
#define EF_MIPS_CPIC 0x00000004 /* STD PIC calling sequence */
|
||||
#define EF_MIPS_ABI2 0x00000020 /* N32 */
|
||||
|
||||
#define EF_MIPS_ARCH_ASE 0x0f000000 /* Architectural extensions */
|
||||
#define EF_MIPS_ARCH_MDMX 0x08000000 /* MDMX multimedia extension */
|
||||
#define EF_MIPS_ARCH_M16 0x04000000 /* MIPS-16 ISA extensions */
|
||||
|
||||
#define EF_MIPS_ARCH 0xf0000000 /* Architecture field */
|
||||
#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code */
|
||||
#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code */
|
||||
#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code */
|
||||
#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code */
|
||||
#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code */
|
||||
#define EF_MIPS_ARCH_32 0x50000000 /* -mips32 code */
|
||||
#define EF_MIPS_ARCH_64 0x60000000 /* -mips64 code */
|
||||
#define EF_MIPS_ARCH_32R2 0x70000000 /* -mips32r2 code */
|
||||
#define EF_MIPS_ARCH_64R2 0x80000000 /* -mips64r2 code */
|
||||
|
||||
#define EF_MIPS_ABI 0x0000f000
|
||||
#define EF_MIPS_ABI_O32 0x00001000
|
||||
#define EF_MIPS_ABI_O64 0x00002000
|
||||
#define EF_MIPS_ABI_EABI32 0x00003000
|
||||
#define EF_MIPS_ABI_EABI64 0x00004000
|
||||
|
||||
#if defined(__MIPSEB__)
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF64_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#elif defined(__MIPSEL__)
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
|
||||
#define ELF64_MACHDEP_ENDIANNESS ELFDATA2LSB
|
||||
#elif !defined(HAVE_NBTOOL_CONFIG_H)
|
||||
#error neither __MIPSEL__ nor __MIPSEB__ are defined.
|
||||
#endif
|
||||
|
||||
#ifdef _KERNEL
|
||||
#ifdef _KERNEL_OPT
|
||||
#include "opt_compat_netbsd.h"
|
||||
#endif
|
||||
#ifdef COMPAT_16
|
||||
/*
|
||||
* Up to 1.6, the ELF dynamic loader (ld.elf_so) was not relocatable.
|
||||
* Tell the kernel ELF exec code not to try relocating the interpreter
|
||||
* for dynamically-linked ELF binaries.
|
||||
*/
|
||||
#define ELF_INTERP_NON_RELOCATABLE
|
||||
#endif /* COMPAT_16 */
|
||||
|
||||
/*
|
||||
* We need to be able to include the ELF header so we can pick out the
|
||||
* ABI being used.
|
||||
*/
|
||||
#ifdef ELFSIZE
|
||||
#define ELF_MD_PROBE_FUNC ELFNAME2(mips_netbsd,probe)
|
||||
#define ELF_MD_COREDUMP_SETUP ELFNAME2(coredump,setup)
|
||||
#endif
|
||||
|
||||
struct exec_package;
|
||||
|
||||
int mips_netbsd_elf32_probe(struct lwp *, struct exec_package *, void *, char *,
|
||||
vaddr_t *);
|
||||
void coredump_elf32_setup(struct lwp *, void *);
|
||||
|
||||
int mips_netbsd_elf64_probe(struct lwp *, struct exec_package *, void *, char *,
|
||||
vaddr_t *);
|
||||
void coredump_elf64_setup(struct lwp *, void *);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
#endif /* _MIPS_ELF_MACHDEP_H_ */
|
||||
@@ -0,0 +1,15 @@
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_MOXIE: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_MOXIE
|
||||
|
||||
#define ARCH_ELFSIZE 32
|
||||
|
||||
#define R_MOXIE_NONE 0
|
||||
#define R_MOXIE_32 1
|
||||
#define R_MOXIE_PCREL10 2
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_MOXIE_,name)
|
||||
@@ -0,0 +1,46 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.7 2002/01/28 21:34:48 thorpej Exp $ */
|
||||
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_ALTERA_NIOS2: \
|
||||
break;
|
||||
|
||||
#define ELF64_MACHDEP_ENDIANNESS XXX /* break compilation */
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
/* no 64-bit ELF machine types supported */
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_ALTERA_NIOS2
|
||||
|
||||
/*
|
||||
* Machine-dependent ELF flags. These are defined by the GNU tools.
|
||||
*/
|
||||
#define EF_NIOS2 0x00810000
|
||||
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
|
||||
/* NIOS2 relocation types */
|
||||
#define R_NIOS2_NONE 0
|
||||
#define R_NIOS2_32 1
|
||||
#define R_NIOS2_16 2
|
||||
#define R_NIOS2_8 3
|
||||
#define R_NIOS2_PC32 4
|
||||
#define R_NIOS2_PC16 5
|
||||
#define R_NIOS2_PC8 6
|
||||
#define R_NIOS2_GOT32 7
|
||||
#define R_NIOS2_GOT16 8
|
||||
#define R_NIOS2_GOT8 9
|
||||
#define R_NIOS2_GOT32O 10
|
||||
#define R_NIOS2_GOT16O 11
|
||||
#define R_NIOS2_GOT8O 12
|
||||
#define R_NIOS2_PLT32 13
|
||||
#define R_NIOS2_PLT16 14
|
||||
#define R_NIOS2_PLT8 15
|
||||
#define R_NIOS2_PLT32O 16
|
||||
#define R_NIOS2_PLT16O 17
|
||||
#define R_NIOS2_PLT8O 18
|
||||
#define R_NIOS2_COPY 19
|
||||
#define R_NIOS2_GLOB_DAT 20
|
||||
#define R_NIOS2_JMP_SLOT 21
|
||||
#define R_NIOS2_RELATIVE 22
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_NIOS2_,name)
|
||||
@@ -0,0 +1,105 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.9 2011/01/15 10:00:07 matt Exp $ */
|
||||
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_PPC: \
|
||||
break;
|
||||
|
||||
#define ELF64_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
case EM_PPC64: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_PPC
|
||||
#define ELF64_MACHDEP_ID EM_PPC64
|
||||
|
||||
#ifdef _LP64
|
||||
#define ARCH_ELFSIZE 64 /* MD native binary size */
|
||||
#else
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
#endif
|
||||
|
||||
/* Specify the value of _GLOBAL_OFFSET_TABLE_ */
|
||||
#define DT_PPC_GOT DT_LOPROC
|
||||
|
||||
#define R_PPC_NONE 0
|
||||
#define R_PPC_32 1
|
||||
#define R_PPC_24 2
|
||||
#define R_PPC_16 3
|
||||
#define R_PPC_16_LO 4
|
||||
#define R_PPC_16_HI 5 /* R_PPC_ADDIS */
|
||||
#define R_PPC_16_HA 6
|
||||
#define R_PPC_14 7
|
||||
#define R_PPC_14_TAKEN 8
|
||||
#define R_PPC_14_NTAKEN 9
|
||||
#define R_PPC_REL24 10 /* R_PPC_BRANCH */
|
||||
#define R_PPC_REL14 11
|
||||
#define R_PPC_REL14_TAKEN 12
|
||||
#define R_PPC_REL14_NTAKEN 13
|
||||
#define R_PPC_GOT16 14
|
||||
#define R_PPC_GOT16_LO 15
|
||||
#define R_PPC_GOT16_HI 16
|
||||
#define R_PPC_GOT16_HA 17
|
||||
#define R_PPC_PLT24 18
|
||||
#define R_PPC_COPY 19
|
||||
#define R_PPC_GLOB_DAT 20
|
||||
#define R_PPC_JMP_SLOT 21
|
||||
#define R_PPC_RELATIVE 22
|
||||
#define R_PPC_LOCAL24PC 23
|
||||
#define R_PPC_U32 24
|
||||
#define R_PPC_U16 25
|
||||
#define R_PPC_REL32 26
|
||||
#define R_PPC_PLT32 27
|
||||
#define R_PPC_PLTREL32 28
|
||||
#define R_PPC_PLT16_LO 29
|
||||
#define R_PPC_PLT16_HI 30
|
||||
#define R_PPC_PLT16_HA 31
|
||||
#define R_PPC_SDAREL16 32
|
||||
#define R_PPC_SECTOFF 33
|
||||
#define R_PPC_SECTOFF_LO 34
|
||||
#define R_PPC_SECTOFF_HI 35
|
||||
#define R_PPC_SECTOFF_HA 36
|
||||
#define R_PPC_ADDR30 37
|
||||
|
||||
/* TLS relocations */
|
||||
#define R_PPC_TLS 67
|
||||
|
||||
#define R_PPC_DTPMOD32 68
|
||||
#define R_PPC_TPREL16 69
|
||||
#define R_PPC_TPREL16_LO 70
|
||||
#define R_PPC_TPREL16_HI 71
|
||||
#define R_PPC_TPREL16_HA 72
|
||||
#define R_PPC_TPREL32 73
|
||||
#define R_PPC_DTPREL16 74
|
||||
#define R_PPC_DTPREL16_LO 75
|
||||
#define R_PPC_DTPREL16_HI 76
|
||||
#define R_PPC_DTPREL16_HA 77
|
||||
#define R_PPC_DTPREL32 78
|
||||
|
||||
#define R_PPC_GOT_TLSGD16 79
|
||||
#define R_PPC_GOT_TLSGD16_LO 80
|
||||
#define R_PPC_GOT_TLSGD16_HI 81
|
||||
#define R_PPC_GOT_TLSGD16_HA 82
|
||||
#define R_PPC_GOT_TLSLD16 83
|
||||
#define R_PPC_GOT_TLSLD16_LO 84
|
||||
#define R_PPC_GOT_TLSLD16_HI 85
|
||||
#define R_PPC_GOT_TLSLD16_HA 86
|
||||
|
||||
#define R_PPC_GOT_TPREL16 87
|
||||
#define R_PPC_GOT_TPREL16_LO 88
|
||||
#define R_PPC_GOT_TPREL16_HI 89
|
||||
#define R_PPC_GOT_TPREL16_HA 90
|
||||
#define R_PPC_GOT_DTPREL16 91
|
||||
#define R_PPC_GOT_DTPREL16_LO 92
|
||||
#define R_PPC_GOT_DTPREL16_HI 93
|
||||
#define R_PPC_GOT_DTPREL16_HA 94
|
||||
#define R_PPC_TLSGD 95
|
||||
#define R_PPC_TLSLD 96
|
||||
|
||||
/* Used for the secure-plt PIC code sequences */
|
||||
#define R_PPC_REL16 249
|
||||
#define R_PPC_REL16_LO 250
|
||||
#define R_PPC_REL16_HI 251
|
||||
#define R_PPC_REL16_HA 252
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_PPC_,name)
|
||||
@@ -0,0 +1,92 @@
|
||||
/* $NetBSD: elf_machdep.h,v 1.7 2009/05/30 05:56:53 skrll Exp $ */
|
||||
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_SPARC: \
|
||||
case EM_SPARC32PLUS: \
|
||||
break;
|
||||
|
||||
#define ELF64_MACHDEP_ENDIANNESS ELFDATA2MSB
|
||||
#define ELF64_MACHDEP_ID_CASES \
|
||||
case EM_SPARC32PLUS: \
|
||||
case EM_SPARCV9: \
|
||||
/* no 64-bit ELF machine types supported */
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_SPARC /* XXX right? */
|
||||
|
||||
#define ARCH_ELFSIZE 32 /* MD native binary size */
|
||||
|
||||
#define R_SPARC_NONE 0
|
||||
#define R_SPARC_8 1
|
||||
#define R_SPARC_16 2
|
||||
#define R_SPARC_32 3
|
||||
#define R_SPARC_DISP8 4
|
||||
#define R_SPARC_DISP16 5
|
||||
#define R_SPARC_DISP32 6
|
||||
#define R_SPARC_WDISP30 7
|
||||
#define R_SPARC_WDISP22 8
|
||||
#define R_SPARC_HI22 9
|
||||
#define R_SPARC_22 10
|
||||
#define R_SPARC_13 11
|
||||
#define R_SPARC_LO10 12
|
||||
#define R_SPARC_GOT10 13
|
||||
#define R_SPARC_GOT13 14
|
||||
#define R_SPARC_GOT22 15
|
||||
#define R_SPARC_PC10 16
|
||||
#define R_SPARC_PC22 17
|
||||
#define R_SPARC_WPLT30 18
|
||||
#define R_SPARC_COPY 19
|
||||
#define R_SPARC_GLOB_DAT 20
|
||||
#define R_SPARC_JMP_SLOT 21
|
||||
#define R_SPARC_RELATIVE 22
|
||||
#define R_SPARC_UA32 23
|
||||
#define R_SPARC_PLT32 24
|
||||
#define R_SPARC_HIPLT22 25
|
||||
#define R_SPARC_LOPLT10 26
|
||||
#define R_SPARC_PCPLT32 27
|
||||
#define R_SPARC_PCPLT22 28
|
||||
#define R_SPARC_PCPLT10 29
|
||||
#define R_SPARC_10 30
|
||||
#define R_SPARC_11 31
|
||||
#define R_SPARC_64 32
|
||||
#define R_SPARC_OLO10 33
|
||||
#define R_SPARC_HH22 34
|
||||
#define R_SPARC_HM10 35
|
||||
#define R_SPARC_LM22 36
|
||||
#define R_SPARC_PC_HH22 37
|
||||
#define R_SPARC_PC_HM10 38
|
||||
#define R_SPARC_PC_LM22 39
|
||||
#define R_SPARC_WDISP16 40
|
||||
#define R_SPARC_WDISP19 41
|
||||
#define R_SPARC_GLOB_JMP 42
|
||||
#define R_SPARC_7 43
|
||||
#define R_SPARC_5 44
|
||||
#define R_SPARC_6 45
|
||||
|
||||
/* TLS relocations */
|
||||
#define R_SPARC_TLS_GD_HI22 56
|
||||
#define R_SPARC_TLS_GD_LO10 57
|
||||
#define R_SPARC_TLS_GD_ADD 58
|
||||
#define R_SPARC_TLS_GD_CALL 59
|
||||
#define R_SPARC_TLS_LDM_HI22 60
|
||||
#define R_SPARC_TLS_LDM_LO10 61
|
||||
#define R_SPARC_TLS_LDM_ADD 62
|
||||
#define R_SPARC_TLS_LDM_CALL 63
|
||||
#define R_SPARC_TLS_LDO_HIX22 64
|
||||
#define R_SPARC_TLS_LDO_LOX10 65
|
||||
#define R_SPARC_TLS_LDO_ADD 66
|
||||
#define R_SPARC_TLS_IE_HI22 67
|
||||
#define R_SPARC_TLS_IE_LO10 68
|
||||
#define R_SPARC_TLS_IE_LD 69
|
||||
#define R_SPARC_TLS_IE_LDX 70
|
||||
#define R_SPARC_TLS_IE_ADD 71
|
||||
#define R_SPARC_TLS_LE_HIX22 72
|
||||
#define R_SPARC_TLS_LE_LOX10 73
|
||||
#define R_SPARC_TLS_DTPMOD32 74
|
||||
#define R_SPARC_TLS_DTPMOD64 75
|
||||
#define R_SPARC_TLS_DTPOFF32 76
|
||||
#define R_SPARC_TLS_DTPOFF64 77
|
||||
#define R_SPARC_TLS_TPOFF32 78
|
||||
#define R_SPARC_TLS_TPOFF64 79
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_SPARC_,name)
|
||||
@@ -0,0 +1,74 @@
|
||||
#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB
|
||||
|
||||
#define ELF32_MACHDEP_ID_CASES \
|
||||
case EM_V850: \
|
||||
break;
|
||||
|
||||
#define ELF32_MACHDEP_ID EM_V850
|
||||
|
||||
|
||||
|
||||
#define EF_V850_ARCH 0xf0000000
|
||||
#define E_V850_ARCH 0x00000000
|
||||
#define E_V850E_ARCH 0x10000000
|
||||
#define E_V850E1_ARCH 0x20000000
|
||||
#define E_V850E2_ARCH 0x30000000
|
||||
#define E_V850E2V3_ARCH 0x40000000
|
||||
|
||||
#define ARCH_ELFSIZE 32
|
||||
|
||||
|
||||
#define R_V850_NONE 0
|
||||
#define R_V850_9_PCREL 1
|
||||
#define R_V850_22_PCREL 2
|
||||
#define R_V850_HI16_S 3
|
||||
#define R_V850_HI16 4
|
||||
#define R_V850_LO16 5
|
||||
#define R_V850_ABS32 6
|
||||
#define R_V850_16 7
|
||||
#define R_V850_8 8
|
||||
#define R_V850_SDA_16_16_OFFSET 9
|
||||
#define R_V850_SDA_15_16_OFFSET 10
|
||||
#define R_V850_ZDA_16_16_OFFSET 11
|
||||
#define R_V850_ZDA_15_16_OFFSET 12
|
||||
#define R_V850_TDA_6_8_OFFSET 13
|
||||
#define R_V850_TDA_7_8_OFFSET 14
|
||||
#define R_V850_TDA_7_7_OFFSET 15
|
||||
#define R_V850_TDA_16_16_OFFSET 16
|
||||
#define R_V850_TDA_4_5_OFFSET 17
|
||||
#define R_V850_TDA_4_4_OFFSET 18
|
||||
#define R_V850_SDA_16_16_SPLIT_OFFSET 19
|
||||
#define R_V850_ZDA_16_16_SPLIT_OFFSET 20
|
||||
#define R_V850_CALLT_6_7_OFFSET 21
|
||||
#define R_V850_CALLT_16_16_OFFSET 22
|
||||
#define R_V850_GNU_VTINHERIT 23
|
||||
#define R_V850_GNU_VTENTRY 24
|
||||
#define R_V850_LONGCALL 25
|
||||
#define R_V850_LONGJUMP 26
|
||||
#define R_V850_ALIGN 27
|
||||
#define R_V850_REL32 28
|
||||
#define R_V850_LO16_SPLIT_OFFSET 29
|
||||
#define R_V850_16_PCREL 30
|
||||
#define R_V850_17_PCREL 31
|
||||
#define R_V850_23 32
|
||||
#define R_V850_32_PCREL 33
|
||||
#define R_V850_32_ABS 34
|
||||
#define R_V850_16_SPLIT_OFFSET 35
|
||||
#define R_V850_16_S1 36
|
||||
#define R_V850_LO16_S1 37
|
||||
#define R_V850_CALLT_15_16_OFFSET 38
|
||||
#define R_V850_32_GOTPCREL 39
|
||||
#define R_V850_16_GOT 40
|
||||
#define R_V850_32_GOT 41
|
||||
#define R_V850_22_PLT 42
|
||||
#define R_V850_32_PLT 43
|
||||
#define R_V850_COPY 44
|
||||
#define R_V850_GLOB_DAT 45
|
||||
#define R_V850_JMP_SLOT 46
|
||||
#define R_V850_RELATIVE 47
|
||||
#define R_V850_16_GOTOFF 48
|
||||
#define R_V850_32_GOTOFF 49
|
||||
#define R_V850_CODE 50
|
||||
#define R_V850_DATA 51
|
||||
|
||||
#define R_TYPE(name) __CONCAT(R_V850_,name)
|
||||
@@ -0,0 +1,45 @@
|
||||
/* $NetBSD: link.h,v 1.13 2008/04/28 20:22:54 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
||||
* NASA Ames Research Center.
|
||||
*
|
||||
* 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. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 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 FOUNDATION OR 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.
|
||||
*/
|
||||
|
||||
#ifndef _LINK_H_
|
||||
#define _LINK_H_
|
||||
|
||||
/*
|
||||
* Pull in the correct definitions for our toolchain target.
|
||||
*/
|
||||
#ifdef __ELF__
|
||||
#include <link_elf.h>
|
||||
#else
|
||||
#include <link_aout.h>
|
||||
#endif
|
||||
|
||||
#endif /* _LINK_H_ */
|
||||
@@ -0,0 +1,79 @@
|
||||
/* $NetBSD: link_elf.h,v 1.8 2009/11/04 19:28:03 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* This only exists for GDB.
|
||||
*/
|
||||
|
||||
#ifndef _LINK_ELF_H_
|
||||
#define _LINK_ELF_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <machine/elf_machdep.h>
|
||||
#include <stdint.h>
|
||||
#include <rtems/rtl/rtl-obj-fwd.h>
|
||||
|
||||
enum sections
|
||||
{
|
||||
rap_text = 0,
|
||||
rap_const = 1,
|
||||
rap_ctor = 2,
|
||||
rap_dtor = 3,
|
||||
rap_data = 4,
|
||||
rap_bss = 5,
|
||||
rap_secs = 6
|
||||
};
|
||||
|
||||
/**
|
||||
* Object details.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
const char* name; /**< Section name. */
|
||||
uint32_t offset; /**< The offset in the elf file. */
|
||||
uint32_t size; /**< The size of the section. */
|
||||
uint32_t rap_id; /**< Which obj does this section belongs to. */
|
||||
}section_detail;
|
||||
|
||||
/**
|
||||
* link map structure will be used for GDB support.
|
||||
*/
|
||||
struct link_map {
|
||||
const char* name; /**< Name of the obj. */
|
||||
uint32_t sec_num; /**< The count of section. */
|
||||
section_detail* sec_detail; /**< The section details. */
|
||||
uint32_t* sec_addr[rap_secs]; /**< The RAP section addr. */
|
||||
uint32_t rpathlen; /**< The length of the path. */
|
||||
char* rpath; /**< The path of object files. */
|
||||
struct link_map* l_next; /**< Linked list of mapped libs. */
|
||||
struct link_map* l_prev;
|
||||
};
|
||||
|
||||
/**
|
||||
* r_debug is used to manage the debug related structures.
|
||||
*/
|
||||
struct r_debug {
|
||||
int r_version; /* not used */
|
||||
struct link_map *r_map; /* list of loaded images */
|
||||
enum {
|
||||
RT_CONSISTENT, /* things are stable */
|
||||
RT_ADD, /* adding a shared library */
|
||||
RT_DELETE /* removing a shared library */
|
||||
} r_state;
|
||||
};
|
||||
|
||||
/*
|
||||
* stub function. It is empty.
|
||||
*/
|
||||
void _rtld_debug_state (void);
|
||||
|
||||
/*
|
||||
* add link map to the list.
|
||||
*/
|
||||
int _rtld_linkmap_add (rtems_rtl_obj_t* obj);
|
||||
|
||||
/*
|
||||
* Remove link map from the list.
|
||||
*/
|
||||
void _rtld_linkmap_delete (rtems_rtl_obj_t* obj);
|
||||
#endif /* _LINK_ELF_H_ */
|
||||
@@ -0,0 +1,152 @@
|
||||
/* $NetBSD: cdefs_elf.h,v 1.24 2005/07/16 17:53:36 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Author: Chris G. Demetriou
|
||||
*
|
||||
* Permission to use, copy, modify and distribute this software and
|
||||
* its documentation is hereby granted, provided that both the copyright
|
||||
* notice and this permission notice appear in all copies of the
|
||||
* software, derivative works or modified versions, and any portions
|
||||
* thereof, and that both notices appear in supporting documentation.
|
||||
*
|
||||
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
||||
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
||||
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
||||
*
|
||||
* Carnegie Mellon requests users of this software to return to
|
||||
*
|
||||
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
||||
* School of Computer Science
|
||||
* Carnegie Mellon University
|
||||
* Pittsburgh PA 15213-3890
|
||||
*
|
||||
* any improvements or extensions that they make and grant Carnegie the
|
||||
* rights to redistribute these changes.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_CDEFS_ELF_H_
|
||||
#define _SYS_CDEFS_ELF_H_
|
||||
|
||||
#ifdef __LEADING_UNDERSCORE
|
||||
#define _C_LABEL(x) __CONCAT(_,x)
|
||||
#define _C_LABEL_STRING(x) "_"x
|
||||
#else
|
||||
#define _C_LABEL(x) x
|
||||
#define _C_LABEL_STRING(x) x
|
||||
#endif
|
||||
|
||||
#if __STDC__
|
||||
#define ___RENAME(x) __asm__(___STRING(_C_LABEL(x)))
|
||||
#else
|
||||
#ifdef __LEADING_UNDERSCORE
|
||||
#define ___RENAME(x) ____RENAME(_/**/x)
|
||||
#define ____RENAME(x) __asm__(___STRING(x))
|
||||
#else
|
||||
#define ___RENAME(x) __asm__(___STRING(x))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define __indr_reference(sym,alias) /* nada, since we do weak refs */
|
||||
|
||||
#if __STDC__
|
||||
#define __strong_alias(alias,sym) \
|
||||
__asm__(".global " _C_LABEL_STRING(#alias) "\n" \
|
||||
_C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
|
||||
|
||||
#define __weak_alias(alias,sym) \
|
||||
__asm__(".weak " _C_LABEL_STRING(#alias) "\n" \
|
||||
_C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
|
||||
#define __weak_extern(sym) \
|
||||
__asm__(".weak " _C_LABEL_STRING(#sym));
|
||||
#define __warn_references(sym,msg) \
|
||||
__asm__(".section .gnu.warning." #sym "\n\t.ascii \"" msg "\"\n\t.text");
|
||||
|
||||
#else /* !__STDC__ */
|
||||
|
||||
#ifdef __LEADING_UNDERSCORE
|
||||
#define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
|
||||
#define ___weak_alias(alias,sym) \
|
||||
__asm__(".weak alias\nalias = sym");
|
||||
#else
|
||||
#define __weak_alias(alias,sym) \
|
||||
__asm__(".weak alias\nalias = sym");
|
||||
#endif
|
||||
#ifdef __LEADING_UNDERSCORE
|
||||
#define __weak_extern(sym) ___weak_extern(_/**/sym)
|
||||
#define ___weak_extern(sym) \
|
||||
__asm__(".weak sym");
|
||||
#else
|
||||
#define __weak_extern(sym) \
|
||||
__asm__(".weak sym");
|
||||
#endif
|
||||
#define __warn_references(sym,msg) \
|
||||
__asm__(".section .gnu.warning.sym\n\t.ascii msg ; .text");
|
||||
|
||||
#endif /* !__STDC__ */
|
||||
|
||||
#if __STDC__
|
||||
#define __SECTIONSTRING(_sec, _str) \
|
||||
__asm__(".section " #_sec "\n\t.asciz \"" _str "\"\n\t.previous")
|
||||
#else
|
||||
#define __SECTIONSTRING(_sec, _str) \
|
||||
__asm__(".section _sec\n\t.asciz _str\n\t.previous")
|
||||
#endif
|
||||
|
||||
#define __IDSTRING(_n,_s) __SECTIONSTRING(.ident,_s)
|
||||
|
||||
#define __RCSID(_s) __IDSTRING(rcsid,_s)
|
||||
#define __SCCSID(_s)
|
||||
#define __SCCSID2(_s)
|
||||
#if 0 /* XXX userland __COPYRIGHTs have \ns in them */
|
||||
#define __COPYRIGHT(_s) __SECTIONSTRING(.copyright,_s)
|
||||
#else
|
||||
#define __COPYRIGHT(_s) \
|
||||
static const char copyright[] \
|
||||
__attribute__((__unused__,__section__(".copyright"))) = _s
|
||||
#endif
|
||||
|
||||
#define __KERNEL_RCSID(_n, _s) __RCSID(_s)
|
||||
#define __KERNEL_SCCSID(_n, _s)
|
||||
#if 0 /* XXX see above */
|
||||
#define __KERNEL_COPYRIGHT(_n, _s) __COPYRIGHT(_s)
|
||||
#else
|
||||
#define __KERNEL_COPYRIGHT(_n, _s) __SECTIONSTRING(.copyright, _s)
|
||||
#endif
|
||||
|
||||
#ifndef __lint__
|
||||
#define __link_set_make_entry(set, sym) \
|
||||
static void const * const __link_set_##set##_sym_##sym \
|
||||
__section("link_set_" #set) __used = &sym
|
||||
#define __link_set_make_entry2(set, sym, n) \
|
||||
static void const * const __link_set_##set##_sym_##sym##_##n \
|
||||
__section("link_set_" #set) __used = &sym[n]
|
||||
#else
|
||||
#define __link_set_make_entry(set, sym) \
|
||||
extern void const * const __link_set_##set##_sym_##sym
|
||||
#define __link_set_make_entry2(set, sym, n) \
|
||||
extern void const * const __link_set_##set##_sym_##sym##_##n
|
||||
#endif /* __lint__ */
|
||||
|
||||
#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym)
|
||||
#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym)
|
||||
#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym)
|
||||
#define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym)
|
||||
#define __link_set_add_text2(set, sym, n) __link_set_make_entry2(set, sym, n)
|
||||
#define __link_set_add_rodata2(set, sym, n) __link_set_make_entry2(set, sym, n)
|
||||
#define __link_set_add_data2(set, sym, n) __link_set_make_entry2(set, sym, n)
|
||||
#define __link_set_add_bss2(set, sym, n) __link_set_make_entry2(set, sym, n)
|
||||
|
||||
#define __link_set_decl(set, ptype) \
|
||||
extern ptype * const __start_link_set_##set[]; \
|
||||
extern ptype * const __stop_link_set_##set[] \
|
||||
|
||||
#define __link_set_start(set) (__start_link_set_##set)
|
||||
#define __link_set_end(set) (__stop_link_set_##set)
|
||||
|
||||
#define __link_set_count(set) \
|
||||
(__link_set_end(set) - __link_set_start(set))
|
||||
|
||||
#endif /* !_SYS_CDEFS_ELF_H_ */
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
||||
## Automatically generated by ampolish3 - Do not edit
|
||||
|
||||
if AMPOLISH3
|
||||
$(srcdir)/preinstall.am: Makefile.am
|
||||
$(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtld
|
||||
*
|
||||
* @brief RTEMS Application Loader.
|
||||
*
|
||||
* Shell command wrappers for the RTEMS Application loader.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rtems/rtl/rap.h>
|
||||
#include <rtems/rtl/rap-shell.h>
|
||||
|
||||
static void
|
||||
shell_rap_command_help (void)
|
||||
{
|
||||
printf ("usage: rap [cmd] [arg]\n" \
|
||||
"Commands and options:\n" \
|
||||
"ls: List the loaded applications (also list)\n" \
|
||||
"ld: Load an application (also load)\n" \
|
||||
"un: Unload an application (also unload)\n");
|
||||
}
|
||||
|
||||
static void
|
||||
shell_rap_get_error (const char* what)
|
||||
{
|
||||
char message[64];
|
||||
int error;
|
||||
error = rtems_rap_get_error (message, sizeof (message));
|
||||
printf ("error: %s: (%d) %s\n", what, error, message);
|
||||
}
|
||||
|
||||
static bool
|
||||
shell_rap_list_handler (void* handle)
|
||||
{
|
||||
printf (" %-10p %-10p %-s\n",
|
||||
handle, rtems_rap_dl_handle (handle), rtems_rap_name (handle));
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
shell_rap_list (int argc, char* argv[])
|
||||
{
|
||||
printf (" App DL Handle Name\n");
|
||||
return rtems_rap_iterate (shell_rap_list_handler) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int
|
||||
shell_rap_load (int argc, char* argv[])
|
||||
{
|
||||
int r = 0;
|
||||
if (argc == 0)
|
||||
{
|
||||
printf ("error: no application name\n");
|
||||
return 0;
|
||||
}
|
||||
if (rtems_rap_load (argv[0], 0, argc - 1, (const char**) (argv + 1)))
|
||||
printf ("%s loaded\n", argv[0]);
|
||||
else
|
||||
{
|
||||
r = 1;
|
||||
shell_rap_get_error ("loading");
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
shell_rap (int argc, char* argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
{
|
||||
shell_rap_command_help ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((strcmp (argv[1], "ls") == 0) ||
|
||||
(strcmp (argv[1], "list") == 0))
|
||||
{
|
||||
return shell_rap_list (argc - 2, argv + 2);
|
||||
}
|
||||
else if ((strcmp (argv[1], "ld") == 0) ||
|
||||
(strcmp (argv[1], "load") == 0))
|
||||
{
|
||||
return shell_rap_load (argc - 2, argv + 2);
|
||||
}
|
||||
|
||||
printf ("error: invalid command: %s\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if !defined(_RAP_SHELL_H_)
|
||||
#define _RAP_SHELL_H_
|
||||
|
||||
int shell_rap (int argc, char* argv[]);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2013 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rap
|
||||
*
|
||||
* @brief RTEMS Application Loader
|
||||
*
|
||||
* This is the RTEMS Application loader for files in the RAP format.
|
||||
*/
|
||||
|
||||
#if !defined (_RAP_H_)
|
||||
#define _RAP_H_
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/chain.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* @defgroup rtems_rap RTEMS Application Loader
|
||||
*
|
||||
* The module implements an application loader for files in the RAP format. The
|
||||
* RAP format is:
|
||||
*
|
||||
* <header>
|
||||
* <compressed container>
|
||||
*
|
||||
* The compressed container is a stream of ELF relocatable object files.
|
||||
*
|
||||
* TBD.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The module iterator handle.
|
||||
*/
|
||||
typedef bool (*rtems_rap_iterator_t) (void* handle);
|
||||
|
||||
/**
|
||||
* Load an application.
|
||||
*
|
||||
* @param name The name of the application file.
|
||||
* @return bool True if the module loads else an error.
|
||||
*/
|
||||
bool rtems_rap_load (const char* name, int mode, int argc, const char* argv[]);
|
||||
|
||||
/**
|
||||
* Unload an application.
|
||||
*
|
||||
* @param obj The application descriptor.
|
||||
* @retval true The application file has been unloaded.
|
||||
* @retval false The application could not be unloaded.
|
||||
*/
|
||||
bool rtems_rap_unload (const char* name);
|
||||
|
||||
/**
|
||||
* Find the application handle given a file name.
|
||||
*
|
||||
* @param name The name of the application file. It can be absolute or
|
||||
* relative. Relative names can the basename with an extension.
|
||||
* @retval NULL No application file with that name found.
|
||||
* @return void* The application descriptor.
|
||||
*/
|
||||
void* rtems_rap_find (const char* name);
|
||||
|
||||
/**
|
||||
* Run an iterator over the modules calling the iterator function.
|
||||
*
|
||||
* @param iterator The iterator function.
|
||||
* @retval true The iterator function returned did not return false.
|
||||
* @retval false The iterator function returned false..
|
||||
*/
|
||||
bool rtems_rap_iterate (rtems_rap_iterator_t iterator);
|
||||
|
||||
/**
|
||||
* Return the name of the module given a handle.
|
||||
*
|
||||
* @param handle The module handle.
|
||||
* @return const char* The name of the module if the handle is valid else it
|
||||
* is NULL.
|
||||
*/
|
||||
const char* rtems_rap_name (void* handle);
|
||||
|
||||
/**
|
||||
* Return the DL handle used to load the module given the RAP handle.
|
||||
*
|
||||
* @param handle The module handle.
|
||||
* @return void* The DL handle returned by the dlopen call.
|
||||
*/
|
||||
void* rtems_rap_dl_handle (void* handle);
|
||||
|
||||
/**
|
||||
* Get the last error message clearing it. This call is not thread safe is
|
||||
* multiple threads are loading object files at the same time. This call
|
||||
* follows the model provided by the dlopen family of calls.
|
||||
*
|
||||
* @param message Pointer to a buffer to copy the message into.
|
||||
* @param max_message The maximum message that can be copied.
|
||||
* @return int The last error number.
|
||||
*/
|
||||
int rtems_rap_get_error (char* message, size_t max_message);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Allocator for the standard heap.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "rtl-alloc-heap.h"
|
||||
|
||||
void
|
||||
rtems_rtl_alloc_heap (bool allocate,
|
||||
rtems_rtl_alloc_tag_t tag,
|
||||
void** address,
|
||||
size_t size)
|
||||
{
|
||||
if (allocate)
|
||||
*address = malloc (size);
|
||||
else
|
||||
{
|
||||
free (*address);
|
||||
*address = NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Allocator for the standard heap.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_ALLOC_HEAP_H_)
|
||||
#define _RTEMS_RTL_ALLOC_HEAP_H_
|
||||
|
||||
#include <rtems/rtl/rtl-allocator.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* Allocator handler for the standard libc heap.
|
||||
*
|
||||
* @param allocation If true the request is to allocate memory else free.
|
||||
* @param tag The type of allocation request.
|
||||
* @param address Pointer to the memory address. If an allocation the value is
|
||||
* unspecific on entry and the allocated address or NULL on
|
||||
* exit. The NULL value means the allocation failed. If a delete
|
||||
* or free request the memory address is the block to free. A
|
||||
* free request of NULL is silently ignored.
|
||||
* @param size The size of the allocation if an allocation request and
|
||||
* not used if deleting or freeing a previous allocation.
|
||||
*/
|
||||
void rtems_rtl_alloc_heap(bool allocate,
|
||||
rtems_rtl_alloc_tag_t tag,
|
||||
void** address,
|
||||
size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Allocator
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_ALLOCATOR_H_)
|
||||
#define _RTEMS_RTL_ALLOCATOR_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "rtl-indirect-ptr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* Define the types of allocation the loader requires.
|
||||
*
|
||||
* @note It is best to use the object tag for general memory allocation and to
|
||||
* leave the tags with specific access properties to the module data
|
||||
*/
|
||||
enum rtems_rtl_alloc_tags_e {
|
||||
RTEMS_RTL_ALLOC_OBJECT, /**< A generic memory object. */
|
||||
RTEMS_RTL_ALLOC_SYMBOL, /**< Memory used for symbols. */
|
||||
RTEMS_RTL_ALLOC_EXTERNAL, /**< Memory used for external symbols. */
|
||||
RTEMS_RTL_ALLOC_READ, /**< The memory is read only. */
|
||||
RTEMS_RTL_ALLOC_READ_WRITE, /**< The memory is read and write. */
|
||||
RTEMS_RTL_ALLOC_READ_EXEC /**< The memory is read and executable. */
|
||||
};
|
||||
|
||||
/**
|
||||
* The allocator tag type.
|
||||
*/
|
||||
typedef enum rtems_rtl_alloc_tags_e rtems_rtl_alloc_tag_t;
|
||||
|
||||
/**
|
||||
* The number of tags.
|
||||
*/
|
||||
#define RTEMS_RTL_ALLOC_TAGS ((size_t) (RTEMS_RTL_ALLOC_READ_EXEC + 1))
|
||||
|
||||
/**
|
||||
* Allocator handler handles all RTL allocations. It can be hooked and
|
||||
* overridded for customised allocation schemes or memory maps.
|
||||
*
|
||||
* @param allocation If true the request is to allocate memory else free.
|
||||
* @param tag The type of allocation request.
|
||||
* @param address Pointer to the memory address. If an allocation the value is
|
||||
* unspecific on entry and the allocated address or NULL on
|
||||
* exit. The NULL value means the allocation failed. If a delete
|
||||
* or free request the memory address is the block to free. A
|
||||
* free request of NULL is silently ignored.
|
||||
* @param size The size of the allocation if an allocation request and
|
||||
* not used if deleting or freeing a previous allocation.
|
||||
*/
|
||||
typedef void (*rtems_rtl_allocator_t)(bool allocate,
|
||||
rtems_rtl_alloc_tag_t tag,
|
||||
void** address,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* The allocator data.
|
||||
*/
|
||||
struct rtems_rtl_alloc_data_s {
|
||||
/**< The memory allocator handler. */
|
||||
rtems_rtl_allocator_t allocator;
|
||||
/**< The indirect pointer chains. */
|
||||
rtems_chain_control indirects[RTEMS_RTL_ALLOC_TAGS];
|
||||
};
|
||||
|
||||
typedef struct rtems_rtl_alloc_data_s rtems_rtl_alloc_data_t;
|
||||
|
||||
/**
|
||||
* Initialise the allocate data.
|
||||
*
|
||||
* @param data The data to initialise.
|
||||
*/
|
||||
void rtems_rtl_alloc_initialise (rtems_rtl_alloc_data_t* data);
|
||||
|
||||
/**
|
||||
* The Runtime Loader allocator new allocates new memory and optionally clear
|
||||
* the memory if requested.
|
||||
*
|
||||
* @param tag The type of allocation request.
|
||||
* @param size The size of the allocation.
|
||||
* @param zero If true the memory is cleared.
|
||||
* @return void* The memory address or NULL is not memory available.
|
||||
*/
|
||||
void* rtems_rtl_alloc_new (rtems_rtl_alloc_tag_t tag, size_t size, bool zero);
|
||||
|
||||
/**
|
||||
* The Runtime Loader allocator delete deletes allocated memory.
|
||||
*
|
||||
* @param tag The type of allocation request.
|
||||
* @param address The memory address to delete. A NULL is ignored.
|
||||
*/
|
||||
void rtems_rtl_alloc_del (rtems_rtl_alloc_tag_t tag, void* address);
|
||||
|
||||
/**
|
||||
* Hook the Runtime Loader allocatior. A handler can call the previous handler
|
||||
* in the chain to use it for specific tags. The default handler uses the
|
||||
* system heap. Do not unhook your handler if memory it allocates has not been
|
||||
* returned.
|
||||
*
|
||||
* @param handler The handler to use as the allocator.
|
||||
* @return rtems_rtl_alloc_handler_t The previous handler.
|
||||
*/
|
||||
rtems_rtl_allocator_t rtems_rtl_alloc_hook (rtems_rtl_allocator_t handler);
|
||||
|
||||
/**
|
||||
* Allocate memory to an indirect handle.
|
||||
*
|
||||
* @param tag The type of allocation request.
|
||||
* @param handle The handle to allocate the memory to.
|
||||
* @param size The size of the allocation.
|
||||
*/
|
||||
void rtems_rtl_alloc_indirect_new (rtems_rtl_alloc_tag_t tag,
|
||||
rtems_rtl_ptr_t* handle,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* Free memory from an indirect handle.
|
||||
*
|
||||
* @param tag The type of allocation request.
|
||||
* @param handle The handle to free the memory from.
|
||||
*/
|
||||
void rtems_rtl_alloc_indirect_del (rtems_rtl_alloc_tag_t tag,
|
||||
rtems_rtl_ptr_t* handle);
|
||||
|
||||
/**
|
||||
* Allocate the memory for a module given the size of the text, const, data and
|
||||
* bss sections. If any part of the allocation fails the no memory is
|
||||
* allocated.
|
||||
*
|
||||
* @param text_base Pointer to the text base pointer.
|
||||
* @param text_size The size of the read/exec section.
|
||||
* @param const_base Pointer to the const base pointer.
|
||||
* @param const_size The size of the read only section.
|
||||
* @param data_base Pointer to the data base pointer.
|
||||
* @prarm data_size The size of the read/write secton.
|
||||
* @param bss_base Pointer to the bss base pointer.
|
||||
* @param bss_size The size of the read/write.
|
||||
* @retval true The memory has been allocated.
|
||||
* @retval false The allocation of memory has failed.
|
||||
*/
|
||||
bool rtems_rtl_alloc_module_new (void** text_base, size_t text_size,
|
||||
void** const_base, size_t const_size,
|
||||
void** data_base, size_t data_size,
|
||||
void** bss_base, size_t bss_size);
|
||||
|
||||
/**
|
||||
* Free the memory allocated to a module.
|
||||
*
|
||||
* @param text_base Pointer to the text base pointer.
|
||||
* @param const_base Pointer to the const base pointer.
|
||||
* @param data_base Pointer to the data base pointer.
|
||||
* @param bss_base Pointer to the bss base pointer.
|
||||
*/
|
||||
void rtems_rtl_alloc_module_del (void** text_base, void** const_base,
|
||||
void** data_base, void** bss_base);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtld
|
||||
*
|
||||
* @brief RTEMS Run-Time Link Editor Chain Iterator
|
||||
*
|
||||
* A means of executing an iterator on a chain.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "rtl-chain-iterator.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_chain_iterate (rtems_chain_control* chain,
|
||||
rtems_chain_iterator iterator,
|
||||
void* data)
|
||||
{
|
||||
rtems_chain_node* node = rtems_chain_first (chain);
|
||||
while (!rtems_chain_is_tail (chain, node))
|
||||
{
|
||||
rtems_chain_node* next_node = rtems_chain_next (node);
|
||||
if (!iterator (node, data))
|
||||
return false;
|
||||
node = next_node;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count iterator.
|
||||
*/
|
||||
static bool
|
||||
rtems_rtl_count_iterator (rtems_chain_node* node, void* data)
|
||||
{
|
||||
int* count = data;
|
||||
++(*count);
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
rtems_rtl_chain_count (rtems_chain_control* chain)
|
||||
{
|
||||
int count = 0;
|
||||
rtems_rtl_chain_iterate (chain, rtems_rtl_count_iterator, &count);
|
||||
return count;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Chain Iterator.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_CHAIN_ITERATOR_H_)
|
||||
#define _RTEMS_RTL_CHAIN_ITERATOR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <rtems/chain.h>
|
||||
|
||||
/**
|
||||
* Chain iterator handler.
|
||||
*/
|
||||
typedef bool (*rtems_chain_iterator) (rtems_chain_node* node, void* data);
|
||||
|
||||
/**
|
||||
* Iterate a chain of nodes invoking the iterator handler. Supply a data
|
||||
* pointer the iterator moves data between the invoker and the iterator.
|
||||
*
|
||||
* The iterator allows removal of the node from the chain.
|
||||
*
|
||||
* @param chain The chain of nodes to iterator over.
|
||||
* @param iterator The iterator handler called once for each node.
|
||||
* @param data Pointer to the data used by the iterator.
|
||||
* @retval true The whole chain was iterated over.
|
||||
* @retval false The iterator returned false.
|
||||
*/
|
||||
bool
|
||||
rtems_rtl_chain_iterate (rtems_chain_control* chain,
|
||||
rtems_chain_iterator iterator,
|
||||
void* data);
|
||||
|
||||
/**
|
||||
* Count the number of nodes on the chain.
|
||||
*
|
||||
* @param chain The chain to count the nodes of.
|
||||
* @return int The number of nodes.
|
||||
*/
|
||||
int rtems_rtl_chain_count (rtems_chain_control* chain);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtl
|
||||
*
|
||||
* @brief RTEMS Module Loading Debugger Interface.
|
||||
*
|
||||
* Inspection of run-time linkers in NetBSD and Android show a common type of
|
||||
* structure that is used to interface to GDB. The NetBSD definition of this
|
||||
* interface is being used and is defined in <link.h>. It defines a protocol
|
||||
* that is used by GDB to inspect the state of dynamic libraries. I have not
|
||||
* checked GDB code at when writing this comment but I suspect GDB sets a break
|
||||
* point on the r_brk field of _rtld_debug and it has code that detects this
|
||||
* break point being hit. When this happens it reads the state and performs the
|
||||
* operation based on the r_state field.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <link.h>
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-trace.h"
|
||||
#include "rtl-obj-fwd.h"
|
||||
|
||||
struct r_debug _rtld_debug;
|
||||
|
||||
void
|
||||
_rtld_debug_state (void)
|
||||
{
|
||||
/*
|
||||
* Empty. GDB only needs to hit this location.
|
||||
*/
|
||||
}
|
||||
|
||||
int
|
||||
_rtld_linkmap_add (rtems_rtl_obj_t* obj)
|
||||
{
|
||||
struct link_map* l = (struct link_map*)obj->detail;
|
||||
struct link_map* prev;
|
||||
uint32_t obj_num = obj->obj_num;
|
||||
int i;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_DETAIL))
|
||||
printf ("rtl: linkmap_add\n");
|
||||
|
||||
for (i = 0; i < obj_num; ++i)
|
||||
{
|
||||
l[i].sec_addr[rap_text] = obj->text_base;
|
||||
l[i].sec_addr[rap_const] = obj->const_base;
|
||||
l[i].sec_addr[rap_data] = obj->data_base;
|
||||
l[i].sec_addr[rap_bss] = obj->bss_base;
|
||||
}
|
||||
|
||||
if (_rtld_debug.r_map == NULL)
|
||||
{
|
||||
_rtld_debug.r_map = l;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (prev = _rtld_debug.r_map; prev->l_next != NULL; prev = prev->l_next);
|
||||
|
||||
l->l_prev = prev;
|
||||
prev->l_next = l;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
_rtld_linkmap_delete (rtems_rtl_obj_t* obj)
|
||||
{
|
||||
struct link_map* l = (struct link_map*)obj->detail;
|
||||
/* link_maps are allocated together if not 1 */
|
||||
struct link_map* e = l + obj->obj_num - 1;
|
||||
|
||||
while (e && e->l_next) e = e->l_next;
|
||||
|
||||
if (l->l_prev == NULL)
|
||||
{
|
||||
if ((_rtld_debug.r_map = e->l_next) != NULL)
|
||||
e->l_next->l_prev = NULL;
|
||||
return;
|
||||
}
|
||||
if ((l->l_prev->l_next = e->l_next) != NULL)
|
||||
e->l_next->l_prev = l->l_prev;
|
||||
return;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker ELF Headers
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_ELF_H_)
|
||||
#define _RTEMS_RTL_ELF_H_
|
||||
|
||||
#include "rtl-fwd.h"
|
||||
#include "rtl-obj-fwd.h"
|
||||
#include "rtl-sym.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
** Imported NetBSD ELF Specifics Start.
|
||||
**/
|
||||
|
||||
/*
|
||||
* Always 32bit for RTEMS at the moment. Do not add '()'. Leave plain.
|
||||
*/
|
||||
#define ELFSIZE 32
|
||||
|
||||
/*
|
||||
* Define _STANDALONE then remove after.
|
||||
*/
|
||||
#define _STANDALONE 1
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/exec_elf.h>
|
||||
|
||||
#undef _STANDALONE
|
||||
|
||||
/**
|
||||
** Imported NetBSD ELF Specifics End.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Maximum string length. This a read buffering limit rather than a
|
||||
* specific ELF length. I hope this is ok as I am concerned about
|
||||
* some C++ symbol lengths.
|
||||
*/
|
||||
#define RTEMS_RTL_ELF_STRING_MAX (256)
|
||||
|
||||
/**
|
||||
* Architecture specific handler to check is a relocation record's type is
|
||||
* required to resolve a symbol.
|
||||
*
|
||||
* @param type The type field in the relocation record.
|
||||
* @retval true The relocation record require symbol resolution.
|
||||
* @retval false The relocation record does not require symbol resolution.
|
||||
*/
|
||||
bool rtems_rtl_elf_rel_resolve_sym (Elf_Word type);
|
||||
|
||||
/**
|
||||
* Architecture specific relocation handler compiled in for a specific
|
||||
* architecture by the build system. The handler applies the relocation
|
||||
* to the target.
|
||||
*
|
||||
* @param obj The object file being relocated.
|
||||
* @param rel The ELF relocation record.
|
||||
* @param sect The section of the object file the relocation is for.
|
||||
* @param symname The symbol's name.
|
||||
* @param syminfo The ELF symbol info field.
|
||||
* @param symvalue If a symbol is referenced, this is the symbols value.
|
||||
* @retval bool The relocation has been applied.
|
||||
* @retval bool The relocation could not be applied.
|
||||
*/
|
||||
bool rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue);
|
||||
|
||||
/**
|
||||
* Architecture specific relocation handler compiled in for a specific
|
||||
* architecture by the build system. The handler applies the relocation
|
||||
* to the target.
|
||||
*
|
||||
* @param obj The object file being relocated.
|
||||
* @param rela The ELF addend relocation record.
|
||||
* @param sect The section of the object file the relocation is for.
|
||||
* @param symname The symbol's name.
|
||||
* @param syminfo The ELF symbol info field.
|
||||
* @param symvalue If a symbol is referenced, this is the symbols value.
|
||||
* @retval bool The relocation has been applied.
|
||||
* @retval bool The relocation could not be applied.
|
||||
*/
|
||||
bool rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue);
|
||||
|
||||
/**
|
||||
* Find the symbol. The symbol is passed as an ELF type symbol with the name
|
||||
* and the value returned is the absolute address of the symbol.
|
||||
*
|
||||
* If the symbol type is STT_NOTYPE the symbol references a global symbol. The
|
||||
* gobal symbol table is searched to find it and that value returned. If the
|
||||
* symbol is local to the object module the section for the symbol is located
|
||||
* and it's base added to the symbol's value giving an absolute location.
|
||||
*
|
||||
* @param obj The object the symbol is being resolved for.
|
||||
* @param sym The ELF type symbol.
|
||||
* @param symname The sym's name read from the symbol string table.
|
||||
* @param value Return the value of the symbol. Only valid if the return value
|
||||
* is true.
|
||||
* @retval true The symbol resolved.
|
||||
* @retval false The symbol could not be result. The RTL error is set.
|
||||
*/
|
||||
bool rtems_rtl_elf_find_symbol (rtems_rtl_obj_t* obj,
|
||||
const Elf_Sym* sym,
|
||||
const char* symname,
|
||||
Elf_Word* value);
|
||||
|
||||
/**
|
||||
* The ELF format check handler.
|
||||
*
|
||||
* @param obj The object being checked.
|
||||
* @param fd The file descriptor.
|
||||
*/
|
||||
bool rtems_rtl_elf_file_check (rtems_rtl_obj_t* obj, int fd);
|
||||
|
||||
/**
|
||||
* The ELF file details handler.
|
||||
*
|
||||
* @param obj Load the details of the obj.
|
||||
*/
|
||||
bool rtems_rtl_elf_load_details (rtems_rtl_obj_t* obj);
|
||||
|
||||
/**
|
||||
* The ELF format load handler.
|
||||
*
|
||||
* @param obj The object to load.
|
||||
* @param fd The file descriptor.
|
||||
*/
|
||||
bool rtems_rtl_elf_file_load (rtems_rtl_obj_t* obj, int fd);
|
||||
|
||||
/**
|
||||
* The ELF format signature handler.
|
||||
*
|
||||
* @return rtems_rtl_loader_format_t* The format's signature.
|
||||
*/
|
||||
rtems_rtl_loader_format_t* rtems_rtl_elf_file_sig (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Error
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-error.h"
|
||||
|
||||
void
|
||||
rtems_rtl_set_error (int error, const char* format, ...)
|
||||
{
|
||||
rtems_rtl_data_t* rtl = rtems_rtl_lock ();
|
||||
va_list ap;
|
||||
va_start (ap, format);
|
||||
rtl->last_errno = error;
|
||||
vsnprintf (rtl->last_error, sizeof (rtl->last_error), format, ap);
|
||||
rtems_rtl_unlock ();
|
||||
va_end (ap);
|
||||
}
|
||||
|
||||
int
|
||||
rtems_rtl_get_error (char* message, size_t max_message)
|
||||
{
|
||||
rtems_rtl_data_t* rtl = rtems_rtl_lock ();
|
||||
int last_errno = rtl->last_errno;
|
||||
strncpy (message, rtl->last_error, sizeof (rtl->last_error));
|
||||
rtems_rtl_unlock ();
|
||||
return last_errno;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Error
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_ERROR_H_)
|
||||
#define _RTEMS_RTL_ERROR_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if __GNUC__
|
||||
#define RTEMS_RTL_PRINTF_ATTR __attribute__((__format__(__printf__,2,3)))
|
||||
#else
|
||||
#define RTEMS_RTL_PRINTF_ATTR
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Sets the error.
|
||||
*
|
||||
* Assumes the RTL has been locked.
|
||||
*
|
||||
* @param error The errno error number.
|
||||
* @param format The error format string.
|
||||
* @param ... The variable arguments that depend on the format string.
|
||||
*/
|
||||
void rtems_rtl_set_error (int error, const char* format, ...) RTEMS_RTL_PRINTF_ATTR;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012-2013 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Error
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rtems/libio_.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-find-file.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-string.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
#if WAF_BUILD
|
||||
#define rtems_filesystem_is_delimiter rtems_filesystem_is_separator
|
||||
#endif
|
||||
|
||||
bool
|
||||
rtems_rtl_find_file (const char* name,
|
||||
const char* paths,
|
||||
const char** file_name,
|
||||
size_t* size)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
*file_name = NULL;
|
||||
*size = 0;
|
||||
|
||||
if (rtems_filesystem_is_delimiter (name[0]) || (name[0] == '.'))
|
||||
{
|
||||
if (stat (name, &sb) == 0)
|
||||
*file_name = rtems_rtl_strdup (name);
|
||||
}
|
||||
else if (paths)
|
||||
{
|
||||
const char* start;
|
||||
const char* end;
|
||||
int len;
|
||||
char* fname;
|
||||
|
||||
start = paths;
|
||||
end = start + strlen (paths);
|
||||
len = strlen (name);
|
||||
|
||||
while (!*file_name && (start != end))
|
||||
{
|
||||
const char* delimiter = strchr (start, ':');
|
||||
|
||||
if (delimiter == NULL)
|
||||
delimiter = end;
|
||||
|
||||
/*
|
||||
* Allocate the path fragment, separator, name, terminating nul. Form the
|
||||
* path then see if the stat call works.
|
||||
*/
|
||||
|
||||
fname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT,
|
||||
(delimiter - start) + 1 + len + 1, true);
|
||||
if (!fname)
|
||||
{
|
||||
rtems_rtl_set_error (ENOMEM, "no memory searching for file");
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy (fname, start, delimiter - start);
|
||||
fname[delimiter - start] = '/';
|
||||
memcpy (fname + (delimiter - start) + 1, name, len);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD))
|
||||
printf ("rtl: find-file: path: %s\n", fname);
|
||||
|
||||
if (stat (fname, &sb) < 0)
|
||||
rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, fname);
|
||||
else
|
||||
*file_name = fname;
|
||||
|
||||
start = delimiter;
|
||||
if (start != end)
|
||||
++start;
|
||||
}
|
||||
}
|
||||
|
||||
if (!*file_name)
|
||||
return false;
|
||||
|
||||
*size = sb.st_size;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012-2013 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Object Support.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_FIND_FILE_H_)
|
||||
#define _RTEMS_RTL_FIND_FILE_H_
|
||||
|
||||
#include <rtems.h>
|
||||
#include <rtems/chain.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* Find a file on disk given a name and a path.
|
||||
*
|
||||
* @param name The file name to find. Can be relative or absolute.
|
||||
* @param paths The paths to search.
|
||||
* @param file_name Place the full path in this location if found.
|
||||
* @param size The size of the file if found as returned by the 'stat' call.
|
||||
* @retval true The file was found.
|
||||
* @retval false The file was not found.
|
||||
*/
|
||||
bool rtems_rtl_find_file (const char* name,
|
||||
const char* paths,
|
||||
const char** file_name,
|
||||
size_t* size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker ELF Headers
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_FWD_H_)
|
||||
#define _RTEMS_RTL_FWD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* The forward declaration of the obj structure.
|
||||
*/
|
||||
struct rtems_rtl_data_s;
|
||||
typedef struct rtems_rtl_data_s rtems_rtl_data_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,115 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rtl.h>
|
||||
#include <errno.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline Elf_Addr
|
||||
load_ptr(void *where)
|
||||
{
|
||||
Elf_Addr res;
|
||||
|
||||
memcpy(&res, where, sizeof(res));
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr target = 0;
|
||||
Elf_Addr *where;
|
||||
Elf_Word tmp;
|
||||
Elf_Word size; //byte
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("rela relocation type is %d relocated address 0x%08x",
|
||||
ELF_R_TYPE(rela->r_info), where);
|
||||
}
|
||||
|
||||
tmp = symvalue;
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(UNUSED0):
|
||||
break;
|
||||
|
||||
case R_TYPE(HUIMM16):
|
||||
tmp = symvalue >> 16;
|
||||
case R_TYPE(LUIMM16):
|
||||
case R_TYPE(RIMM16):
|
||||
size = 2;
|
||||
break;
|
||||
|
||||
case R_TYPE(BYTE4_DATA):
|
||||
size = 4;
|
||||
break;
|
||||
|
||||
case R_TYPE(PCREL24):
|
||||
case R_TYPE(PCREL24_JU):
|
||||
where = (Elf_Addr*)((Elf_Addr)where - 2); /* Back 2 bytes */
|
||||
tmp = symvalue - (Elf_Addr)where;
|
||||
tmp >>= 1;
|
||||
if ((tmp & 0x20000000) == 0x20000000)
|
||||
tmp |= 0xc0000000;
|
||||
|
||||
if ((tmp & 0xff000000) && (~tmp & 0xff800000)) {
|
||||
printf("PCREL24/PCREL24_JU Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
tmp = (load_ptr(where) & 0x0000ff00) | ((tmp & 0x0000ffff) << 16) |
|
||||
((tmp & 0x00ff0000) >> 16);
|
||||
size = 4;
|
||||
break;
|
||||
|
||||
case R_TYPE(PCREL12_JUMP_S):
|
||||
tmp = symvalue - (Elf_Addr)where;
|
||||
tmp >>= 1;
|
||||
if ((tmp & 0x20000000) == 0x20000000)
|
||||
tmp |= 0xc0000000;
|
||||
|
||||
if ((tmp & 0xfffff000) && (~tmp & 0xfffff800)) {
|
||||
printf("PCREL12_JUMP_S Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
tmp = ((*(uint16_t *)where) & 0xf000) | (tmp & 0xfff);
|
||||
size = 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Unspported rela type\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy((void*)where, &tmp, size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rel type record not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr *where;
|
||||
Elf_Word tmp;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
|
||||
printf("relocated address 0x%08lx\n", (Elf_Addr)where);
|
||||
}
|
||||
|
||||
tmp = symvalue;
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(DIR16):
|
||||
*(uint16_t *)where += symvalue + rela->r_addend;
|
||||
break;
|
||||
|
||||
case R_TYPE(DIR32):
|
||||
case R_TYPE(DIR32A16):
|
||||
*where += symvalue + rela->r_addend;
|
||||
break;
|
||||
|
||||
case R_TYPE(DIR24A8):
|
||||
if (ELF32_R_SYM(rela->r_info))
|
||||
*where += symvalue + rela->r_addend;
|
||||
break;
|
||||
|
||||
case R_TYPE(DIR24R8):
|
||||
where = (uint32_t *)((uint32_t)where - 1);
|
||||
*where = (*where & 0xff000000) | ((*where & 0xffffff) + symvalue + rela->r_addend);
|
||||
break;
|
||||
|
||||
case R_TYPE(PCREL8):
|
||||
/* bcc instruction */
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where - 1;
|
||||
if (((Elf32_Sword)tmp > 0x7f) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x80)){
|
||||
printf("PCREL8 overflow\n");
|
||||
return false;
|
||||
} else {
|
||||
*(uint8_t *)where = tmp;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_TYPE(PCREL16):
|
||||
/* bcc instruction */
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where - 2;
|
||||
if (((Elf32_Sword)tmp > 0x7fff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x8000)){
|
||||
printf("PCREL16 overflow\n");
|
||||
return false;
|
||||
} else {
|
||||
*(uint16_t *)where = tmp;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
printf("Unsupported reloc types\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rel type record not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Taken from NetBSD and stripped of the relocations not needed on RTEMS.
|
||||
*/
|
||||
|
||||
/* $NetBSD: mdreloc.c,v 1.31 2010/01/14 11:58:32 skrll Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr target = 0;
|
||||
Elf_Addr* where;
|
||||
Elf_Addr tmp;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rel->r_offset);
|
||||
|
||||
switch (ELF_R_TYPE(rel->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(PC32):
|
||||
target = (Elf_Addr) symvalue;
|
||||
*where += target - (Elf_Addr)where;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc PC32 in %s --> %p (%p @ %p) in %s\n",
|
||||
sect->name, (void*) symvalue,
|
||||
(void *)*where, where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(GOT32):
|
||||
case R_TYPE(32):
|
||||
case R_TYPE(GLOB_DAT):
|
||||
target = (Elf_Addr) symvalue;
|
||||
|
||||
tmp = target + *where;
|
||||
if (*where != tmp)
|
||||
*where = tmp;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc 32/GLOB_DAT in %s --> %p @ %p in %s\n",
|
||||
sect->name, (void *)*where, where,
|
||||
rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(RELATIVE):
|
||||
*where += (Elf_Addr)sect->base;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc RELATIVE in %s --> %p @ %p\n",
|
||||
rtems_rtl_obj_oname (obj), (void *)*where, where);
|
||||
break;
|
||||
|
||||
case R_TYPE(COPY):
|
||||
printf ("rtl: reloc COPY (please report)\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
|
||||
"contents = %p\n",
|
||||
ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
|
||||
(void *)rel->r_offset, (void *)*where);
|
||||
rtems_rtl_set_error (EINVAL,
|
||||
"%s: Unsupported relocation type %ld "
|
||||
"in non-PLT relocations",
|
||||
sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr *where;
|
||||
Elf32_Word tmp;
|
||||
Elf32_Word insn;
|
||||
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(HI16):
|
||||
insn = *where;
|
||||
/* orhi/mvhi instruction
|
||||
* 31--------26|25-21|20-16|15----0|
|
||||
* |0 1 1 1 1 0 |rY |rX |imm16 |
|
||||
*/
|
||||
if (0x1e == (insn >> 26)) {
|
||||
insn &= 0xffff0000;
|
||||
insn |= ((symvalue + rela->r_addend) >> 16);
|
||||
*where = insn;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_TYPE(LO16):
|
||||
insn = *where;
|
||||
/* ori instruction
|
||||
* 31--------26|25-21|20-16|15----0|
|
||||
* |0 0 1 1 1 0 |rY |rX |imm16 |
|
||||
*/
|
||||
if (0xe == (insn >> 26)) {
|
||||
insn &= 0xffff0000;
|
||||
insn |= ((symvalue + rela->r_addend) & 0xffff);
|
||||
*where = insn;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_TYPE(CALL):
|
||||
insn = *where;
|
||||
/*
|
||||
* calli instruction
|
||||
* 31-------26|25---0|
|
||||
* |1 1 1 1 1 0|imm26 |
|
||||
* Syntax: call imm26
|
||||
* Operation: ra = pc + 4; pc = pc + sign_extend(imm26<<2)
|
||||
*/
|
||||
if (0x3e == (insn >> 26)) {
|
||||
Elf_Sword imm26 = symvalue +rela->r_addend - (Elf_Addr)where;
|
||||
imm26 = (imm26 >> 2) & 0x3ffffff;
|
||||
insn = 0xf8000000 + imm26;
|
||||
*where = insn;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_TYPE(BRANCH):
|
||||
insn = *where;
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
tmp = (Elf32_Sword)tmp >> 2;
|
||||
if (((Elf32_Sword)tmp > 0x7fff) || ((Elf32_Sword)tmp < -0x8000)){
|
||||
printf("BRANCH Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
*where = (*where & 0xffff0000) | (tmp & 0xffff);
|
||||
break;
|
||||
|
||||
case R_TYPE(32):
|
||||
*where = symvalue + rela->r_addend;
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
printf("Unsupported reloc types\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
|
||||
printf("relocated address 0x%08lx\n", (Elf_Addr)where);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
static inline Elf_Addr
|
||||
load_ptr(void *where)
|
||||
{
|
||||
Elf_Addr res;
|
||||
|
||||
memcpy(&res, where, sizeof(res));
|
||||
|
||||
return (res);
|
||||
}
|
||||
|
||||
static inline void
|
||||
store_ptr(void *where, Elf_Addr val)
|
||||
{
|
||||
memcpy(where, &val, sizeof(val));
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
|
||||
Elf_Addr *where;
|
||||
Elf_Word tmp;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("relocated address 0x%08lx\n", (Elf_Addr)where);
|
||||
}
|
||||
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(16_RELA):
|
||||
/*
|
||||
* half16: S + A
|
||||
*/
|
||||
*(uint16_t *)where = (symvalue + rela->r_addend) & 0xffff;
|
||||
break;
|
||||
|
||||
case R_TYPE(24_RELA):
|
||||
/*
|
||||
* imm24: (S + A) & 0xFFFFFF
|
||||
*/
|
||||
tmp = symvalue + rela->r_addend;
|
||||
if (((Elf_Sword)tmp > 0x7fffff) || ((Elf_Sword)tmp < -0x800000)) {
|
||||
printf("24_RELA Overflow\n");
|
||||
return false;
|
||||
}
|
||||
*where = (*where & 0xff000000) | tmp & 0xffffff;
|
||||
break;
|
||||
|
||||
case R_TYPE(32_RELA):
|
||||
/*
|
||||
* word32: S + A
|
||||
*/
|
||||
*where += symvalue + rela->r_addend;
|
||||
break;
|
||||
|
||||
case R_TYPE(26_PCREL_RELA):
|
||||
/*
|
||||
* disp24: ((S + A - P) >> 2) & 0xFFFFFF
|
||||
*/
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
tmp = (Elf_Sword)tmp >> 2;
|
||||
if (((Elf_Sword)tmp > 0x7fffff) || ((Elf_Sword)tmp < -0x800000)) {
|
||||
printf("26_PCREL_RELA Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
*where = (*where & 0xff000000) | (tmp & 0xffffff);
|
||||
break;
|
||||
|
||||
case R_TYPE(18_PCREL_RELA):
|
||||
/*
|
||||
* disp16: ((S + A - P) >> 2) & 0xFFFFFF
|
||||
*/
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
tmp = (Elf_Sword)tmp >> 2;
|
||||
if (((Elf_Sword)tmp > 0x7fff) || ((Elf_Sword)tmp < -0x8000)) {
|
||||
printf("18_PCREL_RELA Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
*where = (*where & 0xffff0000) | (tmp & 0xffff);
|
||||
break;
|
||||
|
||||
case R_TYPE(HI16_ULO_RELA):
|
||||
/*
|
||||
* imm16: ((S + A) >> 16)
|
||||
*/
|
||||
tmp = *where;
|
||||
tmp += ((symvalue + rela->r_addend) >> 16) & 0xffff;
|
||||
*where = tmp;
|
||||
break;
|
||||
|
||||
case R_TYPE(HI16_SLO_RELA):
|
||||
/*
|
||||
* imm16: ((S + A) >> 16) or ((S + A + 0x10000) >> 16)
|
||||
*/
|
||||
tmp = symvalue + rela->r_addend;
|
||||
if (tmp & 0x8000) tmp += 0x10000;
|
||||
tmp = (tmp >> 16) & 0xffff;
|
||||
*where += tmp;
|
||||
break;
|
||||
|
||||
case R_TYPE(LO16_RELA):
|
||||
/*
|
||||
* imm16: (S + A) & 0xFFFF
|
||||
*/
|
||||
tmp = symvalue + rela->r_addend;
|
||||
*where = (*where & 0xffff0000) | (tmp & 0xffff);
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
printf("Unsupported rela reloc types\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
|
||||
rtems_rtl_set_error (EINVAL, "rel type record not supported");
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Taken from NetBSD and stripped of the relocations not needed on RTEMS.
|
||||
*/
|
||||
|
||||
/* $NetBSD: mdreloc.c,v 1.26 2010/01/14 11:58:32 skrll Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
static inline int overflow_8_check(int value)
|
||||
{
|
||||
if ((value & 0xffffff00) && (~value & 0xffffff80))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline int overflow_16_check(int value)
|
||||
{
|
||||
if ((value & 0xffff0000) && (~value & 0xffff8000))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symnane,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr target = 0;
|
||||
Elf_Addr* where;
|
||||
Elf_Word tmp;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(PC8):
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
if (overflow_8_check(tmp))
|
||||
return false;
|
||||
|
||||
*(uint8_t *)where = tmp;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc R_TYPE_8/PC8 in %s --> %p (%p) in %s\n",
|
||||
sect->name, (void*) (symvalue + rela->r_addend),
|
||||
(void *)*where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(PC16):
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
if (overflow_16_check(tmp))
|
||||
return false;
|
||||
|
||||
*(uint16_t*)where = tmp;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc R_TYPE_16/PC16 in %s --> %p (%p) in %s\n",
|
||||
sect->name, (void*) (symvalue + rela->r_addend),
|
||||
(void *)*where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
case R_TYPE(PC32):
|
||||
target = (Elf_Addr) symvalue + rela->r_addend;
|
||||
*where += target - (Elf_Addr)where;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc PC32 in %s --> %p (%p) in %s\n",
|
||||
sect->name, (void*) (symvalue + rela->r_addend),
|
||||
(void *)*where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(GOT32):
|
||||
case R_TYPE(32):
|
||||
case R_TYPE(GLOB_DAT):
|
||||
target = (Elf_Addr) symvalue + rela->r_addend;
|
||||
|
||||
if (*where != target)
|
||||
*where = target;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc 32/GLOB_DAT in %s --> %p in %s\n",
|
||||
sect->name, (void *)*where,
|
||||
rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(RELATIVE):
|
||||
*where += (Elf_Addr) sect->base + rela->r_addend;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: reloc RELATIVE in %s --> %p\n",
|
||||
rtems_rtl_obj_oname (obj), (void *)*where);
|
||||
break;
|
||||
|
||||
case R_TYPE(COPY):
|
||||
/*
|
||||
* These are deferred until all other relocations have
|
||||
* been done. All we do here is make sure that the
|
||||
* COPY relocation is not in a shared library. They
|
||||
* are allowed only in executable files.
|
||||
*/
|
||||
printf ("rtl: reloc COPY (please report)\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
|
||||
"contents = %p\n",
|
||||
ELF_R_SYM(rela->r_info), (uint32_t) ELF_R_TYPE(rela->r_info),
|
||||
(void *)rela->r_offset, (void *)*where);
|
||||
rtems_rtl_set_error (EINVAL,
|
||||
"%s: Unsupported relocation type %ld "
|
||||
"in non-PLT relocations",
|
||||
sect->name, (uint32_t) ELF_R_TYPE(rela->r_info));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rel type record not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 1. _gp_disp symbol are not considered in this file.
|
||||
* 2. There is a local/external column;
|
||||
* local corresponds to (STB_LOCAL & STT_SECTION) and
|
||||
* all others are external. Because if the type of a
|
||||
* symbol is STT_SECTION, it must be STB_LOCAL. Thus
|
||||
* just consider symtype here.
|
||||
*/
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr *where;
|
||||
Elf_Word tmp;
|
||||
Elf_Word addend = (Elf_Word)0;
|
||||
Elf_Word local = 0;
|
||||
uint32_t t;
|
||||
|
||||
|
||||
static Elf_Addr *where_hi16;
|
||||
static Elf_Addr ahl;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rel->r_offset);
|
||||
addend = *where;
|
||||
|
||||
if (syminfo == STT_SECTION)
|
||||
local = 1;
|
||||
|
||||
switch (ELF_R_TYPE(rel->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(16):
|
||||
tmp = addend & 0xffff;
|
||||
if ((tmp & 0x8000) == 0x8000)
|
||||
tmp |= 0xffff0000; /* Sign extend */
|
||||
tmp = symvalue + (int)tmp;
|
||||
if ((tmp & 0xffff0000) != 0) {
|
||||
printf("R_MIPS_16 Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
*where = (tmp & 0xffff) | (*where & 0xffff0000);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: R_MIPS_16 %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(32):
|
||||
tmp = symvalue + addend;
|
||||
if (addend != tmp)
|
||||
*where = tmp;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: R_MIPS_32 %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(26):
|
||||
|
||||
addend &= 0x03ffffff;
|
||||
addend <<= 2;
|
||||
|
||||
if (local == 1) { /* STB_LOCAL and STT_SECTION */
|
||||
tmp = symvalue + (((Elf_Addr)where & 0xf0000000) | addend);
|
||||
tmp >>= 2;
|
||||
|
||||
} else { /* external */
|
||||
|
||||
tmp = addend;
|
||||
|
||||
if ((tmp & 0x08000000) == 0x08000000)
|
||||
tmp |= 0xf0000000; /* Sign extened */
|
||||
tmp = ((int)tmp + symvalue) >> 2;
|
||||
|
||||
}
|
||||
|
||||
*where &= ~0x03ffffff;
|
||||
*where |= tmp & 0x03ffffff;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: R_MIPS_26 local=%d %p @ %p in %s\n",
|
||||
local, (void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(HI16):
|
||||
ahl = addend << 16;
|
||||
where_hi16 = where;
|
||||
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: R_MIPS_HI16 %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(LO16):
|
||||
//ahl += (int16_t)addend;
|
||||
t = ahl + (int16_t)addend;
|
||||
tmp = symvalue;
|
||||
if (tmp == 0)
|
||||
return false;
|
||||
|
||||
addend &= 0xffff0000;
|
||||
addend |= (uint16_t)(t + tmp);
|
||||
*where = addend;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf("*where %x where %x\n", *where, where);
|
||||
|
||||
addend = *where_hi16;
|
||||
addend &= 0xffff0000;
|
||||
addend |= ((t + tmp) - (int16_t)(t + tmp)) >> 16;
|
||||
*where_hi16 = addend;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf("*where_hi %x where_hi %x\n", *where_hi16, where_hi16);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: R_MIPS_LO16 %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(PC16):
|
||||
tmp = addend & 0xffff;
|
||||
if ((tmp & 0x8000) == 0x8000)
|
||||
tmp |= 0xffff0000; /* Sign extend */
|
||||
tmp = symvalue + ((int)tmp*4) - (Elf_Addr)where;
|
||||
tmp = (Elf_Sword)tmp >> 2;
|
||||
if (((Elf_Sword)tmp > 0x7fff) || ((Elf_Sword)tmp < -0x8000)) {
|
||||
printf("R_MIPS_PC16 Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
*where = (tmp & 0xffff) | (*where & 0xffff0000);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: R_MIPS_PC16 %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
|
||||
"contents = %p\n",
|
||||
ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
|
||||
(void *)rel->r_offset, (void *)*where);
|
||||
rtems_rtl_set_error (EINVAL,
|
||||
"%s: Unsupported relocation type %ld "
|
||||
"in non-PLT relocations",
|
||||
sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr *where;
|
||||
Elf_Sword tmp;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
|
||||
/* Handle the not 4byte aligned address carefully */
|
||||
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(32):
|
||||
*(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff;
|
||||
*((uint16_t *)where + 1) = (symvalue + rela->r_addend) & 0xffff;
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("*where 0x%04x%04x\n", *((uint16_t *)where + 1), *(uint16_t *)where);
|
||||
}
|
||||
break;
|
||||
|
||||
case R_TYPE(PCREL10):
|
||||
/* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("*where %x\n", *(uint16_t *)where);
|
||||
printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where));
|
||||
}
|
||||
tmp = (symvalue + rela->r_addend - ((Elf_Word)where + 2)); /* pc is the next instruction */
|
||||
tmp = (Elf_Sword)tmp >> 1;
|
||||
if (((Elf32_Sword)tmp > 0x1ff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x200)){
|
||||
printf("Overflow for PCREL10: %d exceed -0x200:0x1ff\n", tmp);
|
||||
return false;
|
||||
}
|
||||
|
||||
*(uint16_t *)where = (*(uint16_t *)where & 0xfc00) | (tmp & 0x3ff);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("*where 0x%04x\n", *(uint16_t *)where);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
printf("Unsupported reloc types\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rel type record not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Taken from NetBSD and stripped of the relocations not needed on RTEMS.
|
||||
*/
|
||||
|
||||
/* $NetBSD: mdreloc.c,v 1.26 2010/01/14 11:58:32 skrll Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
rtems_rtl_obj_sect_t* sect,
|
||||
Elf_Word symvalue)
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
rtems_rtl_obj_sect_t* sect,
|
||||
Elf_Word symvalue)
|
||||
{
|
||||
printf ("rtl: rel type record not supported; please report\n");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Taken from NetBSD and stripped of the relocations not needed on RTEMS.
|
||||
*/
|
||||
|
||||
/* $NetBSD: ppc_reloc.c,v 1.44 2010/01/13 20:17:22 christos Exp $ */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
#define ha(x) ((((u_int32_t)(x) & 0x8000) ? \
|
||||
((u_int32_t)(x) + 0x10000) : (u_int32_t)(x)) >> 16)
|
||||
#define l(x) ((u_int32_t)(x) & 0xffff)
|
||||
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr target = 0;
|
||||
Elf_Addr* where;
|
||||
Elf_Word tmp;
|
||||
uint32_t mask = 0;
|
||||
uint32_t bits = 0;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(32):
|
||||
/*
|
||||
* value:1; Field: word32; Expression: S + A
|
||||
*/
|
||||
*where = symvalue + rela->r_addend;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: ADDR32 %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(14):
|
||||
/*
|
||||
* value:7; Field: low14*; Expression: (S + A) >> 2
|
||||
*/
|
||||
case R_TYPE(24):
|
||||
/*
|
||||
* value:2; Field: low24*; Expression: (S + A) >> 2
|
||||
*/
|
||||
if (ELF_R_TYPE(rela->r_info) == R_TYPE(14)) {
|
||||
bits = 14;
|
||||
mask = 0xfffc;
|
||||
} else {
|
||||
bits = 24;
|
||||
mask = 0x3fffffc;
|
||||
}
|
||||
tmp = (symvalue + rela->r_addend) >> 2;
|
||||
if (tmp > (1<<bits -1 )) {
|
||||
printf("Overflow ADDR14/ADDR24\n");
|
||||
return false;
|
||||
}
|
||||
tmp = *where;
|
||||
tmp &= ~mask;
|
||||
tmp |= (symvalue + rela->r_addend) & mask;
|
||||
*where = tmp;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: ADDR14/ADDR24 %p @ %p in %s\n",
|
||||
(void *)*where, where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(16_HA):
|
||||
/*
|
||||
* value:6; Field:half16; Expression: #ha(S+A)
|
||||
*/
|
||||
|
||||
tmp = symvalue + rela->r_addend;
|
||||
*(uint16_t *)where = (((tmp >> 16) + ((tmp & 0x8000) ? 1: 0)) & 0xffff);
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: 16_HA %p @ %p in %s\n",
|
||||
(void *)*(where), where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(16_HI):
|
||||
/*
|
||||
* value:5; Field:half16; Expression: #hi(S+A)
|
||||
*/
|
||||
*(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: 16_HI %p @ %p in %s\n",
|
||||
(void *)*where, where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
case R_TYPE(16_LO):
|
||||
/*
|
||||
* value:4; Field:half16; Expression: #lo(S+A)
|
||||
*/
|
||||
*(uint16_t *)where = (symvalue + (rela->r_addend)) & 0xffff;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: 16_LO %p @ %p in %s\n",
|
||||
(void *)*where, where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(REL14):
|
||||
/*
|
||||
* value:11; Field:low14*; Expression:(S+A-P)>>2
|
||||
*/
|
||||
case R_TYPE(REL24):
|
||||
/*
|
||||
* value:10; Field:low24*; Expression:(S+A-P)>>2
|
||||
*/
|
||||
if (ELF_R_TYPE(rela->r_info) == R_TYPE(REL24)) {
|
||||
mask = 0x3fffffc;
|
||||
bits = 24;
|
||||
}
|
||||
else if (ELF_R_TYPE(rela->r_info) == R_TYPE(REL14)) {
|
||||
mask = 0xfffc;
|
||||
bits = 14;
|
||||
}
|
||||
|
||||
tmp =((int) (symvalue + rela->r_addend - (Elf_Addr)where)) >> 2;
|
||||
if (((Elf_Sword)tmp > ((1<<(bits-1)) - 1)) ||
|
||||
((Elf_Sword)tmp < -(1<<(bits-1)))) {
|
||||
printf("Overflow REL14/REL24\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
tmp = *where;
|
||||
tmp &= ~mask;
|
||||
tmp |= (symvalue + rela->r_addend - (Elf_Addr)where) & mask;
|
||||
*where = tmp;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: REL24/REL14 %p @ %p in %s\n",
|
||||
(void *)*where, where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
case R_TYPE(REL32):
|
||||
/*
|
||||
* value:26; Field:word32*; Expression:S+A-P
|
||||
*/
|
||||
*where = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
|
||||
printf ("rtl: REL32 %p @ %p in %s\n",
|
||||
(void *)*where, where, rtems_rtl_obj_oname (obj));
|
||||
break;
|
||||
|
||||
default:
|
||||
printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
|
||||
"contents = %p\n",
|
||||
ELF_R_SYM(rela->r_info), (uint32_t) ELF_R_TYPE(rela->r_info),
|
||||
(void *)rela->r_offset, (void *)*where);
|
||||
rtems_rtl_set_error (EINVAL,
|
||||
"%s: Unsupported relocation type %ld "
|
||||
"in non-PLT relocations",
|
||||
sect->name, (uint32_t) ELF_R_TYPE(rela->r_info));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
printf ("rtl: rel type record not supported; please report\n");
|
||||
return false;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,97 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include "rtl-elf.h"
|
||||
#include "rtl-error.h"
|
||||
#include "rtl-trace.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rela* rela,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
Elf_Addr *where;
|
||||
Elf_Word tmp;
|
||||
|
||||
where = (Elf_Addr *)(sect->base + rela->r_offset);
|
||||
|
||||
if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
|
||||
printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
|
||||
printf("relocated address 0x%08lx\n", (Elf_Addr)where);
|
||||
}
|
||||
|
||||
switch (ELF_R_TYPE(rela->r_info)) {
|
||||
case R_TYPE(NONE):
|
||||
break;
|
||||
|
||||
case R_TYPE(HI16_S):
|
||||
tmp = (Elf_Sword)(symvalue + rela->r_addend) >> 16;
|
||||
((uint16_t *)where)[0] = tmp & 0xffff;
|
||||
break;
|
||||
|
||||
case R_TYPE(LO16):
|
||||
tmp = symvalue + rela->r_addend;
|
||||
((uint16_t *)where)[0] = tmp & 0xffff;
|
||||
break;
|
||||
|
||||
case R_TYPE(LO16_S1):
|
||||
tmp = symvalue + rela->r_addend;
|
||||
((uint16_t *)where)[0] = tmp & 0xfffe | 0x1;
|
||||
break;
|
||||
|
||||
case R_TYPE(22_PCREL):
|
||||
tmp = symvalue + rela->r_addend - (Elf_Addr)where;
|
||||
if (((Elf_Sword)tmp > 0x1fffff) || ((Elf_Sword)tmp < -0x200000)) {
|
||||
printf("Overflow\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
((uint16_t *)where)[0] = (*(uint16_t *)where & 0xffc0) |
|
||||
((tmp >> 16) & 0x3f);
|
||||
((uint16_t *)where)[1] = (tmp & 0xfffe);
|
||||
|
||||
break;
|
||||
|
||||
case R_TYPE(ABS32):
|
||||
tmp = symvalue + rela->r_addend;
|
||||
tmp += ((uint16_t *)where)[0];
|
||||
tmp += ((uint16_t *)where)[1] << 16;
|
||||
((uint16_t *)where)[0] = tmp & 0xffff;
|
||||
((uint16_t *)where)[1] = (tmp >> 16) & 0xffff;
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_rtl_set_error (EINVAL, "rela type record not supported");
|
||||
printf("error reloc type\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
|
||||
const Elf_Rel* rel,
|
||||
const rtems_rtl_obj_sect_t* sect,
|
||||
const char* symname,
|
||||
const Elf_Byte syminfo,
|
||||
const Elf_Word symvalue)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "rel type record not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Object File cache buffers a section of the
|
||||
* object file in a buffer to localise read performance.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rtems/rtl/rtl-allocator.h>
|
||||
#include "rtl-obj-cache.h"
|
||||
#include "rtl-error.h"
|
||||
|
||||
bool
|
||||
rtems_rtl_obj_cache_open (rtems_rtl_obj_cache_t* cache, size_t size)
|
||||
{
|
||||
cache->fd = -1;
|
||||
cache->file_size = 0;
|
||||
cache->offset = 0;
|
||||
cache->size = size;
|
||||
cache->level = 0;
|
||||
cache->buffer = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, size, false);
|
||||
if (!cache->buffer)
|
||||
{
|
||||
rtems_rtl_set_error (ENOMEM, "no memory for cache buffer");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
rtems_rtl_obj_cache_close (rtems_rtl_obj_cache_t* cache)
|
||||
{
|
||||
rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, cache->buffer);
|
||||
cache->fd = -1;
|
||||
cache->file_size = 0;
|
||||
cache->level = 0;
|
||||
}
|
||||
|
||||
void
|
||||
rtems_rtl_obj_cache_flush (rtems_rtl_obj_cache_t* cache)
|
||||
{
|
||||
cache->fd = -1;
|
||||
cache->file_size = 0;
|
||||
cache->level = 0;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_obj_cache_read (rtems_rtl_obj_cache_t* cache,
|
||||
int fd,
|
||||
off_t offset,
|
||||
void** buffer,
|
||||
size_t* length)
|
||||
{
|
||||
struct stat sb;
|
||||
|
||||
if (*length > cache->size)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "read size larger than cache size");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cache->fd == fd)
|
||||
{
|
||||
if (offset > cache->file_size)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "offset past end of file: offset=%i size=%i",
|
||||
(int) offset, (int) cache->file_size);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((offset + *length) > cache->file_size)
|
||||
*length = cache->file_size - offset;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
size_t buffer_offset = 0;
|
||||
size_t buffer_read = cache->size;
|
||||
|
||||
/*
|
||||
* Is the data in the cache for this file ?
|
||||
*/
|
||||
if (fd == cache->fd)
|
||||
{
|
||||
/*
|
||||
* Is any part of the data in the cache ?
|
||||
*/
|
||||
if ((offset >= cache->offset) &&
|
||||
(offset < (cache->offset + cache->level)))
|
||||
{
|
||||
buffer_offset = offset - cache->offset;
|
||||
|
||||
/*
|
||||
* Return the location of the data in the cache.
|
||||
*/
|
||||
*buffer = cache->buffer + buffer_offset;
|
||||
|
||||
/*
|
||||
* Is all the data in the cache or just a part ?
|
||||
*/
|
||||
if (*length <= (cache->level - buffer_offset))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy down the data in the buffer and then fill the remaining
|
||||
* space with as much data we are able to read.
|
||||
*/
|
||||
memmove (cache->buffer,
|
||||
cache->buffer + buffer_offset,
|
||||
cache->size - buffer_offset);
|
||||
|
||||
buffer_read = buffer_offset;
|
||||
buffer_offset = cache->size - buffer_offset;
|
||||
}
|
||||
}
|
||||
|
||||
if (lseek (fd, offset + buffer_offset, SEEK_SET) < 0)
|
||||
{
|
||||
rtems_rtl_set_error (errno, "file seek failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Loop reading the data from the file until either an error or 0 is
|
||||
* returned and if data has been read check if the amount is what we
|
||||
* want. If not it is an error. A POSIX read can read data in fragments.
|
||||
*/
|
||||
cache->level = buffer_read;
|
||||
while (buffer_read)
|
||||
{
|
||||
int r = read (fd, cache->buffer + buffer_offset, buffer_read);
|
||||
if (r < 0)
|
||||
{
|
||||
rtems_rtl_set_error (errno, "file read failed");
|
||||
return false;
|
||||
}
|
||||
if ((r == 0) && buffer_read)
|
||||
{
|
||||
cache->level = cache->level - buffer_read;
|
||||
buffer_read = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer_read -= r;
|
||||
buffer_offset += r;
|
||||
}
|
||||
}
|
||||
|
||||
cache->fd = fd;
|
||||
cache->offset = offset;
|
||||
|
||||
if (fstat (cache->fd, &sb) < 0)
|
||||
{
|
||||
rtems_rtl_set_error (errno, "file stat failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
cache->file_size = sb.st_size;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_obj_cache_read_byval (rtems_rtl_obj_cache_t* cache,
|
||||
int fd,
|
||||
off_t offset,
|
||||
void* buffer,
|
||||
size_t length)
|
||||
{
|
||||
void* cbuffer = 0;
|
||||
size_t len = length;
|
||||
bool ok = rtems_rtl_obj_cache_read (cache, fd, offset, &cbuffer, &len);
|
||||
if (ok && (len != length))
|
||||
ok = false;
|
||||
if (ok)
|
||||
memcpy (buffer, cbuffer, length);
|
||||
return ok;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Object File cache buffers a section of the
|
||||
* object file in a buffer to localise read performance.
|
||||
*
|
||||
* This is a simple object file cache that holds a buffer of data from the
|
||||
* offset in the file the read is requested from. Writes are not supported.
|
||||
*
|
||||
* The cache holds the file descriptor, the offset into the file and the amount
|
||||
* of valid data in the cache. If the file is ever modified the user of the
|
||||
* cache to responsible for flushing the cache. For example the cache should be
|
||||
* flused if the file is closed.
|
||||
*
|
||||
* The cache can return by reference or by value. By reference allow access to
|
||||
* the cache buffer. Do not modify the cache's data. By value will copy the
|
||||
* requested data into the user supplied buffer.
|
||||
*
|
||||
* The read by reference call allows you to probe the file's data. For example
|
||||
* a string in an object file can be an unknown length. You can request a read
|
||||
* up to the cache's size by reference. The code will attempt to have this data
|
||||
* in the buffer. If there is not enough data in the file the length will be
|
||||
* modifed to reflect this.
|
||||
*
|
||||
* You can have more than one cache for a single file all looking at different
|
||||
* parts of the file.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_OBJ_CACHE_H_)
|
||||
#define _RTEMS_RTL_OBJ_CACHE_H_
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* The buffer cache.
|
||||
*/
|
||||
typedef struct rtems_rtl_obj_cache_s
|
||||
{
|
||||
int fd; /**< The file descriptor of the data in the cache. */
|
||||
size_t file_size; /**< The size of the file. */
|
||||
off_t offset; /**< The base offset of the buffer. */
|
||||
size_t size; /**< The size of the cache. */
|
||||
size_t level; /**< The amount of data in the cache. A file can be
|
||||
* smaller than the cache file. */
|
||||
uint8_t* buffer; /**< The buffer */
|
||||
} rtems_rtl_obj_cache_t;
|
||||
|
||||
/**
|
||||
* Open a cache allocating a single buffer of the size passed. The default
|
||||
* state of the cache is flushed. No already open checks are made.
|
||||
*
|
||||
* @param cache The cache to initialise.
|
||||
* @param size The size of the cache.
|
||||
* @retval true The cache is open.
|
||||
* @retval false The cache is not open. The RTL error is set.
|
||||
*/
|
||||
bool rtems_rtl_obj_cache_open (rtems_rtl_obj_cache_t* cache, size_t size);
|
||||
|
||||
/**
|
||||
* Close a cache.
|
||||
*
|
||||
* @param cache The cache to close.
|
||||
*/
|
||||
void rtems_rtl_obj_cache_close (rtems_rtl_obj_cache_t* cache);
|
||||
|
||||
/**
|
||||
* Flush the cache. Any further read will read the data from the file.
|
||||
*
|
||||
* @param cache The cache to flush.
|
||||
*/
|
||||
void rtems_rtl_obj_cache_flush (rtems_rtl_obj_cache_t* cache);
|
||||
|
||||
/**
|
||||
* Read data by reference. The length contains the amount of data that should
|
||||
* be available in the cache and referenced by the buffer handle. It must be
|
||||
* less than or equal to the size of the cache. This call will return the
|
||||
* amount of data that is available. It can be less than you ask if the offset
|
||||
* and size is past the end of the file.
|
||||
*
|
||||
* @param cache The cache to reference data from.
|
||||
* @param fd The file descriptor. Must be an open file.
|
||||
* @param offset The offset in the file to reference the data to.
|
||||
* @param buffer The location to reference the data from.
|
||||
* @param length The length of data to reference. Can be modified to a
|
||||
* lesser value and true is still returned so check it.
|
||||
* @retval true The data referenced is in the cache.
|
||||
* @retval false The read failed and the RTL error has been set.
|
||||
*/
|
||||
bool rtems_rtl_obj_cache_read (rtems_rtl_obj_cache_t* cache,
|
||||
int fd,
|
||||
off_t offset,
|
||||
void** buffer,
|
||||
size_t* length);
|
||||
|
||||
/**
|
||||
* Read data by value. The data is copied to the user supplied buffer.
|
||||
*
|
||||
* @param cache The cache to read the data from.
|
||||
* @param fd The file descriptor. Must be an open file.
|
||||
* @param offset The offset in the file to read the data from.
|
||||
* @param buffer The location the data is written into.
|
||||
* @param length The length of data to read.
|
||||
* @retval true The data has been read from the cache.
|
||||
* @retval false The read failed and the RTL error has been set.
|
||||
*/
|
||||
bool rtems_rtl_obj_cache_read_byval (rtems_rtl_obj_cache_t* cache,
|
||||
int fd,
|
||||
off_t offset,
|
||||
void* buffer,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Object Compression manages a compress
|
||||
* stream of data.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rtems/rtl/rtl-allocator.h>
|
||||
#include "rtl-obj-comp.h"
|
||||
#include "rtl-error.h"
|
||||
|
||||
#include "fastlz.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
bool
|
||||
rtems_rtl_obj_comp_open (rtems_rtl_obj_comp_t* comp,
|
||||
size_t size)
|
||||
{
|
||||
comp->cache = NULL;
|
||||
comp->fd = -1;
|
||||
comp->compression = RTEMS_RTL_COMP_LZ77;
|
||||
comp->offset = 0;
|
||||
comp->size = size;
|
||||
comp->level = 0;
|
||||
comp->buffer = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, size, false);
|
||||
if (!comp->buffer)
|
||||
{
|
||||
rtems_rtl_set_error (ENOMEM, "no memory for compressor buffer");
|
||||
return false;
|
||||
}
|
||||
comp->read = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
rtems_rtl_obj_comp_close (rtems_rtl_obj_comp_t* comp)
|
||||
{
|
||||
rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, comp->buffer);
|
||||
comp->cache = NULL;
|
||||
comp->fd = -1;
|
||||
comp->compression = RTEMS_RTL_COMP_LZ77;
|
||||
comp->level = 0;
|
||||
comp->size = 0;
|
||||
comp->offset = 0;
|
||||
comp->read = 0;
|
||||
}
|
||||
|
||||
void
|
||||
rtems_rtl_obj_comp_set (rtems_rtl_obj_comp_t* comp,
|
||||
rtems_rtl_obj_cache_t* cache,
|
||||
int fd,
|
||||
int compression,
|
||||
off_t offset)
|
||||
{
|
||||
comp->cache = cache;
|
||||
comp->fd = fd;
|
||||
comp->compression = compression;
|
||||
comp->offset = offset;
|
||||
comp->level = 0;
|
||||
comp->read = 0;
|
||||
}
|
||||
|
||||
bool
|
||||
rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
|
||||
void* buffer,
|
||||
size_t length)
|
||||
{
|
||||
uint8_t* bin = buffer;
|
||||
|
||||
if (!comp->cache)
|
||||
{
|
||||
rtems_rtl_set_error (EINVAL, "not open");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (comp->fd != comp->cache->fd)
|
||||
{
|
||||
comp->level = 0;
|
||||
}
|
||||
|
||||
while (length)
|
||||
{
|
||||
size_t buffer_level;
|
||||
|
||||
buffer_level = length > comp->level ? comp->level : length;
|
||||
|
||||
if (buffer_level)
|
||||
{
|
||||
memcpy (bin, comp->buffer, buffer_level);
|
||||
|
||||
if ((comp->level - buffer_level) != 0)
|
||||
{
|
||||
memmove (comp->buffer,
|
||||
comp->buffer + buffer_level,
|
||||
comp->level - buffer_level);
|
||||
}
|
||||
|
||||
bin += buffer_level;
|
||||
length -= buffer_level;
|
||||
comp->level -= buffer_level;
|
||||
comp->read += buffer_level;
|
||||
}
|
||||
|
||||
if (length)
|
||||
{
|
||||
uint8_t* input = NULL;
|
||||
uint16_t block_size;
|
||||
size_t in_length = sizeof (block_size);
|
||||
int decompressed;
|
||||
|
||||
if (!rtems_rtl_obj_cache_read (comp->cache, comp->fd, comp->offset,
|
||||
(void**) &input, &in_length))
|
||||
return false;
|
||||
|
||||
block_size = (input[0] << 8) | input[1];
|
||||
|
||||
comp->offset += sizeof (block_size);
|
||||
|
||||
in_length = block_size;
|
||||
|
||||
if (!rtems_rtl_obj_cache_read (comp->cache, comp->fd, comp->offset,
|
||||
(void**) &input, &in_length))
|
||||
return false;
|
||||
|
||||
if (in_length != block_size)
|
||||
{
|
||||
rtems_rtl_set_error (EIO, "compressed read failed: bs=%u in=%u",
|
||||
block_size, in_length);
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (comp->compression)
|
||||
{
|
||||
case RTEMS_RTL_COMP_NONE:
|
||||
memcpy (comp->buffer, input, in_length);
|
||||
decompressed = in_length;
|
||||
break;
|
||||
|
||||
case RTEMS_RTL_COMP_LZ77:
|
||||
decompressed = fastlz_decompress (input, in_length,
|
||||
comp->buffer, comp->size);
|
||||
if (decompressed == 0)
|
||||
{
|
||||
rtems_rtl_set_error (EBADF, "decompression failed");
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
rtems_rtl_set_error (EINVAL, "bad compression type");
|
||||
return false;
|
||||
}
|
||||
|
||||
comp->offset += block_size;
|
||||
|
||||
comp->level = decompressed;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Object File Compression manages a
|
||||
* compressed stream of data.
|
||||
*
|
||||
* This is a simple interface to the object file cache to stream data from
|
||||
* from a compressed object file. There is no ability to seek with the
|
||||
* data from a compressed file. The module exists to allocate the output
|
||||
* buffer when the loader starts and use the cache buffers will have been
|
||||
* allocated.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_OBJ_COMP_H_)
|
||||
#define _RTEMS_RTL_OBJ_COMP_H_
|
||||
|
||||
#include <rtems/rtl/rtl-obj-cache.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* The amount of input data read at a time from the file.
|
||||
*/
|
||||
#define RTEMS_RTL_DECOMP_INPUT_SIZE (256)
|
||||
|
||||
/**
|
||||
* The types of supported compression.
|
||||
*/
|
||||
#define RTEMS_RTL_COMP_NONE (0)
|
||||
#define RTEMS_RTL_COMP_LZ77 (1)
|
||||
|
||||
/**
|
||||
* The compressed file.
|
||||
*/
|
||||
typedef struct rtems_rtl_obj_cpmp_s
|
||||
{
|
||||
rtems_rtl_obj_cache_t* cache; /**< The cache provides the input
|
||||
* buffer. */
|
||||
int fd; /**< The file descriptor. */
|
||||
int compression; /**< The type of compression. */
|
||||
off_t offset; /**< The base offset of the buffer. */
|
||||
size_t size; /**< The size of the output buffer. */
|
||||
size_t level; /**< The amount of data in the buffer. */
|
||||
uint8_t* buffer; /**< The buffer */
|
||||
uint32_t read; /**< The amount of data read. */
|
||||
} rtems_rtl_obj_comp_t;
|
||||
|
||||
/**
|
||||
* Return the input level.
|
||||
*/
|
||||
static inline uint32_t rtems_rtl_obj_comp_input (rtems_rtl_obj_comp_t* comp)
|
||||
{
|
||||
return comp->read;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a compressor allocating the output buffer.
|
||||
*
|
||||
* @param comp The compressor to initialise.
|
||||
* @param size The size of the compressor's output buffer.
|
||||
* @retval true The compressor is open.
|
||||
* @retval false The compressor is not open. The RTL error is set.
|
||||
*/
|
||||
bool rtems_rtl_obj_comp_open (rtems_rtl_obj_comp_t* comp,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* Close a compressor.
|
||||
*
|
||||
* @param comp The compressor to close.
|
||||
*/
|
||||
void rtems_rtl_obj_comp_close (rtems_rtl_obj_comp_t* comp);
|
||||
|
||||
/**
|
||||
* Set the cache and offset in the file the compressed stream starts.
|
||||
*
|
||||
* @param comp The compressor to set the offset in.
|
||||
* @param cache The cache to read the file in by.
|
||||
* @param fd The file descriptor. Must be an open file.
|
||||
* @param compression The type of compression being streamed.
|
||||
* @param offset The offset in the file the compressed stream starts.
|
||||
*/
|
||||
void rtems_rtl_obj_comp_set (rtems_rtl_obj_comp_t* comp,
|
||||
rtems_rtl_obj_cache_t* cache,
|
||||
int fd,
|
||||
int compression,
|
||||
off_t offset);
|
||||
|
||||
/**
|
||||
* Read decompressed data. The length contains the amount of data that should
|
||||
* be available in the cache and referenced by the buffer handle. It must be
|
||||
* less than or equal to the size of the cache. This call will return the
|
||||
* amount of data that is available. It can be less than you ask if the offset
|
||||
* and size is past the end of the file.
|
||||
*
|
||||
* @param comp The compressor to read data from.
|
||||
* @param buffer The buffer the output is written too.
|
||||
* @param length The length of data to read. Can be modified to a
|
||||
* lesser value and true is still returned so check it.
|
||||
* @retval true The data referenced is in the cache.
|
||||
* @retval false The read failed and the RTL error has been set.
|
||||
*/
|
||||
bool rtems_rtl_obj_comp_read (rtems_rtl_obj_comp_t* comp,
|
||||
void* buffer,
|
||||
size_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker ELF Headers
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_OBJ_FWD_H_)
|
||||
#define _RTEMS_RTL_OBJ_FWD_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* The forward declaration of the obj section structure.
|
||||
*/
|
||||
struct rtems_rtl_obj_sect_s;
|
||||
typedef struct rtems_rtl_obj_sect_s rtems_rtl_obj_sect_t;
|
||||
|
||||
/**
|
||||
* The forward declaration of the obj structure.
|
||||
*/
|
||||
struct rtems_rtl_obj_s;
|
||||
typedef struct rtems_rtl_obj_s rtems_rtl_obj_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker ELF Headers
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_RAP_H_)
|
||||
#define _RTEMS_RTL_RAP_H_
|
||||
|
||||
#include "rtl-fwd.h"
|
||||
#include "rtl-obj-fwd.h"
|
||||
#include "rtl-sym.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* The RAP format check handler.
|
||||
*
|
||||
* @param obj The object being checked.
|
||||
* @param fd The file descriptor.
|
||||
*/
|
||||
bool rtems_rtl_rap_file_check (rtems_rtl_obj_t* obj, int fd);
|
||||
|
||||
/**
|
||||
* The RAP format load handler.
|
||||
*
|
||||
* @param obj The object to load.
|
||||
* @param fd The file descriptor.
|
||||
*/
|
||||
bool rtems_rtl_rap_file_load (rtems_rtl_obj_t* obj, int fd);
|
||||
|
||||
/**
|
||||
* The RAP format signature handler.
|
||||
*
|
||||
* @return rtems_rtl_loader_format_t* The format's signature.
|
||||
*/
|
||||
rtems_rtl_loader_format_t* rtems_rtl_rap_file_sig (void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker ELF Shell Support.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_SHELL_H_)
|
||||
#define _RTEMS_RTL_SHELL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* The RTL single shell command contains sub-commands.
|
||||
*
|
||||
* @param argc The argument count.
|
||||
* @param argv Array of argument strings.
|
||||
* @retval 0 No error.
|
||||
* @return int The exit code.
|
||||
*/
|
||||
int rtems_rtl_shell_command (int argc, char* argv[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker String managment.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "rtl-allocator.h"
|
||||
#include "rtl-string.h"
|
||||
|
||||
char*
|
||||
rtems_rtl_strdup (const char *s1)
|
||||
{
|
||||
size_t len = strlen (s1);
|
||||
char* s2 = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, len + 1, false);
|
||||
if (s2)
|
||||
{
|
||||
memcpy (s2, s1, len);
|
||||
s2[len] = '\0';
|
||||
}
|
||||
return s2;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker String managment.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_STRING_H_)
|
||||
#define _RTEMS_RTL_STRING_H_
|
||||
|
||||
#include "rtl-indirect-ptr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* A string duplicate that uses the RTL allocator.
|
||||
*
|
||||
* @param s1 The string to duplicate.
|
||||
* @return char* The copy of the string. NULL if there is no memory.
|
||||
*/
|
||||
char* rtems_rtl_strdup (const char *s1);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker Object File Symbol Table.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_SYM_H_)
|
||||
#define _RTEMS_RTL_SYM_H_
|
||||
|
||||
#include <rtems.h>
|
||||
#include "rtl-obj-fwd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/**
|
||||
* An object file symbol.
|
||||
*/
|
||||
typedef struct rtems_rtl_obj_sym_s
|
||||
{
|
||||
rtems_chain_node node; /**< The node's link in the chain. */
|
||||
const char* name; /**< The symbol's name. */
|
||||
void* value; /**< The value of the symbol. */
|
||||
uint32_t data; /**< Format specific data. */
|
||||
} rtems_rtl_obj_sym_t;
|
||||
|
||||
/**
|
||||
* Table of symbols stored in a hash table.
|
||||
*/
|
||||
typedef struct rtems_rtl_symbols_s
|
||||
{
|
||||
rtems_chain_control* buckets;
|
||||
size_t nbuckets;
|
||||
} rtems_rtl_symbols_t;
|
||||
|
||||
/**
|
||||
* Open a symbol table with the specified number of buckets.
|
||||
*
|
||||
* @param symbols The symbol table to open.
|
||||
* @param buckets The number of buckets in the hash table.
|
||||
* @retval true The symbol is open.
|
||||
* @retval false The symbol table could not created. The RTL
|
||||
* error has the error.
|
||||
*/
|
||||
bool rtems_rtl_symbol_table_open (rtems_rtl_symbols_t* symbols,
|
||||
size_t buckets);
|
||||
|
||||
/**
|
||||
* Close the table and erase the hash table.
|
||||
*
|
||||
* @param symbols Close the symbol table.
|
||||
*/
|
||||
void rtems_rtl_symbol_table_close (rtems_rtl_symbols_t* symbols);
|
||||
|
||||
/**
|
||||
* Add a table of exported symbols to the symbol table.
|
||||
*
|
||||
* The export table is a series of symbol records and each record has two
|
||||
* fields:
|
||||
*
|
||||
* 1. label
|
||||
* 2. address
|
||||
*
|
||||
* The 'label' is an ASCIIZ string of variable length. The address is of size
|
||||
* of an unsigned long for the target running the link editor. The byte order
|
||||
* is defined by the machine type because the table should be built by the
|
||||
* target compiler.
|
||||
*
|
||||
* The table is terminated with a nul string followed by the bytes 0xDE, 0xAD,
|
||||
* 0xBE, and 0xEF. This avoids alignments issues.
|
||||
*
|
||||
* @param obj The object table the symbols are for.
|
||||
* @param esyms The exported symbol table.
|
||||
* @param size The size of the table in bytes.
|
||||
*/
|
||||
bool rtems_rtl_symbol_global_add (rtems_rtl_obj_t* obj,
|
||||
const unsigned char* esyms,
|
||||
unsigned int size);
|
||||
|
||||
/**
|
||||
* Find a symbol given the symbol label in the global symbol table.
|
||||
*
|
||||
* @param name The name as an ASCIIZ string.
|
||||
* @retval NULL No symbol found.
|
||||
* @return rtems_rtl_obj_sym_t* Reference to the symbol.
|
||||
*/
|
||||
rtems_rtl_obj_sym_t* rtems_rtl_symbol_global_find (const char* name);
|
||||
|
||||
/**
|
||||
* Find a symbol given the symbol label in the local object file.
|
||||
*
|
||||
* @param obj The object file to search.
|
||||
* @param name The name as an ASCIIZ string.
|
||||
* @retval NULL No symbol found.
|
||||
* @return rtems_rtl_obj_sym_t* Reference to the symbol.
|
||||
*/
|
||||
rtems_rtl_obj_sym_t* rtems_rtl_symbol_obj_find (rtems_rtl_obj_t* obj,
|
||||
const char* name);
|
||||
|
||||
/**
|
||||
* Add the object file's symbols to the global table.
|
||||
*
|
||||
* @param obj The object file the symbols are to be added.
|
||||
*/
|
||||
void rtems_rtl_symbol_obj_add (rtems_rtl_obj_t* obj);
|
||||
|
||||
/**
|
||||
* Erase the object file's symbols.
|
||||
*
|
||||
* @param obj The object file the symbols are to be erased from.
|
||||
*/
|
||||
void rtems_rtl_symbol_obj_erase (rtems_rtl_obj_t* obj);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtld
|
||||
*
|
||||
* @brief RTEMS Run-Time Link Editor Trace
|
||||
*
|
||||
* A configurable tracer for the RTL. See the header file for the enable and
|
||||
* disable.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rtl-trace.h"
|
||||
|
||||
#if RTEMS_RTL_TRACE
|
||||
static rtems_rtl_trace_mask rtems_rtl_trace_flags;
|
||||
|
||||
bool
|
||||
rtems_rtl_trace (rtems_rtl_trace_mask mask)
|
||||
{
|
||||
bool result = false;
|
||||
if (mask & rtems_rtl_trace_flags)
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
rtems_rtl_trace_mask
|
||||
rtems_rtl_trace_set_mask (rtems_rtl_trace_mask mask)
|
||||
{
|
||||
rtems_rtl_trace_mask state = rtems_rtl_trace_flags;
|
||||
rtems_rtl_trace_flags |= mask;
|
||||
return state;
|
||||
}
|
||||
|
||||
rtems_rtl_trace_mask
|
||||
rtems_rtl_trace_clear_mask (rtems_rtl_trace_mask mask)
|
||||
{
|
||||
rtems_rtl_trace_mask state = rtems_rtl_trace_flags;
|
||||
rtems_rtl_trace_flags &= ~mask;
|
||||
return state;
|
||||
}
|
||||
|
||||
int
|
||||
rtems_rtl_trace_shell_command (int argc, char *argv[])
|
||||
{
|
||||
const char* table[] =
|
||||
{
|
||||
"load",
|
||||
"unload",
|
||||
"section",
|
||||
"symbol",
|
||||
"reloc",
|
||||
"global-sym",
|
||||
"load-sect",
|
||||
"allocator",
|
||||
"unresolved",
|
||||
"detail"
|
||||
};
|
||||
|
||||
rtems_rtl_trace_mask set_value = 0;
|
||||
rtems_rtl_trace_mask clear_value = 0;
|
||||
bool set = true;
|
||||
int arg;
|
||||
int t;
|
||||
|
||||
for (arg = 1; arg < argc; arg++)
|
||||
{
|
||||
if (argv[arg][0] == '-')
|
||||
{
|
||||
switch (argv[arg][1])
|
||||
{
|
||||
case 'h':
|
||||
printf ("usage: %s [-hl] [set/clear] [flags]\n", argv[0]);
|
||||
return 0;
|
||||
case 'l':
|
||||
printf ("%s: valid flags to set or clear are:\n", argv[0]);
|
||||
for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
|
||||
printf (" %s\n", table[t]);
|
||||
return 0;
|
||||
default:
|
||||
printf ("error: unknown option\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strcmp (argv[arg], "set") == 0)
|
||||
set = true;
|
||||
if (strcmp (argv[arg], "clear") == 0)
|
||||
set = false;
|
||||
else if (strcmp (argv[arg], "all") == 0)
|
||||
{
|
||||
if (set)
|
||||
set_value = RTEMS_RTL_TRACE_ALL;
|
||||
else
|
||||
clear_value = RTEMS_RTL_TRACE_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (t = 0; t < (sizeof (table) / sizeof (const char*)); t++)
|
||||
{
|
||||
if (strcmp (argv[arg], table[t]) == 0)
|
||||
{
|
||||
if (set)
|
||||
set_value = 1 << t;
|
||||
else
|
||||
clear_value = 1 << t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rtems_rtl_trace_flags |= set_value;
|
||||
rtems_rtl_trace_flags &= ~clear_value;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2012 Chris Johns <chrisj@rtems.org>
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup rtems_rtl
|
||||
*
|
||||
* @brief RTEMS Run-Time Linker ELF Trace Support.
|
||||
*/
|
||||
|
||||
#if !defined (_RTEMS_RTL_TRACE_H_)
|
||||
#define _RTEMS_RTL_TRACE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* Set to 1 to build trace support in to the RTL code.
|
||||
*/
|
||||
#define RTEMS_RTL_TRACE 1
|
||||
|
||||
/**
|
||||
* The type of the mask.
|
||||
*/
|
||||
typedef uint32_t rtems_rtl_trace_mask;
|
||||
|
||||
/**
|
||||
* List of tracing bits for the various parts of the link editor.
|
||||
*/
|
||||
#define RTEMS_RTL_TRACE_ALL (0xffffffffUL)
|
||||
#define RTEMS_RTL_TRACE_LOAD (1UL << 0)
|
||||
#define RTEMS_RTL_TRACE_UNLOAD (1UL << 1)
|
||||
#define RTEMS_RTL_TRACE_SECTION (1UL << 2)
|
||||
#define RTEMS_RTL_TRACE_SYMBOL (1UL << 3)
|
||||
#define RTEMS_RTL_TRACE_RELOC (1UL << 4)
|
||||
#define RTEMS_RTL_TRACE_GLOBAL_SYM (1UL << 5)
|
||||
#define RTEMS_RTL_TRACE_LOAD_SECT (1UL << 6)
|
||||
#define RTEMS_RTL_TRACE_ALLOCATOR (1UL << 7)
|
||||
#define RTEMS_RTL_TRACE_UNRESOLVED (1UL << 8)
|
||||
#define RTEMS_RTL_TRACE_DETAIL (1UL << 9)
|
||||
|
||||
/**
|
||||
* Call to check if this part is bring traced. If RTEMS_RTL_TRACE is defined to
|
||||
* 0 the code is dead code elminiated when built with -Os, -O2, or higher.
|
||||
*
|
||||
* @param mask The part of the API to trace.
|
||||
* @retval true Tracing is active for the mask.
|
||||
* @retval false Do not trace.
|
||||
*/
|
||||
#if RTEMS_RTL_TRACE
|
||||
bool rtems_rtl_trace (rtems_rtl_trace_mask mask);
|
||||
#else
|
||||
#define rtems_rtl_trace(_m) (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set the mask.
|
||||
*
|
||||
* @param mask The mask bits to set.
|
||||
* @return The previous mask.
|
||||
*/
|
||||
#if RTEMS_RTL_TRACE
|
||||
rtems_rtl_trace_mask rtems_rtl_trace_set_mask (rtems_rtl_trace_mask mask);
|
||||
#else
|
||||
#define rtems_rtl_trace_set_mask(_m)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Clear the mask.
|
||||
*
|
||||
* @param mask The mask bits to clear.
|
||||
* @return The previous mask.
|
||||
*/
|
||||
#if RTEMS_RTL_TRACE
|
||||
rtems_rtl_trace_mask rtems_rtl_trace_clear_mask (rtems_rtl_trace_mask mask);
|
||||
#else
|
||||
#define rtems_rtl_trace_clear_mask(_m)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Add shell trace shell command.
|
||||
*/
|
||||
#if RTEMS_RTL_TRACE
|
||||
int rtems_rtl_trace_shell_command (int argc, char *argv[]);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
+86
-1
@@ -46,7 +46,6 @@ $(PROJECT_INCLUDE)/utf8proc/utf8proc.h: libmisc/utf8proc/utf8proc.h $(PROJECT_IN
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/utf8proc/utf8proc.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/utf8proc/utf8proc.h
|
||||
|
||||
if NEWLIB
|
||||
$(PROJECT_INCLUDE)/sys/$(dirstamp):
|
||||
@$(MKDIR_P) $(PROJECT_INCLUDE)/sys
|
||||
@: > $(PROJECT_INCLUDE)/sys/$(dirstamp)
|
||||
@@ -130,6 +129,92 @@ $(PROJECT_INCLUDE)/rtems/bsdnet/_types.h: libnetworking/rtems/bsdnet/_types.h $(
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bsdnet/_types.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/bsdnet/_types.h
|
||||
endif
|
||||
if LIBDL
|
||||
$(PROJECT_INCLUDE)/dlfcn.h: libdl/dlfcn.h $(PROJECT_INCLUDE)/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/dlfcn.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/dlfcn.h
|
||||
|
||||
$(PROJECT_INCLUDE)/link.h: libdl/include/link.h $(PROJECT_INCLUDE)/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/link.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/link.h
|
||||
|
||||
$(PROJECT_INCLUDE)/link_elf.h: libdl/include/link_elf.h $(PROJECT_INCLUDE)/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/link_elf.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/link_elf.h
|
||||
|
||||
$(PROJECT_INCLUDE)/sys/cdefs_elf.h: libdl/include/sys/cdefs_elf.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/cdefs_elf.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/cdefs_elf.h
|
||||
|
||||
$(PROJECT_INCLUDE)/sys/exec_elf.h: libdl/include/sys/exec_elf.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/exec_elf.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/exec_elf.h
|
||||
|
||||
$(PROJECT_INCLUDE)/machine/$(dirstamp):
|
||||
@$(MKDIR_P) $(PROJECT_INCLUDE)/machine
|
||||
@: > $(PROJECT_INCLUDE)/machine/$(dirstamp)
|
||||
PREINSTALL_DIRS += $(PROJECT_INCLUDE)/machine/$(dirstamp)
|
||||
|
||||
$(PROJECT_INCLUDE)/machine/elf_machdep.h: libdl/include/arch/@RTEMS_CPU@/machine/elf_machdep.h $(PROJECT_INCLUDE)/machine/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/machine/elf_machdep.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/machine/elf_machdep.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp):
|
||||
@$(MKDIR_P) $(PROJECT_INCLUDE)/rtems/rtl
|
||||
@: > $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
PREINSTALL_DIRS += $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/dlfcn-shell.h: libdl/dlfcn-shell.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/dlfcn-shell.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/dlfcn-shell.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl.h: libdl/rtl.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-allocator.h: libdl/rtl-allocator.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-allocator.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-allocator.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-fwd.h: libdl/rtl-obj-fwd.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-fwd.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-fwd.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-fwd.h: libdl/rtl-fwd.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-fwd.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-fwd.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-obj.h: libdl/rtl-obj.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-cache.h: libdl/rtl-obj-cache.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-cache.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-cache.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-comp.h: libdl/rtl-obj-comp.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-comp.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-obj-comp.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-unresolved.h: libdl/rtl-unresolved.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-unresolved.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-unresolved.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-indirect-ptr.h: libdl/rtl-indirect-ptr.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-indirect-ptr.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-indirect-ptr.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rtl-sym.h: libdl/rtl-sym.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rtl-sym.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rtl-sym.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rap.h: libdl/rap.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rap.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rap.h
|
||||
|
||||
$(PROJECT_INCLUDE)/rtems/rtl/rap-shell.h: libdl/rap-shell.h $(PROJECT_INCLUDE)/rtems/rtl/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtl/rap-shell.h
|
||||
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtl/rap-shell.h
|
||||
endif
|
||||
$(PROJECT_INCLUDE)/rtems/bspIo.h: include/rtems/bspIo.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
|
||||
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/bspIo.h
|
||||
|
||||
@@ -77,6 +77,10 @@ if NEWLIB
|
||||
TMP_LIBS += ../libmd/libmd.a
|
||||
endif
|
||||
|
||||
if LIBDL
|
||||
TMP_LIBS += ../libdl/libdl.a
|
||||
endif
|
||||
|
||||
librtemscpu.a: $(TMP_LIBS)
|
||||
rm -f $@
|
||||
$(MKDIR_P) $(ARCH)
|
||||
|
||||
@@ -14,7 +14,7 @@ _SUBDIRS += block14
|
||||
_SUBDIRS += block13
|
||||
_SUBDIRS += rbheap01
|
||||
_SUBDIRS += flashdisk01
|
||||
_SUBDIRS += capture01
|
||||
_SUBDIRS += capture01
|
||||
|
||||
_SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \
|
||||
deviceio01 devnullfatal01 dumpbuf01 gxx01 top\
|
||||
@@ -36,5 +36,9 @@ _SUBDIRS += ftp01
|
||||
_SUBDIRS += syscall01
|
||||
endif
|
||||
|
||||
if DLTESTS
|
||||
_SUBDIRS += dl01
|
||||
endif
|
||||
|
||||
include $(top_srcdir)/../automake/test-subdirs.am
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
@@ -41,6 +41,29 @@ AM_CONDITIONAL([HAS_COMPLEX],[test "$ac_cv_header_complex_h" = yes])
|
||||
AM_CONDITIONAL(NETTESTS,test "$rtems_cv_RTEMS_NETWORKING" = "yes")
|
||||
AM_CONDITIONAL(HAS_POSIX,test x"${rtems_cv_RTEMS_POSIX_API}" = x"yes")
|
||||
|
||||
# Must match the list in cpukit.
|
||||
AC_MSG_CHECKING([whether CPU supports libdl])
|
||||
case $RTEMS_CPU in
|
||||
arm | bfin | h8300 | i386 | lm32 | m32r | m68k | mips | \
|
||||
moxie | nios2 | powerpc | sparc | v850)
|
||||
HAVE_LIBDL=yes ;;
|
||||
*)
|
||||
HAVE_LIBDL=no ;;
|
||||
esac
|
||||
AM_CONDITIONAL(DLTESTS,[test x"$HAVE_LIBDL" = x"yes"])
|
||||
AC_MSG_RESULT([$HAVE_LIBDL])
|
||||
|
||||
AS_IF([test x"$HAVE_LIBDL" = x"yes"],[
|
||||
AC_CHECK_PROG(RTEMS_LD_CHECK,rtems-ld,yes)
|
||||
if test x"$RTEMS_LD_CHECK" != x"yes" ; then
|
||||
AC_MSG_ERROR([Please install rtems-tools.])
|
||||
fi
|
||||
AC_CHECK_PROG(RTEMS_SYMS_CHECK,rtems-syms,yes)
|
||||
if test x"$RTEMS_SYMS_CHECK" != x"yes" ; then
|
||||
AC_MSG_ERROR([Please install rtems-tools.])
|
||||
fi
|
||||
])
|
||||
|
||||
# Explicitly list all Makefiles here
|
||||
AC_CONFIG_FILES([Makefile
|
||||
newlib01/Makefile
|
||||
@@ -78,6 +101,7 @@ devfs03/Makefile
|
||||
devfs04/Makefile
|
||||
deviceio01/Makefile
|
||||
devnullfatal01/Makefile
|
||||
dl01/Makefile
|
||||
dumpbuf01/Makefile
|
||||
ftp01/Makefile
|
||||
gxx01/Makefile
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
rtems_tests_PROGRAMS = dl01
|
||||
dl01_SOURCES = init.c dl-load.c dl-tar.c dl-tar.h
|
||||
|
||||
BUILT_SOURCES = dl-tar.c dl-tar.h
|
||||
|
||||
dist_rtems_tests_DATA = dl01.scn dl01.doc
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(dl01_OBJECTS)
|
||||
LINK_LIBS = $(dl01_LDLIBS)
|
||||
|
||||
dl-o1.o: dl-o1.c
|
||||
|
||||
dl.tar: dl-o1.o
|
||||
@rm -f $@
|
||||
$(PAX) -w -f $@ $<
|
||||
|
||||
dl-tar.c: dl.tar
|
||||
$(BIN2C) -C $< $@
|
||||
CLEANFILES += dl-tar.c
|
||||
|
||||
dl-tar.h: dl.tar
|
||||
$(BIN2C) -H $< $@
|
||||
CLEANFILES += dl-tar.h
|
||||
|
||||
dl01.pre$(EXEEXT): $(dl01_OBJECTS) $(dl01_DEPENDENCIES)
|
||||
@rm -f dl01.pre$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
dl-sym.o: dl01.pre$(EXEEXT)
|
||||
rtems-syms -e -c "$(CFLAGS)" -o $@ $<
|
||||
|
||||
dl01$(EXEEXT): $(dl01_OBJECTS) $(dl01_DEPENDENCIES) dl-sym.o
|
||||
@rm -f dl01$(EXEEXT)
|
||||
$(LINK.c) $(CPU_CFLAGS) $(AM_CFLAGS) $(AM_LDFLAGS) \
|
||||
-o $(basename $@)$(EXEEXT) $(LINK_OBJS) dl-sym.o $(LINK_LIBS)
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "dl-load.h"
|
||||
|
||||
typedef int (*call_t)(int argc, char* argv[]);
|
||||
|
||||
|
||||
static const char* call_1[] = { "Line 1", "Line 2" };
|
||||
static const char* call_2[] = { "Call 2, line 1",
|
||||
"Call 2, line 2",
|
||||
"Call 2, line 3" };
|
||||
|
||||
int dl_load_test(void)
|
||||
{
|
||||
void* handle;
|
||||
call_t call;
|
||||
int call_ret;
|
||||
int unresolved;
|
||||
char* message = "loaded";
|
||||
|
||||
printf("load: /dl-o1.o\n");
|
||||
|
||||
handle = dlopen ("/dl-o1.o", RTLD_NOW | RTLD_GLOBAL);
|
||||
if (!handle)
|
||||
{
|
||||
printf("dlopen failed: %s\n", dlerror());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0)
|
||||
message = "dlinfo error checking unresolved status";
|
||||
else if (unresolved)
|
||||
message = "has unresolved externals";
|
||||
|
||||
printf ("handle: %p %s\n", handle, message);
|
||||
|
||||
call = dlsym (handle, "rtems_main");
|
||||
if (call == NULL)
|
||||
{
|
||||
printf("dlsym failed: symbol not found\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
call_ret = call (2, call_1);
|
||||
if (call_ret != 2)
|
||||
{
|
||||
printf("dlsym call failed: ret value bad\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
call_ret = call (3, call_2);
|
||||
if (call_ret != 3)
|
||||
{
|
||||
printf("dlsym call failed: ret value bad\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (dlclose (handle) < 0)
|
||||
{
|
||||
printf("dlclose failed: %s\n", dlerror());
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf ("handle: %p closed\n", handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if !defined(_DL_LOAD_H_)
|
||||
#define _DL_LOAD_H_
|
||||
|
||||
int dl_load_test(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* Hello World as a loadable module.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* Yes a decl in the source. This is a modules main and I could not find which
|
||||
* header main is defined in.
|
||||
*/
|
||||
int rtems_main (int argc, char* argv[]);
|
||||
|
||||
int rtems_main (int argc, char* argv[])
|
||||
{
|
||||
int arg;
|
||||
printf("Loaded module: argc:%d [%s]\n", argc, __FILE__);
|
||||
for (arg = 0; arg < argc; ++arg)
|
||||
printf(" %d: %s\n", arg, argv[arg]);
|
||||
return argc;
|
||||
}
|
||||
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Chris Johns <chrisj@rtems.org>. All rights reserved.
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "tmacros.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <rtems/rtl/rtl.h>
|
||||
#include <rtems/untar.h>
|
||||
|
||||
#include "dl-load.h"
|
||||
|
||||
const char rtems_test_name[] = "libdl (RTL) Loader 1";
|
||||
|
||||
/* forward declarations to avoid warnings */
|
||||
static rtems_task Init(rtems_task_argument argument);
|
||||
|
||||
#include "dl-tar.h"
|
||||
|
||||
#define TARFILE_START dl_tar
|
||||
#define TARFILE_SIZE dl_tar_size
|
||||
|
||||
static int test(void)
|
||||
{
|
||||
int ret;
|
||||
ret = dl_load_test();
|
||||
if (ret)
|
||||
rtems_test_exit(ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Init(rtems_task_argument arg)
|
||||
{
|
||||
int te;
|
||||
|
||||
TEST_BEGIN();
|
||||
|
||||
te = Untar_FromMemory((void *)TARFILE_START, (size_t)TARFILE_SIZE);
|
||||
if (te != 0)
|
||||
{
|
||||
printf("untar failed: %d\n", te);
|
||||
rtems_test_exit(1);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
TEST_END();
|
||||
|
||||
rtems_test_exit(0);
|
||||
}
|
||||
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
|
||||
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
|
||||
|
||||
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
|
||||
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
|
||||
|
||||
#define CONFIGURE_MAXIMUM_TASKS 1
|
||||
|
||||
#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (8U * 1024U)
|
||||
|
||||
#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
|
||||
|
||||
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
|
||||
|
||||
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
|
||||
#include <rtems/confdefs.h>
|
||||
|
||||
Reference in new issue
Block a user