I am creating an executable using GCC 3.4.0. The goal is an embedded system. I used a way to modularly define "console command handlers" by defining a function pointer in any compiler that should be in a specific linker section. At run time, when a command is entered to the console, I can skip all the handlers in the data section of the console handler without having to have a central table with links to each handler.
Clever clever, well, now he bites me. When I do this in a c file that has no other external links (my handler is the only function, for example), the linker discards it all. My handler is not included in the final executable, and nothing happens in the compiler.
- A hacker is to define a dummy global variable in the c file and refer to it elsewhere, then my handler is turned on in this special data section.
- I can also use -u for the linker, and it works, but it hits the modularity goal.
- I tried using the ((used)) attribute on my callback without any luck - it seems to be ignored.
- There is a KEEP specification in my special section, but that does not help.
Any ideas?
Thanks Kurt
source
share