1
votes

If you want to declare .weakreference for a set of interrupt vectors such as:

.weakreference ISR_SPI_HANDLER, defaultExceptionHandler

in a startup.S file or some framework include, it's very useful except that if you then declare ISR_SPI_HANDLER as a function in your main.c file, ISR_SPI_HANDLER in the startup.S still resolves to defaultExceptionHandler because .weakreference only works in local scope (terminology? pre-linking). However, .weak functions as it's expected, and allows you to "override" the definition with a definition in main.c, but if you don't, you'll always resolve to 0x00, which is inferior obviously to resolving to a default vector.

How can I overcome this?

2
Post your alternate solution as a separate answer, not as part of the question, please. - Peter Cordes

2 Answers

1
votes

Do not use the .weakref in the assembler. Instead just use ISR_SPI_HANDLER as an external. The assembler naturally wants to optimize to PC relative jumps to known locations. You are fighting this and someone else will want the call to defaultExceptionHandler.

Instead use the linker,

  .text : {
    *(.text);
    ISR_SPI_HANDLER = DEFINED(ISR_SPI_HANDLER) ? ISR_SPI_HANDLER : defaultExceptionHandler;
    …
  }

Alternatively, split startup.S with the .weakref and defaultExceptionHandler declaration in one file and another that is using/calling ISR_SPI_HANDLER.

1
votes

NEW SOLUTION:

Apparently, you can use .weak NAME to make it an external symbol and then .set NAME VALUE to give it a different default value than 0x0