I'm building an executable using GCC 3.4.0 . The target is an embedded system. I've been using a way of modularly defining "console command handlers" by defining a function pointer to a handler in any compilation unit to be in a certain linker section. At runtime when a command is entered on the console I can loop through all the handlers in the "console handler data section" without having to have a central table with references to each handler.
Clever clever right, well now it's biting me. When I do this in a c file that has no other externally referenced symbols (my handler is the only function for example), the linker throws all of it away. My handler isn't included in the final executable, neither is anything else in the compilation unit.
- A hack is to define a dummy global variable in the c file and reference it elsewhere, then my handler in it's special data section, is included.
- I can also use -u to the linker and it works, but blows the goal of modularity.
- I've tried using attribute ((used)) on my callback with no luck -- seems to get ignored.
- My special section has the KEEP specification, but that doesn't help.
Any ideas?
Thanks, Kurt