title: undefined reference to `__aeabi_unwind_cpp_pr1' for C-only code
body: <p>I am building a bare-metal code for ARM926 and I need the generated output to be as tight as possible.</p>
  
  <p>In my best effort, though, I still receive this error:</p>
  
  <pre><code>yocto/poky/build-idprint/tmp/work/idprint-poky-linux-gnueabi/idpr/1.0-r0/
  recipe-sysroot/usr/lib/libc.a(raise.o):
  (.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr1'
  </code></pre>
  
  <p>In my <code>Makefile</code> I put this linker flags:</p>
  
  <pre><code>LD_OPT    = -Wl,-gc-sections -Wl,-build-id=none -flto
  LD_LINK   = -static -nostartfiles -nostdlib -Wl,--start-group,-lgcc,-lc,--end-group
  LDFLAGS   = -T $(BINARY).ld -Xlinker -Map=$(BINARY).map $(LD_OPT)
  </code></pre>
  
  <p>And the link command is</p>
  
  <pre><code>$(LINK.cc) $(OBJS) $(LD_LINK) src/lib_dummies.o -o $(BINARY).elf
  </code></pre>
  
  <p>Finally I have a custom linker script as simple as possible:</p>
  
  <pre><code>OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
  OUTPUT_ARCH(arm)
  ENTRY(fiq_main)
  
  SECTIONS
  {
    . = 0x0;
    .text : {
      KEEP(*(.textEntry));
      *(.text*)
      *(.text .gnu.linkonce.t.*)
    }
    . = ALIGN(1024);
    _bss_start = .;
    .data : { *(.data) }
    .bss : { *(.bss) }
    _bss_end = .;
  }
  </code></pre>
  
  <p>I added a custom dummy <code>__aeabi_unwind_cpp_pr1</code> to my code (inspired from libgcc sources) but it didn't help.</p>
  
  <p>I have read about quite a few pages around the web but none explained me why is <code>libgcc</code> trying to link a <code>C++</code> function to my <code>C</code>-only project.
  Okay, <code>$(LINK.cc)</code> is evaluated to <code>arm-poky-linux-gnueabi-g++</code> but I still se no sense trying to link a <code>C++</code> function to <code>libgcc</code>. It would make sense if I was linking <code>libstdc++</code>. Moreover, $(LD) fails for othre reasons (can't find <code>-lgcc</code>).</p>
  
  <p>No optimization flags I could find helped me with this either.</p>
  
  <p>Look, it is very important that my code doesn't add any uneeded stuff.
  Everything started only because I need to use integer division (unresolved <code>__aeabi_idiv</code>...)</p>
  
  <hr>
  
  <p>I omitted the optimization flags for simplicity but, if needed, please tell me and I'll add them.</p>
  
  <p>Any help will be greatly appreciated.
  Thanks.</p>