I have defined a myassert(char *module, int line) function that uses the arguments only in Debug build. myassert() is defined in myassert.c and declared in myassert.h.
In myassert.h there's also a macro that tests an expression:
#define MYASSERT(test) (test) ? (void) 0 : myassert(thisModule, (int)__LINE__))
Now in module.c:
#include "myassert.h" static char thisModule[] = "module"; MYASSERT(always_true == true);
Because myassert() doesn't use its arguments in Release build (it only waits in a forever loop waiting for watchdog), I'd like to avoid including all thisModule strings in the final output file.
However I didn't find a good solution, except redefining MYASSERT() in two different ways, depending on the build, and implementing two different versions for myassert for the two builds.
I'm using -fdata-sections, -ffunction-sections and -Wl,--gc-sections. I think the linker doesn't remove those strings because they are really used in modules and really passed to an external function.