Dynamic linking in RTEMS

Pavel Pisa pisa at cmp.felk.cvut.cz
Wed Jul 27 00:00:30 UTC 2016


Hello Saeed,

On Wednesday 27 of July 2016 01:01:29 Saeed Ehteshamifar wrote:
> Hello,
>
> Thanks Pavel for your answer. I tried to write an app myself that uses
> dynamic loading and I ended up with the following questions:
>
> 1. How to generate *tar* array? Since on top of dl-tar.c it's been noted
> that it's automatically generated. If I'm not wrong, by making a tar image,
> RTEMS puts all binary objects within a single tar file and calls them
> dynamically at run-time, right?

I am not sure at this moment, how it is done by mainline samples makefiles
but simplified command sequence from my examples follows.

> 2. What's the difference between dl01.exe and dl01.pre? Both are executable
> but running dl01.pre leads to "unresolved externals" and the execution
> hangs.

You need to link list of symbols to the base executable image
to inform runtime linker which symbols are available.

# CFLAGS specific for given architecture and its variant
(ARM arch and RaspberryPi2 in the esample/)
CFLAGS1="--pipe -B/opt/rtems4.12/arm-rtems4.12/raspberrypi2/lib/ -specs 
bsp_specs -qrtems -I /opt/rtems4.12/arm-rtems4.12/raspberrypi2/lib/include -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -mtune=cortex-a7 -Wall -O2 -g -ffunction-sections -fdata-sections"


# Prepare location/directory where binary files should be stored.
mkdir -p rootfs/bin

# Compile "library"/ELF code, which should be available at runtime in /bin etc directories
arm-rtems4.12-gcc ${CFLAGS1} -o rootfs/bin/appdl_print.o -c appdl_print.c

# Pack "rootfs" directory content to the TAR file
( cd rootfs && tar -cf ../rootfs_tarfile . )

# Use binutils to to convert TAR image to the data section of regular linkable object
arm-rtems4.12-ld -r --accept-unknown-input-arch -b binary -o rootfs_tarfile.o.tmp rootfs_tarfile
arm-rtems4.12-objcopy --rename-section .data=.rodata,alloc,load,readonly,data,contents rootfs_tarfile.o.tmp rootfs_tarfile.o

# Compile sources to object files which form main application/rtems image
arm-rtems4.12-gcc ${CFLAGS1} -o init.o -c init.c
arm-rtems4.12-gcc ${CFLAGS1} -o task_1.o -c task_1.c

# Do the prelink to find symbols which could be exported by application
rm -f appdl.prelink
arm-rtems4.12-gcc ${CFLAGS1} -Wl,--gc-sections  init.o rootfs_tarfile.o task_1.o -lbar -lm  -o appdl.prelink

# Extract symbols list from prelinked image.- It should be combined with list of additional symbols
# which should be available during runtime linking
rtems-syms -e -c "arm-rtems4.12-gcc ${CFLAGS1}" -S appdl-symbol-table.c -o appdl-symbol-table.o appdl.prelink

# Prepare final image of RTEMS application which includes IMS initial data in TAR object
# file, symbol table and objects forming application
arm-rtems4.12-gcc ${CFLAGS1} -Wl,--gc-sections  init.o rootfs_tarfile.o task_1.o appdl-symbol-table.o -L . -lbar -lm -o appdl

This list is highly simplified, but should give some
overview, how can be dynamic linking used with RTEMS.

There is compact loadable modules format RAP which
can be used instead of simple ELF etc.

Best wishes,

             Pavel

> Best Regards,
> Saeed
>
> On Tue, Jul 19, 2016 at 5:12 PM, Pavel Pisa <pisa at cmp.felk.cvut.cz> wrote:
> > Hello Saeed,
> >
> > libdl had been merged to RTEMS mainline.
> >
> > https://git.rtems.org/rtems/tree/cpukit/libdl
> >
> > There is even example how to use it in mainline
> > and shell functions for test from commandline
> >
> > 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[]);
> >
> > The test cases are included in mainline as well
> >
> > https://git.rtems.org/rtems/tree/testsuites/libtests/dl01
> >
> > https://git.rtems.org/rtems/tree/testsuites/libtests/dl02
> >
> > There is some my example for dlopen shell command as well.
> >
> >
> > https://rtime.felk.cvut.cz/gitweb/rtems-devel.git/blob/HEAD:/rtems-omk-te
> >mplate/appdl/init.c
> >
> > I have posted recently cache operations patches series
> > which is pending comments. This includes some corrections
> > required to synchronize caches after code load and relocate.
> > These patches are required to use libdl on CPUs
> > where instruction cache is not snooped/synchronized
> > automatically (most RISCs, ARM, PowerPC etc.).
> >
> > Best wishes
> >                 Pavel
> > --
> >
> >                 Pavel Pisa
> >     e-mail:     pisa at cmp.felk.cvut.cz
> >     www:        http://cmp.felk.cvut.cz/~pisa
> >     university: http://dce.fel.cvut.cz/
> >     company:    http://www.pikron.com/
> >
> > On Tuesday 19 of July 2016 11:57:47 Saeed Ehteshamifar wrote:
> > > Hi,
> > >
> > > For the slingshot (RTEMS fault-injection tool) I need to dynamically
> > > link test cases into the test suite(s) and execute them on-the-fly.
> > > With a google search on "rtems libdl", I found two pointers for libdl:
> > >
> > > 1. https://git.rtems.org/chrisj/rtl.git/
> > > https://git.rtems.org/chrisj/rtl-host.git/
> > >
> > > 2. https://git.rtems.org/rtems/tree/cpukit/libdl
> > >
> > > Now my question is: Has libdl already been merged in the tree, as the
> > > second pointer suggests? And if yes, are there examples available maybe
> >
> > in
> >
> > > the testsuite folder on how to use that?
> > >
> > > Best Regards,
> > > Saeed

-- 
Yours sincerely

                Pavel Pisa
    e-mail:     pisa at cmp.felk.cvut.cz
    www:        http://cmp.felk.cvut.cz/~pisa
    university: http://dce.fel.cvut.cz/
    company:    http://www.pikron.com/


More information about the devel mailing list