cpukit: Add libdl with the Runtime Loader (RTL) code.

This is a merge of the RTL project.
This commit is contained in:
Chris Johns
2014-10-26 18:09:41 -07:00
parent 513668f6f1
commit ae5fe7e6bc
91 changed files with 14746 additions and 5 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

View File

View File

@@ -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>