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]

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


On Tuesday 09 May 2017 04:24 PM, Nick Clifton wrote:
Hi Georg-Johann,

On 09.05.2017 07:51, Senthil Kumar Selvaraj wrote:
I'm still not convinced we need a new emulation for this.
I would really prefer it if you two can come to an agreement about
the best way to handle this.  I am not adverse to adding a new emulation
if this is what you want, but I would be worried if this leads to an
explosion in the number of linker scripts later on.


I don't see a way how to provide a linker description file without
supplying a new emulation.
How about defining __RODATA_PM_OFFSET__ on the linker command line
and using the current avrtiny.sc script ?


diff --git a/ld/emulparams/avrxmega3.sh b/ld/emulparams/avrxmega3.sh
index abaa5b3..504c492 100644
--- a/ld/emulparams/avrxmega3.sh
+++ b/ld/emulparams/avrxmega3.sh
@@ -1,6 +1,6 @@
  ARCH=avr:103
  MACHINE=
-SCRIPT_NAME=avr
+SCRIPT_NAME=avr_rodata
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 avr.sc and avrtiny.sc 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.

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

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 DWARF.sc script is included into the elf.sc script.
We have tentative patch to put rodata in flash conditionally (e.g. option flag) that
seems to be working.

gcc:
Based on flag, put rodata in new section (tentatively named .rodataFlash). Also generates new multilib (e.g. avrxmega2/flash-rodata) for architecture with -mflash-rodata flag.

Can enable this flag for devices with linear memory.

binutils:
It is similar to avrtiny change made to put rodata in flash. But the section name is .rodataFlash. Sections named .rodata will go to data (i.e. -mflash-rodata not enabled).

avr-libc: change needed to identify the new multilib structure (to be done).

Tested following example with attiny817 simulator that comes with Atmel Studio.
  1 volatile int var;
  2 const short svar = 34;
  3 const char * const hello = "hello world";
  4 volatile char cvar[12];
  5 void main ()
  6 {
  7   while (1)
  8   {
  9     var  = svar;
 10     strcpy (cvar, hello);
 11   }
 12 }

$ avr-objdump -h test.elf

test.new.elf:     file format elf32-avr

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000000  00803e00  000000b0  00000164  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         000000a0  00000000  00000000  000000b4  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .rodataFlash  00000010  000080a0  000000a0  00000154  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .bss          0000000e  00803e00  00803e00  00000164  2**0
                  ALLOC
  4 .stab         00000204  00000000  00000000  00000164  2**2
                  CONTENTS, READONLY, DEBUGGING
  5 .stabstr      0000009c  00000000  00000000  00000368  2**0
                  CONTENTS, READONLY, DEBUGGING
  6 .comment      00000029  00000000  00000000  00000404  2**0
                  CONTENTS, READONLY
  7 .note.gnu.avr.deviceinfo 0000003c  00000000  00000000  00000430 2**2
                  CONTENTS, READONLY

Regards,
Pitchumani
diff --git a/ld/scripttempl/avr.sc b/ld/scripttempl/avr.sc
index b889180..69025b8 100644
--- a/ld/scripttempl/avr.sc
+++ b/ld/scripttempl/avr.sc
@@ -21,6 +21,7 @@ __FUSE_REGION_LENGTH__ = DEFINED(__FUSE_REGION_LENGTH__) ? __FUSE_REGION_LENGTH_
 __LOCK_REGION_LENGTH__ = DEFINED(__LOCK_REGION_LENGTH__) ? __LOCK_REGION_LENGTH__ : 1K;
 __SIGNATURE_REGION_LENGTH__ = DEFINED(__SIGNATURE_REGION_LENGTH__) ? __SIGNATURE_REGION_LENGTH__ : 1K;
 __USER_SIGNATURE_REGION_LENGTH__ = DEFINED(__USER_SIGNATURE_REGION_LENGTH__) ? __USER_SIGNATURE_REGION_LENGTH__ : 1K;
+__RODATA_PM_OFFSET__ = DEFINED(__RODATA_PM_OFFSET__) ? __RODATA_PM_OFFSET__ : 0x8000;
 
 MEMORY
 {
@@ -188,6 +189,13 @@ SECTIONS
     ${RELOCATING+ _etext = . ; }
   } ${RELOCATING+ > text}
 
