[PATCH 1/2] AVR: Assembler now prepares for linker relaxation by default.

Andrew Burgess andrew.burgess@embecosm.com
Tue Dec 23 17:57:00 GMT 2014


Have the assembler prepare for linker relaxation by default.  This
means that users will be able to make use of linker relaxation without
having to adjust the assembler flags, this can make life easier when
compiling libraries.

Having this on by default in the assembler should make no difference to
the assembler code produced, however, some of the debug information will
be slightly less compressed.

A few tests needed to be updated as a result of this change as they
relied on linker relaxation support being off by default.

I've tightened up the definition of which sections can be relaxed on AVR
as part of this commit, the assembler used to think that all
non-debugging sections could be relaxed, when in reality only code
sections can be relaxed for AVR.  The previous definition was not
dangerous, just over cautious.  The new tighter definition allows an
extra test (gas/testsuite/gas/all/forward.d) to continue to pass.

gas/ChangeLog:

	* config/tc-avr.c (struct avr_opt_s): Change link_relax to
	no_link_relax, extend comment.
	(enum options): Add new OPTION_NO_LINK_RELAX.
	(md_longopts): Add entry for -mno-link-relax.
	(md_parse_option): Handle OPTION_NO_LINK_RELAX, and update
	OPTION_LINK_RELAX.
	(md_begin): Initialise linkrelax from no_link_relax.
	(md_show_usage): Include -mno-link-relax option.
	(relaxable_section): Only allocatable code sections can be
	relaxed.
	* config/tc-avr.h (TC_LINKRELAX_FIXUP): Define.

gas/testsuite/ChangeLog:

	* gas/all/gas.exp: Test will not pass on AVR due to linker
	relaxation support.
	* gas/avr/noreloc_withoutrelax.d: Add -mno-link-relax option.
	* gas/avr/link-relax-elf-flag-clear.d: Likewise.

ld/testsuite/ChangeLog:

	* ld/testsuite/ld-avr/relax-elf-flags-02.d: Add -mno-link-relax
	option.
	* ld/testsuite/ld-avr/relax-elf-flags-03.d: Likewise.
	* ld/testsuite/ld-avr/relax-elf-flags-04.d: Likewise.
	* ld/testsuite/ld-avr/relax-elf-flags-05.d: Likewise.
	* ld/testsuite/ld-avr/relax-elf-flags-06.d: Likewise.
---
 gas/ChangeLog                                     | 13 ++++++++++++
 gas/config/tc-avr.c                               | 24 +++++++++++++++--------
 gas/testsuite/ChangeLog                           |  7 +++++++
 gas/testsuite/gas/all/gas.exp                     |  3 ++-
 gas/testsuite/gas/avr/link-relax-elf-flag-clear.d |  2 +-
 gas/testsuite/gas/avr/noreloc_withoutrelax.d      |  2 +-
 ld/testsuite/ChangeLog                            |  9 +++++++++
 ld/testsuite/ld-avr/relax-elf-flags-02.d          |  2 +-
 ld/testsuite/ld-avr/relax-elf-flags-03.d          |  2 +-
 ld/testsuite/ld-avr/relax-elf-flags-04.d          |  4 ++--
 ld/testsuite/ld-avr/relax-elf-flags-05.d          |  4 ++--
 ld/testsuite/ld-avr/relax-elf-flags-06.d          |  2 +-
 12 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index d5c489a..136a3ff 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,5 +1,18 @@
 2014-12-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* config/tc-avr.c (struct avr_opt_s): Change link_relax to
+	no_link_relax, extend comment.
+	(enum options): Add new OPTION_NO_LINK_RELAX.
+	(md_longopts): Add entry for -mno-link-relax.
+	(md_parse_option): Handle OPTION_NO_LINK_RELAX, and update
+	OPTION_LINK_RELAX.
+	(md_begin): Initialise linkrelax from no_link_relax.
+	(md_show_usage): Include -mno-link-relax option.
+	(relaxable_section): Only allocatable code sections can be
+	relaxed.
+
+2014-12-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* config/tc-avr.c: Add include for elf/avr.h.
 	(avr_elf_final_processing): New function.
 	* config/tc-avr.h (elf_tc_final_processing): Define.
diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c
index bda0bd6..79560ac 100644
--- a/gas/config/tc-avr.c
+++ b/gas/config/tc-avr.c
@@ -345,8 +345,8 @@ struct avr_opt_s
   int all_opcodes;  /* -mall-opcodes: accept all known AVR opcodes.  */
   int no_skip_bug;  /* -mno-skip-bug: no warnings for skipping 2-word insns.  */
   int no_wrap;      /* -mno-wrap: reject rjmp/rcall with 8K wrap-around.  */
-  int link_relax;   /* -mlink-relax: generate relocations for linker
-                       relaxation.  */
+  int no_link_relax;   /* -mno-link-relax / -mlink-relax: generate (or not)
+                          relocations for linker relaxation.  */
 };
 
 static struct avr_opt_s avr_opt = { 0, 0, 0, 0 };
