Initialization of global int variable at specific address overwrites initialization of another variable

XMLWordPrintable

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Not Prioritized

      The attached file.c has these lines.

      __attribute__((retain, location(0xC001)))
      int TEST_FirstVariable = 0xABCD;
      
      __attribute__((retain, location(0xC002)))
      long TEST_SecondVariable = 0x12345678;
      
      __attribute__((retain, location(0xC004)))
      long TEST_ThirdVariable = 0xE9F0A1B2;
      

      Build it, then create the disassembly.

      $ cl2000 --abi=eabi file.c -z -o file.out -m file.map lnk.cmd
      $ dis2000 --all file.out > file_dis.txt
      

      Inspect the disassembly. Find these lines ...

      000800f2   0001    .word 0x0001
      000800f3   0000    .word 0x0000
      000800f4   0002    .word 0x0002
      000800f5   0000    .word 0x0000
      000800f6   abcd    .word 0xabcd
      000800f7   0000    .word 0x0000
      000800f8        __TI_Handler_Table_Base:
      000800f8   0002    .word 0x0002
      000800f9   0008    .word 0x0008
      000800fa   00cd    .word 0x00cd
      000800fb   0008    .word 0x0008
      000800fc        __TI_Handler_Table_Limit:
      000800fc        __TI_CINIT_Base:
      000800fc   00dc    .word 0x00dc
      000800fd   0008    .word 0x0008
      000800fe   c006    .word 0xc006
      000800ff   0000    .word 0x0000
      00080100   00e6    .word 0x00e6
      00080101   0008    .word 0x0008
      00080102   c002    .word 0xc002
      00080103   0000    .word 0x0000
      00080104   00ec    .word 0x00ec
      00080105   0008    .word 0x0008
      00080106   c004    .word 0xc004
      00080107   0000    .word 0x0000
      00080108   00f2    .word 0x00f2
      00080109   0008    .word 0x0008
      0008010a   c001    .word 0xc001
      0008010b   0000    .word 0x0000
      

      The .cinit record that begins at 00080108 is for the variable Test_FirstVariable (address 0000c001). The source data for this record begins at 000800f2. The first word of the source data contains an index value of 1, which means this is a decompressed data record. The second word is padding. The next 2 words form a 32-bit value that is the number of 16-bit words to copy. It contains 2, when it should contain 1. This is followed by one word of data, and a final word of padding. To be specific, 000800f4 contains 2, when it should contain 1.

      When the startup code processes these records, Test_SecondVariable (a long) is initialized before Test_FirstVariable (an int). The initialization of Test_FirstVariable, by writing 1 word more than it should, overwrites the first word of Test_SecondVariable.

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-4582 - Initialization of global int variab...
                SYNCHRONIZED
                • Last Sync Date: