sotest Shared Library Module Test
This example builds a small shared library module test case. The test shared
library is built using the relocatable ELF format and installed in a ROMFS file
system. At run time, the shared library is installed and exercised. Requires
CONFIG_LIBC_DLFCN. Other configuration options:
CONFIG_EXAMPLES_SOTEST_DEVMINOR– The minor device number of the ROMFS block driver. For example, theNin/dev/ramN. Used for registering the RAM block driver that will hold the ROMFS file system containing the ELF executables to be tested. Default:0.CONFIG_EXAMPLES_SOTEST_DEVPATH– The path to the ROMFS block driver device. This must matchEXAMPLES_ELF_DEVMINOR. Used for registering the RAM block driver that will hold the ROMFS file system containing the ELF executables to be tested. Default:/dev/ram0.
Notes:
CFLAGSshould be provided inCMODULEFLAGS. RAM and FLASH memory regions may require long allcs. For ARM, this might be:CMODULEFLAGS = $(CFLAGS) -mlong-calls
Similarly for C++ flags which must be provided in
CXXMODULEFLAGS.Your top-level
nuttx/Make.defsfile must also include an appropriate definition,LDMODULEFLAGS, to generate a relocatable ELF object. With GNU LD, this should include-rand-e <entry point>.:LDMODULEFLAGS = -r -e module_initialize
If you use GCC to link, you make also need to include
-nostdlib.This example also requires
genromfs.genromfscan be build as part of the nuttx toolchain. Or can built from thegenromfssources that can be found in the NuttX tools repository (genromfs-0.5.2.tar.gz). In any event, thePATHvariable must include the path to thegenromfsexecutable.ELF size: The ELF files in this example are, be default, quite large because they include a lot of build garbage. You can greatly reduce the size of the ELF binaries are using the
objcopy --strip-unneededcommand to remove un-necessary information from the ELF files.Simulator. You cannot use this example with the NuttX simulator on Cygwin. That is because the Cygwin GCC does not generate ELF file but rather some Windows-native binary format.
If you really want to do this, you can create a NuttX x86 buildroot toolchain and use that be build the ELF executables for the ROMFS file system.
Linker scripts. You might also want to use a linker scripts to combine sections better. An example linker script is at
nuttx/libc/modlib/gnu-elf.ld. That example might have to be tuned for your particular linker output to position additional sections correctly. The GNU LDLDMODULEFLAGSthen might be:LDMODULEFLAGS = -r -e module_initialize -T$(TOPDIR)/libc/modlib/gnu-elf.ld