+  .rodataFlash ${RELOCATING+ ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ } ${RELOCATING-0} :
+  {
+    *(.rodataFlash)
+    ${RELOCATING+ *(.rodataFlash*)}
+    *(.gnu.linkonce.r*)
+  } ${RELOCATING+AT> text}
+
   .data        ${RELOCATING-0} :
   {
     ${RELOCATING+ PROVIDE (__data_start = .) ; }
diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c
index 648a125..6371b70 100644
--- a/gcc/config/avr/avr.c
+++ b/gcc/config/avr/avr.c
@@ -9956,6 +9956,20 @@ avr_asm_asm_output_aligned_bss (FILE *file, tree decl, const char *name,
 }
 
 
+/* Unnamed section callback for rodata_section
+   to track need of __do_copy_data.  */
+
+static void
+avr_output_rodata_section_asm_op (const void *data)
+{
+  if (!TARGET_FLASH_RODATA)
+    avr_need_copy_data_p = true;
+
+  /* Dispatch to default.  */
+  output_section_asm_op (data);
+}
+
+
 /* Unnamed section callback for data_section
    to track need of __do_copy_data.  */
 
@@ -10000,7 +10014,7 @@ avr_asm_init_sections (void)
   /* Override section callbacks to keep track of `avr_need_clear_bss_p'
      resp. `avr_need_copy_data_p'.  */
 
-  readonly_data_section->unnamed.callback = avr_output_data_section_asm_op;
+  readonly_data_section->unnamed.callback = avr_output_rodata_section_asm_op;
   data_section->unnamed.callback = avr_output_data_section_asm_op;
   bss_section->unnamed.callback = avr_output_bss_section_asm_op;
 }
@@ -10012,10 +10026,10 @@ avr_asm_init_sections (void)
 static void
 avr_asm_named_section (const char *name, unsigned int flags, tree decl)
 {
+  const char *old_prefix = ".rodata";
   if (flags & AVR_SECTION_PROGMEM)
     {
       addr_space_t as = (flags & AVR_SECTION_PROGMEM) / SECTION_MACH_DEP;
-      const char *old_prefix = ".rodata";
       const char *new_prefix = avr_addrspace[as].section_name;
 
       if (STR_PREFIX_P (name, old_prefix))
@@ -10029,6 +10043,14 @@ avr_asm_named_section (const char *name, unsigned int flags, tree decl)
       default_elf_asm_named_section (new_prefix, flags, decl);
       return;
     }
+  else if (STR_PREFIX_P(name, old_prefix) && TARGET_FLASH_RODATA)
+    {
+      const char *new_prefix = ".rodataFlash";
+      const char *sname = ACONCAT ((new_prefix,
+                                    name + strlen (old_prefix), NULL));
+      default_elf_asm_named_section (sname, flags, decl);
+      return;
+    }
 
   if (!avr_need_copy_data_p)
     avr_need_copy_data_p = (STR_PREFIX_P (name, ".data")
@@ -10271,6 +10293,21 @@ avr_asm_select_section (tree decl, int reloc, unsigned HOST_WIDE_INT align)
 
       return progmem_section[as];
     }
+  else if (sect->named.name)
+    {
+      const char * name = sect->named.name;
+      const char * old_prefix = ".rodata";
+      const char * new_prefix = ".rodataFlash";
+
+      if (STR_PREFIX_P (name, old_prefix))
+        {
+          const char *sname = ACONCAT ((new_prefix,
+                                        name + strlen (old_prefix), NULL));
+          return get_section (sname,
+                              sect->common.flags & ~SECTION_DECLARED,
+                              sect->named.decl);
+        }
+    }
 
   return sect;
 }
diff --git a/gcc/config/avr/avr.h b/gcc/config/avr/avr.h
index 3dfa8c3..7d4c8fb 100644
--- a/gcc/config/avr/avr.h
+++ b/gcc/config/avr/avr.h
@@ -382,6 +382,9 @@ typedef struct avr_args
 
 #define BSS_SECTION_ASM_OP "\t.section .bss"
 
+#undef READONLY_DATA_SECTION_ASM_OP
+#define READONLY_DATA_SECTION_ASM_OP	(TARGET_FLASH_RODATA ? "\t.section .rodataFlash, \"a\",@progbits" : "\t.section .rodata")
+
 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
    There are no shared libraries on this target, and these sections are
    placed in the read-only program memory, so they are not writable.  */
diff --git a/gcc/config/avr/avr.opt b/gcc/config/avr/avr.opt
index a1edec9..5442931 100644
--- a/gcc/config/avr/avr.opt
+++ b/gcc/config/avr/avr.opt
@@ -66,6 +66,10 @@ mtiny-stack
 Target Report Mask(TINY_STACK)
 Change only the low 8 bits of the stack pointer.
 
+mflash-rodata
+Target Report Mask(FLASH_RODATA)
+Keep the rodata in flash and generate code accordingly.
+
 mrelax
 Target Report
 Relax branches.
