[PATCH 1/2] AVR: Only set link-relax elf flag when appropriate.

Andrew Burgess andrew.burgess@embecosm.com
Fri Dec 5 22:21:00 GMT 2014


The AVR target uses a bit in the elf header flags to indicate if the
object was assembled ready for linker relaxation.  Previously this flag
was always set, even when the object was not assembled ready for linker
relaxation.

This patch moves setting of the flag into the assembler, and sets it
only when the assembler is preparing the file for linker relaxation.

bfd/ChangeLog:

	* elf32-avr.c (bfd_elf_avr_final_write_processing): Don't set
	EF_AVR_LINKRELAX_PREPARED unconditionally.

gas/ChangeLog:

	* 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.
	(avr_elf_final_processing): Declare

gas/testsuite/ChangeLog:

	* 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.
---
 bfd/ChangeLog                                     |  5 +++++
 bfd/elf32-avr.c                                   |  1 -
 gas/ChangeLog                                     | 10 ++++++++++
 gas/config/tc-avr.c                               |  9 ++++++++-
 gas/config/tc-avr.h                               |  3 +++
 gas/testsuite/ChangeLog                           |  6 ++++++
 gas/testsuite/gas/avr/link-relax-elf-flag-clear.d | 10 ++++++++++
 gas/testsuite/gas/avr/link-relax-elf-flag-set.d   |  9 +++++++++
 gas/testsuite/gas/avr/link-relax-elf-flag.s       |  4 ++++
 9 files changed, 55 insertions(+), 2 deletions(-)
 create mode 100644 gas/testsuite/gas/avr/link-relax-elf-flag-clear.d
 create mode 100644 gas/testsuite/gas/avr/link-relax-elf-flag-set.d
 create mode 100644 gas/testsuite/gas/avr/link-relax-elf-flag.s

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index d1c86da..48c8683 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-05  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+	* elf32-avr.c (bfd_elf_avr_final_write_processing): Don't set
+	EF_AVR_LINKRELAX_PREPARED unconditionally.
+
 2014-12-05  Steve Ellcey  <sellcey@mips.com>
 
 	* ecoff.c (_bfd_ecoff_slurp_symbol_table): Add cast.
diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c
index 5aa3cf6..827de7f 100644
--- a/bfd/elf32-avr.c
+++ b/bfd/elf32-avr.c
@@ -1518,7 +1518,6 @@ bfd_elf_avr_final_write_processing (bfd *abfd,
   elf_elfheader (abfd)->e_machine = EM_AVR;
   elf_elfheader (abfd)->e_flags &= ~ EF_AVR_MACH;
   elf_elfheader (abfd)->e_flags |= val;
-  elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
 }
 
 /* Set the right machine number.  */
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 3508468..c62cd67 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,13 @@
+2014-12-05  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.
+	(avr_elf_final_processing): Declare
+	* testsuite/gas/avr/link-relax-elf-flag-clear.d: New file.
+	* testsuite/gas/avr/link-relax-elf-flag-set.d: New file.
+	* testsuite/gas/avr/link-relax-elf-flag.s: New file.
+
 2014-11-28  Sandra Loosemore  <sandra@codesourcery.com>
 
 	* config/tc-nios2.c (can_evaluate_expr, get_expr_value): Delete.
diff --git a/gas/config/tc-avr.c b/gas/config/tc-avr.c
index dfe66c6..bda0bd6 100644
--- a/gas/config/tc-avr.c
+++ b/gas/config/tc-avr.c
@@ -25,7 +25,7 @@
 #include "subsegs.h"
 #include "dwarf2dbg.h"
 #include "dw2gencfi.h"
-
+#include "elf/avr.h"
 
 struct avr_opcodes_s
 {
@@ -1848,3 +1848,10 @@ avr_allow_local_subtract (expressionS * left,
      them.  */
   return FALSE;
 }
+
+void
+avr_elf_final_processing (void)
+{
+  if (linkrelax)
+    elf_elfheader (stdoutput)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
+}
diff --git a/gas/config/tc-avr.h b/gas/config/tc-avr.h
index fb596ad..81ba0fc 100644
--- a/gas/config/tc-avr.h
+++ b/gas/config/tc-avr.h
@@ -213,3 +213,6 @@ extern void tc_cfi_frame_initial_instructions (void);
    relaxation, so do not resolve such expressions in the assembler.  */
 #define md_allow_local_subtract(l,r,s) avr_allow_local_subtract (l, r, s)
 extern bfd_boolean avr_allow_local_subtract (expressionS *, expressionS *, segT);
+
+#define elf_tc_final_processing 	avr_elf_final_processing
+extern void avr_elf_final_processing (void);
diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog
index 5903720..4966216 100644
--- a/gas/testsuite/ChangeLog
+++ b/gas/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2014-12-05  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.
+
 2014-11-30  Alan Modra  <amodra@gmail.com>
 
 	* gas/ppc/a2.d: Update for mftb change.
diff --git a/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d b/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d
new file mode 100644
index 0000000..88cd3c9
--- /dev/null
+++ b/gas/testsuite/gas/avr/link-relax-elf-flag-clear.d
@@ -0,0 +1,10 @@
+#name: AVR, check elf link-relax header flag is clear.
+#as: -mmcu=avrxmega2
+#readelf: -h
+#source: link-relax-elf-flag.s
+#target: avr-*-*
+
+ELF Header:
+#...
+  Flags:                             0x66, avr:102
+#...
\ No newline at end of file
diff --git a/gas/testsuite/gas/avr/link-relax-elf-flag-set.d b/gas/testsuite/gas/avr/link-relax-elf-flag-set.d
new file mode 100644
index 0000000..bde4b25
--- /dev/null
+++ b/gas/testsuite/gas/avr/link-relax-elf-flag-set.d
@@ -0,0 +1,9 @@
+#name: AVR, check elf link-relax header flag is set.
+#as: -mlink-relax -mmcu=avrxmega2
+#readelf: -h
+#source: link-relax-elf-flag.s
+#target: avr-*-*
+
+#...
+  Flags:                             0xe6, avr:102, link-relax
+#...
diff --git a/gas/testsuite/gas/avr/link-relax-elf-flag.s b/gas/testsuite/gas/avr/link-relax-elf-flag.s
new file mode 100644
index 0000000..af543e1
--- /dev/null
+++ b/gas/testsuite/gas/avr/link-relax-elf-flag.s
@@ -0,0 +1,4 @@
+        .text
+        .global _start
+_start:
+        nop
-- 
1.9.3



More information about the Binutils mailing list