This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Using linker directives to conditionally choose code

Hello all,
     Apologies if this has been asked before, but I haven't figured
out a way to do it from the LD documentation or from Googling around.
     I'm working on a highly embedded system on an STM32 (ARM
Cortex-M3 processor).  Thus, flash size is at a premium.  In the
current system, all of the interrupt handlers are defined as weak
symbols, defaulting to an empty handler.  If you want to actually
handle the interrupt, you override the weak symbol with a strong
symbol, and handle the interrupt in your code.
    However, I'm trying to do something a little more generic, without
using (much) more flash space.  What I would like to do is to define a
"registration" interface where users of the API would register a
callback, and then there would be generic versions of the interrupt
handlers that would figure out which interrupt happened, clear it out,
and call the appropriate callback(s).  Something like:

static (void)(*isr1_cb)(void);
static (void)(*isr2_cb)(void);

void ISR_Handler(void)

    if (isr1_fired && isr1_cb)
    if (isr2_fired && isr2_cb)


void register_isr1_cb(void (*cb)(void))
    isr1_cb = cb;


void do_init(void)

I could easily accomplish this by defining strong symbols for all of
the interrupt handlers, but that would eat up a bunch of flash space
for interrupts I don't use.  What I would like instead is to use the
default handler for all interrupts, *unless* someone called
register_isr{1,2}_cb(), at which point it would switch to the strong
ISR_Handler() symbol for just that interrupt.  I've tried a bunch of
stuff around making register_isr1_cb() a macro, having it define new
sections, and then doing conditional things in the linker script based
on those sections, but I haven't gotten it to work.  Before I provide
gory details on what I've tried already, does anyone have any thoughts
as to how I might accomplish this?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]