Dynamic linking via WAF: unresolved externals issue
Saeed Ehteshamifar
salpha.2004 at gmail.com
Tue Aug 30 09:51:15 UTC 2016
Hello,
I'm trying to run my app that uses dynamic linking via WAF (I've tried the
same app via OMK and it's working). Even though the dynamic module
(hello.o) loads successfully (have double checked with RTEMS shell too), it
has unresolved symbols issue after a call to:
dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved)
Here is my code (*init.c*):
#include <rtems.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <rtems/printer.h>
#include <dlfcn.h>
#include <rtems/rtl/rtl.h>
#include <rtems/untar.h>
#include <rtems/imfs.h>
#include <rtems/shellconfig.h>
#include <rtems/monitor.h>
#include <rtems/shell.h>
extern int _binary_dl_tar_start;
extern int _binary_dl_tar_size;
typedef int (*call_t)();
static void expand_rootfs_tarfile(void)
{
rtems_status_code sc;
rtems_printer printer;
rtems_print_printer_printf(&printer);
sc = Untar_FromMemory_Print((void *)(&_binary_dl_tar_start),
(size_t)&_binary_dl_tar_size,
&printer);
if (sc != RTEMS_SUCCESSFUL)
fprintf(stderr, "error: untar failed: %s\n",
rtems_status_text(sc));
}
rtems_task Init(
rtems_task_argument ignored
)
{
call_t hellooo;
int unresolved;
expand_rootfs_tarfile();
void* handle = dlopen ("hello.o", RTLD_NOW | RTLD_GLOBAL);
if (!handle)
{
printf("dlopen failed: %s\n", dlerror());
exit(1);
}
printf ("handle: %p \n", handle);
if (dlinfo (handle, RTLD_DI_UNRESOLVED, &unresolved) < 0)
printf ("dlinfo failed\n");
else if (unresolved)
printf ("unresolved externals\n");
hellooo = dlsym (handle, "hello");
if (hellooo == NULL)
{
printf("dlsym failed: symbol not found\n");
exit(1);
}
hellooo();
printf ("___\n");
if (dlclose (handle) < 0)
{
printf("dlclose failed: %s\n", dlerror());
exit(1);
}
printf ("handle: %p closed\n", handle);
exit(0);
}
/* configuration information */
#include <bsp.h>
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32
#define CONFIGURE_MAXIMUM_TASKS 4
#define CONFIGURE_MINIMUM_TASK_STACK_SIZE (8U * 1024U)
#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
#define CONFIGURE_MAXIMUM_POSIX_KEYS 16
#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 16
#define CONFIGURE_APPLICATION_NEEDS_NULL_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_ZERO_DRIVER
#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
#define CONFIGURE_FILESYSTEM_DOSFS
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK // for rtems shell.
#define CONFIGURE_INIT_TASK_PRIORITY 100
#define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
RTEMS_NO_TIMESLICE | \
RTEMS_NO_ASR | \
RTEMS_INTERRUPT_LEVEL(0))
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
*hello.c*:
#include <stdio.h>
#include <stdlib.h>
int hello ()
{
printf("\n\n*** HELLO WORLD ***\n");
printf("Hello World\n");
printf("*** END OF HELLO WORLD ***\n");
return 0;
}
*wscript* (I manually copied hello.o from o-optimiezed to where wscript
file lies):
import rtems_waf.rtems as rtems
def init(ctx):
rtems.init(ctx)
def options(opt):
rtems.options(opt)
def configure(conf):
rtems.configure(conf)
def build(bld):
rtems.build(bld)
rtems.root_filesystem(bld, 'dl',
['hello.o'],
'dl.tar', 'dl-tar.o')
*Makefile*:
#
# RTEMS_MAKEFILE_PATH is typically set in an environment variable
#
PGM=${ARCH}/dl.exe
# optional managers required
MANAGERS=all
# C source names
CSRCS = init.c hello.c
COBJS = $(CSRCS:%.c=${ARCH}/%.o)
COBJS += build/i386-rtems4.12-pc386/dl-tar.o
include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
include $(RTEMS_CUSTOM)
include $(PROJECT_ROOT)/make/leaf.cfg
OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS)
all: ${ARCH} $(PGM)
$(PGM): $(OBJS)
$(make-exe)
*qemu's output:*qemu-system-i386 -kernel o-optimize/dl.exe -append
"--console=/dev/com1" -serial stdio
i386: isr=0 irr=1
untar: memory at 0x14b244 (10240)
untar: file: hello.o (8000)
handle: 0x16ed04
unresolved externals
FATAL ERROR - Executive shutdown! Any key to reboot...qemu: terminating on
signal 2
s
What is this error about and what am I doing wrong?
Best Regards,
Saeed
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20160830/535d2a00/attachment-0001.html>
More information about the users
mailing list