title: __isr_vectors variable not found when placed inside a static library
body: <p>As a spin-off of a previous question (<a href="https://stackoverflow.com/questions/28895703/sbrk-function-not-found-when-placed-in-a-static-library">sbrk function not found when placed in a static library</a>):
  I'm creating a bare-metal application for the stm32f407 microcontroller, which has an ARM Cortex M4 core. I'm trying to create a static library containing basic stuff like cmsis, the HAL functions, and the interrupt vector table, and link that static library to my main application. However, when the interrupt vector table (which is a variable named <code>__isr_vectors</code>) is placed inside the static library, the variable does not survive linking.</p>
  
  <p>I can piece together what happens: The linker has an object main.o, and a few libraries. It takes all symbols found in <code>main.o</code>, and it takes all symbols out of the libraries that are used by <code>main.o</code> or that are used by other symbols that are already deemed necessary. The <code>__isr_vectors</code> variable is not yet needed at this stage, since no one references this variable explicitly, so it is thrown out by the linker. Then, the linker searches for all input sections named <code>.isr_vector</code> in order to create the output section <code>.isr_vector</code>. However, no symbols survived up to this moment, so that output section is left empty, and my binary is left without an interrupt table.</p>
  
  <p>I know of one trick to get the <code>__isr_vector</code> to survive: reference it in a dummy function in <code>main.c</code>. However, this is kinda ugly and error-prone (you can forget to do that when building a new application against the same static library). So here's my question: Is there another way to make the <code>__isr_vector</code> survive, so that I can just link in my static library and be done with it?</p>
  
  <p>These are the files and steps to reproduce the problem:</p>
  
  <p>vectors.c:</p>
  
  <blockquote>
    <p>__ attribute__ ((section(".isr_vector"), used)) void* __isr_vectors = 0;</p>
  </blockquote>
  
  <p>main.c:</p>
  
  <blockquote>
    <p>void _start(void) {}</p>
  </blockquote>
  
  <p>link.ld:</p>
  
  <blockquote>
    <p>MEMORY
       {
         FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
       }</p>
    
    <p>ENTRY(_start)</p>
    
    <p>SECTIONS
       {
           .isr_vector : ALIGN(4)
           {
               KEEP(*(.isr_vector))
           } >FLASH</p>
  
  <pre><code>   .text : ALIGN(4)
     {
         *(.text .text.*)
     } &gt;FLASH
  </code></pre>
    
    <p>}</p>
  </blockquote>
  
  <p>Commands:</p>
  
  <blockquote>
    <p>"C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\bin\arm-none-eabi-gcc.exe" -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb -ffunction-sections -std=gnu11 -o main.c.obj -c main.c
       "C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\bin\arm-none-eabi-gcc.exe" -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb -ffunction-sections -std=gnu11 -o vectors.c.obj -c vectors.c</p>
    
    <p>"C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\bin\arm-none-eabi-gcc.exe" -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb -ffunction-sections -std=gnu11 -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb -Wl,--gc-sections -nostartfiles -Wl,-Tlink.ld -Wl,-Map=test_linker.without_library.map main.c.obj vectors.c.obj -o test_linker.without_library.elf</p>
    
    <p>"C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\bin\arm-none-eabi-ar.exe cq libtest_linker.lib.a vectors.c.obj</p>
    
    <p>"C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\bin\arm-none-eabi-ranlib.exe" libtest_linker.lib.a</p>
    
    <p>"C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\bin\arm-none-eabi-gcc.exe" -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb -ffunction-sections -std=gnu11 -g -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb -Wl,--gc-sections -nostartfiles -Wl,-Tlink.ld -Wl,-Map=test_linker.with_library.map main.c.obj -o test_linker.with_library.elf libtest_linker.lib.a</p>
  </blockquote>