I've seen this issue discussed several times before, but not with this exact solution, so I'll barge ahead with my own reinterpretation of the wheel...
Fairly often, I generate small, feature-specific modules that qualify as being "generally reuseable" enough to add to the static link library I'm accumulating for use by future products. But because they're self-contained, there's no unresolved references to them from a specific product's application firmware that would get them extracted from said library. The modules usually have some global variable or subroutine name that might be used with a "-u" linker commandline switch, but not always. And if the module was compiled as C++ source, its subroutine names will probably be mangled anyway.
So what ol' Jack Burton does in a situation like that is to #include this header file in such self-contained modules:
// moduleTitle.h - Provides a macro to insert a nonmangled public symbol // // Often, a module is so self-contained that a prospective application // has nothing to "grab onto" to force its extraction from the static // library. The following macro can be used to add a non-mangled symbol // to a module's compiled output file. Then, the common makefile // template's "DEMANDEDSYMBOLS" mechanism can be used to add a "force // symbol to be undefined" for it: // // #ifndef ModuleTitle #define ModuleTitle(name) asm(".global " #name "\n.set " #name ", 0xBEADB007"); #endif
So a self-contained module might start out like so:
// someModule.cpp - A pithy description of this module // #include "moduleTitle.h" ModuleTitle(SomeModule)
The common makefile template provides the following service:
# ============================= # = Forcing Libray extraction = # ============================= # # Makefiles that include this one can pull even self-contained modules # from the library by creating undefined references to strategically- # selected symbols. To make this process look less imposing, the stock # Makefile is allowed to set up a simple list of those symbols without # needing to know the linker commandline switch format. Here's where # we expand such a list into the appropriate linker commandline args: # LDFLAGS += $(patsubst %,-u %,$(DEMANDEDMODULES))
, so a project-specific Makefile can do something like this:
# List module title to be "demanded" from the probe link archive here. # Some of the available library modules are self-contained; nothing # "calls" them from the application code, so the linker doesn't know # to include them. To get such a module included, you can add specific # symbols to the linker's "shopping list". Such self-contained modules # should use the "ModuleTitle" macro to provide clearly descriptive names # that can be added to the list of "symbols to demand" # DEMANDEDMODULES += DebugScratchpad DEMANDEDMODULES += FirmwareUpdate DEMANDEDMODULES += StackCheck