This is the mail archive of the 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]

Re: [patch,avr] Take #2 PR21472: Upgrade emulation avrxmega3 so it has .rodata in flash instead of in SRAM.

On 09.05.2017 12:54, Nick Clifton wrote:
Hi Georg-Johann,
diff --git a/ld/emulparams/ b/ld/emulparams/
index abaa5b3..504c492 100644
--- a/ld/emulparams/
+++ b/ld/emulparams/
@@ -1,6 +1,6 @@

I would much prefer it if you did not create a new script, but instead added
parametrisation to the current avr and avrtiny scripts.  (In fact it would be
even better if you could combine and and just have one script).

The reason for this is that the more scripts you have, the greater the chances
of making an error or missing one out when it comes to future changes.

Ah, now I understand the objection.  It was because I added a new
template script, not because of the new avrxmega3.x etc.

So here is a patch that maker more generic and uses
RODATA_PM_OFFSET to achieve is.

Take a look at the script.  It is used by lots of different targets, but
it is highly customizable via definitions in the target's specific emulparams

The alternative approach, which I would also consider to be reasonable, is to have
a base avr script that defines all of the things that are consistent between all
three proposed avr linker scripts and to include this script into smaller,
avr-variant scripts that just defines those things that are specific to that variant.
Kind of like how the script is included into the script.


I didn't unite with though which is a different story.

	Upgrade the currently unused emulation avrxmega3 to one which
	supports avrxmega2 devices with flash memory visible in the
	SRAM address range.

	* emulparams/ (RODATA_PM_OFFSET): Set to 0x8000.
	* scripttempl/
	as default if not already defined.
	(.data) [!RODATA_PM_OFFSET]: Don't include .rodata and friends.
	(.rodata) [RODATA_PM_OFFSET]: Put at an offset of

	* config/tc-avr.c (mcu_types): Add entries for: attiny416,
	attiny417, attiny816, attiny817.

diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c
index 7214c07..79837c8 100644
--- a/gas/config/tc-avr.c
+++ b/gas/config/tc-avr.c
@@ -300,6 +300,10 @@ static struct mcu_type_s mcu_types[] =
   {"atxmega16e5", AVR_ISA_XMEGA,  bfd_mach_avrxmega2},
   {"atxmega8e5",  AVR_ISA_XMEGA,  bfd_mach_avrxmega2},
   {"atxmega32x1", AVR_ISA_XMEGA,  bfd_mach_avrxmega2},
+  {"attiny416",   AVR_ISA_XMEGA,  bfd_mach_avrxmega3},
+  {"attiny417",   AVR_ISA_XMEGA,  bfd_mach_avrxmega3},
+  {"attiny816",   AVR_ISA_XMEGA,  bfd_mach_avrxmega3},
+  {"attiny817",   AVR_ISA_XMEGA,  bfd_mach_avrxmega3},
   {"atxmega64a3", AVR_ISA_XMEGA,  bfd_mach_avrxmega4},
   {"atxmega64a3u",AVR_ISA_XMEGAU, bfd_mach_avrxmega4},
   {"atxmega64a4u",AVR_ISA_XMEGAU, bfd_mach_avrxmega4},
diff --git a/ld/emulparams/ b/ld/emulparams/
index abaa5b3..7c5a1e5 100644
--- a/ld/emulparams/
+++ b/ld/emulparams/
@@ -9,4 +9,5 @@ TEMPLATE_NAME=elf32
diff --git a/ld/scripttempl/ b/ld/scripttempl/
index b889180..144d32d 100644
--- a/ld/scripttempl/
+++ b/ld/scripttempl/
@@ -4,6 +4,17 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
+#         If empty, .rodata sections will be part of .data.  This is for
+#         devices where it is not possible to use LD* instructions to read
+#         from flash.
+#         If non-empty, .rodata is not part of .data and the .rodata
+#         objects are assigned addresses at an offest of RODATA_PM_OFFSET.
+#         This is for devices that feature reading from flash by means of
+#         LD* instructions, provided the addresses are offset by
+#         __RODATA_PM_OFFSET__ (which defaults to RODATA_PM_OFFSET).
 cat <<EOF
 /* Copyright (C) 2014-2017 Free Software Foundation, Inc.
+if test -n "$RODATA_PM_OFFSET"; then
+    cat <<EOF
+cat <<EOF
   text   (rx)   : ORIGIN = 0, LENGTH = __TEXT_REGION_LENGTH__
@@ -187,15 +206,45 @@ SECTIONS
     KEEP (*(.fini0))
     ${RELOCATING+ _etext = . ; }
   } ${RELOCATING+ > text}
+# Devices like ATtiny816 allow to read from flash memory by means of LD*
+# instructions provided we add an offset of __RODATA_PM_OFFSET__ to the
+# flash addresses.
+if test -n "$RODATA_PM_OFFSET"; then
+    cat <<EOF
+  .rodata ${RELOCATING+ ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ } ${RELOCATING-0} :
+  {
+    *(.rodata)
+    ${RELOCATING+ *(.rodata*)}
+    *(.gnu.linkonce.r*)
+  } ${RELOCATING+AT> text}
+cat <<EOF
   .data        ${RELOCATING-0} :
     ${RELOCATING+ PROVIDE (__data_start = .) ; }
     ${RELOCATING+ *(.data*)}
+    *(.gnu.linkonce.d*)
+# Classical devices that don't show flash memory in the SRAM address space
+# need .rodata to be part of .data because the compiler will use LD*
+# instructions and LD* cannot access flash.
+if test -z "$RODATA_PM_OFFSET"; then
+    cat <<EOF
     *(.rodata)  /* We need to include .rodata here if gcc is used */
     ${RELOCATING+ *(.rodata*)} /* with -fdata-sections.  */
-    *(.gnu.linkonce.d*)
+    *(.gnu.linkonce.r*)
+cat <<EOF
     ${RELOCATING+. = ALIGN(2);}
     ${RELOCATING+ _edata = . ; }
     ${RELOCATING+ PROVIDE (__data_end = .) ; }

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