This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Interrupts in Static Library (CCS)

Hi,

I have a Static Library project. There are 2 interrupt subroutines in it. When I link my "main" project and the library, it doesn't work properly. I've found that there are not interrupt vectors for my library interrupts in an area 0xff80...0xffff. Yet vectors to interrups of a "main" project are there, ok.

Library interrupt subroutines (ISR hooks) are compiled (see them in listings of library), but I cannot find them in .MAP file of linked project.

How can I make Linker to include my library ISR and corresponding vectors in an output file?

Thanks!

  • UNDEFINED SYMBOLS - that is an answer!
    When we attach a library to a project, Linker searches in the library ONLY for "undefined symbols". That is a great advantage of a library - no linking of unused code... But ISRs are not referenced in "main" project - so they are not searched.

    I added 

    --undef_sym=USCI_A0_ISR_HOOK
    --undef_sym=TIMER1_A0_ISR_HOOK
    to Symbol Management options of Linker - and the ISR are linked now!
  • Indeed, the linker won't link parts that aren't referenced before.
    It not only allows for just linking required code but also allows overriding library functions by own versions (which then are used by other library functions). A common example is putchar() which can be simply overwritten with an own implementation to stash aways output data generated by printf and others.

    However, if the hooks aren't referenced, they aren't used. Your hack of the linker file will make them being linked, but they are still not referenced anywhere.
    The problem is that normally, the compiler will generate a reference to an ISR by putting their address into the interrupt vector table. Since any object file content will be linked, the vector table entry will get linked and there is the reference to the ISR. But in a library, there is no reference to the vector table entry, so it won't get linked and therefore there is no reference to the ISR and it won't get linked.

    What you need s to put the ISR address into the interrupt vector table. Then it will be linked automatically.
    Well, I don't know how to do it on CCS or IAR.

  • Thank you for your attenton to my topic!

    The wonderful thing is that CCS generates interrupt vectors! As I mentioned earlier, I added symbols 

    TIMER1_A0_ISR_HOOK and USCI_A0_ISR_HOOK

    to advanced Linker options as unresoled symbols. That is enough, as I see. The program runs OK! 

    I still don't understand when and where interrupt vectors appear. Maybe in linking. But it works :)

  • Iurii Vlasenko said:
    The wonderful thing is that CCS generates interrupt vectors! As I mentioned earlier, I added symbols
    TIMER1_A0_ISR_HOOK and USCI_A0_ISR_HOOK


    Looking closer at your post, you didn't add symbols, you actually removed symbols. (undef = un-define)

    I don't know the internal mechanisms of CCS, but it seems that there is a built-in requirement for having all interrupt vectors filled, And the default is to provide dummy-hooks for all vectors that didn't have an override in your C code. So ISRs from libraries won't be linked. By undefining the hooks, you forced linking the references from the library for the now empty vectors and therefore the ISRs too.

**Attention** This is a public forum