This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch, avr] Prevent .noinit section from incorrect placement


This patch is similar to:
https://sourceware.org/ml/binutils/2014-07/msg00033.html

When .data and .bss sections are empty .noinit section is placed at data
region's start. This will be incorrect for devices that has different
data start address than data region start in linker script.

Test case:  
  1 int volatile a __attribute__((section(".noinit")));
  2 void main ()
  3 {
  4   while (1)
  5     a++;
  6 }

avr-gcc -O1 -Wl,-gc-sections -mmcu=attiny841

Below patch updates .noinit section's VMA to end of .bss section. So, .noinit
section will be placed at .data section address (-Tdata=<address>) when .data
and .bss sections are empty.

If ok, could someone commit please? I do not have commit access.

Regards,
Pitchumani

ld/ChangeLog

2016-01-22  Pitchumani Sivanupandi  <pitchumani.s@atmel.com>

    * scripttempl/avr.sc (.noinit): Force .noinit VMA to end of .bss VMA.
    * scripttempl/avrtiny.sc (.noinit): Likewise.

diff --git a/ld/scripttempl/avr.sc b/ld/scripttempl/avr.sc
index 038e7ab..0f136c5 100644
--- a/ld/scripttempl/avr.sc
+++ b/ld/scripttempl/avr.sc
@@ -210,7 +210,7 @@ SECTIONS
   ${RELOCATING+ __data_load_end = __data_load_start + SIZEOF(.data); }

   /* Global data not cleared after reset.  */
-  .noinit ${RELOCATING-0}:
+  .noinit ${RELOCATING+ ADDR(.bss) + SIZEOF (.bss)} ${RELOCATING-0}: ${RELOCATING+ AT (ADDR (.noinit))}
   {
     ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
     *(.noinit*)
diff --git a/ld/scripttempl/avrtiny.sc b/ld/scripttempl/avrtiny.sc
index a4cf5db..e998fd2 100644
--- a/ld/scripttempl/avrtiny.sc
+++ b/ld/scripttempl/avrtiny.sc
@@ -210,7 +210,7 @@ SECTIONS
   ${RELOCATING+ __data_load_end = __data_load_start + SIZEOF(.data); }

   /* Global data not cleared after reset.  */
-  .noinit ${RELOCATING-0}:
+  .noinit ${RELOCATING+ ADDR(.bss) + SIZEOF (.bss)} ${RELOCATING-0} : ${RELOCATING+ AT (ADDR (.noinit))}
   {
     ${RELOCATING+ PROVIDE (__noinit_start = .) ; }
     *(.noinit*)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]