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.

Compiler does not generate proper relocations for interrupts



I have a piece of code that uses interrupts. Generally, the values of the interrupts are saved in the ELF file in sections called RTC, PORT2, TIMER2_A1 etc.

When flashed, those values are copied to the interrupt vector table at 0xFFD2.

However, in my relocatable file, the sections have value 0, and their relocations ALL point to __TI_ISR_TRAP, when the TIMER0_A1 and TIMER0_A0 should point to my functions.

Dump of the values of the interrupts:

Contents of section RTC:
 ffd2 0000                                 ..              
Contents of section PORT2:
 ffd4 0000                                 ..              
Contents of section TIMER2_A1:
 ffd6 0000                                 ..              
Contents of section TIMER2_A0:
 ffd8 0000                                 ..              
Contents of section USCI_B1:
 ffda 0000                                 ..              
Contents of section USCI_A1:
 ffdc 0000                                 ..              
Contents of section PORT1:
 ffde 0000                                 ..              
Contents of section TIMER1_A1:
 ffe0 0000                                 ..              
Contents of section TIMER1_A0:
 ffe2 0000                                 ..              
Contents of section DMA:
 ffe4 0000                                 ..              
Contents of section USB_UBM:
 ffe6 0000                                 ..              
Contents of section TIMER0_A1:
 ffe8 0000                                 ..              
Contents of section TIMER0_A0:
 ffea 0000                                 ..              
Contents of section ADC12:
 ffec 0000                                 ..              
Contents of section USCI_B0:
 ffee 0000                                 ..              
Contents of section USCI_A0:
 fff0 0000                                 ..              
Contents of section WDT:
 fff2 0000                                 ..              
Contents of section TIMER0_B1:
 fff4 0000                                 ..              
Contents of section TIMER0_B0:
 fff6 0000                                 ..              
Contents of section COMP_B:
 fff8 0000                                 ..              
Contents of section UNMI:
 fffa 0000                                 ..              
Contents of section SYSNMI:
 fffc 0000                                 ..              
Contents of section .reset:
 fffe 0000                                 .. 

Dump of the relocations:

Relocation section '.relRTC' at offset 0xc4d0 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relPORT2' at offset 0xc4d8 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relTIMER2_A1' at offset 0xc4e0 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relTIMER2_A0' at offset 0xc4e8 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relUSCI_B1' at offset 0xc4f0 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relUSCI_A1' at offset 0xc4f8 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relPORT1' at offset 0xc500 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relTIMER1_A1' at offset 0xc508 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relTIMER1_A0' at offset 0xc510 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relDMA' at offset 0xc518 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relUSB_UBM' at offset 0xc520 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relADC12' at offset 0xc528 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relUSCI_B0' at offset 0xc530 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relUSCI_A0' at offset 0xc538 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relWDT' at offset 0xc540 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relTIMER0_B1' at offset 0xc548 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relTIMER0_B0' at offset 0xc550 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relCOMP_B' at offset 0xc558 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relUNMI' at offset 0xc560 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP

Relocation section '.relSYSNMI' at offset 0xc568 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP
Relocation section '.rel.reset' at offset 0xc298 contains 1 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  00058b02 R_MSP430_ABS16    00000000   _c_int00

Any ideas ? Can someone reproduce it ?

Thank you.

