I have a function in my code I only call from the debugger. To the compiler, this function looks like dead code. Is there an attribute or pragma I can place on this function to make sure it is always liked to my application? How about for skipping the dead code elimination phase? My function is declared as a helper function in a header file because it is associated with a templated C++ class definition.
Note that I *do* have a nonsensical condition statement in my class constructors (based on the constructor arguments) that "calls" the function that I don't want to eliminate. The problem is that the compiler is apparently smart enough to know that the nonsensical condition can't occur (though I'm amazed it has enough information to figure that out), and it eliminates the call as dead code.
I don't see why you insist on linking in a function that is never called.
Here is a way to deceive the compiler:
.. int trojan=0; ..
extern int trojan; extern void unusedsub(...,...); .. if(trojan)unusedsub(arg1,arg2) ..
Even this trick may fail if the compiler is allowed to do global analysis/multi-file optimizations. In that case, you would have to set trojan equal to an expression whose value is unknown to the compiler but to you is known to be equal to zero.