Bug 12484

Summary: avr-ld doesn't warn when a memory section is over
Product: binutils Reporter: massi <massimiliano.cialdi>
Component: ldAssignee: unassigned
Status: RESOLVED FIXED    
Severity: critical CC: nickc, s.pitchumani
Priority: P2    
Version: 2.21   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: A sample to reproduce the problem

Description massi 2011-02-11 15:41:42 UTC
Created attachment 5235 [details]
A sample to reproduce the problem

the initialized data belongs to ram, but them images is hold in flash of microcontroller.

Suppose to have a 32KB flash ans 2KB sram microncontroller.
Suppose to have a .text section as big as 31KB, and suppose to have a vector of initialized data as big as 1.5KB.

The binary file will be 32.5KB long, too long to be programmed into microcontroller's flash.

I would expect a linker error like:
region `text' overflowed by xx bytes
Comment 1 Pitchumani 2017-06-12 13:02:48 UTC
IMO, linker script should have been changed,

from:
  .data   : AT (ADDR (.text) + SIZEOF (.text))                                                                                                        
   {
      PROVIDE (__data_start = .) ;
     *(.data) 
     *(.data*)
     *(.rodata)  /* We need to include .rodata here if gcc is used */
     *(.rodata*) /* with -fdata-sections.  */
     *(.gnu.linkonce.d*)
     . = ALIGN(2);
      _edata = . ;
      PROVIDE (__data_end = .) ;
   }  > data

to:
  .data   : 
   {
      PROVIDE (__data_start = .) ;
     *(.data) 
     *(.data*)
     *(.rodata)  /* We need to include .rodata here if gcc is used */
     *(.rodata*) /* with -fdata-sections.  */
     *(.gnu.linkonce.d*)
     . = ALIGN(2);
      _edata = . ;
      PROVIDE (__data_end = .) ;
   }  > data AT> text

This way linker knows from which region the .data to be loaded, and finds overflow correctly.
Comment 2 Nick Clifton 2017-06-16 11:00:41 UTC
Hi Pitchumani,

(In reply to Pitchumani from comment #1)
> IMO, linker script should have been changed,

I think that you are using an old version of the linker.  The latest release
(2.28) already contains the change you are suggesting.

Cheers
  Nick
Comment 3 Pitchumani 2017-06-17 04:48:59 UTC
(In reply to Nick Clifton from comment #2)
> Hi Pitchumani,
> 
> (In reply to Pitchumani from comment #1)
> > IMO, linker script should have been changed,
> 
> I think that you are using an old version of the linker.  The latest release
> (2.28) already contains the change you are suggesting.

Hi Nick
Thanks. Yes, I meant the OP's attached testcase/ linker script.