title: variables defined in linker script not coming through in c++ startup file
body: <p>I have the following linker script (left out irrelevant parts)</p>
  <pre><code>MEMORY
  {
    PROGRAM_FLASH (rx) : ORIGIN = 0x60000000, LENGTH = 0x40000 
    SRAM_DTC (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 
    SRAM_ITC (rwx) : ORIGIN = 0x0, LENGTH = 0x10000
    SRAM_OC (rwx) : ORIGIN = 0x20200000, LENGTH = 0x20000 
  }
  
  ENTRY(ResetISR)
  
  SECTIONS
  {
       /* Image Vector Table and Boot Data for booting from external flash */
  .boot_hdr : ALIGN(4)
  {
      FILL(0xff)
      __boot_hdr_start__ = ABSOLUTE(.) ;
      KEEP(*(.boot_hdr.conf))
      . = 0x1000 ;
      KEEP(*(.boot_hdr.ivt))
      . = 0x1020 ;
      KEEP(*(.boot_hdr.boot_data))
      . = 0x1030 ;
      KEEP(*(.boot_hdr.dcd_data))
      __boot_hdr_end__ = ABSOLUTE(.) ;
      . = 0x2000 ;
  } &gt;PROGRAM_FLASH
  
  .vector : ALIGN(4)
  {
      FILL(0xff)
      __vector_table_flash_start__ = . ;
      __vector_table_dtc_start__ = LOADADDR(.vector) ;
      
      KEEP(*(.isr_vector))
      
      . = ALIGN(4) ;
      
      __vector_table_size__ = . ;
       
  } &gt;PROGRAM_FLASH
  </code></pre>
  <p>So relevant takeaways:</p>
  <ul>
  <li>flash memory starts at 0x600000000</li>
  <li>some XIP boot bytes are written to dedicated locations beginning of flash, followed by &quot;my own stuff&quot;.</li>
  <li>I put vector tables at 0x60002000 (or better put, nxp sdk expects some xip bytes and jumps to 0x60002000 where I can put my own stuff).</li>
  <li>I am creating some variables with the current location so that I can use them in my startup script</li>
  <li>When I look at the disassembled code, i can clearly see that my vector tables described 0x45 words, so with above linker script I would expect that my <code>__vector_table_size__</code> at least would be 0x45</li>
  </ul>
  <p>In my startup .cpp I added some <code>extern</code>s so that I can read the memory info created by the linker.</p>
  <pre><code>extern unsigned int __vector_table_flash_start__;
  extern unsigned int __vector_table_dtc_start__;
  extern unsigned int __vector_table_size__;
      
  /* some temp vars so that my assignments don't get optimized out */
  volatile unsigned int i;
  volatile unsigned int ii;
  volatile unsigned int iii;
  
  __attribute__ ((naked, section(&quot;.after_vectors.reset&quot;)))
  void ResetISR(void) {
      // Disable interrupts
      __asm volatile (&quot;cpsid i&quot;);
      __asm volatile (&quot;MSR MSP, %0&quot; : : &quot;r&quot; (&amp;_vStackTop) : );
      //__asm volatile (&quot;LDR r9, = __global_offset_table_flash_start__&quot;);
      
      i = __vector_table_flash_start__;
      ii = __vector_table_dtc_start__;
      iii = __vector_table_size__;
  }
  </code></pre>
  <p>Again, nothing interesting, just some code to make sure nothing is optimized out, and that I can see the actual values of the variables in the debugger.</p>
  <p>When we know that my flash starts at <code>0x60000000</code> and that my <code>.vector</code> section has an offset of <code>0x2000</code></p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Variable</th>
  <th>Expected</th>
  <th>Actual</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td><strong>vector_table_flash_start</strong></td>
  <td>0x6002000</td>
  <td>0x20010000</td>
  </tr>
  <tr>
  <td><strong>vector_table_dtc_start</strong></td>
  <td>0x6002000</td>
  <td>0x20010000</td>
  </tr>
  <tr>
  <td><strong>vector_table_size</strong></td>
  <td>0x45</td>
  <td>0xffffffff</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>What I am doing wrong here??</p>
  <p>For reference, the relevant section of disassemble (<code>arm-none-eabi-objdump --disassemble-all eclipse/MIMXRT1024_Project/Debug/MIMXRT1024_Project.axf &gt; disassemble_pic</code>)</p>
  <p><a href="https://i.stack.imgur.com/Wzbt5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wzbt5.png" alt="enter image description here" /></a></p>