@@ -411,7 +411,8 @@ enum options
   OPTION_NO_SKIP_BUG,
   OPTION_NO_WRAP,
   OPTION_ISA_RMW,
-  OPTION_LINK_RELAX
+  OPTION_LINK_RELAX,
+  OPTION_NO_LINK_RELAX
 };
 
 struct option md_longopts[] =
@@ -422,6 +423,7 @@ struct option md_longopts[] =
   { "mno-wrap",     no_argument, NULL, OPTION_NO_WRAP     },
   { "mrmw",         no_argument, NULL, OPTION_ISA_RMW     },
   { "mlink-relax",  no_argument, NULL, OPTION_LINK_RELAX  },
+  { "mno-link-relax",  no_argument, NULL, OPTION_NO_LINK_RELAX  },
   { NULL, no_argument, NULL, 0 }
 };
 
@@ -528,8 +530,9 @@ md_show_usage (FILE *stream)
 	"  -mno-wrap        reject rjmp/rcall instructions with 8K wrap-around\n"
 	"                   (default for avr3, avr5)\n"
 	"  -mrmw            accept Read-Modify-Write instructions\n"
-    "  -mlink-relax     generate relocations for linker relaxation\n"
-    ));
+	"  -mlink-relax     generate relocations for linker relaxation (default)\n"
+	"  -mno-link-relax  don't generate relocations for linker relaxation.\n"
+        ));
   show_mcu_list (stream);
 }
 
@@ -600,7 +603,10 @@ md_parse_option (int c, char *arg)
       specified_mcu.isa |= AVR_ISA_RMW;
       return 1;
     case OPTION_LINK_RELAX:
-      avr_opt.link_relax = 1;
+      avr_opt.no_link_relax = 0;
+      return 1;
+    case OPTION_NO_LINK_RELAX:
+      avr_opt.no_link_relax = 1;
       return 1;
     }
 
@@ -652,7 +658,7 @@ md_begin (void)
     }
 
   bfd_set_arch_mach (stdoutput, TARGET_ARCH, avr_mcu->mach);
-  linkrelax = avr_opt.link_relax;
+  linkrelax = !avr_opt.no_link_relax;
 }
 
 /* Resolve STR as a constant expression and return the result.
@@ -1239,7 +1245,9 @@ md_pcrel_from_section (fixS *fixp, segT sec)
 static bfd_boolean
 relaxable_section (asection *sec)
 {
-  return (sec->flags & SEC_DEBUGGING) == 0;
+  return ((sec->flags & SEC_DEBUGGING) == 0
+          && (sec->flags & SEC_CODE) != 0
+          && (sec->flags & SEC_ALLOC) != 0);
 }
 
 /* Does whatever the xtensa port does.  */
diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog
index d6d6450..9121f46 100644
--- a/gas/testsuite/ChangeLog
+++ b/gas/testsuite/ChangeLog
@@ -1,5 +1,12 @@
 2014-12-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* gas/all/gas.exp: Test will not pass on AVR due to linker
+	relaxation support.
+	* gas/avr/noreloc_withoutrelax.d: Add -mno-link-relax option.
+	* gas/avr/link-relax-elf-flag-clear.d: Likewise.
+
+2014-12-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* gas/avr/link-relax-elf-flag-clear.d: New file.
 	* gas/avr/link-relax-elf-flag-set.d: New file.
 	* gas/avr/link-relax-elf-flag.s: New file.
