bug-binutils
[Top][All Lists]
Advanced

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

Re: Binutils/ld: linker script does not work for AVR mega 0 series (avrx


From: Nick Clifton
Subject: Re: Binutils/ld: linker script does not work for AVR mega 0 series (avrxmega3)
Date: Mon, 31 Oct 2022 14:57:03 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0

Hi Konrad,

the linker fails on trying to arrange data/bss segments even with very few 
small variables. E.g.:

Please could you file a bug report for this problem here:

  https://sourceware.org/bugzilla/enter_bug.cgi?product=binutils


avr-g++ -Os -Wl,--gc-sections -B 
~/tronic/atmel-compiler-packs/mega/gcc/dev/atmega3208 -mmcu=atmega3208 -o 
fw.elf dimmer.o dmx.o input.o ledout.o pwm.o
<...>/lib/gcc/avr/12.2.0/../../../../avr/bin/ld: address 0x803004 of fw.elf 
section `.bss' is not within region `data'

If you can include these object files as an aid for reproducing the problem, 
that would be appreciated.


I narrowed the problem down to the Linker script avrxmega3.xn - it somehow messes up the data segment in the MEMORY section at the top. I was able to get it to link by changing that line:

-  data   (rw!x) : ORIGIN = 0x802000, LENGTH = __DATA_REGION_LENGTH__
+  data   (rw!x) : ORIGIN = 0x802000, LENGTH = 0x10000

The fixed origin seems very dubious to me and I wasn't able to debug 
__DATA_REGION_LENGTH__.

It is defined earlier on in script:

  __DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? 
__DATA_REGION_LENGTH__ : 0xffa0;

In terms of source code, it is defined in ld/scripttempl/avr.sc as:

  __DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? 
__DATA_REGION_LENGTH__ : $DATA_LENGTH;

and DATA_LENGTH is defined in the ld/emulparams/avr*.sh files.



I consider my fix "an ugly hack". The linker script in Arduino looks more elegant and also works:

__DATA_REGION_ORIGIN__ = DEFINED(__DATA_REGION_ORIGIN__) ? 
__DATA_REGION_ORIGIN__ : 0x802000;
//...
data   (rw!x) : ORIGIN = __DATA_REGION_ORIGIN__, LENGTH = __DATA_REGION_LENGTH__

Actually this reasonable, and would provide some more utility to users.

Currently the avr.sc file (mentioned above) has this code:

   data   (rw!x) : ORIGIN = $DATA_ORIGIN, LENGTH = __DATA_REGION_LENGTH__

and the definition of DATA_ORIGIN can be found in ld/emulparams/avrxmega3.sh:

  DATA_ORIGIN=0x802000

I am not intimately familiar with the AVR architecture variants, so I do not
know if this is a reasonable value...

Cheers
  Nick




reply via email to

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