EDIT: Just in case, this is how the normal ELF looks like.

  • Jon Zarate said:
    However, in my relocatable file, the sections have value 0

    Exactly how do you create this relocatable file?  Please show the build commands and options exactly as they are used.

    Thanks and regards,

    -George

  • I won't be able to copy/paste it until friday, however, the argument I used to make it relocatable was --relocatable. Actaually, I just added -r and it changed to --relocatable automatically. I guess it recognized it.

    However, the values being 0's is not a problem to me. The values on other sections before perfoming the relocations are also 0. The problem is that the relocations regarding the interrupt sections are wrong. I expected something like this:

    Relocation section '.relTIMER1_A1' at offset 0xc508 contains 1 entries:
     Offset     Info    Type            Sym.Value  Sym. Name
    00000000  0005a702 R_MSP430_ABS16    00000034   TIMER0_A1_ISR
    
    Relocation section '.relTIMER1_A0' at offset 0xc510 contains 1 entries:
     Offset     Info    Type            Sym.Value  Sym. Name
    00000000  0005a702 R_MSP430_ABS16    00000034   TIMER0_A0_ISR
    

    Instead of all of them pointing to __TI_ISR_TRAP:

    Relocation section '.relTIMER1_A1' at offset 0xc508 contains 1 entries:
     Offset     Info    Type            Sym.Value  Sym. Name
    00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP
    
    Relocation section '.relTIMER1_A0' at offset 0xc510 contains 1 entries:
     Offset     Info    Type            Sym.Value  Sym. Name
    00000000  0005a702 R_MSP430_ABS16    00000034   __TI_ISR_TRAP
    

    Hope it´s clearer now.

    Thanks.

  • Paging . Why can't I add @Archaeologist ?
    Have you been able to reproduce it ? Is it a bug ?
    Thank you.
  • Because I am merely a figment of your imagination. But seriously, I am not an expert in the TI MSP linker's interrupt vector handling, so I don't know what's going on.
  • Archaeologist said:
    Because I am merely a figment of your imagination

    LOL. Well, you have been my savior many times.

    Archaeologist said:
    But seriously, I am not an expert in the TI MSP linker's interrupt vector handling, so I don't know what's going on.

    Could you at least tell me if you can reproduce it ? Just create a relocatable project that uses interrupts, check the relocation symbols and tell me if they are all __TI_ISR_TRAP like in my case. If that happens, I may have found a bug ! From now on, call me hacker !

    (sorry I could not resist the temptation ^^)

    Thank you both.

  • Just wanted to say I tried to reproduce it again and it did happen again. I just created a proyect that blinks a LED using a Timer (interrupt) and the same problem appeared.


    There are many workarrounds I could try, however, is this a bug ? Can someone confirm before I start solving it in another way ?

    Thanks.

  • Should I post this question in another forum ?
  • No, this is the right forum. I haven't been able to get to this because I'm not immediately familiar with how it works, working with relocatable executable files is not technically a supported mode, and I've got lots of other issues that need to be addressed. I suspect the others who watch this forum are in pretty much the same situation.
  • I apologize for the delay.  This took more research than is typical.

    A file linked with --relocatable (or -r for short) can be linked again.  But it is not ready for execution, just like an object file created by the assembler is not ready for execution.  ELF does provide for building dynamic executable files, but this capability is not supported for MSP430.

    Thanks and regards,

    -George

  • George Mock said:
    But it is not ready for execution

    (1) What do you mean ? After I link/relocate all the addresses in the code I can run it. I have already done it before. I don't quite get the comparison here.

    George Mock said:
    but this capability is not supported

    Still, it's weird that other relocations work like a charm, (2) did you find out why isn't it working ? (3) Did you check the linker code or something ?

    (4) Any chance of getting it fixed in the next release next month ?

  • 1) Right, *after* you relocate it. Before you relocate it, it won't run.
    2) George is referring to "dynamic shared object" support, which is simply not implemented for MSP
  • Archaeologist said:
    George is referring to "dynamic shared object" support, which is simply not implemented for MSP

    I don't understand, how is this related to why the relocation works on some sections but doesn't on others ?. I am not using shared mode, I am using relocatable mode.

    https://en.wikipedia.org/wiki/Executable_and_Linkable_Format said:
    0x10 2 e_type 1, 2, 3, 4 specify whether the object is relocatable, executable, shared, or core, respectively.

    Thanks.

  • George is not addressing your question directly. He is telling you that the overall path you are taking, a "relocatable executable file" is not a mode that is intended to be supported in ELF files; in fact, no such mode actually exists. "DYNAMIC relocatable executable files" (aka shared object files) are the industry-standard solution to the sorts of problems you are trying to solve. However, the TI MSP compiler does not support this feature.