diff --git a/gas/testsuite/gas/all/gas.exp b/gas/testsuite/gas/all/gas.exp
index 8fa89e4..6002def 100644
--- a/gas/testsuite/gas/all/gas.exp
+++ b/gas/testsuite/gas/all/gas.exp
@@ -55,9 +55,10 @@ if { ![istarget cris-*-*] && ![istarget crisv32-*-*]
 # The MN10300 port supports link time relaxation which in turn allows
 # for link time resolution of the differneces of two symbols which are
 # undefined at assembly time.  Hence this test will not pass for the
-# MN10300.  The same thing is true for the RX port as well.
+# MN10300.  The same thing is true for the RX and AVR port as well.
 if { ![istarget hppa*-*-*]
      && ![istarget alpha*-*-*vms*]
+     && ![istarget avr-*-*]
      && ![istarget rx-*-*]
      && ![istarget mn10300-*-*]
      && ![istarget msp430*-*-*]
diff --git a/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d b/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d
index 88cd3c9..e7ef22c 100644
--- a/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d
+++ b/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d
@@ -1,5 +1,5 @@
 #name: AVR, check elf link-relax header flag is clear.
-#as: -mmcu=avrxmega2
+#as: -mno-link-relax -mmcu=avrxmega2
 #readelf: -h
 #source: link-relax-elf-flag.s
 #target: avr-*-*
diff --git a/gas/testsuite/gas/avr/noreloc_withoutrelax.d b/gas/testsuite/gas/avr/noreloc_withoutrelax.d
index daaaeb2..7ec7d32 100644
--- a/gas/testsuite/gas/avr/noreloc_withoutrelax.d
+++ b/gas/testsuite/gas/avr/noreloc_withoutrelax.d
@@ -1,5 +1,5 @@
 #name: AVR no DIFF relocs without link relax
-#as: -mmcu=avrxmega2
+#as: -mmcu=avrxmega2 -mno-link-relax
 #objdump: -r
 #source: relax.s
 #target: avr-*-*
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index fdef038..4f0db34 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,5 +1,14 @@
 2014-12-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* ld/testsuite/ld-avr/relax-elf-flags-02.d: Add -mno-link-relax
+	option.
+	* ld/testsuite/ld-avr/relax-elf-flags-03.d: Likewise.
+	* ld/testsuite/ld-avr/relax-elf-flags-04.d: Likewise.
+	* ld/testsuite/ld-avr/relax-elf-flags-05.d: Likewise.
+	* ld/testsuite/ld-avr/relax-elf-flags-06.d: Likewise.
+
+2014-12-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* ld-avr/relax-elf-flags-01.d: New file.
 	* ld-avr/relax-elf-flags-02.d: New file.
 	* ld-avr/relax-elf-flags-03.d: New file.
diff --git a/ld/testsuite/ld-avr/relax-elf-flags-02.d b/ld/testsuite/ld-avr/relax-elf-flags-02.d
index 6a008bd..c4d7660 100644
--- a/ld/testsuite/ld-avr/relax-elf-flags-02.d
+++ b/ld/testsuite/ld-avr/relax-elf-flags-02.d
@@ -1,7 +1,7 @@
 #name: AVR, check link-relax flag is clear on partial link (first file)
 #as: -mmcu=avrxmega2
 #ld: -r -mavrxmega2
-#source: relax-elf-flags-a.s
+#source: relax-elf-flags-a.s -mno-link-relax
 #source: relax-elf-flags-b.s -mlink-relax
 #readelf: -h
 #target: avr-*-*
diff --git a/ld/testsuite/ld-avr/relax-elf-flags-03.d b/ld/testsuite/ld-avr/relax-elf-flags-03.d
index 3d2a70d..c75c1df 100644
--- a/ld/testsuite/ld-avr/relax-elf-flags-03.d
+++ b/ld/testsuite/ld-avr/relax-elf-flags-03.d
@@ -2,7 +2,7 @@
 #as: -mmcu=avrxmega2
 #ld: -r -mavrxmega2
 #source: relax-elf-flags-a.s -mlink-relax
-#source: relax-elf-flags-b.s
+#source: relax-elf-flags-b.s -mno-link-relax
 #readelf: -h
 #target: avr-*-*
 
diff --git a/ld/testsuite/ld-avr/relax-elf-flags-04.d b/ld/testsuite/ld-avr/relax-elf-flags-04.d
index e2a9bb6..8fa4574 100644
--- a/ld/testsuite/ld-avr/relax-elf-flags-04.d
+++ b/ld/testsuite/ld-avr/relax-elf-flags-04.d
@@ -1,8 +1,8 @@
 #name: AVR, check link-relax flag is clear on partial link (both files)
 #as: -mmcu=avrxmega2
 #ld: -r -mavrxmega2
-#source: relax-elf-flags-a.s
-#source: relax-elf-flags-b.s
+#source: relax-elf-flags-a.s -mno-link-relax
+#source: relax-elf-flags-b.s -mno-link-relax
 #readelf: -h
 #target: avr-*-*
 
diff --git a/ld/testsuite/ld-avr/relax-elf-flags-05.d b/ld/testsuite/ld-avr/relax-elf-flags-05.d
index 8c41e8d..de62bbb 100644
--- a/ld/testsuite/ld-avr/relax-elf-flags-05.d
+++ b/ld/testsuite/ld-avr/relax-elf-flags-05.d
@@ -1,8 +1,8 @@
 #name: AVR, check link-relax flag is set final link (no inputs relaxable)
 #as: -mmcu=avrxmega2
 #ld: -relax -mavrxmega2
-#source: relax-elf-flags-a.s
-#source: relax-elf-flags-b.s
+#source: relax-elf-flags-a.s -mno-link-relax
+#source: relax-elf-flags-b.s -mno-link-relax
 #readelf: -h
 #target: avr-*-*
 
diff --git a/ld/testsuite/ld-avr/relax-elf-flags-06.d b/ld/testsuite/ld-avr/relax-elf-flags-06.d
index 5d8e3c1..5a8e810 100644
--- a/ld/testsuite/ld-avr/relax-elf-flags-06.d
+++ b/ld/testsuite/ld-avr/relax-elf-flags-06.d
@@ -2,7 +2,7 @@
 #as: -mmcu=avrxmega2
 #ld: -relax -mavrxmega2
 #source: relax-elf-flags-a.s -mlink-relax
-#source: relax-elf-flags-b.s
+#source: relax-elf-flags-b.s -mno-link-relax
 #readelf: -h
 #target: avr-*-*
 
-- 
1.9.3



More information about the Binutils mailing list