I would like to create a C-code module that will contain several functions. It should be R/W and R/O independent and at the beginning it should contain a table which will hold offsets of the contained functions relative to the table start. This way I can load the module into an arbitrary RAM location and call functions indirectly through that table. I tried several approaches, but never managed to get it linked without errors...
regards
Dejan
It is often not possible when writing in C, unless you link that module as a 100% self-contained unit.
The compiler code will often make use of helper functions from the C runtime library. If these functions aren't contained in that unit then the unit needs references in the reverse direction. And if the C RTL helper functions aren't also position-independent then your unit will not be position-independent.
Next thing is that if your functions requires CRTL functions, it may also require initialization of the CRTL. So there may be needs for code that would normally be called from the startup file - except that the code called from the startup file will normally also expect the existence of a main().
A Windows linker has specific support for creating dynamic link libraries. Most embedded compiler tool chains doesn't have similar support, which makes it hard to convince the linker to produce something that can be loaded and used dynamically without using assembler.
OK, I forgot to mention that functions do not make any external calls and are self-contained. So, it's only the issue of propper configuring linker scatter file, I guess...
Note that "self-contained" C code may still require CRTL helper functions.
I am quite familiar how C-copmilers work and ss I said, my module does not call any external functions nor CRT routines (linker would complain).
Anyway, I've solved the problem by adding small ASM interface module and now it passes linking and works as supposed. I just thoughgt that it can be possible to code it entirely in C...