diff --git a/gcc/config/avr/t-avr b/gcc/config/avr/t-avr
index e725d58..f7024cb 100644
--- a/gcc/config/avr/t-avr
+++ b/gcc/config/avr/t-avr
@@ -97,6 +97,7 @@ install-device-specs: s-device-specs installdirs
 
 s-mlib: $(srcdir)/config/avr/t-multilib
 
-$(srcdir)/config/avr/t-multilib: $(srcdir)/config/avr/genmultilib.awk \
-				 $(AVR_MCUS)
-	$(AWK) -f $< -v FORMAT=Makefile   $< $(AVR_MCUS) > $@
+#$(srcdir)/config/avr/t-multilib: $(srcdir)/config/avr/genmultilib.awk \
+#				 $(AVR_MCUS)
+#	$(AWK) -f $< -v FORMAT=Makefile   $< $(AVR_MCUS) > $@
+
diff --git a/gcc/config/avr/t-multilib b/gcc/config/avr/t-multilib
index 8389422..d29e98a 100644
--- a/gcc/config/avr/t-multilib
+++ b/gcc/config/avr/t-multilib
@@ -21,21 +21,31 @@
 # along with GCC; see the file COPYING3.  If not see
 # <http://www.gnu.org/licenses/>.
 
-MULTILIB_OPTIONS = mmcu=avr2/mmcu=avr25/mmcu=avr3/mmcu=avr31/mmcu=avr35/mmcu=avr4/mmcu=avr5/mmcu=avr51/mmcu=avr6/mmcu=avrxmega2/mmcu=avrxmega4/mmcu=avrxmega5/mmcu=avrxmega6/mmcu=avrxmega7/mmcu=avrtiny msp8
+MULTI_ARCH_OPTIONS = mmcu=avr2/mmcu=avr25/mmcu=avr3/mmcu=avr31/mmcu=avr35/mmcu=avr4/mmcu=avr5/mmcu=avr51/mmcu=avr6/mmcu=avrxmega2/mmcu=avrxmega4/mmcu=avrxmega5/mmcu=avrxmega6/mmcu=avrxmega7/mmcu=avrtiny
+MULTI_ARCH_DIRNAMES = avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 avrtiny
 
-MULTILIB_DIRNAMES =  avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 avrtiny tiny-stack avr25/tiny-stack
+MULTI_FEATURE_OPTIONS = msp8/mflash-rodata
+MULTI_FEATURE_DIRNAMES = tiny-stack flash-rodata
+
+MULTILIB_REQUIRED += *mmcu=avr2
+MULTILIB_REQUIRED += *mmcu=avr2/msp8
+MULTILIB_REQUIRED += *mmcu=avr25
+MULTILIB_REQUIRED += *mmcu=avr25/msp8
+MULTILIB_REQUIRED += *mmcu=avr3
+MULTILIB_REQUIRED += *mmcu=avr31
+MULTILIB_REQUIRED += *mmcu=avr35
+MULTILIB_REQUIRED += *mmcu=avr4
+MULTILIB_REQUIRED += *mmcu=avr5
+MULTILIB_REQUIRED += *mmcu=avr51
+MULTILIB_REQUIRED += *mmcu=avr6
+MULTILIB_REQUIRED += *mmcu=avrxmega2
+MULTILIB_REQUIRED += *mmcu=avrxmega2/mflash-rodata
+MULTILIB_REQUIRED += *mmcu=avrxmega4
+MULTILIB_REQUIRED += *mmcu=avrxmega5
+MULTILIB_REQUIRED += *mmcu=avrxmega6
+MULTILIB_REQUIRED += *mmcu=avrxmega7
+MULTILIB_REQUIRED += *mmcu=avrtiny
+
+MULTILIB_OPTIONS       = $(MULTI_ARCH_OPTIONS) $(MULTI_FEATURE_OPTIONS)
+MULTILIB_DIRNAMES      = $(MULTI_ARCH_DIRNAMES) $(MULTI_FEATURE_DIRNAMES)
 
-MULTILIB_EXCEPTIONS = \
-	mmcu=avr3/msp8 \
-	mmcu=avr31/msp8 \
-	mmcu=avr35/msp8 \
-	mmcu=avr4/msp8 \
-	mmcu=avr5/msp8 \
-	mmcu=avr51/msp8 \
-	mmcu=avr6/msp8 \
-	mmcu=avrxmega2/msp8 \
-	mmcu=avrxmega4/msp8 \
-	mmcu=avrxmega5/msp8 \
-	mmcu=avrxmega6/msp8 \
-	mmcu=avrxmega7/msp8 \
-	mmcu=avrtiny/msp8

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