clinkerdlopendlsymrtems

How do I link an application for dynamic loading by RTEMS?


I'm using RTEMS 4.11 and the builtin POSIX API functions to dynamically load a program image into memory. The program image is loaded in RTEMS using the following code:

void* handle = dlopen(prog_name, RTLD_NOW | RTLD_GLOBAL);
if (!handle)
    printf("dlopen: %s\n", dlerror());

I'm using the GCC built by RTEMS Source Builder to compile the object located at prog_name in the in-memory filesystem.

What command line should I use to properly compile a single C file to be loaded this way?

For reference, I've tried the following command line options, but got an error:

$ /opt/rtems-4.11/bin/sparc-rtems4.11-gcc test.c -c -o test.elf -shared -fPIC -nostdlib
$ # dlopen: global symbol not found: _GLOBAL_OFFSET_TABLE_

$ /opt/rtems-4.11/bin/sparc-rtems4.11-gcc test.c -o test.elf -fPIC -shared -nostdlib
$ # dlopen: ELF file contains program headers

I have also tried some other combinations and also using the rtems-ld program. Any ideas?


Solution

  • Turns out the only important option is -c (compile and assemble but do not link).

    $ /opt/rtems-4.11/bin/sparc-rtems4.11-gcc test.c -c -o test.elf
    $ # this now works
    

    Credit