Link a simple program and load into RTEMS with dlopen
Chris Johns
chrisj at rtems.org
Tue Sep 18 05:55:22 UTC 2018
On 18/09/2018 01:29, Boldizsar.Palotas at esa.int wrote:
> Hi,
Hi, and welcome.
> 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());
This looks fine.
> I'm using the GCC built by RTEMS Source Builder to compile the object located at
> prog_namein the in-memory filesystem.
Great.
> What command line should I use to properly compile a single C file to be loaded
> this way?
You need to use the same command line used to compile any source to an object
file. The dynamic loader in RTEMS supports a relocatable ELF file the compiler
creates with out the need for special options.
> 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
Do not use the `-shared` option, also the `-fPIC` option is not needed for RTEMS
loadable code.
The RTEMS loader is not like the Linux or FreeBSD libdl loaders. The RTEMS
loader will perform a standard link-edit process to locate the code in your
address space.
> $ # Run in emulator, result:
> $ # dlopen: global symbol not found: _GLOBAL_OFFSET_TABLE_
This will be related to either the -shared or -fPIC options.
> I have also tried some other combinations and also using the rtems-ld program.
The rtems-ld command is used to managing more complex sets of object files. You
can load the ELF files directly.
> Any ideas?
I hope this helps.
Chris
More information about the users
mailing list