avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Linking and unused functions.


From: Ebert, Rolf
Subject: RE: [avr-gcc-list] Linking and unused functions.
Date: Thu, 4 Mar 2004 10:35:03 +0100

> >   I am not used to this behavior. I'm used to having only the
> >   functions actually called getting linked into the hex file.
> >
 
>   http://www.avr1.org/pipermail/avr-gcc-list/2002-October/002919.html

> This is exactly what avr-libc does.
> 
> This should probably be added to the FAQ.

It certainly belongs into the FAQ.

On the other hand, -ffunction-sections and -Wl,--gc-sections is a documented
feature of gcc.  It is very useful, especially in the embedded world.

In C++ and Ada is is very common to have several
methods/functions/subprograms in one file.  In gcc-Ada it not even possible
to put the subprograms of one package in different .o files.  

Bern Trog from Ada-AVR (avr-ada.sourceforge.net) project has developed a
patch to the avr-libc linker script to make it work correctly.  I think it
does not hurt the usual C development and would be good enhancement of the
general AVR gcc tool chain.

        Rolf


----
--- old/avr2.x  Mon Nov 17 19:37:00 2003
+++ new/avr2.x  Wed Nov 19 20:06:24 2003
@@ -1,4 +1,8 @@
-/* Default linker script, for normal executables */
+/*
+   Modified linker script, added KEEP() to get non-zero size .elf files
when using:
+  -ffunction-sections (-fdata-sections) and -Wl,--gc-sections
+*/
+
 OUTPUT_FORMAT("elf32-avr","elf32-avr","elf32-avr")
 OUTPUT_ARCH(avr:2)
 MEMORY
@@ -69,7 +73,7 @@
   /* Internal text space or external memory */
   .text :
   {
-    *(.vectors)
+    KEEP(*(.vectors))
      __ctors_start = . ;
      *(.ctors)
      __ctors_end = . ;
@@ -79,20 +83,24 @@
     *(.progmem.gcc*)
     *(.progmem*)
     . = ALIGN(2);
-    *(.init0)  /* Start here after reset.  */
-    *(.init1)
-    *(.init2)  /* Clear __zero_reg__, set up stack pointer.  */
-    *(.init3)
-    *(.init4)  /* Initialize data and BSS.  */
-    *(.init5)
-    *(.init6)  /* C++ constructors.  */
-    *(.init7)
-    *(.init8)
-    *(.init9)  /* Call main().  */
+
+    KEEP(*(.init0))  /* Start here after reset.  */
+    KEEP(*(.init1))
+    KEEP(*(.init2))  /* Clear __zero_reg__, set up stack pointer.  */
+    KEEP(*(.init3))
+    KEEP(*(.init4))  /* Initialize data and BSS.  */
+    KEEP(*(.init5))
+    KEEP(*(.init6))  /* C++ constructors.  */
+    KEEP(*(.init7))
+    KEEP(*(.init8))
+    KEEP(*(.init9))  /* Call main().  */
+
     *(.text)
     . = ALIGN(2);
     *(.text.*)
     . = ALIGN(2);
+
+    KEEP(*(.fini?))
     *(.fini9)  /* _exit() starts here.  */
     *(.fini8)
     *(.fini7)

_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


reply via email to

[Prev in Thread] Current Thread [Next in Thread]