binutils/binutils: fixup version strings
author"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Sep 11 18:18:53 2011 +0200 (2011-09-11)
changeset 2664346263a07115
parent 2663 7179903f8d2e
child 2665 5b7e91ec300c
binutils/binutils: fixup version strings

Recently, all binutils versions have been renamed after a GPL compliance
issue was found and fixed in binutils;
http://sourceware.org/ml/binutils/2011-08/msg00198.html

Although legacy symlinks have been put in place, we should now use
the new, real version strings.

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
config/binutils/binutils.in
patches/binutils/2.16.1/100-bfd-hash-tweak.patch
patches/binutils/2.16.1/110-psignal.patch
patches/binutils/2.16.1/120-skip-comments.patch
patches/binutils/2.16.1/130-callahan.patch
patches/binutils/2.16.1/140-cross-gprof.patch
patches/binutils/2.16.1/150-stabs-tweak.patch
patches/binutils/2.16.1/160-i386-no-divide-comment.patch
patches/binutils/2.16.1a/100-bfd-hash-tweak.patch
patches/binutils/2.16.1a/110-psignal.patch
patches/binutils/2.16.1a/120-skip-comments.patch
patches/binutils/2.16.1a/130-callahan.patch
patches/binutils/2.16.1a/140-cross-gprof.patch
patches/binutils/2.16.1a/150-stabs-tweak.patch
patches/binutils/2.16.1a/160-i386-no-divide-comment.patch
patches/binutils/2.17/100-uclibc-conf.patch
patches/binutils/2.17/110-arm-eabi-conf.patch
patches/binutils/2.17/120-makeinfo-version.patch
patches/binutils/2.17/130-ld_makefile_patch.patch
patches/binutils/2.17/140-better_file_error.patch
patches/binutils/2.17/150-check_ldrunpath_length.patch
patches/binutils/2.17/160-mips-ELF_MAXPAGESIZE-4K.patch
patches/binutils/2.17/170-bfd-hash-tweak.patch
patches/binutils/2.17/180-psignal.patch
patches/binutils/2.17/190-skip-comments.patch
patches/binutils/2.17/200-cross-gprof.patch
patches/binutils/2.17/210-i386-no-divide-comment.patch
patches/binutils/2.17a/100-uclibc-conf.patch
patches/binutils/2.17a/110-arm-eabi-conf.patch
patches/binutils/2.17a/120-makeinfo-version.patch
patches/binutils/2.17a/130-ld_makefile_patch.patch
patches/binutils/2.17a/140-better_file_error.patch
patches/binutils/2.17a/150-check_ldrunpath_length.patch
patches/binutils/2.17a/160-mips-ELF_MAXPAGESIZE-4K.patch
patches/binutils/2.17a/170-bfd-hash-tweak.patch
patches/binutils/2.17a/180-psignal.patch
patches/binutils/2.17a/190-skip-comments.patch
patches/binutils/2.17a/200-cross-gprof.patch
patches/binutils/2.17a/210-i386-no-divide-comment.patch
patches/binutils/2.18/100-makeinfo-version.patch
patches/binutils/2.18/110-enable-dash-v2.patch
patches/binutils/2.18/120-i386-no-divide-comment.patch
patches/binutils/2.18/130-avr32-atmel-v1.0.1.patch
patches/binutils/2.18a/100-makeinfo-version.patch
patches/binutils/2.18a/110-enable-dash-v2.patch
patches/binutils/2.18a/120-i386-no-divide-comment.patch
patches/binutils/2.18a/130-avr32-atmel-v1.0.1.patch
patches/binutils/2.19.1/100-ppc64-pie.patch
patches/binutils/2.19.1/110-RPATH_ENVVAR-smack.patch
patches/binutils/2.19.1/120-sh-targets.patch
patches/binutils/2.19.1/130-check_ldrunpath_length.patch
patches/binutils/2.19.1/140-pt-pax-flags-20081101.patch
patches/binutils/2.19.1/150-warn-textrel.patch
patches/binutils/2.19.1/160-use-new-ld-dtags.patch
patches/binutils/2.19.1/170-use-relro.patch
patches/binutils/2.19.1/180-libiberty-pic.patch
patches/binutils/2.19.1/190-mips64-defaultemul.patch
patches/binutils/2.19.1a/100-ppc64-pie.patch
patches/binutils/2.19.1a/110-RPATH_ENVVAR-smack.patch
patches/binutils/2.19.1a/120-sh-targets.patch
patches/binutils/2.19.1a/130-check_ldrunpath_length.patch
patches/binutils/2.19.1a/140-pt-pax-flags-20081101.patch
patches/binutils/2.19.1a/150-warn-textrel.patch
patches/binutils/2.19.1a/160-use-new-ld-dtags.patch
patches/binutils/2.19.1a/170-use-relro.patch
patches/binutils/2.19.1a/180-libiberty-pic.patch
patches/binutils/2.19.1a/190-mips64-defaultemul.patch
patches/binutils/2.20.1/100-ppc64-pie.patch
patches/binutils/2.20.1/110-RPATH_ENVVAR-smack.patch
patches/binutils/2.20.1/120-sh-targets.patch
patches/binutils/2.20.1/130-ld-sysroot.patch
patches/binutils/2.20.1/140-check_ldrunpath_length.patch
patches/binutils/2.20.1/150-pt-pax-flags-20090909.patch
patches/binutils/2.20.1/160-amd64-32bit-path.patch
patches/binutils/2.20.1/170-warn-textrel.patch
patches/binutils/2.20.1/190-use-new-ld-dtags.patch
patches/binutils/2.20.1/200-document-new-dtags-behaviour.patch
patches/binutils/2.20.1/220-use-relro.patch
patches/binutils/2.20.1/230-libiberty-pic.patch
patches/binutils/2.20.1/240-ld_makefile.patch
patches/binutils/2.20.1/250-arm-eabi-conf.patch
patches/binutils/2.20.1/270-better_file_error.patch
patches/binutils/2.20.1/280-unexport_LD_LIBRARY_PATH.patch
patches/binutils/2.20.1/290-ld-stub-crash.patch
patches/binutils/2.20.1/300-mips64-defaultemul.patch
patches/binutils/2.20.1a/100-ppc64-pie.patch
patches/binutils/2.20.1a/110-RPATH_ENVVAR-smack.patch
patches/binutils/2.20.1a/120-sh-targets.patch
patches/binutils/2.20.1a/130-ld-sysroot.patch
patches/binutils/2.20.1a/140-check_ldrunpath_length.patch
patches/binutils/2.20.1a/150-pt-pax-flags-20090909.patch
patches/binutils/2.20.1a/160-amd64-32bit-path.patch
patches/binutils/2.20.1a/170-warn-textrel.patch
patches/binutils/2.20.1a/190-use-new-ld-dtags.patch
patches/binutils/2.20.1a/200-document-new-dtags-behaviour.patch
patches/binutils/2.20.1a/220-use-relro.patch
patches/binutils/2.20.1a/230-libiberty-pic.patch
patches/binutils/2.20.1a/240-ld_makefile.patch
patches/binutils/2.20.1a/250-arm-eabi-conf.patch
patches/binutils/2.20.1a/270-better_file_error.patch
patches/binutils/2.20.1a/280-unexport_LD_LIBRARY_PATH.patch
patches/binutils/2.20.1a/290-ld-stub-crash.patch
patches/binutils/2.20.1a/300-mips64-defaultemul.patch
     1.1 --- a/config/binutils/binutils.in	Sun Sep 11 18:26:12 2011 +0200
     1.2 +++ b/config/binutils/binutils.in	Sun Sep 11 18:18:53 2011 +0200
     1.3 @@ -8,29 +8,29 @@
     1.4  # Don't remove next line
     1.5  # CT_INSERT_VERSION_BELOW
     1.6  
     1.7 -config BINUTILS_V_2_20_1
     1.8 +config BINUTILS_V_2_20_1a
     1.9      bool
    1.10 -    prompt "2.20.1"
    1.11 +    prompt "2.20.1a"
    1.12      select BINUTILS_2_20_or_later
    1.13  
    1.14 -config BINUTILS_V_2_19_1
    1.15 +config BINUTILS_V_2_19_1a
    1.16      bool
    1.17 -    prompt "2.19.1"
    1.18 +    prompt "2.19.1a"
    1.19      select BINUTILS_2_19_or_later
    1.20  
    1.21 -config BINUTILS_V_2_18
    1.22 +config BINUTILS_V_2_18a
    1.23      bool
    1.24 -    prompt "2.18"
    1.25 +    prompt "2.18a"
    1.26      select BINUTILS_2_18_or_later
    1.27  
    1.28 -config BINUTILS_V_2_17
    1.29 +config BINUTILS_V_2_17a
    1.30      bool
    1.31 -    prompt "2.17 (OBSOLETE)"
    1.32 +    prompt "2.17a (OBSOLETE)"
    1.33      depends on OBSOLETE
    1.34  
    1.35 -config BINUTILS_V_2_16_1
    1.36 +config BINUTILS_V_2_16_1a
    1.37      bool
    1.38 -    prompt "2.16.1 (OBSOLETE)"
    1.39 +    prompt "2.16.1a (OBSOLETE)"
    1.40      depends on OBSOLETE
    1.41  
    1.42  endchoice
    1.43 @@ -39,11 +39,11 @@
    1.44      string
    1.45  # Don't remove next line
    1.46  # CT_INSERT_VERSION_STRING_BELOW
    1.47 -    default "2.20.1" if BINUTILS_V_2_20_1
    1.48 -    default "2.19.1" if BINUTILS_V_2_19_1
    1.49 -    default "2.18" if BINUTILS_V_2_18
    1.50 -    default "2.17" if BINUTILS_V_2_17
    1.51 -    default "2.16.1" if BINUTILS_V_2_16_1
    1.52 +    default "2.20.1a" if BINUTILS_V_2_20_1a
    1.53 +    default "2.19.1a" if BINUTILS_V_2_19_1a
    1.54 +    default "2.18a" if BINUTILS_V_2_18a
    1.55 +    default "2.17a" if BINUTILS_V_2_17a
    1.56 +    default "2.16.1a" if BINUTILS_V_2_16_1a
    1.57  
    1.58  config BINUTILS_2_21_or_later
    1.59      bool
     2.1 --- a/patches/binutils/2.16.1/100-bfd-hash-tweak.patch	Sun Sep 11 18:26:12 2011 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,23 +0,0 @@
     2.4 -Signed-off-by: dank@kegel.com
     2.5 -
     2.6 -Raising the size of the hash table is a noticable win when linking 
     2.7 -at least one large app.  
     2.8 -
     2.9 -There was a patch,
    2.10 -http://sources.redhat.com/ml/binutils/2004-06/msg00165.html
    2.11 -to do this dynamically.  No idea why that didn't make it in.
    2.12 -So this tiny change to raise the default size is just
    2.13 -a stopgap for now.
    2.14 -
    2.15 -
    2.16 ---- binutils-2.16.1/bfd/hash.c.old	2006-03-02 23:01:39.000000000 -0800
    2.17 -+++ binutils-2.16.1/bfd/hash.c	2006-03-02 23:01:58.000000000 -0800
    2.18 -@@ -300,7 +300,7 @@
    2.19 - */
    2.20 - 
    2.21 - /* The default number of entries to use when creating a hash table.  */
    2.22 --#define DEFAULT_SIZE 4051
    2.23 -+#define DEFAULT_SIZE 32749
    2.24 - static size_t bfd_default_hash_table_size = DEFAULT_SIZE;
    2.25 - 
    2.26 - /* Create a new hash table, given a number of entries.  */
     3.1 --- a/patches/binutils/2.16.1/110-psignal.patch	Sun Sep 11 18:26:12 2011 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,40 +0,0 @@
     3.4 -Make psignal prototype in libiberty match that in glibc.
     3.5 -
     3.6 -Fixes:
     3.7 -
     3.8 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c: In function `psignal':
     3.9 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `signo' doesn't match prototype
    3.10 -/usr/include/signal.h:131: prototype declaration
    3.11 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `message' doesn't match prototype
    3.12 -/usr/include/signal.h:131: prototype declaration
    3.13 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:568: warning: comparison between signed and unsigned
    3.14 -mprotect... make[1]: *** [strsignal.o] Error 1
    3.15 -make[1]: Leaving directory `/export/hda3/dkegel/queue/jobdir.produser_cpsm17/crosstool-0.32/build/i686-unknown-linux-gnu/gcc-2.95.3-glibc-2.1.3/build-binutils/libiberty'
    3.16 -make: *** [all-libiberty] Error 2
    3.17 -
    3.18 -when building on red hat 7.1
    3.19 -though it's a bit of a mystery why libiberty's psignal is being compiled at
    3.20 -all, since red hat 7.1's glibc supports psignal (hence the error message)
    3.21 -
    3.22 ---- binutils-2.15/libiberty/strsignal.c.old	2005-04-18 13:57:40.000000000 -0700
    3.23 -+++ binutils-2.15/libiberty/strsignal.c	2005-04-18 13:59:09.000000000 -0700
    3.24 -@@ -544,7 +544,7 @@
    3.25 - 
    3.26 - /*
    3.27 - 
    3.28 --@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
    3.29 -+@deftypefn Supplemental void psignal (int @var{signo}, const char *@var{message})
    3.30 - 
    3.31 - Print @var{message} to the standard error, followed by a colon,
    3.32 - followed by the description of the signal specified by @var{signo},
    3.33 -@@ -557,9 +557,7 @@
    3.34 - #ifndef HAVE_PSIGNAL
    3.35 - 
    3.36 - void
    3.37 --psignal (signo, message)
    3.38 --  unsigned signo;
    3.39 --  char *message;
    3.40 -+psignal (int signo, const char *message)
    3.41 - {
    3.42 -   if (signal_names == NULL)
    3.43 -     {
     4.1 --- a/patches/binutils/2.16.1/120-skip-comments.patch	Sun Sep 11 18:26:12 2011 +0200
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,95 +0,0 @@
     4.4 -[removed first hunk so it would apply to 2.16.1 - copyright date already updated - dank]
     4.5 -
     4.6 -Retrieved from http://sources.redhat.com/ml/binutils/2004-04/msg00646.html
     4.7 -Fixes
     4.8 -localealias.s:544: Error: junk at end of line, first unrecognized character is `,' 
     4.9 -when building glibc-2.3.2 with gcc-3.4.0 and binutils-2.15.90.0.3
    4.10 -
    4.11 -Paths adjusted to match crosstool's patcher.
    4.12 -
    4.13 -Message-Id: m3n052qw2g.fsf@whitebox.m5r.de
    4.14 -From: Andreas Schwab <schwab at suse dot de>
    4.15 -To: Nathan Sidwell <nathan at codesourcery dot com>
    4.16 -Cc: Ian Lance Taylor <ian at wasabisystems dot com>, binutils at sources dot redhat dot com
    4.17 -Date: Fri, 23 Apr 2004 22:27:19 +0200
    4.18 -Subject: Re: demand_empty_rest_of_line and ignore_rest_of_line
    4.19 -
    4.20 -Nathan Sidwell <nathan@codesourcery.com> writes:
    4.21 -
    4.22 -> Index: read.c
    4.23 -> ===================================================================
    4.24 -> RCS file: /cvs/src/src/gas/read.c,v
    4.25 -> retrieving revision 1.76
    4.26 -> diff -c -3 -p -r1.76 read.c
    4.27 -> *** read.c	12 Mar 2004 17:48:12 -0000	1.76
    4.28 -> --- read.c	18 Mar 2004 09:56:05 -0000
    4.29 -> *************** read_a_source_file (char *name)
    4.30 -> *** 1053,1059 ****
    4.31 ->   #endif
    4.32 ->   	  input_line_pointer--;
    4.33 ->   	  /* Report unknown char as ignored.  */
    4.34 -> ! 	  ignore_rest_of_line ();
    4.35 ->   	}
    4.36 ->   
    4.37 ->   #ifdef md_after_pass_hook
    4.38 -> --- 1053,1059 ----
    4.39 ->   #endif
    4.40 ->   	  input_line_pointer--;
    4.41 ->   	  /* Report unknown char as ignored.  */
    4.42 -> ! 	  demand_empty_rest_of_line ();
    4.43 ->   	}
    4.44 ->   
    4.45 ->   #ifdef md_after_pass_hook
    4.46 -
    4.47 -This means that the unknown character is no longer ignored, despite the
    4.48 -comment.  As a side effect a line starting with a line comment character
    4.49 -not followed by APP in NO_APP mode now triggers an error instead of just a
    4.50 -warning, breaking builds of glibc on m68k-linux.  Earlier in
    4.51 -read_a_source_file where #APP is handled there is another comment that
    4.52 -claims that unknown comments are ignored, when in fact they aren't (only
    4.53 -the initial line comment character is skipped).
    4.54 -
    4.55 -Note that the presence of #APP will mess up the line counters, but
    4.56 -that appears to be difficult to fix.
    4.57 -
    4.58 -Andreas.
    4.59 -
    4.60 -2004-04-23  Andreas Schwab  <schwab@suse.de>
    4.61 -
    4.62 -	* read.c (read_a_source_file): Ignore unknown text after line
    4.63 -	comment character.  Fix misleading comment.
    4.64 -
    4.65 ---- binutils/gas/read.c.~1.78.~	2004-04-23 08:58:23.000000000 +0200
    4.66 -+++ binutils/gas/read.c	2004-04-23 21:49:01.000000000 +0200
    4.67 -@@ -950,10 +950,14 @@ read_a_source_file (char *name)
    4.68 - 	      unsigned int new_length;
    4.69 - 	      char *tmp_buf = 0;
    4.70 - 
    4.71 --	      bump_line_counters ();
    4.72 - 	      s = input_line_pointer;
    4.73 - 	      if (strncmp (s, "APP\n", 4))
    4.74 --		continue;	/* We ignore it */
    4.75 -+		{
    4.76 -+		  /* We ignore it */
    4.77 -+		  ignore_rest_of_line ();
    4.78 -+		  continue;
    4.79 -+		}
    4.80 -+	      bump_line_counters ();
    4.81 - 	      s += 4;
    4.82 - 
    4.83 - 	      sb_new (&sbuf);
    4.84 -@@ -1052,7 +1056,7 @@ read_a_source_file (char *name)
    4.85 - 	    continue;
    4.86 - #endif
    4.87 - 	  input_line_pointer--;
    4.88 --	  /* Report unknown char as ignored.  */
    4.89 -+	  /* Report unknown char as error.  */
    4.90 - 	  demand_empty_rest_of_line ();
    4.91 - 	}
    4.92 - 
    4.93 -
    4.94 --- 
    4.95 -Andreas Schwab, SuSE Labs, schwab@suse.de
    4.96 -SuSE Linux AG, Maxfeldstra&#xC3;e 5, 90409 N&#xC3;rnberg, Germany
    4.97 -Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
    4.98 -"And now for something completely different."
     5.1 --- a/patches/binutils/2.16.1/130-callahan.patch	Sun Sep 11 18:26:12 2011 +0200
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,693 +0,0 @@
     5.4 -Signed-off-by: dank@kegel.com
     5.5 -Fixes ld speed issue. 
     5.6 -See http://weblogs.mozillazine.org/roc/archives/2005/02/optimizing_gnu.html
     5.7 -See thread "Re: optimizations for 3x speedup in ld",
     5.8 -http://sources.redhat.com/ml/binutils/2005-03/msg00847.html
     5.9 -
    5.10 -Wildcard section matching enhancement, backported from the binutils CVS tree.
    5.11 -Here's the CVS log comment from the original change to ldlang.c:
    5.12 -
    5.13 -revision 1.177
    5.14 -date: 2005/04/06 15:33:02;  author: jakub;  state: Exp;  lines: +438 -51
    5.15 -2005-04-06  Jakub Jelinek  <jakub@redhat.com>
    5.16 -
    5.17 -        * ldlang.c: Formatting.
    5.18 -        (walk_wild_consider_section): Remember return value from wildcardp.
    5.19 -        (is_simple_wild): Use strcspn instead of 2 strpbrk calls and strlen.
    5.20 -        (wild_spec_can_overlap): Use strcspn instead of strpbrk and strlen.
    5.21 -
    5.22 -2005-04-06  Robert O'Callahan  <rocallahan@novell.com>
    5.23 -
    5.24 -        * ld.h (lean_section_userdata_type): Remove.
    5.25 -        (fat_section_userdata_type): Remove file field.
    5.26 -        (SECTION_USERDATA_SIZE): Remove.
    5.27 -        * ldlang.c (init_os): Eliminate initialization of unused
    5.28 -        lean_section_userdata_type.
    5.29 -
    5.30 -        * ldlang.h (callback_t, walk_wild_section_handler_t): New
    5.31 -        typedefs.
    5.32 -        (struct lang_wild_statement_struct): Add walk_wild_section_handler
    5.33 -        and handler_data fields.
    5.34 -        * ldlang.c (callback_t): Removed.
    5.35 -        (walk_wild_consider_section, walk_wild_section_general,
    5.36 -        section_iterator_callback, find_section, is_simple_wild,
    5.37 -        match_simple_wild, walk_wild_section_specs1_wild0,
    5.38 -        walk_wild_section_specs1_wild1, walk_wild_section_specs2_wild1,
    5.39 -        walk_wild_section_specs3_wild2, walk_wild_section_specs4_wild2,
    5.40 -        wild_spec_can_overlap, analyze_walk_wild_section_handler): New
    5.41 -        functions.
    5.42 -        (lang_add_wild): Call analyze_walk_wild_section_handler.
    5.43 -        (walk_wild_section): Renamed to walk_wild_section_general and
    5.44 -        created a wrapper function.
    5.45 -        (section_iterator_callback_data): New typedef.
    5.46 -
    5.47 -
    5.48 -Index: src/ld/ld.h
    5.49 -===================================================================
    5.50 -RCS file: /cvs/src/src/ld/ld.h,v
    5.51 -retrieving revision 1.26
    5.52 -retrieving revision 1.27
    5.53 -diff -u -r1.26 -r1.27
    5.54 ---- binutils/ld/ld.h.old	16 Mar 2005 21:52:42 -0000	1.26
    5.55 -+++ binutils/ld/ld.h	6 Apr 2005 15:33:02 -0000	1.27
    5.56 -@@ -1,6 +1,6 @@
    5.57 - /* ld.h -- general linker header file
    5.58 -    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
    5.59 --   2001, 2002, 2003, 2004
    5.60 -+   2001, 2002, 2003, 2004, 2005
    5.61 -    Free Software Foundation, Inc.
    5.62 - 
    5.63 -    This file is part of GLD, the Gnu Linker.
    5.64 -@@ -89,28 +89,15 @@
    5.65 -   struct map_symbol_def *next;
    5.66 - };
    5.67 - 
    5.68 --/* Extra information we hold on sections */
    5.69 --typedef struct lean_user_section_struct {
    5.70 --  /* For output sections: pointer to the section where this data will go.  */
    5.71 --  struct lang_input_statement_struct *file;
    5.72 --} lean_section_userdata_type;
    5.73 --
    5.74 - /* The initial part of fat_user_section_struct has to be idential with
    5.75 -    lean_user_section_struct.  */
    5.76 - typedef struct fat_user_section_struct {
    5.77 --  /* For output sections: pointer to the section where this data will go.  */
    5.78 --  struct lang_input_statement_struct *file;
    5.79 -   /* For input sections, when writing a map file: head / tail of a linked
    5.80 -      list of hash table entries for symbols defined in this section.  */
    5.81 -   struct map_symbol_def *map_symbol_def_head;
    5.82 -   struct map_symbol_def **map_symbol_def_tail;
    5.83 - } fat_section_userdata_type;
    5.84 - 
    5.85 --#define SECTION_USERDATA_SIZE \
    5.86 -- (command_line.reduce_memory_overheads \
    5.87 --  ? sizeof (lean_section_userdata_type) \
    5.88 --  : sizeof (fat_section_userdata_type))
    5.89 --
    5.90 - #define get_userdata(x) ((x)->userdata)
    5.91 - 
    5.92 - #define BYTE_SIZE	(1)
    5.93 -Index: src/ld/ldlang.c
    5.94 -===================================================================
    5.95 -RCS file: /cvs/src/src/ld/ldlang.c,v
    5.96 -retrieving revision 1.176
    5.97 -retrieving revision 1.177
    5.98 -diff -u -r1.176 -r1.177
    5.99 ---- binutils/ld/ldlang.c.old	18 Mar 2005 13:56:26 -0000	1.176
   5.100 -+++ binutils/ld/ldlang.c	6 Apr 2005 15:33:02 -0000	1.177
   5.101 -@@ -84,9 +84,6 @@
   5.102 - static void lang_record_phdrs (void);
   5.103 - static void lang_do_version_exports_section (void);
   5.104 - 
   5.105 --typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
   5.106 --			    asection *, lang_input_statement_type *, void *);
   5.107 --
   5.108 - /* Exported variables.  */
   5.109 - lang_output_section_statement_type *abs_output_section;
   5.110 - lang_statement_list_type lang_output_section_statement;
   5.111 -@@ -155,21 +152,71 @@
   5.112 - 
   5.113 - /* Generic traversal routines for finding matching sections.  */
   5.114 - 
   5.115 -+/* Try processing a section against a wildcard.  This just calls
   5.116 -+   the callback unless the filename exclusion list is present
   5.117 -+   and excludes the file.  It's hardly ever present so this
   5.118 -+   function is very fast.  */
   5.119 -+
   5.120 -+static void
   5.121 -+walk_wild_consider_section (lang_wild_statement_type *ptr,
   5.122 -+			    lang_input_statement_type *file,
   5.123 -+			    asection *s,
   5.124 -+			    struct wildcard_list *sec,
   5.125 -+			    callback_t callback,
   5.126 -+			    void *data)
   5.127 -+{
   5.128 -+  bfd_boolean skip = FALSE;
   5.129 -+  struct name_list *list_tmp;
   5.130 -+
   5.131 -+  /* Don't process sections from files which were
   5.132 -+     excluded.  */
   5.133 -+  for (list_tmp = sec->spec.exclude_name_list;
   5.134 -+       list_tmp;
   5.135 -+       list_tmp = list_tmp->next)
   5.136 -+    {
   5.137 -+      bfd_boolean is_wildcard = wildcardp (list_tmp->name);
   5.138 -+      if (is_wildcard)
   5.139 -+	skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
   5.140 -+      else
   5.141 -+	skip = strcmp (list_tmp->name, file->filename) == 0;
   5.142 -+
   5.143 -+      /* If this file is part of an archive, and the archive is
   5.144 -+	 excluded, exclude this file.  */
   5.145 -+      if (! skip && file->the_bfd != NULL
   5.146 -+	  && file->the_bfd->my_archive != NULL
   5.147 -+	  && file->the_bfd->my_archive->filename != NULL)
   5.148 -+	{
   5.149 -+	  if (is_wildcard)
   5.150 -+	    skip = fnmatch (list_tmp->name,
   5.151 -+			    file->the_bfd->my_archive->filename,
   5.152 -+			    0) == 0;
   5.153 -+	  else
   5.154 -+	    skip = strcmp (list_tmp->name,
   5.155 -+			   file->the_bfd->my_archive->filename) == 0;
   5.156 -+	}
   5.157 -+
   5.158 -+      if (skip)
   5.159 -+	break;
   5.160 -+    }
   5.161 -+
   5.162 -+  if (!skip)
   5.163 -+    (*callback) (ptr, sec, s, file, data);
   5.164 -+}
   5.165 -+
   5.166 -+/* Lowest common denominator routine that can handle everything correctly,
   5.167 -+   but slowly.  */
   5.168 -+
   5.169 - static void
   5.170 --walk_wild_section (lang_wild_statement_type *ptr,
   5.171 --		   lang_input_statement_type *file,
   5.172 --		   callback_t callback,
   5.173 --		   void *data)
   5.174 -+walk_wild_section_general (lang_wild_statement_type *ptr,
   5.175 -+			   lang_input_statement_type *file,
   5.176 -+			   callback_t callback,
   5.177 -+			   void *data)
   5.178 - {
   5.179 -   asection *s;
   5.180 --
   5.181 --  if (file->just_syms_flag)
   5.182 --    return;
   5.183 -+  struct wildcard_list *sec;
   5.184 - 
   5.185 -   for (s = file->the_bfd->sections; s != NULL; s = s->next)
   5.186 -     {
   5.187 --      struct wildcard_list *sec;
   5.188 --
   5.189 -       sec = ptr->section_list;
   5.190 -       if (sec == NULL)
   5.191 - 	(*callback) (ptr, sec, s, file, data);
   5.192 -@@ -177,39 +224,8 @@
   5.193 -       while (sec != NULL)
   5.194 - 	{
   5.195 - 	  bfd_boolean skip = FALSE;
   5.196 --	  struct name_list *list_tmp;
   5.197 - 
   5.198 --	  /* Don't process sections from files which were
   5.199 --	     excluded.  */
   5.200 --	  for (list_tmp = sec->spec.exclude_name_list;
   5.201 --	       list_tmp;
   5.202 --	       list_tmp = list_tmp->next)
   5.203 --	    {
   5.204 --	      if (wildcardp (list_tmp->name))
   5.205 --		skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
   5.206 --	      else
   5.207 --		skip = strcmp (list_tmp->name, file->filename) == 0;
   5.208 --
   5.209 --	      /* If this file is part of an archive, and the archive is
   5.210 --		 excluded, exclude this file.  */
   5.211 --	      if (! skip && file->the_bfd != NULL
   5.212 --		  && file->the_bfd->my_archive != NULL
   5.213 --		  && file->the_bfd->my_archive->filename != NULL)
   5.214 --		{
   5.215 --		  if (wildcardp (list_tmp->name))
   5.216 --		    skip = fnmatch (list_tmp->name,
   5.217 --				    file->the_bfd->my_archive->filename,
   5.218 --				    0) == 0;
   5.219 --		  else
   5.220 --		    skip = strcmp (list_tmp->name,
   5.221 --				   file->the_bfd->my_archive->filename) == 0;
   5.222 --		}
   5.223 --
   5.224 --	      if (skip)
   5.225 --		break;
   5.226 --	    }
   5.227 --
   5.228 --	  if (!skip && sec->spec.name != NULL)
   5.229 -+	  if (sec->spec.name != NULL)
   5.230 - 	    {
   5.231 - 	      const char *sname = bfd_get_section_name (file->the_bfd, s);
   5.232 - 
   5.233 -@@ -220,13 +236,381 @@
   5.234 - 	    }
   5.235 - 
   5.236 - 	  if (!skip)
   5.237 --	    (*callback) (ptr, sec, s, file, data);
   5.238 -+	    walk_wild_consider_section (ptr, file, s, sec, callback, data);
   5.239 - 
   5.240 - 	  sec = sec->next;
   5.241 - 	}
   5.242 -     }
   5.243 - }
   5.244 - 
   5.245 -+/* Routines to find a single section given its name.  If there's more
   5.246 -+   than one section with that name, we report that.  */
   5.247 -+
   5.248 -+typedef struct
   5.249 -+{
   5.250 -+  asection *found_section;
   5.251 -+  bfd_boolean multiple_sections_found;
   5.252 -+} section_iterator_callback_data;
   5.253 -+
   5.254 -+static bfd_boolean
   5.255 -+section_iterator_callback (bfd *bfd ATTRIBUTE_UNUSED, asection *s, void *data)
   5.256 -+{
   5.257 -+  section_iterator_callback_data *d = data;
   5.258 -+
   5.259 -+  if (d->found_section != NULL)
   5.260 -+    {
   5.261 -+      d->multiple_sections_found = TRUE;
   5.262 -+      return TRUE;
   5.263 -+    }
   5.264 -+
   5.265 -+  d->found_section = s;
   5.266 -+  return FALSE;
   5.267 -+}
   5.268 -+
   5.269 -+static asection *
   5.270 -+find_section (lang_input_statement_type *file,
   5.271 -+	      struct wildcard_list *sec,
   5.272 -+	      bfd_boolean *multiple_sections_found)
   5.273 -+{
   5.274 -+  section_iterator_callback_data cb_data = { NULL, FALSE };
   5.275 -+
   5.276 -+  bfd_get_section_by_name_if (file->the_bfd, sec->spec.name, 
   5.277 -+			      section_iterator_callback, &cb_data);
   5.278 -+  *multiple_sections_found = cb_data.multiple_sections_found;
   5.279 -+  return cb_data.found_section;
   5.280 -+}
   5.281 -+
   5.282 -+/* Code for handling simple wildcards without going through fnmatch,
   5.283 -+   which can be expensive because of charset translations etc.  */
   5.284 -+
   5.285 -+/* A simple wild is a literal string followed by a single '*',
   5.286 -+   where the literal part is at least 4 characters long.  */
   5.287 -+
   5.288 -+static bfd_boolean
   5.289 -+is_simple_wild (const char *name)
   5.290 -+{
   5.291 -+  size_t len = strcspn (name, "*?[");
   5.292 -+  return len >= 4 && name[len] == '*' && name[len + 1] == '\0';
   5.293 -+}
   5.294 -+
   5.295 -+static bfd_boolean
   5.296 -+match_simple_wild (const char *pattern, const char *name)
   5.297 -+{
   5.298 -+  /* The first four characters of the pattern are guaranteed valid
   5.299 -+     non-wildcard characters.  So we can go faster.  */
   5.300 -+  if (pattern[0] != name[0] || pattern[1] != name[1]
   5.301 -+      || pattern[2] != name[2] || pattern[3] != name[3])
   5.302 -+    return FALSE;
   5.303 -+
   5.304 -+  pattern += 4;
   5.305 -+  name += 4;
   5.306 -+  while (*pattern != '*')
   5.307 -+    if (*name++ != *pattern++)
   5.308 -+      return FALSE;
   5.309 -+
   5.310 -+  return TRUE;
   5.311 -+}
   5.312 -+
   5.313 -+/* Specialized, optimized routines for handling different kinds of
   5.314 -+   wildcards */
   5.315 -+
   5.316 -+static void
   5.317 -+walk_wild_section_specs1_wild0 (lang_wild_statement_type *ptr,
   5.318 -+				lang_input_statement_type *file,
   5.319 -+				callback_t callback,
   5.320 -+				void *data)
   5.321 -+{
   5.322 -+  /* We can just do a hash lookup for the section with the right name.
   5.323 -+     But if that lookup discovers more than one section with the name
   5.324 -+     (should be rare), we fall back to the general algorithm because
   5.325 -+     we would otherwise have to sort the sections to make sure they
   5.326 -+     get processed in the bfd's order.  */
   5.327 -+  bfd_boolean multiple_sections_found;
   5.328 -+  struct wildcard_list *sec0 = ptr->handler_data[0];
   5.329 -+  asection *s0 = find_section (file, sec0, &multiple_sections_found);
   5.330 -+
   5.331 -+  if (multiple_sections_found)
   5.332 -+    walk_wild_section_general (ptr, file, callback, data);
   5.333 -+  else if (s0)
   5.334 -+    walk_wild_consider_section (ptr, file, s0, sec0, callback, data);
   5.335 -+}
   5.336 -+
   5.337 -+static void
   5.338 -+walk_wild_section_specs1_wild1 (lang_wild_statement_type *ptr,
   5.339 -+				lang_input_statement_type *file,
   5.340 -+				callback_t callback,
   5.341 -+				void *data)
   5.342 -+{
   5.343 -+  asection *s;
   5.344 -+  struct wildcard_list *wildsec0 = ptr->handler_data[0];
   5.345 -+
   5.346 -+  for (s = file->the_bfd->sections; s != NULL; s = s->next)
   5.347 -+    {
   5.348 -+      const char *sname = bfd_get_section_name (file->the_bfd, s);
   5.349 -+      bfd_boolean skip = !match_simple_wild (wildsec0->spec.name, sname);
   5.350 -+
   5.351 -+      if (!skip)
   5.352 -+	walk_wild_consider_section (ptr, file, s, wildsec0, callback, data);
   5.353 -+    }
   5.354 -+}
   5.355 -+
   5.356 -+static void
   5.357 -+walk_wild_section_specs2_wild1 (lang_wild_statement_type *ptr,
   5.358 -+				lang_input_statement_type *file,
   5.359 -+				callback_t callback,
   5.360 -+				void *data)
   5.361 -+{
   5.362 -+  asection *s;
   5.363 -+  struct wildcard_list *sec0 = ptr->handler_data[0];
   5.364 -+  struct wildcard_list *wildsec1 = ptr->handler_data[1];
   5.365 -+  bfd_boolean multiple_sections_found;
   5.366 -+  asection *s0 = find_section (file, sec0, &multiple_sections_found);
   5.367 -+
   5.368 -+  if (multiple_sections_found)
   5.369 -+    {
   5.370 -+      walk_wild_section_general (ptr, file, callback, data);
   5.371 -+      return;
   5.372 -+    }
   5.373 -+
   5.374 -+  /* Note that if the section was not found, s0 is NULL and
   5.375 -+     we'll simply never succeed the s == s0 test below.  */
   5.376 -+  for (s = file->the_bfd->sections; s != NULL; s = s->next)
   5.377 -+    {
   5.378 -+      /* Recall that in this code path, a section cannot satisfy more
   5.379 -+	 than one spec, so if s == s0 then it cannot match
   5.380 -+	 wildspec1.  */
   5.381 -+      if (s == s0)
   5.382 -+	walk_wild_consider_section (ptr, file, s, sec0, callback, data);
   5.383 -+      else
   5.384 -+	{
   5.385 -+	  const char *sname = bfd_get_section_name (file->the_bfd, s);
   5.386 -+	  bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname);
   5.387 -+
   5.388 -+	  if (!skip)
   5.389 -+	    walk_wild_consider_section (ptr, file, s, wildsec1, callback,
   5.390 -+					data);
   5.391 -+	}
   5.392 -+    }
   5.393 -+}
   5.394 -+
   5.395 -+static void
   5.396 -+walk_wild_section_specs3_wild2 (lang_wild_statement_type *ptr,
   5.397 -+				lang_input_statement_type *file,
   5.398 -+				callback_t callback,
   5.399 -+				void *data)
   5.400 -+{
   5.401 -+  asection *s;
   5.402 -+  struct wildcard_list *sec0 = ptr->handler_data[0];
   5.403 -+  struct wildcard_list *wildsec1 = ptr->handler_data[1];
   5.404 -+  struct wildcard_list *wildsec2 = ptr->handler_data[2];
   5.405 -+  bfd_boolean multiple_sections_found;
   5.406 -+  asection *s0 = find_section (file, sec0, &multiple_sections_found);
   5.407 -+
   5.408 -+  if (multiple_sections_found)
   5.409 -+    {
   5.410 -+      walk_wild_section_general (ptr, file, callback, data);
   5.411 -+      return;
   5.412 -+    }
   5.413 -+
   5.414 -+  for (s = file->the_bfd->sections; s != NULL; s = s->next)
   5.415 -+    {
   5.416 -+      if (s == s0)
   5.417 -+	walk_wild_consider_section (ptr, file, s, sec0, callback, data);
   5.418 -+      else
   5.419 -+	{
   5.420 -+	  const char *sname = bfd_get_section_name (file->the_bfd, s);
   5.421 -+	  bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname);
   5.422 -+
   5.423 -+	  if (!skip)
   5.424 -+	    walk_wild_consider_section (ptr, file, s, wildsec1, callback, data);
   5.425 -+	  else
   5.426 -+	    {
   5.427 -+	      skip = !match_simple_wild (wildsec2->spec.name, sname);
   5.428 -+	      if (!skip)
   5.429 -+		walk_wild_consider_section (ptr, file, s, wildsec2, callback,
   5.430 -+					    data);
   5.431 -+	    }
   5.432 -+	}
   5.433 -+    }
   5.434 -+}
   5.435 -+
   5.436 -+static void
   5.437 -+walk_wild_section_specs4_wild2 (lang_wild_statement_type *ptr,
   5.438 -+				lang_input_statement_type *file,
   5.439 -+				callback_t callback,
   5.440 -+				void *data)
   5.441 -+{
   5.442 -+  asection *s;
   5.443 -+  struct wildcard_list *sec0 = ptr->handler_data[0];
   5.444 -+  struct wildcard_list *sec1 = ptr->handler_data[1];
   5.445 -+  struct wildcard_list *wildsec2 = ptr->handler_data[2];
   5.446 -+  struct wildcard_list *wildsec3 = ptr->handler_data[3];
   5.447 -+  bfd_boolean multiple_sections_found;
   5.448 -+  asection *s0 = find_section (file, sec0, &multiple_sections_found), *s1;
   5.449 -+
   5.450 -+  if (multiple_sections_found)
   5.451 -+    {
   5.452 -+      walk_wild_section_general (ptr, file, callback, data);
   5.453 -+      return;
   5.454 -+    }
   5.455 -+
   5.456 -+  s1 = find_section (file, sec1, &multiple_sections_found);
   5.457 -+  if (multiple_sections_found)
   5.458 -+    {
   5.459 -+      walk_wild_section_general (ptr, file, callback, data);
   5.460 -+      return;
   5.461 -+    }
   5.462 -+
   5.463 -+  for (s = file->the_bfd->sections; s != NULL; s = s->next)
   5.464 -+    {
   5.465 -+      if (s == s0)
   5.466 -+	walk_wild_consider_section (ptr, file, s, sec0, callback, data);
   5.467 -+      else
   5.468 -+	if (s == s1)
   5.469 -+	  walk_wild_consider_section (ptr, file, s, sec1, callback, data);
   5.470 -+	else
   5.471 -+	  {
   5.472 -+	    const char *sname = bfd_get_section_name (file->the_bfd, s);
   5.473 -+	    bfd_boolean skip = !match_simple_wild (wildsec2->spec.name,
   5.474 -+						   sname);
   5.475 -+
   5.476 -+	    if (!skip)
   5.477 -+	      walk_wild_consider_section (ptr, file, s, wildsec2, callback,
   5.478 -+					  data);
   5.479 -+	    else
   5.480 -+	      {
   5.481 -+		skip = !match_simple_wild (wildsec3->spec.name, sname);
   5.482 -+		if (!skip)
   5.483 -+		  walk_wild_consider_section (ptr, file, s, wildsec3,
   5.484 -+					      callback, data);
   5.485 -+	      }
   5.486 -+	  }
   5.487 -+    }
   5.488 -+}
   5.489 -+
   5.490 -+static void
   5.491 -+walk_wild_section (lang_wild_statement_type *ptr,
   5.492 -+		   lang_input_statement_type *file,
   5.493 -+		   callback_t callback,
   5.494 -+		   void *data)
   5.495 -+{
   5.496 -+  if (file->just_syms_flag)
   5.497 -+    return;
   5.498 -+
   5.499 -+  (*ptr->walk_wild_section_handler) (ptr, file, callback, data);
   5.500 -+}
   5.501 -+
   5.502 -+/* Returns TRUE when name1 is a wildcard spec that might match
   5.503 -+   something name2 can match.  We're conservative: we return FALSE
   5.504 -+   only if the prefixes of name1 and name2 are different up to the
   5.505 -+   first wildcard character.  */
   5.506 -+
   5.507 -+static bfd_boolean
   5.508 -+wild_spec_can_overlap (const char *name1, const char *name2)
   5.509 -+{
   5.510 -+  size_t prefix1_len = strcspn (name1, "?*[");
   5.511 -+  size_t prefix2_len = strcspn (name2, "?*[");
   5.512 -+  size_t min_prefix_len;
   5.513 -+
   5.514 -+  /* Note that if there is no wildcard character, then we treat the
   5.515 -+     terminating 0 as part of the prefix.  Thus ".text" won't match
   5.516 -+     ".text." or ".text.*", for example.  */
   5.517 -+  if (name1[prefix1_len] == '\0')
   5.518 -+    prefix1_len++;
   5.519 -+  if (name2[prefix2_len] == '\0')
   5.520 -+    prefix2_len++;
   5.521 -+
   5.522 -+  min_prefix_len = prefix1_len < prefix2_len ? prefix1_len : prefix2_len;
   5.523 -+
   5.524 -+  return memcmp (name1, name2, min_prefix_len) == 0;
   5.525 -+}
   5.526 -+
   5.527 -+/* Select specialized code to handle various kinds of wildcard
   5.528 -+   statements.  */
   5.529 -+
   5.530 -+static void
   5.531 -+analyze_walk_wild_section_handler (lang_wild_statement_type *ptr)
   5.532 -+{
   5.533 -+  int sec_count = 0;
   5.534 -+  int wild_name_count = 0;
   5.535 -+  struct wildcard_list *sec;
   5.536 -+  int signature;
   5.537 -+  int data_counter;
   5.538 -+
   5.539 -+  ptr->walk_wild_section_handler = walk_wild_section_general;
   5.540 -+
   5.541 -+  /* Count how many wildcard_specs there are, and how many of those
   5.542 -+     actually use wildcards in the name.  Also, bail out if any of the
   5.543 -+     wildcard names are NULL. (Can this actually happen?
   5.544 -+     walk_wild_section used to test for it.)  And bail out if any
   5.545 -+     of the wildcards are more complex than a simple string
   5.546 -+     ending in a single '*'.  */
   5.547 -+  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
   5.548 -+    {
   5.549 -+      ++sec_count;
   5.550 -+      if (sec->spec.name == NULL)
   5.551 -+	return;
   5.552 -+      if (wildcardp (sec->spec.name))
   5.553 -+	{
   5.554 -+	  ++wild_name_count;
   5.555 -+	  if (!is_simple_wild (sec->spec.name))
   5.556 -+	    return;
   5.557 -+	}
   5.558 -+    }
   5.559 -+
   5.560 -+  /* The zero-spec case would be easy to optimize but it doesn't
   5.561 -+     happen in practice.  Likewise, more than 4 specs doesn't
   5.562 -+     happen in practice.  */
   5.563 -+  if (sec_count == 0 || sec_count > 4)
   5.564 -+    return;
   5.565 -+
   5.566 -+  /* Check that no two specs can match the same section.  */
   5.567 -+  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
   5.568 -+    {
   5.569 -+      struct wildcard_list *sec2;
   5.570 -+      for (sec2 = sec->next; sec2 != NULL; sec2 = sec2->next)
   5.571 -+	{
   5.572 -+	  if (wild_spec_can_overlap (sec->spec.name, sec2->spec.name))
   5.573 -+	    return;
   5.574 -+	}
   5.575 -+    }
   5.576 -+
   5.577 -+  signature = (sec_count << 8) + wild_name_count;
   5.578 -+  switch (signature)
   5.579 -+    {
   5.580 -+    case 0x0100:
   5.581 -+      ptr->walk_wild_section_handler = walk_wild_section_specs1_wild0;
   5.582 -+      break;
   5.583 -+    case 0x0101:
   5.584 -+      ptr->walk_wild_section_handler = walk_wild_section_specs1_wild1;
   5.585 -+      break;
   5.586 -+    case 0x0201:
   5.587 -+      ptr->walk_wild_section_handler = walk_wild_section_specs2_wild1;
   5.588 -+      break;
   5.589 -+    case 0x0302:
   5.590 -+      ptr->walk_wild_section_handler = walk_wild_section_specs3_wild2;
   5.591 -+      break;
   5.592 -+    case 0x0402:
   5.593 -+      ptr->walk_wild_section_handler = walk_wild_section_specs4_wild2;
   5.594 -+      break;
   5.595 -+    default:
   5.596 -+      return;
   5.597 -+    }
   5.598 -+
   5.599 -+  /* Now fill the data array with pointers to the specs, first the
   5.600 -+     specs with non-wildcard names, then the specs with wildcard
   5.601 -+     names.  It's OK to process the specs in different order from the
   5.602 -+     given order, because we've already determined that no section
   5.603 -+     will match more than one spec.  */
   5.604 -+  data_counter = 0;
   5.605 -+  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
   5.606 -+    if (!wildcardp (sec->spec.name))
   5.607 -+      ptr->handler_data[data_counter++] = sec;
   5.608 -+  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
   5.609 -+    if (wildcardp (sec->spec.name))
   5.610 -+      ptr->handler_data[data_counter++] = sec;
   5.611 -+}
   5.612 -+
   5.613 - /* Handle a wild statement for a single file F.  */
   5.614 - 
   5.615 - static void
   5.616 -@@ -1175,17 +1559,12 @@
   5.617 - static void
   5.618 - init_os (lang_output_section_statement_type *s)
   5.619 - {
   5.620 --  lean_section_userdata_type *new;
   5.621 --
   5.622 -   if (s->bfd_section != NULL)
   5.623 -     return;
   5.624 - 
   5.625 -   if (strcmp (s->name, DISCARD_SECTION_NAME) == 0)
   5.626 -     einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME);
   5.627 - 
   5.628 --  new = stat_alloc (SECTION_USERDATA_SIZE);
   5.629 --  memset (new, 0, SECTION_USERDATA_SIZE);
   5.630 --
   5.631 -   s->bfd_section = bfd_get_section_by_name (output_bfd, s->name);
   5.632 -   if (s->bfd_section == NULL)
   5.633 -     s->bfd_section = bfd_make_section (output_bfd, s->name);
   5.634 -@@ -1199,7 +1578,14 @@
   5.635 -   /* We initialize an output sections output offset to minus its own
   5.636 -      vma to allow us to output a section through itself.  */
   5.637 -   s->bfd_section->output_offset = 0;
   5.638 --  get_userdata (s->bfd_section) = new;
   5.639 -+  if (!command_line.reduce_memory_overheads)
   5.640 -+    {
   5.641 -+      fat_section_userdata_type *new
   5.642 -+	= stat_alloc (sizeof (fat_section_userdata_type));
   5.643 -+      memset (new, 0, sizeof (fat_section_userdata_type));
   5.644 -+      get_userdata (s->bfd_section) = new;
   5.645 -+    }
   5.646 -+
   5.647 - 
   5.648 -   /* If there is a base address, make sure that any sections it might
   5.649 -      mention are initialized.  */
   5.650 -@@ -4939,6 +5325,7 @@
   5.651 -   new->section_list = section_list;
   5.652 -   new->keep_sections = keep_sections;
   5.653 -   lang_list_init (&new->children);
   5.654 -+  analyze_walk_wild_section_handler (new);
   5.655 - }
   5.656 - 
   5.657 - void
   5.658 -Index: src/ld/ldlang.h
   5.659 -===================================================================
   5.660 -RCS file: /cvs/src/src/ld/ldlang.h,v
   5.661 -retrieving revision 1.44
   5.662 -retrieving revision 1.45
   5.663 -diff -u -r1.44 -r1.45
   5.664 ---- binutils/ld/ldlang.h.old	3 Mar 2005 11:51:58 -0000	1.44
   5.665 -+++ binutils/ld/ldlang.h	6 Apr 2005 15:33:03 -0000	1.45
   5.666 -@@ -298,7 +298,17 @@
   5.667 -   union lang_statement_union *file;
   5.668 - } lang_afile_asection_pair_statement_type;
   5.669 - 
   5.670 --typedef struct lang_wild_statement_struct
   5.671 -+typedef struct lang_wild_statement_struct lang_wild_statement_type;
   5.672 -+
   5.673 -+typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
   5.674 -+			    asection *, lang_input_statement_type *, void *);
   5.675 -+
   5.676 -+typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
   5.677 -+					     lang_input_statement_type *,
   5.678 -+					     callback_t callback,
   5.679 -+					     void *data);
   5.680 -+
   5.681 -+struct lang_wild_statement_struct
   5.682 - {
   5.683 -   lang_statement_header_type header;
   5.684 -   const char *filename;
   5.685 -@@ -306,7 +316,10 @@
   5.686 -   struct wildcard_list *section_list;
   5.687 -   bfd_boolean keep_sections;
   5.688 -   lang_statement_list_type children;
   5.689 --} lang_wild_statement_type;
   5.690 -+
   5.691 -+  walk_wild_section_handler_t walk_wild_section_handler;
   5.692 -+  struct wildcard_list *handler_data[4];
   5.693 -+};
   5.694 - 
   5.695 - typedef struct lang_address_statement_struct
   5.696 - {
     6.1 --- a/patches/binutils/2.16.1/140-cross-gprof.patch	Sun Sep 11 18:26:12 2011 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,22 +0,0 @@
     6.4 ---- binutils-2.15/configure.old	2004-07-21 21:36:47.000000000 -0700
     6.5 -+++ binutils-2.15/configure	2004-07-21 21:37:08.000000000 -0700
     6.6 -@@ -999,7 +999,7 @@
     6.7 - 
     6.8 - # Some tools are only suitable for building in a "native" situation.
     6.9 - # Remove these if host!=target.  
    6.10 --native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
    6.11 -+native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
    6.12 - 
    6.13 - # Similarly, some are only suitable for cross toolchains.
    6.14 - # Remove these if host=target.
    6.15 ---- binutils-2.15/configure.in.old	2004-07-21 21:37:19.000000000 -0700
    6.16 -+++ binutils-2.15/configure.in	2004-07-21 21:37:34.000000000 -0700
    6.17 -@@ -236,7 +236,7 @@
    6.18 - 
    6.19 - # Some tools are only suitable for building in a "native" situation.
    6.20 - # Remove these if host!=target.  
    6.21 --native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
    6.22 -+native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
    6.23 - 
    6.24 - # Similarly, some are only suitable for cross toolchains.
    6.25 - # Remove these if host=target.
     7.1 --- a/patches/binutils/2.16.1/150-stabs-tweak.patch	Sun Sep 11 18:26:12 2011 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,28 +0,0 @@
     7.4 -Signed-off-by: dank@kegel.com
     7.5 -
     7.6 -See http://sourceware.org/ml/binutils/2005-12/msg00270.html
     7.7 -http://sourceware.org/ml/binutils-cvs/2005-12/msg00139.html
     7.8 -
     7.9 -STABS hash table size change, backported from the binutils CVS tree.  Here's
    7.10 -the CVS log comment for the original change:
    7.11 -
    7.12 -revision 1.25
    7.13 -date: 2005/12/29 10:29:23;  author: nickc;  state: Exp;  lines: +2 -3
    7.14 -(_bfd_link_section_stabs): Use bfd_hash_table_init rather than
    7.15 -bfd_hash_table_init_n(...,251) so that the size of the hash table can be
    7.16 -controlled by the user.
    7.17 -
    7.18 ---- binutils/bfd/stabs.c.old	4 May 2005 15:53:39 -0000	1.24
    7.19 -+++ binutils/bfd/stabs.c	29 Dec 2005 10:29:23 -0000	1.25
    7.20 -@@ -194,9 +194,8 @@
    7.21 - 	goto error_return;
    7.22 -       /* Make sure the first byte is zero.  */
    7.23 -       (void) _bfd_stringtab_add (sinfo->strings, "", TRUE, TRUE);
    7.24 --      if (! bfd_hash_table_init_n (&sinfo->includes,
    7.25 --				   stab_link_includes_newfunc,
    7.26 --				   251))
    7.27 -+      if (! bfd_hash_table_init (&sinfo->includes,
    7.28 -+				 stab_link_includes_newfunc))
    7.29 - 	goto error_return;
    7.30 -       sinfo->stabstr = bfd_make_section_anyway (abfd, ".stabstr");
    7.31 -       if (sinfo->stabstr == NULL)
     8.1 --- a/patches/binutils/2.16.1/160-i386-no-divide-comment.patch	Sun Sep 11 18:26:12 2011 +0200
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,40 +0,0 @@
     8.4 -diff -durN binutils-2.16.1.orig/gas/config/tc-i386.c binutils-2.16.1/gas/config/tc-i386.c
     8.5 ---- binutils-2.16.1.orig/gas/config/tc-i386.c	2005-04-13 19:58:42.000000000 +0200
     8.6 -+++ binutils-2.16.1/gas/config/tc-i386.c	2008-09-22 09:00:09.000000000 +0200
     8.7 -@@ -192,16 +192,10 @@
     8.8 - #endif
     8.9 - 	;
    8.10 - 
    8.11 --#if (defined (TE_I386AIX)				\
    8.12 --     || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))	\
    8.13 --	 && !defined (TE_LINUX)				\
    8.14 -- 	 && !defined (TE_NETWARE)			\
    8.15 --	 && !defined (TE_FreeBSD)			\
    8.16 --	 && !defined (TE_NetBSD)))
    8.17 - /* This array holds the chars that always start a comment.  If the
    8.18 -    pre-processor is disabled, these aren't very useful.  */
    8.19 --const char comment_chars[] = "#/";
    8.20 --#define PREFIX_SEPARATOR '\\'
    8.21 -+const char comment_chars[] = "#";
    8.22 -+#define PREFIX_SEPARATOR '/'
    8.23 - 
    8.24 - /* This array holds the chars that only start a comment at the beginning of
    8.25 -    a line.  If the line seems to have the form '# 123 filename'
    8.26 -@@ -211,16 +205,7 @@
    8.27 -    #NO_APP at the beginning of its output.
    8.28 -    Also note that comments started like this one will always work if
    8.29 -    '/' isn't otherwise defined.  */
    8.30 --const char line_comment_chars[] = "#";
    8.31 --
    8.32 --#else
    8.33 --/* Putting '/' here makes it impossible to use the divide operator.
    8.34 --   However, we need it for compatibility with SVR4 systems.  */
    8.35 --const char comment_chars[] = "#";
    8.36 --#define PREFIX_SEPARATOR '/'
    8.37 --
    8.38 --const char line_comment_chars[] = "/#";
    8.39 --#endif
    8.40 -+const char line_comment_chars[] = "#/";
    8.41 - 
    8.42 - const char line_separator_chars[] = ";";
    8.43 - 
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/patches/binutils/2.16.1a/100-bfd-hash-tweak.patch	Sun Sep 11 18:18:53 2011 +0200
     9.3 @@ -0,0 +1,23 @@
     9.4 +Signed-off-by: dank@kegel.com
     9.5 +
     9.6 +Raising the size of the hash table is a noticable win when linking 
     9.7 +at least one large app.  
     9.8 +
     9.9 +There was a patch,
    9.10 +http://sources.redhat.com/ml/binutils/2004-06/msg00165.html
    9.11 +to do this dynamically.  No idea why that didn't make it in.
    9.12 +So this tiny change to raise the default size is just
    9.13 +a stopgap for now.
    9.14 +
    9.15 +
    9.16 +--- binutils-2.16.1/bfd/hash.c.old	2006-03-02 23:01:39.000000000 -0800
    9.17 ++++ binutils-2.16.1/bfd/hash.c	2006-03-02 23:01:58.000000000 -0800
    9.18 +@@ -300,7 +300,7 @@
    9.19 + */
    9.20 + 
    9.21 + /* The default number of entries to use when creating a hash table.  */
    9.22 +-#define DEFAULT_SIZE 4051
    9.23 ++#define DEFAULT_SIZE 32749
    9.24 + static size_t bfd_default_hash_table_size = DEFAULT_SIZE;
    9.25 + 
    9.26 + /* Create a new hash table, given a number of entries.  */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/patches/binutils/2.16.1a/110-psignal.patch	Sun Sep 11 18:18:53 2011 +0200
    10.3 @@ -0,0 +1,40 @@
    10.4 +Make psignal prototype in libiberty match that in glibc.
    10.5 +
    10.6 +Fixes:
    10.7 +
    10.8 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c: In function `psignal':
    10.9 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `signo' doesn't match prototype
   10.10 +/usr/include/signal.h:131: prototype declaration
   10.11 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `message' doesn't match prototype
   10.12 +/usr/include/signal.h:131: prototype declaration
   10.13 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:568: warning: comparison between signed and unsigned
   10.14 +mprotect... make[1]: *** [strsignal.o] Error 1
   10.15 +make[1]: Leaving directory `/export/hda3/dkegel/queue/jobdir.produser_cpsm17/crosstool-0.32/build/i686-unknown-linux-gnu/gcc-2.95.3-glibc-2.1.3/build-binutils/libiberty'
   10.16 +make: *** [all-libiberty] Error 2
   10.17 +
   10.18 +when building on red hat 7.1
   10.19 +though it's a bit of a mystery why libiberty's psignal is being compiled at
   10.20 +all, since red hat 7.1's glibc supports psignal (hence the error message)
   10.21 +
   10.22 +--- binutils-2.15/libiberty/strsignal.c.old	2005-04-18 13:57:40.000000000 -0700
   10.23 ++++ binutils-2.15/libiberty/strsignal.c	2005-04-18 13:59:09.000000000 -0700
   10.24 +@@ -544,7 +544,7 @@
   10.25 + 
   10.26 + /*
   10.27 + 
   10.28 +-@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
   10.29 ++@deftypefn Supplemental void psignal (int @var{signo}, const char *@var{message})
   10.30 + 
   10.31 + Print @var{message} to the standard error, followed by a colon,
   10.32 + followed by the description of the signal specified by @var{signo},
   10.33 +@@ -557,9 +557,7 @@
   10.34 + #ifndef HAVE_PSIGNAL
   10.35 + 
   10.36 + void
   10.37 +-psignal (signo, message)
   10.38 +-  unsigned signo;
   10.39 +-  char *message;
   10.40 ++psignal (int signo, const char *message)
   10.41 + {
   10.42 +   if (signal_names == NULL)
   10.43 +     {
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/patches/binutils/2.16.1a/120-skip-comments.patch	Sun Sep 11 18:18:53 2011 +0200
    11.3 @@ -0,0 +1,95 @@
    11.4 +[removed first hunk so it would apply to 2.16.1 - copyright date already updated - dank]
    11.5 +
    11.6 +Retrieved from http://sources.redhat.com/ml/binutils/2004-04/msg00646.html
    11.7 +Fixes
    11.8 +localealias.s:544: Error: junk at end of line, first unrecognized character is `,' 
    11.9 +when building glibc-2.3.2 with gcc-3.4.0 and binutils-2.15.90.0.3
   11.10 +
   11.11 +Paths adjusted to match crosstool's patcher.
   11.12 +
   11.13 +Message-Id: m3n052qw2g.fsf@whitebox.m5r.de
   11.14 +From: Andreas Schwab <schwab at suse dot de>
   11.15 +To: Nathan Sidwell <nathan at codesourcery dot com>
   11.16 +Cc: Ian Lance Taylor <ian at wasabisystems dot com>, binutils at sources dot redhat dot com
   11.17 +Date: Fri, 23 Apr 2004 22:27:19 +0200
   11.18 +Subject: Re: demand_empty_rest_of_line and ignore_rest_of_line
   11.19 +
   11.20 +Nathan Sidwell <nathan@codesourcery.com> writes:
   11.21 +
   11.22 +> Index: read.c
   11.23 +> ===================================================================
   11.24 +> RCS file: /cvs/src/src/gas/read.c,v
   11.25 +> retrieving revision 1.76
   11.26 +> diff -c -3 -p -r1.76 read.c
   11.27 +> *** read.c	12 Mar 2004 17:48:12 -0000	1.76
   11.28 +> --- read.c	18 Mar 2004 09:56:05 -0000
   11.29 +> *************** read_a_source_file (char *name)
   11.30 +> *** 1053,1059 ****
   11.31 +>   #endif
   11.32 +>   	  input_line_pointer--;
   11.33 +>   	  /* Report unknown char as ignored.  */
   11.34 +> ! 	  ignore_rest_of_line ();
   11.35 +>   	}
   11.36 +>   
   11.37 +>   #ifdef md_after_pass_hook
   11.38 +> --- 1053,1059 ----
   11.39 +>   #endif
   11.40 +>   	  input_line_pointer--;
   11.41 +>   	  /* Report unknown char as ignored.  */
   11.42 +> ! 	  demand_empty_rest_of_line ();
   11.43 +>   	}
   11.44 +>   
   11.45 +>   #ifdef md_after_pass_hook
   11.46 +
   11.47 +This means that the unknown character is no longer ignored, despite the
   11.48 +comment.  As a side effect a line starting with a line comment character
   11.49 +not followed by APP in NO_APP mode now triggers an error instead of just a
   11.50 +warning, breaking builds of glibc on m68k-linux.  Earlier in
   11.51 +read_a_source_file where #APP is handled there is another comment that
   11.52 +claims that unknown comments are ignored, when in fact they aren't (only
   11.53 +the initial line comment character is skipped).
   11.54 +
   11.55 +Note that the presence of #APP will mess up the line counters, but
   11.56 +that appears to be difficult to fix.
   11.57 +
   11.58 +Andreas.
   11.59 +
   11.60 +2004-04-23  Andreas Schwab  <schwab@suse.de>
   11.61 +
   11.62 +	* read.c (read_a_source_file): Ignore unknown text after line
   11.63 +	comment character.  Fix misleading comment.
   11.64 +
   11.65 +--- binutils/gas/read.c.~1.78.~	2004-04-23 08:58:23.000000000 +0200
   11.66 ++++ binutils/gas/read.c	2004-04-23 21:49:01.000000000 +0200
   11.67 +@@ -950,10 +950,14 @@ read_a_source_file (char *name)
   11.68 + 	      unsigned int new_length;
   11.69 + 	      char *tmp_buf = 0;
   11.70 + 
   11.71 +-	      bump_line_counters ();
   11.72 + 	      s = input_line_pointer;
   11.73 + 	      if (strncmp (s, "APP\n", 4))
   11.74 +-		continue;	/* We ignore it */
   11.75 ++		{
   11.76 ++		  /* We ignore it */
   11.77 ++		  ignore_rest_of_line ();
   11.78 ++		  continue;
   11.79 ++		}
   11.80 ++	      bump_line_counters ();
   11.81 + 	      s += 4;
   11.82 + 
   11.83 + 	      sb_new (&sbuf);
   11.84 +@@ -1052,7 +1056,7 @@ read_a_source_file (char *name)
   11.85 + 	    continue;
   11.86 + #endif
   11.87 + 	  input_line_pointer--;
   11.88 +-	  /* Report unknown char as ignored.  */
   11.89 ++	  /* Report unknown char as error.  */
   11.90 + 	  demand_empty_rest_of_line ();
   11.91 + 	}
   11.92 + 
   11.93 +
   11.94 +-- 
   11.95 +Andreas Schwab, SuSE Labs, schwab@suse.de
   11.96 +SuSE Linux AG, Maxfeldstra&#xC3;e 5, 90409 N&#xC3;rnberg, Germany
   11.97 +Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
   11.98 +"And now for something completely different."
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/patches/binutils/2.16.1a/130-callahan.patch	Sun Sep 11 18:18:53 2011 +0200
    12.3 @@ -0,0 +1,693 @@
    12.4 +Signed-off-by: dank@kegel.com
    12.5 +Fixes ld speed issue. 
    12.6 +See http://weblogs.mozillazine.org/roc/archives/2005/02/optimizing_gnu.html
    12.7 +See thread "Re: optimizations for 3x speedup in ld",
    12.8 +http://sources.redhat.com/ml/binutils/2005-03/msg00847.html
    12.9 +
   12.10 +Wildcard section matching enhancement, backported from the binutils CVS tree.
   12.11 +Here's the CVS log comment from the original change to ldlang.c:
   12.12 +
   12.13 +revision 1.177
   12.14 +date: 2005/04/06 15:33:02;  author: jakub;  state: Exp;  lines: +438 -51
   12.15 +2005-04-06  Jakub Jelinek  <jakub@redhat.com>
   12.16 +
   12.17 +        * ldlang.c: Formatting.
   12.18 +        (walk_wild_consider_section): Remember return value from wildcardp.
   12.19 +        (is_simple_wild): Use strcspn instead of 2 strpbrk calls and strlen.
   12.20 +        (wild_spec_can_overlap): Use strcspn instead of strpbrk and strlen.
   12.21 +
   12.22 +2005-04-06  Robert O'Callahan  <rocallahan@novell.com>
   12.23 +
   12.24 +        * ld.h (lean_section_userdata_type): Remove.
   12.25 +        (fat_section_userdata_type): Remove file field.
   12.26 +        (SECTION_USERDATA_SIZE): Remove.
   12.27 +        * ldlang.c (init_os): Eliminate initialization of unused
   12.28 +        lean_section_userdata_type.
   12.29 +
   12.30 +        * ldlang.h (callback_t, walk_wild_section_handler_t): New
   12.31 +        typedefs.
   12.32 +        (struct lang_wild_statement_struct): Add walk_wild_section_handler
   12.33 +        and handler_data fields.
   12.34 +        * ldlang.c (callback_t): Removed.
   12.35 +        (walk_wild_consider_section, walk_wild_section_general,
   12.36 +        section_iterator_callback, find_section, is_simple_wild,
   12.37 +        match_simple_wild, walk_wild_section_specs1_wild0,
   12.38 +        walk_wild_section_specs1_wild1, walk_wild_section_specs2_wild1,
   12.39 +        walk_wild_section_specs3_wild2, walk_wild_section_specs4_wild2,
   12.40 +        wild_spec_can_overlap, analyze_walk_wild_section_handler): New
   12.41 +        functions.
   12.42 +        (lang_add_wild): Call analyze_walk_wild_section_handler.
   12.43 +        (walk_wild_section): Renamed to walk_wild_section_general and
   12.44 +        created a wrapper function.
   12.45 +        (section_iterator_callback_data): New typedef.
   12.46 +
   12.47 +
   12.48 +Index: src/ld/ld.h
   12.49 +===================================================================
   12.50 +RCS file: /cvs/src/src/ld/ld.h,v
   12.51 +retrieving revision 1.26
   12.52 +retrieving revision 1.27
   12.53 +diff -u -r1.26 -r1.27
   12.54 +--- binutils/ld/ld.h.old	16 Mar 2005 21:52:42 -0000	1.26
   12.55 ++++ binutils/ld/ld.h	6 Apr 2005 15:33:02 -0000	1.27
   12.56 +@@ -1,6 +1,6 @@
   12.57 + /* ld.h -- general linker header file
   12.58 +    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   12.59 +-   2001, 2002, 2003, 2004
   12.60 ++   2001, 2002, 2003, 2004, 2005
   12.61 +    Free Software Foundation, Inc.
   12.62 + 
   12.63 +    This file is part of GLD, the Gnu Linker.
   12.64 +@@ -89,28 +89,15 @@
   12.65 +   struct map_symbol_def *next;
   12.66 + };
   12.67 + 
   12.68 +-/* Extra information we hold on sections */
   12.69 +-typedef struct lean_user_section_struct {
   12.70 +-  /* For output sections: pointer to the section where this data will go.  */
   12.71 +-  struct lang_input_statement_struct *file;
   12.72 +-} lean_section_userdata_type;
   12.73 +-
   12.74 + /* The initial part of fat_user_section_struct has to be idential with
   12.75 +    lean_user_section_struct.  */
   12.76 + typedef struct fat_user_section_struct {
   12.77 +-  /* For output sections: pointer to the section where this data will go.  */
   12.78 +-  struct lang_input_statement_struct *file;
   12.79 +   /* For input sections, when writing a map file: head / tail of a linked
   12.80 +      list of hash table entries for symbols defined in this section.  */
   12.81 +   struct map_symbol_def *map_symbol_def_head;
   12.82 +   struct map_symbol_def **map_symbol_def_tail;
   12.83 + } fat_section_userdata_type;
   12.84 + 
   12.85 +-#define SECTION_USERDATA_SIZE \
   12.86 +- (command_line.reduce_memory_overheads \
   12.87 +-  ? sizeof (lean_section_userdata_type) \
   12.88 +-  : sizeof (fat_section_userdata_type))
   12.89 +-
   12.90 + #define get_userdata(x) ((x)->userdata)
   12.91 + 
   12.92 + #define BYTE_SIZE	(1)
   12.93 +Index: src/ld/ldlang.c
   12.94 +===================================================================
   12.95 +RCS file: /cvs/src/src/ld/ldlang.c,v
   12.96 +retrieving revision 1.176
   12.97 +retrieving revision 1.177
   12.98 +diff -u -r1.176 -r1.177
   12.99 +--- binutils/ld/ldlang.c.old	18 Mar 2005 13:56:26 -0000	1.176
  12.100 ++++ binutils/ld/ldlang.c	6 Apr 2005 15:33:02 -0000	1.177
  12.101 +@@ -84,9 +84,6 @@
  12.102 + static void lang_record_phdrs (void);
  12.103 + static void lang_do_version_exports_section (void);
  12.104 + 
  12.105 +-typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
  12.106 +-			    asection *, lang_input_statement_type *, void *);
  12.107 +-
  12.108 + /* Exported variables.  */
  12.109 + lang_output_section_statement_type *abs_output_section;
  12.110 + lang_statement_list_type lang_output_section_statement;
  12.111 +@@ -155,21 +152,71 @@
  12.112 + 
  12.113 + /* Generic traversal routines for finding matching sections.  */
  12.114 + 
  12.115 ++/* Try processing a section against a wildcard.  This just calls
  12.116 ++   the callback unless the filename exclusion list is present
  12.117 ++   and excludes the file.  It's hardly ever present so this
  12.118 ++   function is very fast.  */
  12.119 ++
  12.120 ++static void
  12.121 ++walk_wild_consider_section (lang_wild_statement_type *ptr,
  12.122 ++			    lang_input_statement_type *file,
  12.123 ++			    asection *s,
  12.124 ++			    struct wildcard_list *sec,
  12.125 ++			    callback_t callback,
  12.126 ++			    void *data)
  12.127 ++{
  12.128 ++  bfd_boolean skip = FALSE;
  12.129 ++  struct name_list *list_tmp;
  12.130 ++
  12.131 ++  /* Don't process sections from files which were
  12.132 ++     excluded.  */
  12.133 ++  for (list_tmp = sec->spec.exclude_name_list;
  12.134 ++       list_tmp;
  12.135 ++       list_tmp = list_tmp->next)
  12.136 ++    {
  12.137 ++      bfd_boolean is_wildcard = wildcardp (list_tmp->name);
  12.138 ++      if (is_wildcard)
  12.139 ++	skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
  12.140 ++      else
  12.141 ++	skip = strcmp (list_tmp->name, file->filename) == 0;
  12.142 ++
  12.143 ++      /* If this file is part of an archive, and the archive is
  12.144 ++	 excluded, exclude this file.  */
  12.145 ++      if (! skip && file->the_bfd != NULL
  12.146 ++	  && file->the_bfd->my_archive != NULL
  12.147 ++	  && file->the_bfd->my_archive->filename != NULL)
  12.148 ++	{
  12.149 ++	  if (is_wildcard)
  12.150 ++	    skip = fnmatch (list_tmp->name,
  12.151 ++			    file->the_bfd->my_archive->filename,
  12.152 ++			    0) == 0;
  12.153 ++	  else
  12.154 ++	    skip = strcmp (list_tmp->name,
  12.155 ++			   file->the_bfd->my_archive->filename) == 0;
  12.156 ++	}
  12.157 ++
  12.158 ++      if (skip)
  12.159 ++	break;
  12.160 ++    }
  12.161 ++
  12.162 ++  if (!skip)
  12.163 ++    (*callback) (ptr, sec, s, file, data);
  12.164 ++}
  12.165 ++
  12.166 ++/* Lowest common denominator routine that can handle everything correctly,
  12.167 ++   but slowly.  */
  12.168 ++
  12.169 + static void
  12.170 +-walk_wild_section (lang_wild_statement_type *ptr,
  12.171 +-		   lang_input_statement_type *file,
  12.172 +-		   callback_t callback,
  12.173 +-		   void *data)
  12.174 ++walk_wild_section_general (lang_wild_statement_type *ptr,
  12.175 ++			   lang_input_statement_type *file,
  12.176 ++			   callback_t callback,
  12.177 ++			   void *data)
  12.178 + {
  12.179 +   asection *s;
  12.180 +-
  12.181 +-  if (file->just_syms_flag)
  12.182 +-    return;
  12.183 ++  struct wildcard_list *sec;
  12.184 + 
  12.185 +   for (s = file->the_bfd->sections; s != NULL; s = s->next)
  12.186 +     {
  12.187 +-      struct wildcard_list *sec;
  12.188 +-
  12.189 +       sec = ptr->section_list;
  12.190 +       if (sec == NULL)
  12.191 + 	(*callback) (ptr, sec, s, file, data);
  12.192 +@@ -177,39 +224,8 @@
  12.193 +       while (sec != NULL)
  12.194 + 	{
  12.195 + 	  bfd_boolean skip = FALSE;
  12.196 +-	  struct name_list *list_tmp;
  12.197 + 
  12.198 +-	  /* Don't process sections from files which were
  12.199 +-	     excluded.  */
  12.200 +-	  for (list_tmp = sec->spec.exclude_name_list;
  12.201 +-	       list_tmp;
  12.202 +-	       list_tmp = list_tmp->next)
  12.203 +-	    {
  12.204 +-	      if (wildcardp (list_tmp->name))
  12.205 +-		skip = fnmatch (list_tmp->name, file->filename, 0) == 0;
  12.206 +-	      else
  12.207 +-		skip = strcmp (list_tmp->name, file->filename) == 0;
  12.208 +-
  12.209 +-	      /* If this file is part of an archive, and the archive is
  12.210 +-		 excluded, exclude this file.  */
  12.211 +-	      if (! skip && file->the_bfd != NULL
  12.212 +-		  && file->the_bfd->my_archive != NULL
  12.213 +-		  && file->the_bfd->my_archive->filename != NULL)
  12.214 +-		{
  12.215 +-		  if (wildcardp (list_tmp->name))
  12.216 +-		    skip = fnmatch (list_tmp->name,
  12.217 +-				    file->the_bfd->my_archive->filename,
  12.218 +-				    0) == 0;
  12.219 +-		  else
  12.220 +-		    skip = strcmp (list_tmp->name,
  12.221 +-				   file->the_bfd->my_archive->filename) == 0;
  12.222 +-		}
  12.223 +-
  12.224 +-	      if (skip)
  12.225 +-		break;
  12.226 +-	    }
  12.227 +-
  12.228 +-	  if (!skip && sec->spec.name != NULL)
  12.229 ++	  if (sec->spec.name != NULL)
  12.230 + 	    {
  12.231 + 	      const char *sname = bfd_get_section_name (file->the_bfd, s);
  12.232 + 
  12.233 +@@ -220,13 +236,381 @@
  12.234 + 	    }
  12.235 + 
  12.236 + 	  if (!skip)
  12.237 +-	    (*callback) (ptr, sec, s, file, data);
  12.238 ++	    walk_wild_consider_section (ptr, file, s, sec, callback, data);
  12.239 + 
  12.240 + 	  sec = sec->next;
  12.241 + 	}
  12.242 +     }
  12.243 + }
  12.244 + 
  12.245 ++/* Routines to find a single section given its name.  If there's more
  12.246 ++   than one section with that name, we report that.  */
  12.247 ++
  12.248 ++typedef struct
  12.249 ++{
  12.250 ++  asection *found_section;
  12.251 ++  bfd_boolean multiple_sections_found;
  12.252 ++} section_iterator_callback_data;
  12.253 ++
  12.254 ++static bfd_boolean
  12.255 ++section_iterator_callback (bfd *bfd ATTRIBUTE_UNUSED, asection *s, void *data)
  12.256 ++{
  12.257 ++  section_iterator_callback_data *d = data;
  12.258 ++
  12.259 ++  if (d->found_section != NULL)
  12.260 ++    {
  12.261 ++      d->multiple_sections_found = TRUE;
  12.262 ++      return TRUE;
  12.263 ++    }
  12.264 ++
  12.265 ++  d->found_section = s;
  12.266 ++  return FALSE;
  12.267 ++}
  12.268 ++
  12.269 ++static asection *
  12.270 ++find_section (lang_input_statement_type *file,
  12.271 ++	      struct wildcard_list *sec,
  12.272 ++	      bfd_boolean *multiple_sections_found)
  12.273 ++{
  12.274 ++  section_iterator_callback_data cb_data = { NULL, FALSE };
  12.275 ++
  12.276 ++  bfd_get_section_by_name_if (file->the_bfd, sec->spec.name, 
  12.277 ++			      section_iterator_callback, &cb_data);
  12.278 ++  *multiple_sections_found = cb_data.multiple_sections_found;
  12.279 ++  return cb_data.found_section;
  12.280 ++}
  12.281 ++
  12.282 ++/* Code for handling simple wildcards without going through fnmatch,
  12.283 ++   which can be expensive because of charset translations etc.  */
  12.284 ++
  12.285 ++/* A simple wild is a literal string followed by a single '*',
  12.286 ++   where the literal part is at least 4 characters long.  */
  12.287 ++
  12.288 ++static bfd_boolean
  12.289 ++is_simple_wild (const char *name)
  12.290 ++{
  12.291 ++  size_t len = strcspn (name, "*?[");
  12.292 ++  return len >= 4 && name[len] == '*' && name[len + 1] == '\0';
  12.293 ++}
  12.294 ++
  12.295 ++static bfd_boolean
  12.296 ++match_simple_wild (const char *pattern, const char *name)
  12.297 ++{
  12.298 ++  /* The first four characters of the pattern are guaranteed valid
  12.299 ++     non-wildcard characters.  So we can go faster.  */
  12.300 ++  if (pattern[0] != name[0] || pattern[1] != name[1]
  12.301 ++      || pattern[2] != name[2] || pattern[3] != name[3])
  12.302 ++    return FALSE;
  12.303 ++
  12.304 ++  pattern += 4;
  12.305 ++  name += 4;
  12.306 ++  while (*pattern != '*')
  12.307 ++    if (*name++ != *pattern++)
  12.308 ++      return FALSE;
  12.309 ++
  12.310 ++  return TRUE;
  12.311 ++}
  12.312 ++
  12.313 ++/* Specialized, optimized routines for handling different kinds of
  12.314 ++   wildcards */
  12.315 ++
  12.316 ++static void
  12.317 ++walk_wild_section_specs1_wild0 (lang_wild_statement_type *ptr,
  12.318 ++				lang_input_statement_type *file,
  12.319 ++				callback_t callback,
  12.320 ++				void *data)
  12.321 ++{
  12.322 ++  /* We can just do a hash lookup for the section with the right name.
  12.323 ++     But if that lookup discovers more than one section with the name
  12.324 ++     (should be rare), we fall back to the general algorithm because
  12.325 ++     we would otherwise have to sort the sections to make sure they
  12.326 ++     get processed in the bfd's order.  */
  12.327 ++  bfd_boolean multiple_sections_found;
  12.328 ++  struct wildcard_list *sec0 = ptr->handler_data[0];
  12.329 ++  asection *s0 = find_section (file, sec0, &multiple_sections_found);
  12.330 ++
  12.331 ++  if (multiple_sections_found)
  12.332 ++    walk_wild_section_general (ptr, file, callback, data);
  12.333 ++  else if (s0)
  12.334 ++    walk_wild_consider_section (ptr, file, s0, sec0, callback, data);
  12.335 ++}
  12.336 ++
  12.337 ++static void
  12.338 ++walk_wild_section_specs1_wild1 (lang_wild_statement_type *ptr,
  12.339 ++				lang_input_statement_type *file,
  12.340 ++				callback_t callback,
  12.341 ++				void *data)
  12.342 ++{
  12.343 ++  asection *s;
  12.344 ++  struct wildcard_list *wildsec0 = ptr->handler_data[0];
  12.345 ++
  12.346 ++  for (s = file->the_bfd->sections; s != NULL; s = s->next)
  12.347 ++    {
  12.348 ++      const char *sname = bfd_get_section_name (file->the_bfd, s);
  12.349 ++      bfd_boolean skip = !match_simple_wild (wildsec0->spec.name, sname);
  12.350 ++
  12.351 ++      if (!skip)
  12.352 ++	walk_wild_consider_section (ptr, file, s, wildsec0, callback, data);
  12.353 ++    }
  12.354 ++}
  12.355 ++
  12.356 ++static void
  12.357 ++walk_wild_section_specs2_wild1 (lang_wild_statement_type *ptr,
  12.358 ++				lang_input_statement_type *file,
  12.359 ++				callback_t callback,
  12.360 ++				void *data)
  12.361 ++{
  12.362 ++  asection *s;
  12.363 ++  struct wildcard_list *sec0 = ptr->handler_data[0];
  12.364 ++  struct wildcard_list *wildsec1 = ptr->handler_data[1];
  12.365 ++  bfd_boolean multiple_sections_found;
  12.366 ++  asection *s0 = find_section (file, sec0, &multiple_sections_found);
  12.367 ++
  12.368 ++  if (multiple_sections_found)
  12.369 ++    {
  12.370 ++      walk_wild_section_general (ptr, file, callback, data);
  12.371 ++      return;
  12.372 ++    }
  12.373 ++
  12.374 ++  /* Note that if the section was not found, s0 is NULL and
  12.375 ++     we'll simply never succeed the s == s0 test below.  */
  12.376 ++  for (s = file->the_bfd->sections; s != NULL; s = s->next)
  12.377 ++    {
  12.378 ++      /* Recall that in this code path, a section cannot satisfy more
  12.379 ++	 than one spec, so if s == s0 then it cannot match
  12.380 ++	 wildspec1.  */
  12.381 ++      if (s == s0)
  12.382 ++	walk_wild_consider_section (ptr, file, s, sec0, callback, data);
  12.383 ++      else
  12.384 ++	{
  12.385 ++	  const char *sname = bfd_get_section_name (file->the_bfd, s);
  12.386 ++	  bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname);
  12.387 ++
  12.388 ++	  if (!skip)
  12.389 ++	    walk_wild_consider_section (ptr, file, s, wildsec1, callback,
  12.390 ++					data);
  12.391 ++	}
  12.392 ++    }
  12.393 ++}
  12.394 ++
  12.395 ++static void
  12.396 ++walk_wild_section_specs3_wild2 (lang_wild_statement_type *ptr,
  12.397 ++				lang_input_statement_type *file,
  12.398 ++				callback_t callback,
  12.399 ++				void *data)
  12.400 ++{
  12.401 ++  asection *s;
  12.402 ++  struct wildcard_list *sec0 = ptr->handler_data[0];
  12.403 ++  struct wildcard_list *wildsec1 = ptr->handler_data[1];
  12.404 ++  struct wildcard_list *wildsec2 = ptr->handler_data[2];
  12.405 ++  bfd_boolean multiple_sections_found;
  12.406 ++  asection *s0 = find_section (file, sec0, &multiple_sections_found);
  12.407 ++
  12.408 ++  if (multiple_sections_found)
  12.409 ++    {
  12.410 ++      walk_wild_section_general (ptr, file, callback, data);
  12.411 ++      return;
  12.412 ++    }
  12.413 ++
  12.414 ++  for (s = file->the_bfd->sections; s != NULL; s = s->next)
  12.415 ++    {
  12.416 ++      if (s == s0)
  12.417 ++	walk_wild_consider_section (ptr, file, s, sec0, callback, data);
  12.418 ++      else
  12.419 ++	{
  12.420 ++	  const char *sname = bfd_get_section_name (file->the_bfd, s);
  12.421 ++	  bfd_boolean skip = !match_simple_wild (wildsec1->spec.name, sname);
  12.422 ++
  12.423 ++	  if (!skip)
  12.424 ++	    walk_wild_consider_section (ptr, file, s, wildsec1, callback, data);
  12.425 ++	  else
  12.426 ++	    {
  12.427 ++	      skip = !match_simple_wild (wildsec2->spec.name, sname);
  12.428 ++	      if (!skip)
  12.429 ++		walk_wild_consider_section (ptr, file, s, wildsec2, callback,
  12.430 ++					    data);
  12.431 ++	    }
  12.432 ++	}
  12.433 ++    }
  12.434 ++}
  12.435 ++
  12.436 ++static void
  12.437 ++walk_wild_section_specs4_wild2 (lang_wild_statement_type *ptr,
  12.438 ++				lang_input_statement_type *file,
  12.439 ++				callback_t callback,
  12.440 ++				void *data)
  12.441 ++{
  12.442 ++  asection *s;
  12.443 ++  struct wildcard_list *sec0 = ptr->handler_data[0];
  12.444 ++  struct wildcard_list *sec1 = ptr->handler_data[1];
  12.445 ++  struct wildcard_list *wildsec2 = ptr->handler_data[2];
  12.446 ++  struct wildcard_list *wildsec3 = ptr->handler_data[3];
  12.447 ++  bfd_boolean multiple_sections_found;
  12.448 ++  asection *s0 = find_section (file, sec0, &multiple_sections_found), *s1;
  12.449 ++
  12.450 ++  if (multiple_sections_found)
  12.451 ++    {
  12.452 ++      walk_wild_section_general (ptr, file, callback, data);
  12.453 ++      return;
  12.454 ++    }
  12.455 ++
  12.456 ++  s1 = find_section (file, sec1, &multiple_sections_found);
  12.457 ++  if (multiple_sections_found)
  12.458 ++    {
  12.459 ++      walk_wild_section_general (ptr, file, callback, data);
  12.460 ++      return;
  12.461 ++    }
  12.462 ++
  12.463 ++  for (s = file->the_bfd->sections; s != NULL; s = s->next)
  12.464 ++    {
  12.465 ++      if (s == s0)
  12.466 ++	walk_wild_consider_section (ptr, file, s, sec0, callback, data);
  12.467 ++      else
  12.468 ++	if (s == s1)
  12.469 ++	  walk_wild_consider_section (ptr, file, s, sec1, callback, data);
  12.470 ++	else
  12.471 ++	  {
  12.472 ++	    const char *sname = bfd_get_section_name (file->the_bfd, s);
  12.473 ++	    bfd_boolean skip = !match_simple_wild (wildsec2->spec.name,
  12.474 ++						   sname);
  12.475 ++
  12.476 ++	    if (!skip)
  12.477 ++	      walk_wild_consider_section (ptr, file, s, wildsec2, callback,
  12.478 ++					  data);
  12.479 ++	    else
  12.480 ++	      {
  12.481 ++		skip = !match_simple_wild (wildsec3->spec.name, sname);
  12.482 ++		if (!skip)
  12.483 ++		  walk_wild_consider_section (ptr, file, s, wildsec3,
  12.484 ++					      callback, data);
  12.485 ++	      }
  12.486 ++	  }
  12.487 ++    }
  12.488 ++}
  12.489 ++
  12.490 ++static void
  12.491 ++walk_wild_section (lang_wild_statement_type *ptr,
  12.492 ++		   lang_input_statement_type *file,
  12.493 ++		   callback_t callback,
  12.494 ++		   void *data)
  12.495 ++{
  12.496 ++  if (file->just_syms_flag)
  12.497 ++    return;
  12.498 ++
  12.499 ++  (*ptr->walk_wild_section_handler) (ptr, file, callback, data);
  12.500 ++}
  12.501 ++
  12.502 ++/* Returns TRUE when name1 is a wildcard spec that might match
  12.503 ++   something name2 can match.  We're conservative: we return FALSE
  12.504 ++   only if the prefixes of name1 and name2 are different up to the
  12.505 ++   first wildcard character.  */
  12.506 ++
  12.507 ++static bfd_boolean
  12.508 ++wild_spec_can_overlap (const char *name1, const char *name2)
  12.509 ++{
  12.510 ++  size_t prefix1_len = strcspn (name1, "?*[");
  12.511 ++  size_t prefix2_len = strcspn (name2, "?*[");
  12.512 ++  size_t min_prefix_len;
  12.513 ++
  12.514 ++  /* Note that if there is no wildcard character, then we treat the
  12.515 ++     terminating 0 as part of the prefix.  Thus ".text" won't match
  12.516 ++     ".text." or ".text.*", for example.  */
  12.517 ++  if (name1[prefix1_len] == '\0')
  12.518 ++    prefix1_len++;
  12.519 ++  if (name2[prefix2_len] == '\0')
  12.520 ++    prefix2_len++;
  12.521 ++
  12.522 ++  min_prefix_len = prefix1_len < prefix2_len ? prefix1_len : prefix2_len;
  12.523 ++
  12.524 ++  return memcmp (name1, name2, min_prefix_len) == 0;
  12.525 ++}
  12.526 ++
  12.527 ++/* Select specialized code to handle various kinds of wildcard
  12.528 ++   statements.  */
  12.529 ++
  12.530 ++static void
  12.531 ++analyze_walk_wild_section_handler (lang_wild_statement_type *ptr)
  12.532 ++{
  12.533 ++  int sec_count = 0;
  12.534 ++  int wild_name_count = 0;
  12.535 ++  struct wildcard_list *sec;
  12.536 ++  int signature;
  12.537 ++  int data_counter;
  12.538 ++
  12.539 ++  ptr->walk_wild_section_handler = walk_wild_section_general;
  12.540 ++
  12.541 ++  /* Count how many wildcard_specs there are, and how many of those
  12.542 ++     actually use wildcards in the name.  Also, bail out if any of the
  12.543 ++     wildcard names are NULL. (Can this actually happen?
  12.544 ++     walk_wild_section used to test for it.)  And bail out if any
  12.545 ++     of the wildcards are more complex than a simple string
  12.546 ++     ending in a single '*'.  */
  12.547 ++  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
  12.548 ++    {
  12.549 ++      ++sec_count;
  12.550 ++      if (sec->spec.name == NULL)
  12.551 ++	return;
  12.552 ++      if (wildcardp (sec->spec.name))
  12.553 ++	{
  12.554 ++	  ++wild_name_count;
  12.555 ++	  if (!is_simple_wild (sec->spec.name))
  12.556 ++	    return;
  12.557 ++	}
  12.558 ++    }
  12.559 ++
  12.560 ++  /* The zero-spec case would be easy to optimize but it doesn't
  12.561 ++     happen in practice.  Likewise, more than 4 specs doesn't
  12.562 ++     happen in practice.  */
  12.563 ++  if (sec_count == 0 || sec_count > 4)
  12.564 ++    return;
  12.565 ++
  12.566 ++  /* Check that no two specs can match the same section.  */
  12.567 ++  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
  12.568 ++    {
  12.569 ++      struct wildcard_list *sec2;
  12.570 ++      for (sec2 = sec->next; sec2 != NULL; sec2 = sec2->next)
  12.571 ++	{
  12.572 ++	  if (wild_spec_can_overlap (sec->spec.name, sec2->spec.name))
  12.573 ++	    return;
  12.574 ++	}
  12.575 ++    }
  12.576 ++
  12.577 ++  signature = (sec_count << 8) + wild_name_count;
  12.578 ++  switch (signature)
  12.579 ++    {
  12.580 ++    case 0x0100:
  12.581 ++      ptr->walk_wild_section_handler = walk_wild_section_specs1_wild0;
  12.582 ++      break;
  12.583 ++    case 0x0101:
  12.584 ++      ptr->walk_wild_section_handler = walk_wild_section_specs1_wild1;
  12.585 ++      break;
  12.586 ++    case 0x0201:
  12.587 ++      ptr->walk_wild_section_handler = walk_wild_section_specs2_wild1;
  12.588 ++      break;
  12.589 ++    case 0x0302:
  12.590 ++      ptr->walk_wild_section_handler = walk_wild_section_specs3_wild2;
  12.591 ++      break;
  12.592 ++    case 0x0402:
  12.593 ++      ptr->walk_wild_section_handler = walk_wild_section_specs4_wild2;
  12.594 ++      break;
  12.595 ++    default:
  12.596 ++      return;
  12.597 ++    }
  12.598 ++
  12.599 ++  /* Now fill the data array with pointers to the specs, first the
  12.600 ++     specs with non-wildcard names, then the specs with wildcard
  12.601 ++     names.  It's OK to process the specs in different order from the
  12.602 ++     given order, because we've already determined that no section
  12.603 ++     will match more than one spec.  */
  12.604 ++  data_counter = 0;
  12.605 ++  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
  12.606 ++    if (!wildcardp (sec->spec.name))
  12.607 ++      ptr->handler_data[data_counter++] = sec;
  12.608 ++  for (sec = ptr->section_list; sec != NULL; sec = sec->next)
  12.609 ++    if (wildcardp (sec->spec.name))
  12.610 ++      ptr->handler_data[data_counter++] = sec;
  12.611 ++}
  12.612 ++
  12.613 + /* Handle a wild statement for a single file F.  */
  12.614 + 
  12.615 + static void
  12.616 +@@ -1175,17 +1559,12 @@
  12.617 + static void
  12.618 + init_os (lang_output_section_statement_type *s)
  12.619 + {
  12.620 +-  lean_section_userdata_type *new;
  12.621 +-
  12.622 +   if (s->bfd_section != NULL)
  12.623 +     return;
  12.624 + 
  12.625 +   if (strcmp (s->name, DISCARD_SECTION_NAME) == 0)
  12.626 +     einfo (_("%P%F: Illegal use of `%s' section\n"), DISCARD_SECTION_NAME);
  12.627 + 
  12.628 +-  new = stat_alloc (SECTION_USERDATA_SIZE);
  12.629 +-  memset (new, 0, SECTION_USERDATA_SIZE);
  12.630 +-
  12.631 +   s->bfd_section = bfd_get_section_by_name (output_bfd, s->name);
  12.632 +   if (s->bfd_section == NULL)
  12.633 +     s->bfd_section = bfd_make_section (output_bfd, s->name);
  12.634 +@@ -1199,7 +1578,14 @@
  12.635 +   /* We initialize an output sections output offset to minus its own
  12.636 +      vma to allow us to output a section through itself.  */
  12.637 +   s->bfd_section->output_offset = 0;
  12.638 +-  get_userdata (s->bfd_section) = new;
  12.639 ++  if (!command_line.reduce_memory_overheads)
  12.640 ++    {
  12.641 ++      fat_section_userdata_type *new
  12.642 ++	= stat_alloc (sizeof (fat_section_userdata_type));
  12.643 ++      memset (new, 0, sizeof (fat_section_userdata_type));
  12.644 ++      get_userdata (s->bfd_section) = new;
  12.645 ++    }
  12.646 ++
  12.647 + 
  12.648 +   /* If there is a base address, make sure that any sections it might
  12.649 +      mention are initialized.  */
  12.650 +@@ -4939,6 +5325,7 @@
  12.651 +   new->section_list = section_list;
  12.652 +   new->keep_sections = keep_sections;
  12.653 +   lang_list_init (&new->children);
  12.654 ++  analyze_walk_wild_section_handler (new);
  12.655 + }
  12.656 + 
  12.657 + void
  12.658 +Index: src/ld/ldlang.h
  12.659 +===================================================================
  12.660 +RCS file: /cvs/src/src/ld/ldlang.h,v
  12.661 +retrieving revision 1.44
  12.662 +retrieving revision 1.45
  12.663 +diff -u -r1.44 -r1.45
  12.664 +--- binutils/ld/ldlang.h.old	3 Mar 2005 11:51:58 -0000	1.44
  12.665 ++++ binutils/ld/ldlang.h	6 Apr 2005 15:33:03 -0000	1.45
  12.666 +@@ -298,7 +298,17 @@
  12.667 +   union lang_statement_union *file;
  12.668 + } lang_afile_asection_pair_statement_type;
  12.669 + 
  12.670 +-typedef struct lang_wild_statement_struct
  12.671 ++typedef struct lang_wild_statement_struct lang_wild_statement_type;
  12.672 ++
  12.673 ++typedef void (*callback_t) (lang_wild_statement_type *, struct wildcard_list *,
  12.674 ++			    asection *, lang_input_statement_type *, void *);
  12.675 ++
  12.676 ++typedef void (*walk_wild_section_handler_t) (lang_wild_statement_type *,
  12.677 ++					     lang_input_statement_type *,
  12.678 ++					     callback_t callback,
  12.679 ++					     void *data);
  12.680 ++
  12.681 ++struct lang_wild_statement_struct
  12.682 + {
  12.683 +   lang_statement_header_type header;
  12.684 +   const char *filename;
  12.685 +@@ -306,7 +316,10 @@
  12.686 +   struct wildcard_list *section_list;
  12.687 +   bfd_boolean keep_sections;
  12.688 +   lang_statement_list_type children;
  12.689 +-} lang_wild_statement_type;
  12.690 ++
  12.691 ++  walk_wild_section_handler_t walk_wild_section_handler;
  12.692 ++  struct wildcard_list *handler_data[4];
  12.693 ++};
  12.694 + 
  12.695 + typedef struct lang_address_statement_struct
  12.696 + {
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/patches/binutils/2.16.1a/140-cross-gprof.patch	Sun Sep 11 18:18:53 2011 +0200
    13.3 @@ -0,0 +1,22 @@
    13.4 +--- binutils-2.15/configure.old	2004-07-21 21:36:47.000000000 -0700
    13.5 ++++ binutils-2.15/configure	2004-07-21 21:37:08.000000000 -0700
    13.6 +@@ -999,7 +999,7 @@
    13.7 + 
    13.8 + # Some tools are only suitable for building in a "native" situation.
    13.9 + # Remove these if host!=target.  
   13.10 +-native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   13.11 ++native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   13.12 + 
   13.13 + # Similarly, some are only suitable for cross toolchains.
   13.14 + # Remove these if host=target.
   13.15 +--- binutils-2.15/configure.in.old	2004-07-21 21:37:19.000000000 -0700
   13.16 ++++ binutils-2.15/configure.in	2004-07-21 21:37:34.000000000 -0700
   13.17 +@@ -236,7 +236,7 @@
   13.18 + 
   13.19 + # Some tools are only suitable for building in a "native" situation.
   13.20 + # Remove these if host!=target.  
   13.21 +-native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   13.22 ++native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   13.23 + 
   13.24 + # Similarly, some are only suitable for cross toolchains.
   13.25 + # Remove these if host=target.
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/patches/binutils/2.16.1a/150-stabs-tweak.patch	Sun Sep 11 18:18:53 2011 +0200
    14.3 @@ -0,0 +1,28 @@
    14.4 +Signed-off-by: dank@kegel.com
    14.5 +
    14.6 +See http://sourceware.org/ml/binutils/2005-12/msg00270.html
    14.7 +http://sourceware.org/ml/binutils-cvs/2005-12/msg00139.html
    14.8 +
    14.9 +STABS hash table size change, backported from the binutils CVS tree.  Here's
   14.10 +the CVS log comment for the original change:
   14.11 +
   14.12 +revision 1.25
   14.13 +date: 2005/12/29 10:29:23;  author: nickc;  state: Exp;  lines: +2 -3
   14.14 +(_bfd_link_section_stabs): Use bfd_hash_table_init rather than
   14.15 +bfd_hash_table_init_n(...,251) so that the size of the hash table can be
   14.16 +controlled by the user.
   14.17 +
   14.18 +--- binutils/bfd/stabs.c.old	4 May 2005 15:53:39 -0000	1.24
   14.19 ++++ binutils/bfd/stabs.c	29 Dec 2005 10:29:23 -0000	1.25
   14.20 +@@ -194,9 +194,8 @@
   14.21 + 	goto error_return;
   14.22 +       /* Make sure the first byte is zero.  */
   14.23 +       (void) _bfd_stringtab_add (sinfo->strings, "", TRUE, TRUE);
   14.24 +-      if (! bfd_hash_table_init_n (&sinfo->includes,
   14.25 +-				   stab_link_includes_newfunc,
   14.26 +-				   251))
   14.27 ++      if (! bfd_hash_table_init (&sinfo->includes,
   14.28 ++				 stab_link_includes_newfunc))
   14.29 + 	goto error_return;
   14.30 +       sinfo->stabstr = bfd_make_section_anyway (abfd, ".stabstr");
   14.31 +       if (sinfo->stabstr == NULL)
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/patches/binutils/2.16.1a/160-i386-no-divide-comment.patch	Sun Sep 11 18:18:53 2011 +0200
    15.3 @@ -0,0 +1,40 @@
    15.4 +diff -durN binutils-2.16.1.orig/gas/config/tc-i386.c binutils-2.16.1/gas/config/tc-i386.c
    15.5 +--- binutils-2.16.1.orig/gas/config/tc-i386.c	2005-04-13 19:58:42.000000000 +0200
    15.6 ++++ binutils-2.16.1/gas/config/tc-i386.c	2008-09-22 09:00:09.000000000 +0200
    15.7 +@@ -192,16 +192,10 @@
    15.8 + #endif
    15.9 + 	;
   15.10 + 
   15.11 +-#if (defined (TE_I386AIX)				\
   15.12 +-     || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))	\
   15.13 +-	 && !defined (TE_LINUX)				\
   15.14 +- 	 && !defined (TE_NETWARE)			\
   15.15 +-	 && !defined (TE_FreeBSD)			\
   15.16 +-	 && !defined (TE_NetBSD)))
   15.17 + /* This array holds the chars that always start a comment.  If the
   15.18 +    pre-processor is disabled, these aren't very useful.  */
   15.19 +-const char comment_chars[] = "#/";
   15.20 +-#define PREFIX_SEPARATOR '\\'
   15.21 ++const char comment_chars[] = "#";
   15.22 ++#define PREFIX_SEPARATOR '/'
   15.23 + 
   15.24 + /* This array holds the chars that only start a comment at the beginning of
   15.25 +    a line.  If the line seems to have the form '# 123 filename'
   15.26 +@@ -211,16 +205,7 @@
   15.27 +    #NO_APP at the beginning of its output.
   15.28 +    Also note that comments started like this one will always work if
   15.29 +    '/' isn't otherwise defined.  */
   15.30 +-const char line_comment_chars[] = "#";
   15.31 +-
   15.32 +-#else
   15.33 +-/* Putting '/' here makes it impossible to use the divide operator.
   15.34 +-   However, we need it for compatibility with SVR4 systems.  */
   15.35 +-const char comment_chars[] = "#";
   15.36 +-#define PREFIX_SEPARATOR '/'
   15.37 +-
   15.38 +-const char line_comment_chars[] = "/#";
   15.39 +-#endif
   15.40 ++const char line_comment_chars[] = "#/";
   15.41 + 
   15.42 + const char line_separator_chars[] = ";";
   15.43 + 
    16.1 --- a/patches/binutils/2.17/100-uclibc-conf.patch	Sun Sep 11 18:26:12 2011 +0200
    16.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.3 @@ -1,149 +0,0 @@
    16.4 -diff -dur binutils-2.17.old/bfd/configure binutils-2.17/bfd/configure
    16.5 ---- binutils-2.17.old/bfd/configure	2006-06-23 20:17:03.000000000 +0200
    16.6 -+++ binutils-2.17/bfd/configure	2007-05-01 18:26:03.000000000 +0200
    16.7 -@@ -3576,7 +3576,7 @@
    16.8 -   ;;
    16.9 - 
   16.10 - # This must be Linux ELF.
   16.11 --linux-gnu*)
   16.12 -+linux-gnu*|linux-uclibc*)
   16.13 -   lt_cv_deplibs_check_method=pass_all
   16.14 -   ;;
   16.15 - 
   16.16 -diff -dur binutils-2.17.old/binutils/configure binutils-2.17/binutils/configure
   16.17 ---- binutils-2.17.old/binutils/configure	2006-04-06 23:49:29.000000000 +0200
   16.18 -+++ binutils-2.17/binutils/configure	2007-05-01 18:26:03.000000000 +0200
   16.19 -@@ -3411,7 +3411,7 @@
   16.20 -   ;;
   16.21 - 
   16.22 - # This must be Linux ELF.
   16.23 --linux-gnu*)
   16.24 -+linux-gnu*|linux-uclibc*)
   16.25 -   lt_cv_deplibs_check_method=pass_all
   16.26 -   ;;
   16.27 - 
   16.28 -diff -dur binutils-2.17.old/configure binutils-2.17/configure
   16.29 ---- binutils-2.17.old/configure	2006-04-06 23:49:25.000000000 +0200
   16.30 -+++ binutils-2.17/configure	2007-05-01 18:26:03.000000000 +0200
   16.31 -@@ -1276,7 +1276,7 @@
   16.32 -   am33_2.0-*-linux*)
   16.33 -     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   16.34 -     ;;
   16.35 --  sh-*-linux*)
   16.36 -+  sh*-*-linux*)
   16.37 -     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   16.38 -     ;;    
   16.39 -   sh*-*-pe|mips*-*-pe|*arm-wince-pe)
   16.40 -@@ -1584,7 +1584,7 @@
   16.41 -   romp-*-*)
   16.42 -     noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
   16.43 -     ;;
   16.44 --  sh-*-* | sh64-*-*)
   16.45 -+  sh*-*-* | sh64-*-*)
   16.46 -     case "${host}" in
   16.47 -       i[3456789]86-*-vsta) ;; # don't add gprof back in
   16.48 -       i[3456789]86-*-go32*) ;; # don't add gprof back in
   16.49 -diff -dur binutils-2.17.old/configure.in binutils-2.17/configure.in
   16.50 ---- binutils-2.17.old/configure.in	2006-06-23 20:19:53.000000000 +0200
   16.51 -+++ binutils-2.17/configure.in	2007-05-01 18:26:03.000000000 +0200
   16.52 -@@ -468,7 +468,7 @@
   16.53 -   am33_2.0-*-linux*)
   16.54 -     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   16.55 -     ;;
   16.56 --  sh-*-linux*)
   16.57 -+  sh*-*-linux*)
   16.58 -     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   16.59 -     ;;    
   16.60 -   sh*-*-pe|mips*-*-pe|*arm-wince-pe)
   16.61 -@@ -776,7 +776,7 @@
   16.62 -   romp-*-*)
   16.63 -     noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
   16.64 -     ;;
   16.65 --  sh-*-* | sh64-*-*)
   16.66 -+  sh*-*-* | sh64-*-*)
   16.67 -     case "${host}" in
   16.68 -       i[[3456789]]86-*-vsta) ;; # don't add gprof back in
   16.69 -       i[[3456789]]86-*-go32*) ;; # don't add gprof back in
   16.70 -diff -dur binutils-2.17.old/gas/configure binutils-2.17/gas/configure
   16.71 ---- binutils-2.17.old/gas/configure	2006-04-06 23:49:31.000000000 +0200
   16.72 -+++ binutils-2.17/gas/configure	2007-05-01 18:26:03.000000000 +0200
   16.73 -@@ -3411,7 +3411,7 @@
   16.74 -   ;;
   16.75 - 
   16.76 - # This must be Linux ELF.
   16.77 --linux-gnu*)
   16.78 -+linux-gnu*|linux-uclibc*)
   16.79 -   lt_cv_deplibs_check_method=pass_all
   16.80 -   ;;
   16.81 - 
   16.82 -diff -dur binutils-2.17.old/gprof/configure binutils-2.17/gprof/configure
   16.83 ---- binutils-2.17.old/gprof/configure	2006-04-06 23:49:33.000000000 +0200
   16.84 -+++ binutils-2.17/gprof/configure	2007-05-01 18:26:03.000000000 +0200
   16.85 -@@ -3414,6 +3414,11 @@
   16.86 -   lt_cv_deplibs_check_method=pass_all
   16.87 -   ;;
   16.88 - 
   16.89 -+linux-uclibc*)
   16.90 -+  lt_cv_deplibs_check_method=pass_all
   16.91 -+  lt_cv_file_magic_test_file=`echo /lib/libuClibc-*.so`
   16.92 -+  ;;
   16.93 -+
   16.94 - netbsd* | knetbsd*-gnu)
   16.95 -   if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
   16.96 -     lt_cv_deplibs_check_method='match_pattern /lib[^/\.]+\.so\.[0-9]+\.[0-9]+$'
   16.97 -diff -dur binutils-2.17.old/ld/configure binutils-2.17/ld/configure
   16.98 ---- binutils-2.17.old/ld/configure	2006-04-11 12:36:26.000000000 +0200
   16.99 -+++ binutils-2.17/ld/configure	2007-05-01 18:26:03.000000000 +0200
  16.100 -@@ -3413,7 +3413,7 @@
  16.101 -   ;;
  16.102 - 
  16.103 - # This must be Linux ELF.
  16.104 --linux-gnu*)
  16.105 -+linux-gnu*|linux-uclibc*)
  16.106 -   lt_cv_deplibs_check_method=pass_all
  16.107 -   ;;
  16.108 - 
  16.109 -diff -dur binutils-2.17.old/libtool.m4 binutils-2.17/libtool.m4
  16.110 ---- binutils-2.17.old/libtool.m4	2005-12-27 17:37:57.000000000 +0100
  16.111 -+++ binutils-2.17/libtool.m4	2007-05-01 18:26:03.000000000 +0200
  16.112 -@@ -739,7 +739,7 @@
  16.113 -   ;;
  16.114 - 
  16.115 - # This must be Linux ELF.
  16.116 --linux-gnu*)
  16.117 -+linux-gnu*|linux-uclibc*)
  16.118 -   lt_cv_deplibs_check_method=pass_all
  16.119 -   ;;
  16.120 - 
  16.121 -diff -dur binutils-2.17.old/ltconfig binutils-2.17/ltconfig
  16.122 ---- binutils-2.17.old/ltconfig	2005-07-16 04:36:38.000000000 +0200
  16.123 -+++ binutils-2.17/ltconfig	2007-05-01 18:26:03.000000000 +0200
  16.124 -@@ -602,6 +602,7 @@
  16.125 - 
  16.126 - # Transform linux* to *-*-linux-gnu*, to support old configure scripts.
  16.127 - case $host_os in
  16.128 -+linux-uclibc*) ;;
  16.129 - linux-gnu*) ;;
  16.130 - linux*) host=`echo $host | sed 's/^\(.*-.*-linux\)\(.*\)$/\1-gnu\2/'`
  16.131 - esac
  16.132 -@@ -1247,7 +1248,7 @@
  16.133 -   ;;
  16.134 - 
  16.135 - # This must be Linux ELF.
  16.136 --linux-gnu*)
  16.137 -+linux-gnu*|linux-uclibc*)
  16.138 -   version_type=linux
  16.139 -   need_lib_prefix=no
  16.140 -   need_version=no
  16.141 -diff -dur binutils-2.17.old/opcodes/configure binutils-2.17/opcodes/configure
  16.142 ---- binutils-2.17.old/opcodes/configure	2006-02-17 15:36:28.000000000 +0100
  16.143 -+++ binutils-2.17/opcodes/configure	2007-05-01 18:26:03.000000000 +0200
  16.144 -@@ -3579,7 +3579,7 @@
  16.145 -   ;;
  16.146 - 
  16.147 - # This must be Linux ELF.
  16.148 --linux-gnu*)
  16.149 -+linux-gnu*|linux-uclibc*)
  16.150 -   lt_cv_deplibs_check_method=pass_all
  16.151 -   ;;
  16.152 - 
    17.1 --- a/patches/binutils/2.17/110-arm-eabi-conf.patch	Sun Sep 11 18:26:12 2011 +0200
    17.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.3 @@ -1,24 +0,0 @@
    17.4 -diff -dur binutils-2.17.old/configure binutils-2.17/configure
    17.5 ---- binutils-2.17.old/configure	2007-05-01 18:26:03.000000000 +0200
    17.6 -+++ binutils-2.17/configure	2007-05-01 18:26:06.000000000 +0200
    17.7 -@@ -1305,7 +1305,7 @@
    17.8 -   arm-*-elf* | strongarm-*-elf* | xscale-*-elf* | arm*-*-eabi* )
    17.9 -     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   17.10 -     ;;
   17.11 --  arm*-*-linux-gnueabi)
   17.12 -+  arm*-*-linux-gnueabi | arm*-*-linux-uclibcgnueabi)
   17.13 -     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   17.14 -     noconfigdirs="$noconfigdirs target-libjava target-libobjc"
   17.15 -     ;;
   17.16 -diff -dur binutils-2.17.old/configure.in binutils-2.17/configure.in
   17.17 ---- binutils-2.17.old/configure.in	2007-05-01 18:26:03.000000000 +0200
   17.18 -+++ binutils-2.17/configure.in	2007-05-01 18:26:06.000000000 +0200
   17.19 -@@ -497,7 +497,7 @@
   17.20 -   arm-*-elf* | strongarm-*-elf* | xscale-*-elf* | arm*-*-eabi* )
   17.21 -     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   17.22 -     ;;
   17.23 --  arm*-*-linux-gnueabi)
   17.24 -+  arm*-*-linux-gnueabi | arm*-*-linux-uclibcgnueabi)
   17.25 -     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   17.26 -     noconfigdirs="$noconfigdirs target-libjava target-libobjc"
   17.27 -     ;;
    18.1 --- a/patches/binutils/2.17/120-makeinfo-version.patch	Sun Sep 11 18:26:12 2011 +0200
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,16 +0,0 @@
    18.4 -diff -u binutils-2.18-orig/configure binutils-2.18/configure
    18.5 ---- binutils-2.18-orig/configure	2007-08-06 16:29:40.000000000 -0400
    18.6 -+++ binutils-2.18/configure	2007-09-27 22:41:51.000000000 -0400
    18.7 -@@ -6125,10 +6125,10 @@
    18.8 -   *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
    18.9 -   *)
   18.10 - 
   18.11 --    # For an installed makeinfo, we require it to be from texinfo 4.4 or
   18.12 -+    # For an installed makeinfo, we require it to be from texinfo 4.6 or
   18.13 -     # higher, else we use the "missing" dummy.
   18.14 -     if ${MAKEINFO} --version \
   18.15 --       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])' >/dev/null 2>&1; then
   18.16 -+       | egrep 'texinfo[^0-9]*(4\.([6-9]|[1-9][0-9])|[5-9]|[1-9][0-9])' >/dev/null 2>&1; then
   18.17 -       :
   18.18 -     else
   18.19 -       MAKEINFO="$MISSING makeinfo"
    19.1 --- a/patches/binutils/2.17/130-ld_makefile_patch.patch	Sun Sep 11 18:26:12 2011 +0200
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,24 +0,0 @@
    19.4 -diff -dur binutils-2.17.old/ld/Makefile.am binutils-2.17/ld/Makefile.am
    19.5 ---- binutils-2.17.old/ld/Makefile.am	2006-06-03 06:45:50.000000000 +0200
    19.6 -+++ binutils-2.17/ld/Makefile.am	2007-05-01 18:26:09.000000000 +0200
    19.7 -@@ -20,7 +20,7 @@
    19.8 - # We put the scripts in the directory $(scriptdir)/ldscripts.
    19.9 - # We can't put the scripts in $(datadir) because the SEARCH_DIR
   19.10 - # directives need to be different for native and cross linkers.
   19.11 --scriptdir = $(tooldir)/lib
   19.12 -+scriptdir = $(libdir)
   19.13 - 
   19.14 - EMUL = @EMUL@
   19.15 - EMULATION_OFILES = @EMULATION_OFILES@
   19.16 -diff -dur binutils-2.17.old/ld/Makefile.in binutils-2.17/ld/Makefile.in
   19.17 ---- binutils-2.17.old/ld/Makefile.in	2006-06-03 06:45:50.000000000 +0200
   19.18 -+++ binutils-2.17/ld/Makefile.in	2007-05-01 18:26:09.000000000 +0200
   19.19 -@@ -269,7 +269,7 @@
   19.20 - # We put the scripts in the directory $(scriptdir)/ldscripts.
   19.21 - # We can't put the scripts in $(datadir) because the SEARCH_DIR
   19.22 - # directives need to be different for native and cross linkers.
   19.23 --scriptdir = $(tooldir)/lib
   19.24 -+scriptdir = $(libdir)
   19.25 - BASEDIR = $(srcdir)/..
   19.26 - BFDDIR = $(BASEDIR)/bfd
   19.27 - INCDIR = $(BASEDIR)/include
    20.1 --- a/patches/binutils/2.17/140-better_file_error.patch	Sun Sep 11 18:26:12 2011 +0200
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,17 +0,0 @@
    20.4 -diff -dur binutils-2.17.old/bfd/opncls.c binutils-2.17/bfd/opncls.c
    20.5 ---- binutils-2.17.old/bfd/opncls.c	2006-03-16 13:20:16.000000000 +0100
    20.6 -+++ binutils-2.17/bfd/opncls.c	2007-05-01 18:26:11.000000000 +0200
    20.7 -@@ -158,6 +158,13 @@
    20.8 - {
    20.9 -   bfd *nbfd;
   20.10 -   const bfd_target *target_vec;
   20.11 -+  struct stat s;
   20.12 -+
   20.13 -+  if (stat (filename, &s) == 0)
   20.14 -+    if (S_ISDIR(s.st_mode)) {
   20.15 -+      bfd_set_error (bfd_error_file_not_recognized);
   20.16 -+      return NULL;
   20.17 -+    }
   20.18 - 
   20.19 -   nbfd = _bfd_new_bfd ();
   20.20 -   if (nbfd == NULL)
    21.1 --- a/patches/binutils/2.17/150-check_ldrunpath_length.patch	Sun Sep 11 18:26:12 2011 +0200
    21.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.3 @@ -1,21 +0,0 @@
    21.4 -diff -dur binutils-2.17.old/ld/emultempl/elf32.em binutils-2.17/ld/emultempl/elf32.em
    21.5 ---- binutils-2.17.old/ld/emultempl/elf32.em	2006-06-12 15:05:04.000000000 +0200
    21.6 -+++ binutils-2.17/ld/emultempl/elf32.em	2007-05-01 18:26:13.000000000 +0200
    21.7 -@@ -970,6 +970,8 @@
    21.8 - 	      && command_line.rpath == NULL)
    21.9 - 	    {
   21.10 - 	      lib_path = (const char *) getenv ("LD_RUN_PATH");
   21.11 -+	      if ((lib_path) && (strlen (lib_path) == 0))
   21.12 -+		  lib_path = NULL;
   21.13 - 	      if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
   21.14 - 						      force))
   21.15 - 		break;
   21.16 -@@ -1154,6 +1156,8 @@
   21.17 -   rpath = command_line.rpath;
   21.18 -   if (rpath == NULL)
   21.19 -     rpath = (const char *) getenv ("LD_RUN_PATH");
   21.20 -+  if ((rpath) && (strlen (rpath) == 0))
   21.21 -+      rpath = NULL;
   21.22 -   if (! (bfd_elf_size_dynamic_sections
   21.23 - 	 (output_bfd, command_line.soname, rpath,
   21.24 - 	  command_line.filter_shlib,
    22.1 --- a/patches/binutils/2.17/160-mips-ELF_MAXPAGESIZE-4K.patch	Sun Sep 11 18:26:12 2011 +0200
    22.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.3 @@ -1,28 +0,0 @@
    22.4 -diff -dur binutils-2.17.old/bfd/elf32-mips.c binutils-2.17/bfd/elf32-mips.c
    22.5 ---- binutils-2.17.old/bfd/elf32-mips.c	2006-03-22 10:28:13.000000000 +0100
    22.6 -+++ binutils-2.17/bfd/elf32-mips.c	2007-05-01 18:26:15.000000000 +0200
    22.7 -@@ -1617,7 +1617,9 @@
    22.8 - 
    22.9 - /* The SVR4 MIPS ABI says that this should be 0x10000, and Linux uses
   22.10 -    page sizes of up to that limit, so we need to respect it.  */
   22.11 --#define ELF_MAXPAGESIZE			0x10000
   22.12 -+/*#define ELF_MAXPAGESIZE			0x10000*/
   22.13 -+/* Use 4K to shrink the elf header.  NOT for general use! */
   22.14 -+#define ELF_MAXPAGESIZE			0x1000
   22.15 - #define elf32_bed			elf32_tradbed
   22.16 - 
   22.17 - /* Include the target file again for this target.  */
   22.18 -diff -dur binutils-2.17.old/bfd/elfn32-mips.c binutils-2.17/bfd/elfn32-mips.c
   22.19 ---- binutils-2.17.old/bfd/elfn32-mips.c	2005-11-23 15:04:17.000000000 +0100
   22.20 -+++ binutils-2.17/bfd/elfn32-mips.c	2007-05-01 18:26:15.000000000 +0200
   22.21 -@@ -2402,7 +2402,9 @@
   22.22 - 
   22.23 - /* The SVR4 MIPS ABI says that this should be 0x10000, and Linux uses
   22.24 -    page sizes of up to that limit, so we need to respect it.  */
   22.25 --#define ELF_MAXPAGESIZE			0x10000
   22.26 -+/*#define ELF_MAXPAGESIZE			0x10000*/
   22.27 -+/* Use 4K to shrink the elf header.  NOT for general use! */
   22.28 -+#define ELF_MAXPAGESIZE			0x1000
   22.29 - #define elf32_bed			elf32_tradbed
   22.30 - 
   22.31 - /* Include the target file again for this target.  */
    23.1 --- a/patches/binutils/2.17/170-bfd-hash-tweak.patch	Sun Sep 11 18:26:12 2011 +0200
    23.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.3 @@ -1,23 +0,0 @@
    23.4 -Signed-off-by: dank@kegel.com
    23.5 -
    23.6 -Raising the size of the hash table is a noticable win when linking 
    23.7 -at least one large app.  
    23.8 -
    23.9 -There was a patch,
   23.10 -http://sources.redhat.com/ml/binutils/2004-06/msg00165.html
   23.11 -to do this dynamically.  No idea why that didn't make it in.
   23.12 -So this tiny change to raise the default size is just
   23.13 -a stopgap for now.
   23.14 -
   23.15 -
   23.16 ---- binutils-2.17/bfd/hash.c.old	2006-03-02 23:01:39.000000000 -0800
   23.17 -+++ binutils-2.17/bfd/hash.c	2006-03-02 23:01:58.000000000 -0800
   23.18 -@@ -298,7 +298,7 @@
   23.19 - */
   23.20 - 
   23.21 - /* The default number of entries to use when creating a hash table.  */
   23.22 --#define DEFAULT_SIZE 4051
   23.23 -+#define DEFAULT_SIZE 32749
   23.24 - static size_t bfd_default_hash_table_size = DEFAULT_SIZE;
   23.25 - 
   23.26 - /* Create a new hash table, given a number of entries.  */
    24.1 --- a/patches/binutils/2.17/180-psignal.patch	Sun Sep 11 18:26:12 2011 +0200
    24.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.3 @@ -1,29 +0,0 @@
    24.4 -Make psignal prototype in libiberty match that in glibc.
    24.5 -
    24.6 -Fixes:
    24.7 -
    24.8 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c: In function `psignal':
    24.9 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `signo' doesn't match prototype
   24.10 -/usr/include/signal.h:131: prototype declaration
   24.11 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `message' doesn't match prototype
   24.12 -/usr/include/signal.h:131: prototype declaration
   24.13 -gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:568: warning: comparison between signed and unsigned
   24.14 -mprotect... make[1]: *** [strsignal.o] Error 1
   24.15 -make[1]: Leaving directory `/export/hda3/dkegel/queue/jobdir.produser_cpsm17/crosstool-0.32/build/i686-unknown-linux-gnu/gcc-2.95.3-glibc-2.1.3/build-binutils/libiberty'
   24.16 -make: *** [all-libiberty] Error 2
   24.17 -
   24.18 -when building on red hat 7.1
   24.19 -though it's a bit of a mystery why libiberty's psignal is being compiled at
   24.20 -all, since red hat 7.1's glibc supports psignal (hence the error message)
   24.21 -
   24.22 ---- binutils-2.17/libiberty/strsignal.c.old	2005-04-18 13:57:40.000000000 -0700
   24.23 -+++ binutils-2.17/libiberty/strsignal.c	2005-04-18 13:59:09.000000000 -0700
   24.24 -@@ -536,7 +536,7 @@
   24.25 - 
   24.26 - /*
   24.27 - 
   24.28 --@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
   24.29 -+@deftypefn Supplemental void psignal (int @var{signo}, const char *@var{message})
   24.30 - 
   24.31 - Print @var{message} to the standard error, followed by a colon,
   24.32 - followed by the description of the signal specified by @var{signo},
    25.1 --- a/patches/binutils/2.17/190-skip-comments.patch	Sun Sep 11 18:26:12 2011 +0200
    25.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.3 @@ -1,95 +0,0 @@
    25.4 -[removed first hunk so it would apply to 2.16.1 - copyright date already updated - dank]
    25.5 -
    25.6 -Retrieved from http://sources.redhat.com/ml/binutils/2004-04/msg00646.html
    25.7 -Fixes
    25.8 -localealias.s:544: Error: junk at end of line, first unrecognized character is `,' 
    25.9 -when building glibc-2.3.2 with gcc-3.4.0 and binutils-2.15.90.0.3
   25.10 -
   25.11 -Paths adjusted to match crosstool's patcher.
   25.12 -
   25.13 -Message-Id: m3n052qw2g.fsf@whitebox.m5r.de
   25.14 -From: Andreas Schwab <schwab at suse dot de>
   25.15 -To: Nathan Sidwell <nathan at codesourcery dot com>
   25.16 -Cc: Ian Lance Taylor <ian at wasabisystems dot com>, binutils at sources dot redhat dot com
   25.17 -Date: Fri, 23 Apr 2004 22:27:19 +0200
   25.18 -Subject: Re: demand_empty_rest_of_line and ignore_rest_of_line
   25.19 -
   25.20 -Nathan Sidwell <nathan@codesourcery.com> writes:
   25.21 -
   25.22 -> Index: read.c
   25.23 -> ===================================================================
   25.24 -> RCS file: /cvs/src/src/gas/read.c,v
   25.25 -> retrieving revision 1.76
   25.26 -> diff -c -3 -p -r1.76 read.c
   25.27 -> *** read.c	12 Mar 2004 17:48:12 -0000	1.76
   25.28 -> --- read.c	18 Mar 2004 09:56:05 -0000
   25.29 -> *************** read_a_source_file (char *name)
   25.30 -> *** 1053,1059 ****
   25.31 ->   #endif
   25.32 ->   	  input_line_pointer--;
   25.33 ->   	  /* Report unknown char as ignored.  */
   25.34 -> ! 	  ignore_rest_of_line ();
   25.35 ->   	}
   25.36 ->   
   25.37 ->   #ifdef md_after_pass_hook
   25.38 -> --- 1053,1059 ----
   25.39 ->   #endif
   25.40 ->   	  input_line_pointer--;
   25.41 ->   	  /* Report unknown char as ignored.  */
   25.42 -> ! 	  demand_empty_rest_of_line ();
   25.43 ->   	}
   25.44 ->   
   25.45 ->   #ifdef md_after_pass_hook
   25.46 -
   25.47 -This means that the unknown character is no longer ignored, despite the
   25.48 -comment.  As a side effect a line starting with a line comment character
   25.49 -not followed by APP in NO_APP mode now triggers an error instead of just a
   25.50 -warning, breaking builds of glibc on m68k-linux.  Earlier in
   25.51 -read_a_source_file where #APP is handled there is another comment that
   25.52 -claims that unknown comments are ignored, when in fact they aren't (only
   25.53 -the initial line comment character is skipped).
   25.54 -
   25.55 -Note that the presence of #APP will mess up the line counters, but
   25.56 -that appears to be difficult to fix.
   25.57 -
   25.58 -Andreas.
   25.59 -
   25.60 -2004-04-23  Andreas Schwab  <schwab@suse.de>
   25.61 -
   25.62 -	* read.c (read_a_source_file): Ignore unknown text after line
   25.63 -	comment character.  Fix misleading comment.
   25.64 -
   25.65 ---- binutils/gas/read.c.~1.78.~	2004-04-23 08:58:23.000000000 +0200
   25.66 -+++ binutils/gas/read.c	2004-04-23 21:49:01.000000000 +0200
   25.67 -@@ -1008,10 +1008,14 @@ read_a_source_file (char *name)
   25.68 - 	      unsigned int new_length;
   25.69 - 	      char *tmp_buf = 0;
   25.70 - 
   25.71 --	      bump_line_counters ();
   25.72 - 	      s = input_line_pointer;
   25.73 - 	      if (strncmp (s, "APP\n", 4))
   25.74 --		continue;	/* We ignore it */
   25.75 -+		{
   25.76 -+		  /* We ignore it */
   25.77 -+		  ignore_rest_of_line ();
   25.78 -+		  continue;
   25.79 -+		}
   25.80 -+	      bump_line_counters ();
   25.81 - 	      s += 4;
   25.82 - 
   25.83 - 	      sb_new (&sbuf);
   25.84 -@@ -1110,7 +1110,7 @@ read_a_source_file (char *name)
   25.85 - 	    continue;
   25.86 - #endif
   25.87 - 	  input_line_pointer--;
   25.88 --	  /* Report unknown char as ignored.  */
   25.89 -+	  /* Report unknown char as error.  */
   25.90 - 	  demand_empty_rest_of_line ();
   25.91 - 	}
   25.92 - 
   25.93 -
   25.94 --- 
   25.95 -Andreas Schwab, SuSE Labs, schwab@suse.de
   25.96 -SuSE Linux AG, Maxfeldstra&#xC3;e 5, 90409 N&#xC3;rnberg, Germany
   25.97 -Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
   25.98 -"And now for something completely different."
    26.1 --- a/patches/binutils/2.17/200-cross-gprof.patch	Sun Sep 11 18:26:12 2011 +0200
    26.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.3 @@ -1,22 +0,0 @@
    26.4 ---- binutils-2.17/configure.old	2004-07-21 21:36:47.000000000 -0700
    26.5 -+++ binutils-2.17/configure	2004-07-21 21:37:08.000000000 -0700
    26.6 -@@ -1022,7 +1022,7 @@
    26.7 - 
    26.8 - # Some tools are only suitable for building in a "native" situation.
    26.9 - # Remove these if host!=target.  
   26.10 --native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   26.11 -+native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   26.12 - 
   26.13 - # Similarly, some are only suitable for cross toolchains.
   26.14 - # Remove these if host=target.
   26.15 ---- binutils-2.17/configure.in.old	2004-07-21 21:37:19.000000000 -0700
   26.16 -+++ binutils-2.17/configure.in	2004-07-21 21:37:34.000000000 -0700
   26.17 -@@ -227,7 +227,7 @@
   26.18 - 
   26.19 - # Some tools are only suitable for building in a "native" situation.
   26.20 - # Remove these if host!=target.  
   26.21 --native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   26.22 -+native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   26.23 - 
   26.24 - # Similarly, some are only suitable for cross toolchains.
   26.25 - # Remove these if host=target.
    27.1 --- a/patches/binutils/2.17/210-i386-no-divide-comment.patch	Sun Sep 11 18:26:12 2011 +0200
    27.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.3 @@ -1,64 +0,0 @@
    27.4 -diff -durN binutils-2.17.orig/gas/config/tc-i386.c binutils-2.17/gas/config/tc-i386.c
    27.5 ---- binutils-2.17.orig/gas/config/tc-i386.c	2006-04-07 08:40:57.000000000 +0200
    27.6 -+++ binutils-2.17/gas/config/tc-i386.c	2008-09-22 09:06:07.000000000 +0200
    27.7 -@@ -196,24 +196,10 @@
    27.8 - #endif
    27.9 - 	;
   27.10 - 
   27.11 --#if (defined (TE_I386AIX)				\
   27.12 --     || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))	\
   27.13 --	 && !defined (TE_GNU)				\
   27.14 --	 && !defined (TE_LINUX)				\
   27.15 -- 	 && !defined (TE_NETWARE)			\
   27.16 --	 && !defined (TE_FreeBSD)			\
   27.17 --	 && !defined (TE_NetBSD)))
   27.18 - /* This array holds the chars that always start a comment.  If the
   27.19 --   pre-processor is disabled, these aren't very useful.  The option
   27.20 --   --divide will remove '/' from this list.  */
   27.21 --const char *i386_comment_chars = "#/";
   27.22 --#define SVR4_COMMENT_CHARS 1
   27.23 --#define PREFIX_SEPARATOR '\\'
   27.24 --
   27.25 --#else
   27.26 -+   pre-processor is disabled, these aren't very useful.  */
   27.27 - const char *i386_comment_chars = "#";
   27.28 - #define PREFIX_SEPARATOR '/'
   27.29 --#endif
   27.30 - 
   27.31 - /* This array holds the chars that only start a comment at the beginning of
   27.32 -    a line.  If the line seems to have the form '# 123 filename'
   27.33 -@@ -5486,20 +5472,6 @@
   27.34 -       break;
   27.35 - 
   27.36 -     case OPTION_DIVIDE:
   27.37 --#ifdef SVR4_COMMENT_CHARS
   27.38 --      {
   27.39 --	char *n, *t;
   27.40 --	const char *s;
   27.41 --
   27.42 --	n = (char *) xmalloc (strlen (i386_comment_chars) + 1);
   27.43 --	t = n;
   27.44 --	for (s = i386_comment_chars; *s != '\0'; s++)
   27.45 --	  if (*s != '/')
   27.46 --	    *t++ = *s;
   27.47 --	*t = '\0';
   27.48 --	i386_comment_chars = n;
   27.49 --      }
   27.50 --#endif
   27.51 -       break;
   27.52 - 
   27.53 -     default:
   27.54 -@@ -5525,13 +5497,8 @@
   27.55 -   fprintf (stream, _("\
   27.56 -   -s                      ignored\n"));
   27.57 - #endif
   27.58 --#ifdef SVR4_COMMENT_CHARS
   27.59 --  fprintf (stream, _("\
   27.60 --  --divide                do not treat `/' as a comment character\n"));
   27.61 --#else
   27.62 -   fprintf (stream, _("\
   27.63 -   --divide                ignored\n"));
   27.64 --#endif
   27.65 - }
   27.66 - 
   27.67 - #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/patches/binutils/2.17a/100-uclibc-conf.patch	Sun Sep 11 18:18:53 2011 +0200
    28.3 @@ -0,0 +1,149 @@
    28.4 +diff -dur binutils-2.17.old/bfd/configure binutils-2.17/bfd/configure
    28.5 +--- binutils-2.17.old/bfd/configure	2006-06-23 20:17:03.000000000 +0200
    28.6 ++++ binutils-2.17/bfd/configure	2007-05-01 18:26:03.000000000 +0200
    28.7 +@@ -3576,7 +3576,7 @@
    28.8 +   ;;
    28.9 + 
   28.10 + # This must be Linux ELF.
   28.11 +-linux-gnu*)
   28.12 ++linux-gnu*|linux-uclibc*)
   28.13 +   lt_cv_deplibs_check_method=pass_all
   28.14 +   ;;
   28.15 + 
   28.16 +diff -dur binutils-2.17.old/binutils/configure binutils-2.17/binutils/configure
   28.17 +--- binutils-2.17.old/binutils/configure	2006-04-06 23:49:29.000000000 +0200
   28.18 ++++ binutils-2.17/binutils/configure	2007-05-01 18:26:03.000000000 +0200
   28.19 +@@ -3411,7 +3411,7 @@
   28.20 +   ;;
   28.21 + 
   28.22 + # This must be Linux ELF.
   28.23 +-linux-gnu*)
   28.24 ++linux-gnu*|linux-uclibc*)
   28.25 +   lt_cv_deplibs_check_method=pass_all
   28.26 +   ;;
   28.27 + 
   28.28 +diff -dur binutils-2.17.old/configure binutils-2.17/configure
   28.29 +--- binutils-2.17.old/configure	2006-04-06 23:49:25.000000000 +0200
   28.30 ++++ binutils-2.17/configure	2007-05-01 18:26:03.000000000 +0200
   28.31 +@@ -1276,7 +1276,7 @@
   28.32 +   am33_2.0-*-linux*)
   28.33 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   28.34 +     ;;
   28.35 +-  sh-*-linux*)
   28.36 ++  sh*-*-linux*)
   28.37 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   28.38 +     ;;    
   28.39 +   sh*-*-pe|mips*-*-pe|*arm-wince-pe)
   28.40 +@@ -1584,7 +1584,7 @@
   28.41 +   romp-*-*)
   28.42 +     noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
   28.43 +     ;;
   28.44 +-  sh-*-* | sh64-*-*)
   28.45 ++  sh*-*-* | sh64-*-*)
   28.46 +     case "${host}" in
   28.47 +       i[3456789]86-*-vsta) ;; # don't add gprof back in
   28.48 +       i[3456789]86-*-go32*) ;; # don't add gprof back in
   28.49 +diff -dur binutils-2.17.old/configure.in binutils-2.17/configure.in
   28.50 +--- binutils-2.17.old/configure.in	2006-06-23 20:19:53.000000000 +0200
   28.51 ++++ binutils-2.17/configure.in	2007-05-01 18:26:03.000000000 +0200
   28.52 +@@ -468,7 +468,7 @@
   28.53 +   am33_2.0-*-linux*)
   28.54 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   28.55 +     ;;
   28.56 +-  sh-*-linux*)
   28.57 ++  sh*-*-linux*)
   28.58 +     noconfigdirs="$noconfigdirs ${libgcj} target-newlib target-libgloss"
   28.59 +     ;;    
   28.60 +   sh*-*-pe|mips*-*-pe|*arm-wince-pe)
   28.61 +@@ -776,7 +776,7 @@
   28.62 +   romp-*-*)
   28.63 +     noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
   28.64 +     ;;
   28.65 +-  sh-*-* | sh64-*-*)
   28.66 ++  sh*-*-* | sh64-*-*)
   28.67 +     case "${host}" in
   28.68 +       i[[3456789]]86-*-vsta) ;; # don't add gprof back in
   28.69 +       i[[3456789]]86-*-go32*) ;; # don't add gprof back in
   28.70 +diff -dur binutils-2.17.old/gas/configure binutils-2.17/gas/configure
   28.71 +--- binutils-2.17.old/gas/configure	2006-04-06 23:49:31.000000000 +0200
   28.72 ++++ binutils-2.17/gas/configure	2007-05-01 18:26:03.000000000 +0200
   28.73 +@@ -3411,7 +3411,7 @@
   28.74 +   ;;
   28.75 + 
   28.76 + # This must be Linux ELF.
   28.77 +-linux-gnu*)
   28.78 ++linux-gnu*|linux-uclibc*)
   28.79 +   lt_cv_deplibs_check_method=pass_all
   28.80 +   ;;
   28.81 + 
   28.82 +diff -dur binutils-2.17.old/gprof/configure binutils-2.17/gprof/configure
   28.83 +--- binutils-2.17.old/gprof/configure	2006-04-06 23:49:33.000000000 +0200
   28.84 ++++ binutils-2.17/gprof/configure	2007-05-01 18:26:03.000000000 +0200
   28.85 +@@ -3414,6 +3414,11 @@
   28.86 +   lt_cv_deplibs_check_method=pass_all
   28.87 +   ;;
   28.88 + 
   28.89 ++linux-uclibc*)
   28.90 ++  lt_cv_deplibs_check_method=pass_all
   28.91 ++  lt_cv_file_magic_test_file=`echo /lib/libuClibc-*.so`
   28.92 ++  ;;
   28.93 ++
   28.94 + netbsd* | knetbsd*-gnu)
   28.95 +   if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
   28.96 +     lt_cv_deplibs_check_method='match_pattern /lib[^/\.]+\.so\.[0-9]+\.[0-9]+$'
   28.97 +diff -dur binutils-2.17.old/ld/configure binutils-2.17/ld/configure
   28.98 +--- binutils-2.17.old/ld/configure	2006-04-11 12:36:26.000000000 +0200
   28.99 ++++ binutils-2.17/ld/configure	2007-05-01 18:26:03.000000000 +0200
  28.100 +@@ -3413,7 +3413,7 @@
  28.101 +   ;;
  28.102 + 
  28.103 + # This must be Linux ELF.
  28.104 +-linux-gnu*)
  28.105 ++linux-gnu*|linux-uclibc*)
  28.106 +   lt_cv_deplibs_check_method=pass_all
  28.107 +   ;;
  28.108 + 
  28.109 +diff -dur binutils-2.17.old/libtool.m4 binutils-2.17/libtool.m4
  28.110 +--- binutils-2.17.old/libtool.m4	2005-12-27 17:37:57.000000000 +0100
  28.111 ++++ binutils-2.17/libtool.m4	2007-05-01 18:26:03.000000000 +0200
  28.112 +@@ -739,7 +739,7 @@
  28.113 +   ;;
  28.114 + 
  28.115 + # This must be Linux ELF.
  28.116 +-linux-gnu*)
  28.117 ++linux-gnu*|linux-uclibc*)
  28.118 +   lt_cv_deplibs_check_method=pass_all
  28.119 +   ;;
  28.120 + 
  28.121 +diff -dur binutils-2.17.old/ltconfig binutils-2.17/ltconfig
  28.122 +--- binutils-2.17.old/ltconfig	2005-07-16 04:36:38.000000000 +0200
  28.123 ++++ binutils-2.17/ltconfig	2007-05-01 18:26:03.000000000 +0200
  28.124 +@@ -602,6 +602,7 @@
  28.125 + 
  28.126 + # Transform linux* to *-*-linux-gnu*, to support old configure scripts.
  28.127 + case $host_os in
  28.128 ++linux-uclibc*) ;;
  28.129 + linux-gnu*) ;;
  28.130 + linux*) host=`echo $host | sed 's/^\(.*-.*-linux\)\(.*\)$/\1-gnu\2/'`
  28.131 + esac
  28.132 +@@ -1247,7 +1248,7 @@
  28.133 +   ;;
  28.134 + 
  28.135 + # This must be Linux ELF.
  28.136 +-linux-gnu*)
  28.137 ++linux-gnu*|linux-uclibc*)
  28.138 +   version_type=linux
  28.139 +   need_lib_prefix=no
  28.140 +   need_version=no
  28.141 +diff -dur binutils-2.17.old/opcodes/configure binutils-2.17/opcodes/configure
  28.142 +--- binutils-2.17.old/opcodes/configure	2006-02-17 15:36:28.000000000 +0100
  28.143 ++++ binutils-2.17/opcodes/configure	2007-05-01 18:26:03.000000000 +0200
  28.144 +@@ -3579,7 +3579,7 @@
  28.145 +   ;;
  28.146 + 
  28.147 + # This must be Linux ELF.
  28.148 +-linux-gnu*)
  28.149 ++linux-gnu*|linux-uclibc*)
  28.150 +   lt_cv_deplibs_check_method=pass_all
  28.151 +   ;;
  28.152 + 
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/patches/binutils/2.17a/110-arm-eabi-conf.patch	Sun Sep 11 18:18:53 2011 +0200
    29.3 @@ -0,0 +1,24 @@
    29.4 +diff -dur binutils-2.17.old/configure binutils-2.17/configure
    29.5 +--- binutils-2.17.old/configure	2007-05-01 18:26:03.000000000 +0200
    29.6 ++++ binutils-2.17/configure	2007-05-01 18:26:06.000000000 +0200
    29.7 +@@ -1305,7 +1305,7 @@
    29.8 +   arm-*-elf* | strongarm-*-elf* | xscale-*-elf* | arm*-*-eabi* )
    29.9 +     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   29.10 +     ;;
   29.11 +-  arm*-*-linux-gnueabi)
   29.12 ++  arm*-*-linux-gnueabi | arm*-*-linux-uclibcgnueabi)
   29.13 +     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   29.14 +     noconfigdirs="$noconfigdirs target-libjava target-libobjc"
   29.15 +     ;;
   29.16 +diff -dur binutils-2.17.old/configure.in binutils-2.17/configure.in
   29.17 +--- binutils-2.17.old/configure.in	2007-05-01 18:26:03.000000000 +0200
   29.18 ++++ binutils-2.17/configure.in	2007-05-01 18:26:06.000000000 +0200
   29.19 +@@ -497,7 +497,7 @@
   29.20 +   arm-*-elf* | strongarm-*-elf* | xscale-*-elf* | arm*-*-eabi* )
   29.21 +     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   29.22 +     ;;
   29.23 +-  arm*-*-linux-gnueabi)
   29.24 ++  arm*-*-linux-gnueabi | arm*-*-linux-uclibcgnueabi)
   29.25 +     noconfigdirs="$noconfigdirs target-libffi target-qthreads"
   29.26 +     noconfigdirs="$noconfigdirs target-libjava target-libobjc"
   29.27 +     ;;
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/patches/binutils/2.17a/120-makeinfo-version.patch	Sun Sep 11 18:18:53 2011 +0200
    30.3 @@ -0,0 +1,16 @@
    30.4 +diff -u binutils-2.18-orig/configure binutils-2.18/configure
    30.5 +--- binutils-2.18-orig/configure	2007-08-06 16:29:40.000000000 -0400
    30.6 ++++ binutils-2.18/configure	2007-09-27 22:41:51.000000000 -0400
    30.7 +@@ -6125,10 +6125,10 @@
    30.8 +   *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
    30.9 +   *)
   30.10 + 
   30.11 +-    # For an installed makeinfo, we require it to be from texinfo 4.4 or
   30.12 ++    # For an installed makeinfo, we require it to be from texinfo 4.6 or
   30.13 +     # higher, else we use the "missing" dummy.
   30.14 +     if ${MAKEINFO} --version \
   30.15 +-       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])' >/dev/null 2>&1; then
   30.16 ++       | egrep 'texinfo[^0-9]*(4\.([6-9]|[1-9][0-9])|[5-9]|[1-9][0-9])' >/dev/null 2>&1; then
   30.17 +       :
   30.18 +     else
   30.19 +       MAKEINFO="$MISSING makeinfo"
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/patches/binutils/2.17a/130-ld_makefile_patch.patch	Sun Sep 11 18:18:53 2011 +0200
    31.3 @@ -0,0 +1,24 @@
    31.4 +diff -dur binutils-2.17.old/ld/Makefile.am binutils-2.17/ld/Makefile.am
    31.5 +--- binutils-2.17.old/ld/Makefile.am	2006-06-03 06:45:50.000000000 +0200
    31.6 ++++ binutils-2.17/ld/Makefile.am	2007-05-01 18:26:09.000000000 +0200
    31.7 +@@ -20,7 +20,7 @@
    31.8 + # We put the scripts in the directory $(scriptdir)/ldscripts.
    31.9 + # We can't put the scripts in $(datadir) because the SEARCH_DIR
   31.10 + # directives need to be different for native and cross linkers.
   31.11 +-scriptdir = $(tooldir)/lib
   31.12 ++scriptdir = $(libdir)
   31.13 + 
   31.14 + EMUL = @EMUL@
   31.15 + EMULATION_OFILES = @EMULATION_OFILES@
   31.16 +diff -dur binutils-2.17.old/ld/Makefile.in binutils-2.17/ld/Makefile.in
   31.17 +--- binutils-2.17.old/ld/Makefile.in	2006-06-03 06:45:50.000000000 +0200
   31.18 ++++ binutils-2.17/ld/Makefile.in	2007-05-01 18:26:09.000000000 +0200
   31.19 +@@ -269,7 +269,7 @@
   31.20 + # We put the scripts in the directory $(scriptdir)/ldscripts.
   31.21 + # We can't put the scripts in $(datadir) because the SEARCH_DIR
   31.22 + # directives need to be different for native and cross linkers.
   31.23 +-scriptdir = $(tooldir)/lib
   31.24 ++scriptdir = $(libdir)
   31.25 + BASEDIR = $(srcdir)/..
   31.26 + BFDDIR = $(BASEDIR)/bfd
   31.27 + INCDIR = $(BASEDIR)/include
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/patches/binutils/2.17a/140-better_file_error.patch	Sun Sep 11 18:18:53 2011 +0200
    32.3 @@ -0,0 +1,17 @@
    32.4 +diff -dur binutils-2.17.old/bfd/opncls.c binutils-2.17/bfd/opncls.c
    32.5 +--- binutils-2.17.old/bfd/opncls.c	2006-03-16 13:20:16.000000000 +0100
    32.6 ++++ binutils-2.17/bfd/opncls.c	2007-05-01 18:26:11.000000000 +0200
    32.7 +@@ -158,6 +158,13 @@
    32.8 + {
    32.9 +   bfd *nbfd;
   32.10 +   const bfd_target *target_vec;
   32.11 ++  struct stat s;
   32.12 ++
   32.13 ++  if (stat (filename, &s) == 0)
   32.14 ++    if (S_ISDIR(s.st_mode)) {
   32.15 ++      bfd_set_error (bfd_error_file_not_recognized);
   32.16 ++      return NULL;
   32.17 ++    }
   32.18 + 
   32.19 +   nbfd = _bfd_new_bfd ();
   32.20 +   if (nbfd == NULL)
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/patches/binutils/2.17a/150-check_ldrunpath_length.patch	Sun Sep 11 18:18:53 2011 +0200
    33.3 @@ -0,0 +1,21 @@
    33.4 +diff -dur binutils-2.17.old/ld/emultempl/elf32.em binutils-2.17/ld/emultempl/elf32.em
    33.5 +--- binutils-2.17.old/ld/emultempl/elf32.em	2006-06-12 15:05:04.000000000 +0200
    33.6 ++++ binutils-2.17/ld/emultempl/elf32.em	2007-05-01 18:26:13.000000000 +0200
    33.7 +@@ -970,6 +970,8 @@
    33.8 + 	      && command_line.rpath == NULL)
    33.9 + 	    {
   33.10 + 	      lib_path = (const char *) getenv ("LD_RUN_PATH");
   33.11 ++	      if ((lib_path) && (strlen (lib_path) == 0))
   33.12 ++		  lib_path = NULL;
   33.13 + 	      if (gld${EMULATION_NAME}_search_needed (lib_path, &n,
   33.14 + 						      force))
   33.15 + 		break;
   33.16 +@@ -1154,6 +1156,8 @@
   33.17 +   rpath = command_line.rpath;
   33.18 +   if (rpath == NULL)
   33.19 +     rpath = (const char *) getenv ("LD_RUN_PATH");
   33.20 ++  if ((rpath) && (strlen (rpath) == 0))
   33.21 ++      rpath = NULL;
   33.22 +   if (! (bfd_elf_size_dynamic_sections
   33.23 + 	 (output_bfd, command_line.soname, rpath,
   33.24 + 	  command_line.filter_shlib,
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/patches/binutils/2.17a/160-mips-ELF_MAXPAGESIZE-4K.patch	Sun Sep 11 18:18:53 2011 +0200
    34.3 @@ -0,0 +1,28 @@
    34.4 +diff -dur binutils-2.17.old/bfd/elf32-mips.c binutils-2.17/bfd/elf32-mips.c
    34.5 +--- binutils-2.17.old/bfd/elf32-mips.c	2006-03-22 10:28:13.000000000 +0100
    34.6 ++++ binutils-2.17/bfd/elf32-mips.c	2007-05-01 18:26:15.000000000 +0200
    34.7 +@@ -1617,7 +1617,9 @@
    34.8 + 
    34.9 + /* The SVR4 MIPS ABI says that this should be 0x10000, and Linux uses
   34.10 +    page sizes of up to that limit, so we need to respect it.  */
   34.11 +-#define ELF_MAXPAGESIZE			0x10000
   34.12 ++/*#define ELF_MAXPAGESIZE			0x10000*/
   34.13 ++/* Use 4K to shrink the elf header.  NOT for general use! */
   34.14 ++#define ELF_MAXPAGESIZE			0x1000
   34.15 + #define elf32_bed			elf32_tradbed
   34.16 + 
   34.17 + /* Include the target file again for this target.  */
   34.18 +diff -dur binutils-2.17.old/bfd/elfn32-mips.c binutils-2.17/bfd/elfn32-mips.c
   34.19 +--- binutils-2.17.old/bfd/elfn32-mips.c	2005-11-23 15:04:17.000000000 +0100
   34.20 ++++ binutils-2.17/bfd/elfn32-mips.c	2007-05-01 18:26:15.000000000 +0200
   34.21 +@@ -2402,7 +2402,9 @@
   34.22 + 
   34.23 + /* The SVR4 MIPS ABI says that this should be 0x10000, and Linux uses
   34.24 +    page sizes of up to that limit, so we need to respect it.  */
   34.25 +-#define ELF_MAXPAGESIZE			0x10000
   34.26 ++/*#define ELF_MAXPAGESIZE			0x10000*/
   34.27 ++/* Use 4K to shrink the elf header.  NOT for general use! */
   34.28 ++#define ELF_MAXPAGESIZE			0x1000
   34.29 + #define elf32_bed			elf32_tradbed
   34.30 + 
   34.31 + /* Include the target file again for this target.  */
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/patches/binutils/2.17a/170-bfd-hash-tweak.patch	Sun Sep 11 18:18:53 2011 +0200
    35.3 @@ -0,0 +1,23 @@
    35.4 +Signed-off-by: dank@kegel.com
    35.5 +
    35.6 +Raising the size of the hash table is a noticable win when linking 
    35.7 +at least one large app.  
    35.8 +
    35.9 +There was a patch,
   35.10 +http://sources.redhat.com/ml/binutils/2004-06/msg00165.html
   35.11 +to do this dynamically.  No idea why that didn't make it in.
   35.12 +So this tiny change to raise the default size is just
   35.13 +a stopgap for now.
   35.14 +
   35.15 +
   35.16 +--- binutils-2.17/bfd/hash.c.old	2006-03-02 23:01:39.000000000 -0800
   35.17 ++++ binutils-2.17/bfd/hash.c	2006-03-02 23:01:58.000000000 -0800
   35.18 +@@ -298,7 +298,7 @@
   35.19 + */
   35.20 + 
   35.21 + /* The default number of entries to use when creating a hash table.  */
   35.22 +-#define DEFAULT_SIZE 4051
   35.23 ++#define DEFAULT_SIZE 32749
   35.24 + static size_t bfd_default_hash_table_size = DEFAULT_SIZE;
   35.25 + 
   35.26 + /* Create a new hash table, given a number of entries.  */
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/patches/binutils/2.17a/180-psignal.patch	Sun Sep 11 18:18:53 2011 +0200
    36.3 @@ -0,0 +1,29 @@
    36.4 +Make psignal prototype in libiberty match that in glibc.
    36.5 +
    36.6 +Fixes:
    36.7 +
    36.8 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c: In function `psignal':
    36.9 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `signo' doesn't match prototype
   36.10 +/usr/include/signal.h:131: prototype declaration
   36.11 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:563: argument `message' doesn't match prototype
   36.12 +/usr/include/signal.h:131: prototype declaration
   36.13 +gcc-2.95.3-glibc-2.1.3/binutils-2.15/libiberty/strsignal.c:568: warning: comparison between signed and unsigned
   36.14 +mprotect... make[1]: *** [strsignal.o] Error 1
   36.15 +make[1]: Leaving directory `/export/hda3/dkegel/queue/jobdir.produser_cpsm17/crosstool-0.32/build/i686-unknown-linux-gnu/gcc-2.95.3-glibc-2.1.3/build-binutils/libiberty'
   36.16 +make: *** [all-libiberty] Error 2
   36.17 +
   36.18 +when building on red hat 7.1
   36.19 +though it's a bit of a mystery why libiberty's psignal is being compiled at
   36.20 +all, since red hat 7.1's glibc supports psignal (hence the error message)
   36.21 +
   36.22 +--- binutils-2.17/libiberty/strsignal.c.old	2005-04-18 13:57:40.000000000 -0700
   36.23 ++++ binutils-2.17/libiberty/strsignal.c	2005-04-18 13:59:09.000000000 -0700
   36.24 +@@ -536,7 +536,7 @@
   36.25 + 
   36.26 + /*
   36.27 + 
   36.28 +-@deftypefn Supplemental void psignal (unsigned @var{signo}, char *@var{message})
   36.29 ++@deftypefn Supplemental void psignal (int @var{signo}, const char *@var{message})
   36.30 + 
   36.31 + Print @var{message} to the standard error, followed by a colon,
   36.32 + followed by the description of the signal specified by @var{signo},
    37.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    37.2 +++ b/patches/binutils/2.17a/190-skip-comments.patch	Sun Sep 11 18:18:53 2011 +0200
    37.3 @@ -0,0 +1,95 @@
    37.4 +[removed first hunk so it would apply to 2.16.1 - copyright date already updated - dank]
    37.5 +
    37.6 +Retrieved from http://sources.redhat.com/ml/binutils/2004-04/msg00646.html
    37.7 +Fixes
    37.8 +localealias.s:544: Error: junk at end of line, first unrecognized character is `,' 
    37.9 +when building glibc-2.3.2 with gcc-3.4.0 and binutils-2.15.90.0.3
   37.10 +
   37.11 +Paths adjusted to match crosstool's patcher.
   37.12 +
   37.13 +Message-Id: m3n052qw2g.fsf@whitebox.m5r.de
   37.14 +From: Andreas Schwab <schwab at suse dot de>
   37.15 +To: Nathan Sidwell <nathan at codesourcery dot com>
   37.16 +Cc: Ian Lance Taylor <ian at wasabisystems dot com>, binutils at sources dot redhat dot com
   37.17 +Date: Fri, 23 Apr 2004 22:27:19 +0200
   37.18 +Subject: Re: demand_empty_rest_of_line and ignore_rest_of_line
   37.19 +
   37.20 +Nathan Sidwell <nathan@codesourcery.com> writes:
   37.21 +
   37.22 +> Index: read.c
   37.23 +> ===================================================================
   37.24 +> RCS file: /cvs/src/src/gas/read.c,v
   37.25 +> retrieving revision 1.76
   37.26 +> diff -c -3 -p -r1.76 read.c
   37.27 +> *** read.c	12 Mar 2004 17:48:12 -0000	1.76
   37.28 +> --- read.c	18 Mar 2004 09:56:05 -0000
   37.29 +> *************** read_a_source_file (char *name)
   37.30 +> *** 1053,1059 ****
   37.31 +>   #endif
   37.32 +>   	  input_line_pointer--;
   37.33 +>   	  /* Report unknown char as ignored.  */
   37.34 +> ! 	  ignore_rest_of_line ();
   37.35 +>   	}
   37.36 +>   
   37.37 +>   #ifdef md_after_pass_hook
   37.38 +> --- 1053,1059 ----
   37.39 +>   #endif
   37.40 +>   	  input_line_pointer--;
   37.41 +>   	  /* Report unknown char as ignored.  */
   37.42 +> ! 	  demand_empty_rest_of_line ();
   37.43 +>   	}
   37.44 +>   
   37.45 +>   #ifdef md_after_pass_hook
   37.46 +
   37.47 +This means that the unknown character is no longer ignored, despite the
   37.48 +comment.  As a side effect a line starting with a line comment character
   37.49 +not followed by APP in NO_APP mode now triggers an error instead of just a
   37.50 +warning, breaking builds of glibc on m68k-linux.  Earlier in
   37.51 +read_a_source_file where #APP is handled there is another comment that
   37.52 +claims that unknown comments are ignored, when in fact they aren't (only
   37.53 +the initial line comment character is skipped).
   37.54 +
   37.55 +Note that the presence of #APP will mess up the line counters, but
   37.56 +that appears to be difficult to fix.
   37.57 +
   37.58 +Andreas.
   37.59 +
   37.60 +2004-04-23  Andreas Schwab  <schwab@suse.de>
   37.61 +
   37.62 +	* read.c (read_a_source_file): Ignore unknown text after line
   37.63 +	comment character.  Fix misleading comment.
   37.64 +
   37.65 +--- binutils/gas/read.c.~1.78.~	2004-04-23 08:58:23.000000000 +0200
   37.66 ++++ binutils/gas/read.c	2004-04-23 21:49:01.000000000 +0200
   37.67 +@@ -1008,10 +1008,14 @@ read_a_source_file (char *name)
   37.68 + 	      unsigned int new_length;
   37.69 + 	      char *tmp_buf = 0;
   37.70 + 
   37.71 +-	      bump_line_counters ();
   37.72 + 	      s = input_line_pointer;
   37.73 + 	      if (strncmp (s, "APP\n", 4))
   37.74 +-		continue;	/* We ignore it */
   37.75 ++		{
   37.76 ++		  /* We ignore it */
   37.77 ++		  ignore_rest_of_line ();
   37.78 ++		  continue;
   37.79 ++		}
   37.80 ++	      bump_line_counters ();
   37.81 + 	      s += 4;
   37.82 + 
   37.83 + 	      sb_new (&sbuf);
   37.84 +@@ -1110,7 +1110,7 @@ read_a_source_file (char *name)
   37.85 + 	    continue;
   37.86 + #endif
   37.87 + 	  input_line_pointer--;
   37.88 +-	  /* Report unknown char as ignored.  */
   37.89 ++	  /* Report unknown char as error.  */
   37.90 + 	  demand_empty_rest_of_line ();
   37.91 + 	}
   37.92 + 
   37.93 +
   37.94 +-- 
   37.95 +Andreas Schwab, SuSE Labs, schwab@suse.de
   37.96 +SuSE Linux AG, Maxfeldstra&#xC3;e 5, 90409 N&#xC3;rnberg, Germany
   37.97 +Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
   37.98 +"And now for something completely different."
    38.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    38.2 +++ b/patches/binutils/2.17a/200-cross-gprof.patch	Sun Sep 11 18:18:53 2011 +0200
    38.3 @@ -0,0 +1,22 @@
    38.4 +--- binutils-2.17/configure.old	2004-07-21 21:36:47.000000000 -0700
    38.5 ++++ binutils-2.17/configure	2004-07-21 21:37:08.000000000 -0700
    38.6 +@@ -1022,7 +1022,7 @@
    38.7 + 
    38.8 + # Some tools are only suitable for building in a "native" situation.
    38.9 + # Remove these if host!=target.  
   38.10 +-native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   38.11 ++native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   38.12 + 
   38.13 + # Similarly, some are only suitable for cross toolchains.
   38.14 + # Remove these if host=target.
   38.15 +--- binutils-2.17/configure.in.old	2004-07-21 21:37:19.000000000 -0700
   38.16 ++++ binutils-2.17/configure.in	2004-07-21 21:37:34.000000000 -0700
   38.17 +@@ -227,7 +227,7 @@
   38.18 + 
   38.19 + # Some tools are only suitable for building in a "native" situation.
   38.20 + # Remove these if host!=target.  
   38.21 +-native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff gprof target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   38.22 ++native_only="autoconf automake libtool fileutils find gawk gettext gzip hello indent m4 rcs recode sed shellutils tar textutils uudecode wdiff target-groff guile perl time ash bash bzip2 prms gnuserv target-gperf"
   38.23 + 
   38.24 + # Similarly, some are only suitable for cross toolchains.
   38.25 + # Remove these if host=target.
    39.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    39.2 +++ b/patches/binutils/2.17a/210-i386-no-divide-comment.patch	Sun Sep 11 18:18:53 2011 +0200
    39.3 @@ -0,0 +1,64 @@
    39.4 +diff -durN binutils-2.17.orig/gas/config/tc-i386.c binutils-2.17/gas/config/tc-i386.c
    39.5 +--- binutils-2.17.orig/gas/config/tc-i386.c	2006-04-07 08:40:57.000000000 +0200
    39.6 ++++ binutils-2.17/gas/config/tc-i386.c	2008-09-22 09:06:07.000000000 +0200
    39.7 +@@ -196,24 +196,10 @@
    39.8 + #endif
    39.9 + 	;
   39.10 + 
   39.11 +-#if (defined (TE_I386AIX)				\
   39.12 +-     || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))	\
   39.13 +-	 && !defined (TE_GNU)				\
   39.14 +-	 && !defined (TE_LINUX)				\
   39.15 +- 	 && !defined (TE_NETWARE)			\
   39.16 +-	 && !defined (TE_FreeBSD)			\
   39.17 +-	 && !defined (TE_NetBSD)))
   39.18 + /* This array holds the chars that always start a comment.  If the
   39.19 +-   pre-processor is disabled, these aren't very useful.  The option
   39.20 +-   --divide will remove '/' from this list.  */
   39.21 +-const char *i386_comment_chars = "#/";
   39.22 +-#define SVR4_COMMENT_CHARS 1
   39.23 +-#define PREFIX_SEPARATOR '\\'
   39.24 +-
   39.25 +-#else
   39.26 ++   pre-processor is disabled, these aren't very useful.  */
   39.27 + const char *i386_comment_chars = "#";
   39.28 + #define PREFIX_SEPARATOR '/'
   39.29 +-#endif
   39.30 + 
   39.31 + /* This array holds the chars that only start a comment at the beginning of
   39.32 +    a line.  If the line seems to have the form '# 123 filename'
   39.33 +@@ -5486,20 +5472,6 @@
   39.34 +       break;
   39.35 + 
   39.36 +     case OPTION_DIVIDE:
   39.37 +-#ifdef SVR4_COMMENT_CHARS
   39.38 +-      {
   39.39 +-	char *n, *t;
   39.40 +-	const char *s;
   39.41 +-
   39.42 +-	n = (char *) xmalloc (strlen (i386_comment_chars) + 1);
   39.43 +-	t = n;
   39.44 +-	for (s = i386_comment_chars; *s != '\0'; s++)
   39.45 +-	  if (*s != '/')
   39.46 +-	    *t++ = *s;
   39.47 +-	*t = '\0';
   39.48 +-	i386_comment_chars = n;
   39.49 +-      }
   39.50 +-#endif
   39.51 +       break;
   39.52 + 
   39.53 +     default:
   39.54 +@@ -5525,13 +5497,8 @@
   39.55 +   fprintf (stream, _("\
   39.56 +   -s                      ignored\n"));
   39.57 + #endif
   39.58 +-#ifdef SVR4_COMMENT_CHARS
   39.59 +-  fprintf (stream, _("\
   39.60 +-  --divide                do not treat `/' as a comment character\n"));
   39.61 +-#else
   39.62 +   fprintf (stream, _("\
   39.63 +   --divide                ignored\n"));
   39.64 +-#endif
   39.65 + }
   39.66 + 
   39.67 + #if ((defined (OBJ_MAYBE_COFF) && defined (OBJ_MAYBE_AOUT)) \
    40.1 --- a/patches/binutils/2.18/100-makeinfo-version.patch	Sun Sep 11 18:26:12 2011 +0200
    40.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    40.3 @@ -1,32 +0,0 @@
    40.4 -diff -u binutils-2.18-orig/configure binutils-2.18/configure
    40.5 ---- binutils-2.18-orig/configure	2007-08-06 16:29:40.000000000 -0400
    40.6 -+++ binutils-2.18/configure	2007-09-27 22:41:51.000000000 -0400
    40.7 -@@ -6125,10 +6125,10 @@
    40.8 -   *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
    40.9 -   *)
   40.10 - 
   40.11 --    # For an installed makeinfo, we require it to be from texinfo 4.4 or
   40.12 -+    # For an installed makeinfo, we require it to be from texinfo 4.6 or
   40.13 -     # higher, else we use the "missing" dummy.
   40.14 -     if ${MAKEINFO} --version \
   40.15 --       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])' >/dev/null 2>&1; then
   40.16 -+       | egrep 'texinfo[^0-9]*(4\.([6-9]|[1-9][0-9])|[5-9]|[1-9][0-9])' >/dev/null 2>&1; then
   40.17 -       :
   40.18 -     else
   40.19 -       MAKEINFO="$MISSING makeinfo"
   40.20 -diff -u binutils-2.18-orig/configure.ac binutils-2.18/configure.ac
   40.21 ---- binutils-2.18-orig/configure.ac	2007-08-28 16:24:26.000000000 -0400
   40.22 -+++ binutils-2.18/configure.ac	2007-09-27 22:41:00.000000000 -0400
   40.23 -@@ -2400,10 +2400,10 @@
   40.24 -   *" texinfo "*) MAKEINFO='$$r/$(BUILD_SUBDIR)/texinfo/makeinfo/makeinfo' ;;
   40.25 -   *)
   40.26 - changequote(,)
   40.27 --    # For an installed makeinfo, we require it to be from texinfo 4.4 or
   40.28 -+    # For an installed makeinfo, we require it to be from texinfo 4.6 or
   40.29 -     # higher, else we use the "missing" dummy.
   40.30 -     if ${MAKEINFO} --version \
   40.31 --       | egrep 'texinfo[^0-9]*([1-3][0-9]|4\.[4-9]|[5-9])' >/dev/null 2>&1; then
   40.32 -+       | egrep 'texinfo[^0-9]*(4\.([6-9]|[1-9][0-9])|[5-9]|[1-9][0-9])' >/dev/null 2>&1; then
   40.33 -       :
   40.34 -     else
   40.35 -       MAKEINFO="$MISSING makeinfo"
    41.1 --- a/patches/binutils/2.18/110-enable-dash-v2.patch	Sun Sep 11 18:26:12 2011 +0200
    41.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.3 @@ -1,20 +0,0 @@
    41.4 -Enable using a shell other than bash.
    41.5 -Courtesy "Martin Guy" <martinwguy@yahoo.it>
    41.6 -http://sourceware.org/ml/crossgcc/2008-08/msg00037.html
    41.7 -
    41.8 ---- binutils-2.18.orig/ld/genscripts.sh	2007-08-12 20:00:07.000000000 +0100
    41.9 -+++ binutils-2.18/ld/genscripts.sh	2008-08-25 16:09:54.000000000 +0100
   41.10 -@@ -398,9 +398,11 @@
   41.11 -     . $em_script
   41.12 -     em_script=$current_script
   41.13 -   }
   41.14 --  fragment()
   41.15 -+  
   41.16 -+  alias fragment='em_lineno=$LINENO; fragment_em'
   41.17 -+  fragment_em()
   41.18 -   {
   41.19 --    local lineno=$[${BASH_LINENO[0]} + 1]
   41.20 -+    local lineno=$[$em_lineno + 1]
   41.21 -     echo >> e${EMULATION_NAME}.c "#line $lineno \"$em_script\""
   41.22 -     cat >> e${EMULATION_NAME}.c
   41.23 -   }
    42.1 --- a/patches/binutils/2.18/120-i386-no-divide-comment.patch	Sun Sep 11 18:26:12 2011 +0200
    42.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    42.3 @@ -1,64 +0,0 @@
    42.4 -diff -durN binutils-2.18.orig/gas/config/tc-i386.c binutils-2.18/gas/config/tc-i386.c
    42.5 ---- binutils-2.18.orig/gas/config/tc-i386.c	2007-08-24 16:01:22.000000000 +0200
    42.6 -+++ binutils-2.18/gas/config/tc-i386.c	2008-09-22 08:11:42.000000000 +0200
    42.7 -@@ -180,24 +180,10 @@
    42.8 - #endif
    42.9 - 	;
   42.10 - 
   42.11 --#if (defined (TE_I386AIX)				\
   42.12 --     || ((defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF))	\
   42.13 --	 && !defined (TE_GNU)				\
   42.14 --	 && !defined (TE_LINUX)				\
   42.15 -- 	 && !defined (TE_NETWARE)			\
   42.16 --	 && !defined (TE_FreeBSD)			\
   42.17 --	 && !defined (TE_NetBSD)))
   42.18 - /* This array holds the chars that always start a comment.  If the
   42.19 --   pre-processor is disabled, these aren't very useful.  The option
   42.20 --   --divide will remove '/' from this list.  */
   42.21 --const char *i386_comment_chars = "#/";
   42.22 --#define SVR4_COMMENT_CHARS 1
   42.23 --#define PREFIX_SEPARATOR '\\'
   42.24 --
   42.25 --#else
   42.26 -+   pre-processor is disabled, these aren't very useful.  */
   42.27 - const char *i386_comment_chars = "#";
   42.28 - #define PREFIX_SEPARATOR '/'
   42.29 --#endif
   42.30 - 
   42.31 - /* This array holds the chars that only start a comment at the beginning of
   42.32 -    a line.  If the line seems to have the form '# 123 filename'
   42.33 -@@ -6061,20 +6047,6 @@
   42.34 -       break;
   42.35 - 
   42.36 -     case OPTION_DIVIDE:
   42.37 --#ifdef SVR4_COMMENT_CHARS
   42.38 --      {
   42.39 --	char *n, *t;
   42.40 --	const char *s;
   42.41 --
   42.42 --	n = (char *) xmalloc (strlen (i386_comment_chars) + 1);
   42.43 --	t = n;
   42.44 --	for (s = i386_comment_chars; *s != '\0'; s++)
   42.45 --	  if (*s != '/')
   42.46 --	    *t++ = *s;
   42.47 --	*t = '\0';
   42.48 --	i386_comment_chars = n;
   42.49 --      }
   42.50 --#endif
   42.51 -       break;
   42.52 - 
   42.53 -     case OPTION_MARCH:
   42.54 -@@ -6142,13 +6114,8 @@
   42.55 -   fprintf (stream, _("\
   42.56 -   --32/--64               generate 32bit/64bit code\n"));
   42.57 - #endif
   42.58 --#ifdef SVR4_COMMENT_CHARS
   42.59 --  fprintf (stream, _("\
   42.60 --  --divide                do not treat `/' as a comment character\n"));
   42.61 --#else
   42.62 -   fprintf (stream, _("\
   42.63 -   --divide                ignored\n"));
   42.64 --#endif
   42.65 -   fprintf (stream, _("\
   42.66 -   -march=CPU/-mtune=CPU   generate code/optimize for CPU, where CPU is one of:\n\
   42.67 -                            i386, i486, pentium, pentiumpro, pentium4, nocona,\n\
    43.1 --- a/patches/binutils/2.18/130-avr32-atmel-v1.0.1.patch	Sun Sep 11 18:26:12 2011 +0200
    43.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    43.3 @@ -1,52747 +0,0 @@
    43.4 ---- a/bfd/archures.c
    43.5 -+++ b/bfd/archures.c
    43.6 -@@ -346,6 +346,11 @@ DESCRIPTION
    43.7 - .#define bfd_mach_avr4		4
    43.8 - .#define bfd_mach_avr5		5
    43.9 - .#define bfd_mach_avr6		6
   43.10 -+.  bfd_arch_avr32,     {* Atmel AVR32 *}
   43.11 -+.#define bfd_mach_avr32_ap	7000
   43.12 -+.#define bfd_mach_avr32_uc	3000
   43.13 -+.#define bfd_mach_avr32_ucr1    3001
   43.14 -+.#define bfd_mach_avr32_ucr2    3002
   43.15 - .  bfd_arch_bfin,        {* ADI Blackfin *}
   43.16 - .#define bfd_mach_bfin          1
   43.17 - .  bfd_arch_cr16,       {* National Semiconductor CompactRISC (ie CR16). *}
   43.18 -@@ -438,6 +443,7 @@ extern const bfd_arch_info_type bfd_alph
   43.19 - extern const bfd_arch_info_type bfd_arc_arch;
   43.20 - extern const bfd_arch_info_type bfd_arm_arch;
   43.21 - extern const bfd_arch_info_type bfd_avr_arch;
   43.22 -+extern const bfd_arch_info_type bfd_avr32_arch;
   43.23 - extern const bfd_arch_info_type bfd_bfin_arch;
   43.24 - extern const bfd_arch_info_type bfd_cr16_arch;
   43.25 - extern const bfd_arch_info_type bfd_cr16c_arch;
   43.26 -@@ -509,6 +515,7 @@ static const bfd_arch_info_type * const 
   43.27 -     &bfd_arc_arch,
   43.28 -     &bfd_arm_arch,
   43.29 -     &bfd_avr_arch,
   43.30 -+    &bfd_avr32_arch,
   43.31 -     &bfd_bfin_arch,
   43.32 -     &bfd_cr16_arch,
   43.33 -     &bfd_cr16c_arch,
   43.34 ---- a/bfd/config.bfd
   43.35 -+++ b/bfd/config.bfd
   43.36 -@@ -335,6 +335,10 @@ case "${targ}" in
   43.37 -     targ_underscore=yes
   43.38 -     ;;
   43.39 - 
   43.40 -+  avr32-*-*)
   43.41 -+    targ_defvec=bfd_elf32_avr32_vec
   43.42 -+    ;;
   43.43 -+
   43.44 -   c30-*-*aout* | tic30-*-*aout*)
   43.45 -     targ_defvec=tic30_aout_vec
   43.46 -     ;;
   43.47 ---- a/bfd/configure.in
   43.48 -+++ b/bfd/configure.in
   43.49 -@@ -8,7 +8,7 @@ AC_CONFIG_SRCDIR([libbfd.c])
   43.50 - AC_CANONICAL_TARGET
   43.51 - AC_ISC_POSIX
   43.52 - 
   43.53 --AM_INIT_AUTOMAKE(bfd, 2.18)
   43.54 -+AM_INIT_AUTOMAKE(bfd, 2.18.atmel.1.0.1.avr32linux.1)
   43.55 - 
   43.56 - dnl These must be called before AM_PROG_LIBTOOL, because it may want
   43.57 - dnl to call AC_CHECK_PROG.
   43.58 -@@ -619,6 +619,7 @@ do
   43.59 -     bfd_efi_app_ia64_vec)	tb="$tb efi-app-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
   43.60 -     bfd_elf32_am33lin_vec)	tb="$tb elf32-am33lin.lo elf32.lo $elf" ;;
   43.61 -     bfd_elf32_avr_vec)		tb="$tb elf32-avr.lo elf32.lo $elf" ;;
   43.62 -+    bfd_elf32_avr32_vec)	tb="$tb elf32-avr32.lo elf32.lo $elf" ;;
   43.63 -     bfd_elf32_bfin_vec)		tb="$tb elf32-bfin.lo elf32.lo $elf" ;;
   43.64 -     bfd_elf32_bfinfdpic_vec)	tb="$tb elf32-bfin.lo elf32.lo $elf" ;;
   43.65 -     bfd_elf32_big_generic_vec) 	tb="$tb elf32-gen.lo elf32.lo $elf" ;;
   43.66 ---- /dev/null
   43.67 -+++ b/bfd/cpu-avr32.c
   43.68 -@@ -0,0 +1,51 @@
   43.69 -+/* BFD library support routines for AVR32.
   43.70 -+   Copyright 2003-2006 Atmel Corporation.
   43.71 -+
   43.72 -+   Written by Haavard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
   43.73 -+
   43.74 -+   This is part of BFD, the Binary File Descriptor library.
   43.75 -+
   43.76 -+   This program is free software; you can redistribute it and/or modify
   43.77 -+   it under the terms of the GNU General Public License as published by
   43.78 -+   the Free Software Foundation; either version 2 of the License, or
   43.79 -+   (at your option) any later version.
   43.80 -+
   43.81 -+   This program is distributed in the hope that it will be useful,
   43.82 -+   but WITHOUT ANY WARRANTY; without even the implied warranty of
   43.83 -+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   43.84 -+   GNU General Public License for more details.
   43.85 -+
   43.86 -+   You should have received a copy of the GNU General Public License
   43.87 -+   along with this program; if not, write to the Free Software
   43.88 -+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
   43.89 -+
   43.90 -+#include "bfd.h"
   43.91 -+#include "sysdep.h"
   43.92 -+#include "libbfd.h"
   43.93 -+
   43.94 -+#define N(machine, print, default, next)			\
   43.95 -+  {								\
   43.96 -+    32,				/* 32 bits in a word */		\
   43.97 -+    32,				/* 32 bits in an address */	\
   43.98 -+    8,				/* 8 bits in a byte */		\
   43.99 -+    bfd_arch_avr32,		/* architecture */		\
  43.100 -+    machine,			/* machine */			\
  43.101 -+    "avr32",			/* arch name */			\
  43.102 -+    print,			/* printable name */		\
  43.103 -+    1,				/* section align power */	\
  43.104 -+    default,			/* the default machine? */	\
  43.105 -+    bfd_default_compatible,					\
  43.106 -+    bfd_default_scan,						\
  43.107 -+    next,							\
  43.108 -+  }
  43.109 -+
  43.110 -+static const bfd_arch_info_type cpu_info[] =
  43.111 -+{
  43.112 -+  N(bfd_mach_avr32_ap, "avr32:ap", FALSE, &cpu_info[1]),
  43.113 -+  N(bfd_mach_avr32_uc, "avr32:uc", FALSE, &cpu_info[2]),
  43.114 -+  N(bfd_mach_avr32_ucr1, "avr32:ucr1", FALSE, &cpu_info[3]),
  43.115 -+  N(bfd_mach_avr32_ucr2, "avr32:ucr2", FALSE, NULL),
  43.116 -+};
  43.117 -+
  43.118 -+const bfd_arch_info_type bfd_avr32_arch =
  43.119 -+  N(bfd_mach_avr32_ap, "avr32", TRUE, &cpu_info[0]);
  43.120 ---- /dev/null
  43.121 -+++ b/bfd/elf32-avr32.c
  43.122 -@@ -0,0 +1,3915 @@
  43.123 -+/* AVR32-specific support for 32-bit ELF.
  43.124 -+   Copyright 2003-2006 Atmel Corporation.
  43.125 -+
  43.126 -+   Written by Haavard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
  43.127 -+
  43.128 -+   This file is part of BFD, the Binary File Descriptor library.
  43.129 -+
  43.130 -+   This program is free software; you can redistribute it and/or modify
  43.131 -+   it under the terms of the GNU General Public License as published by
  43.132 -+   the Free Software Foundation; either version 2 of the License, or
  43.133 -+   (at your option) any later version.
  43.134 -+
  43.135 -+   This program is distributed in the hope that it will be useful,
  43.136 -+   but WITHOUT ANY WARRANTY; without even the implied warranty of
  43.137 -+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  43.138 -+   GNU General Public License for more details.
  43.139 -+
  43.140 -+   You should have received a copy of the GNU General Public License
  43.141 -+   along with this program; if not, write to the Free Software
  43.142 -+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  43.143 -+
  43.144 -+#include "bfd.h"
  43.145 -+#include "sysdep.h"
  43.146 -+#include "bfdlink.h"
  43.147 -+#include "libbfd.h"
  43.148 -+#include "elf-bfd.h"
  43.149 -+#include "elf/avr32.h"
  43.150 -+#include "elf32-avr32.h"
  43.151 -+
  43.152 -+#define xDEBUG
  43.153 -+#define xRELAX_DEBUG
  43.154 -+
  43.155 -+#ifdef DEBUG
  43.156 -+# define pr_debug(fmt, args...) fprintf(stderr, fmt, ##args)
  43.157 -+#else
  43.158 -+# define pr_debug(fmt, args...) do { } while (0)
  43.159 -+#endif
  43.160 -+
  43.161 -+#ifdef RELAX_DEBUG
  43.162 -+# define RDBG(fmt, args...) fprintf(stderr, fmt, ##args)
  43.163 -+#else
  43.164 -+# define RDBG(fmt, args...) do { } while (0)
  43.165 -+#endif
  43.166 -+
  43.167 -+/* When things go wrong, we want it to blow up, damnit! */
  43.168 -+#undef BFD_ASSERT
  43.169 -+#undef abort
  43.170 -+#define BFD_ASSERT(expr)					\
  43.171 -+  do								\
  43.172 -+    {								\
  43.173 -+      if (!(expr))						\
  43.174 -+	{							\
  43.175 -+	  bfd_assert(__FILE__, __LINE__);			\
  43.176 -+	  abort();						\
  43.177 -+	}							\
  43.178 -+    }								\
  43.179 -+  while (0)
  43.180 -+
  43.181 -+/* The name of the dynamic interpreter. This is put in the .interp section. */
  43.182 -+#define ELF_DYNAMIC_INTERPRETER		"/lib/ld.so.1"
  43.183 -+
  43.184 -+#define AVR32_GOT_HEADER_SIZE		8
  43.185 -+#define AVR32_FUNCTION_STUB_SIZE	8
  43.186 -+
  43.187 -+#define ELF_R_INFO(x, y) ELF32_R_INFO(x, y)
  43.188 -+#define ELF_R_TYPE(x) ELF32_R_TYPE(x)
  43.189 -+#define ELF_R_SYM(x) ELF32_R_SYM(x)
  43.190 -+
  43.191 -+#define NOP_OPCODE 0xd703
  43.192 -+
  43.193 -+
  43.194 -+/* Mapping between BFD relocations and ELF relocations */
  43.195 -+
  43.196 -+static reloc_howto_type *
  43.197 -+bfd_elf32_bfd_reloc_type_lookup(bfd *abfd, bfd_reloc_code_real_type code);
  43.198 -+
  43.199 -+static reloc_howto_type *
  43.200 -+bfd_elf32_bfd_reloc_name_lookup(bfd *abfd, const char *r_name);
  43.201 -+
  43.202 -+static void
  43.203 -+avr32_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst);
  43.204 -+
  43.205 -+/* Generic HOWTO */
  43.206 -+#define GENH(name, align, size, bitsize, pcrel, bitpos, complain, mask)	\
  43.207 -+  HOWTO(name, align, size, bitsize, pcrel, bitpos,			\
  43.208 -+	complain_overflow_##complain, bfd_elf_generic_reloc, #name,	\
  43.209 -+	FALSE, 0, mask, pcrel)
  43.210 -+
  43.211 -+static reloc_howto_type elf_avr32_howto_table[] = {
  43.212 -+  /*   NAME		 ALN SZ BSZ PCREL  BP COMPLAIN  MASK	    */
  43.213 -+  GENH(R_AVR32_NONE,	  0, 0, 0,  FALSE, 0, dont,	0x00000000),
  43.214 -+
  43.215 -+  GENH(R_AVR32_32,	  0, 2, 32, FALSE, 0, dont,	0xffffffff),
  43.216 -+  GENH(R_AVR32_16,	  0, 1, 16, FALSE, 0, bitfield,	0x0000ffff),
  43.217 -+  GENH(R_AVR32_8,	  0, 0,  8, FALSE, 0, bitfield,	0x000000ff),
  43.218 -+  GENH(R_AVR32_32_PCREL,  0, 2, 32, TRUE,  0, signed,   0xffffffff),
  43.219 -+  GENH(R_AVR32_16_PCREL,  0, 1, 16, TRUE,  0, signed,   0x0000ffff),
  43.220 -+  GENH(R_AVR32_8_PCREL,	  0, 0,  8, TRUE,  0, signed,   0x000000ff),
  43.221 -+
  43.222 -+  /* Difference between two symbol (sym2 - sym1).  The reloc encodes
  43.223 -+     the value of sym1.  The field contains the difference before any
  43.224 -+     relaxing is done.  */
  43.225 -+  GENH(R_AVR32_DIFF32,	  0, 2, 32, FALSE, 0, dont,	0xffffffff),
  43.226 -+  GENH(R_AVR32_DIFF16,	  0, 1, 16, FALSE, 0, signed,	0x0000ffff),
  43.227 -+  GENH(R_AVR32_DIFF8,	  0, 0,  8, FALSE, 0, signed,	0x000000ff),
  43.228 -+
  43.229 -+  GENH(R_AVR32_GOT32,	  0, 2, 32, FALSE, 0, signed,	0xffffffff),
  43.230 -+  GENH(R_AVR32_GOT16,	  0, 1, 16, FALSE, 0, signed,	0x0000ffff),
  43.231 -+  GENH(R_AVR32_GOT8,	  0, 0,  8, FALSE, 0, signed,	0x000000ff),
  43.232 -+
  43.233 -+  GENH(R_AVR32_21S,	  0, 2, 21, FALSE, 0, signed,	0x1e10ffff),
  43.234 -+  GENH(R_AVR32_16U,	  0, 2, 16, FALSE, 0, unsigned,	0x0000ffff),
  43.235 -+  GENH(R_AVR32_16S,	  0, 2, 16, FALSE, 0, signed,	0x0000ffff),
  43.236 -+  GENH(R_AVR32_8S,	  0, 1,  8, FALSE, 4, signed,	0x00000ff0),
  43.237 -+  GENH(R_AVR32_8S_EXT,	  0, 2,  8, FALSE, 0, signed,	0x000000ff),
  43.238 -+
  43.239 -+  GENH(R_AVR32_22H_PCREL, 1, 2, 21, TRUE,  0, signed,	0x1e10ffff),
  43.240 -+  GENH(R_AVR32_18W_PCREL, 2, 2, 16, TRUE,  0, signed,	0x0000ffff),
  43.241 -+  GENH(R_AVR32_16B_PCREL, 0, 2, 16, TRUE,  0, signed,	0x0000ffff),
  43.242 -+  GENH(R_AVR32_16N_PCREL, 0, 2, 16, TRUE,  0, signed,	0x0000ffff),
  43.243 -+  GENH(R_AVR32_14UW_PCREL, 2, 2, 12, TRUE, 0, unsigned, 0x0000f0ff),
  43.244 -+  GENH(R_AVR32_11H_PCREL, 1, 1, 10, TRUE,  4, signed,	0x00000ff3),
  43.245 -+  GENH(R_AVR32_10UW_PCREL, 2, 2, 8, TRUE,  0, unsigned, 0x000000ff),
  43.246 -+  GENH(R_AVR32_9H_PCREL,  1, 1,  8, TRUE,  4, signed,	0x00000ff0),
  43.247 -+  GENH(R_AVR32_9UW_PCREL, 2, 1,  7, TRUE,  4, unsigned,	0x000007f0),
  43.248 -+
  43.249 -+  GENH(R_AVR32_HI16,	 16, 2, 16, FALSE, 0, dont,	0x0000ffff),
  43.250 -+  GENH(R_AVR32_LO16,	  0, 2, 16, FALSE, 0, dont,	0x0000ffff),
  43.251 -+
  43.252 -+  GENH(R_AVR32_GOTPC,	  0, 2, 32, FALSE, 0, dont,	0xffffffff),
  43.253 -+  GENH(R_AVR32_GOTCALL,   2, 2, 21, FALSE, 0, signed,	0x1e10ffff),
  43.254 -+  GENH(R_AVR32_LDA_GOT,	  2, 2, 21, FALSE, 0, signed,	0x1e10ffff),
  43.255 -+  GENH(R_AVR32_GOT21S,	  0, 2, 21, FALSE, 0, signed,	0x1e10ffff),
  43.256 -+  GENH(R_AVR32_GOT18SW,	  2, 2, 16, FALSE, 0, signed,	0x0000ffff),
  43.257 -+  GENH(R_AVR32_GOT16S,	  0, 2, 16, FALSE, 0, signed,	0x0000ffff),
  43.258 -+  GENH(R_AVR32_GOT7UW,	  2, 1,  5, FALSE, 4, unsigned, 0x000001f0),
  43.259 -+
  43.260 -+  GENH(R_AVR32_32_CPENT,  0, 2, 32, FALSE, 0, dont,	0xffffffff),
  43.261 -+  GENH(R_AVR32_CPCALL,	  2, 2, 16, TRUE,  0, signed,	0x0000ffff),
  43.262 -+  GENH(R_AVR32_16_CP,	  0, 2, 16, TRUE,  0, signed,	0x0000ffff),
  43.263 -+  GENH(R_AVR32_9W_CP,	  2, 1,  7, TRUE,  4, unsigned, 0x000007f0),
  43.264 -+
  43.265 -+  GENH(R_AVR32_RELATIVE,  0, 2, 32, FALSE, 0, signed,	0xffffffff),
  43.266 -+  GENH(R_AVR32_GLOB_DAT,  0, 2, 32, FALSE, 0, dont,	0xffffffff),
  43.267 -+  GENH(R_AVR32_JMP_SLOT,  0, 2, 32, FALSE, 0, dont,	0xffffffff),
  43.268 -+
  43.269 -+  GENH(R_AVR32_ALIGN,	  0, 1, 0,  FALSE, 0, unsigned, 0x00000000),
  43.270 -+
  43.271 -+  GENH(R_AVR32_15S,	  2, 2, 15, FALSE, 0, signed,	0x00007fff),
  43.272 -+};
  43.273 -+
  43.274 -+struct elf_reloc_map
  43.275 -+{
  43.276 -+  bfd_reloc_code_real_type bfd_reloc_val;
  43.277 -+  unsigned char elf_reloc_val;
  43.278 -+};
  43.279 -+
  43.280 -+static const struct elf_reloc_map avr32_reloc_map[] =
  43.281 -+{
  43.282 -+  { BFD_RELOC_NONE,			R_AVR32_NONE },
  43.283 -+
  43.284 -+  { BFD_RELOC_32,			R_AVR32_32 },
  43.285 -+  { BFD_RELOC_16,			R_AVR32_16 },
  43.286 -+  { BFD_RELOC_8,			R_AVR32_8 },
  43.287 -+  { BFD_RELOC_32_PCREL,			R_AVR32_32_PCREL },
  43.288 -+  { BFD_RELOC_16_PCREL,			R_AVR32_16_PCREL },
  43.289 -+  { BFD_RELOC_8_PCREL,			R_AVR32_8_PCREL },
  43.290 -+  { BFD_RELOC_AVR32_DIFF32,		R_AVR32_DIFF32 },
  43.291 -+  { BFD_RELOC_AVR32_DIFF16,		R_AVR32_DIFF16 },
  43.292 -+  { BFD_RELOC_AVR32_DIFF8,		R_AVR32_DIFF8 },
  43.293 -+  { BFD_RELOC_AVR32_GOT32,		R_AVR32_GOT32 },
  43.294 -+  { BFD_RELOC_AVR32_GOT16,		R_AVR32_GOT16 },
  43.295 -+  { BFD_RELOC_AVR32_GOT8,		R_AVR32_GOT8 },
  43.296 -+
  43.297 -+  { BFD_RELOC_AVR32_21S,		R_AVR32_21S },
  43.298 -+  { BFD_RELOC_AVR32_16U,		R_AVR32_16U },
  43.299 -+  { BFD_RELOC_AVR32_16S,		R_AVR32_16S },
  43.300 -+  { BFD_RELOC_AVR32_SUB5,		R_AVR32_16S },
  43.301 -+  { BFD_RELOC_AVR32_8S_EXT,		R_AVR32_8S_EXT },
  43.302 -+  { BFD_RELOC_AVR32_8S,			R_AVR32_8S },
  43.303 -+
  43.304 -+  { BFD_RELOC_AVR32_22H_PCREL,		R_AVR32_22H_PCREL },
  43.305 -+  { BFD_RELOC_AVR32_18W_PCREL,		R_AVR32_18W_PCREL },
  43.306 -+  { BFD_RELOC_AVR32_16B_PCREL,		R_AVR32_16B_PCREL },
  43.307 -+  { BFD_RELOC_AVR32_16N_PCREL,		R_AVR32_16N_PCREL },
  43.308 -+  { BFD_RELOC_AVR32_11H_PCREL,		R_AVR32_11H_PCREL },
  43.309 -+  { BFD_RELOC_AVR32_10UW_PCREL,		R_AVR32_10UW_PCREL },
  43.310 -+  { BFD_RELOC_AVR32_9H_PCREL,		R_AVR32_9H_PCREL },
  43.311 -+  { BFD_RELOC_AVR32_9UW_PCREL,		R_AVR32_9UW_PCREL },
  43.312 -+
  43.313 -+  { BFD_RELOC_HI16,			R_AVR32_HI16 },
  43.314 -+  { BFD_RELOC_LO16,			R_AVR32_LO16 },
  43.315 -+
  43.316 -+  { BFD_RELOC_AVR32_GOTPC,		R_AVR32_GOTPC },
  43.317 -+  { BFD_RELOC_AVR32_GOTCALL,		R_AVR32_GOTCALL },
  43.318 -+  { BFD_RELOC_AVR32_LDA_GOT,		R_AVR32_LDA_GOT },
  43.319 -+  { BFD_RELOC_AVR32_GOT21S,		R_AVR32_GOT21S },
  43.320 -+  { BFD_RELOC_AVR32_GOT18SW,		R_AVR32_GOT18SW },
  43.321 -+  { BFD_RELOC_AVR32_GOT16S,		R_AVR32_GOT16S },
  43.322 -+  /* GOT7UW should never be generated by the assembler */
  43.323 -+
  43.324 -+  { BFD_RELOC_AVR32_32_CPENT,		R_AVR32_32_CPENT },
  43.325 -+  { BFD_RELOC_AVR32_CPCALL,		R_AVR32_CPCALL },
  43.326 -+  { BFD_RELOC_AVR32_16_CP,		R_AVR32_16_CP },
  43.327 -+  { BFD_RELOC_AVR32_9W_CP,		R_AVR32_9W_CP },
  43.328 -+
  43.329 -+  { BFD_RELOC_AVR32_ALIGN,		R_AVR32_ALIGN },
  43.330 -+
  43.331 -+  { BFD_RELOC_AVR32_15S,		R_AVR32_15S },
  43.332 -+};
  43.333 -+
  43.334 -+static reloc_howto_type *
  43.335 -+bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  43.336 -+				 bfd_reloc_code_real_type code)
  43.337 -+{
  43.338 -+  unsigned int i;
  43.339 -+
  43.340 -+  for (i = 0; i < sizeof(avr32_reloc_map) / sizeof(struct elf_reloc_map); i++)
  43.341 -+    {
  43.342 -+      if (avr32_reloc_map[i].bfd_reloc_val == code)
  43.343 -+	return &elf_avr32_howto_table[avr32_reloc_map[i].elf_reloc_val];
  43.344 -+    }
  43.345 -+
  43.346 -+  return NULL;
  43.347 -+}
  43.348 -+
  43.349 -+static reloc_howto_type *
  43.350 -+bfd_elf32_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
  43.351 -+                 const char *r_name)
  43.352 -+{
  43.353 -+  unsigned int i;
  43.354 -+
  43.355 -+  for (i = 0;
  43.356 -+       i < sizeof (elf_avr32_howto_table) / sizeof (elf_avr32_howto_table[0]);
  43.357 -+       i++)
  43.358 -+    if (elf_avr32_howto_table[i].name != NULL
  43.359 -+    && strcasecmp (elf_avr32_howto_table[i].name, r_name) == 0)
  43.360 -+      return &elf_avr32_howto_table[i];
  43.361 -+
  43.362 -+  return NULL;
  43.363 -+}
  43.364 -+
  43.365 -+/* Set the howto pointer for an AVR32 ELF reloc.  */
  43.366 -+static void
  43.367 -+avr32_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
  43.368 -+		     arelent *cache_ptr,
  43.369 -+		     Elf_Internal_Rela *dst)
  43.370 -+{
  43.371 -+  unsigned int r_type;
  43.372 -+
  43.373 -+  r_type = ELF32_R_TYPE (dst->r_info);
  43.374 -+  BFD_ASSERT (r_type < (unsigned int) R_AVR32_max);
  43.375 -+  cache_ptr->howto = &elf_avr32_howto_table[r_type];
  43.376 -+}
  43.377 -+
  43.378 -+
  43.379 -+/* AVR32 ELF linker hash table and associated hash entries. */
  43.380 -+
  43.381 -+static struct bfd_hash_entry *
  43.382 -+avr32_elf_link_hash_newfunc(struct bfd_hash_entry *entry,
  43.383 -+			    struct bfd_hash_table *table,
  43.384 -+			    const char *string);
  43.385 -+static void
  43.386 -+avr32_elf_copy_indirect_symbol(struct bfd_link_info *info,
  43.387 -+			       struct elf_link_hash_entry *dir,
  43.388 -+			       struct elf_link_hash_entry *ind);
  43.389 -+static struct bfd_link_hash_table *
  43.390 -+avr32_elf_link_hash_table_create(bfd *abfd);
  43.391 -+
  43.392 -+/*
  43.393 -+  Try to limit memory usage to something reasonable when sorting the
  43.394 -+  GOT.  If just a couple of entries end up getting more references
  43.395 -+  than this, it won't affect performance at all, but if there are many
  43.396 -+  of them, we could end up with the wrong symbols being assigned the
  43.397 -+  first GOT entries.
  43.398 -+*/
  43.399 -+#define MAX_NR_GOT_HOLES	2048
  43.400 -+
  43.401 -+/*
  43.402 -+  AVR32 GOT entry.  We need to keep track of refcounts and offsets
  43.403 -+  simultaneously, since we need the offsets during relaxation, and we
  43.404 -+  also want to be able to drop GOT entries during relaxation. In
  43.405 -+  addition to this, we want to keep the list of GOT entries sorted so
  43.406 -+  that we can keep the most-used entries at the lowest offsets.
  43.407 -+*/
  43.408 -+struct got_entry
  43.409 -+{
  43.410 -+  struct got_entry *next;
  43.411 -+  struct got_entry **pprev;
  43.412 -+  int refcount;
  43.413 -+  bfd_signed_vma offset;
  43.414 -+};
  43.415 -+
  43.416 -+struct elf_avr32_link_hash_entry
  43.417 -+{
  43.418 -+  struct elf_link_hash_entry root;
  43.419 -+
  43.420 -+  /* Number of runtime relocations against this symbol.  */
  43.421 -+  unsigned int possibly_dynamic_relocs;
  43.422 -+
  43.423 -+  /* If there are anything but R_AVR32_GOT18 relocations against this
  43.424 -+     symbol, it means that someone may be taking the address of the
  43.425 -+     function, and we should therefore not create a stub.  */
  43.426 -+  bfd_boolean no_fn_stub;
  43.427 -+
  43.428 -+  /* If there is a R_AVR32_32 relocation in a read-only section
  43.429 -+     against this symbol, we could be in trouble. If we're linking a
  43.430 -+     shared library or this symbol is defined in one, it means we must
  43.431 -+     emit a run-time reloc for it and that's not allowed in read-only
  43.432 -+     sections.  */
  43.433 -+  asection *readonly_reloc_sec;
  43.434 -+  bfd_vma readonly_reloc_offset;
  43.435 -+
  43.436 -+  /* Record which frag (if any) contains the symbol.  This is used
  43.437 -+     during relaxation in order to avoid having to update all symbols
  43.438 -+     whenever we move something.  For local symbols, this information
  43.439 -+     is in the local_sym_frag member of struct elf_obj_tdata.  */
  43.440 -+  struct fragment *sym_frag;
  43.441 -+};
  43.442 -+#define avr32_elf_hash_entry(ent) ((struct elf_avr32_link_hash_entry *)(ent))
  43.443 -+
  43.444 -+struct elf_avr32_link_hash_table
  43.445 -+{
  43.446 -+  struct elf_link_hash_table root;
  43.447 -+
  43.448 -+  /* Shortcuts to get to dynamic linker sections.  */
  43.449 -+  asection *sgot;
  43.450 -+  asection *srelgot;
  43.451 -+  asection *sstub;
  43.452 -+
  43.453 -+  /* We use a variation of Pigeonhole Sort to sort the GOT.  After the
  43.454 -+     initial refcounts have been determined, we initialize
  43.455 -+     nr_got_holes to the highest refcount ever seen and allocate an
  43.456 -+     array of nr_got_holes entries for got_hole.  Each GOT entry is
  43.457 -+     then stored in this array at the index given by its refcount.
  43.458 -+
  43.459 -+     When a GOT entry has its refcount decremented during relaxation,
  43.460 -+     it is moved to a lower index in the got_hole array.
  43.461 -+   */
  43.462 -+  struct got_entry **got_hole;
  43.463 -+  int nr_got_holes;
  43.464 -+
  43.465 -+  /* Dynamic relocations to local symbols.  Only used when linking a
  43.466 -+     shared library and -Bsymbolic is not given.  */
  43.467 -+  unsigned int local_dynamic_relocs;
  43.468 -+
  43.469 -+  bfd_boolean relocations_analyzed;
  43.470 -+  bfd_boolean symbols_adjusted;
  43.471 -+  bfd_boolean repeat_pass;
  43.472 -+  bfd_boolean direct_data_refs;
  43.473 -+  unsigned int relax_iteration;
  43.474 -+  unsigned int relax_pass;
  43.475 -+};
  43.476 -+#define avr32_elf_hash_table(p)				\
  43.477 -+  ((struct elf_avr32_link_hash_table *)((p)->hash))
  43.478 -+
  43.479 -+static struct bfd_hash_entry *
  43.480 -+avr32_elf_link_hash_newfunc(struct bfd_hash_entry *entry,
  43.481 -+			    struct bfd_hash_table *table,
  43.482 -+			    const char *string)
  43.483 -+{
  43.484 -+  struct elf_avr32_link_hash_entry *ret = avr32_elf_hash_entry(entry);
  43.485 -+
  43.486 -+  /* Allocate the structure if it hasn't already been allocated by a
  43.487 -+     subclass */
  43.488 -+  if (ret == NULL)
  43.489 -+    ret = (struct elf_avr32_link_hash_entry *)
  43.490 -+      bfd_hash_allocate(table, sizeof(struct elf_avr32_link_hash_entry));
  43.491 -+
  43.492 -+  if (ret == NULL)
  43.493 -+    return NULL;
  43.494 -+
  43.495 -+  memset(ret, 0, sizeof(struct elf_avr32_link_hash_entry));
  43.496 -+
  43.497 -+  /* Give the superclass a chance */
  43.498 -+  ret = (struct elf_avr32_link_hash_entry *)
  43.499 -+    _bfd_elf_link_hash_newfunc((struct bfd_hash_entry *)ret, table, string);
  43.500 -+
  43.501 -+  return (struct bfd_hash_entry *)ret;
  43.502 -+}
  43.503 -+
  43.504 -+/* Copy data from an indirect symbol to its direct symbol, hiding the
  43.505 -+   old indirect symbol.  Process additional relocation information.
  43.506 -+   Also called for weakdefs, in which case we just let
  43.507 -+   _bfd_elf_link_hash_copy_indirect copy the flags for us.  */
  43.508 -+
  43.509 -+static void
  43.510 -+avr32_elf_copy_indirect_symbol(struct bfd_link_info *info,
  43.511 -+			       struct elf_link_hash_entry *dir,
  43.512 -+			       struct elf_link_hash_entry *ind)
  43.513 -+{
  43.514 -+  struct elf_avr32_link_hash_entry *edir, *eind;
  43.515 -+
  43.516 -+  _bfd_elf_link_hash_copy_indirect (info, dir, ind);
  43.517 -+
  43.518 -+  if (ind->root.type != bfd_link_hash_indirect)
  43.519 -+    return;
  43.520 -+
  43.521 -+  edir = (struct elf_avr32_link_hash_entry *)dir;
  43.522 -+  eind = (struct elf_avr32_link_hash_entry *)ind;
  43.523 -+
  43.524 -+  edir->possibly_dynamic_relocs += eind->possibly_dynamic_relocs;
  43.525 -+  edir->no_fn_stub = edir->no_fn_stub || eind->no_fn_stub;
  43.526 -+}
  43.527 -+
  43.528 -+static struct bfd_link_hash_table *
  43.529 -+avr32_elf_link_hash_table_create(bfd *abfd)
  43.530 -+{
  43.531 -+  struct elf_avr32_link_hash_table *ret;
  43.532 -+
  43.533 -+  ret = bfd_zmalloc(sizeof(*ret));
  43.534 -+  if (ret == NULL)
  43.535 -+    return NULL;
  43.536 -+
  43.537 -+  if (! _bfd_elf_link_hash_table_init(&ret->root, abfd,
  43.538 -+				      avr32_elf_link_hash_newfunc,
  43.539 -+                      sizeof (struct elf_avr32_link_hash_entry)))
  43.540 -+    {
  43.541 -+      free(ret);
  43.542 -+      return NULL;
  43.543 -+    }
  43.544 -+
  43.545 -+  /* Prevent the BFD core from creating bogus got_entry pointers */
  43.546 -+  ret->root.init_got_refcount.glist = NULL;
  43.547 -+  ret->root.init_plt_refcount.glist = NULL;
  43.548 -+  ret->root.init_got_offset.glist = NULL;
  43.549 -+  ret->root.init_plt_offset.glist = NULL;
  43.550 -+
  43.551 -+  return &ret->root.root;
  43.552 -+}
  43.553 -+
  43.554 -+
  43.555 -+/* Initial analysis and creation of dynamic sections and symbols */
  43.556 -+
  43.557 -+static asection *
  43.558 -+create_dynamic_section(bfd *dynobj, const char *name, flagword flags,
  43.559 -+		       unsigned int align_power);
  43.560 -+static struct elf_link_hash_entry *
  43.561 -+create_dynamic_symbol(bfd *dynobj, struct bfd_link_info *info,
  43.562 -+		      const char *name, asection *sec,
  43.563 -+		      bfd_vma offset);
  43.564 -+static bfd_boolean
  43.565 -+avr32_elf_create_got_section (bfd *dynobj, struct bfd_link_info *info);
  43.566 -+static bfd_boolean
  43.567 -+avr32_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info);
  43.568 -+static bfd_boolean
  43.569 -+avr32_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
  43.570 -+		    const Elf_Internal_Rela *relocs);
  43.571 -+static bfd_boolean
  43.572 -+avr32_elf_adjust_dynamic_symbol(struct bfd_link_info *info,
  43.573 -+				struct elf_link_hash_entry *h);
  43.574 -+
  43.575 -+static asection *
  43.576 -+create_dynamic_section(bfd *dynobj, const char *name, flagword flags,
  43.577 -+		       unsigned int align_power)
  43.578 -+{
  43.579 -+  asection *sec;
  43.580 -+
  43.581 -+  sec = bfd_make_section(dynobj, name);
  43.582 -+  if (!sec
  43.583 -+      || !bfd_set_section_flags(dynobj, sec, flags)
  43.584 -+      || !bfd_set_section_alignment(dynobj, sec, align_power))
  43.585 -+    return NULL;
  43.586 -+
  43.587 -+  return sec;
  43.588 -+}
  43.589 -+
  43.590 -+static struct elf_link_hash_entry *
  43.591 -+create_dynamic_symbol(bfd *dynobj, struct bfd_link_info *info,
  43.592 -+		      const char *name, asection *sec,
  43.593 -+		      bfd_vma offset)
  43.594 -+{
  43.595 -+  struct bfd_link_hash_entry *bh = NULL;
  43.596 -+  struct elf_link_hash_entry *h;
  43.597 -+  const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
  43.598 -+
  43.599 -+  if (!(_bfd_generic_link_add_one_symbol
  43.600 -+	(info, dynobj, name, BSF_GLOBAL, sec, offset, NULL, FALSE,
  43.601 -+	 bed->collect, &bh)))
  43.602 -+    return NULL;
  43.603 -+
  43.604 -+  h = (struct elf_link_hash_entry *)bh;
  43.605 -+  h->def_regular = 1;
  43.606 -+  h->type = STT_OBJECT;
  43.607 -+  h->other = STV_HIDDEN;
  43.608 -+
  43.609 -+  return h;
  43.610 -+}
  43.611 -+
  43.612 -+static bfd_boolean
  43.613 -+avr32_elf_create_got_section (bfd *dynobj, struct bfd_link_info *info)
  43.614 -+{
  43.615 -+  struct elf_avr32_link_hash_table *htab;
  43.616 -+  flagword flags;
  43.617 -+  const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
  43.618 -+
  43.619 -+  htab = avr32_elf_hash_table(info);
  43.620 -+  flags = bed->dynamic_sec_flags;
  43.621 -+
  43.622 -+  if (htab->sgot)
  43.623 -+    return TRUE;
  43.624 -+
  43.625 -+  htab->sgot = create_dynamic_section(dynobj, ".got", flags, 2);
  43.626 -+  if (!htab->srelgot)
  43.627 -+    htab->srelgot = create_dynamic_section(dynobj, ".rela.got",
  43.628 -+					   flags | SEC_READONLY, 2);
  43.629 -+
  43.630 -+  if (!htab->sgot || !htab->srelgot)
  43.631 -+    return FALSE;
  43.632 -+
  43.633 -+  htab->root.hgot = create_dynamic_symbol(dynobj, info, "_GLOBAL_OFFSET_TABLE_",
  43.634 -+					  htab->sgot, 0);
  43.635 -+  if (!htab->root.hgot)
  43.636 -+    return FALSE;
  43.637 -+
  43.638 -+  /* Make room for the GOT header */
  43.639 -+  htab->sgot->size += bed->got_header_size;
  43.640 -+
  43.641 -+  return TRUE;
  43.642 -+}
  43.643 -+
  43.644 -+/* (1) Create all dynamic (i.e. linker generated) sections that we may
  43.645 -+   need during the link */
  43.646 -+
  43.647 -+static bfd_boolean
  43.648 -+avr32_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
  43.649 -+{
  43.650 -+  struct elf_avr32_link_hash_table *htab;
  43.651 -+  flagword flags;
  43.652 -+  const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
  43.653 -+
  43.654 -+  pr_debug("(1) create dynamic sections\n");
  43.655 -+
  43.656 -+  htab = avr32_elf_hash_table(info);
  43.657 -+  flags = bed->dynamic_sec_flags;
  43.658 -+
  43.659 -+  if (!avr32_elf_create_got_section (dynobj, info))
  43.660 -+    return FALSE;
  43.661 -+
  43.662 -+  if (!htab->sstub)
  43.663 -+    htab->sstub = create_dynamic_section(dynobj, ".stub",
  43.664 -+					 flags | SEC_READONLY | SEC_CODE, 2);
  43.665 -+
  43.666 -+  if (!htab->sstub)
  43.667 -+    return FALSE;
  43.668 -+
  43.669 -+  return TRUE;
  43.670 -+}
  43.671 -+
  43.672 -+/* (2) Go through all the relocs and count any potential GOT- or
  43.673 -+   PLT-references to each symbol */
  43.674 -+
  43.675 -+static bfd_boolean
  43.676 -+avr32_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
  43.677 -+		    const Elf_Internal_Rela *relocs)
  43.678 -+{
  43.679 -+  Elf_Internal_Shdr *symtab_hdr;
  43.680 -+  struct elf_avr32_link_hash_table *htab;
  43.681 -+  struct elf_link_hash_entry **sym_hashes;
  43.682 -+  const Elf_Internal_Rela *rel, *rel_end;
  43.683 -+  struct got_entry **local_got_ents;
  43.684 -+  struct got_entry *got;
  43.685 -+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
  43.686 -+  asection *sgot;
  43.687 -+  bfd *dynobj;
  43.688 -+
  43.689 -+  pr_debug("(2) check relocs for %s:<%s> (size 0x%lx)\n",
  43.690 -+	   abfd->filename, sec->name, sec->size);
  43.691 -+
  43.692 -+  if (info->relocatable)
  43.693 -+    return TRUE;
  43.694 -+
  43.695 -+  dynobj = elf_hash_table(info)->dynobj;
  43.696 -+  symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
  43.697 -+  sym_hashes = elf_sym_hashes(abfd);
  43.698 -+  htab = avr32_elf_hash_table(info);
  43.699 -+  local_got_ents = elf_local_got_ents(abfd);
  43.700 -+  sgot = htab->sgot;
  43.701 -+
  43.702 -+  rel_end = relocs + sec->reloc_count;
  43.703 -+  for (rel = relocs; rel < rel_end; rel++)
  43.704 -+    {
  43.705 -+      unsigned long r_symndx, r_type;
  43.706 -+      struct elf_avr32_link_hash_entry *h;
  43.707 -+
  43.708 -+      r_symndx = ELF32_R_SYM(rel->r_info);
  43.709 -+      r_type = ELF32_R_TYPE(rel->r_info);
  43.710 -+
  43.711 -+      /* Local symbols use local_got_ents, while others store the same
  43.712 -+	 information in the hash entry */
  43.713 -+      if (r_symndx < symtab_hdr->sh_info)
  43.714 -+	{
  43.715 -+	  pr_debug("  (2a) processing local symbol %lu\n", r_symndx);
  43.716 -+	  h = NULL;
  43.717 -+	}
  43.718 -+      else
  43.719 -+	{
  43.720 -+	  h = (struct elf_avr32_link_hash_entry *)
  43.721 -+	    sym_hashes[r_symndx - symtab_hdr->sh_info];
  43.722 -+	  while (h->root.type == bfd_link_hash_indirect
  43.723 -+		 || h->root.type == bfd_link_hash_warning)
  43.724 -+	    h = (struct elf_avr32_link_hash_entry *)h->root.root.u.i.link;
  43.725 -+	  pr_debug("  (2a) processing symbol %s\n", h->root.root.root.string);
  43.726 -+	}
  43.727 -+
  43.728 -+      /* Some relocs require special sections to be created.  */
  43.729 -+      switch (r_type)
  43.730 -+	{
  43.731 -+	case R_AVR32_GOT32:
  43.732 -+	case R_AVR32_GOT16:
  43.733 -+	case R_AVR32_GOT8:
  43.734 -+	case R_AVR32_GOT21S:
  43.735 -+	case R_AVR32_GOT18SW:
  43.736 -+	case R_AVR32_GOT16S:
  43.737 -+	case R_AVR32_GOT7UW:
  43.738 -+	case R_AVR32_LDA_GOT:
  43.739 -+	case R_AVR32_GOTCALL:
  43.740 -+	  if (rel->r_addend)
  43.741 -+	    {
  43.742 -+	      if (info->callbacks->reloc_dangerous
  43.743 -+		  (info, _("Non-zero addend on GOT-relative relocation"),
  43.744 -+		   abfd, sec, rel->r_offset) == FALSE)
  43.745 -+		return FALSE;
  43.746 -+	    }
  43.747 -+	  /* fall through */
  43.748 -+	case R_AVR32_GOTPC:
  43.749 -+	  if (dynobj == NULL)
  43.750 -+	    elf_hash_table(info)->dynobj = dynobj = abfd;
  43.751 -+	  if (sgot == NULL && !avr32_elf_create_got_section(dynobj, info))
  43.752 -+	    return FALSE;
  43.753 -+	  break;
  43.754 -+	case R_AVR32_32:
  43.755 -+	  /* We may need to create .rela.dyn later on.  */
  43.756 -+	  if (dynobj == NULL
  43.757 -+	      && (info->shared || h != NULL)
  43.758 -+	      && (sec->flags & SEC_ALLOC))
  43.759 -+	    elf_hash_table(info)->dynobj = dynobj = abfd;
  43.760 -+	  break;
  43.761 -+	}
  43.762 -+
  43.763 -+      if (h != NULL && r_type != R_AVR32_GOT18SW)
  43.764 -+	h->no_fn_stub = TRUE;
  43.765 -+
  43.766 -+      switch (r_type)
  43.767 -+	{
  43.768 -+	case R_AVR32_GOT32:
  43.769 -+	case R_AVR32_GOT16:
  43.770 -+	case R_AVR32_GOT8:
  43.771 -+	case R_AVR32_GOT21S:
  43.772 -+	case R_AVR32_GOT18SW:
  43.773 -+	case R_AVR32_GOT16S:
  43.774 -+	case R_AVR32_GOT7UW:
  43.775 -+	case R_AVR32_LDA_GOT:
  43.776 -+	case R_AVR32_GOTCALL:
  43.777 -+	  if (h != NULL)
  43.778 -+	    {
  43.779 -+	      got = h->root.got.glist;
  43.780 -+	      if (!got)
  43.781 -+		{
  43.782 -+		  got = bfd_zalloc(abfd, sizeof(struct got_entry));
  43.783 -+		  if (!got)
  43.784 -+		    return FALSE;
  43.785 -+		  h->root.got.glist = got;
  43.786 -+		}
  43.787 -+	    }
  43.788 -+	  else
  43.789 -+	    {
  43.790 -+	      if (!local_got_ents)
  43.791 -+		{
  43.792 -+		  bfd_size_type size;
  43.793 -+		  bfd_size_type i;
  43.794 -+		  struct got_entry *tmp_entry;
  43.795 -+
  43.796 -+		  size = symtab_hdr->sh_info;
  43.797 -+		  size *= sizeof(struct got_entry *) + sizeof(struct got_entry);
  43.798 -+		  local_got_ents = bfd_zalloc(abfd, size);
  43.799 -+		  if (!local_got_ents)
  43.800 -+		    return FALSE;
  43.801 -+
  43.802 -+		  elf_local_got_ents(abfd) = local_got_ents;
  43.803 -+
  43.804 -+		  tmp_entry = (struct got_entry *)(local_got_ents
  43.805 -+						   + symtab_hdr->sh_info);
  43.806 -+		  for (i = 0; i < symtab_hdr->sh_info; i++)
  43.807 -+		    local_got_ents[i] = &tmp_entry[i];
  43.808 -+		}
  43.809 -+
  43.810 -+	      got = local_got_ents[r_symndx];
  43.811 -+	    }
  43.812 -+
  43.813 -+	  got->refcount++;
  43.814 -+	  if (got->refcount > htab->nr_got_holes)
  43.815 -+	    htab->nr_got_holes = got->refcount;
  43.816 -+	  break;
  43.817 -+
  43.818 -+	case R_AVR32_32:
  43.819 -+	  if ((info->shared || h != NULL)
  43.820 -+	      && (sec->flags & SEC_ALLOC))
  43.821 -+	    {
  43.822 -+	      if (htab->srelgot == NULL)
  43.823 -+		{
  43.824 -+		  htab->srelgot = create_dynamic_section(dynobj, ".rela.got",
  43.825 -+							 bed->dynamic_sec_flags
  43.826 -+							 | SEC_READONLY, 2);
  43.827 -+		  if (htab->srelgot == NULL)
  43.828 -+		    return FALSE;
  43.829 -+		}
  43.830 -+
  43.831 -+	      if (sec->flags & SEC_READONLY
  43.832 -+		  && !h->readonly_reloc_sec)
  43.833 -+		{
  43.834 -+		  h->readonly_reloc_sec = sec;
  43.835 -+		  h->readonly_reloc_offset = rel->r_offset;
  43.836 -+		}
  43.837 -+
  43.838 -+	      if (h != NULL)
  43.839 -+		{
  43.840 -+		  pr_debug("Non-GOT reference to symbol %s\n",
  43.841 -+			   h->root.root.root.string);
  43.842 -+		  h->possibly_dynamic_relocs++;
  43.843 -+		}
  43.844 -+	      else
  43.845 -+		{
  43.846 -+		  pr_debug("Non-GOT reference to local symbol %lu\n",
  43.847 -+			   r_symndx);
  43.848 -+		  htab->local_dynamic_relocs++;
  43.849 -+		}
  43.850 -+	    }
  43.851 -+
  43.852 -+	  break;
  43.853 -+
  43.854 -+	  /* TODO: GNU_VTINHERIT and GNU_VTENTRY */
  43.855 -+	}
  43.856 -+    }
  43.857 -+
  43.858 -+  return TRUE;
  43.859 -+}
  43.860 -+
  43.861 -+/* (3) Adjust a symbol defined by a dynamic object and referenced by a
  43.862 -+   regular object.  The current definition is in some section of the
  43.863 -+   dynamic object, but we're not including those sections.  We have to
  43.864 -+   change the definition to something the rest of the link can
  43.865 -+   understand.  */
  43.866 -+
  43.867 -+static bfd_boolean
  43.868 -+avr32_elf_adjust_dynamic_symbol(struct bfd_link_info *info,
  43.869 -+				struct elf_link_hash_entry *h)
  43.870 -+{
  43.871 -+  struct elf_avr32_link_hash_table *htab;
  43.872 -+  struct elf_avr32_link_hash_entry *havr;
  43.873 -+  bfd *dynobj;
  43.874 -+
  43.875 -+  pr_debug("(3) adjust dynamic symbol %s\n", h->root.root.string);
  43.876 -+
  43.877 -+  htab = avr32_elf_hash_table(info);
  43.878 -+  havr = (struct elf_avr32_link_hash_entry *)h;
  43.879 -+  dynobj = elf_hash_table(info)->dynobj;
  43.880 -+
  43.881 -+  /* Make sure we know what is going on here.  */
  43.882 -+  BFD_ASSERT (dynobj != NULL
  43.883 -+	      && (h->u.weakdef != NULL
  43.884 -+		  || (h->def_dynamic
  43.885 -+		      && h->ref_regular
  43.886 -+		      && !h->def_regular)));
  43.887 -+
  43.888 -+  /* We don't want dynamic relocations in read-only sections. */
  43.889 -+  if (havr->readonly_reloc_sec)
  43.890 -+    {
  43.891 -+      if (info->callbacks->reloc_dangerous
  43.892 -+	  (info, _("dynamic relocation in read-only section"),
  43.893 -+	   havr->readonly_reloc_sec->owner, havr->readonly_reloc_sec,
  43.894 -+	   havr->readonly_reloc_offset) == FALSE)
  43.895 -+	return FALSE;
  43.896 -+    }
  43.897 -+
  43.898 -+  /* If this is a function, create a stub if possible and set the
  43.899 -+     symbol to the stub location.  */
  43.900 -+  if (0 && !havr->no_fn_stub)
  43.901 -+    {
  43.902 -+      if (!h->def_regular)
  43.903 -+	{
  43.904 -+	  asection *s = htab->sstub;
  43.905 -+
  43.906 -+	  BFD_ASSERT(s != NULL);
  43.907 -+
  43.908 -+	  h->root.u.def.section = s;
  43.909 -+	  h->root.u.def.value = s->size;
  43.910 -+	  h->plt.offset = s->size;
  43.911 -+	  s->size += AVR32_FUNCTION_STUB_SIZE;
  43.912 -+
  43.913 -+	  return TRUE;
  43.914 -+	}
  43.915 -+    }
  43.916 -+  else if (h->type == STT_FUNC)
  43.917 -+    {
  43.918 -+      /* This will set the entry for this symbol in the GOT to 0, and
  43.919 -+	 the dynamic linker will take care of this. */
  43.920 -+      h->root.u.def.value = 0;
  43.921 -+      return TRUE;
  43.922 -+    }
  43.923 -+
  43.924 -+  /* If this is a weak symbol, and there is a real definition, the
  43.925 -+     processor independent code will have arranged for us to see the
  43.926 -+     real definition first, and we can just use the same value.  */
  43.927 -+  if (h->u.weakdef != NULL)
  43.928 -+    {
  43.929 -+      BFD_ASSERT(h->u.weakdef->root.type == bfd_link_hash_defined
  43.930 -+		 || h->u.weakdef->root.type == bfd_link_hash_defweak);
  43.931 -+      h->root.u.def.section = h->u.weakdef->root.u.def.section;
  43.932 -+      h->root.u.def.value = h->u.weakdef->root.u.def.value;
  43.933 -+      return TRUE;
  43.934 -+    }
  43.935 -+
  43.936 -+  /* This is a reference to a symbol defined by a dynamic object which
  43.937 -+     is not a function.  */
  43.938 -+
  43.939 -+  return TRUE;
  43.940 -+}
  43.941 -+
  43.942 -+
  43.943 -+/* Garbage-collection of unused sections */
  43.944 -+
  43.945 -+static asection *
  43.946 -+avr32_elf_gc_mark_hook(asection *sec,
  43.947 -+		       struct bfd_link_info *info ATTRIBUTE_UNUSED,
  43.948 -+		       Elf_Internal_Rela *rel,
  43.949 -+		       struct elf_link_hash_entry *h,
  43.950 -+		       Elf_Internal_Sym *sym)
  43.951 -+{
  43.952 -+  if (h)
  43.953 -+    {
  43.954 -+      switch (ELF32_R_TYPE(rel->r_info))
  43.955 -+	{
  43.956 -+	  /* TODO: VTINHERIT/VTENTRY */
  43.957 -+	default:
  43.958 -+	  switch (h->root.type)
  43.959 -+	    {
  43.960 -+	    case bfd_link_hash_defined:
  43.961 -+	    case bfd_link_hash_defweak:
  43.962 -+	      return h->root.u.def.section;
  43.963 -+
  43.964 -+	    case bfd_link_hash_common:
  43.965 -+	      return h->root.u.c.p->section;
  43.966 -+
  43.967 -+	    default:
  43.968 -+	      break;
  43.969 -+	    }
  43.970 -+	}
  43.971 -+    }
  43.972 -+  else
  43.973 -+    return bfd_section_from_elf_index(sec->owner, sym->st_shndx);
  43.974 -+
  43.975 -+  return NULL;
  43.976 -+}
  43.977 -+
  43.978 -+/* Update the GOT entry reference counts for the section being removed. */
  43.979 -+static bfd_boolean
  43.980 -+avr32_elf_gc_sweep_hook(bfd *abfd,
  43.981 -+			struct bfd_link_info *info ATTRIBUTE_UNUSED,
  43.982 -+			asection *sec,
  43.983 -+			const Elf_Internal_Rela *relocs)
  43.984 -+{
  43.985 -+  Elf_Internal_Shdr *symtab_hdr;
  43.986 -+  struct elf_avr32_link_hash_entry **sym_hashes;
  43.987 -+  struct got_entry **local_got_ents;
  43.988 -+  const Elf_Internal_Rela *rel, *relend;
  43.989 -+
  43.990 -+  if (!(sec->flags & SEC_ALLOC))
  43.991 -+    return TRUE;
  43.992 -+
  43.993 -+  symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
  43.994 -+  sym_hashes = (struct elf_avr32_link_hash_entry **)elf_sym_hashes(abfd);
  43.995 -+  local_got_ents = elf_local_got_ents(abfd);
  43.996 -+
  43.997 -+  relend = relocs + sec->reloc_count;
  43.998 -+  for (rel = relocs; rel < relend; rel++)
  43.999 -+    {
 43.1000 -+      unsigned long r_symndx;
 43.1001 -+      unsigned int r_type;
 43.1002 -+      struct elf_avr32_link_hash_entry *h = NULL;
 43.1003 -+
 43.1004 -+      r_symndx = ELF32_R_SYM(rel->r_info);
 43.1005 -+      if (r_symndx >= symtab_hdr->sh_info)
 43.1006 -+	{
 43.1007 -+	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 43.1008 -+	  while (h->root.root.type == bfd_link_hash_indirect
 43.1009 -+		 || h->root.root.type == bfd_link_hash_warning)
 43.1010 -+	    h = (struct elf_avr32_link_hash_entry *)h->root.root.u.i.link;
 43.1011 -+	}
 43.1012 -+
 43.1013 -+      r_type = ELF32_R_TYPE(rel->r_info);
 43.1014 -+
 43.1015 -+      switch (r_type)
 43.1016 -+	{
 43.1017 -+	case R_AVR32_GOT32:
 43.1018 -+	case R_AVR32_GOT16:
 43.1019 -+	case R_AVR32_GOT8:
 43.1020 -+	case R_AVR32_GOT21S:
 43.1021 -+	case R_AVR32_GOT18SW:
 43.1022 -+	case R_AVR32_GOT16S:
 43.1023 -+	case R_AVR32_GOT7UW:
 43.1024 -+	case R_AVR32_LDA_GOT:
 43.1025 -+	case R_AVR32_GOTCALL:
 43.1026 -+	  if (h)
 43.1027 -+	    h->root.got.glist->refcount--;
 43.1028 -+	  else
 43.1029 -+	    local_got_ents[r_symndx]->refcount--;
 43.1030 -+	  break;
 43.1031 -+
 43.1032 -+	case R_AVR32_32:
 43.1033 -+	  if (info->shared || h)
 43.1034 -+	    {
 43.1035 -+	      if (h)
 43.1036 -+		h->possibly_dynamic_relocs--;
 43.1037 -+	      else
 43.1038 -+		avr32_elf_hash_table(info)->local_dynamic_relocs--;
 43.1039 -+	    }
 43.1040 -+
 43.1041 -+	default:
 43.1042 -+	  break;
 43.1043 -+	}
 43.1044 -+    }
 43.1045 -+
 43.1046 -+  return TRUE;
 43.1047 -+}
 43.1048 -+
 43.1049 -+/* Sizing and refcounting of dynamic sections */
 43.1050 -+
 43.1051 -+static void
 43.1052 -+insert_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got);
 43.1053 -+static void
 43.1054 -+unref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got);
 43.1055 -+static void
 43.1056 -+ref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got);
 43.1057 -+static bfd_boolean
 43.1058 -+assign_got_offsets(struct elf_avr32_link_hash_table *htab);
 43.1059 -+static bfd_boolean
 43.1060 -+allocate_dynrelocs(struct elf_link_hash_entry *h, void *_info);
 43.1061 -+static bfd_boolean
 43.1062 -+avr32_elf_size_dynamic_sections (bfd *output_bfd,
 43.1063 -+				 struct bfd_link_info *info);
 43.1064 -+
 43.1065 -+static void
 43.1066 -+insert_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got)
 43.1067 -+{
 43.1068 -+  /* Any entries with got_refcount > htab->nr_got_holes end up in the
 43.1069 -+   * last pigeonhole without any sorting. We expect the number of such
 43.1070 -+   * entries to be small, so it is very unlikely to affect
 43.1071 -+   * performance.  */
 43.1072 -+  int entry = got->refcount;
 43.1073 -+
 43.1074 -+  if (entry > htab->nr_got_holes)
 43.1075 -+    entry = htab->nr_got_holes;
 43.1076 -+
 43.1077 -+  got->pprev = &htab->got_hole[entry];
 43.1078 -+  got->next = htab->got_hole[entry];
 43.1079 -+
 43.1080 -+  if (got->next)
 43.1081 -+    got->next->pprev = &got->next;
 43.1082 -+
 43.1083 -+  htab->got_hole[entry] = got;
 43.1084 -+}
 43.1085 -+
 43.1086 -+/* Decrement the refcount of a GOT entry and update its position in
 43.1087 -+   the pigeonhole array.  */
 43.1088 -+static void
 43.1089 -+unref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got)
 43.1090 -+{
 43.1091 -+  BFD_ASSERT(got->refcount > 0);
 43.1092 -+
 43.1093 -+  if (got->next)
 43.1094 -+    got->next->pprev = got->pprev;
 43.1095 -+
 43.1096 -+  *(got->pprev) = got->next;
 43.1097 -+  got->refcount--;
 43.1098 -+  insert_got_entry(htab, got);
 43.1099 -+}
 43.1100 -+
 43.1101 -+static void
 43.1102 -+ref_got_entry(struct elf_avr32_link_hash_table *htab, struct got_entry *got)
 43.1103 -+{
 43.1104 -+  if (got->next)
 43.1105 -+    got->next->pprev = got->pprev;
 43.1106 -+
 43.1107 -+  *(got->pprev) = got->next;
 43.1108 -+  got->refcount++;
 43.1109 -+  insert_got_entry(htab, got);
 43.1110 -+
 43.1111 -+  BFD_ASSERT(got->refcount > 0);
 43.1112 -+}
 43.1113 -+
 43.1114 -+/* Assign offsets to all GOT entries we intend to keep.  The entries
 43.1115 -+   that are referenced most often are placed at low offsets so that we
 43.1116 -+   can use compact instructions as much as possible.
 43.1117 -+
 43.1118 -+   Returns TRUE if any offsets or the total size of the GOT changed.  */
 43.1119 -+
 43.1120 -+static bfd_boolean
 43.1121 -+assign_got_offsets(struct elf_avr32_link_hash_table *htab)
 43.1122 -+{
 43.1123 -+  struct got_entry *got;
 43.1124 -+  bfd_size_type got_size = 0;
 43.1125 -+  bfd_boolean changed = FALSE;
 43.1126 -+  bfd_signed_vma offset;
 43.1127 -+  int i;
 43.1128 -+
 43.1129 -+  /* The GOT header provides the address of the DYNAMIC segment, so
 43.1130 -+     we need that even if the GOT is otherwise empty.  */
 43.1131 -+  if (htab->root.dynamic_sections_created)
 43.1132 -+    got_size = AVR32_GOT_HEADER_SIZE;
 43.1133 -+
 43.1134 -+  for (i = htab->nr_got_holes; i > 0; i--)
 43.1135 -+    {
 43.1136 -+      got = htab->got_hole[i];
 43.1137 -+      while (got)
 43.1138 -+	{
 43.1139 -+	  if (got->refcount > 0)
 43.1140 -+	    {
 43.1141 -+	      offset = got_size;
 43.1142 -+	      if (got->offset != offset)
 43.1143 -+		{
 43.1144 -+		  RDBG("GOT offset changed: %ld -> %ld\n",
 43.1145 -+		       got->offset, offset);
 43.1146 -+		  changed = TRUE;
 43.1147 -+		}
 43.1148 -+	      got->offset = offset;
 43.1149 -+	      got_size += 4;
 43.1150 -+	    }
 43.1151 -+	  got = got->next;
 43.1152 -+	}
 43.1153 -+    }
 43.1154 -+
 43.1155 -+  if (htab->sgot->size != got_size)
 43.1156 -+    {
 43.1157 -+      RDBG("GOT size changed: %lu -> %lu\n", htab->sgot->size,
 43.1158 -+	   got_size);
 43.1159 -+      changed = TRUE;
 43.1160 -+    }
 43.1161 -+  htab->sgot->size = got_size;
 43.1162 -+
 43.1163 -+  RDBG("assign_got_offsets: total size %lu (%s)\n",
 43.1164 -+       got_size, changed ? "changed" : "no change");
 43.1165 -+
 43.1166 -+  return changed;
 43.1167 -+}
 43.1168 -+
 43.1169 -+static bfd_boolean
 43.1170 -+allocate_dynrelocs(struct elf_link_hash_entry *h, void *_info)
 43.1171 -+{
 43.1172 -+  struct bfd_link_info *info = _info;
 43.1173 -+  struct elf_avr32_link_hash_table *htab;
 43.1174 -+  struct elf_avr32_link_hash_entry *havr;
 43.1175 -+  struct got_entry *got;
 43.1176 -+
 43.1177 -+  pr_debug("  (4b) allocate_dynrelocs: %s\n", h->root.root.string);
 43.1178 -+
 43.1179 -+  if (h->root.type == bfd_link_hash_indirect)
 43.1180 -+    return TRUE;
 43.1181 -+
 43.1182 -+  if (h->root.type == bfd_link_hash_warning)
 43.1183 -+    /* When warning symbols are created, they **replace** the "real"
 43.1184 -+       entry in the hash table, thus we never get to see the real
 43.1185 -+       symbol in a hash traversal.  So look at it now.  */
 43.1186 -+    h = (struct elf_link_hash_entry *) h->root.u.i.link;
 43.1187 -+
 43.1188 -+  htab = avr32_elf_hash_table(info);
 43.1189 -+  havr = (struct elf_avr32_link_hash_entry *)h;
 43.1190 -+
 43.1191 -+  got = h->got.glist;
 43.1192 -+
 43.1193 -+  /* If got is NULL, the symbol is never referenced through the GOT */
 43.1194 -+  if (got && got->refcount > 0)
 43.1195 -+    {
 43.1196 -+      insert_got_entry(htab, got);
 43.1197 -+
 43.1198 -+      /* Shared libraries need relocs for all GOT entries unless the
 43.1199 -+	 symbol is forced local or -Bsymbolic is used.  Others need
 43.1200 -+	 relocs for everything that is not guaranteed to be defined in
 43.1201 -+	 a regular object.  */
 43.1202 -+      if ((info->shared
 43.1203 -+	   && !info->symbolic
 43.1204 -+	   && h->dynindx != -1)
 43.1205 -+	  || (htab->root.dynamic_sections_created
 43.1206 -+	      && h->def_dynamic
 43.1207 -+	      && !h->def_regular))
 43.1208 -+	htab->srelgot->size += sizeof(Elf32_External_Rela);
 43.1209 -+    }
 43.1210 -+
 43.1211 -+  if (havr->possibly_dynamic_relocs
 43.1212 -+      && (info->shared
 43.1213 -+	  || (elf_hash_table(info)->dynamic_sections_created
 43.1214 -+	      && h->def_dynamic
 43.1215 -+	      && !h->def_regular)))
 43.1216 -+    {
 43.1217 -+      pr_debug("Allocating %d dynamic reloc against symbol %s...\n",
 43.1218 -+	       havr->possibly_dynamic_relocs, h->root.root.string);
 43.1219 -+      htab->srelgot->size += (havr->possibly_dynamic_relocs
 43.1220 -+			      * sizeof(Elf32_External_Rela));
 43.1221 -+    }
 43.1222 -+
 43.1223 -+  return TRUE;
 43.1224 -+}
 43.1225 -+
 43.1226 -+/* (4) Calculate the sizes of the linker-generated sections and
 43.1227 -+   allocate memory for them.  */
 43.1228 -+
 43.1229 -+static bfd_boolean
 43.1230 -+avr32_elf_size_dynamic_sections (bfd *output_bfd,
 43.1231 -+				 struct bfd_link_info *info)
 43.1232 -+{
 43.1233 -+  struct elf_avr32_link_hash_table *htab;
 43.1234 -+  bfd *dynobj;
 43.1235 -+  asection *s;
 43.1236 -+  bfd *ibfd;
 43.1237 -+  bfd_boolean relocs;
 43.1238 -+
 43.1239 -+  pr_debug("(4) size dynamic sections\n");
 43.1240 -+
 43.1241 -+  htab = avr32_elf_hash_table(info);
 43.1242 -+  dynobj = htab->root.dynobj;
 43.1243 -+  BFD_ASSERT(dynobj != NULL);
 43.1244 -+
 43.1245 -+  if (htab->root.dynamic_sections_created)
 43.1246 -+    {
 43.1247 -+      /* Initialize the contents of the .interp section to the name of
 43.1248 -+	 the dynamic loader */
 43.1249 -+      if (info->executable)
 43.1250 -+	{
 43.1251 -+	  s = bfd_get_section_by_name(dynobj, ".interp");
 43.1252 -+	  BFD_ASSERT(s != NULL);
 43.1253 -+	  s->size = sizeof(ELF_DYNAMIC_INTERPRETER);
 43.1254 -+	  s->contents = (unsigned char *)ELF_DYNAMIC_INTERPRETER;
 43.1255 -+	}
 43.1256 -+    }
 43.1257 -+
 43.1258 -+  if (htab->nr_got_holes > 0)
 43.1259 -+    {
 43.1260 -+      /* Allocate holes for the pigeonhole sort algorithm */
 43.1261 -+      pr_debug("Highest GOT refcount: %d\n", htab->nr_got_holes);
 43.1262 -+
 43.1263 -+      /* Limit the memory usage by clipping the number of pigeonholes
 43.1264 -+       * at a predefined maximum. All entries with a higher refcount
 43.1265 -+       * will end up in the last pigeonhole.  */
 43.1266 -+    if (htab->nr_got_holes >= MAX_NR_GOT_HOLES)
 43.1267 -+    {
 43.1268 -+        htab->nr_got_holes = MAX_NR_GOT_HOLES - 1;
 43.1269 -+
 43.1270 -+        pr_debug("Limiting maximum number of GOT pigeonholes to %u\n",
 43.1271 -+                    htab->nr_got_holes);
 43.1272 -+    }
 43.1273 -+      htab->got_hole = bfd_zalloc(output_bfd,
 43.1274 -+				  sizeof(struct got_entry *)
 43.1275 -+				  * (htab->nr_got_holes + 1));
 43.1276 -+      if (!htab->got_hole)
 43.1277 -+	return FALSE;
 43.1278 -+
 43.1279 -+      /* Set up .got offsets for local syms.  */
 43.1280 -+      for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
 43.1281 -+	{
 43.1282 -+	  struct got_entry **local_got;
 43.1283 -+	  struct got_entry **end_local_got;
 43.1284 -+	  Elf_Internal_Shdr *symtab_hdr;
 43.1285 -+	  bfd_size_type locsymcount;
 43.1286 -+
 43.1287 -+	  pr_debug("  (4a) processing file %s...\n", ibfd->filename);
 43.1288 -+
 43.1289 -+	  BFD_ASSERT(bfd_get_flavour(ibfd) == bfd_target_elf_flavour);
 43.1290 -+
 43.1291 -+	  local_got = elf_local_got_ents(ibfd);
 43.1292 -+	  if (!local_got)
 43.1293 -+	    continue;
 43.1294 -+
 43.1295 -+	  symtab_hdr = &elf_tdata(ibfd)->symtab_hdr;
 43.1296 -+	  locsymcount = symtab_hdr->sh_info;
 43.1297 -+	  end_local_got = local_got + locsymcount;
 43.1298 -+
 43.1299 -+	  for (; local_got < end_local_got; ++local_got)
 43.1300 -+	    insert_got_entry(htab, *local_got);
 43.1301 -+	}
 43.1302 -+    }
 43.1303 -+
 43.1304 -+  /* Allocate global sym .got entries and space for global sym
 43.1305 -+     dynamic relocs */
 43.1306 -+  elf_link_hash_traverse(&htab->root, allocate_dynrelocs, info);
 43.1307 -+
 43.1308 -+  /* Now that we have sorted the GOT entries, we are ready to
 43.1309 -+     assign offsets and determine the initial size of the GOT. */
 43.1310 -+  if (htab->sgot)
 43.1311 -+    assign_got_offsets(htab);
 43.1312 -+
 43.1313 -+  /* Allocate space for local sym dynamic relocs */
 43.1314 -+  BFD_ASSERT(htab->local_dynamic_relocs == 0 || info->shared);
 43.1315 -+  if (htab->local_dynamic_relocs)
 43.1316 -+    htab->srelgot->size += (htab->local_dynamic_relocs
 43.1317 -+			    * sizeof(Elf32_External_Rela));
 43.1318 -+
 43.1319 -+  /* We now have determined the sizes of the various dynamic
 43.1320 -+     sections. Allocate memory for them. */
 43.1321 -+  relocs = FALSE;
 43.1322 -+  for (s = dynobj->sections; s; s = s->next)
 43.1323 -+    {
 43.1324 -+      if ((s->flags & SEC_LINKER_CREATED) == 0)
 43.1325 -+	continue;
 43.1326 -+
 43.1327 -+      if (s == htab->sgot
 43.1328 -+	  || s == htab->sstub)
 43.1329 -+	{
 43.1330 -+	  /* Strip this section if we don't need it */
 43.1331 -+	}
 43.1332 -+      else if (strncmp (bfd_get_section_name(dynobj, s), ".rela", 5) == 0)
 43.1333 -+	{
 43.1334 -+	  if (s->size != 0)
 43.1335 -+	    relocs = TRUE;
 43.1336 -+
 43.1337 -+	  s->reloc_count = 0;
 43.1338 -+	}
 43.1339 -+      else
 43.1340 -+	{
 43.1341 -+	  /* It's not one of our sections */
 43.1342 -+	  continue;
 43.1343 -+	}
 43.1344 -+
 43.1345 -+      if (s->size == 0)
 43.1346 -+	{
 43.1347 -+	  /* Strip unneeded sections */
 43.1348 -+	  pr_debug("Stripping section %s from output...\n", s->name);
 43.1349 -+	  /* deleted function in 2.17
 43.1350 -+      _bfd_strip_section_from_output(info, s);
 43.1351 -+      */
 43.1352 -+	  continue;
 43.1353 -+	}
 43.1354 -+
 43.1355 -+      s->contents = bfd_zalloc(dynobj, s->size);
 43.1356 -+      if (s->contents == NULL)
 43.1357 -+	return FALSE;
 43.1358 -+    }
 43.1359 -+
 43.1360 -+  if (htab->root.dynamic_sections_created)
 43.1361 -+    {
 43.1362 -+      /* Add some entries to the .dynamic section.  We fill in the
 43.1363 -+	 values later, in sh_elf_finish_dynamic_sections, but we
 43.1364 -+	 must add the entries now so that we get the correct size for
 43.1365 -+	 the .dynamic section.  The DT_DEBUG entry is filled in by the
 43.1366 -+	 dynamic linker and used by the debugger.  */
 43.1367 -+#define add_dynamic_entry(TAG, VAL) _bfd_elf_add_dynamic_entry(info, TAG, VAL)
 43.1368 -+
 43.1369 -+      if (!add_dynamic_entry(DT_PLTGOT, 0))
 43.1370 -+	return FALSE;
 43.1371 -+      if (!add_dynamic_entry(DT_AVR32_GOTSZ, 0))
 43.1372 -+	return FALSE;
 43.1373 -+
 43.1374 -+      if (info->executable)
 43.1375 -+	{
 43.1376 -+	  if (!add_dynamic_entry(DT_DEBUG, 0))
 43.1377 -+	    return FALSE;
 43.1378 -+	}
 43.1379 -+      if (relocs)
 43.1380 -+	{
 43.1381 -+	  if (!add_dynamic_entry(DT_RELA, 0)
 43.1382 -+	      || !add_dynamic_entry(DT_RELASZ, 0)
 43.1383 -+	      || !add_dynamic_entry(DT_RELAENT,
 43.1384 -+				    sizeof(Elf32_External_Rela)))
 43.1385 -+	    return FALSE;
 43.1386 -+	}
 43.1387 -+    }
 43.1388 -+#undef add_dynamic_entry
 43.1389 -+
 43.1390 -+  return TRUE;
 43.1391 -+}
 43.1392 -+
 43.1393 -+
 43.1394 -+/* Access to internal relocations, section contents and symbols.
 43.1395 -+   (stolen from the xtensa port)  */
 43.1396 -+
 43.1397 -+static Elf_Internal_Rela *
 43.1398 -+retrieve_internal_relocs (bfd *abfd, asection *sec, bfd_boolean keep_memory);
 43.1399 -+static void
 43.1400 -+pin_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs);
 43.1401 -+static void
 43.1402 -+release_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs);
 43.1403 -+static bfd_byte *
 43.1404 -+retrieve_contents (bfd *abfd, asection *sec, bfd_boolean keep_memory);
 43.1405 -+/*
 43.1406 -+static void
 43.1407 -+pin_contents (asection *sec, bfd_byte *contents);
 43.1408 -+*/
 43.1409 -+static void
 43.1410 -+release_contents (asection *sec, bfd_byte *contents);
 43.1411 -+static Elf_Internal_Sym *
 43.1412 -+retrieve_local_syms (bfd *input_bfd, bfd_boolean keep_memory);
 43.1413 -+/*
 43.1414 -+static void
 43.1415 -+pin_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf);
 43.1416 -+*/
 43.1417 -+static void
 43.1418 -+release_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf);
 43.1419 -+
 43.1420 -+/* During relaxation, we need to modify relocations, section contents,
 43.1421 -+   and symbol definitions, and we need to keep the original values from
 43.1422 -+   being reloaded from the input files, i.e., we need to "pin" the
 43.1423 -+   modified values in memory.  We also want to continue to observe the
 43.1424 -+   setting of the "keep-memory" flag.  The following functions wrap the
 43.1425 -+   standard BFD functions to take care of this for us.  */
 43.1426 -+
 43.1427 -+static Elf_Internal_Rela *
 43.1428 -+retrieve_internal_relocs (bfd *abfd, asection *sec, bfd_boolean keep_memory)
 43.1429 -+{
 43.1430 -+  /* _bfd_elf_link_read_relocs knows about caching, so no need for us
 43.1431 -+     to be clever here.  */
 43.1432 -+  return _bfd_elf_link_read_relocs(abfd, sec, NULL, NULL, keep_memory);
 43.1433 -+}
 43.1434 -+
 43.1435 -+static void
 43.1436 -+pin_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs)
 43.1437 -+{
 43.1438 -+  elf_section_data (sec)->relocs = internal_relocs;
 43.1439 -+}
 43.1440 -+
 43.1441 -+static void
 43.1442 -+release_internal_relocs (asection *sec, Elf_Internal_Rela *internal_relocs)
 43.1443 -+{
 43.1444 -+  if (internal_relocs
 43.1445 -+      && elf_section_data (sec)->relocs != internal_relocs)
 43.1446 -+    free (internal_relocs);
 43.1447 -+}
 43.1448 -+
 43.1449 -+static bfd_byte *
 43.1450 -+retrieve_contents (bfd *abfd, asection *sec, bfd_boolean keep_memory)
 43.1451 -+{
 43.1452 -+  bfd_byte *contents;
 43.1453 -+  bfd_size_type sec_size;
 43.1454 -+
 43.1455 -+  sec_size = bfd_get_section_limit (abfd, sec);
 43.1456 -+  contents = elf_section_data (sec)->this_hdr.contents;
 43.1457 -+
 43.1458 -+  if (contents == NULL && sec_size != 0)
 43.1459 -+    {
 43.1460 -+      if (!bfd_malloc_and_get_section (abfd, sec, &contents))
 43.1461 -+	{
 43.1462 -+	  if (contents)
 43.1463 -+	    free (contents);
 43.1464 -+	  return NULL;
 43.1465 -+	}
 43.1466 -+      if (keep_memory)
 43.1467 -+	elf_section_data (sec)->this_hdr.contents = contents;
 43.1468 -+    }
 43.1469 -+  return contents;
 43.1470 -+}
 43.1471 -+
 43.1472 -+/*
 43.1473 -+static void
 43.1474 -+pin_contents (asection *sec, bfd_byte *contents)
 43.1475 -+{
 43.1476 -+  elf_section_data (sec)->this_hdr.contents = contents;
 43.1477 -+}
 43.1478 -+*/
 43.1479 -+static void
 43.1480 -+release_contents (asection *sec, bfd_byte *contents)
 43.1481 -+{
 43.1482 -+  if (contents && elf_section_data (sec)->this_hdr.contents != contents)
 43.1483 -+    free (contents);
 43.1484 -+}
 43.1485 -+
 43.1486 -+static Elf_Internal_Sym *
 43.1487 -+retrieve_local_syms (bfd *input_bfd, bfd_boolean keep_memory)
 43.1488 -+{
 43.1489 -+  Elf_Internal_Shdr *symtab_hdr;
 43.1490 -+  Elf_Internal_Sym *isymbuf;
 43.1491 -+  size_t locsymcount;
 43.1492 -+
 43.1493 -+  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
 43.1494 -+  locsymcount = symtab_hdr->sh_info;
 43.1495 -+
 43.1496 -+  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
 43.1497 -+  if (isymbuf == NULL && locsymcount != 0)
 43.1498 -+    {
 43.1499 -+      isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
 43.1500 -+				      NULL, NULL, NULL);
 43.1501 -+      if (isymbuf && keep_memory)
 43.1502 -+	symtab_hdr->contents = (unsigned char *) isymbuf;
 43.1503 -+    }
 43.1504 -+
 43.1505 -+  return isymbuf;
 43.1506 -+}
 43.1507 -+
 43.1508 -+/*
 43.1509 -+static void
 43.1510 -+pin_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf)
 43.1511 -+{
 43.1512 -+  elf_tdata (input_bfd)->symtab_hdr.contents = (unsigned char *)isymbuf;
 43.1513 -+}
 43.1514 -+
 43.1515 -+*/
 43.1516 -+static void
 43.1517 -+release_local_syms (bfd *input_bfd, Elf_Internal_Sym *isymbuf)
 43.1518 -+{
 43.1519 -+  if (isymbuf && (elf_tdata (input_bfd)->symtab_hdr.contents
 43.1520 -+		  != (unsigned char *)isymbuf))
 43.1521 -+    free (isymbuf);
 43.1522 -+}
 43.1523 -+
 43.1524 -+/* Data structures used during relaxation. */
 43.1525 -+
 43.1526 -+enum relax_state_id {
 43.1527 -+  RS_ERROR = -1,
 43.1528 -+  RS_NONE = 0,
 43.1529 -+  RS_ALIGN,
 43.1530 -+  RS_CPENT,
 43.1531 -+  RS_PIC_CALL,
 43.1532 -+  RS_PIC_MCALL,
 43.1533 -+  RS_PIC_RCALL2,
 43.1534 -+  RS_PIC_RCALL1,
 43.1535 -+  RS_PIC_LDA,
 43.1536 -+  RS_PIC_LDW4,
 43.1537 -+  RS_PIC_LDW3,
 43.1538 -+  RS_PIC_SUB5,
 43.1539 -+  RS_NOPIC_MCALL,
 43.1540 -+  RS_NOPIC_RCALL2,
 43.1541 -+  RS_NOPIC_RCALL1,
 43.1542 -+  RS_NOPIC_LDW4,
 43.1543 -+  RS_NOPIC_LDDPC,
 43.1544 -+  RS_NOPIC_SUB5,
 43.1545 -+  RS_NOPIC_MOV2,
 43.1546 -+  RS_NOPIC_MOV1,
 43.1547 -+  RS_RCALL2,
 43.1548 -+  RS_RCALL1,
 43.1549 -+  RS_BRC2,
 43.1550 -+  RS_BRC1,
 43.1551 -+  RS_BRAL,
 43.1552 -+  RS_RJMP,
 43.1553 -+  RS_MAX,
 43.1554 -+};
 43.1555 -+
 43.1556 -+enum reference_type {
 43.1557 -+  REF_ABSOLUTE,
 43.1558 -+  REF_PCREL,
 43.1559 -+  REF_CPOOL,
 43.1560 -+  REF_GOT,
 43.1561 -+};
 43.1562 -+
 43.1563 -+struct relax_state
 43.1564 -+{
 43.1565 -+  const char *name;
 43.1566 -+  enum relax_state_id id;
 43.1567 -+  enum relax_state_id direct;
 43.1568 -+  enum relax_state_id next;
 43.1569 -+  enum relax_state_id prev;
 43.1570 -+
 43.1571 -+  enum reference_type reftype;
 43.1572 -+
 43.1573 -+  unsigned int r_type;
 43.1574 -+
 43.1575 -+  bfd_vma opcode;
 43.1576 -+  bfd_vma opcode_mask;
 43.1577 -+
 43.1578 -+  bfd_signed_vma range_min;
 43.1579 -+  bfd_signed_vma range_max;
 43.1580 -+
 43.1581 -+  bfd_size_type size;
 43.1582 -+};
 43.1583 -+
 43.1584 -+/*
 43.1585 -+ * This is for relocs that
 43.1586 -+ *   a) has an addend or is of type R_AVR32_DIFF32, and
 43.1587 -+ *   b) references a different section than it's in, and
 43.1588 -+ *   c) references a section that is relaxable
 43.1589 -+ *
 43.1590 -+ * as well as relocs that references the constant pool, in which case
 43.1591 -+ * the add_frag member points to the frag containing the constant pool
 43.1592 -+ * entry.
 43.1593 -+ *
 43.1594 -+ * Such relocs must be fixed up whenever we delete any code. Sections
 43.1595 -+ * that don't have any relocs with all of the above properties don't
 43.1596 -+ * have any additional reloc data, but sections that do will have
 43.1597 -+ * additional data for all its relocs.
 43.1598 -+ */
 43.1599 -+struct avr32_reloc_data
 43.1600 -+{
 43.1601 -+  struct fragment *add_frag;
 43.1602 -+  struct fragment *sub_frag;
 43.1603 -+};
 43.1604 -+
 43.1605 -+/*
 43.1606 -+ * A 'fragment' is a relaxable entity, that is, code may be added or
 43.1607 -+ * deleted at the end of a fragment. When this happens, all subsequent
 43.1608 -+ * fragments in the list will have their offsets updated.
 43.1609 -+ */
 43.1610 -+struct fragment
 43.1611 -+{
 43.1612 -+  enum relax_state_id state;
 43.1613 -+  enum relax_state_id initial_state;
 43.1614 -+
 43.1615 -+  Elf_Internal_Rela *rela;
 43.1616 -+  bfd_size_type size;
 43.1617 -+  bfd_vma offset;
 43.1618 -+  int size_adjust;
 43.1619 -+  int offset_adjust;
 43.1620 -+  bfd_boolean has_grown;
 43.1621 -+
 43.1622 -+  /* Only used by constant pool entries.  When this drops to zero, the
 43.1623 -+     frag is discarded (i.e. size_adjust is set to -4.)  */
 43.1624 -+  int refcount;
 43.1625 -+};
 43.1626 -+
 43.1627 -+struct avr32_relax_data
 43.1628 -+{
 43.1629 -+  unsigned int frag_count;
 43.1630 -+  struct fragment *frag;
 43.1631 -+  struct avr32_reloc_data *reloc_data;
 43.1632 -+
 43.1633 -+  /* TRUE if this section has one or more relaxable relocations */
 43.1634 -+  bfd_boolean is_relaxable;
 43.1635 -+  unsigned int iteration;
 43.1636 -+};
 43.1637 -+
 43.1638 -+struct avr32_section_data
 43.1639 -+{
 43.1640 -+  struct bfd_elf_section_data elf;
 43.1641 -+  struct avr32_relax_data relax_data;
 43.1642 -+};
 43.1643 -+
 43.1644 -+/* Relax state definitions */
 43.1645 -+
 43.1646 -+#define PIC_MOV2_OPCODE		0xe0600000
 43.1647 -+#define PIC_MOV2_MASK		0xe1e00000
 43.1648 -+#define PIC_MOV2_RANGE_MIN	(-1048576 * 4)
 43.1649 -+#define PIC_MOV2_RANGE_MAX	(1048575 * 4)
 43.1650 -+#define PIC_MCALL_OPCODE	0xf0160000
 43.1651 -+#define PIC_MCALL_MASK		0xffff0000
 43.1652 -+#define PIC_MCALL_RANGE_MIN	(-131072)
 43.1653 -+#define PIC_MCALL_RANGE_MAX	(131068)
 43.1654 -+#define RCALL2_OPCODE		0xe0a00000
 43.1655 -+#define RCALL2_MASK		0xe1ef0000
 43.1656 -+#define RCALL2_RANGE_MIN	(-2097152)
 43.1657 -+#define RCALL2_RANGE_MAX	(2097150)
 43.1658 -+#define RCALL1_OPCODE		0xc00c0000
 43.1659 -+#define RCALL1_MASK		0xf00c0000
 43.1660 -+#define RCALL1_RANGE_MIN	(-1024)
 43.1661 -+#define RCALL1_RANGE_MAX	(1022)
 43.1662 -+#define PIC_LDW4_OPCODE		0xecf00000
 43.1663 -+#define PIC_LDW4_MASK		0xfff00000
 43.1664 -+#define PIC_LDW4_RANGE_MIN	(-32768)
 43.1665 -+#define PIC_LDW4_RANGE_MAX	(32767)
 43.1666 -+#define PIC_LDW3_OPCODE		0x6c000000
 43.1667 -+#define PIC_LDW3_MASK		0xfe000000
 43.1668 -+#define PIC_LDW3_RANGE_MIN	(0)
 43.1669 -+#define PIC_LDW3_RANGE_MAX	(124)
 43.1670 -+#define SUB5_PC_OPCODE		0xfec00000
 43.1671 -+#define SUB5_PC_MASK		0xfff00000
 43.1672 -+#define SUB5_PC_RANGE_MIN	(-32768)
 43.1673 -+#define SUB5_PC_RANGE_MAX	(32767)
 43.1674 -+#define NOPIC_MCALL_OPCODE	0xf01f0000
 43.1675 -+#define NOPIC_MCALL_MASK	0xffff0000
 43.1676 -+#define NOPIC_MCALL_RANGE_MIN	PIC_MCALL_RANGE_MIN
 43.1677 -+#define NOPIC_MCALL_RANGE_MAX	PIC_MCALL_RANGE_MAX
 43.1678 -+#define NOPIC_LDW4_OPCODE	0xfef00000
 43.1679 -+#define NOPIC_LDW4_MASK		0xfff00000
 43.1680 -+#define NOPIC_LDW4_RANGE_MIN	PIC_LDW4_RANGE_MIN
 43.1681 -+#define NOPIC_LDW4_RANGE_MAX	PIC_LDW4_RANGE_MAX
 43.1682 -+#define LDDPC_OPCODE		0x48000000
 43.1683 -+#define LDDPC_MASK		0xf8000000
 43.1684 -+#define LDDPC_RANGE_MIN		0
 43.1685 -+#define LDDPC_RANGE_MAX		508
 43.1686 -+
 43.1687 -+#define NOPIC_MOV2_OPCODE  0xe0600000
 43.1688 -+#define NOPIC_MOV2_MASK        0xe1e00000
 43.1689 -+#define NOPIC_MOV2_RANGE_MIN   (-1048576)
 43.1690 -+#define NOPIC_MOV2_RANGE_MAX   (1048575)
 43.1691 -+#define NOPIC_MOV1_OPCODE  0x30000000
 43.1692 -+#define NOPIC_MOV1_MASK        0xf0000000
 43.1693 -+#define NOPIC_MOV1_RANGE_MIN   (-128)
 43.1694 -+#define NOPIC_MOV1_RANGE_MAX   (127)
 43.1695 -+
 43.1696 -+/* Only brc2 variants with cond[3] == 0 is considered, since the
 43.1697 -+   others are not relaxable.  bral is a special case and is handled
 43.1698 -+   separately.  */
 43.1699 -+#define BRC2_OPCODE		0xe0800000
 43.1700 -+#define BRC2_MASK		0xe1e80000
 43.1701 -+#define BRC2_RANGE_MIN		(-2097152)
 43.1702 -+#define BRC2_RANGE_MAX		(2097150)
 43.1703 -+#define BRC1_OPCODE		0xc0000000
 43.1704 -+#define BRC1_MASK		0xf0080000
 43.1705 -+#define BRC1_RANGE_MIN		(-256)
 43.1706 -+#define BRC1_RANGE_MAX		(254)
 43.1707 -+#define BRAL_OPCODE		0xe08f0000
 43.1708 -+#define BRAL_MASK		0xe1ef0000
 43.1709 -+#define BRAL_RANGE_MIN		BRC2_RANGE_MIN
 43.1710 -+#define BRAL_RANGE_MAX		BRC2_RANGE_MAX
 43.1711 -+#define RJMP_OPCODE		0xc0080000
 43.1712 -+#define RJMP_MASK		0xf00c0000
 43.1713 -+#define RJMP_RANGE_MIN		(-1024)
 43.1714 -+#define RJMP_RANGE_MAX		(1022)
 43.1715 -+
 43.1716 -+/* Define a relax state using the GOT  */
 43.1717 -+#define RG(id, dir, next, prev, r_type, opc, size)			\
 43.1718 -+  { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_GOT,		\
 43.1719 -+      R_AVR32_##r_type,	opc##_OPCODE, opc##_MASK,			\
 43.1720 -+      opc##_RANGE_MIN, opc##_RANGE_MAX, size }
 43.1721 -+/* Define a relax state using the Constant Pool  */
 43.1722 -+#define RC(id, dir, next, prev, r_type, opc, size)			\
 43.1723 -+  { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_CPOOL,	\
 43.1724 -+      R_AVR32_##r_type,	opc##_OPCODE, opc##_MASK,			\
 43.1725 -+      opc##_RANGE_MIN, opc##_RANGE_MAX, size }
 43.1726 -+
 43.1727 -+/* Define a relax state using pc-relative direct reference  */
 43.1728 -+#define RP(id, dir, next, prev, r_type, opc, size)			\
 43.1729 -+  { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_PCREL,	\
 43.1730 -+      R_AVR32_##r_type,	opc##_OPCODE, opc##_MASK,			\
 43.1731 -+      opc##_RANGE_MIN, opc##_RANGE_MAX, size }
 43.1732 -+
 43.1733 -+/* Define a relax state using non-pc-relative direct reference */
 43.1734 -+#define RD(id, dir, next, prev, r_type, opc, size)         \
 43.1735 -+  { "RS_"#id, RS_##id, RS_##dir, RS_##next, RS_##prev, REF_ABSOLUTE,   \
 43.1736 -+      R_AVR32_##r_type,    opc##_OPCODE, opc##_MASK,           \
 43.1737 -+      opc##_RANGE_MIN, opc##_RANGE_MAX, size }
 43.1738 -+
 43.1739 -+/* Define a relax state that will be handled specially  */
 43.1740 -+#define RS(id, r_type, size)						\
 43.1741 -+  { "RS_"#id, RS_##id, RS_NONE, RS_NONE, RS_NONE, REF_ABSOLUTE,		\
 43.1742 -+      R_AVR32_##r_type, 0, 0, 0, 0, size }
 43.1743 -+
 43.1744 -+const struct relax_state relax_state[RS_MAX] = {
 43.1745 -+  RS(NONE, NONE, 0),
 43.1746 -+  RS(ALIGN, ALIGN, 0),
 43.1747 -+  RS(CPENT, 32_CPENT, 4),
 43.1748 -+
 43.1749 -+  RG(PIC_CALL, PIC_RCALL1, PIC_MCALL, NONE, GOTCALL, PIC_MOV2, 10),
 43.1750 -+  RG(PIC_MCALL, PIC_RCALL1, NONE, PIC_CALL, GOT18SW, PIC_MCALL, 4),
 43.1751 -+  RP(PIC_RCALL2, NONE, PIC_RCALL1, PIC_MCALL, 22H_PCREL, RCALL2, 4),
 43.1752 -+  RP(PIC_RCALL1, NONE, NONE, PIC_RCALL2, 11H_PCREL, RCALL1, 2),
 43.1753 -+
 43.1754 -+  RG(PIC_LDA, PIC_SUB5, PIC_LDW4, NONE, LDA_GOT, PIC_MOV2, 8),
 43.1755 -+  RG(PIC_LDW4, PIC_SUB5, PIC_LDW3, PIC_LDA, GOT16S, PIC_LDW4, 4),
 43.1756 -+  RG(PIC_LDW3, PIC_SUB5, NONE, PIC_LDW4, GOT7UW, PIC_LDW3, 2),
 43.1757 -+  RP(PIC_SUB5, NONE, NONE, PIC_LDW3, 16N_PCREL, SUB5_PC, 4),
 43.1758 -+
 43.1759 -+  RC(NOPIC_MCALL, NOPIC_RCALL1, NONE, NONE, CPCALL, NOPIC_MCALL, 4),
 43.1760 -+  RP(NOPIC_RCALL2, NONE, NOPIC_RCALL1, NOPIC_MCALL, 22H_PCREL, RCALL2, 4),
 43.1761 -+  RP(NOPIC_RCALL1, NONE, NONE, NOPIC_RCALL2, 11H_PCREL, RCALL1, 2),
 43.1762 -+
 43.1763 -+  RC(NOPIC_LDW4, NOPIC_MOV1, NOPIC_LDDPC, NONE, 16_CP, NOPIC_LDW4, 4),
 43.1764 -+  RC(NOPIC_LDDPC, NOPIC_MOV1, NONE, NOPIC_LDW4, 9W_CP, LDDPC, 2),
 43.1765 -+  RP(NOPIC_SUB5, NOPIC_MOV1, NONE, NOPIC_LDDPC, 16N_PCREL, SUB5_PC, 4),
 43.1766 -+  RD(NOPIC_MOV2, NONE, NOPIC_MOV1, NOPIC_SUB5, 21S, NOPIC_MOV2, 4),
 43.1767 -+  RD(NOPIC_MOV1, NONE, NONE, NOPIC_MOV2, 8S, NOPIC_MOV1, 2),
 43.1768 -+
 43.1769 -+  RP(RCALL2, NONE, RCALL1, NONE, 22H_PCREL, RCALL2, 4),
 43.1770 -+  RP(RCALL1, NONE, NONE, RCALL2, 11H_PCREL, RCALL1, 2),
 43.1771 -+  RP(BRC2, NONE, BRC1, NONE, 22H_PCREL, BRC2, 4),
 43.1772 -+  RP(BRC1, NONE, NONE, BRC2, 9H_PCREL, BRC1, 2),
 43.1773 -+  RP(BRAL, NONE, RJMP, NONE, 22H_PCREL, BRAL, 4),
 43.1774 -+  RP(RJMP, NONE, NONE, BRAL, 11H_PCREL, RJMP, 2),
 43.1775 -+};
 43.1776 -+
 43.1777 -+static bfd_boolean
 43.1778 -+avr32_elf_new_section_hook(bfd *abfd, asection *sec)
 43.1779 -+{
 43.1780 -+  struct avr32_section_data *sdata;
 43.1781 -+
 43.1782 -+  sdata = bfd_zalloc(abfd, sizeof(struct avr32_section_data));
 43.1783 -+  if (!sdata)
 43.1784 -+    return FALSE;
 43.1785 -+
 43.1786 -+  sec->used_by_bfd = sdata;
 43.1787 -+  return _bfd_elf_new_section_hook(abfd, sec);
 43.1788 -+}
 43.1789 -+
 43.1790 -+static struct avr32_relax_data *
 43.1791 -+avr32_relax_data(asection *sec)
 43.1792 -+{
 43.1793 -+  struct avr32_section_data *sdata;
 43.1794 -+
 43.1795 -+  BFD_ASSERT(sec->used_by_bfd);
 43.1796 -+
 43.1797 -+  sdata = (struct avr32_section_data *)elf_section_data(sec);
 43.1798 -+  return &sdata->relax_data;
 43.1799 -+}
 43.1800 -+
 43.1801 -+/* Link-time relaxation */
 43.1802 -+
 43.1803 -+static bfd_boolean
 43.1804 -+avr32_elf_relax_section(bfd *abfd, asection *sec,
 43.1805 -+			struct bfd_link_info *info, bfd_boolean *again);
 43.1806 -+
 43.1807 -+enum relax_pass_id {
 43.1808 -+  RELAX_PASS_SIZE_FRAGS,
 43.1809 -+  RELAX_PASS_MOVE_DATA,
 43.1810 -+};
 43.1811 -+
 43.1812 -+/* Stolen from the xtensa port */
 43.1813 -+static int
 43.1814 -+internal_reloc_compare (const void *ap, const void *bp)
 43.1815 -+{
 43.1816 -+  const Elf_Internal_Rela *a = (const Elf_Internal_Rela *) ap;
 43.1817 -+  const Elf_Internal_Rela *b = (const Elf_Internal_Rela *) bp;
 43.1818 -+
 43.1819 -+  if (a->r_offset != b->r_offset)
 43.1820 -+    return (a->r_offset - b->r_offset);
 43.1821 -+
 43.1822 -+  /* We don't need to sort on these criteria for correctness,
 43.1823 -+     but enforcing a more strict ordering prevents unstable qsort
 43.1824 -+     from behaving differently with different implementations.
 43.1825 -+     Without the code below we get correct but different results
 43.1826 -+     on Solaris 2.7 and 2.8.  We would like to always produce the
 43.1827 -+     same results no matter the host.  */
 43.1828 -+
 43.1829 -+  if (a->r_info != b->r_info)
 43.1830 -+    return (a->r_info - b->r_info);
 43.1831 -+
 43.1832 -+  return (a->r_addend - b->r_addend);
 43.1833 -+}
 43.1834 -+
 43.1835 -+static enum relax_state_id
 43.1836 -+get_pcrel22_relax_state(bfd *abfd, asection *sec, struct bfd_link_info *info,
 43.1837 -+			const Elf_Internal_Rela *rela)
 43.1838 -+{
 43.1839 -+  bfd_byte *contents;
 43.1840 -+  bfd_vma insn;
 43.1841 -+  enum relax_state_id rs = RS_NONE;
 43.1842 -+
 43.1843 -+  contents = retrieve_contents(abfd, sec, info->keep_memory);
 43.1844 -+  if (!contents)
 43.1845 -+    return RS_ERROR;
 43.1846 -+
 43.1847 -+  insn = bfd_get_32(abfd, contents + rela->r_offset);
 43.1848 -+  if ((insn & RCALL2_MASK) == RCALL2_OPCODE)
 43.1849 -+    rs = RS_RCALL2;
 43.1850 -+  else if ((insn & BRAL_MASK) == BRAL_OPCODE)
 43.1851 -+    /* Optimizing bral -> rjmp gets us into all kinds of
 43.1852 -+       trouble with jump tables. Better not do it.  */
 43.1853 -+    rs = RS_NONE;
 43.1854 -+  else if ((insn & BRC2_MASK) == BRC2_OPCODE)
 43.1855 -+    rs = RS_BRC2;
 43.1856 -+
 43.1857 -+  release_contents(sec, contents);
 43.1858 -+
 43.1859 -+  return rs;
 43.1860 -+}
 43.1861 -+
 43.1862 -+static enum relax_state_id
 43.1863 -+get_initial_relax_state(bfd *abfd, asection *sec, struct bfd_link_info *info,
 43.1864 -+			const Elf_Internal_Rela *rela)
 43.1865 -+{
 43.1866 -+  switch (ELF_R_TYPE(rela->r_info))
 43.1867 -+    {
 43.1868 -+    case R_AVR32_GOTCALL:
 43.1869 -+      return RS_PIC_CALL;
 43.1870 -+    case R_AVR32_GOT18SW:
 43.1871 -+      return RS_PIC_MCALL;
 43.1872 -+    case R_AVR32_LDA_GOT:
 43.1873 -+      return RS_PIC_LDA;
 43.1874 -+    case R_AVR32_GOT16S:
 43.1875 -+      return RS_PIC_LDW4;
 43.1876 -+    case R_AVR32_CPCALL:
 43.1877 -+      return RS_NOPIC_MCALL;
 43.1878 -+    case R_AVR32_16_CP:
 43.1879 -+      return RS_NOPIC_LDW4;
 43.1880 -+    case R_AVR32_9W_CP:
 43.1881 -+      return RS_NOPIC_LDDPC;
 43.1882 -+    case R_AVR32_ALIGN:
 43.1883 -+      return RS_ALIGN;
 43.1884 -+    case R_AVR32_32_CPENT:
 43.1885 -+      return RS_CPENT;
 43.1886 -+    case R_AVR32_22H_PCREL:
 43.1887 -+      return get_pcrel22_relax_state(abfd, sec, info, rela);
 43.1888 -+    case R_AVR32_9H_PCREL:
 43.1889 -+      return RS_BRC1;
 43.1890 -+    default:
 43.1891 -+      return RS_NONE;
 43.1892 -+    }
 43.1893 -+}
 43.1894 -+
 43.1895 -+static bfd_boolean
 43.1896 -+reloc_is_cpool_ref(const Elf_Internal_Rela *rela)
 43.1897 -+{
 43.1898 -+  switch (ELF_R_TYPE(rela->r_info))
 43.1899 -+    {
 43.1900 -+    case R_AVR32_CPCALL:
 43.1901 -+    case R_AVR32_16_CP:
 43.1902 -+    case R_AVR32_9W_CP:
 43.1903 -+      return TRUE;
 43.1904 -+    default:
 43.1905 -+      return FALSE;
 43.1906 -+    }
 43.1907 -+}
 43.1908 -+
 43.1909 -+static struct fragment *
 43.1910 -+new_frag(bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
 43.1911 -+	 struct avr32_relax_data *rd, enum relax_state_id state,
 43.1912 -+	 Elf_Internal_Rela *rela)
 43.1913 -+{
 43.1914 -+  struct fragment *frag;
 43.1915 -+  bfd_size_type r_size;
 43.1916 -+  bfd_vma r_offset;
 43.1917 -+  unsigned int i = rd->frag_count;
 43.1918 -+
 43.1919 -+  BFD_ASSERT(state >= RS_NONE && state < RS_MAX);
 43.1920 -+
 43.1921 -+  rd->frag_count++;
 43.1922 -+  frag = bfd_realloc(rd->frag, sizeof(struct fragment) * rd->frag_count);
 43.1923 -+  if (!frag)
 43.1924 -+    return NULL;
 43.1925 -+  rd->frag = frag;
 43.1926 -+
 43.1927 -+  frag += i;
 43.1928 -+  memset(frag, 0, sizeof(struct fragment));
 43.1929 -+
 43.1930 -+  if (state == RS_ALIGN)
 43.1931 -+    r_size = (((rela->r_offset + (1 << rela->r_addend) - 1)
 43.1932 -+	       & ~((1 << rela->r_addend) - 1)) - rela->r_offset);
 43.1933 -+  else
 43.1934 -+    r_size = relax_state[state].size;
 43.1935 -+
 43.1936 -+  if (rela)
 43.1937 -+    r_offset = rela->r_offset;
 43.1938 -+  else
 43.1939 -+    r_offset = sec->size;
 43.1940 -+
 43.1941 -+  if (i == 0)
 43.1942 -+    {
 43.1943 -+      frag->offset = 0;
 43.1944 -+      frag->size = r_offset + r_size;
 43.1945 -+    }
 43.1946 -+  else
 43.1947 -+    {
 43.1948 -+      frag->offset = rd->frag[i - 1].offset + rd->frag[i - 1].size;
 43.1949 -+      frag->size = r_offset + r_size - frag->offset;
 43.1950 -+    }
 43.1951 -+
 43.1952 -+  if (state != RS_CPENT)
 43.1953 -+    /* Make sure we don't discard this frag */
 43.1954 -+    frag->refcount = 1;
 43.1955 -+
 43.1956 -+  frag->initial_state = frag->state = state;
 43.1957 -+  frag->rela = rela;
 43.1958 -+
 43.1959 -+  return frag;
 43.1960 -+}
 43.1961 -+
 43.1962 -+static struct fragment *
 43.1963 -+find_frag(asection *sec, bfd_vma offset)
 43.1964 -+{
 43.1965 -+  struct fragment *first, *last;
 43.1966 -+  struct avr32_relax_data *rd = avr32_relax_data(sec);
 43.1967 -+
 43.1968 -+  if (rd->frag_count == 0)
 43.1969 -+    return NULL;
 43.1970 -+
 43.1971 -+  first = &rd->frag[0];
 43.1972 -+  last = &rd->frag[rd->frag_count - 1];
 43.1973 -+
 43.1974 -+  /* This may be a reloc referencing the end of a section.  The last
 43.1975 -+     frag will never have a reloc associated with it, so its size will
 43.1976 -+     never change, thus the offset adjustment of the last frag will
 43.1977 -+     always be the same as the offset adjustment of the end of the
 43.1978 -+     section.  */
 43.1979 -+  if (offset == sec->size)
 43.1980 -+    {
 43.1981 -+      BFD_ASSERT(last->offset + last->size == sec->size);
 43.1982 -+      BFD_ASSERT(!last->rela);
 43.1983 -+      return last;
 43.1984 -+    }
 43.1985 -+
 43.1986 -+  while (first <= last)
 43.1987 -+    {
 43.1988 -+      struct fragment *mid;
 43.1989 -+
 43.1990 -+      mid = (last - first) / 2 + first;
 43.1991 -+      if ((mid->offset + mid->size) <= offset)
 43.1992 -+	first = mid + 1;
 43.1993 -+      else if (mid->offset > offset)
 43.1994 -+	last = mid - 1;
 43.1995 -+      else
 43.1996 -+	return mid;
 43.1997 -+    }
 43.1998 -+
 43.1999 -+  return NULL;
 43.2000 -+}
 43.2001 -+
 43.2002 -+/* Look through all relocs in a section and determine if any relocs
 43.2003 -+   may be affected by relaxation in other sections.  If so, allocate
 43.2004 -+   an array of additional relocation data which links the affected
 43.2005 -+   relocations to the frag(s) where the relaxation may occur.
 43.2006 -+
 43.2007 -+   This function also links cpool references to cpool entries and
 43.2008 -+   increments the refcount of the latter when this happens.  */
 43.2009 -+
 43.2010 -+static bfd_boolean
 43.2011 -+allocate_reloc_data(bfd *abfd, asection *sec, Elf_Internal_Rela *relocs,
 43.2012 -+		    struct bfd_link_info *info)
 43.2013 -+{
 43.2014 -+  Elf_Internal_Shdr *symtab_hdr;
 43.2015 -+  Elf_Internal_Sym *isymbuf = NULL;
 43.2016 -+  struct avr32_relax_data *rd;
 43.2017 -+  unsigned int i;
 43.2018 -+  bfd_boolean ret = FALSE;
 43.2019 -+
 43.2020 -+  symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
 43.2021 -+  rd = avr32_relax_data(sec);
 43.2022 -+
 43.2023 -+  RDBG("%s<%s>: allocate_reloc_data\n", abfd->filename, sec->name);
 43.2024 -+
 43.2025 -+  for (i = 0; i < sec->reloc_count; i++)
 43.2026 -+    {
 43.2027 -+      Elf_Internal_Rela *rel = &relocs[i];
 43.2028 -+      asection *sym_sec;
 43.2029 -+      unsigned long r_symndx;
 43.2030 -+      bfd_vma sym_value;
 43.2031 -+
 43.2032 -+      if (!rel->r_addend && ELF_R_TYPE(rel->r_info) != R_AVR32_DIFF32
 43.2033 -+	  && !reloc_is_cpool_ref(rel))
 43.2034 -+	continue;
 43.2035 -+
 43.2036 -+      r_symndx = ELF_R_SYM(rel->r_info);
 43.2037 -+
 43.2038 -+      if (r_symndx < symtab_hdr->sh_info)
 43.2039 -+	{
 43.2040 -+	  Elf_Internal_Sym *isym;
 43.2041 -+
 43.2042 -+	  if (!isymbuf)
 43.2043 -+	    isymbuf = retrieve_local_syms(abfd, info->keep_memory);
 43.2044 -+	  if (!isymbuf)
 43.2045 -+	    return FALSE;
 43.2046 -+
 43.2047 -+	  isym = &isymbuf[r_symndx];
 43.2048 -+	  sym_sec = bfd_section_from_elf_index(abfd, isym->st_shndx);
 43.2049 -+	  sym_value = isym->st_value;
 43.2050 -+	}
 43.2051 -+      else
 43.2052 -+	{
 43.2053 -+	  struct elf_link_hash_entry *h;
 43.2054 -+
 43.2055 -+	  h = elf_sym_hashes(abfd)[r_symndx - symtab_hdr->sh_info];
 43.2056 -+
 43.2057 -+	  while (h->root.type == bfd_link_hash_indirect
 43.2058 -+		 || h->root.type == bfd_link_hash_warning)
 43.2059 -+	    h = (struct elf_link_hash_entry *)h->root.u.i.link;
 43.2060 -+
 43.2061 -+	  if (h->root.type != bfd_link_hash_defined
 43.2062 -+	      && h->root.type != bfd_link_hash_defweak)
 43.2063 -+	    continue;
 43.2064 -+
 43.2065 -+	  sym_sec = h->root.u.def.section;
 43.2066 -+	  sym_value = h->root.u.def.value;
 43.2067 -+	}
 43.2068 -+
 43.2069 -+      if (sym_sec && avr32_relax_data(sym_sec)->is_relaxable)
 43.2070 -+	{
 43.2071 -+	  bfd_size_type size;
 43.2072 -+	  struct fragment *frag;
 43.2073 -+
 43.2074 -+	  if (!rd->reloc_data)
 43.2075 -+	    {
 43.2076 -+	      size = sizeof(struct avr32_reloc_data) * sec->reloc_count;
 43.2077 -+	      rd->reloc_data = bfd_zalloc(abfd, size);
 43.2078 -+	      if (!rd->reloc_data)
 43.2079 -+		goto out;
 43.2080 -+	    }
 43.2081 -+
 43.2082 -+	  RDBG("[%3d] 0x%04lx: target: 0x%lx + 0x%lx",
 43.2083 -+	       i, rel->r_offset, sym_value, rel->r_addend);
 43.2084 -+
 43.2085 -+	  frag = find_frag(sym_sec, sym_value + rel->r_addend);
 43.2086 -+	  BFD_ASSERT(frag);
 43.2087 -+	  rd->reloc_data[i].add_frag = frag;
 43.2088 -+
 43.2089 -+	  RDBG(" -> %s<%s>:%04lx\n", sym_sec->owner->filename, sym_sec->name,
 43.2090 -+	       frag->rela ? frag->rela->r_offset : sym_sec->size);
 43.2091 -+
 43.2092 -+	  if (reloc_is_cpool_ref(rel))
 43.2093 -+	    {
 43.2094 -+	      BFD_ASSERT(ELF_R_TYPE(frag->rela->r_info) == R_AVR32_32_CPENT);
 43.2095 -+	      frag->refcount++;
 43.2096 -+	    }
 43.2097 -+
 43.2098 -+	  if (ELF_R_TYPE(rel->r_info) == R_AVR32_DIFF32)
 43.2099 -+	    {
 43.2100 -+	      bfd_byte *contents;
 43.2101 -+	      bfd_signed_vma diff;
 43.2102 -+
 43.2103 -+	      contents = retrieve_contents(abfd, sec, info->keep_memory);
 43.2104 -+	      if (!contents)
 43.2105 -+		goto out;
 43.2106 -+
 43.2107 -+	      diff = bfd_get_signed_32(abfd, contents + rel->r_offset);
 43.2108 -+	      frag = find_frag(sym_sec, sym_value + rel->r_addend + diff);
 43.2109 -+	      BFD_ASSERT(frag);
 43.2110 -+	      rd->reloc_data[i].sub_frag = frag;
 43.2111 -+
 43.2112 -+	      release_contents(sec, contents);
 43.2113 -+	    }
 43.2114 -+	}
 43.2115 -+    }
 43.2116 -+
 43.2117 -+  ret = TRUE;
 43.2118 -+
 43.2119 -+ out:
 43.2120 -+  release_local_syms(abfd, isymbuf);
 43.2121 -+  return ret;
 43.2122 -+}
 43.2123 -+
 43.2124 -+static bfd_boolean
 43.2125 -+global_sym_set_frag(struct elf_avr32_link_hash_entry *havr,
 43.2126 -+		    struct bfd_link_info *info ATTRIBUTE_UNUSED)
 43.2127 -+{
 43.2128 -+  struct fragment *frag;
 43.2129 -+  asection *sec;
 43.2130 -+
 43.2131 -+  if (havr->root.root.type != bfd_link_hash_defined
 43.2132 -+      && havr->root.root.type != bfd_link_hash_defweak)
 43.2133 -+    return TRUE;
 43.2134 -+
 43.2135 -+  sec = havr->root.root.u.def.section;
 43.2136 -+  if (bfd_is_const_section(sec)
 43.2137 -+      || !avr32_relax_data(sec)->is_relaxable)
 43.2138 -+    return TRUE;
 43.2139 -+
 43.2140 -+  frag = find_frag(sec, havr->root.root.u.def.value);
 43.2141 -+  if (!frag)
 43.2142 -+    {
 43.2143 -+      unsigned int i;
 43.2144 -+      struct avr32_relax_data *rd = avr32_relax_data(sec);
 43.2145 -+
 43.2146 -+      RDBG("In %s: No frag for %s <%s+%lu> (limit %lu)\n",
 43.2147 -+	   sec->owner->filename, havr->root.root.root.string,
 43.2148 -+	   sec->name, havr->root.root.u.def.value, sec->size);
 43.2149 -+      for (i = 0; i < rd->frag_count; i++)
 43.2150 -+	RDBG("    %8lu - %8lu\n", rd->frag[i].offset,
 43.2151 -+	     rd->frag[i].offset + rd->frag[i].size);
 43.2152 -+    }
 43.2153 -+  BFD_ASSERT(frag);
 43.2154 -+
 43.2155 -+  havr->sym_frag = frag;
 43.2156 -+  return TRUE;
 43.2157 -+}
 43.2158 -+
 43.2159 -+static bfd_boolean
 43.2160 -+analyze_relocations(struct bfd_link_info *info)
 43.2161 -+{
 43.2162 -+  bfd *abfd;
 43.2163 -+  asection *sec;
 43.2164 -+
 43.2165 -+  /* Divide all relaxable sections into fragments */
 43.2166 -+  for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
 43.2167 -+    {
 43.2168 -+      if (!(elf_elfheader(abfd)->e_flags & EF_AVR32_LINKRELAX))
 43.2169 -+	{
 43.2170 -+	  if (!(*info->callbacks->warning)
 43.2171 -+	      (info, _("input is not relaxable"), NULL, abfd, NULL, 0))
 43.2172 -+	    return FALSE;
 43.2173 -+	  continue;
 43.2174 -+	}
 43.2175 -+
 43.2176 -+      for (sec = abfd->sections; sec; sec = sec->next)
 43.2177 -+	{
 43.2178 -+	  struct avr32_relax_data *rd;
 43.2179 -+	  struct fragment *frag;
 43.2180 -+	  Elf_Internal_Rela *relocs;
 43.2181 -+	  unsigned int i;
 43.2182 -+	  bfd_boolean ret = TRUE;
 43.2183 -+
 43.2184 -+	  if (!(sec->flags & SEC_RELOC) || sec->reloc_count == 0)
 43.2185 -+	    continue;
 43.2186 -+
 43.2187 -+	  rd = avr32_relax_data(sec);
 43.2188 -+
 43.2189 -+	  relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
 43.2190 -+	  if (!relocs)
 43.2191 -+	    return FALSE;
 43.2192 -+
 43.2193 -+	  qsort(relocs, sec->reloc_count, sizeof(Elf_Internal_Rela),
 43.2194 -+		internal_reloc_compare);
 43.2195 -+
 43.2196 -+	  for (i = 0; i < sec->reloc_count; i++)
 43.2197 -+	    {
 43.2198 -+	      enum relax_state_id state;
 43.2199 -+
 43.2200 -+	      ret = FALSE;
 43.2201 -+	      state = get_initial_relax_state(abfd, sec, info, &relocs[i]);
 43.2202 -+	      if (state == RS_ERROR)
 43.2203 -+		break;
 43.2204 -+
 43.2205 -+	      if (state)
 43.2206 -+		{
 43.2207 -+		  frag = new_frag(abfd, sec, rd, state, &relocs[i]);
 43.2208 -+		  if (!frag)
 43.2209 -+		    break;
 43.2210 -+
 43.2211 -+		  pin_internal_relocs(sec, relocs);
 43.2212 -+		  rd->is_relaxable = TRUE;
 43.2213 -+		}
 43.2214 -+
 43.2215 -+	      ret = TRUE;
 43.2216 -+	    }
 43.2217 -+
 43.2218 -+	  release_internal_relocs(sec, relocs);
 43.2219 -+	  if (!ret)
 43.2220 -+	    return ret;
 43.2221 -+
 43.2222 -+	  if (rd->is_relaxable)
 43.2223 -+	    {
 43.2224 -+	      frag = new_frag(abfd, sec, rd, RS_NONE, NULL);
 43.2225 -+	      if (!frag)
 43.2226 -+		return FALSE;
 43.2227 -+	    }
 43.2228 -+	}
 43.2229 -+    }
 43.2230 -+
 43.2231 -+  /* Link each global symbol to the fragment where it's defined.  */
 43.2232 -+  elf_link_hash_traverse(elf_hash_table(info), global_sym_set_frag, info);
 43.2233 -+
 43.2234 -+  /* Do the same for local symbols. */
 43.2235 -+  for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
 43.2236 -+    {
 43.2237 -+      Elf_Internal_Sym *isymbuf, *isym;
 43.2238 -+      struct fragment **local_sym_frag;
 43.2239 -+      unsigned int i, sym_count;
 43.2240 -+
 43.2241 -+      sym_count = elf_tdata(abfd)->symtab_hdr.sh_info;
 43.2242 -+      if (sym_count == 0)
 43.2243 -+	continue;
 43.2244 -+
 43.2245 -+      local_sym_frag = bfd_zalloc(abfd, sym_count * sizeof(struct fragment *));
 43.2246 -+      if (!local_sym_frag)
 43.2247 -+	return FALSE;
 43.2248 -+      elf_tdata(abfd)->local_sym_frag = local_sym_frag;
 43.2249 -+
 43.2250 -+      isymbuf = retrieve_local_syms(abfd, info->keep_memory);
 43.2251 -+      if (!isymbuf)
 43.2252 -+	return FALSE;
 43.2253 -+
 43.2254 -+      for (i = 0; i < sym_count; i++)
 43.2255 -+	{
 43.2256 -+	  struct avr32_relax_data *rd;
 43.2257 -+	  struct fragment *frag;
 43.2258 -+	  asection *sec;
 43.2259 -+
 43.2260 -+	  isym = &isymbuf[i];
 43.2261 -+
 43.2262 -+	  sec = bfd_section_from_elf_index(abfd, isym->st_shndx);
 43.2263 -+	  if (!sec)
 43.2264 -+	    continue;
 43.2265 -+
 43.2266 -+	  rd = avr32_relax_data(sec);
 43.2267 -+	  if (!rd->is_relaxable)
 43.2268 -+	    continue;
 43.2269 -+
 43.2270 -+	  frag = find_frag(sec, isym->st_value);
 43.2271 -+	  BFD_ASSERT(frag);
 43.2272 -+
 43.2273 -+	  local_sym_frag[i] = frag;
 43.2274 -+	}
 43.2275 -+
 43.2276 -+      release_local_syms(abfd, isymbuf);
 43.2277 -+    }
 43.2278 -+
 43.2279 -+  /* And again for relocs with addends and constant pool references */
 43.2280 -+  for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
 43.2281 -+    for (sec = abfd->sections; sec; sec = sec->next)
 43.2282 -+      {
 43.2283 -+	Elf_Internal_Rela *relocs;
 43.2284 -+	bfd_boolean ret;
 43.2285 -+
 43.2286 -+	if (!(sec->flags & SEC_RELOC) || sec->reloc_count == 0)
 43.2287 -+	  continue;
 43.2288 -+
 43.2289 -+	relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
 43.2290 -+	if (!relocs)
 43.2291 -+	  return FALSE;
 43.2292 -+
 43.2293 -+	ret = allocate_reloc_data(abfd, sec, relocs, info);
 43.2294 -+
 43.2295 -+	release_internal_relocs(sec, relocs);
 43.2296 -+	if (ret == FALSE)
 43.2297 -+	  return ret;
 43.2298 -+      }
 43.2299 -+
 43.2300 -+  return TRUE;
 43.2301 -+}
 43.2302 -+
 43.2303 -+static bfd_boolean
 43.2304 -+rs_is_good_enough(const struct relax_state *rs, struct fragment *frag,
 43.2305 -+		  bfd_vma symval, bfd_vma addr, struct got_entry *got,
 43.2306 -+		  struct avr32_reloc_data *ind_data,
 43.2307 -+		  bfd_signed_vma offset_adjust)
 43.2308 -+{
 43.2309 -+  bfd_signed_vma target = 0;
 43.2310 -+
 43.2311 -+  switch (rs->reftype)
 43.2312 -+    {
 43.2313 -+    case REF_ABSOLUTE:
 43.2314 -+      target = symval;
 43.2315 -+      break;
 43.2316 -+    case REF_PCREL:
 43.2317 -+      target = symval - addr;
 43.2318 -+      break;
 43.2319 -+    case REF_CPOOL:
 43.2320 -+      /* cpool frags are always in the same section and always after
 43.2321 -+	 all frags referring to it.  So it's always correct to add in
 43.2322 -+	 offset_adjust here.  */
 43.2323 -+      target = (ind_data->add_frag->offset + ind_data->add_frag->offset_adjust
 43.2324 -+		+ offset_adjust - frag->offset - frag->offset_adjust);
 43.2325 -+      break;
 43.2326 -+    case REF_GOT:
 43.2327 -+      target = got->offset;
 43.2328 -+      break;
 43.2329 -+    default:
 43.2330 -+      abort();
 43.2331 -+    }
 43.2332 -+
 43.2333 -+  if (target >= rs->range_min && target <= rs->range_max)
 43.2334 -+    return TRUE;
 43.2335 -+  else
 43.2336 -+    return FALSE;
 43.2337 -+}
 43.2338 -+
 43.2339 -+static bfd_boolean
 43.2340 -+avr32_size_frags(bfd *abfd, asection *sec, struct bfd_link_info *info)
 43.2341 -+{
 43.2342 -+  struct elf_avr32_link_hash_table *htab;
 43.2343 -+  struct avr32_relax_data *rd;
 43.2344 -+  Elf_Internal_Shdr *symtab_hdr;
 43.2345 -+  Elf_Internal_Rela *relocs = NULL;
 43.2346 -+  Elf_Internal_Sym *isymbuf = NULL;
 43.2347 -+  struct got_entry **local_got_ents;
 43.2348 -+  struct fragment **local_sym_frag;
 43.2349 -+  bfd_boolean ret = FALSE;
 43.2350 -+  bfd_signed_vma delta = 0;
 43.2351 -+  unsigned int i;
 43.2352 -+
 43.2353 -+  htab = avr32_elf_hash_table(info);
 43.2354 -+  rd = avr32_relax_data(sec);
 43.2355 -+
 43.2356 -+  if (sec == htab->sgot)
 43.2357 -+    {
 43.2358 -+      RDBG("Relaxing GOT section (vma: 0x%lx)\n",
 43.2359 -+	   sec->output_section->vma + sec->output_offset);
 43.2360 -+      if (assign_got_offsets(htab))
 43.2361 -+	htab->repeat_pass = TRUE;
 43.2362 -+      return TRUE;
 43.2363 -+    }
 43.2364 -+
 43.2365 -+  if (!rd->is_relaxable)
 43.2366 -+    return TRUE;
 43.2367 -+
 43.2368 -+  if (!sec->rawsize)
 43.2369 -+    sec->rawsize = sec->size;
 43.2370 -+
 43.2371 -+  symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
 43.2372 -+  relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
 43.2373 -+  if (!relocs)
 43.2374 -+    goto out;
 43.2375 -+
 43.2376 -+  isymbuf = retrieve_local_syms(abfd, info->keep_memory);
 43.2377 -+  if (!isymbuf)
 43.2378 -+    goto out;
 43.2379 -+
 43.2380 -+  local_got_ents = elf_local_got_ents(abfd);
 43.2381 -+  local_sym_frag = elf_tdata(abfd)->local_sym_frag;
 43.2382 -+
 43.2383 -+  RDBG("size_frags: %s<%s>\n  vma: 0x%08lx, size: 0x%08lx\n",
 43.2384 -+       abfd->filename, sec->name,
 43.2385 -+       sec->output_section->vma + sec->output_offset, sec->size);
 43.2386 -+
 43.2387 -+  for (i = 0; i < rd->frag_count; i++)
 43.2388 -+    {
 43.2389 -+      struct fragment *frag = &rd->frag[i];
 43.2390 -+      struct avr32_reloc_data *r_data = NULL, *ind_data = NULL;
 43.2391 -+      const struct relax_state *state, *next_state;
 43.2392 -+      struct fragment *target_frag = NULL;
 43.2393 -+      asection *sym_sec = NULL;
 43.2394 -+      Elf_Internal_Rela *rela;
 43.2395 -+      struct got_entry *got;
 43.2396 -+      bfd_vma symval, r_offset, addend, addr;
 43.2397 -+      bfd_signed_vma size_adjust = 0, distance;
 43.2398 -+      unsigned long r_symndx;
 43.2399 -+      bfd_boolean defined = TRUE, dynamic = FALSE;
 43.2400 -+      unsigned char sym_type;
 43.2401 -+
 43.2402 -+      frag->offset_adjust += delta;
 43.2403 -+      state = next_state = &relax_state[frag->state];
 43.2404 -+      rela = frag->rela;
 43.2405 -+
 43.2406 -+      BFD_ASSERT(state->id == frag->state);
 43.2407 -+
 43.2408 -+      RDBG("  0x%04lx%c%d: %s [size %ld]", rela ? rela->r_offset : sec->rawsize,
 43.2409 -+	   (frag->offset_adjust < 0)?'-':'+',
 43.2410 -+	   abs(frag->offset_adjust), state->name, state->size);
 43.2411 -+
 43.2412 -+      if (!rela)
 43.2413 -+	{
 43.2414 -+	  RDBG(": no reloc, ignoring\n");
 43.2415 -+	  continue;
 43.2416 -+	}
 43.2417 -+
 43.2418 -+      BFD_ASSERT((unsigned int)(rela - relocs) < sec->reloc_count);
 43.2419 -+      BFD_ASSERT(state != RS_NONE);
 43.2420 -+
 43.2421 -+      r_offset = rela->r_offset + frag->offset_adjust;
 43.2422 -+      addr = sec->output_section->vma + sec->output_offset + r_offset;
 43.2423 -+
 43.2424 -+      switch (frag->state)
 43.2425 -+	{
 43.2426 -+	case RS_ALIGN:
 43.2427 -+	  size_adjust = ((addr + (1 << rela->r_addend) - 1)
 43.2428 -+			 & ~((1 << rela->r_addend) - 1));
 43.2429 -+	  size_adjust -= (sec->output_section->vma + sec->output_offset
 43.2430 -+			  + frag->offset + frag->offset_adjust
 43.2431 -+			  + frag->size + frag->size_adjust);
 43.2432 -+
 43.2433 -+	  RDBG(": adjusting size %lu -> %lu\n", frag->size + frag->size_adjust,
 43.2434 -+	       frag->size + frag->size_adjust + size_adjust);
 43.2435 -+	  break;
 43.2436 -+
 43.2437 -+	case RS_CPENT:
 43.2438 -+	  if (frag->refcount == 0 && frag->size_adjust == 0)
 43.2439 -+	    {
 43.2440 -+	      RDBG(": discarding frag\n");
 43.2441 -+	      size_adjust = -4;
 43.2442 -+	    }
 43.2443 -+	  else if (frag->refcount > 0 && frag->size_adjust < 0)
 43.2444 -+	    {
 43.2445 -+	      RDBG(": un-discarding frag\n");
 43.2446 -+	      size_adjust = 4;
 43.2447 -+	    }
 43.2448 -+	  break;
 43.2449 -+
 43.2450 -+	default:
 43.2451 -+	  if (rd->reloc_data)
 43.2452 -+	    r_data = &rd->reloc_data[frag->rela - relocs];
 43.2453 -+
 43.2454 -+	  /* If this is a cpool reference, we want the symbol that the
 43.2455 -+	     cpool entry refers to, not the symbol for the cpool entry
 43.2456 -+	     itself, as we already know what frag it's in.  */
 43.2457 -+	  if (relax_state[frag->initial_state].reftype == REF_CPOOL)
 43.2458 -+	    {
 43.2459 -+	      Elf_Internal_Rela *irela = r_data->add_frag->rela;
 43.2460 -+
 43.2461 -+	      r_symndx = ELF_R_SYM(irela->r_info);
 43.2462 -+	      addend = irela->r_addend;
 43.2463 -+
 43.2464 -+	      /* The constant pool must be in the same section as the
 43.2465 -+		 reloc referring to it.  */
 43.2466 -+	      BFD_ASSERT((unsigned long)(irela - relocs) < sec->reloc_count);
 43.2467 -+
 43.2468 -+	      ind_data = r_data;
 43.2469 -+	      r_data = &rd->reloc_data[irela - relocs];
 43.2470 -+	    }
 43.2471 -+	  else
 43.2472 -+	    {
 43.2473 -+	      r_symndx = ELF_R_SYM(rela->r_info);
 43.2474 -+	      addend = rela->r_addend;
 43.2475 -+	    }
 43.2476 -+
 43.2477 -+	  /* Get the value of the symbol referred to by the reloc.  */
 43.2478 -+	  if (r_symndx < symtab_hdr->sh_info)
 43.2479 -+	    {
 43.2480 -+	      Elf_Internal_Sym *isym;
 43.2481 -+
 43.2482 -+	      isym = isymbuf + r_symndx;
 43.2483 -+	      symval = 0;
 43.2484 -+
 43.2485 -+	      RDBG(" local sym %lu: ", r_symndx);
 43.2486 -+
 43.2487 -+	      if (isym->st_shndx == SHN_UNDEF)
 43.2488 -+		defined = FALSE;
 43.2489 -+	      else if (isym->st_shndx == SHN_ABS)
 43.2490 -+		sym_sec = bfd_abs_section_ptr;
 43.2491 -+	      else if (isym->st_shndx == SHN_COMMON)
 43.2492 -+		sym_sec = bfd_com_section_ptr;
 43.2493 -+	      else
 43.2494 -+		sym_sec = bfd_section_from_elf_index(abfd, isym->st_shndx);
 43.2495 -+
 43.2496 -+	      symval = isym->st_value;
 43.2497 -+	      sym_type = ELF_ST_TYPE(isym->st_info);
 43.2498 -+	      target_frag = local_sym_frag[r_symndx];
 43.2499 -+
 43.2500 -+	      if (local_got_ents)
 43.2501 -+		got = local_got_ents[r_symndx];
 43.2502 -+	      else
 43.2503 -+		got = NULL;
 43.2504 -+	    }
 43.2505 -+	  else
 43.2506 -+	    {
 43.2507 -+	      /* Global symbol */
 43.2508 -+	      unsigned long index;
 43.2509 -+	      struct elf_link_hash_entry *h;
 43.2510 -+	      struct elf_avr32_link_hash_entry *havr;
 43.2511 -+
 43.2512 -+	      index = r_symndx - symtab_hdr->sh_info;
 43.2513 -+	      h = elf_sym_hashes(abfd)[index];
 43.2514 -+	      BFD_ASSERT(h != NULL);
 43.2515 -+
 43.2516 -+	      while (h->root.type == bfd_link_hash_indirect
 43.2517 -+		     || h->root.type == bfd_link_hash_warning)
 43.2518 -+		h = (struct elf_link_hash_entry *)h->root.u.i.link;
 43.2519 -+
 43.2520 -+	      havr = (struct elf_avr32_link_hash_entry *)h;
 43.2521 -+	      got = h->got.glist;
 43.2522 -+
 43.2523 -+	      symval = 0;
 43.2524 -+
 43.2525 -+	      RDBG(" %s: ", h->root.root.string);
 43.2526 -+
 43.2527 -+	      if (h->root.type != bfd_link_hash_defined
 43.2528 -+		  && h->root.type != bfd_link_hash_defweak)
 43.2529 -+		{
 43.2530 -+		  RDBG("(undef)");
 43.2531 -+		  defined = FALSE;
 43.2532 -+		}
 43.2533 -+	      else if ((info->shared && !info->symbolic && h->dynindx != -1)
 43.2534 -+		       || (htab->root.dynamic_sections_created
 43.2535 -+			   && h->def_dynamic && !h->def_regular))
 43.2536 -+		{
 43.2537 -+		  RDBG("(dynamic)");
 43.2538 -+		  dynamic = TRUE;
 43.2539 -+		  sym_sec = h->root.u.def.section;
 43.2540 -+		}
 43.2541 -+	      else
 43.2542 -+		{
 43.2543 -+		  sym_sec = h->root.u.def.section;
 43.2544 -+		  symval = h->root.u.def.value;
 43.2545 -+		  target_frag = havr->sym_frag;
 43.2546 -+		}
 43.2547 -+
 43.2548 -+	      sym_type = h->type;
 43.2549 -+	    }
 43.2550 -+
 43.2551 -+	  /* Thanks to elf32-ppc for this one.  */
 43.2552 -+	  if (sym_sec && sym_sec->sec_info_type == ELF_INFO_TYPE_MERGE)
 43.2553 -+	    {
 43.2554 -+	      /* At this stage in linking, no SEC_MERGE symbol has been
 43.2555 -+		 adjusted, so all references to such symbols need to be
 43.2556 -+		 passed through _bfd_merged_section_offset.  (Later, in
 43.2557 -+		 relocate_section, all SEC_MERGE symbols *except* for
 43.2558 -+		 section symbols have been adjusted.)
 43.2559 -+
 43.2560 -+	         SEC_MERGE sections are not relaxed by us, as they
 43.2561 -+	         shouldn't contain any code.  */
 43.2562 -+
 43.2563 -+	      BFD_ASSERT(!target_frag && !(r_data && r_data->add_frag));
 43.2564 -+
 43.2565 -+	      /* gas may reduce relocations against symbols in SEC_MERGE
 43.2566 -+		 sections to a relocation against the section symbol when
 43.2567 -+		 the original addend was zero.  When the reloc is against
 43.2568 -+		 a section symbol we should include the addend in the
 43.2569 -+		 offset passed to _bfd_merged_section_offset, since the
 43.2570 -+		 location of interest is the original symbol.  On the
 43.2571 -+		 other hand, an access to "sym+addend" where "sym" is not
 43.2572 -+		 a section symbol should not include the addend;  Such an
 43.2573 -+		 access is presumed to be an offset from "sym";  The
 43.2574 -+		 location of interest is just "sym".  */
 43.2575 -+	      RDBG("\n    MERGE: %s: 0x%lx+0x%lx+0x%lx -> ",
 43.2576 -+		   (sym_type == STT_SECTION)?"section":"not section",
 43.2577 -+		   sym_sec->output_section->vma + sym_sec->output_offset,
 43.2578 -+		   symval, addend);
 43.2579 -+
 43.2580 -+	      if (sym_type == STT_SECTION)
 43.2581 -+		symval += addend;
 43.2582 -+
 43.2583 -+	      symval = (_bfd_merged_section_offset
 43.2584 -+			(abfd, &sym_sec,
 43.2585 -+			 elf_section_data(sym_sec)->sec_info, symval));
 43.2586 -+
 43.2587 -+	      if (sym_type != STT_SECTION)
 43.2588 -+		symval += addend;
 43.2589 -+	    }
 43.2590 -+	  else
 43.2591 -+	    symval += addend;
 43.2592 -+
 43.2593 -+	  if (defined && !dynamic)
 43.2594 -+	    {
 43.2595 -+	      RDBG("0x%lx+0x%lx",
 43.2596 -+		   sym_sec->output_section->vma + sym_sec->output_offset,
 43.2597 -+		   symval);
 43.2598 -+	      symval += sym_sec->output_section->vma + sym_sec->output_offset;
 43.2599 -+	    }
 43.2600 -+
 43.2601 -+	  if (r_data && r_data->add_frag)
 43.2602 -+	    /* If the add_frag pointer is set, it means that this reloc
 43.2603 -+	       has an addend that may be affected by relaxation.  */
 43.2604 -+	    target_frag = r_data->add_frag;
 43.2605 -+
 43.2606 -+	  if (target_frag)
 43.2607 -+	    {
 43.2608 -+	      symval += target_frag->offset_adjust;
 43.2609 -+
 43.2610 -+	      /* If target_frag comes after this frag in the same
 43.2611 -+		 section, we should assume that it will be moved by
 43.2612 -+		 the same amount we are.  */
 43.2613 -+	      if ((target_frag - rd->frag) < (int)rd->frag_count
 43.2614 -+		  && target_frag > frag)
 43.2615 -+		symval += delta;
 43.2616 -+	    }
 43.2617 -+
 43.2618 -+	  distance = symval - addr;
 43.2619 -+
 43.2620 -+	  /* First, try to make a direct reference.  If the symbol is
 43.2621 -+	     dynamic or undefined, we must take care not to change its
 43.2622 -+	     reference type, that is, we can't make it direct.
 43.2623 -+
 43.2624 -+	     Also, it seems like some sections may actually be resized
 43.2625 -+	     after the relaxation code is done, so we can't really
 43.2626 -+	     trust that our "distance" is correct.  There's really no
 43.2627 -+	     easy solution to this problem, so we'll just disallow
 43.2628 -+	     direct references to SEC_DATA sections.
 43.2629 -+
 43.2630 -+	     Oh, and .bss isn't actually SEC_DATA, so we disallow
 43.2631 -+	     !SEC_HAS_CONTENTS as well. */
 43.2632 -+	  if (!dynamic && defined
 43.2633 -+	      && (htab->direct_data_refs
 43.2634 -+		  || (!(sym_sec->flags & SEC_DATA)
 43.2635 -+		      && (sym_sec->flags & SEC_HAS_CONTENTS)))
 43.2636 -+	      && next_state->direct)
 43.2637 -+	    {
 43.2638 -+	      next_state = &relax_state[next_state->direct];
 43.2639 -+	      RDBG(" D-> %s", next_state->name);
 43.2640 -+	    }
 43.2641 -+
 43.2642 -+	  /* Iterate backwards until we find a state that fits.  */
 43.2643 -+	  while (next_state->prev
 43.2644 -+		 && !rs_is_good_enough(next_state, frag, symval, addr,
 43.2645 -+				       got, ind_data, delta))
 43.2646 -+	    {
 43.2647 -+	      next_state = &relax_state[next_state->prev];
 43.2648 -+	      RDBG(" P-> %s", next_state->name);
 43.2649 -+	    }
 43.2650 -+
 43.2651 -+	  /* Then try to find the best possible state.  */
 43.2652 -+	  while (next_state->next)
 43.2653 -+	    {
 43.2654 -+	      const struct relax_state *candidate;
 43.2655 -+
 43.2656 -+	      candidate = &relax_state[next_state->next];
 43.2657 -+	      if (!rs_is_good_enough(candidate, frag, symval, addr, got,
 43.2658 -+				     ind_data, delta))
 43.2659 -+		break;
 43.2660 -+
 43.2661 -+	      next_state = candidate;
 43.2662 -+	      RDBG(" N-> %s", next_state->name);
 43.2663 -+	    }
 43.2664 -+
 43.2665 -+	  RDBG(" [size %ld]\n", next_state->size);
 43.2666 -+
 43.2667 -+	  BFD_ASSERT(next_state->id);
 43.2668 -+	  BFD_ASSERT(!dynamic || next_state->reftype == REF_GOT);
 43.2669 -+
 43.2670 -+	  size_adjust = next_state->size - state->size;
 43.2671 -+
 43.2672 -+	  /* There's a theoretical possibility that shrinking one frag
 43.2673 -+	     may cause another to grow, which may cause the first one to
 43.2674 -+	     grow as well, and we're back where we started.  Avoid this
 43.2675 -+	     scenario by disallowing a frag that has grown to ever
 43.2676 -+	     shrink again.  */
 43.2677 -+	  if (state->reftype == REF_GOT && next_state->reftype != REF_GOT)
 43.2678 -+	    {
 43.2679 -+	      if (frag->has_grown)
 43.2680 -+		next_state = state;
 43.2681 -+	      else
 43.2682 -+		unref_got_entry(htab, got);
 43.2683 -+	    }
 43.2684 -+	  else if (state->reftype != REF_GOT && next_state->reftype == REF_GOT)
 43.2685 -+	    {
 43.2686 -+	      ref_got_entry(htab, got);
 43.2687 -+	      frag->has_grown = TRUE;
 43.2688 -+	    }
 43.2689 -+	  else if (state->reftype == REF_CPOOL
 43.2690 -+		   && next_state->reftype != REF_CPOOL)
 43.2691 -+	    {
 43.2692 -+	      if (frag->has_grown)
 43.2693 -+		next_state = state;
 43.2694 -+	      else
 43.2695 -+		ind_data->add_frag->refcount--;
 43.2696 -+	    }
 43.2697 -+	  else if (state->reftype != REF_CPOOL
 43.2698 -+		   && next_state->reftype == REF_CPOOL)
 43.2699 -+	    {
 43.2700 -+	      ind_data->add_frag->refcount++;
 43.2701 -+	      frag->has_grown = TRUE;
 43.2702 -+	    }
 43.2703 -+	  else
 43.2704 -+	    {
 43.2705 -+	      if (frag->has_grown && size_adjust < 0)
 43.2706 -+		next_state = state;
 43.2707 -+	      else if (size_adjust > 0)
 43.2708 -+		frag->has_grown = TRUE;
 43.2709 -+	    }
 43.2710 -+
 43.2711 -+	  size_adjust = next_state->size - state->size;
 43.2712 -+	  frag->state = next_state->id;
 43.2713 -+
 43.2714 -+	  break;
 43.2715 -+	}
 43.2716 -+
 43.2717 -+      if (size_adjust)
 43.2718 -+	htab->repeat_pass = TRUE;
 43.2719 -+
 43.2720 -+      frag->size_adjust += size_adjust;
 43.2721 -+      sec->size += size_adjust;
 43.2722 -+      delta += size_adjust;
 43.2723 -+
 43.2724 -+      BFD_ASSERT((frag->offset + frag->offset_adjust
 43.2725 -+		  + frag->size + frag->size_adjust)
 43.2726 -+		 == (frag[1].offset + frag[1].offset_adjust + delta));
 43.2727 -+    }
 43.2728 -+
 43.2729 -+  ret = TRUE;
 43.2730 -+
 43.2731 -+ out:
 43.2732 -+  release_local_syms(abfd, isymbuf);
 43.2733 -+  release_internal_relocs(sec, relocs);
 43.2734 -+  return ret;
 43.2735 -+}
 43.2736 -+
 43.2737 -+static bfd_boolean
 43.2738 -+adjust_global_symbol(struct elf_avr32_link_hash_entry *havr,
 43.2739 -+		     struct bfd_link_info *info ATTRIBUTE_UNUSED)
 43.2740 -+{
 43.2741 -+  struct elf_link_hash_entry *h = &havr->root;
 43.2742 -+
 43.2743 -+  if (havr->sym_frag && (h->root.type == bfd_link_hash_defined
 43.2744 -+			 || h->root.type == bfd_link_hash_defweak))
 43.2745 -+    {
 43.2746 -+      RDBG("adjust_global_symbol: %s 0x%08lx -> 0x%08lx\n",
 43.2747 -+	   h->root.root.string, h->root.u.def.value,
 43.2748 -+	   h->root.u.def.value + havr->sym_frag->offset_adjust);
 43.2749 -+      h->root.u.def.value += havr->sym_frag->offset_adjust;
 43.2750 -+    }
 43.2751 -+  return TRUE;
 43.2752 -+}
 43.2753 -+
 43.2754 -+static bfd_boolean
 43.2755 -+adjust_syms(struct bfd_link_info *info)
 43.2756 -+{
 43.2757 -+  struct elf_avr32_link_hash_table *htab;
 43.2758 -+  bfd *abfd;
 43.2759 -+
 43.2760 -+  htab = avr32_elf_hash_table(info);
 43.2761 -+  elf_link_hash_traverse(&htab->root, adjust_global_symbol, info);
 43.2762 -+
 43.2763 -+  for (abfd = info->input_bfds; abfd; abfd = abfd->link_next)
 43.2764 -+    {
 43.2765 -+      Elf_Internal_Sym *isymbuf;
 43.2766 -+      struct fragment **local_sym_frag, *frag;
 43.2767 -+      unsigned int i, sym_count;
 43.2768 -+
 43.2769 -+      sym_count = elf_tdata(abfd)->symtab_hdr.sh_info;
 43.2770 -+      if (sym_count == 0)
 43.2771 -+	continue;
 43.2772 -+
 43.2773 -+      isymbuf = retrieve_local_syms(abfd, info->keep_memory);
 43.2774 -+      if (!isymbuf)
 43.2775 -+	return FALSE;
 43.2776 -+
 43.2777 -+      local_sym_frag = elf_tdata(abfd)->local_sym_frag;
 43.2778 -+
 43.2779 -+      for (i = 0; i < sym_count; i++)
 43.2780 -+	{
 43.2781 -+	  frag = local_sym_frag[i];
 43.2782 -+	  if (frag)
 43.2783 -+	    {
 43.2784 -+	      RDBG("adjust_local_symbol: %s[%u] 0x%08lx -> 0x%08lx\n",
 43.2785 -+		   abfd->filename, i, isymbuf[i].st_value,
 43.2786 -+		   isymbuf[i].st_value + frag->offset_adjust);
 43.2787 -+	      isymbuf[i].st_value += frag->offset_adjust;
 43.2788 -+	    }
 43.2789 -+	}
 43.2790 -+
 43.2791 -+      release_local_syms(abfd, isymbuf);
 43.2792 -+    }
 43.2793 -+
 43.2794 -+  htab->symbols_adjusted = TRUE;
 43.2795 -+  return TRUE;
 43.2796 -+}
 43.2797 -+
 43.2798 -+static bfd_boolean
 43.2799 -+adjust_relocs(bfd *abfd, asection *sec, struct bfd_link_info *info)
 43.2800 -+{
 43.2801 -+  struct avr32_relax_data *rd;
 43.2802 -+  Elf_Internal_Rela *relocs;
 43.2803 -+  Elf_Internal_Shdr *symtab_hdr;
 43.2804 -+  unsigned int i;
 43.2805 -+  bfd_boolean ret = FALSE;
 43.2806 -+
 43.2807 -+  rd = avr32_relax_data(sec);
 43.2808 -+  if (!rd->reloc_data)
 43.2809 -+    return TRUE;
 43.2810 -+
 43.2811 -+  RDBG("adjust_relocs: %s<%s> (count: %u)\n", abfd->filename, sec->name,
 43.2812 -+       sec->reloc_count);
 43.2813 -+
 43.2814 -+  relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
 43.2815 -+  if (!relocs)
 43.2816 -+    return FALSE;
 43.2817 -+
 43.2818 -+  symtab_hdr = &elf_tdata(abfd)->symtab_hdr;
 43.2819 -+
 43.2820 -+  for (i = 0; i < sec->reloc_count; i++)
 43.2821 -+    {
 43.2822 -+      Elf_Internal_Rela *rela = &relocs[i];
 43.2823 -+      struct avr32_reloc_data *r_data = &rd->reloc_data[i];
 43.2824 -+      struct fragment *sym_frag;
 43.2825 -+      unsigned long r_symndx;
 43.2826 -+
 43.2827 -+      if (r_data->add_frag)
 43.2828 -+	{
 43.2829 -+	  r_symndx = ELF_R_SYM(rela->r_info);
 43.2830 -+
 43.2831 -+	  if (r_symndx < symtab_hdr->sh_info)
 43.2832 -+	    sym_frag = elf_tdata(abfd)->local_sym_frag[r_symndx];
 43.2833 -+	  else
 43.2834 -+	    {
 43.2835 -+	      struct elf_link_hash_entry *h;
 43.2836 -+
 43.2837 -+	      h = elf_sym_hashes(abfd)[r_symndx - symtab_hdr->sh_info];
 43.2838 -+
 43.2839 -+	      while (h->root.type == bfd_link_hash_indirect
 43.2840 -+		     || h->root.type == bfd_link_hash_warning)
 43.2841 -+		h = (struct elf_link_hash_entry *)h->root.u.i.link;
 43.2842 -+
 43.2843 -+	      BFD_ASSERT(h->root.type == bfd_link_hash_defined
 43.2844 -+			 || h->root.type == bfd_link_hash_defweak);
 43.2845 -+
 43.2846 -+	      sym_frag = ((struct elf_avr32_link_hash_entry *)h)->sym_frag;
 43.2847 -+	    }
 43.2848 -+
 43.2849 -+	  RDBG("    addend: 0x%08lx -> 0x%08lx\n",
 43.2850 -+	       rela->r_addend,
 43.2851 -+	       rela->r_addend + r_data->add_frag->offset_adjust
 43.2852 -+	       - (sym_frag ? sym_frag->offset_adjust : 0));
 43.2853 -+
 43.2854 -+	  /* If this is against a section symbol, we won't find any
 43.2855 -+	     sym_frag, so we'll just adjust the addend.  */
 43.2856 -+	  rela->r_addend += r_data->add_frag->offset_adjust;
 43.2857 -+	  if (sym_frag)
 43.2858 -+	    rela->r_addend -= sym_frag->offset_adjust;
 43.2859 -+
 43.2860 -+	  if (r_data->sub_frag)
 43.2861 -+	    {
 43.2862 -+	      bfd_byte *contents;
 43.2863 -+	      bfd_signed_vma diff;
 43.2864 -+
 43.2865 -+	      contents = retrieve_contents(abfd, sec, info->keep_memory);
 43.2866 -+	      if (!contents)
 43.2867 -+		goto out;
 43.2868 -+
 43.2869 -+	      /* I realize now that sub_frag is misnamed.  It's
 43.2870 -+		 actually add_frag which is subtracted in this
 43.2871 -+		 case...  */
 43.2872 -+	      diff = bfd_get_signed_32(abfd, contents + rela->r_offset);
 43.2873 -+	      diff += (r_data->sub_frag->offset_adjust
 43.2874 -+		       - r_data->add_frag->offset_adjust);
 43.2875 -+	      bfd_put_32(abfd, diff, contents + rela->r_offset);
 43.2876 -+
 43.2877 -+	      RDBG("   0x%lx: DIFF32 updated: 0x%lx\n", rela->r_offset, diff);
 43.2878 -+
 43.2879 -+	      release_contents(sec, contents);
 43.2880 -+	    }
 43.2881 -+	}
 43.2882 -+      else
 43.2883 -+	BFD_ASSERT(!r_data->sub_frag);
 43.2884 -+    }
 43.2885 -+
 43.2886 -+  ret = TRUE;
 43.2887 -+
 43.2888 -+ out:
 43.2889 -+  release_internal_relocs(sec, relocs);
 43.2890 -+  return ret;
 43.2891 -+}
 43.2892 -+
 43.2893 -+static bfd_boolean
 43.2894 -+avr32_move_data(bfd *abfd, asection *sec, struct bfd_link_info *info)
 43.2895 -+{
 43.2896 -+  struct elf_avr32_link_hash_table *htab;
 43.2897 -+  struct avr32_relax_data *rd;
 43.2898 -+  struct fragment *frag, *fragend;
 43.2899 -+  Elf_Internal_Rela *relocs = NULL;
 43.2900 -+  bfd_byte *contents = NULL;
 43.2901 -+  unsigned int i;
 43.2902 -+  bfd_boolean ret = FALSE;
 43.2903 -+
 43.2904 -+  htab = avr32_elf_hash_table(info);
 43.2905 -+  rd = avr32_relax_data(sec);
 43.2906 -+
 43.2907 -+  if (!htab->symbols_adjusted)
 43.2908 -+    if (!adjust_syms(info))
 43.2909 -+      return FALSE;
 43.2910 -+
 43.2911 -+  if (rd->is_relaxable)
 43.2912 -+    {
 43.2913 -+      /* Resize the section first, so that we can be sure that enough
 43.2914 -+	 memory is allocated in case the section has grown.  */
 43.2915 -+      if (sec->size > sec->rawsize
 43.2916 -+	  && elf_section_data(sec)->this_hdr.contents)
 43.2917 -+	{
 43.2918 -+	  /* We must not use cached data if the section has grown.  */
 43.2919 -+	  free(elf_section_data(sec)->this_hdr.contents);
 43.2920 -+	  elf_section_data(sec)->this_hdr.contents = NULL;
 43.2921 -+	}
 43.2922 -+
 43.2923 -+      relocs = retrieve_internal_relocs(abfd, sec, info->keep_memory);
 43.2924 -+      if (!relocs)
 43.2925 -+	goto out;
 43.2926 -+      contents = retrieve_contents(abfd, sec, info->keep_memory);
 43.2927 -+      if (!contents)
 43.2928 -+	goto out;
 43.2929 -+
 43.2930 -+      fragend = rd->frag + rd->frag_count;
 43.2931 -+
 43.2932 -+      RDBG("move_data: %s<%s>: relocs=%p, contents=%p\n",
 43.2933 -+	   abfd->filename, sec->name, relocs, contents);
 43.2934 -+
 43.2935 -+      /* First, move the data into place. We must take care to move
 43.2936 -+	 frags in the right order so that we don't accidentally
 43.2937 -+	 overwrite parts of the next frag.  */
 43.2938 -+      for (frag = rd->frag; frag < fragend; frag++)
 43.2939 -+	{
 43.2940 -+	  RDBG("    0x%08lx%c0x%x: size 0x%lx%c0x%x\n",
 43.2941 -+	       frag->offset, frag->offset_adjust >= 0 ? '+' : '-',
 43.2942 -+	       abs(frag->offset_adjust),
 43.2943 -+	       frag->size, frag->size_adjust >= 0 ? '+' : '-',
 43.2944 -+	       abs(frag->size_adjust));
 43.2945 -+	  if (frag->offset_adjust > 0)
 43.2946 -+	    {
 43.2947 -+	      struct fragment *prev = frag - 1;
 43.2948 -+	      struct fragment *last;
 43.2949 -+
 43.2950 -+	      for (last = frag; last < fragend && last->offset_adjust > 0;
 43.2951 -+		   last++) ;
 43.2952 -+
 43.2953 -+	      if (last == fragend)
 43.2954 -+		last--;
 43.2955 -+
 43.2956 -+	      for (frag = last; frag != prev; frag--)
 43.2957 -+		{
 43.2958 -+		  if (frag->offset_adjust
 43.2959 -+		      && frag->size + frag->size_adjust > 0)
 43.2960 -+		    {
 43.2961 -+		      RDBG("memmove 0x%lx -> 0x%lx (size %lu)\n",
 43.2962 -+			   frag->offset, frag->offset + frag->offset_adjust,
 43.2963 -+			   frag->size + frag->size_adjust);
 43.2964 -+		      memmove(contents + frag->offset + frag->offset_adjust,
 43.2965 -+			      contents + frag->offset,
 43.2966 -+			      frag->size + frag->size_adjust);
 43.2967 -+		    }
 43.2968 -+		}
 43.2969 -+	      frag = last;
 43.2970 -+	    }
 43.2971 -+	  else if (frag->offset_adjust && frag->size + frag->size_adjust > 0)
 43.2972 -+	    {
 43.2973 -+	      RDBG("memmove 0x%lx -> 0x%lx (size %lu)\n",
 43.2974 -+		   frag->offset, frag->offset + frag->offset_adjust,
 43.2975 -+		   frag->size + frag->size_adjust);
 43.2976 -+	      memmove(contents + frag->offset + frag->offset_adjust,
 43.2977 -+		      contents + frag->offset,
 43.2978 -+		      frag->size + frag->size_adjust);
 43.2979 -+	    }
 43.2980 -+	}
 43.2981 -+
 43.2982 -+      i = 0;
 43.2983 -+
 43.2984 -+      for (frag = rd->frag; frag < fragend; frag++)
 43.2985 -+	{
 43.2986 -+	  const struct relax_state *state, *istate;
 43.2987 -+	  struct avr32_reloc_data *r_data = NULL;
 43.2988 -+
 43.2989 -+	  istate = &relax_state[frag->initial_state];
 43.2990 -+	  state = &relax_state[frag->state];
 43.2991 -+
 43.2992 -+	  if (rd->reloc_data)
 43.2993 -+	    r_data = &rd->reloc_data[frag->rela - relocs];
 43.2994 -+
 43.2995 -+	  BFD_ASSERT((long)(frag->size + frag->size_adjust) >= 0);
 43.2996 -+	  BFD_ASSERT(state->reftype != REF_CPOOL
 43.2997 -+		     || r_data->add_frag->refcount > 0);
 43.2998 -+
 43.2999 -+	  if (istate->reftype == REF_CPOOL && state->reftype != REF_CPOOL)
 43.3000 -+	    {
 43.3001 -+	      struct fragment *ifrag;
 43.3002 -+
 43.3003 -+	      /* An indirect reference through the cpool has been
 43.3004 -+		 converted to a direct reference.  We must update the
 43.3005 -+		 reloc to point to the symbol itself instead of the
 43.3006 -+		 constant pool entry.  The reloc type will be updated
 43.3007 -+		 later.  */
 43.3008 -+	      ifrag = r_data->add_frag;
 43.3009 -+	      frag->rela->r_info = ifrag->rela->r_info;
 43.3010 -+	      frag->rela->r_addend = ifrag->rela->r_addend;
 43.3011 -+
 43.3012 -+	      /* Copy the reloc data so the addend will be adjusted
 43.3013 -+		 correctly later.  */
 43.3014 -+	      *r_data = rd->reloc_data[ifrag->rela - relocs];
 43.3015 -+	    }
 43.3016 -+
 43.3017 -+	  /* Move all relocs covered by this frag.  */
 43.3018 -+	  if (frag->rela)
 43.3019 -+	    BFD_ASSERT(&relocs[i] <= frag->rela);
 43.3020 -+	  else
 43.3021 -+	    BFD_ASSERT((frag + 1) == fragend && frag->state == RS_NONE);
 43.3022 -+
 43.3023 -+	  if (frag == rd->frag)
 43.3024 -+	    BFD_ASSERT(i == 0);
 43.3025 -+	  else
 43.3026 -+	    BFD_ASSERT(&relocs[i] > frag[-1].rela);
 43.3027 -+
 43.3028 -+	  /* If non-null, frag->rela is the last relocation in the
 43.3029 -+	     fragment.  frag->rela can only be null in the last
 43.3030 -+	     fragment, so in that case, we'll just do the rest.  */
 43.3031 -+	  for (; (i < sec->reloc_count
 43.3032 -+		  && (!frag->rela || &relocs[i] <= frag->rela)); i++)
 43.3033 -+	    {
 43.3034 -+	      RDBG("[%4u] r_offset 0x%08lx -> 0x%08lx\n", i, relocs[i].r_offset,
 43.3035 -+		   relocs[i].r_offset + frag->offset_adjust);
 43.3036 -+	      relocs[i].r_offset += frag->offset_adjust;
 43.3037 -+	    }
 43.3038 -+
 43.3039 -+	  if (frag->refcount == 0)
 43.3040 -+	    {
 43.3041 -+	      /* If this frag is to be discarded, make sure we won't
 43.3042 -+		 relocate it later on.  */
 43.3043 -+	      BFD_ASSERT(frag->state == RS_CPENT);
 43.3044 -+	      frag->rela->r_info = ELF_R_INFO(ELF_R_SYM(frag->rela->r_info),
 43.3045 -+					    R_AVR32_NONE);
 43.3046 -+	    }
 43.3047 -+	  else if (frag->state == RS_ALIGN)
 43.3048 -+	    {
 43.3049 -+	      bfd_vma addr, addr_end;
 43.3050 -+
 43.3051 -+	      addr = frag->rela->r_offset;
 43.3052 -+	      addr_end = (frag->offset + frag->offset_adjust
 43.3053 -+			  + frag->size + frag->size_adjust);
 43.3054 -+
 43.3055 -+	      /* If the section is executable, insert NOPs.
 43.3056 -+		 Otherwise, insert zeroes.  */
 43.3057 -+	      if (sec->flags & SEC_CODE)
 43.3058 -+		{
 43.3059 -+		  if (addr & 1)
 43.3060 -+		    {
 43.3061 -+		      bfd_put_8(abfd, 0, contents + addr);
 43.3062 -+		      addr++;
 43.3063 -+		    }
 43.3064 -+
 43.3065 -+		  BFD_ASSERT(!((addr_end - addr) & 1));
 43.3066 -+
 43.3067 -+		  while (addr < addr_end)
 43.3068 -+		    {
 43.3069 -+		      bfd_put_16(abfd, NOP_OPCODE, contents + addr);
 43.3070 -+		      addr += 2;
 43.3071 -+		    }
 43.3072 -+		}
 43.3073 -+	      else
 43.3074 -+		memset(contents + addr, 0, addr_end - addr);
 43.3075 -+	    }
 43.3076 -+	  else if (state->opcode_mask)
 43.3077 -+	    {
 43.3078 -+	      bfd_vma insn;
 43.3079 -+
 43.3080 -+	      /* Update the opcode and the relocation type unless it's a
 43.3081 -+		 "special" relax state (i.e. RS_NONE, RS_ALIGN or
 43.3082 -+		 RS_CPENT.), in which case the opcode mask is zero.  */
 43.3083 -+	      insn = bfd_get_32(abfd, contents + frag->rela->r_offset);
 43.3084 -+	      insn &= ~state->opcode_mask;
 43.3085 -+	      insn |= state->opcode;
 43.3086 -+	      RDBG("    0x%lx: inserting insn %08lx\n",
 43.3087 -+		   frag->rela->r_offset, insn);
 43.3088 -+	      bfd_put_32(abfd, insn, contents + frag->rela->r_offset);
 43.3089 -+
 43.3090 -+	      frag->rela->r_info = ELF_R_INFO(ELF_R_SYM(frag->rela->r_info),
 43.3091 -+					      state->r_type);
 43.3092 -+	    }
 43.3093 -+
 43.3094 -+	  if ((frag + 1) == fragend)
 43.3095 -+	    BFD_ASSERT((frag->offset + frag->size + frag->offset_adjust
 43.3096 -+			+ frag->size_adjust) == sec->size);
 43.3097 -+	  else
 43.3098 -+	    BFD_ASSERT((frag->offset + frag->size + frag->offset_adjust
 43.3099 -+			+ frag->size_adjust)
 43.3100 -+		       == (frag[1].offset + frag[1].offset_adjust));
 43.3101 -+	}
 43.3102 -+    }
 43.3103 -+
 43.3104 -+  /* Adjust reloc addends and DIFF32 differences */
 43.3105 -+  if (!adjust_relocs(abfd, sec, info))
 43.3106 -+    return FALSE;
 43.3107 -+
 43.3108 -+  ret = TRUE;
 43.3109 -+
 43.3110 -+ out:
 43.3111 -+  release_contents(sec, contents);
 43.3112 -+  release_internal_relocs(sec, relocs);
 43.3113 -+  return ret;
 43.3114 -+}
 43.3115 -+
 43.3116 -+static bfd_boolean
 43.3117 -+avr32_elf_relax_section(bfd *abfd, asection *sec,
 43.3118 -+			struct bfd_link_info *info, bfd_boolean *again)
 43.3119 -+{
 43.3120 -+  struct elf_avr32_link_hash_table *htab;
 43.3121 -+  struct avr32_relax_data *rd;
 43.3122 -+
 43.3123 -+  *again = FALSE;
 43.3124 -+  if (info->relocatable)
 43.3125 -+    return TRUE;
 43.3126 -+
 43.3127 -+  htab = avr32_elf_hash_table(info);
 43.3128 -+  if ((!(sec->flags & SEC_RELOC) || sec->reloc_count == 0)
 43.3129 -+      && sec != htab->sgot)
 43.3130 -+    return TRUE;
 43.3131 -+
 43.3132 -+  if (!htab->relocations_analyzed)
 43.3133 -+    {
 43.3134 -+      if (!analyze_relocations(info))
 43.3135 -+	return FALSE;
 43.3136 -+      htab->relocations_analyzed = TRUE;
 43.3137 -+    }
 43.3138 -+
 43.3139 -+  rd = avr32_relax_data(sec);
 43.3140 -+
 43.3141 -+  if (rd->iteration != htab->relax_iteration)
 43.3142 -+    {
 43.3143 -+      if (!htab->repeat_pass)
 43.3144 -+	htab->relax_pass++;
 43.3145 -+      htab->relax_iteration++;
 43.3146 -+      htab->repeat_pass = FALSE;
 43.3147 -+    }
 43.3148 -+
 43.3149 -+  rd->iteration++;
 43.3150 -+
 43.3151 -+  switch (htab->relax_pass)
 43.3152 -+    {
 43.3153 -+    case RELAX_PASS_SIZE_FRAGS:
 43.3154 -+      if (!avr32_size_frags(abfd, sec, info))
 43.3155 -+	return FALSE;
 43.3156 -+      *again = TRUE;
 43.3157 -+      break;
 43.3158 -+    case RELAX_PASS_MOVE_DATA:
 43.3159 -+      if (!avr32_move_data(abfd, sec, info))
 43.3160 -+	return FALSE;
 43.3161 -+      break;
 43.3162 -+  }
 43.3163 -+
 43.3164 -+  return TRUE;
 43.3165 -+}
 43.3166 -+
 43.3167 -+
 43.3168 -+/* Relocation */
 43.3169 -+
 43.3170 -+static bfd_reloc_status_type
 43.3171 -+avr32_check_reloc_value(asection *sec, Elf_Internal_Rela *rela,
 43.3172 -+			bfd_signed_vma relocation, reloc_howto_type *howto);
 43.3173 -+static bfd_reloc_status_type
 43.3174 -+avr32_final_link_relocate(reloc_howto_type *howto, bfd *input_bfd,
 43.3175 -+			  asection *input_section, bfd_byte *contents,
 43.3176 -+			  Elf_Internal_Rela *rel, bfd_vma value);
 43.3177 -+static bfd_boolean
 43.3178 -+avr32_elf_relocate_section(bfd *output_bfd, struct bfd_link_info *info,
 43.3179 -+			   bfd *input_bfd, asection *input_section,
 43.3180 -+			   bfd_byte *contents, Elf_Internal_Rela *relocs,
 43.3181 -+			   Elf_Internal_Sym *local_syms,
 43.3182 -+			   asection **local_sections);
 43.3183 -+
 43.3184 -+
 43.3185 -+#define symbol_address(symbol) \
 43.3186 -+  symbol->value + symbol->section->output_section->vma \
 43.3187 -+  + symbol->section->output_offset
 43.3188 -+
 43.3189 -+#define avr32_elf_insert_field(size, field, abfd, reloc_entry, data)	\
 43.3190 -+  do									\
 43.3191 -+    {									\
 43.3192 -+      unsigned long x;							\
 43.3193 -+      x = bfd_get_##size (abfd, data + reloc_entry->address);		\
 43.3194 -+      x &= ~reloc_entry->howto->dst_mask;				\
 43.3195 -+      x |= field & reloc_entry->howto->dst_mask;			\
 43.3196 -+      bfd_put_##size (abfd, (bfd_vma) x, data + reloc_entry->address);	\
 43.3197 -+    }									\
 43.3198 -+  while(0)
 43.3199 -+
 43.3200 -+static bfd_reloc_status_type
 43.3201 -+avr32_check_reloc_value(asection *sec ATTRIBUTE_UNUSED,
 43.3202 -+			Elf_Internal_Rela *rela ATTRIBUTE_UNUSED,
 43.3203 -+			bfd_signed_vma relocation,
 43.3204 -+			reloc_howto_type *howto)
 43.3205 -+{
 43.3206 -+  bfd_vma reloc_u;
 43.3207 -+
 43.3208 -+  /* We take "complain_overflow_dont" to mean "don't complain on
 43.3209 -+     alignment either". This way, we don't have to special-case
 43.3210 -+     R_AVR32_HI16 */
 43.3211 -+  if (howto->complain_on_overflow == complain_overflow_dont)
 43.3212 -+    return bfd_reloc_ok;
 43.3213 -+
 43.3214 -+  /* Check if the value is correctly aligned */
 43.3215 -+  if (relocation & ((1 << howto->rightshift) - 1))
 43.3216 -+    {
 43.3217 -+      RDBG("misaligned: %s<%s+%lx>: %s: 0x%lx (align %u)\n",
 43.3218 -+	   sec->owner->filename, sec->name, rela->r_offset,
 43.3219 -+	   howto->name, relocation, howto->rightshift);
 43.3220 -+      return bfd_reloc_overflow;
 43.3221 -+    }
 43.3222 -+
 43.3223 -+  /* Now, get rid of the unnecessary bits */
 43.3224 -+  relocation >>= howto->rightshift;
 43.3225 -+  reloc_u = (bfd_vma)relocation;
 43.3226 -+
 43.3227 -+  switch (howto->complain_on_overflow)
 43.3228 -+    {
 43.3229 -+    case complain_overflow_unsigned:
 43.3230 -+    case complain_overflow_bitfield:
 43.3231 -+      if (reloc_u > (unsigned long)((1 << howto->bitsize) - 1))
 43.3232 -+	{
 43.3233 -+	  RDBG("unsigned overflow: %s<%s+%lx>: %s: 0x%lx (size %u)\n",
 43.3234 -+	       sec->owner->filename, sec->name, rela->r_offset,
 43.3235 -+	       howto->name, reloc_u, howto->bitsize);
 43.3236 -+	  RDBG("reloc vma: 0x%lx\n",
 43.3237 -+	       sec->output_section->vma + sec->output_offset + rela->r_offset);
 43.3238 -+
 43.3239 -+	  return bfd_reloc_overflow;
 43.3240 -+	}
 43.3241 -+      break;
 43.3242 -+    case complain_overflow_signed:
 43.3243 -+      if (relocation > (1 << (howto->bitsize - 1)) - 1)
 43.3244 -+	{
 43.3245 -+	  RDBG("signed overflow: %s<%s+%lx>: %s: 0x%lx (size %u)\n",
 43.3246 -+	       sec->owner->filename, sec->name, rela->r_offset,
 43.3247 -+	       howto->name, reloc_u, howto->bitsize);
 43.3248 -+	  RDBG("reloc vma: 0x%lx\n",
 43.3249 -+	       sec->output_section->vma + sec->output_offset + rela->r_offset);
 43.3250 -+
 43.3251 -+	  return bfd_reloc_overflow;
 43.3252 -+	}
 43.3253 -+      if (relocation < -(1 << (howto->bitsize - 1)))
 43.3254 -+	{
 43.3255 -+	  RDBG("signed overflow: %s<%s+%lx>: %s: -0x%lx (size %u)\n",
 43.3256 -+	       sec->owner->filename, sec->name, rela->r_offset,
 43.3257 -+	       howto->name, -relocation, howto->bitsize);
 43.3258 -+	  RDBG("reloc vma: 0x%lx\n",
 43.3259 -+	       sec->output_section->vma + sec->output_offset + rela->r_offset);
 43.3260 -+
 43.3261 -+	  return bfd_reloc_overflow;
 43.3262 -+	}
 43.3263 -+      break;
 43.3264 -+    default:
 43.3265 -+      abort();
 43.3266 -+    }
 43.3267 -+
 43.3268 -+  return bfd_reloc_ok;
 43.3269 -+}
 43.3270 -+
 43.3271 -+
 43.3272 -+static bfd_reloc_status_type
 43.3273 -+avr32_final_link_relocate(reloc_howto_type *howto,
 43.3274 -+			  bfd *input_bfd,
 43.3275 -+			  asection *input_section,
 43.3276 -+			  bfd_byte *contents,
 43.3277 -+			  Elf_Internal_Rela *rel,
 43.3278 -+			  bfd_vma value)
 43.3279 -+{
 43.3280 -+  bfd_vma field;
 43.3281 -+  bfd_vma relocation;
 43.3282 -+  bfd_reloc_status_type status;
 43.3283 -+  bfd_byte *p = contents + rel->r_offset;
 43.3284 -+  unsigned long x;
 43.3285 -+
 43.3286 -+  pr_debug("  (6b) final link relocate\n");
 43.3287 -+
 43.3288 -+  /* Sanity check the address */
 43.3289 -+  if (rel->r_offset > input_section->size)
 43.3290 -+    {
 43.3291 -+      (*_bfd_error_handler)
 43.3292 -+	("%B: %A+0x%lx: offset out of range (section size: 0x%lx)",
 43.3293 -+	 input_bfd, input_section, rel->r_offset, input_section->size);
 43.3294 -+      return bfd_reloc_outofrange;
 43.3295 -+    }
 43.3296 -+
 43.3297 -+  relocation = value + rel->r_addend;
 43.3298 -+
 43.3299 -+  if (howto->pc_relative)
 43.3300 -+    {
 43.3301 -+      bfd_vma addr;
 43.3302 -+
 43.3303 -+      addr = input_section->output_section->vma
 43.3304 -+	+ input_section->output_offset + rel->r_offset;
 43.3305 -+      addr &= ~0UL << howto->rightshift;
 43.3306 -+      relocation -= addr;
 43.3307 -+    }
 43.3308 -+
 43.3309 -+  switch (ELF32_R_TYPE(rel->r_info))
 43.3310 -+    {
 43.3311 -+    case R_AVR32_16N_PCREL:
 43.3312 -+      /* sub reg, pc, . - (sym + addend) */
 43.3313 -+      relocation = -relocation;
 43.3314 -+      break;
 43.3315 -+    }
 43.3316 -+
 43.3317 -+  status = avr32_check_reloc_value(input_section, rel, relocation, howto);
 43.3318 -+
 43.3319 -+  relocation >>= howto->rightshift;
 43.3320 -+  if (howto->bitsize == 21)
 43.3321 -+    field = (relocation & 0xffff)
 43.3322 -+      | ((relocation & 0x10000) << 4)
 43.3323 -+      | ((relocation & 0x1e0000) << 8);
 43.3324 -+  else if (howto->bitsize == 12)
 43.3325 -+    field = (relocation & 0xff) | ((relocation & 0xf00) << 4);
 43.3326 -+  else if (howto->bitsize == 10)
 43.3327 -+    field = ((relocation & 0xff) << 4)
 43.3328 -+      | ((relocation & 0x300) >> 8);
 43.3329 -+  else
 43.3330 -+    field = relocation << howto->bitpos;
 43.3331 -+
 43.3332 -+  switch (howto->size)
 43.3333 -+    {
 43.3334 -+    case 0:
 43.3335 -+      x = bfd_get_8 (input_bfd, p);
 43.3336 -+      x &= ~howto->dst_mask;
 43.3337 -+      x |= field & howto->dst_mask;
 43.3338 -+      bfd_put_8 (input_bfd, (bfd_vma) x, p);
 43.3339 -+      break;
 43.3340 -+    case 1:
 43.3341 -+      x = bfd_get_16 (input_bfd, p);
 43.3342 -+      x &= ~howto->dst_mask;
 43.3343 -+      x |= field & howto->dst_mask;
 43.3344 -+      bfd_put_16 (input_bfd, (bfd_vma) x, p);
 43.3345 -+      break;
 43.3346 -+    case 2:
 43.3347 -+      x = bfd_get_32 (input_bfd, p);
 43.3348 -+      x &= ~howto->dst_mask;
 43.3349 -+      x |= field & howto->dst_mask;
 43.3350 -+      bfd_put_32 (input_bfd, (bfd_vma) x, p);
 43.3351 -+      break;
 43.3352 -+    default:
 43.3353 -+      abort();
 43.3354 -+    }
 43.3355 -+
 43.3356 -+  return status;
 43.3357 -+}
 43.3358 -+
 43.3359 -+/* (6) Apply relocations to the normal (non-dynamic) sections */
 43.3360 -+
 43.3361 -+static bfd_boolean
 43.3362 -+avr32_elf_relocate_section(bfd *output_bfd, struct bfd_link_info *info,
 43.3363 -+			   bfd *input_bfd, asection *input_section,
 43.3364 -+			   bfd_byte *contents, Elf_Internal_Rela *relocs,
 43.3365 -+			   Elf_Internal_Sym *local_syms,
 43.3366 -+			   asection **local_sections)
 43.3367 -+{
 43.3368 -+  struct elf_avr32_link_hash_table *htab;
 43.3369 -+  Elf_Internal_Shdr *symtab_hdr;
 43.3370 -+  Elf_Internal_Rela *rel, *relend;
 43.3371 -+  struct elf_link_hash_entry **sym_hashes;
 43.3372 -+  struct got_entry **local_got_ents;
 43.3373 -+  asection *sgot;
 43.3374 -+  asection *srelgot;
 43.3375 -+
 43.3376 -+  pr_debug("(6) relocate section %s:<%s> (size 0x%lx)\n",
 43.3377 -+	   input_bfd->filename, input_section->name, input_section->size);
 43.3378 -+
 43.3379 -+  /* If we're doing a partial link, we don't have to do anything since
 43.3380 -+     we're using RELA relocations */
 43.3381 -+  if (info->relocatable)
 43.3382 -+    return TRUE;
 43.3383 -+
 43.3384 -+  htab = avr32_elf_hash_table(info);
 43.3385 -+  symtab_hdr = &elf_tdata(input_bfd)->symtab_hdr;
 43.3386 -+  sym_hashes = elf_sym_hashes(input_bfd);
 43.3387 -+  local_got_ents = elf_local_got_ents(input_bfd);
 43.3388 -+  sgot = htab->sgot;
 43.3389 -+  srelgot = htab->srelgot;
 43.3390 -+
 43.3391 -+  relend = relocs + input_section->reloc_count;
 43.3392 -+  for (rel = relocs; rel < relend; rel++)
 43.3393 -+    {
 43.3394 -+      unsigned long r_type, r_symndx;
 43.3395 -+      reloc_howto_type *howto;
 43.3396 -+      Elf_Internal_Sym *sym = NULL;
 43.3397 -+      struct elf_link_hash_entry *h = NULL;
 43.3398 -+      asection *sec = NULL;
 43.3399 -+      bfd_vma value;
 43.3400 -+      bfd_vma offset;
 43.3401 -+      bfd_reloc_status_type status;
 43.3402 -+
 43.3403 -+      r_type = ELF32_R_TYPE(rel->r_info);
 43.3404 -+      r_symndx = ELF32_R_SYM(rel->r_info);
 43.3405 -+
 43.3406 -+      if (r_type == R_AVR32_NONE
 43.3407 -+	  || r_type == R_AVR32_ALIGN
 43.3408 -+	  || r_type == R_AVR32_DIFF32
 43.3409 -+	  || r_type == R_AVR32_DIFF16
 43.3410 -+	  || r_type == R_AVR32_DIFF8)
 43.3411 -+	continue;
 43.3412 -+
 43.3413 -+      /* Sanity check */
 43.3414 -+      if (r_type > R_AVR32_max)
 43.3415 -+	{
 43.3416 -+	  bfd_set_error(bfd_error_bad_value);
 43.3417 -+	  return FALSE;
 43.3418 -+	}
 43.3419 -+
 43.3420 -+      howto = &elf_avr32_howto_table[r_type];
 43.3421 -+
 43.3422 -+      if (r_symndx < symtab_hdr->sh_info)
 43.3423 -+	{
 43.3424 -+	  sym = local_syms + r_symndx;
 43.3425 -+	  sec = local_sections[r_symndx];
 43.3426 -+
 43.3427 -+	  pr_debug("  (6a) processing %s against local symbol %lu\n",
 43.3428 -+		   howto->name, r_symndx);
 43.3429 -+
 43.3430 -+	  /* The following function changes rel->r_addend behind our back. */
 43.3431 -+	  value = _bfd_elf_rela_local_sym(output_bfd, sym, &sec, rel);
 43.3432 -+	  pr_debug("    => value: %lx, addend: %lx\n", value, rel->r_addend);
 43.3433 -+	}
 43.3434 -+      else
 43.3435 -+	{
 43.3436 -+	  if (sym_hashes == NULL)
 43.3437 -+	    return FALSE;
 43.3438 -+
 43.3439 -+	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
 43.3440 -+	  while (h->root.type == bfd_link_hash_indirect
 43.3441 -+		 || h->root.type == bfd_link_hash_warning)
 43.3442 -+	    h = (struct elf_link_hash_entry *)h->root.u.i.link;
 43.3443 -+
 43.3444 -+	  pr_debug("  (6a) processing %s against symbol %s\n",
 43.3445 -+		   howto->name, h->root.root.string);
 43.3446 -+
 43.3447 -+	  if (h->root.type == bfd_link_hash_defined
 43.3448 -+	      || h->root.type == bfd_link_hash_defweak)
 43.3449 -+	    {
 43.3450 -+	      bfd_boolean dyn;
 43.3451 -+
 43.3452 -+	      dyn = htab->root.dynamic_sections_created;
 43.3453 -+	      sec = h->root.u.def.section;
 43.3454 -+
 43.3455 -+	      if (sec->output_section)
 43.3456 -+		value = (h->root.u.def.value
 43.3457 -+			 + sec->output_section->vma
 43.3458 -+			 + sec->output_offset);
 43.3459 -+	      else
 43.3460 -+		value = h->root.u.def.value;
 43.3461 -+	    }
 43.3462 -+	  else if (h->root.type == bfd_link_hash_undefweak)
 43.3463 -+	    value = 0;
 43.3464 -+	  else if (info->unresolved_syms_in_objects == RM_IGNORE
 43.3465 -+		   && ELF_ST_VISIBILITY(h->other) == STV_DEFAULT)
 43.3466 -+	    value = 0;
 43.3467 -+	  else
 43.3468 -+	    {
 43.3469 -+	      bfd_boolean err;
 43.3470 -+	      err = (info->unresolved_syms_in_objects == RM_GENERATE_ERROR
 43.3471 -+		     || ELF_ST_VISIBILITY(h->other) != STV_DEFAULT);
 43.3472 -+	      if (!info->callbacks->undefined_symbol
 43.3473 -+		  (info, h->root.root.string, input_bfd,
 43.3474 -+		   input_section, rel->r_offset, err))
 43.3475 -+		return FALSE;
 43.3476 -+	      value = 0;
 43.3477 -+	    }
 43.3478 -+
 43.3479 -+	  pr_debug("    => value: %lx, addend: %lx\n", value, rel->r_addend);
 43.3480 -+	}
 43.3481 -+
 43.3482 -+      switch (r_type)
 43.3483 -+	{
 43.3484 -+	case R_AVR32_GOT32:
 43.3485 -+	case R_AVR32_GOT16:
 43.3486 -+	case R_AVR32_GOT8:
 43.3487 -+	case R_AVR32_GOT21S:
 43.3488 -+	case R_AVR32_GOT18SW:
 43.3489 -+	case R_AVR32_GOT16S:
 43.3490 -+	case R_AVR32_GOT7UW:
 43.3491 -+	case R_AVR32_LDA_GOT:
 43.3492 -+	case R_AVR32_GOTCALL:
 43.3493 -+	  BFD_ASSERT(sgot != NULL);
 43.3494 -+
 43.3495 -+	  if (h != NULL)
 43.3496 -+	    {
 43.3497 -+	      BFD_ASSERT(h->got.glist->refcount > 0);
 43.3498 -+	      offset = h->got.glist->offset;
 43.3499 -+
 43.3500 -+	      BFD_ASSERT(offset < sgot->size);
 43.3501 -+	      if (!elf_hash_table(info)->dynamic_sections_created
 43.3502 -+		  || (h->def_regular
 43.3503 -+		      && (!info->shared
 43.3504 -+			  || info->symbolic
 43.3505 -+			  || h->dynindx == -1)))
 43.3506 -+		{
 43.3507 -+		  /* This is actually a static link, or it is a
 43.3508 -+		     -Bsymbolic link and the symbol is defined
 43.3509 -+		     locally, or the symbol was forced to be local.  */
 43.3510 -+		  bfd_put_32(output_bfd, value, sgot->contents + offset);
 43.3511 -+		}
 43.3512 -+	    }
 43.3513 -+	  else
 43.3514 -+	    {
 43.3515 -+	      BFD_ASSERT(local_got_ents &&
 43.3516 -+			 local_got_ents[r_symndx]->refcount > 0);
 43.3517 -+	      offset = local_got_ents[r_symndx]->offset;
 43.3518 -+
 43.3519 -+	      /* Local GOT entries don't have relocs.  If this is a
 43.3520 -+		 shared library, the dynamic linker will add the load
 43.3521 -+		 address to the initial value at startup.  */
 43.3522 -+	      BFD_ASSERT(offset < sgot->size);
 43.3523 -+	      pr_debug("Initializing GOT entry at offset %lu: 0x%lx\n",
 43.3524 -+		       offset, value);
 43.3525 -+	      bfd_put_32 (output_bfd, value, sgot->contents + offset);
 43.3526 -+	    }
 43.3527 -+
 43.3528 -+	  value = sgot->output_offset + offset;
 43.3529 -+	  pr_debug("GOT reference: New value %lx\n", value);
 43.3530 -+	  break;
 43.3531 -+
 43.3532 -+	case R_AVR32_GOTPC:
 43.3533 -+	  /* This relocation type is for constant pool entries used in
 43.3534 -+	     the calculation "Rd = PC - (PC - GOT)", where the
 43.3535 -+	     constant pool supplies the constant (PC - GOT)
 43.3536 -+	     offset. The symbol value + addend indicates where the
 43.3537 -+	     value of PC is taken. */
 43.3538 -+	  value -= sgot->output_section->vma;
 43.3539 -+	  break;
 43.3540 -+
 43.3541 -+	case R_AVR32_32_PCREL:
 43.3542 -+	  /* We must adjust r_offset to account for discarded data in
 43.3543 -+	     the .eh_frame section.  This is probably not the right
 43.3544 -+	     way to do this, since AFAICS all other architectures do
 43.3545 -+	     it some other way.  I just can't figure out how...  */
 43.3546 -+	  {
 43.3547 -+	    bfd_vma r_offset;
 43.3548 -+
 43.3549 -+	    r_offset = _bfd_elf_section_offset(output_bfd, info,
 43.3550 -+					       input_section,
 43.3551 -+					       rel->r_offset);
 43.3552 -+	    if (r_offset == (bfd_vma)-1
 43.3553 -+		|| r_offset == (bfd_vma)-2)
 43.3554 -+	      continue;
 43.3555 -+	    rel->r_offset = r_offset;
 43.3556 -+	  }
 43.3557 -+	  break;
 43.3558 -+
 43.3559 -+	case R_AVR32_32:
 43.3560 -+	  /* We need to emit a run-time relocation in the following cases:
 43.3561 -+	       - we're creating a shared library
 43.3562 -+	       - the symbol is not defined in any regular objects
 43.3563 -+
 43.3564 -+	     Of course, sections that aren't going to be part of the
 43.3565 -+	     run-time image will not get any relocs, and undefined
 43.3566 -+	     symbols won't have any either (only weak undefined
 43.3567 -+	     symbols should get this far).  */
 43.3568 -+	  if ((info->shared
 43.3569 -+	       || (elf_hash_table(info)->dynamic_sections_created
 43.3570 -+		   && h != NULL
 43.3571 -+		   && h->def_dynamic
 43.3572 -+		   && !h->def_regular))
 43.3573 -+	      && r_symndx != 0
 43.3574 -+	      && (input_section->flags & SEC_ALLOC))
 43.3575 -+	    {
 43.3576 -+	      Elf_Internal_Rela outrel;
 43.3577 -+	      bfd_byte *loc;
 43.3578 -+	      bfd_boolean skip, relocate;
 43.3579 -+	      struct elf_avr32_link_hash_entry *avrh;
 43.3580 -+
 43.3581 -+	      pr_debug("Going to generate dynamic reloc...\n");
 43.3582 -+
 43.3583 -+	      skip = FALSE;
 43.3584 -+	      relocate = FALSE;
 43.3585 -+
 43.3586 -+	      outrel.r_offset = _bfd_elf_section_offset(output_bfd, info,
 43.3587 -+							input_section,
 43.3588 -+							rel->r_offset);
 43.3589 -+	      if (outrel.r_offset == (bfd_vma)-1)
 43.3590 -+		skip = TRUE;
 43.3591 -+	      else if (outrel.r_offset == (bfd_vma)-2)
 43.3592 -+		skip = TRUE, relocate = TRUE;
 43.3593 -+
 43.3594 -+	      outrel.r_offset += (input_section->output_section->vma
 43.3595 -+				  + input_section->output_offset);
 43.3596 -+
 43.3597 -+	      pr_debug("    ... offset %lx, dynindx %ld\n",
 43.3598 -+		       outrel.r_offset, h ? h->dynindx : -1);
 43.3599 -+
 43.3600 -+	      if (skip)
 43.3601 -+		memset(&outrel, 0, sizeof(outrel));
 43.3602 -+	      else
 43.3603 -+		{
 43.3604 -+		  avrh = (struct elf_avr32_link_hash_entry *)h;
 43.3605 -+		  /* h->dynindx may be -1 if this symbol was marked to
 43.3606 -+		     become local.  */
 43.3607 -+		  if (h == NULL
 43.3608 -+		      || ((info->symbolic || h->dynindx == -1)
 43.3609 -+			  && h->def_regular))
 43.3610 -+		    {
 43.3611 -+		      relocate = TRUE;
 43.3612 -+		      outrel.r_info = ELF32_R_INFO(0, R_AVR32_RELATIVE);
 43.3613 -+		      outrel.r_addend = value + rel->r_addend;
 43.3614 -+		      pr_debug("    ... R_AVR32_RELATIVE\n");
 43.3615 -+		    }
 43.3616 -+		  else
 43.3617 -+		    {
 43.3618 -+		      BFD_ASSERT(h->dynindx != -1);
 43.3619 -+		      relocate = TRUE;
 43.3620 -+		      outrel.r_info = ELF32_R_INFO(h->dynindx, R_AVR32_GLOB_DAT);
 43.3621 -+		      outrel.r_addend = rel->r_addend;
 43.3622 -+		      pr_debug("    ... R_AVR32_GLOB_DAT\n");
 43.3623 -+		    }
 43.3624 -+		}
 43.3625 -+
 43.3626 -+	      pr_debug("srelgot reloc_count: %d, size %lu\n",
 43.3627 -+		       srelgot->reloc_count, srelgot->size);
 43.3628 -+
 43.3629 -+	      loc = srelgot->contents;
 43.3630 -+	      loc += srelgot->reloc_count++ * sizeof(Elf32_External_Rela);
 43.3631 -+	      bfd_elf32_swap_reloca_out(output_bfd, &outrel, loc);
 43.3632 -+
 43.3633 -+	      BFD_ASSERT(srelgot->reloc_count * sizeof(Elf32_External_Rela)
 43.3634 -+			 <= srelgot->size);
 43.3635 -+
 43.3636 -+	      if (!relocate)
 43.3637 -+		continue;
 43.3638 -+	    }
 43.3639 -+	  break;
 43.3640 -+	}
 43.3641 -+
 43.3642 -+      status = avr32_final_link_relocate(howto, input_bfd, input_section,
 43.3643 -+					 contents, rel, value);
 43.3644 -+
 43.3645 -+      switch (status)
 43.3646 -+	{
 43.3647 -+	case bfd_reloc_ok:
 43.3648 -+	  break;
 43.3649 -+
 43.3650 -+	case bfd_reloc_overflow:
 43.3651 -+	  {
 43.3652 -+	    const char *name;
 43.3653 -+
 43.3654 -+	    if (h != NULL)
 43.3655 -+	      name = h->root.root.string;
 43.3656 -+	    else
 43.3657 -+	      {
 43.3658 -+		name = bfd_elf_string_from_elf_section(input_bfd,
 43.3659 -+						       symtab_hdr->sh_link,
 43.3660 -+						       sym->st_name);
 43.3661 -+		if (name == NULL)
 43.3662 -+		  return FALSE;
 43.3663 -+		if (*name == '\0')
 43.3664 -+		  name = bfd_section_name(input_bfd, sec);
 43.3665 -+	      }
 43.3666 -+	    if (!((*info->callbacks->reloc_overflow)
 43.3667 -+		  (info, (h ? &h->root : NULL), name, howto->name,
 43.3668 -+		   rel->r_addend, input_bfd, input_section, rel->r_offset)))
 43.3669 -+	      return FALSE;
 43.3670 -+	  }
 43.3671 -+	  break;
 43.3672 -+
 43.3673 -+	case bfd_reloc_outofrange:
 43.3674 -+	default:
 43.3675 -+	  abort();
 43.3676 -+	}
 43.3677 -+    }
 43.3678 -+
 43.3679 -+  return TRUE;
 43.3680 -+}
 43.3681 -+
 43.3682 -+
 43.3683 -+/* Additional processing of dynamic sections after relocation */
 43.3684 -+
 43.3685 -+static bfd_boolean
 43.3686 -+avr32_elf_finish_dynamic_symbol(bfd *output_bfd, struct bfd_link_info *info,
 43.3687 -+				struct elf_link_hash_entry *h,
 43.3688 -+				Elf_Internal_Sym *sym);
 43.3689 -+static bfd_boolean
 43.3690 -+avr32_elf_finish_dynamic_sections(bfd *output_bfd, struct bfd_link_info *info);
 43.3691 -+
 43.3692 -+
 43.3693 -+/* (7) Initialize the contents of a dynamic symbol and/or emit
 43.3694 -+   relocations for it */
 43.3695 -+
 43.3696 -+static bfd_boolean
 43.3697 -+avr32_elf_finish_dynamic_symbol(bfd *output_bfd, struct bfd_link_info *info,
 43.3698 -+				struct elf_link_hash_entry *h,
 43.3699 -+				Elf_Internal_Sym *sym)
 43.3700 -+{
 43.3701 -+  struct elf_avr32_link_hash_table *htab;
 43.3702 -+  struct got_entry *got;
 43.3703 -+
 43.3704 -+  pr_debug("(7) finish dynamic symbol: %s\n", h->root.root.string);
 43.3705 -+
 43.3706 -+  htab = avr32_elf_hash_table(info);
 43.3707 -+  got = h->got.glist;
 43.3708 -+
 43.3709 -+  if (got && got->refcount > 0)
 43.3710 -+    {
 43.3711 -+      asection *sgot;
 43.3712 -+      asection *srelgot;
 43.3713 -+      Elf_Internal_Rela rel;
 43.3714 -+      bfd_byte *loc;
 43.3715 -+
 43.3716 -+      /* This symbol has an entry in the GOT. Set it up. */
 43.3717 -+      sgot = htab->sgot;
 43.3718 -+      srelgot = htab->srelgot;
 43.3719 -+      BFD_ASSERT(sgot && srelgot);
 43.3720 -+
 43.3721 -+      rel.r_offset = (sgot->output_section->vma
 43.3722 -+		      + sgot->output_offset
 43.3723 -+		      + got->offset);
 43.3724 -+
 43.3725 -+      /* If this is a static link, or it is a -Bsymbolic link and the
 43.3726 -+	 symbol is defined locally or was forced to be local because
 43.3727 -+	 of a version file, we just want to emit a RELATIVE reloc. The
 43.3728 -+	 entry in the global offset table will already have been
 43.3729 -+	 initialized in the relocate_section function. */
 43.3730 -+      if ((info->shared
 43.3731 -+	   && !info->symbolic
 43.3732 -+	   && h->dynindx != -1)
 43.3733 -+	  || (htab->root.dynamic_sections_created
 43.3734 -+	      && h->def_dynamic
 43.3735 -+	      && !h->def_regular))
 43.3736 -+	{
 43.3737 -+	  bfd_put_32(output_bfd, 0, sgot->contents + got->offset);
 43.3738 -+	  rel.r_info = ELF32_R_INFO(h->dynindx, R_AVR32_GLOB_DAT);
 43.3739 -+	  rel.r_addend = 0;
 43.3740 -+
 43.3741 -+	  pr_debug("GOT reloc R_AVR32_GLOB_DAT, dynindx: %ld\n", h->dynindx);
 43.3742 -+	  pr_debug("    srelgot reloc_count: %d, size: %lu\n",
 43.3743 -+		   srelgot->reloc_count, srelgot->size);
 43.3744 -+
 43.3745 -+	  loc = (srelgot->contents
 43.3746 -+		 + srelgot->reloc_count++ * sizeof(Elf32_External_Rela));
 43.3747 -+	  bfd_elf32_swap_reloca_out(output_bfd, &rel, loc);
 43.3748 -+
 43.3749 -+	  BFD_ASSERT(srelgot->reloc_count * sizeof(Elf32_External_Rela)
 43.3750 -+		     <= srelgot->size);
 43.3751 -+	}
 43.3752 -+    }
 43.3753 -+
 43.3754 -+  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute */
 43.3755 -+  if (strcmp(h->root.root.string, "_DYNAMIC") == 0
 43.3756 -+      || strcmp(h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
 43.3757 -+    sym->st_shndx = SHN_ABS;
 43.3758 -+
 43.3759 -+  return TRUE;
 43.3760 -+}
 43.3761 -+
 43.3762 -+/* (8) Do any remaining initialization of the dynamic sections */
 43.3763 -+
 43.3764 -+static bfd_boolean
 43.3765 -+avr32_elf_finish_dynamic_sections(bfd *output_bfd, struct bfd_link_info *info)
 43.3766 -+{
 43.3767 -+  struct elf_avr32_link_hash_table *htab;
 43.3768 -+  asection *sgot, *sdyn;
 43.3769 -+
 43.3770 -+  pr_debug("(8) finish dynamic sections\n");
 43.3771 -+
 43.3772 -+  htab = avr32_elf_hash_table(info);
 43.3773 -+  sgot = htab->sgot;
 43.3774 -+  sdyn = bfd_get_section_by_name(htab->root.dynobj, ".dynamic");
 43.3775 -+
 43.3776 -+  if (htab->root.dynamic_sections_created)
 43.3777 -+    {
 43.3778 -+      Elf32_External_Dyn *dyncon, *dynconend;
 43.3779 -+
 43.3780 -+      BFD_ASSERT(sdyn && sgot && sgot->size >= AVR32_GOT_HEADER_SIZE);
 43.3781 -+
 43.3782 -+      dyncon = (Elf32_External_Dyn *)sdyn->contents;
 43.3783 -+      dynconend = (Elf32_External_Dyn *)(sdyn->contents + sdyn->size);
 43.3784 -+      for (; dyncon < dynconend; dyncon++)
 43.3785 -+	{
 43.3786 -+	  Elf_Internal_Dyn dyn;
 43.3787 -+	  asection *s;
 43.3788 -+
 43.3789 -+	  bfd_elf32_swap_dyn_in(htab->root.dynobj, dyncon, &dyn);
 43.3790 -+
 43.3791 -+	  switch (dyn.d_tag)
 43.3792 -+	    {
 43.3793 -+	    default:
 43.3794 -+	      break;
 43.3795 -+
 43.3796 -+	    case DT_PLTGOT:
 43.3797 -+	      s = sgot->output_section;
 43.3798 -+	      BFD_ASSERT(s != NULL);
 43.3799 -+	      dyn.d_un.d_ptr = s->vma;
 43.3800 -+	      bfd_elf32_swap_dyn_out(output_bfd, &dyn, dyncon);
 43.3801 -+	      break;
 43.3802 -+
 43.3803 -+	    case DT_AVR32_GOTSZ:
 43.3804 -+	      s = sgot->output_section;
 43.3805 -+	      BFD_ASSERT(s != NULL);
 43.3806 -+	      dyn.d_un.d_val = s->size;
 43.3807 -+	      bfd_elf32_swap_dyn_out(output_bfd, &dyn, dyncon);
 43.3808 -+	      break;
 43.3809 -+	    }
 43.3810 -+	}
 43.3811 -+
 43.3812 -+      /* Fill in the first two entries in the global offset table */
 43.3813 -+      bfd_put_32(output_bfd,
 43.3814 -+		 sdyn->output_section->vma + sdyn->output_offset,
 43.3815 -+		 sgot->contents);
 43.3816 -+
 43.3817 -+      /* The runtime linker will fill this one in with the address of
 43.3818 -+	 the run-time link map */
 43.3819 -+      bfd_put_32(output_bfd, 0, sgot->contents + 4);
 43.3820 -+    }
 43.3821 -+
 43.3822 -+  if (sgot)
 43.3823 -+    elf_section_data(sgot->output_section)->this_hdr.sh_entsize = 4;
 43.3824 -+
 43.3825 -+  return TRUE;
 43.3826 -+}
 43.3827 -+
 43.3828 -+
 43.3829 -+/* AVR32-specific private ELF data */
 43.3830 -+
 43.3831 -+static bfd_boolean
 43.3832 -+avr32_elf_set_private_flags(bfd *abfd, flagword flags);
 43.3833 -+static bfd_boolean
 43.3834 -+avr32_elf_copy_private_bfd_data(bfd *ibfd, bfd *obfd);
 43.3835 -+static bfd_boolean
 43.3836 -+avr32_elf_merge_private_bfd_data(bfd *ibfd, bfd *obfd);
 43.3837 -+static bfd_boolean
 43.3838 -+avr32_elf_print_private_bfd_data(bfd *abfd, void *ptr);
 43.3839 -+
 43.3840 -+static bfd_boolean
 43.3841 -+avr32_elf_set_private_flags(bfd *abfd, flagword flags)
 43.3842 -+{
 43.3843 -+  elf_elfheader(abfd)->e_flags = flags;
 43.3844 -+  elf_flags_init(abfd) = TRUE;
 43.3845 -+
 43.3846 -+  return TRUE;
 43.3847 -+}
 43.3848 -+
 43.3849 -+/* Copy backend specific data from one object module to another.  */
 43.3850 -+
 43.3851 -+static bfd_boolean
 43.3852 -+avr32_elf_copy_private_bfd_data(bfd *ibfd, bfd *obfd)
 43.3853 -+{
 43.3854 -+  elf_elfheader(obfd)->e_flags = elf_elfheader(ibfd)->e_flags;
 43.3855 -+  return TRUE;
 43.3856 -+}
 43.3857 -+
 43.3858 -+/* Merge backend specific data from an object file to the output
 43.3859 -+   object file when linking.  */
 43.3860 -+
 43.3861 -+static bfd_boolean
 43.3862 -+avr32_elf_merge_private_bfd_data(bfd *ibfd, bfd *obfd)
 43.3863 -+{
 43.3864 -+  flagword out_flags, in_flags;
 43.3865 -+
 43.3866 -+  pr_debug("(0) merge_private_bfd_data: %s -> %s\n",
 43.3867 -+	   ibfd->filename, obfd->filename);
 43.3868 -+
 43.3869 -+  in_flags = elf_elfheader(ibfd)->e_flags;
 43.3870 -+  out_flags = elf_elfheader(obfd)->e_flags;
 43.3871 -+
 43.3872 -+  if (elf_flags_init(obfd))
 43.3873 -+    {
 43.3874 -+      /* If one of the inputs are non-PIC, the output must be
 43.3875 -+	 considered non-PIC.  The same applies to linkrelax.  */
 43.3876 -+      if (!(in_flags & EF_AVR32_PIC))
 43.3877 -+	out_flags &= ~EF_AVR32_PIC;
 43.3878 -+      if (!(in_flags & EF_AVR32_LINKRELAX))
 43.3879 -+	out_flags &= ~EF_AVR32_LINKRELAX;
 43.3880 -+    }
 43.3881 -+  else
 43.3882 -+    {
 43.3883 -+      elf_flags_init(obfd) = TRUE;
 43.3884 -+      out_flags = in_flags;
 43.3885 -+    }
 43.3886 -+
 43.3887 -+  elf_elfheader(obfd)->e_flags = out_flags;
 43.3888 -+
 43.3889 -+  return TRUE;
 43.3890 -+}
 43.3891 -+
 43.3892 -+static bfd_boolean
 43.3893 -+avr32_elf_print_private_bfd_data(bfd *abfd, void *ptr)
 43.3894 -+{
 43.3895 -+  FILE *file = (FILE *)ptr;
 43.3896 -+  unsigned long flags;
 43.3897 -+
 43.3898 -+  BFD_ASSERT(abfd != NULL && ptr != NULL);
 43.3899 -+
 43.3900 -+  _bfd_elf_print_private_bfd_data(abfd, ptr);
 43.3901 -+
 43.3902 -+  flags = elf_elfheader(abfd)->e_flags;
 43.3903 -+
 43.3904 -+  fprintf(file, _("private flags = %lx:"), elf_elfheader(abfd)->e_flags);
 43.3905 -+
 43.3906 -+  if (flags & EF_AVR32_PIC)
 43.3907 -+    fprintf(file, " [PIC]");
 43.3908 -+  if (flags & EF_AVR32_LINKRELAX)
 43.3909 -+    fprintf(file, " [linker relaxable]");
 43.3910 -+
 43.3911 -+  flags &= ~(EF_AVR32_PIC | EF_AVR32_LINKRELAX);
 43.3912 -+
 43.3913 -+  if (flags)
 43.3914 -+    fprintf(file, _("<Unrecognized flag bits set>"));
 43.3915 -+
 43.3916 -+  fputc('\n', file);
 43.3917 -+
 43.3918 -+  return TRUE;
 43.3919 -+}
 43.3920 -+
 43.3921 -+/* Set avr32-specific linker options.  */
 43.3922 -+void bfd_elf32_avr32_set_options(struct bfd_link_info *info,
 43.3923 -+				 int direct_data_refs)
 43.3924 -+{
 43.3925 -+  struct elf_avr32_link_hash_table *htab;
 43.3926 -+
 43.3927 -+  htab = avr32_elf_hash_table (info);
 43.3928 -+  htab->direct_data_refs = !!direct_data_refs;
 43.3929 -+}
 43.3930 -+
 43.3931 -+
 43.3932 -+
 43.3933 -+/* Understanding core dumps */
 43.3934 -+
 43.3935 -+static bfd_boolean
 43.3936 -+avr32_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note);
 43.3937 -+static bfd_boolean
 43.3938 -+avr32_elf_grok_psinfo(bfd *abfd, Elf_Internal_Note *note);
 43.3939 -+
 43.3940 -+static bfd_boolean
 43.3941 -+avr32_elf_grok_prstatus(bfd *abfd, Elf_Internal_Note *note)
 43.3942 -+{
 43.3943 -+  /* Linux/AVR32B elf_prstatus */
 43.3944 -+  if (note->descsz != 148)
 43.3945 -+    return FALSE;
 43.3946 -+
 43.3947 -+  /* pr_cursig */
 43.3948 -+  elf_tdata(abfd)->core_signal = bfd_get_16(abfd, note->descdata + 12);
 43.3949 -+
 43.3950 -+  /* pr_pid */
 43.3951 -+  elf_tdata(abfd)->core_pid = bfd_get_32(abfd, note->descdata + 24);
 43.3952 -+
 43.3953 -+  /* Make a ".reg/999" section for pr_reg. The size is for 16
 43.3954 -+     general-purpose registers, SR and r12_orig (18 * 4 = 72).  */
 43.3955 -+  return _bfd_elfcore_make_pseudosection(abfd, ".reg", 72,
 43.3956 -+					 note->descpos + 72);
 43.3957 -+}
 43.3958 -+
 43.3959 -+static bfd_boolean
 43.3960 -+avr32_elf_grok_psinfo(bfd *abfd, Elf_Internal_Note *note)
 43.3961 -+{
 43.3962 -+  /* Linux/AVR32B elf_prpsinfo */
 43.3963 -+  if (note->descsz != 128)
 43.3964 -+    return FALSE;
 43.3965 -+
 43.3966 -+  elf_tdata(abfd)->core_program
 43.3967 -+    = _bfd_elfcore_strndup(abfd, note->descdata + 32, 16);
 43.3968 -+  elf_tdata(abfd)->core_command
 43.3969 -+    = _bfd_elfcore_strndup(abfd, note->descdata + 48, 80);
 43.3970 -+
 43.3971 -+  /* Note that for some reason, a spurious space is tacked
 43.3972 -+     onto the end of the args in some (at least one anyway)
 43.3973 -+     implementations, so strip it off if it exists.  */
 43.3974 -+
 43.3975 -+  {
 43.3976 -+    char *command = elf_tdata (abfd)->core_command;
 43.3977 -+    int n = strlen (command);
 43.3978 -+
 43.3979 -+    if (0 < n && command[n - 1] == ' ')
 43.3980 -+      command[n - 1] = '\0';
 43.3981 -+  }
 43.3982 -+
 43.3983 -+  return TRUE;
 43.3984 -+}
 43.3985 -+
 43.3986 -+
 43.3987 -+#define ELF_ARCH			bfd_arch_avr32
 43.3988 -+#define ELF_MACHINE_CODE		EM_AVR32
 43.3989 -+#define ELF_MAXPAGESIZE			0x1000
 43.3990 -+
 43.3991 -+#define TARGET_BIG_SYM			bfd_elf32_avr32_vec
 43.3992 -+#define TARGET_BIG_NAME			"elf32-avr32"
 43.3993 -+
 43.3994 -+#define elf_backend_grok_prstatus	avr32_elf_grok_prstatus
 43.3995 -+#define elf_backend_grok_psinfo		avr32_elf_grok_psinfo
 43.3996 -+
 43.3997 -+/* Only RELA relocations are used */
 43.3998 -+#define elf_backend_may_use_rel_p	0
 43.3999 -+#define elf_backend_may_use_rela_p	1
 43.4000 -+#define elf_backend_default_use_rela_p	1
 43.4001 -+#define elf_backend_rela_normal		1
 43.4002 -+#define elf_info_to_howto_rel		NULL
 43.4003 -+#define elf_info_to_howto		avr32_info_to_howto
 43.4004 -+
 43.4005 -+#define bfd_elf32_bfd_copy_private_bfd_data	avr32_elf_copy_private_bfd_data
 43.4006 -+#define bfd_elf32_bfd_merge_private_bfd_data	avr32_elf_merge_private_bfd_data
 43.4007 -+#define bfd_elf32_bfd_set_private_flags		avr32_elf_set_private_flags
 43.4008 -+#define bfd_elf32_bfd_print_private_bfd_data	avr32_elf_print_private_bfd_data
 43.4009 -+#define bfd_elf32_new_section_hook		avr32_elf_new_section_hook
 43.4010 -+
 43.4011 -+#define elf_backend_gc_mark_hook		avr32_elf_gc_mark_hook
 43.4012 -+#define elf_backend_gc_sweep_hook		avr32_elf_gc_sweep_hook
 43.4013 -+#define elf_backend_relocate_section	avr32_elf_relocate_section
 43.4014 -+#define elf_backend_copy_indirect_symbol avr32_elf_copy_indirect_symbol
 43.4015 -+#define elf_backend_create_dynamic_sections avr32_elf_create_dynamic_sections
 43.4016 -+#define bfd_elf32_bfd_link_hash_table_create avr32_elf_link_hash_table_create
 43.4017 -+#define elf_backend_adjust_dynamic_symbol avr32_elf_adjust_dynamic_symbol
 43.4018 -+#define elf_backend_size_dynamic_sections avr32_elf_size_dynamic_sections
 43.4019 -+#define elf_backend_finish_dynamic_symbol avr32_elf_finish_dynamic_symbol
 43.4020 -+#define elf_backend_finish_dynamic_sections avr32_elf_finish_dynamic_sections
 43.4021 -+
 43.4022 -+#define bfd_elf32_bfd_relax_section	avr32_elf_relax_section
 43.4023 -+
 43.4024 -+/* Find out which symbols need an entry in .got. */
 43.4025 -+#define elf_backend_check_relocs	avr32_check_relocs
 43.4026 -+#define elf_backend_can_refcount	1
 43.4027 -+#define elf_backend_can_gc_sections	1
 43.4028 -+#define elf_backend_plt_readonly	1
 43.4029 -+#define elf_backend_plt_not_loaded	1
 43.4030 -+#define elf_backend_want_plt_sym	0
 43.4031 -+#define elf_backend_plt_alignment	2
 43.4032 -+#define elf_backend_want_dynbss		0
 43.4033 -+#define elf_backend_want_got_plt	0
 43.4034 -+#define elf_backend_want_got_sym	1
 43.4035 -+#define elf_backend_got_header_size	AVR32_GOT_HEADER_SIZE
 43.4036 -+
 43.4037 -+#include "elf32-target.h"
 43.4038 ---- /dev/null
 43.4039 -+++ b/bfd/elf32-avr32.h
 43.4040 -@@ -0,0 +1,23 @@
 43.4041 -+/* AVR32-specific support for 32-bit ELF.
 43.4042 -+   Copyright 2007 Atmel Corporation.
 43.4043 -+
 43.4044 -+   Written by Haavard Skinnemoen, Atmel Norway, <hskinnemoen@atmel.com>
 43.4045 -+
 43.4046 -+   This file is part of BFD, the Binary File Descriptor library.
 43.4047 -+
 43.4048 -+   This program is free software; you can redistribute it and/or modify
 43.4049 -+   it under the terms of the GNU General Public License as published by
 43.4050 -+   the Free Software Foundation; either version 2 of the License, or
 43.4051 -+   (at your option) any later version.
 43.4052 -+
 43.4053 -+   This program is distributed in the hope that it will be useful,
 43.4054 -+   but WITHOUT ANY WARRANTY; without even the implied warranty of
 43.4055 -+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 43.4056 -+   GNU General Public License for more details.
 43.4057 -+
 43.4058 -+   You should have received a copy of the GNU General Public License
 43.4059 -+   along with this program; if not, write to the Free Software
 43.4060 -+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
 43.4061 -+
 43.4062 -+void bfd_elf32_avr32_set_options(struct bfd_link_info *info,
 43.4063 -+				 int direct_data_refs);
 43.4064 ---- a/bfd/elf-bfd.h
 43.4065 -+++ b/bfd/elf-bfd.h
 43.4066 -@@ -1400,6 +1400,10 @@ struct elf_obj_tdata
 43.4067 -      find_nearest_line.  */
 43.4068 -   struct mips_elf_find_line *find_line_info;
 43.4069 - 
 43.4070 -+  /* Used by AVR32 ELF relaxation code.  Contains an array of pointers
 43.4071 -+     for each local symbol to the fragment where it is defined.  */
 43.4072 -+  struct fragment **local_sym_frag;
 43.4073 -+
 43.4074 -   /* A place to stash dwarf1 info for this bfd.  */
 43.4075 -   struct dwarf1_debug *dwarf1_find_line_info;
 43.4076 - 
 43.4077 ---- a/bfd/Makefile.am
 43.4078 -+++ b/bfd/Makefile.am
 43.4079 -@@ -63,6 +63,7 @@ ALL_MACHINES = \
 43.4080 - 	cpu-arc.lo \
 43.4081 - 	cpu-arm.lo \
 43.4082 - 	cpu-avr.lo \
 43.4083 -+	cpu-avr32.lo \
 43.4084 - 	cpu-bfin.lo \
 43.4085 - 	cpu-cr16.lo \
 43.4086 - 	cpu-cr16c.lo \
 43.4087 -@@ -243,6 +244,7 @@ BFD32_BACKENDS = \
 43.4088 - 	elf32-arc.lo \
 43.4089 - 	elf32-arm.lo \
 43.4090 - 	elf32-avr.lo \
 43.4091 -+	elf32-avr32.lo \
 43.4092 - 	elf32-bfin.lo \
 43.4093 - 	elf32-cr16.lo \
 43.4094 - 	elf32-cr16c.lo \
 43.4095 -@@ -1328,6 +1330,10 @@ elf32-cr16.lo: elf32-cr16.c $(INCDIR)/fi
 43.4096 -   $(INCDIR)/hashtab.h $(INCDIR)/libiberty.h elf-bfd.h \
 43.4097 -   $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
 43.4098 -   $(INCDIR)/elf/cr16.h $(INCDIR)/elf/reloc-macros.h elf32-target.h
 43.4099 -+elf32-avr32.lo: elf32-avr32.c $(INCDIR)/filenames.h elf-bfd.h \
 43.4100 -+  $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
 43.4101 -+  $(INCDIR)/bfdlink.h $(INCDIR)/elf/avr32.h $(INCDIR)/elf/reloc-macros.h \
 43.4102 -+  elf32-target.h
 43.4103 - elf32-cr16c.lo: elf32-cr16c.c $(INCDIR)/filenames.h \
 43.4104 -   $(INCDIR)/hashtab.h $(INCDIR)/bfdlink.h $(INCDIR)/elf/cr16c.h \
 43.4105 -   $(INCDIR)/elf/reloc-macros.h elf-bfd.h $(INCDIR)/elf/common.h \
 43.4106 ---- a/bfd/reloc.c
 43.4107 -+++ b/bfd/reloc.c
 43.4108 -@@ -3948,6 +3948,131 @@ ENUMDOC
 43.4109 -   instructions
 43.4110 - 
 43.4111 - ENUM
 43.4112 -+  BFD_RELOC_AVR32_DIFF32
 43.4113 -+ENUMX
 43.4114 -+  BFD_RELOC_AVR32_DIFF16
 43.4115 -+ENUMX
 43.4116 -+  BFD_RELOC_AVR32_DIFF8
 43.4117 -+ENUMDOC
 43.4118 -+  Difference between two labels: L2 - L1. The value of L1 is encoded
 43.4119 -+  as sym + addend, while the initial difference after assembly is
 43.4120 -+  inserted into the object file by the assembler.
 43.4121 -+ENUM
 43.4122 -+  BFD_RELOC_AVR32_GOT32
 43.4123 -+ENUMX
 43.4124 -+  BFD_RELOC_AVR32_GOT16
 43.4125 -+ENUMX
 43.4126 -+  BFD_RELOC_AVR32_GOT8
 43.4127 -+ENUMDOC
 43.4128 -+  Reference to a symbol through the Global Offset Table. The linker
 43.4129 -+  will allocate an entry for symbol in the GOT and insert the offset
 43.4130 -+  of this entry as the relocation value.
 43.4131 -+ENUM
 43.4132 -+  BFD_RELOC_AVR32_21S
 43.4133 -+ENUMX
 43.4134 -+  BFD_RELOC_AVR32_16U
 43.4135 -+ENUMX
 43.4136 -+  BFD_RELOC_AVR32_16S
 43.4137 -+ENUMX
 43.4138 -+  BFD_RELOC_AVR32_SUB5
 43.4139 -+ENUMX
 43.4140 -+  BFD_RELOC_AVR32_8S_EXT
 43.4141 -+ENUMX
 43.4142 -+  BFD_RELOC_AVR32_8S
 43.4143 -+ENUMX
 43.4144 -+  BFD_RELOC_AVR32_15S
 43.4145 -+ENUMDOC
 43.4146 -+  Normal (non-pc-relative) code relocations. Alignment and signedness
 43.4147 -+  is indicated by the suffixes. S means signed, U means unsigned. W
 43.4148 -+  means word-aligned, H means halfword-aligned, neither means
 43.4149 -+  byte-aligned (no alignment.) SUB5 is the same relocation as 16S.
 43.4150 -+ENUM
 43.4151 -+  BFD_RELOC_AVR32_22H_PCREL
 43.4152 -+ENUMX
 43.4153 -+  BFD_RELOC_AVR32_18W_PCREL
 43.4154 -+ENUMX
 43.4155 -+  BFD_RELOC_AVR32_16B_PCREL
 43.4156 -+ENUMX
 43.4157 -+  BFD_RELOC_AVR32_16N_PCREL
 43.4158 -+ENUMX
 43.4159 -+  BFD_RELOC_AVR32_14UW_PCREL
 43.4160 -+ENUMX
 43.4161 -+  BFD_RELOC_AVR32_11H_PCREL
 43.4162 -+ENUMX
 43.4163 -+  BFD_RELOC_AVR32_10UW_PCREL
 43.4164 -+ENUMX
 43.4165 -+  BFD_RELOC_AVR32_9H_PCREL
 43.4166 -+ENUMX
 43.4167 -+  BFD_RELOC_AVR32_9UW_PCREL
 43.4168 -+ENUMDOC
 43.4169 -+  PC-relative relocations are signed if neither 'U' nor 'S' is
 43.4170 -+  specified. However, we explicitly tack on a 'B' to indicate no
 43.4171 -+  alignment, to avoid confusion with data relocs. All of these resolve
 43.4172 -+  to sym + addend - offset, except the one with 'N' (negated) suffix.
 43.4173 -+  This particular one resolves to offset - sym - addend.
 43.4174 -+ENUM
 43.4175 -+  BFD_RELOC_AVR32_GOTPC
 43.4176 -+ENUMDOC
 43.4177 -+  Subtract the link-time address of the GOT from (symbol + addend)
 43.4178 -+  and insert the result.
 43.4179 -+ENUM
 43.4180 -+  BFD_RELOC_AVR32_GOTCALL
 43.4181 -+ENUMX
 43.4182 -+  BFD_RELOC_AVR32_LDA_GOT
 43.4183 -+ENUMX
 43.4184 -+  BFD_RELOC_AVR32_GOT21S
 43.4185 -+ENUMX
 43.4186 -+  BFD_RELOC_AVR32_GOT18SW
 43.4187 -+ENUMX
 43.4188 -+  BFD_RELOC_AVR32_GOT16S
 43.4189 -+ENUMDOC
 43.4190 -+  Reference to a symbol through the GOT. The linker will allocate an
 43.4191 -+  entry for symbol in the GOT and insert the offset of this entry as
 43.4192 -+  the relocation value. addend must be zero. As usual, 'S' means
 43.4193 -+  signed, 'W' means word-aligned, etc.
 43.4194 -+ENUM
 43.4195 -+  BFD_RELOC_AVR32_32_CPENT
 43.4196 -+ENUMDOC
 43.4197 -+  32-bit constant pool entry. I don't think 8- and 16-bit entries make
 43.4198 -+  a whole lot of sense.
 43.4199 -+ENUM
 43.4200 -+  BFD_RELOC_AVR32_CPCALL
 43.4201 -+ENUMX
 43.4202 -+  BFD_RELOC_AVR32_16_CP
 43.4203 -+ENUMX
 43.4204 -+  BFD_RELOC_AVR32_9W_CP
 43.4205 -+ENUMDOC
 43.4206 -+  Constant pool references. Some of these relocations are signed,
 43.4207 -+  others are unsigned. It doesn't really matter, since the constant
 43.4208 -+  pool always comes after the code that references it.
 43.4209 -+ENUM
 43.4210 -+  BFD_RELOC_AVR32_ALIGN
 43.4211 -+ENUMDOC
 43.4212 -+  sym must be the absolute symbol. The addend specifies the alignment
 43.4213 -+  order, e.g. if addend is 2, the linker must add padding so that the
 43.4214 -+  next address is aligned to a 4-byte boundary.
 43.4215 -+ENUM
 43.4216 -+  BFD_RELOC_AVR32_14UW
 43.4217 -+ENUMX
 43.4218 -+  BFD_RELOC_AVR32_10UW
 43.4219 -+ENUMX
 43.4220 -+  BFD_RELOC_AVR32_10SW
 43.4221 -+ENUMX
 43.4222 -+  BFD_RELOC_AVR32_STHH_W
 43.4223 -+ENUMX
 43.4224 -+  BFD_RELOC_AVR32_7UW
 43.4225 -+ENUMX
 43.4226 -+  BFD_RELOC_AVR32_6S
 43.4227 -+ENUMX
 43.4228 -+  BFD_RELOC_AVR32_6UW
 43.4229 -+ENUMX
 43.4230 -+  BFD_RELOC_AVR32_4UH
 43.4231 -+ENUMX
 43.4232 -+  BFD_RELOC_AVR32_3U
 43.4233 -+ENUMDOC
 43.4234 -+  Code relocations that will never make it to the output file.
 43.4235 -+
 43.4236 -+ENUM
 43.4237 -   BFD_RELOC_390_12
 43.4238 - ENUMDOC
 43.4239 -    Direct 12 bit.
 43.4240 ---- a/bfd/targets.c
 43.4241 -+++ b/bfd/targets.c
 43.4242 -@@ -564,6 +564,7 @@ extern const bfd_target bfd_efi_app_ia32
 43.4243 - extern const bfd_target bfd_efi_app_x86_64_vec;
 43.4244 - extern const bfd_target bfd_efi_app_ia64_vec;
 43.4245 - extern const bfd_target bfd_elf32_avr_vec;
 43.4246 -+extern const bfd_target bfd_elf32_avr32_vec;
 43.4247 - extern const bfd_target bfd_elf32_bfin_vec;
 43.4248 - extern const bfd_target bfd_elf32_bfinfdpic_vec;
 43.4249 - extern const bfd_target bfd_elf32_big_generic_vec;
 43.4250 -@@ -884,6 +885,7 @@ static const bfd_target * const _bfd_tar
 43.4251 - 	&bfd_efi_app_ia64_vec,
 43.4252 - #endif
 43.4253 - 	&bfd_elf32_avr_vec,
 43.4254 -+	&bfd_elf32_avr32_vec,
 43.4255 - 	&bfd_elf32_bfin_vec,
 43.4256 - 	&bfd_elf32_bfinfdpic_vec,
 43.4257 - 
 43.4258 ---- a/binutils/Makefile.am
 43.4259 -+++ b/binutils/Makefile.am
 43.4260 -@@ -577,7 +577,7 @@ readelf.o: readelf.c sysdep.h $(INCDIR)/
 43.4261 -   $(INCDIR)/ansidecl.h $(INCDIR)/symcat.h bucomm.h dwarf.h \
 43.4262 -   $(INCDIR)/elf/common.h $(INCDIR)/elf/external.h $(INCDIR)/elf/internal.h \
 43.4263 -   $(INCDIR)/elf/h8.h $(INCDIR)/elf/reloc-macros.h $(INCDIR)/elf/alpha.h \
 43.4264 --  $(INCDIR)/elf/arc.h $(INCDIR)/elf/arm.h $(INCDIR)/elf/avr.h \
 43.4265 -+  $(INCDIR)/elf/arc.h $(INCDIR)/elf/arm.h $(INCDIR)/elf/avr.h $(INCDIR)/elf/avr32.h\
 43.4266 -   $(INCDIR)/elf/bfin.h $(INCDIR)/elf/cris.h $(INCDIR)/elf/crx.h \
 43.4267 -   $(INCDIR)/elf/d10v.h $(INCDIR)/elf/d30v.h $(INCDIR)/elf/dlx.h \
 43.4268 -   $(INCDIR)/elf/fr30.h $(INCDIR)/elf/frv.h $(INCDIR)/elf/hppa.h \
 43.4269 ---- a/binutils/readelf.c
 43.4270 -+++ b/binutils/readelf.c
 43.4271 -@@ -21,7 +21,7 @@
 43.4272 -    along with this program; if not, write to the Free Software
 43.4273 -    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
 43.4274 -    02110-1301, USA.  */
 43.4275 --
 43.4276 -+
 43.4277 - /* The difference between readelf and objdump:
 43.4278 - 
 43.4279 -   Both programs are capable of displaying the contents of ELF format files,
 43.4280 -@@ -40,7 +40,7 @@
 43.4281 -   There is also the case that readelf can provide more information about an
 43.4282 -   ELF file than is provided by objdump.  In particular it can display DWARF
 43.4283 -   debugging information which (at the moment) objdump cannot.  */
 43.4284 --
 43.4285 -+
 43.4286 - #include "sysdep.h"
 43.4287 - #include <assert.h>
 43.4288 - #include <sys/stat.h>
 43.4289 -@@ -109,6 +109,7 @@
 43.4290 - #include "elf/arc.h"
 43.4291 - #include "elf/arm.h"
 43.4292 - #include "elf/avr.h"
 43.4293 -+#include "elf/avr32.h"
 43.4294 - #include "elf/bfin.h"
 43.4295 - #include "elf/cr16.h"
 43.4296 - #include "elf/cris.h"
 43.4297 -@@ -303,7 +304,7 @@ static void (*byte_put) (unsigned char *
 43.4298 - #define streq(a,b)	  (strcmp ((a), (b)) == 0)
 43.4299 - #define strneq(a,b,n)	  (strncmp ((a), (b), (n)) == 0)
 43.4300 - #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
 43.4301 --
 43.4302 -+
 43.4303 - static void *
 43.4304 - get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
 43.4305 - 	  const char *reason)
 43.4306 -@@ -614,6 +615,7 @@ guess_is_rela (unsigned long e_machine)
 43.4307 -     case EM_ALPHA:
 43.4308 -     case EM_ALTERA_NIOS2:
 43.4309 -     case EM_AVR:
 43.4310 -+    case EM_AVR32:
 43.4311 -     case EM_AVR_OLD:
 43.4312 -     case EM_BLACKFIN:
 43.4313 -     case EM_CR16:
 43.4314 -@@ -1006,6 +1008,10 @@ dump_relocations (FILE *file,
 43.4315 - 	  rtype = elf_avr_reloc_type (type);
 43.4316 - 	  break;
 43.4317 - 
 43.4318 -+	case EM_AVR32:
 43.4319 -+	  rtype = elf_avr32_reloc_type (type);
 43.4320 -+	  break;
 43.4321 -+
 43.4322 - 	case EM_OLD_SPARCV9:
 43.4323 - 	case EM_SPARC32PLUS:
 43.4324 - 	case EM_SPARCV9:
 43.4325 -@@ -1763,6 +1769,7 @@ get_machine_name (unsigned e_machine)
 43.4326 -     case EM_VAX:		return "Digital VAX";
 43.4327 -     case EM_AVR_OLD:
 43.4328 -     case EM_AVR:		return "Atmel AVR 8-bit microcontroller";
 43.4329 -+    case EM_AVR32:		return "Atmel AVR32";
 43.4330 -     case EM_CRIS:		return "Axis Communications 32-bit embedded processor";
 43.4331 -     case EM_JAVELIN:		return "Infineon Technologies 32-bit embedded cpu";
 43.4332 -     case EM_FIREPATH:		return "Element 14 64-bit DSP processor";
 43.4333 ---- a/gas/as.c
 43.4334 -+++ b/gas/as.c
 43.4335 -@@ -441,10 +441,10 @@ parse_args (int * pargc, char *** pargv)
 43.4336 -        the end of the preceeding line so that it is simpler to
 43.4337 -        selectively add and remove lines from this list.  */
 43.4338 -     {"alternate", no_argument, NULL, OPTION_ALTERNATE}
 43.4339 --    /* The entry for "a" is here to prevent getopt_long_only() from
 43.4340 --       considering that -a is an abbreviation for --alternate.  This is
 43.4341 --       necessary because -a=<FILE> is a valid switch but getopt would
 43.4342 --       normally reject it since --alternate does not take an argument.  */
 43.4343 -+    /* The next two entries are here to prevent getopt_long_only() from
 43.4344 -+       considering that -a or -al is an abbreviation for --alternate.
 43.4345 -+       This is necessary because -a=<FILE> is a valid switch but getopt
 43.4346 -+       would normally reject it since --alternate does not take an argument.  */
 43.4347 -     ,{"a", optional_argument, NULL, 'a'}
 43.4348 -     /* Handle -al=<FILE>.  */
 43.4349 -     ,{"al", optional_argument, NULL, OPTION_AL}
 43.4350 -@@ -803,8 +803,15 @@ This program has absolutely no warranty.
 43.4351 - 	case 'a':
 43.4352 - 	  if (optarg)
 43.4353 - 	    {
 43.4354 --	      if (optarg != old_argv[optind] && optarg[-1] == '=')
 43.4355 --		--optarg;
 43.4356 -+	      /* If optarg is part of the -a switch and not a separate argument
 43.4357 -+		 in its own right, then scan backwards to the just after the -a.
 43.4358 -+		 This means skipping over both '=' and 'l' which might have been
 43.4359 -+		 taken to be part of the -a switch itself.  */
 43.4360 -+	      if (optarg != old_argv[optind])
 43.4361 -+		{
 43.4362 -+		  while (optarg[-1] == '=' || optarg[-1] == 'l')
 43.4363 -+		    --optarg;