I can explain for sure (I hope you want to read a lot of text, it's not easy to explain in a few words) :
I use a kind of "filesystem" in RAM. Most of the data is read only, but files are also used for updating, writing to EEPROM, FLASH, ...
The "FileSystem" class contains a list "File" instances. The "FileSystem class is completly static. So for example the html server can open a file like this : FileSystem::Open(char* filename).
The specific functionality behind a file is done in a class derived from "File". This can be a simple "RamFile" that contain some data on a specific RAM address.
For example :
static const char data = "This is a test file containing just a simple text";
RamFile TestDataFile("testdata.txt", data, strlen(data));
The constructor of RamFile calls the constructor of File, wich links its 'this' pointer in the FileSystem.
Now the compile and link process :
My system is set up to use different pieces of code in seperate libraries. For example "ethlib.a" (tcp/ip stack) , "oslib.a" (operating system) and "boardlib.a" (board component interfaces like SPI, flash, ...). The same libraries are used in different projects.
Besides the libraries, I have a set of source files (and corresponding objects) generated for a specific project. So the linker uses these objects directly, togheter with the archived objects in the libraries.
Now the problem starts : I want to have some files with information about the board components in a webpage --> so this belongs to "boardlib.a".
I construct a file called "html_board.cpp" and puts something in like the above example. I add to the makefile for the library and generate the library.
After recompiling the whole project, I suspect the newly added file in the filesystem to be available, but no, even the data itself is not in executable (verified in an object dump).
Next step to put the two lines as in the example in one of the projects source files, and not in the library --> system works like expected.
Next idea : maybe the linker ignores "html_board.o" file (part of the library)because none of it is referenced elsewhere. To test this theary, I changed above "html_board.cpp" example to :
int dummy = 0;
static const char data = "This is a test file containing just a simple text";
RamFile TestDataFile("testdata.txt", data, strlen(data));
and in one of the projects source files :
extern int dummy;
void foo()
{
dummy++;
...
...
}
I make sure foo() is called and dummy can not be optimized away. Surprise : the "testdata.txt" is in the FileSystem.
So I'm pretty sure now, the linker ignores the "html_board.o" from the boardlib.a completely. As soon that there is something in the file used, the whole file is used.
I hope there is a simple solution to force the compiler to instantiate my file file objects.
I tried with "static const" and the compiler option '-fkeep-static-consts", but no good result.
Hope its clear now, sorry for the long story.
Stefaan