summaryrefslogtreecommitdiff
path: root/devel/avr-binutils/files/patch-coff-avr
diff options
context:
space:
mode:
authorJoerg Wunsch <joerg@FreeBSD.org>2010-03-04 13:38:30 +0000
committerJoerg Wunsch <joerg@FreeBSD.org>2010-03-04 13:38:30 +0000
commit0c3e719d750fa615e71fea1a8f6c69ce67ae39c7 (patch)
tree9d825dab9a6cbdef8ff3b7f4edb0677583f98ceb /devel/avr-binutils/files/patch-coff-avr
parentUpdate to Mercurial 1.4.3. (diff)
Upgrade to GNU binutils 2.20, including patches from WinAVR 20100110.
Feature safe: yes
Notes
Notes: svn path=/head/; revision=250557
Diffstat (limited to 'devel/avr-binutils/files/patch-coff-avr')
-rw-r--r--devel/avr-binutils/files/patch-coff-avr3589
1 files changed, 1753 insertions, 1836 deletions
diff --git a/devel/avr-binutils/files/patch-coff-avr b/devel/avr-binutils/files/patch-coff-avr
index eae0c2ea69e8..c8c97f20b35d 100644
--- a/devel/avr-binutils/files/patch-coff-avr
+++ b/devel/avr-binutils/files/patch-coff-avr
@@ -1,6 +1,1476 @@
---- ./binutils/bucomm.c.orig 2008-01-09 11:40:32.000000000 +0100
-+++ ./binutils/bucomm.c 2009-01-06 17:45:34.000000000 +0100
-@@ -549,6 +549,32 @@
+diff -Nruw bfd/Makefile.am bfd/Makefile.am
+--- bfd/Makefile.am 2009-10-16 17:17:44.000000000 +0530
++++ bfd/Makefile.am 2010-02-11 10:59:11.320193800 +0530
+@@ -228,6 +228,8 @@
+ coff-apollo.lo \
+ coff-arm.lo \
+ coff-aux.lo \
++ coff-avr.lo \
++ coff-ext-avr.lo \
+ coff-go32.lo \
+ coff-h8300.lo \
+ coff-h8500.lo \
+@@ -411,6 +413,8 @@
+ coff-apollo.c \
+ coff-arm.c \
+ coff-aux.c \
++ coff-avr.c \
++ coff-ext-avr.c \
+ coff-go32.c \
+ coff-h8300.c \
+ coff-h8500.c \
+diff -Nruw bfd/Makefile.in bfd/Makefile.in
+--- bfd/Makefile.in 2009-10-16 17:17:48.000000000 +0530
++++ bfd/Makefile.in 2010-02-11 11:13:52.698455300 +0530
+@@ -524,6 +524,8 @@
+ coff-apollo.lo \
+ coff-arm.lo \
+ coff-aux.lo \
++ coff-avr.lo \
++ coff-ext-avr.lo \
+ coff-go32.lo \
+ coff-h8300.lo \
+ coff-h8500.lo \
+@@ -707,6 +709,8 @@
+ coff-apollo.c \
+ coff-arm.c \
+ coff-aux.c \
++ coff-avr.c \
++ coff-ext-avr.c \
+ coff-go32.c \
+ coff-h8300.c \
+ coff-h8500.c \
+diff -Nruw bfd/coff-avr.c bfd/coff-avr.c
+--- bfd/coff-avr.c 1970-01-01 05:30:00.000000000 +0530
++++ bfd/coff-avr.c 2010-02-10 17:35:58.222099600 +0530
+@@ -0,0 +1,613 @@
++/* BFD back-end for Atmel AVR COFF files.
++ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
++ Free Software Foundation, Inc.
++ Created mostly by substituting "avr" for "i860" in coff-i860.c
++
++This file is part of BFD, the Binary File Descriptor library.
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 2 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
++
++#include "bfd.h"
++#include "sysdep.h"
++#include "libbfd.h"
++
++#include "coff/avr.h"
++
++#include "coff/internal.h"
++
++#include "libcoff.h"
++
++static bfd_reloc_status_type coff_avr_reloc
++ PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
++static reloc_howto_type *coff_avr_rtype_to_howto
++ PARAMS ((bfd *, asection *, struct internal_reloc *,
++ struct coff_link_hash_entry *, struct internal_syment *,
++ bfd_vma *));
++static const bfd_target * coff_avr_object_p PARAMS ((bfd *));
++
++#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
++/* The page size is a guess based on ELF. */
++
++#define COFF_PAGE_SIZE 0x1000
++
++/* For some reason when using avr COFF the value stored in the .text
++ section for a reference to a common symbol is the value itself plus
++ any desired offset. Ian Taylor, Cygnus Support. */
++
++/* If we are producing relocateable output, we need to do some
++ adjustments to the object file that are not done by the
++ bfd_perform_relocation function. This function is called by every
++ reloc type to make any required adjustments. */
++
++static bfd_reloc_status_type
++coff_avr_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
++ error_message)
++ bfd *abfd;
++ arelent *reloc_entry;
++ asymbol *symbol;
++ PTR data;
++ asection *input_section ATTRIBUTE_UNUSED;
++ bfd *output_bfd;
++ char **error_message ATTRIBUTE_UNUSED;
++{
++ symvalue diff;
++
++ if (output_bfd == (bfd *) NULL)
++ return bfd_reloc_continue;
++
++ if (bfd_is_com_section (symbol->section))
++ {
++ /* We are relocating a common symbol. The current value in the
++ object file is ORIG + OFFSET, where ORIG is the value of the
++ common symbol as seen by the object file when it was compiled
++ (this may be zero if the symbol was undefined) and OFFSET is
++ the offset into the common symbol (normally zero, but may be
++ non-zero when referring to a field in a common structure).
++ ORIG is the negative of reloc_entry->addend, which is set by
++ the CALC_ADDEND macro below. We want to replace the value in
++ the object file with NEW + OFFSET, where NEW is the value of
++ the common symbol which we are going to put in the final
++ object file. NEW is symbol->value. */
++ diff = symbol->value + reloc_entry->addend;
++ }
++ else
++ {
++ /* For some reason bfd_perform_relocation always effectively
++ ignores the addend for a COFF target when producing
++ relocateable output. This seems to be always wrong for 860
++ COFF, so we handle the addend here instead. */
++ diff = reloc_entry->addend;
++ }
++
++#define DOIT(x) \
++ x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
++
++ if (diff != 0)
++ {
++ reloc_howto_type *howto = reloc_entry->howto;
++ unsigned char *addr = (unsigned char *) data + reloc_entry->address;
++
++ switch (howto->size)
++ {
++ case 0:
++ {
++ char x = bfd_get_8 (abfd, addr);
++ DOIT (x);
++ bfd_put_8 (abfd, x, addr);
++ }
++ break;
++
++ case 1:
++ {
++ short x = bfd_get_16 (abfd, addr);
++ DOIT (x);
++ bfd_put_16 (abfd, (bfd_vma) x, addr);
++ }
++ break;
++
++ case 2:
++ {
++ long x = bfd_get_32 (abfd, addr);
++ DOIT (x);
++ bfd_put_32 (abfd, (bfd_vma) x, addr);
++ }
++ break;
++
++ default:
++ abort ();
++ }
++ }
++
++ /* Now let bfd_perform_relocation finish everything up. */
++ return bfd_reloc_continue;
++}
++
++#ifndef PCRELOFFSET
++#define PCRELOFFSET FALSE
++#endif
++
++static reloc_howto_type howto_table[] =
++{
++ EMPTY_HOWTO (0),
++ EMPTY_HOWTO (1),
++ EMPTY_HOWTO (2),
++ EMPTY_HOWTO (3),
++ EMPTY_HOWTO (4),
++ EMPTY_HOWTO (5),
++ HOWTO (R_DIR32, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "dir32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ TRUE), /* pcrel_offset */
++ /* {7}, */
++ HOWTO (R_IMAGEBASE, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "rva32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ FALSE), /* pcrel_offset */
++ EMPTY_HOWTO (010),
++ EMPTY_HOWTO (011),
++ EMPTY_HOWTO (012),
++ EMPTY_HOWTO (013),
++ EMPTY_HOWTO (014),
++ EMPTY_HOWTO (015),
++ EMPTY_HOWTO (016),
++ HOWTO (R_RELBYTE, /* type */
++ 0, /* rightshift */
++ 0, /* size (0 = byte, 1 = short, 2 = long) */
++ 8, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "8", /* name */
++ TRUE, /* partial_inplace */
++ 0x000000ff, /* src_mask */
++ 0x000000ff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_RELWORD, /* type */
++ 0, /* rightshift */
++ 1, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "16", /* name */
++ TRUE, /* partial_inplace */
++ 0x0000ffff, /* src_mask */
++ 0x0000ffff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_RELLONG, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_PCRBYTE, /* type */
++ 0, /* rightshift */
++ 0, /* size (0 = byte, 1 = short, 2 = long) */
++ 8, /* bitsize */
++ TRUE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_signed, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "DISP8", /* name */
++ TRUE, /* partial_inplace */
++ 0x000000ff, /* src_mask */
++ 0x000000ff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_PCRWORD, /* type */
++ 0, /* rightshift */
++ 1, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ TRUE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_signed, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "DISP16", /* name */
++ TRUE, /* partial_inplace */
++ 0x0000ffff, /* src_mask */
++ 0x0000ffff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_PCRLONG, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ TRUE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_signed, /* complain_on_overflow */
++ coff_avr_reloc, /* special_function */
++ "DISP32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ PCRELOFFSET) /* pcrel_offset */
++};
++
++/* Turn a howto into a reloc nunmber */
++
++#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
++#define BADMAG(x) AVRBADMAG(x)
++#define AVR 1 /* Customize coffcode.h */
++
++#define RTYPE2HOWTO(cache_ptr, dst) \
++ (cache_ptr)->howto = howto_table + (dst)->r_type;
++
++/* For AVR COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
++ library. On some other COFF targets STYP_BSS is normally
++ STYP_NOLOAD. */
++#define BSS_NOLOAD_IS_SHARED_LIBRARY
++
++/* Compute the addend of a reloc. If the reloc is to a common symbol,
++ the object file contains the value of the common symbol. By the
++ time this is called, the linker may be using a different symbol
++ from a different object file with a different value. Therefore, we
++ hack wildly to locate the original symbol from this file so that we
++ can make the correct adjustment. This macro sets coffsym to the
++ symbol from the original file, and uses it to set the addend value
++ correctly. If this is not a common symbol, the usual addend
++ calculation is done, except that an additional tweak is needed for
++ PC relative relocs.
++ FIXME: This macro refers to symbols and asect; these are from the
++ calling function, not the macro arguments. */
++
++#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
++ { \
++ coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
++ if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
++ coffsym = (obj_symbols (abfd) \
++ + (cache_ptr->sym_ptr_ptr - symbols)); \
++ else if (ptr) \
++ coffsym = coff_symbol_from (abfd, ptr); \
++ if (coffsym != (coff_symbol_type *) NULL \
++ && coffsym->native->u.syment.n_scnum == 0) \
++ cache_ptr->addend = - coffsym->native->u.syment.n_value; \
++ else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
++ && ptr->section != (asection *) NULL) \
++ cache_ptr->addend = - (ptr->section->vma + ptr->value); \
++ else \
++ cache_ptr->addend = 0; \
++ if (ptr && howto_table[reloc.r_type].pc_relative) \
++ cache_ptr->addend += asect->vma; \
++ }
++
++/* We use the special COFF backend linker. */
++#define coff_relocate_section _bfd_coff_generic_relocate_section
++
++static reloc_howto_type *
++coff_avr_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
++ bfd *abfd ATTRIBUTE_UNUSED;
++ asection *sec;
++ struct internal_reloc *rel;
++ struct coff_link_hash_entry *h;
++ struct internal_syment *sym;
++ bfd_vma *addendp;
++{
++
++ reloc_howto_type *howto;
++
++ howto = howto_table + rel->r_type;
++
++ if (howto->pc_relative)
++ *addendp += sec->vma;
++
++ if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
++ {
++ /* This is a common symbol. The section contents include the
++ size (sym->n_value) as an addend. The relocate_section
++ function will be adding in the final value of the symbol. We
++ need to subtract out the current size in order to get the
++ correct result. */
++
++ BFD_ASSERT (h != NULL);
++
++ /* I think we *do* want to bypass this. If we don't, I have seen some data
++ parameters get the wrong relcation address. If I link two versions
++ with and without this section bypassed and then do a binary comparison,
++ the addresses which are different can be looked up in the map. The
++ case in which this section has been bypassed has addresses which correspond
++ to values I can find in the map. */
++ *addendp -= sym->n_value;
++ }
++
++ /* If the output symbol is common (in which case this must be a
++ relocateable link), we need to add in the final size of the
++ common symbol. */
++ if (h != NULL && h->root.type == bfd_link_hash_common)
++ *addendp += h->root.u.c.size;
++
++ return howto;
++}
++
++#define coff_rtype_to_howto coff_avr_rtype_to_howto
++
++#ifndef bfd_pe_print_pdata
++#define bfd_pe_print_pdata NULL
++#endif
++
++#include "coffcode.h"
++
++static const bfd_target *
++coff_avr_object_p(a)
++ bfd *a;
++{
++ return coff_object_p (a);
++}
++
++/* Handle all the abominations of AVR COFF:
++
++ Generic COFF always uses the D1 slot to indicate the "most
++ important" derived type, and the D2...Dn slots for decreasing
++ importance. E. g., a function symbol will always have its DT_FCN
++ element in D1, an array its DT_ARY (its first DT_ARY in a
++ multi-dimensional array). In contrast, AVR COFF expects this most
++ important derived type specifier in the upmost Dn slot that is
++ allocated at all (i. e. that is != 0).
++
++ Generic COFF says that "Any symbol that satisfies more than one
++ condition [... for AUX entries] should have a union format in its
++ auxiliary entry." AVR COFF uses sepearate AUX entries for multiple
++ derived types, and in some cases (like the ISFCN one), even puts
++ the most important one into the last allocated AUX entry. We
++ join/split them here at the border as well. Note that when
++ generating AUX entries (where we need to split them), the n_numaux
++ field must already have been set up properly (e. g. in
++ binutils/wrcoff.c) since the entry renumbering and pointerization
++ would not work otherwise. Thus, we only split the information into
++ multiple records if n_numaux > 1. For similar reasons, we keep
++ n_numaux > 1 on input to keep the appropriate AUX entries
++ allocated, so a symbol can be reconstructed if it is being passed
++ through one of the GNU tools.
++
++ Note that this adjustment is called after the symbol itself has
++ been swapped in, but before the AUX entries are swapped in. This
++ is the only hook available that could swap (or merge) AUX entries
++ at all, so we have to operate on the external AUX entries still. */
++
++void
++avr_coff_adjust_sym_in_post (abfd, ext, in)
++ bfd *abfd;
++ PTR ext;
++ PTR in;
++{
++ struct internal_syment *dst = (struct internal_syment *)in;
++ unsigned short dt, bt, ndt;
++ dt = dst->n_type & ~N_BTMASK;
++ bt = BTYPE (dst->n_type);
++
++ /* Some AVR COFF producers seem to violate the COFF specs, and
++ produce symbols for tag names that have the C_FOO filled in
++ properly, but T_NULL as the base type value. Patch up here,
++ since some of our generic COFF tools (in particular
++ binutils/rdcoff.c) rely on the correct data. */
++ if (bt == T_NULL)
++ switch (dst->n_sclass)
++ {
++ case C_STRTAG:
++ bt = T_STRUCT;
++ break;
++
++ case C_UNTAG:
++ bt = T_UNION;
++ break;
++
++ case C_ENTAG:
++ bt = T_ENUM;
++ break;
++ }
++
++ /* Swap the derived type slots. */
++ if (dt != 0)
++ {
++ ndt = 0;
++ while (dt != 0)
++ {
++ ndt = (ndt << N_TSHIFT) | (dt & (N_TMASK >> N_BTSHFT));
++ dt >>= N_TSHIFT;
++ }
++ dst->n_type = (ndt << N_BTSHFT) | bt;
++ }
++ else
++ dst->n_type = bt;
++
++ /* If the derived type is function, and there is more than one AUX
++ entry, swap the first and the last AUX entry, so the most
++ interesting one will become the first.
++
++ If the fundamental type is a tagged type (struct/union/enum), try
++ to find the AUX entry describing the tagged type (the one that
++ has x_sym.x_tagndx filled in), and merge the tag index into the
++ first AUX entry. Depending on the actual input file, there might
++ be further DT_PTR entries which we just ignore, since we could
++ not handle that information anyway. */
++ if (dst->n_numaux > 1 && dst->n_sclass != C_FILE)
++ {
++ AUXENT caux, *auxp1, *auxp2;
++ size_t symesz;
++ unsigned int i;
++
++ symesz = bfd_coff_symesz (abfd);
++ i = dst->n_numaux;
++
++ auxp1 = (AUXENT *)((char *)ext + symesz);
++ auxp2 = (AUXENT *)((char *)ext + i * symesz);
++
++ if (ISFCN (dst->n_type)
++ || (ISPTR(dst->n_type)
++ && (bt == T_STRUCT || bt == T_UNION || bt == T_ENUM)))
++ {
++ caux = *auxp2;
++ *auxp2 = *auxp1;
++ *auxp1 = caux;
++ }
++ else
++ caux = *auxp1;
++
++ if ((ISFCN (dst->n_type) || ISARY (dst->n_type))
++ && (bt == T_STRUCT || bt == T_UNION || bt == T_ENUM))
++ {
++ while (i > 1)
++ {
++ auxp2 = (AUXENT *)((char *)ext + i * symesz);
++
++ if (auxp2->x_sym.x_tagndx[0] != 0 || auxp2->x_sym.x_tagndx[1] != 0
++ || auxp2->x_sym.x_tagndx[2] != 0 || auxp2->x_sym.x_tagndx[3] != 0)
++ {
++ memcpy (caux.x_sym.x_tagndx, auxp2->x_sym.x_tagndx,
++ 4 * sizeof (char));
++ break;
++ }
++ i--;
++ }
++ if (i > 1)
++ *auxp1 = caux;
++ }
++ }
++}
++
++/* When exporting an AVR COFF file, just undo all that has been done
++ above. Again, we are called after the symbol itself has been
++ swapped out, but before the AUX entries are being written.
++ Unfortunately, we are only given a pointer to the symbol itself, so
++ we have to derive the pointer to the respective aux entries from
++ that address, which is a bit clumsy. */
++void
++avr_coff_adjust_sym_out_post (abfd, in, ext)
++ bfd *abfd;
++ PTR in;
++ PTR ext;
++{
++ struct internal_syment *src = (struct internal_syment *)(in);
++ struct external_syment *dst = (struct external_syment *)(ext);
++ unsigned short dt, bt, ndt;
++
++ dt = src->n_type & ~N_BTMASK;
++ bt = BTYPE (src->n_type);
++
++ if (dt != 0)
++ {
++ ndt = 0;
++ while (dt != 0)
++ {
++ ndt = (ndt << N_TSHIFT) | (dt & (N_TMASK >> N_BTSHFT));
++ dt >>= N_TSHIFT;
++ }
++ H_PUT_16 (abfd, (ndt << N_BTSHFT) | bt, dst->e_type);
++ }
++
++ if (src->n_numaux > 1 && src->n_sclass != C_FILE)
++ {
++ combined_entry_type *srce, *dste;
++ char *hackp;
++ unsigned int i;
++
++ /* Recover the original combinend_entry_type *. */
++ hackp = (char *)in;
++ hackp -= offsetof(combined_entry_type, u.syment);
++ srce = (combined_entry_type *)hackp;
++ srce++;
++
++ /* We simply duplicate the first AUX entry as many times as
++ needed. Since COFF itself normally uses just a single AUX
++ entry for all the information, this will work -- each COFF
++ consumer will then just pick the fields it is particularly
++ interested in. This would not work for the AVR COFF specific
++ DT_PTR AUX entries, but we don't support them anyway. */
++ for (i = 1; i < src->n_numaux; i++)
++ {
++ dste = srce + i;
++ *dste = *srce;
++ }
++ }
++}
++
++const bfd_target
++#ifdef TARGET_SYM
++ TARGET_SYM =
++#else
++ avrcoff_vec =
++#endif
++{
++#ifdef TARGET_NAME
++ TARGET_NAME,
++#else
++ "coff-avr", /* name */
++#endif
++ bfd_target_coff_flavour,
++ BFD_ENDIAN_LITTLE, /* data byte order is little */
++ BFD_ENDIAN_LITTLE, /* header byte order is little */
++
++ (HAS_RELOC | EXEC_P | /* object flags */
++ HAS_LINENO | HAS_DEBUG |
++ HAS_SYMS | HAS_LOCALS | WP_TEXT),
++
++ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
++ 0, /* leading char */
++ '/', /* ar_pad_char */
++ 15, /* ar_max_namelen */
++
++ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
++ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
++ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
++ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
++ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
++ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
++
++/* Note that we allow an object file to be treated as a core file as well. */
++ {_bfd_dummy_target, coff_avr_object_p, /* bfd_check_format */
++ bfd_generic_archive_p, coff_avr_object_p},
++ {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
++ bfd_false},
++ {bfd_false, coff_write_object_contents, /* bfd_write_contents */
++ _bfd_write_archive_contents, bfd_false},
++
++ BFD_JUMP_TABLE_GENERIC (coff),
++ BFD_JUMP_TABLE_COPY (coff),
++ BFD_JUMP_TABLE_CORE (_bfd_nocore),
++ BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
++ BFD_JUMP_TABLE_SYMBOLS (coff),
++ BFD_JUMP_TABLE_RELOCS (coff),
++ BFD_JUMP_TABLE_WRITE (coff),
++ BFD_JUMP_TABLE_LINK (coff),
++ BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
++
++ NULL,
++
++ COFF_SWAP_TABLE
++};
+diff -Nruw bfd/coff-ext-avr.c bfd/coff-ext-avr.c
+--- bfd/coff-ext-avr.c 1970-01-01 05:30:00.000000000 +0530
++++ bfd/coff-ext-avr.c 2010-02-10 17:35:58.222099600 +0530
+@@ -0,0 +1,428 @@
++/* BFD back-end for Atmel AVR "extended" COFF files.
++ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
++ Free Software Foundation, Inc.
++ This is mostly the same as avr-coff, except of the presence of the
++ COFF optional header.
++
++This file is part of BFD, the Binary File Descriptor library.
++
++This program is free software; you can redistribute it and/or modify
++it under the terms of the GNU General Public License as published by
++the Free Software Foundation; either version 2 of the License, or
++(at your option) any later version.
++
++This program is distributed in the hope that it will be useful,
++but WITHOUT ANY WARRANTY; without even the implied warranty of
++MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++GNU General Public License for more details.
++
++You should have received a copy of the GNU General Public License
++along with this program; if not, write to the Free Software
++Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
++
++#include "bfd.h"
++#include "sysdep.h"
++#include "libbfd.h"
++
++#define AVR_EXT_COFF 1
++#include "coff/avr.h"
++
++#include "coff/internal.h"
++
++#include "libcoff.h"
++
++static bfd_reloc_status_type coff_ext_avr_reloc
++ PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
++static reloc_howto_type *coff_ext_avr_rtype_to_howto
++ PARAMS ((bfd *, asection *, struct internal_reloc *,
++ struct coff_link_hash_entry *, struct internal_syment *,
++ bfd_vma *));
++static const bfd_target * coff_ext_avr_object_p PARAMS ((bfd *));
++
++#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
++/* The page size is a guess based on ELF. */
++
++#define COFF_PAGE_SIZE 0x1000
++
++/* For some reason when using avr COFF the value stored in the .text
++ section for a reference to a common symbol is the value itself plus
++ any desired offset. Ian Taylor, Cygnus Support. */
++
++/* If we are producing relocateable output, we need to do some
++ adjustments to the object file that are not done by the
++ bfd_perform_relocation function. This function is called by every
++ reloc type to make any required adjustments. */
++
++static bfd_reloc_status_type
++coff_ext_avr_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
++ error_message)
++ bfd *abfd;
++ arelent *reloc_entry;
++ asymbol *symbol;
++ PTR data;
++ asection *input_section ATTRIBUTE_UNUSED;
++ bfd *output_bfd;
++ char **error_message ATTRIBUTE_UNUSED;
++{
++ symvalue diff;
++
++ if (output_bfd == (bfd *) NULL)
++ return bfd_reloc_continue;
++
++ if (bfd_is_com_section (symbol->section))
++ {
++ /* We are relocating a common symbol. The current value in the
++ object file is ORIG + OFFSET, where ORIG is the value of the
++ common symbol as seen by the object file when it was compiled
++ (this may be zero if the symbol was undefined) and OFFSET is
++ the offset into the common symbol (normally zero, but may be
++ non-zero when referring to a field in a common structure).
++ ORIG is the negative of reloc_entry->addend, which is set by
++ the CALC_ADDEND macro below. We want to replace the value in
++ the object file with NEW + OFFSET, where NEW is the value of
++ the common symbol which we are going to put in the final
++ object file. NEW is symbol->value. */
++ diff = symbol->value + reloc_entry->addend;
++ }
++ else
++ {
++ /* For some reason bfd_perform_relocation always effectively
++ ignores the addend for a COFF target when producing
++ relocateable output. This seems to be always wrong for 860
++ COFF, so we handle the addend here instead. */
++ diff = reloc_entry->addend;
++ }
++
++#define DOIT(x) \
++ x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
++
++ if (diff != 0)
++ {
++ reloc_howto_type *howto = reloc_entry->howto;
++ unsigned char *addr = (unsigned char *) data + reloc_entry->address;
++
++ switch (howto->size)
++ {
++ case 0:
++ {
++ char x = bfd_get_8 (abfd, addr);
++ DOIT (x);
++ bfd_put_8 (abfd, x, addr);
++ }
++ break;
++
++ case 1:
++ {
++ short x = bfd_get_16 (abfd, addr);
++ DOIT (x);
++ bfd_put_16 (abfd, (bfd_vma) x, addr);
++ }
++ break;
++
++ case 2:
++ {
++ long x = bfd_get_32 (abfd, addr);
++ DOIT (x);
++ bfd_put_32 (abfd, (bfd_vma) x, addr);
++ }
++ break;
++
++ default:
++ abort ();
++ }
++ }
++
++ /* Now let bfd_perform_relocation finish everything up. */
++ return bfd_reloc_continue;
++}
++
++#ifndef PCRELOFFSET
++#define PCRELOFFSET FALSE
++#endif
++
++static reloc_howto_type howto_table[] =
++{
++ EMPTY_HOWTO (0),
++ EMPTY_HOWTO (1),
++ EMPTY_HOWTO (2),
++ EMPTY_HOWTO (3),
++ EMPTY_HOWTO (4),
++ EMPTY_HOWTO (5),
++ HOWTO (R_DIR32, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "dir32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ TRUE), /* pcrel_offset */
++ /* {7}, */
++ HOWTO (R_IMAGEBASE, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "rva32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ FALSE), /* pcrel_offset */
++ EMPTY_HOWTO (010),
++ EMPTY_HOWTO (011),
++ EMPTY_HOWTO (012),
++ EMPTY_HOWTO (013),
++ EMPTY_HOWTO (014),
++ EMPTY_HOWTO (015),
++ EMPTY_HOWTO (016),
++ HOWTO (R_RELBYTE, /* type */
++ 0, /* rightshift */
++ 0, /* size (0 = byte, 1 = short, 2 = long) */
++ 8, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "8", /* name */
++ TRUE, /* partial_inplace */
++ 0x000000ff, /* src_mask */
++ 0x000000ff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_RELWORD, /* type */
++ 0, /* rightshift */
++ 1, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "16", /* name */
++ TRUE, /* partial_inplace */
++ 0x0000ffff, /* src_mask */
++ 0x0000ffff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_RELLONG, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ FALSE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_bitfield, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_PCRBYTE, /* type */
++ 0, /* rightshift */
++ 0, /* size (0 = byte, 1 = short, 2 = long) */
++ 8, /* bitsize */
++ TRUE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_signed, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "DISP8", /* name */
++ TRUE, /* partial_inplace */
++ 0x000000ff, /* src_mask */
++ 0x000000ff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_PCRWORD, /* type */
++ 0, /* rightshift */
++ 1, /* size (0 = byte, 1 = short, 2 = long) */
++ 16, /* bitsize */
++ TRUE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_signed, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "DISP16", /* name */
++ TRUE, /* partial_inplace */
++ 0x0000ffff, /* src_mask */
++ 0x0000ffff, /* dst_mask */
++ PCRELOFFSET), /* pcrel_offset */
++ HOWTO (R_PCRLONG, /* type */
++ 0, /* rightshift */
++ 2, /* size (0 = byte, 1 = short, 2 = long) */
++ 32, /* bitsize */
++ TRUE, /* pc_relative */
++ 0, /* bitpos */
++ complain_overflow_signed, /* complain_on_overflow */
++ coff_ext_avr_reloc, /* special_function */
++ "DISP32", /* name */
++ TRUE, /* partial_inplace */
++ 0xffffffff, /* src_mask */
++ 0xffffffff, /* dst_mask */
++ PCRELOFFSET) /* pcrel_offset */
++};
++
++/* Turn a howto into a reloc nunmber */
++
++#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
++#define BADMAG(x) AVRBADMAG(x)
++#define AVR 1 /* Customize coffcode.h */
++
++#define RTYPE2HOWTO(cache_ptr, dst) \
++ (cache_ptr)->howto = howto_table + (dst)->r_type;
++
++/* For AVR COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
++ library. On some other COFF targets STYP_BSS is normally
++ STYP_NOLOAD. */
++#define BSS_NOLOAD_IS_SHARED_LIBRARY
++
++/* Compute the addend of a reloc. If the reloc is to a common symbol,
++ the object file contains the value of the common symbol. By the
++ time this is called, the linker may be using a different symbol
++ from a different object file with a different value. Therefore, we
++ hack wildly to locate the original symbol from this file so that we
++ can make the correct adjustment. This macro sets coffsym to the
++ symbol from the original file, and uses it to set the addend value
++ correctly. If this is not a common symbol, the usual addend
++ calculation is done, except that an additional tweak is needed for
++ PC relative relocs.
++ FIXME: This macro refers to symbols and asect; these are from the
++ calling function, not the macro arguments. */
++
++#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
++ { \
++ coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
++ if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
++ coffsym = (obj_symbols (abfd) \
++ + (cache_ptr->sym_ptr_ptr - symbols)); \
++ else if (ptr) \
++ coffsym = coff_symbol_from (abfd, ptr); \
++ if (coffsym != (coff_symbol_type *) NULL \
++ && coffsym->native->u.syment.n_scnum == 0) \
++ cache_ptr->addend = - coffsym->native->u.syment.n_value; \
++ else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
++ && ptr->section != (asection *) NULL) \
++ cache_ptr->addend = - (ptr->section->vma + ptr->value); \
++ else \
++ cache_ptr->addend = 0; \
++ if (ptr && howto_table[reloc.r_type].pc_relative) \
++ cache_ptr->addend += asect->vma; \
++ }
++
++/* We use the special COFF backend linker. */
++#define coff_relocate_section _bfd_coff_generic_relocate_section
++
++static reloc_howto_type *
++coff_ext_avr_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
++ bfd *abfd ATTRIBUTE_UNUSED;
++ asection *sec;
++ struct internal_reloc *rel;
++ struct coff_link_hash_entry *h;
++ struct internal_syment *sym;
++ bfd_vma *addendp;
++{
++
++ reloc_howto_type *howto;
++
++ howto = howto_table + rel->r_type;
++
++ if (howto->pc_relative)
++ *addendp += sec->vma;
++
++ if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
++ {
++ /* This is a common symbol. The section contents include the
++ size (sym->n_value) as an addend. The relocate_section
++ function will be adding in the final value of the symbol. We
++ need to subtract out the current size in order to get the
++ correct result. */
++
++ BFD_ASSERT (h != NULL);
++
++ /* I think we *do* want to bypass this. If we don't, I have seen some data
++ parameters get the wrong relcation address. If I link two versions
++ with and without this section bypassed and then do a binary comparison,
++ the addresses which are different can be looked up in the map. The
++ case in which this section has been bypassed has addresses which correspond
++ to values I can find in the map. */
++ *addendp -= sym->n_value;
++ }
++
++ /* If the output symbol is common (in which case this must be a
++ relocateable link), we need to add in the final size of the
++ common symbol. */
++ if (h != NULL && h->root.type == bfd_link_hash_common)
++ *addendp += h->root.u.c.size;
++
++ return howto;
++}
++
++#define coff_rtype_to_howto coff_ext_avr_rtype_to_howto
++
++#ifndef bfd_pe_print_pdata
++#define bfd_pe_print_pdata NULL
++#endif
++
++#include "coffcode.h"
++
++static const bfd_target *
++coff_ext_avr_object_p(a)
++ bfd *a;
++{
++ return coff_object_p (a);
++}
++
++const bfd_target
++#ifdef TARGET_SYM
++ TARGET_SYM =
++#else
++ avrextcoff_vec =
++#endif
++{
++#ifdef TARGET_NAME
++ TARGET_NAME,
++#else
++ "coff-ext-avr", /* name */
++#endif
++ bfd_target_coff_flavour,
++ BFD_ENDIAN_LITTLE, /* data byte order is little */
++ BFD_ENDIAN_LITTLE, /* header byte order is little */
++
++ (HAS_RELOC | EXEC_P | /* object flags */
++ HAS_LINENO | HAS_DEBUG |
++ HAS_SYMS | HAS_LOCALS | WP_TEXT),
++
++ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
++ 0, /* leading char */
++ '/', /* ar_pad_char */
++ 15, /* ar_max_namelen */
++
++ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
++ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
++ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
++ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
++ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
++ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
++
++/* Note that we allow an object file to be treated as a core file as well. */
++ {_bfd_dummy_target, coff_ext_avr_object_p, /* bfd_check_format */
++ bfd_generic_archive_p, coff_ext_avr_object_p},
++ {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
++ bfd_false},
++ {bfd_false, coff_write_object_contents, /* bfd_write_contents */
++ _bfd_write_archive_contents, bfd_false},
++
++ BFD_JUMP_TABLE_GENERIC (coff),
++ BFD_JUMP_TABLE_COPY (coff),
++ BFD_JUMP_TABLE_CORE (_bfd_nocore),
++ BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
++ BFD_JUMP_TABLE_SYMBOLS (coff),
++ BFD_JUMP_TABLE_RELOCS (coff),
++ BFD_JUMP_TABLE_WRITE (coff),
++ BFD_JUMP_TABLE_LINK (coff),
++ BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
++
++ NULL,
++
++ COFF_SWAP_TABLE
++};
+diff -Nruw bfd/coffcode.h bfd/coffcode.h
+--- bfd/coffcode.h 2009-09-10 17:17:12.000000000 +0530
++++ bfd/coffcode.h 2010-02-10 17:35:58.253349600 +0530
+@@ -1,3 +1,4 @@
++
+ /* Support for the generic parts of most COFF variants, for BFD.
+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+@@ -1910,6 +1911,17 @@
+ coff->relocbase = 0;
+ coff->local_toc_sym_map = 0;
+
++ /* These members communicate important constants about the symbol
++ table to GDB's symbol-reading code. These `constants'
++ unfortunately vary among coff implementations... */
++ coff->local_n_btmask = N_BTMASK;
++ coff->local_n_btshft = N_BTSHFT;
++ coff->local_n_tmask = N_TMASK;
++ coff->local_n_tshift = N_TSHIFT;
++ coff->local_symesz = bfd_coff_symesz (abfd);
++ coff->local_auxesz = bfd_coff_auxesz (abfd);
++ coff->local_linesz = bfd_coff_linesz (abfd);
++
+ /* make_abs_section(abfd);*/
+
+ return TRUE;
+@@ -1934,17 +1946,6 @@
+
+ coff->sym_filepos = internal_f->f_symptr;
+
+- /* These members communicate important constants about the symbol
+- table to GDB's symbol-reading code. These `constants'
+- unfortunately vary among coff implementations... */
+- coff->local_n_btmask = N_BTMASK;
+- coff->local_n_btshft = N_BTSHFT;
+- coff->local_n_tmask = N_TMASK;
+- coff->local_n_tshift = N_TSHIFT;
+- coff->local_symesz = bfd_coff_symesz (abfd);
+- coff->local_auxesz = bfd_coff_auxesz (abfd);
+- coff->local_linesz = bfd_coff_linesz (abfd);
+-
+ coff->timestamp = internal_f->f_timdat;
+
+ obj_raw_syment_count (abfd) =
+@@ -2076,6 +2077,11 @@
+ }
+ break;
+ #endif
++#ifdef AVRMAGIC
++ case AVRMAGIC:
++ arch = bfd_arch_avr;
++ break;
++#endif
+ #ifdef MC68MAGIC
+ case MC68MAGIC:
+ case M68MAGIC:
+@@ -2871,6 +2877,13 @@
+ return TRUE;
+ #endif
+
++#ifdef AVRMAGIC
++ case bfd_arch_avr:
++ *magicp = AVRMAGIC;
++ return TRUE;
++ break;
++#endif
++
+ #ifdef PPCMAGIC
+ case bfd_arch_powerpc:
+ *magicp = PPCMAGIC;
+@@ -3698,6 +3711,11 @@
+ section.s_page = 0;
+ #endif
+
++#ifdef AVR
++ /* AVR uses s_paddr the way GNU uses s_vaddr, and effectively
++ ignores s_vaddr. */
++ section.s_paddr = current->vma;
++#endif
+ #ifdef COFF_WITH_PE
+ section.s_paddr = 0;
+ #endif
+@@ -4042,6 +4060,17 @@
+ internal_a.magic = ZMAGIC;
+ #endif
+
++#ifdef AVR
++ /* a.out is a dummy for non-extended COFF */
++ internal_a.magic = AVRAOUTMAGIC;
++ /* Upper nibble of f_flags must be set for historical reasons.
++ The upper byte remains blank on coff-avr, so undo the F_AR32WR
++ setting performed above. */
++ internal_f.f_flags |= F_JUNK;
++ internal_f.f_flags &= ~F_UNUSED;
++#define __A_MAGIC_SET__
++#endif /* AVR */
++
+ #if defined(PPC_PE)
+ #define __A_MAGIC_SET__
+ internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
+@@ -4109,8 +4138,16 @@
+ #endif
+ }
+
++#ifdef AVR_EXT_COFF
++ /* Note that we do not set F_PTRINFO because the GNU toolchain
++ doesn't provide any information about the target of a pointer,
++ so we cannot derive which section our pointer target would be
++ in. */
++ internal_a.vstamp = F_FULLPATHS | F_STRUCTINFO;
++#else
+ /* FIXME: Does anybody ever set this to another value? */
+ internal_a.vstamp = 0;
++#endif
+
+ /* Now should write relocs, strings, syms. */
+ obj_sym_filepos (abfd) = sym_base;
+@@ -4668,6 +4705,10 @@
+ /* In PE, 0x69 (105) denotes a weak external symbol. */
+ case C_NT_WEAK:
+ #endif
++#ifdef AVR
++ /* Some AVR COFF compilers handle EXTDEF like EXT. */
++ case C_EXTDEF: /* external definition */
++#endif
+ switch (coff_classify_symbol (abfd, &src->u.syment))
+ {
+ case COFF_SYMBOL_GLOBAL:
+@@ -4891,7 +4932,9 @@
+ && src->u.syment.n_scnum == 0)
+ break;
+ /* Fall through. */
++#if !defined(AVR)
+ case C_EXTDEF: /* External definition. */
++#endif
+ case C_ULABEL: /* Undefined label. */
+ case C_USTATIC: /* Undefined static. */
+ #ifndef COFF_WITH_PE
+diff -Nruw bfd/coffgen.c bfd/coffgen.c
+--- bfd/coffgen.c 2009-09-10 17:17:12.000000000 +0530
++++ bfd/coffgen.c 2010-02-11 11:20:28.795092600 +0530
+@@ -699,6 +699,20 @@
+ if (last_file != NULL)
+ last_file->n_value = native_index;
+ last_file = &(s->u.syment);
++ if (bfd_get_arch (bfd_ptr) == bfd_arch_avr
++ && bfd_coff_long_filenames (bfd_ptr)
++ && s->u.syment.n_numaux > 0)
++ {
++ /* AVR COFF records long filenames in successive aux
++ records. Adjust the number of aux records
++ required here, so the renumbering will account
++ for them. */
++ unsigned int filnmlen = bfd_coff_filnmlen (bfd_ptr);
++ unsigned int namelen = strlen (coff_symbol_ptr->symbol.name);
++ unsigned int n = (namelen + filnmlen - 1) / filnmlen;
++
++ s->u.syment.n_numaux = n > NAUXENTS? NAUXENTS: n;
++ }
+ }
+ else
+ /* Modify the symbol values according to their section and
+@@ -827,6 +841,20 @@
+ {
+ if (name_length <= filnmlen)
+ strncpy (auxent->x_file.x_fname, name, filnmlen);
++ else if (bfd_get_arch (abfd) == bfd_arch_avr)
++ {
++ /* AVR COFF records long filenames in successive aux records. */
++ int i = 1;
++ while (name_length > filnmlen && i < NAUXENTS)
++ {
++ strncpy (auxent->x_file.x_fname, name, filnmlen);
++ name += filnmlen;
++ name_length -= filnmlen;
++ i++;
++ auxent = &(native + i)->u.auxent;
++ }
++ strncpy (auxent->x_file.x_fname, name, filnmlen);
++ }
+ else
+ {
+ auxent->x_file.x_n.x_offset = *string_size_p + STRING_SIZE_SIZE;
+@@ -1272,6 +1300,10 @@
+ if (bfd_bwrite (".file", (bfd_size_type) 6, abfd) != 6)
+ return FALSE;
+ }
++ if (bfd_get_arch (abfd) == bfd_arch_avr)
++ /* AVR COFF handles long file names in aux records. */
++ maxlen = name_length;
++ else
+ maxlen = bfd_coff_filnmlen (abfd);
+ }
+ else
+@@ -1710,14 +1742,27 @@
+ {
+ /* Ordinary short filename, put into memory anyway. The
+ Microsoft PE tools sometimes store a filename in
+- multiple AUX entries. */
++ multiple AUX entries.
++ AVR COFF does it that way, too. */
+ if (internal_ptr->u.syment.n_numaux > 1
+- && coff_data (abfd)->pe)
+- internal_ptr->u.syment._n._n_n._n_offset =
+- ((bfd_hostptr_t)
+- copy_name (abfd,
+- (internal_ptr + 1)->u.auxent.x_file.x_fname,
+- internal_ptr->u.syment.n_numaux * symesz));
++ && (coff_data (abfd)->pe
++ || (bfd_get_arch (abfd) == bfd_arch_avr)))
++ {
++ char *b;
++ unsigned int i;
++
++ /* We allocate enough storage to fit the contents of
++ this many aux records, and simply append a \0.
++ This ensures the string will always be
++ terminated, even in the case where it just fit
++ into the aux records. */
++ b = (char *) bfd_alloc (abfd,
++ internal_ptr->u.syment.n_numaux * FILNMLEN + 1);
++ internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t) b;
++ b[internal_ptr->u.syment.n_numaux * FILNMLEN] = '\0';
++ for (i = 0; i < internal_ptr->u.syment.n_numaux; i++, b += FILNMLEN)
++ memcpy (b, (internal_ptr + i + 1)->u.auxent.x_file.x_fname, FILNMLEN);
++ }
+ else
+ internal_ptr->u.syment._n._n_n._n_offset =
+ ((bfd_hostptr_t)
+@@ -1823,9 +1868,9 @@
+
+ if (new_symbol == NULL)
+ return NULL;
+- /* @@ The 10 is a guess at a plausible maximum number of aux entries
++ /* @@ The NAUXENTS is a guess at a plausible maximum number of aux entries
+ (but shouldn't be a constant). */
+- amt = sizeof (combined_entry_type) * 10;
++ amt = sizeof (combined_entry_type) * (NAUXENTS + 1);
+ new_symbol->native = (combined_entry_type *) bfd_zalloc (abfd, amt);
+ if (!new_symbol->native)
+ return NULL;
+diff -Nruw bfd/coffswap.h bfd/coffswap.h
+--- bfd/coffswap.h 2009-09-07 13:45:15.000000000 +0530
++++ bfd/coffswap.h 2010-02-11 11:24:25.908936000 +0530
+@@ -383,7 +383,11 @@
+ void * ext1,
+ int type,
+ int in_class,
+- int indx,
++ int indx
++#if defined(AVR) && __GNUC__
++ __attribute__((unused))
++#endif
++ ,
+ int numaux,
+ void * in1)
+ {
+@@ -409,9 +413,13 @@
+ #else
+ if (numaux > 1)
+ {
++#if defined(AVR)
++ memcpy (in->x_file.x_fname, ext->x_file.x_fname, sizeof (AUXENT));
++#else
+ if (indx == 0)
+ memcpy (in->x_file.x_fname, ext->x_file.x_fname,
+ numaux * sizeof (AUXENT));
++#endif
+ }
+ else
+ memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
+diff -Nruw bfd/config.bfd bfd/config.bfd
+--- bfd/config.bfd 2009-08-06 23:08:00.000000000 +0530
++++ bfd/config.bfd 2010-02-10 17:35:58.300224600 +0530
+@@ -339,6 +339,7 @@
+
+ avr-*-*)
+ targ_defvec=bfd_elf32_avr_vec
++ targ_selvecs="bfd_elf32_avr_vec avrcoff_vec avrextcoff_vec"
+ ;;
+
+ bfin-*-*)
+diff -Nruw bfd/configure bfd/configure
+--- bfd/configure 2009-10-16 17:17:47.000000000 +0530
++++ bfd/configure 2010-02-10 17:35:58.331474600 +0530
+@@ -14782,6 +14782,8 @@
+ armpe_little_vec) tb="$tb pe-arm.lo peigen.lo cofflink.lo " ;;
+ armpei_big_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
+ armpei_little_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
++ avrcoff_vec) tb="$tb coff-avr.lo cofflink.lo " ;;
++ avrextcoff_vec) tb="$tb coff-ext-avr.lo cofflink.lo " ;;
+ b_out_vec_big_host) tb="$tb bout.lo aout32.lo" ;;
+ b_out_vec_little_host) tb="$tb bout.lo aout32.lo" ;;
+ bfd_pei_ia64_vec) tb="$tb pei-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
+diff -Nruw bfd/configure.in bfd/configure.in
+--- bfd/configure.in 2009-10-16 17:17:44.000000000 +0530
++++ bfd/configure.in 2010-02-10 17:35:58.331474600 +0530
+@@ -670,6 +670,8 @@
+ armpe_little_vec) tb="$tb pe-arm.lo peigen.lo cofflink.lo " ;;
+ armpei_big_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
+ armpei_little_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
++ avrcoff_vec) tb="$tb coff-avr.lo cofflink.lo " ;;
++ avrextcoff_vec) tb="$tb coff-ext-avr.lo cofflink.lo " ;;
+ b_out_vec_big_host) tb="$tb bout.lo aout32.lo" ;;
+ b_out_vec_little_host) tb="$tb bout.lo aout32.lo" ;;
+ bfd_pei_ia64_vec) tb="$tb pei-ia64.lo pepigen.lo cofflink.lo"; target_size=64 ;;
+diff -Nruw bfd/targets.c bfd/targets.c
+--- bfd/targets.c 2009-09-10 17:17:13.000000000 +0530
++++ bfd/targets.c 2010-02-10 17:35:58.347099600 +0530
+@@ -564,6 +564,8 @@
+ extern const bfd_target armpe_little_vec;
+ extern const bfd_target armpei_big_vec;
+ extern const bfd_target armpei_little_vec;
++extern const bfd_target avrcoff_vec;
++extern const bfd_target avrextcoff_vec;
+ extern const bfd_target b_out_vec_big_host;
+ extern const bfd_target b_out_vec_little_host;
+ extern const bfd_target bfd_pei_ia64_vec;
+@@ -890,6 +892,8 @@
+ &armpe_little_vec,
+ &armpei_big_vec,
+ &armpei_little_vec,
++ &avrcoff_vec,
++ &avrextcoff_vec,
+ &b_out_vec_big_host,
+ &b_out_vec_little_host,
+ #ifdef BFD64
+diff -Nruw binutils/Makefile.am binutils/Makefile.am
+--- binutils/Makefile.am 2009-09-09 13:43:23.000000000 +0530
++++ binutils/Makefile.am 2010-02-10 17:35:57.972099600 +0530
+@@ -101,7 +101,7 @@
+ resbin.c rescoff.c resrc.c resres.c \
+ size.c srconv.c stabs.c strings.c sysdump.c \
+ unwind-ia64.c version.c \
+- windres.c winduni.c wrstabs.c \
++ windres.c winduni.c wrcoff.c wrstabs.c \
+ windmc.c mclex.c
+
+ GENERATED_CFILES = \
+@@ -109,7 +109,7 @@
+ defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
+
+ DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
+-WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
++WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c wrcoff.c
+
+ # Code shared by all the binutils.
+ BULIBS = bucomm.c version.c filemode.c
+diff -Nruw binutils/Makefile.in binutils/Makefile.in
+--- binutils/Makefile.in 2009-09-09 13:43:23.000000000 +0530
++++ binutils/Makefile.in 2010-02-10 17:35:57.987724600 +0530
+@@ -126,7 +126,7 @@
+ nm_new_OBJECTS = $(am_nm_new_OBJECTS)
+ nm_new_LDADD = $(LDADD)
+ am__objects_2 = rddbg.$(OBJEXT) debug.$(OBJEXT) stabs.$(OBJEXT) \
+- ieee.$(OBJEXT) rdcoff.$(OBJEXT)
++ ieee.$(OBJEXT) rdcoff.$(OBJEXT) wrcoff.$(OBJEXT)
+ am__objects_3 = $(am__objects_2) wrstabs.$(OBJEXT)
+ am_objcopy_OBJECTS = objcopy.$(OBJEXT) not-strip.$(OBJEXT) \
+ rename.$(OBJEXT) $(am__objects_3) $(am__objects_1)
+@@ -439,7 +439,7 @@
+ resbin.c rescoff.c resrc.c resres.c \
+ size.c srconv.c stabs.c strings.c sysdump.c \
+ unwind-ia64.c version.c \
+- windres.c winduni.c wrstabs.c \
++ windres.c winduni.c wrcoff.c wrstabs.c \
+ windmc.c mclex.c
+
+ GENERATED_CFILES = \
+@@ -447,7 +447,7 @@
+ defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
+
+ DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
+-WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
++WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c wrcoff.c
+
+ # Code shared by all the binutils.
+ BULIBS = bucomm.c version.c filemode.c
+diff -Nruw binutils/bucomm.c binutils/bucomm.c
+--- binutils/bucomm.c 2009-09-14 17:13:26.000000000 +0530
++++ binutils/bucomm.c 2010-02-10 17:35:58.034599600 +0530
+@@ -550,6 +550,32 @@
return ret;
}
@@ -33,9 +1503,22 @@
/* Returns the size of the named file. If the file does not
exist, or if it is not a real file, then a suitable non-fatal
error message is printed and zero is returned. */
---- ./binutils/budbg.h.orig 2008-06-12 13:57:40.000000000 +0200
-+++ ./binutils/budbg.h 2009-01-06 17:45:34.000000000 +0100
-@@ -51,8 +51,11 @@
+diff -Nruw binutils/bucomm.h binutils/bucomm.h
+--- binutils/bucomm.h 2009-09-02 12:52:31.000000000 +0530
++++ binutils/bucomm.h 2010-02-10 17:35:58.050224600 +0530
+@@ -58,6 +58,8 @@
+
+ off_t get_file_size (const char *);
+
++const char *bu_basename PARAMS ((const char *));
++
+ extern char *program_name;
+
+ /* filemode.c */
+diff -Nruw binutils/budbg.h binutils/budbg.h
+--- binutils/budbg.h 2009-09-02 12:52:31.000000000 +0530
++++ binutils/budbg.h 2010-02-10 17:35:58.050224600 +0530
+@@ -52,8 +52,11 @@
extern bfd_boolean write_ieee_debugging_info (bfd *, void *);
@@ -48,8 +1531,140 @@
+ (bfd *abfd, void *, long *symcountp, asymbol ***);
+
#endif
---- ./binutils/debug.h.orig 2007-07-05 18:54:45.000000000 +0200
-+++ ./binutils/debug.h 2009-01-06 17:45:34.000000000 +0100
+diff -Nruw binutils/debug.c binutils/debug.c
+--- binutils/debug.c 2009-09-14 17:13:26.000000000 +0530
++++ binutils/debug.c 2010-02-11 10:50:38.043866600 +0530
+@@ -31,6 +31,7 @@
+ #include <assert.h>
+ #include "bfd.h"
+ #include "libiberty.h"
++#include "bucomm.h"
+ #include "debug.h"
+
+ /* Global information we keep for debugging. A pointer to this
+@@ -552,6 +553,19 @@
+ struct debug_type_s *t;
+ };
+
++/* Simple list, used for pathname translations. */
++struct xlat_list
++{
++ /* Next string on list. */
++ struct xlat_list *next;
++ /* Old part to match against. */
++ const char *old;
++ size_t olen;
++ /* New part to replace. */
++ const char *newstr;
++ size_t nlen;
++};
++
+ /* Local functions. */
+
+ static void debug_error (const char *);
+@@ -588,6 +602,11 @@
+ (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
+ static bfd_boolean debug_class_type_samep
+ (struct debug_handle *, struct debug_type_s *, struct debug_type_s *);
++static const char *debug_xlat_pathname (const char *);
++
++/* List of pathname translations. */
++static struct xlat_list *xlat, *xltail;
++static bfd_boolean xlat_basename;
+
+ /* Issue an error message. */
+
+@@ -680,6 +699,8 @@
+
+ if (name == NULL)
+ name = "";
++ else
++ name = debug_xlat_pathname (name);
+
+ nfile = (struct debug_file *) xmalloc (sizeof *nfile);
+ memset (nfile, 0, sizeof *nfile);
+@@ -720,6 +741,8 @@
+
+ if (name == NULL)
+ name = "";
++ else
++ name = debug_xlat_pathname (name);
+
+ if (info->current_unit == NULL)
+ {
+@@ -3370,3 +3393,69 @@
+
+ return TRUE;
+ }
++
++/* Register a pathname translation. */
++void
++debug_register_pathname_xlat (oname, nname)
++ const char *oname;
++ const char *nname;
++{
++ struct xlat_list *xlp;
++
++ /* Special case: if oname is given as NULL, this means the
++ --basename option has been given to objcopy. */
++ if (oname == NULL)
++ {
++ xlat_basename = TRUE;
++ return;
++ }
++
++ xlp = (struct xlat_list *) xmalloc (sizeof (struct xlat_list));
++ xlp->next = NULL;
++ if (xlat == NULL)
++ xlat = xltail = xlp;
++ else
++ {
++ xltail->next = xlp;
++ xltail = xlp;
++ }
++ xlp->old = oname;
++ xlp->newstr = nname;
++ xlp->olen = strlen (oname);
++ xlp->nlen = strlen (nname);
++}
++
++/* Try to translate a pathname. */
++static const char *
++debug_xlat_pathname (oname)
++ const char *oname;
++{
++ struct xlat_list *xlp;
++ char *cp;
++ size_t olen;
++
++ if (xlat_basename)
++ return bu_basename (oname);
++
++ olen = strlen (oname);
++ for (xlp = xlat; xlp; xlp = xlp->next)
++ {
++ if (xlp->olen > olen)
++ /* This cannot be our turn. */
++ continue;
++ /* Since we have pre-computed all our length values to avoid
++ repetitively computing them, just use memcmp() since it's
++ faster than strcmp(). */
++ if (memcmp (xlp->old, oname, xlp->olen) == 0)
++ {
++ cp = (char *) xmalloc (olen + xlp->nlen - xlp->olen + 1);
++ memcpy (cp, xlp->newstr, xlp->nlen);
++ memcpy (cp + xlp->nlen, oname + xlp->olen,
++ olen - xlp->olen + 1);
++ return cp;
++ }
++ }
++
++ /* Not found, pass the original name on. */
++ return oname;
++}
+diff -Nruw binutils/debug.h binutils/debug.h
+--- binutils/debug.h 2009-09-14 17:13:26.000000000 +0530
++++ binutils/debug.h 2010-02-10 17:35:58.097099600 +0530
@@ -440,6 +440,12 @@
extern bfd_boolean debug_start_source (void *, const char *);
@@ -63,18 +1678,19 @@
/* Record a function definition. This implicitly starts a function
block. The debug_type argument is the type of the return value.
The bfd_boolean indicates whether the function is globally visible.
---- ./binutils/doc/objcopy.1.orig 2008-09-10 09:50:26.000000000 +0200
-+++ ./binutils/doc/objcopy.1 2009-01-06 17:45:34.000000000 +0100
-@@ -193,6 +193,8 @@
+diff -Nruw binutils/doc/objcopy.1 binutils/doc/objcopy.1
+--- binutils/doc/objcopy.1 2009-10-16 17:22:19.000000000 +0530
++++ binutils/doc/objcopy.1 2010-02-11 10:22:09.312500000 +0530
+@@ -202,6 +202,8 @@
[\fB\-\-readonly\-text\fR]
[\fB\-\-pure\fR]
[\fB\-\-impure\fR]
-+ [\fB\-\-change\-pathname\fR \fIold\fR=\fInew\fR]
-+ [\fB\-\-basename\fR]
- [\fB\-v\fR|\fB\-\-verbose\fR]
- [\fB\-V\fR|\fB\-\-version\fR]
- [\fB\-\-help\fR] [\fB\-\-info\fR]
-@@ -805,6 +807,23 @@
++ [\fB\-\-change\-pathname\fR \fIold\fR=\fInew\fR]
++ [\fB\-\-basename\fR]
+ [\fB\-\-file\-alignment=\fR\fInum\fR]
+ [\fB\-\-heap=\fR\fIsize\fR]
+ [\fB\-\-image\-base=\fR\fIaddress\fR]
+@@ -885,6 +887,23 @@
It can also be a useful way of reducing the size of a \fB\-\-just\-symbols\fR
linker input file.
.RE
@@ -98,8 +1714,112 @@
.IP "\fB\-V\fR" 4
.IX Item "-V"
.PD 0
---- ./binutils/rdcoff.c.orig 2007-07-05 18:54:45.000000000 +0200
-+++ ./binutils/rdcoff.c 2009-01-06 17:45:34.000000000 +0100
+diff -Nruw binutils/objcopy.c binutils/objcopy.c
+--- binutils/objcopy.c 2009-09-14 17:13:26.000000000 +0530
++++ binutils/objcopy.c 2010-02-11 10:56:56.890302300 +0530
+@@ -32,6 +32,7 @@
+ #include "elf-bfd.h"
+ #include <sys/stat.h>
+ #include "libbfd.h"
++#include "debug.h"
+ #include "coff/internal.h"
+ #include "libcoff.h"
+
+@@ -297,6 +298,8 @@
+ OPTION_IMPURE,
+ OPTION_EXTRACT_SYMBOL,
+ OPTION_REVERSE_BYTES,
++ OPTION_CHANGE_PATHNAME,
++ OPTION_BASENAME,
+ OPTION_FILE_ALIGNMENT,
+ OPTION_HEAP,
+ OPTION_IMAGE_BASE,
+@@ -346,10 +349,12 @@
+ {"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
+ {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
+ {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE},
++ {"basename", no_argument, 0, OPTION_BASENAME},
+ {"binary-architecture", required_argument, 0, 'B'},
+ {"byte", required_argument, 0, 'b'},
+ {"change-addresses", required_argument, 0, OPTION_CHANGE_ADDRESSES},
+ {"change-leading-char", no_argument, 0, OPTION_CHANGE_LEADING_CHAR},
++ {"change-pathname", required_argument, 0, OPTION_CHANGE_PATHNAME},
+ {"change-section-address", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
+ {"change-section-lma", required_argument, 0, OPTION_CHANGE_SECTION_LMA},
+ {"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA},
+@@ -543,6 +548,8 @@
+ --prefix-alloc-sections <prefix>\n\
+ Add <prefix> to start of every allocatable\n\
+ section name\n\
++ --change-pathname <old>=<new> Change debug pathnames from <old> to <new>\n\
++ --basename Strip directory part from debug pathnames\n\
+ --file-alignment <num> Set PE file alignment to <num>\n\
+ --heap <reserve>[,<commit>] Set PE reserve/commit heap to <reserve>/\n\
+ <commit>\n\
+@@ -999,6 +1006,8 @@
+ asymbol **from = isyms, **to = osyms;
+ long src_count = 0, dst_count = 0;
+ int relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
++ bfd_boolean need_for_debugging = convert_debugging
++ && bfd_get_arch (abfd) == bfd_arch_avr;
+
+ for (; src_count < symcount; src_count++)
+ {
+@@ -1099,7 +1108,8 @@
+ || bfd_is_com_section (bfd_get_section (sym)))
+ keep = strip_symbols != STRIP_UNNEEDED;
+ else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
+- keep = (strip_symbols != STRIP_DEBUG
++ keep = need_for_debugging
++ || (strip_symbols != STRIP_DEBUG
+ && strip_symbols != STRIP_UNNEEDED
+ && ! convert_debugging);
+ else if (bfd_coff_get_comdat_section (abfd, bfd_get_section (sym)))
+@@ -2817,6 +2827,10 @@
+ return write_ieee_debugging_info (obfd, dhandle);
+
+ if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
++ && bfd_get_arch (obfd) == bfd_arch_avr)
++ return write_coff_debugging_info (obfd, dhandle, symcountp, symppp);
++
++ if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
+ || bfd_get_flavour (obfd) == bfd_target_elf_flavour)
+ {
+ bfd_byte *syms, *strings;
+@@ -3641,6 +3655,30 @@
+ prefix_alloc_sections_string = optarg;
+ break;
+
++ case OPTION_CHANGE_PATHNAME:
++ {
++ const char *s;
++ int len;
++ char *name;
++
++ s = strchr (optarg, '=');
++ if (s == NULL)
++ fatal (_("bad format for %s"), "--change-pathname");
++
++ len = s - optarg;
++ name = (char *) xmalloc (len + 1);
++ strncpy (name, optarg, len);
++ name[len] = '\0';
++
++ debug_register_pathname_xlat (name, s + 1);
++ }
++ break;
++
++ case OPTION_BASENAME:
++ /* very special case of pathname translation */
++ debug_register_pathname_xlat (NULL, NULL);
++ break;
++
+ case OPTION_READONLY_TEXT:
+ bfd_flags_to_set |= WP_TEXT;
+ bfd_flags_to_clear &= ~WP_TEXT;
+diff -Nruw binutils/rdcoff.c binutils/rdcoff.c
+--- binutils/rdcoff.c 2009-09-02 12:52:32.000000000 +0530
++++ binutils/rdcoff.c 2010-02-10 17:35:58.128349600 +0530
@@ -82,6 +82,9 @@
struct coff_slots *slots;
/* Basic types. */
@@ -243,165 +1963,9 @@
if (ISFCN (syment.n_type))
{
fnname = name;
---- ./binutils/objcopy.c.orig 2008-08-06 02:42:17.000000000 +0200
-+++ ./binutils/objcopy.c 2009-01-06 17:45:34.000000000 +0100
-@@ -32,6 +32,7 @@
- #include "elf-bfd.h"
- #include <sys/stat.h>
- #include "libbfd.h"
-+#include "debug.h"
-
- struct is_specified_symbol_predicate_data
- {
-@@ -270,7 +271,9 @@
- OPTION_PURE,
- OPTION_IMPURE,
- OPTION_EXTRACT_SYMBOL,
-- OPTION_REVERSE_BYTES
-+ OPTION_REVERSE_BYTES,
-+ OPTION_CHANGE_PATHNAME,
-+ OPTION_BASENAME
- };
-
- /* Options to handle if running as "strip". */
-@@ -314,10 +317,12 @@
- {"adjust-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
- {"adjust-warnings", no_argument, 0, OPTION_CHANGE_WARNINGS},
- {"alt-machine-code", required_argument, 0, OPTION_ALT_MACH_CODE},
-+ {"basename", no_argument, 0, OPTION_BASENAME},
- {"binary-architecture", required_argument, 0, 'B'},
- {"byte", required_argument, 0, 'b'},
- {"change-addresses", required_argument, 0, OPTION_CHANGE_ADDRESSES},
- {"change-leading-char", no_argument, 0, OPTION_CHANGE_LEADING_CHAR},
-+ {"change-pathname", required_argument, 0, OPTION_CHANGE_PATHNAME},
- {"change-section-address", required_argument, 0, OPTION_CHANGE_SECTION_ADDRESS},
- {"change-section-lma", required_argument, 0, OPTION_CHANGE_SECTION_LMA},
- {"change-section-vma", required_argument, 0, OPTION_CHANGE_SECTION_VMA},
-@@ -502,6 +507,8 @@
- --prefix-alloc-sections <prefix>\n\
- Add <prefix> to start of every allocatable\n\
- section name\n\
-+ --change-pathname <old>=<new> Change debug pathnames from <old> to <new>\n\
-+ --basename Strip directory part from debug pathnames\n\
- -v --verbose List all object files modified\n\
- @<file> Read options from <file>\n\
- -V --version Display this program's version number\n\
-@@ -948,6 +955,8 @@
- asymbol **from = isyms, **to = osyms;
- long src_count = 0, dst_count = 0;
- int relocatable = (abfd->flags & (EXEC_P | DYNAMIC)) == 0;
-+ bfd_boolean need_for_debugging = convert_debugging
-+ && bfd_get_arch (abfd) == bfd_arch_avr;
-
- for (; src_count < symcount; src_count++)
- {
-@@ -1047,9 +1056,10 @@
- || bfd_is_com_section (bfd_get_section (sym)))
- keep = strip_symbols != STRIP_UNNEEDED;
- else if ((flags & BSF_DEBUGGING) != 0) /* Debugging symbol. */
-- keep = (strip_symbols != STRIP_DEBUG
-- && strip_symbols != STRIP_UNNEEDED
-- && ! convert_debugging);
-+ keep = need_for_debugging
-+ || (strip_symbols != STRIP_DEBUG
-+ && strip_symbols != STRIP_UNNEEDED
-+ && ! convert_debugging);
- else if (bfd_coff_get_comdat_section (abfd, bfd_get_section (sym)))
- /* COMDAT sections store special information in local
- symbols, so we cannot risk stripping any of them. */
-@@ -2659,6 +2669,10 @@
- return write_ieee_debugging_info (obfd, dhandle);
-
- if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
-+ && bfd_get_arch (obfd) == bfd_arch_avr)
-+ return write_coff_debugging_info (obfd, dhandle, symcountp, symppp);
-+
-+ if (bfd_get_flavour (obfd) == bfd_target_coff_flavour
- || bfd_get_flavour (obfd) == bfd_target_elf_flavour)
- {
- bfd_byte *syms, *strings;
-@@ -3359,6 +3373,30 @@
- prefix_alloc_sections_string = optarg;
- break;
-
-+ case OPTION_CHANGE_PATHNAME:
-+ {
-+ const char *s;
-+ int len;
-+ char *name;
-+
-+ s = strchr (optarg, '=');
-+ if (s == NULL)
-+ fatal (_("bad format for %s"), "--change-pathname");
-+
-+ len = s - optarg;
-+ name = (char *) xmalloc (len + 1);
-+ strncpy (name, optarg, len);
-+ name[len] = '\0';
-+
-+ debug_register_pathname_xlat (name, s + 1);
-+ }
-+ break;
-+
-+ case OPTION_BASENAME:
-+ /* very special case of pathname translation */
-+ debug_register_pathname_xlat (NULL, NULL);
-+ break;
-+
- case OPTION_READONLY_TEXT:
- bfd_flags_to_set |= WP_TEXT;
- bfd_flags_to_clear &= ~WP_TEXT;
---- ./binutils/Makefile.in.orig 2008-08-25 06:38:13.000000000 +0200
-+++ ./binutils/Makefile.in 2009-01-06 17:45:34.000000000 +0100
-@@ -133,7 +133,7 @@
- nm_new_OBJECTS = $(am_nm_new_OBJECTS)
- nm_new_LDADD = $(LDADD)
- am__objects_2 = rddbg.$(OBJEXT) debug.$(OBJEXT) stabs.$(OBJEXT) \
-- ieee.$(OBJEXT) rdcoff.$(OBJEXT)
-+ ieee.$(OBJEXT) rdcoff.$(OBJEXT) wrcoff.$(OBJEXT)
- am__objects_3 = $(am__objects_2) wrstabs.$(OBJEXT)
- am_objcopy_OBJECTS = objcopy.$(OBJEXT) not-strip.$(OBJEXT) \
- rename.$(OBJEXT) $(am__objects_3) $(am__objects_1)
-@@ -421,7 +421,7 @@
- resbin.c rescoff.c resrc.c resres.c \
- size.c srconv.c stabs.c strings.c sysdump.c \
- unwind-ia64.c version.c \
-- windres.c winduni.c wrstabs.c \
-+ windres.c winduni.c wrcoff.c wrstabs.c \
- windmc.c mclex.c
-
- GENERATED_CFILES = \
-@@ -429,7 +429,7 @@
- defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
-
- DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
--WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
-+WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c wrcoff.c
-
- # Code shared by all the binutils.
- BULIBS = bucomm.c version.c filemode.c
---- ./binutils/Makefile.am.orig 2008-08-25 06:38:13.000000000 +0200
-+++ ./binutils/Makefile.am 2009-01-06 17:45:34.000000000 +0100
-@@ -97,7 +97,7 @@
- resbin.c rescoff.c resrc.c resres.c \
- size.c srconv.c stabs.c strings.c sysdump.c \
- unwind-ia64.c version.c \
-- windres.c winduni.c wrstabs.c \
-+ windres.c winduni.c wrcoff.c wrstabs.c \
- windmc.c mclex.c
-
- GENERATED_CFILES = \
-@@ -105,7 +105,7 @@
- defparse.c deflex.c nlmheader.c rcparse.c mcparse.c
-
- DEBUG_SRCS = rddbg.c debug.c stabs.c ieee.c rdcoff.c
--WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c
-+WRITE_DEBUG_SRCS = $(DEBUG_SRCS) wrstabs.c wrcoff.c
-
- # Code shared by all the binutils.
- BULIBS = bucomm.c version.c filemode.c
---- ./binutils/wrcoff.c.orig 2009-01-06 17:45:34.000000000 +0100
-+++ ./binutils/wrcoff.c 2009-01-06 17:45:34.000000000 +0100
+diff -Nruw binutils/wrcoff.c binutils/wrcoff.c
+--- binutils/wrcoff.c 1970-01-01 05:30:00.000000000 +0530
++++ binutils/wrcoff.c 2010-02-10 17:35:58.159599600 +0530
@@ -0,0 +1,3410 @@
+/* wrcoff.c -- Generate (AVR) COFF debugging information
+ Copyright 2003 Free Software Foundation, Inc.
@@ -3813,160 +5377,9 @@
+
+ return TRUE;
+}
---- ./binutils/debug.c.orig 2007-07-05 18:54:45.000000000 +0200
-+++ ./binutils/debug.c 2009-01-06 17:45:34.000000000 +0100
-@@ -31,6 +31,7 @@
- #include <assert.h>
- #include "bfd.h"
- #include "libiberty.h"
-+#include "bucomm.h"
- #include "debug.h"
-
- /* Global information we keep for debugging. A pointer to this
-@@ -552,6 +553,19 @@
- struct debug_type *t;
- };
-
-+/* Simple list, used for pathname translations. */
-+struct xlat_list
-+{
-+ /* Next string on list. */
-+ struct xlat_list *next;
-+ /* Old part to match against. */
-+ const char *old;
-+ size_t olen;
-+ /* New part to replace. */
-+ const char *newstr;
-+ size_t nlen;
-+};
-+
- /* Local functions. */
-
- static void debug_error (const char *);
-@@ -588,6 +602,11 @@
- (struct debug_handle *, struct debug_type *, struct debug_type *);
- static bfd_boolean debug_class_type_samep
- (struct debug_handle *, struct debug_type *, struct debug_type *);
-+static const char *debug_xlat_pathname (const char *);
-+
-+/* List of pathname translations. */
-+static struct xlat_list *xlat, *xltail;
-+static bfd_boolean xlat_basename;
-
- /* Issue an error message. */
-
-@@ -680,6 +699,8 @@
-
- if (name == NULL)
- name = "";
-+ else
-+ name = debug_xlat_pathname (name);
-
- nfile = (struct debug_file *) xmalloc (sizeof *nfile);
- memset (nfile, 0, sizeof *nfile);
-@@ -720,6 +741,8 @@
-
- if (name == NULL)
- name = "";
-+ else
-+ name = debug_xlat_pathname (name);
-
- if (info->current_unit == NULL)
- {
-@@ -3370,3 +3393,69 @@
-
- return TRUE;
- }
-+
-+/* Register a pathname translation. */
-+void
-+debug_register_pathname_xlat (oname, nname)
-+ const char *oname;
-+ const char *nname;
-+{
-+ struct xlat_list *xlp;
-+
-+ /* Special case: if oname is given as NULL, this means the
-+ --basename option has been given to objcopy. */
-+ if (oname == NULL)
-+ {
-+ xlat_basename = TRUE;
-+ return;
-+ }
-+
-+ xlp = (struct xlat_list *) xmalloc (sizeof (struct xlat_list));
-+ xlp->next = NULL;
-+ if (xlat == NULL)
-+ xlat = xltail = xlp;
-+ else
-+ {
-+ xltail->next = xlp;
-+ xltail = xlp;
-+ }
-+ xlp->old = oname;
-+ xlp->newstr = nname;
-+ xlp->olen = strlen (oname);
-+ xlp->nlen = strlen (nname);
-+}
-+
-+/* Try to translate a pathname. */
-+static const char *
-+debug_xlat_pathname (oname)
-+ const char *oname;
-+{
-+ struct xlat_list *xlp;
-+ char *cp;
-+ size_t olen;
-+
-+ if (xlat_basename)
-+ return bu_basename (oname);
-+
-+ olen = strlen (oname);
-+ for (xlp = xlat; xlp; xlp = xlp->next)
-+ {
-+ if (xlp->olen > olen)
-+ /* This cannot be our turn. */
-+ continue;
-+ /* Since we have pre-computed all our length values to avoid
-+ repetitively computing them, just use memcmp() since it's
-+ faster than strcmp(). */
-+ if (memcmp (xlp->old, oname, xlp->olen) == 0)
-+ {
-+ cp = (char *) xmalloc (olen + xlp->nlen - xlp->olen + 1);
-+ memcpy (cp, xlp->newstr, xlp->nlen);
-+ memcpy (cp + xlp->nlen, oname + xlp->olen,
-+ olen - xlp->olen + 1);
-+ return cp;
-+ }
-+ }
-+
-+ /* Not found, pass the original name on. */
-+ return oname;
-+}
---- ./binutils/bucomm.h.orig 2007-08-30 12:19:03.000000000 +0200
-+++ ./binutils/bucomm.h 2009-01-06 17:45:34.000000000 +0100
-@@ -57,6 +57,8 @@
-
- off_t get_file_size (const char *);
-
-+const char *bu_basename PARAMS ((const char *));
-+
- extern char *program_name;
-
- /* filemode.c */
---- ./include/coff/internal.h.orig 2007-07-12 09:16:41.000000000 +0200
-+++ ./include/coff/internal.h 2009-01-06 17:45:34.000000000 +0100
-@@ -630,6 +630,8 @@
-
- };
-
-+#define NAUXENTS 10 /* number of pre-allocated aux entries */
-+
- /********************** RELOCATION DIRECTIVES **********************/
-
- struct internal_reloc
---- ./include/coff/avr.h.orig 2009-01-06 17:45:34.000000000 +0100
-+++ ./include/coff/avr.h 2009-01-06 17:45:34.000000000 +0100
+diff -Nruw include/coff/avr.h include/coff/avr.h
+--- include/coff/avr.h 1970-01-01 05:30:00.000000000 +0530
++++ include/coff/avr.h 2010-02-10 17:35:58.362724600 +0530
@@ -0,0 +1,110 @@
+/* coff information for Atmel AVR.
+
@@ -4078,1511 +5491,15 @@
+
+#define RELOC struct external_reloc
+#define RELSZ 10
---- ./bfd/coffgen.c.orig 2008-08-14 04:38:22.000000000 +0200
-+++ ./bfd/coffgen.c 2009-01-06 17:45:34.000000000 +0100
-@@ -687,6 +687,20 @@
- if (last_file != NULL)
- last_file->n_value = native_index;
- last_file = &(s->u.syment);
-+ if (bfd_get_arch (bfd_ptr) == bfd_arch_avr
-+ && bfd_coff_long_filenames (bfd_ptr)
-+ && s->u.syment.n_numaux > 0)
-+ {
-+ /* AVR COFF records long filenames in successive aux
-+ records. Adjust the number of aux records
-+ required here, so the renumbering will account
-+ for them. */
-+ unsigned int filnmlen = bfd_coff_filnmlen (bfd_ptr);
-+ unsigned int namelen = strlen (coff_symbol_ptr->symbol.name);
-+ unsigned int n = (namelen + filnmlen - 1) / filnmlen;
-+
-+ s->u.syment.n_numaux = n > NAUXENTS? NAUXENTS: n;
-+ }
- }
- else
- /* Modify the symbol values according to their section and
-@@ -815,6 +829,20 @@
- {
- if (name_length <= filnmlen)
- strncpy (auxent->x_file.x_fname, name, filnmlen);
-+ else if (bfd_get_arch (abfd) == bfd_arch_avr)
-+ {
-+ /* AVR COFF records long filenames in successive aux records. */
-+ int i = 1;
-+ while (name_length > filnmlen && i < NAUXENTS)
-+ {
-+ strncpy (auxent->x_file.x_fname, name, filnmlen);
-+ name += filnmlen;
-+ name_length -= filnmlen;
-+ i++;
-+ auxent = &(native + i)->u.auxent;
-+ }
-+ strncpy (auxent->x_file.x_fname, name, filnmlen);
-+ }
- else
- {
- auxent->x_file.x_n.x_offset = *string_size_p + STRING_SIZE_SIZE;
-@@ -1218,7 +1246,11 @@
- if (bfd_bwrite (".file", (bfd_size_type) 6, abfd) != 6)
- return FALSE;
- }
-- maxlen = bfd_coff_filnmlen (abfd);
-+ if (bfd_get_arch (abfd) == bfd_arch_avr)
-+ /* AVR COFF handles long file names in aux records. */
-+ maxlen = name_length;
-+ else
-+ maxlen = bfd_coff_filnmlen (abfd);
- }
- else
- maxlen = bfd_coff_force_symnames_in_strings (abfd) ? 0 : SYMNMLEN;
-@@ -1655,14 +1687,27 @@
- {
- /* Ordinary short filename, put into memory anyway. The
- Microsoft PE tools sometimes store a filename in
-- multiple AUX entries. */
-+ multiple AUX entries.
-+ AVR COFF does it that way, too. */
- if (internal_ptr->u.syment.n_numaux > 1
-- && coff_data (abfd)->pe)
-- internal_ptr->u.syment._n._n_n._n_offset =
-- ((bfd_hostptr_t)
-- copy_name (abfd,
-- (internal_ptr + 1)->u.auxent.x_file.x_fname,
-- internal_ptr->u.syment.n_numaux * symesz));
-+ && (coff_data (abfd)->pe
-+ || (bfd_get_arch (abfd) == bfd_arch_avr)))
-+ {
-+ char *b;
-+ unsigned int i;
-+
-+ /* We allocate enough storage to fit the contents of
-+ this many aux records, and simply append a \0.
-+ This ensures the string will always be
-+ terminated, even in the case where it just fit
-+ into the aux records. */
-+ b = (char *) bfd_alloc (abfd,
-+ internal_ptr->u.syment.n_numaux * FILNMLEN + 1);
-+ internal_ptr->u.syment._n._n_n._n_offset = (bfd_hostptr_t) b;
-+ b[internal_ptr->u.syment.n_numaux * FILNMLEN] = '\0';
-+ for (i = 0; i < internal_ptr->u.syment.n_numaux; i++, b += FILNMLEN)
-+ memcpy (b, (internal_ptr + i + 1)->u.auxent.x_file.x_fname, FILNMLEN);
-+ }
- else
- internal_ptr->u.syment._n._n_n._n_offset =
- ((bfd_hostptr_t)
-@@ -1768,9 +1813,9 @@
-
- if (new == NULL)
- return NULL;
-- /* @@ The 10 is a guess at a plausible maximum number of aux entries
-- (but shouldn't be a constant). */
-- amt = sizeof (combined_entry_type) * 10;
-+ /* @@ The NAUXENTS is a guess at a plausible maximum number of aux
-+ entries (but shouldn't be a constant). */
-+ amt = sizeof (combined_entry_type) * (NAUXENTS + 1);
- new->native = bfd_zalloc (abfd, amt);
- if (!new->native)
- return NULL;
---- ./bfd/configure.orig 2008-10-16 15:20:42.000000000 +0200
-+++ ./bfd/configure 2009-01-06 17:45:34.000000000 +0100
-@@ -19626,6 +19626,8 @@
- armpe_little_vec) tb="$tb pe-arm.lo peigen.lo cofflink.lo " ;;
- armpei_big_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
- armpei_little_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
-+ avrcoff_vec) tb="$tb coff-avr.lo cofflink.lo " ;;
-+ avrextcoff_vec) tb="$tb coff-ext-avr.lo cofflink.lo " ;;
- b_out_vec_big_host) tb="$tb bout.lo aout32.lo" ;;
- b_out_vec_little_host) tb="$tb bout.lo aout32.lo" ;;
- bfd_efi_app_ia32_vec) tb="$tb efi-app-ia32.lo peigen.lo cofflink.lo" ;;
---- ./bfd/targets.c.orig 2008-02-14 16:20:26.000000000 +0100
-+++ ./bfd/targets.c 2009-01-06 17:45:34.000000000 +0100
-@@ -558,6 +558,8 @@
- extern const bfd_target armpe_little_vec;
- extern const bfd_target armpei_big_vec;
- extern const bfd_target armpei_little_vec;
-+extern const bfd_target avrcoff_vec;
-+extern const bfd_target avrextcoff_vec;
- extern const bfd_target b_out_vec_big_host;
- extern const bfd_target b_out_vec_little_host;
- extern const bfd_target bfd_efi_app_ia32_vec;
-@@ -882,6 +884,8 @@
- &armpe_little_vec,
- &armpei_big_vec,
- &armpei_little_vec,
-+ &avrcoff_vec,
-+ &avrextcoff_vec,
- &b_out_vec_big_host,
- &b_out_vec_little_host,
- &bfd_efi_app_ia32_vec,
---- ./bfd/configure.in.orig 2008-10-16 15:20:34.000000000 +0200
-+++ ./bfd/configure.in 2009-01-06 17:45:34.000000000 +0100
-@@ -619,6 +619,8 @@
- armpe_little_vec) tb="$tb pe-arm.lo peigen.lo cofflink.lo " ;;
- armpei_big_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
- armpei_little_vec) tb="$tb pei-arm.lo peigen.lo cofflink.lo " ;;
-+ avrcoff_vec) tb="$tb coff-avr.lo cofflink.lo " ;;
-+ avrextcoff_vec) tb="$tb coff-ext-avr.lo cofflink.lo " ;;
- b_out_vec_big_host) tb="$tb bout.lo aout32.lo" ;;
- b_out_vec_little_host) tb="$tb bout.lo aout32.lo" ;;
- bfd_efi_app_ia32_vec) tb="$tb efi-app-ia32.lo peigen.lo cofflink.lo" ;;
---- ./bfd/Makefile.in.orig 2009-01-06 17:33:01.000000000 +0100
-+++ ./bfd/Makefile.in 2009-01-06 17:45:34.000000000 +0100
-@@ -462,6 +462,8 @@
- coff-apollo.lo \
- coff-arm.lo \
- coff-aux.lo \
-+ coff-avr.lo \
-+ coff-ext-avr.lo \
- coff-h8300.lo \
- coff-h8500.lo \
- coff-i386.lo \
-@@ -643,6 +645,8 @@
- coff-apollo.c \
- coff-arm.c \
- coff-aux.c \
-+ coff-avr.c \
-+ coff-ext-avr.c \
- coff-h8300.c \
- coff-h8500.c \
- coff-i386.c \
-@@ -1573,13 +1577,13 @@
- bfdver.h: $(srcdir)/version.h $(srcdir)/Makefile.in
- @echo "creating $@"
- @bfd_version=`echo "$(VERSION)" | sed -e 's/\([^\.]*\)\.*\([^\.]*\)\.*\([^\.]*\)\.*\([^\.]*\)\.*\([^\.]*\).*/\1.00\2.00\3.00\4.00\5/' -e 's/\([^\.]*\)\..*\(..\)\..*\(..\)\..*\(..\)\..*\(..\)$$/\1\2\3\4\5/'` ;\
-- bfd_version_string="\"$(VERSION)\"" ;\
-+ bfd_version_string="\"$(VERSION) + coff-avr-patch (20050630)\"" ;\
- bfd_soversion="$(VERSION)" ;\
- bfd_version_package="\"$(PKGVERSION)\"" ;\
- report_bugs_to="\"$(REPORT_BUGS_TO)\"" ;\
- if test "x$(RELEASE)" = x ; then \
- bfd_version_date=`sed -n -e 's/.*DATE //p' < $(srcdir)/version.h` ;\
-- bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
-+ bfd_version_string="\"$(VERSION).$${bfd_version_date} + coff-avr-patch (20050630)\"" ;\
- bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
- fi ;\
- sed -e "s,@bfd_version@,$$bfd_version," \
-@@ -1783,6 +1787,12 @@
- $(INCDIR)/coff/internal.h $(INCDIR)/coff/m68k.h $(INCDIR)/coff/external.h \
- coff-m68k.c $(INCDIR)/hashtab.h libcoff.h $(INCDIR)/bfdlink.h \
- coffcode.h coffswap.h
-+coff-avr.lo: coff-avr.c $(INCDIR)/filenames.h $(INCDIR)/coff/avr.h \
-+ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
-+ libcoff.h $(INCDIR)/bfdlink.h coffcode.h coffswap.h
-+coff-ext-avr.lo: coff-ext-avr.c $(INCDIR)/filenames.h $(INCDIR)/coff/avr.h \
-+ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
-+ libcoff.h $(INCDIR)/bfdlink.h coffcode.h coffswap.h
- coff-h8300.lo: coff-h8300.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \
- $(INCDIR)/bfdlink.h genlink.h $(INCDIR)/coff/h8300.h \
- $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
---- ./bfd/config.bfd.orig 2008-04-16 20:02:01.000000000 +0200
-+++ ./bfd/config.bfd 2009-01-06 17:45:34.000000000 +0100
-@@ -328,6 +328,7 @@
-
- avr-*-*)
- targ_defvec=bfd_elf32_avr_vec
-+ targ_selvecs="bfd_elf32_avr_vec avrcoff_vec avrextcoff_vec"
- ;;
-
- bfin-*-*)
---- ./bfd/coff-avr.c.orig 2009-01-06 17:45:34.000000000 +0100
-+++ ./bfd/coff-avr.c 2009-01-06 17:45:34.000000000 +0100
-@@ -0,0 +1,613 @@
-+/* BFD back-end for Atmel AVR COFF files.
-+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
-+ Free Software Foundation, Inc.
-+ Created mostly by substituting "avr" for "i860" in coff-i860.c
-+
-+This file is part of BFD, the Binary File Descriptor library.
-+
-+This program is free software; you can redistribute it and/or modify
-+it under the terms of the GNU General Public License as published by
-+the Free Software Foundation; either version 2 of the License, or
-+(at your option) any later version.
-+
-+This program is distributed in the hope that it will be useful,
-+but WITHOUT ANY WARRANTY; without even the implied warranty of
-+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+GNU General Public License for more details.
-+
-+You should have received a copy of the GNU General Public License
-+along with this program; if not, write to the Free Software
-+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-+
-+#include "bfd.h"
-+#include "sysdep.h"
-+#include "libbfd.h"
-+
-+#include "coff/avr.h"
-+
-+#include "coff/internal.h"
-+
-+#include "libcoff.h"
-+
-+static bfd_reloc_status_type coff_avr_reloc
-+ PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
-+static reloc_howto_type *coff_avr_rtype_to_howto
-+ PARAMS ((bfd *, asection *, struct internal_reloc *,
-+ struct coff_link_hash_entry *, struct internal_syment *,
-+ bfd_vma *));
-+static const bfd_target * coff_avr_object_p PARAMS ((bfd *));
-+
-+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
-+/* The page size is a guess based on ELF. */
-+
-+#define COFF_PAGE_SIZE 0x1000
-+
-+/* For some reason when using avr COFF the value stored in the .text
-+ section for a reference to a common symbol is the value itself plus
-+ any desired offset. Ian Taylor, Cygnus Support. */
-+
-+/* If we are producing relocateable output, we need to do some
-+ adjustments to the object file that are not done by the
-+ bfd_perform_relocation function. This function is called by every
-+ reloc type to make any required adjustments. */
-+
-+static bfd_reloc_status_type
-+coff_avr_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
-+ error_message)
-+ bfd *abfd;
-+ arelent *reloc_entry;
-+ asymbol *symbol;
-+ PTR data;
-+ asection *input_section ATTRIBUTE_UNUSED;
-+ bfd *output_bfd;
-+ char **error_message ATTRIBUTE_UNUSED;
-+{
-+ symvalue diff;
-+
-+ if (output_bfd == (bfd *) NULL)
-+ return bfd_reloc_continue;
-+
-+ if (bfd_is_com_section (symbol->section))
-+ {
-+ /* We are relocating a common symbol. The current value in the
-+ object file is ORIG + OFFSET, where ORIG is the value of the
-+ common symbol as seen by the object file when it was compiled
-+ (this may be zero if the symbol was undefined) and OFFSET is
-+ the offset into the common symbol (normally zero, but may be
-+ non-zero when referring to a field in a common structure).
-+ ORIG is the negative of reloc_entry->addend, which is set by
-+ the CALC_ADDEND macro below. We want to replace the value in
-+ the object file with NEW + OFFSET, where NEW is the value of
-+ the common symbol which we are going to put in the final
-+ object file. NEW is symbol->value. */
-+ diff = symbol->value + reloc_entry->addend;
-+ }
-+ else
-+ {
-+ /* For some reason bfd_perform_relocation always effectively
-+ ignores the addend for a COFF target when producing
-+ relocateable output. This seems to be always wrong for 860
-+ COFF, so we handle the addend here instead. */
-+ diff = reloc_entry->addend;
-+ }
-+
-+#define DOIT(x) \
-+ x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
-+
-+ if (diff != 0)
-+ {
-+ reloc_howto_type *howto = reloc_entry->howto;
-+ unsigned char *addr = (unsigned char *) data + reloc_entry->address;
-+
-+ switch (howto->size)
-+ {
-+ case 0:
-+ {
-+ char x = bfd_get_8 (abfd, addr);
-+ DOIT (x);
-+ bfd_put_8 (abfd, x, addr);
-+ }
-+ break;
-+
-+ case 1:
-+ {
-+ short x = bfd_get_16 (abfd, addr);
-+ DOIT (x);
-+ bfd_put_16 (abfd, (bfd_vma) x, addr);
-+ }
-+ break;
-+
-+ case 2:
-+ {
-+ long x = bfd_get_32 (abfd, addr);
-+ DOIT (x);
-+ bfd_put_32 (abfd, (bfd_vma) x, addr);
-+ }
-+ break;
-+
-+ default:
-+ abort ();
-+ }
-+ }
-+
-+ /* Now let bfd_perform_relocation finish everything up. */
-+ return bfd_reloc_continue;
-+}
-+
-+#ifndef PCRELOFFSET
-+#define PCRELOFFSET FALSE
-+#endif
-+
-+static reloc_howto_type howto_table[] =
-+{
-+ EMPTY_HOWTO (0),
-+ EMPTY_HOWTO (1),
-+ EMPTY_HOWTO (2),
-+ EMPTY_HOWTO (3),
-+ EMPTY_HOWTO (4),
-+ EMPTY_HOWTO (5),
-+ HOWTO (R_DIR32, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "dir32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ TRUE), /* pcrel_offset */
-+ /* {7}, */
-+ HOWTO (R_IMAGEBASE, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "rva32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ FALSE), /* pcrel_offset */
-+ EMPTY_HOWTO (010),
-+ EMPTY_HOWTO (011),
-+ EMPTY_HOWTO (012),
-+ EMPTY_HOWTO (013),
-+ EMPTY_HOWTO (014),
-+ EMPTY_HOWTO (015),
-+ EMPTY_HOWTO (016),
-+ HOWTO (R_RELBYTE, /* type */
-+ 0, /* rightshift */
-+ 0, /* size (0 = byte, 1 = short, 2 = long) */
-+ 8, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "8", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x000000ff, /* src_mask */
-+ 0x000000ff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_RELWORD, /* type */
-+ 0, /* rightshift */
-+ 1, /* size (0 = byte, 1 = short, 2 = long) */
-+ 16, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "16", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x0000ffff, /* src_mask */
-+ 0x0000ffff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_RELLONG, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_PCRBYTE, /* type */
-+ 0, /* rightshift */
-+ 0, /* size (0 = byte, 1 = short, 2 = long) */
-+ 8, /* bitsize */
-+ TRUE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_signed, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "DISP8", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x000000ff, /* src_mask */
-+ 0x000000ff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_PCRWORD, /* type */
-+ 0, /* rightshift */
-+ 1, /* size (0 = byte, 1 = short, 2 = long) */
-+ 16, /* bitsize */
-+ TRUE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_signed, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "DISP16", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x0000ffff, /* src_mask */
-+ 0x0000ffff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_PCRLONG, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ TRUE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_signed, /* complain_on_overflow */
-+ coff_avr_reloc, /* special_function */
-+ "DISP32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ PCRELOFFSET) /* pcrel_offset */
-+};
-+
-+/* Turn a howto into a reloc nunmber */
-+
-+#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
-+#define BADMAG(x) AVRBADMAG(x)
-+#define AVR 1 /* Customize coffcode.h */
-+
-+#define RTYPE2HOWTO(cache_ptr, dst) \
-+ (cache_ptr)->howto = howto_table + (dst)->r_type;
-+
-+/* For AVR COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
-+ library. On some other COFF targets STYP_BSS is normally
-+ STYP_NOLOAD. */
-+#define BSS_NOLOAD_IS_SHARED_LIBRARY
-+
-+/* Compute the addend of a reloc. If the reloc is to a common symbol,
-+ the object file contains the value of the common symbol. By the
-+ time this is called, the linker may be using a different symbol
-+ from a different object file with a different value. Therefore, we
-+ hack wildly to locate the original symbol from this file so that we
-+ can make the correct adjustment. This macro sets coffsym to the
-+ symbol from the original file, and uses it to set the addend value
-+ correctly. If this is not a common symbol, the usual addend
-+ calculation is done, except that an additional tweak is needed for
-+ PC relative relocs.
-+ FIXME: This macro refers to symbols and asect; these are from the
-+ calling function, not the macro arguments. */
-+
-+#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
-+ { \
-+ coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
-+ if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
-+ coffsym = (obj_symbols (abfd) \
-+ + (cache_ptr->sym_ptr_ptr - symbols)); \
-+ else if (ptr) \
-+ coffsym = coff_symbol_from (abfd, ptr); \
-+ if (coffsym != (coff_symbol_type *) NULL \
-+ && coffsym->native->u.syment.n_scnum == 0) \
-+ cache_ptr->addend = - coffsym->native->u.syment.n_value; \
-+ else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
-+ && ptr->section != (asection *) NULL) \
-+ cache_ptr->addend = - (ptr->section->vma + ptr->value); \
-+ else \
-+ cache_ptr->addend = 0; \
-+ if (ptr && howto_table[reloc.r_type].pc_relative) \
-+ cache_ptr->addend += asect->vma; \
-+ }
-+
-+/* We use the special COFF backend linker. */
-+#define coff_relocate_section _bfd_coff_generic_relocate_section
-+
-+static reloc_howto_type *
-+coff_avr_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
-+ bfd *abfd ATTRIBUTE_UNUSED;
-+ asection *sec;
-+ struct internal_reloc *rel;
-+ struct coff_link_hash_entry *h;
-+ struct internal_syment *sym;
-+ bfd_vma *addendp;
-+{
-+
-+ reloc_howto_type *howto;
-+
-+ howto = howto_table + rel->r_type;
-+
-+ if (howto->pc_relative)
-+ *addendp += sec->vma;
-+
-+ if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
-+ {
-+ /* This is a common symbol. The section contents include the
-+ size (sym->n_value) as an addend. The relocate_section
-+ function will be adding in the final value of the symbol. We
-+ need to subtract out the current size in order to get the
-+ correct result. */
-+
-+ BFD_ASSERT (h != NULL);
-+
-+ /* I think we *do* want to bypass this. If we don't, I have seen some data
-+ parameters get the wrong relcation address. If I link two versions
-+ with and without this section bypassed and then do a binary comparison,
-+ the addresses which are different can be looked up in the map. The
-+ case in which this section has been bypassed has addresses which correspond
-+ to values I can find in the map. */
-+ *addendp -= sym->n_value;
-+ }
-+
-+ /* If the output symbol is common (in which case this must be a
-+ relocateable link), we need to add in the final size of the
-+ common symbol. */
-+ if (h != NULL && h->root.type == bfd_link_hash_common)
-+ *addendp += h->root.u.c.size;
-+
-+ return howto;
-+}
-+
-+#define coff_rtype_to_howto coff_avr_rtype_to_howto
-+
-+#ifndef bfd_pe_print_pdata
-+#define bfd_pe_print_pdata NULL
-+#endif
-+
-+#include "coffcode.h"
-+
-+static const bfd_target *
-+coff_avr_object_p(a)
-+ bfd *a;
-+{
-+ return coff_object_p (a);
-+}
-+
-+/* Handle all the abominations of AVR COFF:
-+
-+ Generic COFF always uses the D1 slot to indicate the "most
-+ important" derived type, and the D2...Dn slots for decreasing
-+ importance. E. g., a function symbol will always have its DT_FCN
-+ element in D1, an array its DT_ARY (its first DT_ARY in a
-+ multi-dimensional array). In contrast, AVR COFF expects this most
-+ important derived type specifier in the upmost Dn slot that is
-+ allocated at all (i. e. that is != 0).
-+
-+ Generic COFF says that "Any symbol that satisfies more than one
-+ condition [... for AUX entries] should have a union format in its
-+ auxiliary entry." AVR COFF uses sepearate AUX entries for multiple
-+ derived types, and in some cases (like the ISFCN one), even puts
-+ the most important one into the last allocated AUX entry. We
-+ join/split them here at the border as well. Note that when
-+ generating AUX entries (where we need to split them), the n_numaux
-+ field must already have been set up properly (e. g. in
-+ binutils/wrcoff.c) since the entry renumbering and pointerization
-+ would not work otherwise. Thus, we only split the information into
-+ multiple records if n_numaux > 1. For similar reasons, we keep
-+ n_numaux > 1 on input to keep the appropriate AUX entries
-+ allocated, so a symbol can be reconstructed if it is being passed
-+ through one of the GNU tools.
-+
-+ Note that this adjustment is called after the symbol itself has
-+ been swapped in, but before the AUX entries are swapped in. This
-+ is the only hook available that could swap (or merge) AUX entries
-+ at all, so we have to operate on the external AUX entries still. */
-+
-+void
-+avr_coff_adjust_sym_in_post (abfd, ext, in)
-+ bfd *abfd;
-+ PTR ext;
-+ PTR in;
-+{
-+ struct internal_syment *dst = (struct internal_syment *)in;
-+ unsigned short dt, bt, ndt;
-+ dt = dst->n_type & ~N_BTMASK;
-+ bt = BTYPE (dst->n_type);
-+
-+ /* Some AVR COFF producers seem to violate the COFF specs, and
-+ produce symbols for tag names that have the C_FOO filled in
-+ properly, but T_NULL as the base type value. Patch up here,
-+ since some of our generic COFF tools (in particular
-+ binutils/rdcoff.c) rely on the correct data. */
-+ if (bt == T_NULL)
-+ switch (dst->n_sclass)
-+ {
-+ case C_STRTAG:
-+ bt = T_STRUCT;
-+ break;
-+
-+ case C_UNTAG:
-+ bt = T_UNION;
-+ break;
-+
-+ case C_ENTAG:
-+ bt = T_ENUM;
-+ break;
-+ }
-+
-+ /* Swap the derived type slots. */
-+ if (dt != 0)
-+ {
-+ ndt = 0;
-+ while (dt != 0)
-+ {
-+ ndt = (ndt << N_TSHIFT) | (dt & (N_TMASK >> N_BTSHFT));
-+ dt >>= N_TSHIFT;
-+ }
-+ dst->n_type = (ndt << N_BTSHFT) | bt;
-+ }
-+ else
-+ dst->n_type = bt;
-+
-+ /* If the derived type is function, and there is more than one AUX
-+ entry, swap the first and the last AUX entry, so the most
-+ interesting one will become the first.
-+
-+ If the fundamental type is a tagged type (struct/union/enum), try
-+ to find the AUX entry describing the tagged type (the one that
-+ has x_sym.x_tagndx filled in), and merge the tag index into the
-+ first AUX entry. Depending on the actual input file, there might
-+ be further DT_PTR entries which we just ignore, since we could
-+ not handle that information anyway. */
-+ if (dst->n_numaux > 1 && dst->n_sclass != C_FILE)
-+ {
-+ AUXENT caux, *auxp1, *auxp2;
-+ size_t symesz;
-+ unsigned int i;
-+
-+ symesz = bfd_coff_symesz (abfd);
-+ i = dst->n_numaux;
-+
-+ auxp1 = (AUXENT *)((char *)ext + symesz);
-+ auxp2 = (AUXENT *)((char *)ext + i * symesz);
-+
-+ if (ISFCN (dst->n_type)
-+ || (ISPTR(dst->n_type)
-+ && (bt == T_STRUCT || bt == T_UNION || bt == T_ENUM)))
-+ {
-+ caux = *auxp2;
-+ *auxp2 = *auxp1;
-+ *auxp1 = caux;
-+ }
-+ else
-+ caux = *auxp1;
-+
-+ if ((ISFCN (dst->n_type) || ISARY (dst->n_type))
-+ && (bt == T_STRUCT || bt == T_UNION || bt == T_ENUM))
-+ {
-+ while (i > 1)
-+ {
-+ auxp2 = (AUXENT *)((char *)ext + i * symesz);
-+
-+ if (auxp2->x_sym.x_tagndx[0] != 0 || auxp2->x_sym.x_tagndx[1] != 0
-+ || auxp2->x_sym.x_tagndx[2] != 0 || auxp2->x_sym.x_tagndx[3] != 0)
-+ {
-+ memcpy (caux.x_sym.x_tagndx, auxp2->x_sym.x_tagndx,
-+ 4 * sizeof (char));
-+ break;
-+ }
-+ i--;
-+ }
-+ if (i > 1)
-+ *auxp1 = caux;
-+ }
-+ }
-+}
-+
-+/* When exporting an AVR COFF file, just undo all that has been done
-+ above. Again, we are called after the symbol itself has been
-+ swapped out, but before the AUX entries are being written.
-+ Unfortunately, we are only given a pointer to the symbol itself, so
-+ we have to derive the pointer to the respective aux entries from
-+ that address, which is a bit clumsy. */
-+void
-+avr_coff_adjust_sym_out_post (abfd, in, ext)
-+ bfd *abfd;
-+ PTR in;
-+ PTR ext;
-+{
-+ struct internal_syment *src = (struct internal_syment *)(in);
-+ struct external_syment *dst = (struct external_syment *)(ext);
-+ unsigned short dt, bt, ndt;
-+
-+ dt = src->n_type & ~N_BTMASK;
-+ bt = BTYPE (src->n_type);
-+
-+ if (dt != 0)
-+ {
-+ ndt = 0;
-+ while (dt != 0)
-+ {
-+ ndt = (ndt << N_TSHIFT) | (dt & (N_TMASK >> N_BTSHFT));
-+ dt >>= N_TSHIFT;
-+ }
-+ H_PUT_16 (abfd, (ndt << N_BTSHFT) | bt, dst->e_type);
-+ }
-+
-+ if (src->n_numaux > 1 && src->n_sclass != C_FILE)
-+ {
-+ combined_entry_type *srce, *dste;
-+ char *hackp;
-+ unsigned int i;
-+
-+ /* Recover the original combinend_entry_type *. */
-+ hackp = (char *)in;
-+ hackp -= offsetof(combined_entry_type, u.syment);
-+ srce = (combined_entry_type *)hackp;
-+ srce++;
-+
-+ /* We simply duplicate the first AUX entry as many times as
-+ needed. Since COFF itself normally uses just a single AUX
-+ entry for all the information, this will work -- each COFF
-+ consumer will then just pick the fields it is particularly
-+ interested in. This would not work for the AVR COFF specific
-+ DT_PTR AUX entries, but we don't support them anyway. */
-+ for (i = 1; i < src->n_numaux; i++)
-+ {
-+ dste = srce + i;
-+ *dste = *srce;
-+ }
-+ }
-+}
-+
-+const bfd_target
-+#ifdef TARGET_SYM
-+ TARGET_SYM =
-+#else
-+ avrcoff_vec =
-+#endif
-+{
-+#ifdef TARGET_NAME
-+ TARGET_NAME,
-+#else
-+ "coff-avr", /* name */
-+#endif
-+ bfd_target_coff_flavour,
-+ BFD_ENDIAN_LITTLE, /* data byte order is little */
-+ BFD_ENDIAN_LITTLE, /* header byte order is little */
-+
-+ (HAS_RELOC | EXEC_P | /* object flags */
-+ HAS_LINENO | HAS_DEBUG |
-+ HAS_SYMS | HAS_LOCALS | WP_TEXT),
-+
-+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
-+ 0, /* leading char */
-+ '/', /* ar_pad_char */
-+ 15, /* ar_max_namelen */
-+
-+ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
-+ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
-+ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
-+ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
-+ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
-+ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
-+
-+/* Note that we allow an object file to be treated as a core file as well. */
-+ {_bfd_dummy_target, coff_avr_object_p, /* bfd_check_format */
-+ bfd_generic_archive_p, coff_avr_object_p},
-+ {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
-+ bfd_false},
-+ {bfd_false, coff_write_object_contents, /* bfd_write_contents */
-+ _bfd_write_archive_contents, bfd_false},
-+
-+ BFD_JUMP_TABLE_GENERIC (coff),
-+ BFD_JUMP_TABLE_COPY (coff),
-+ BFD_JUMP_TABLE_CORE (_bfd_nocore),
-+ BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
-+ BFD_JUMP_TABLE_SYMBOLS (coff),
-+ BFD_JUMP_TABLE_RELOCS (coff),
-+ BFD_JUMP_TABLE_WRITE (coff),
-+ BFD_JUMP_TABLE_LINK (coff),
-+ BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
-+
-+ NULL,
-+
-+ COFF_SWAP_TABLE
-+};
---- ./bfd/Makefile.am.orig 2008-10-16 15:20:34.000000000 +0200
-+++ ./bfd/Makefile.am 2009-01-06 17:45:34.000000000 +0100
-@@ -208,6 +208,8 @@
- coff-apollo.lo \
- coff-arm.lo \
- coff-aux.lo \
-+ coff-avr.lo \
-+ coff-ext-avr.lo \
- coff-h8300.lo \
- coff-h8500.lo \
- coff-i386.lo \
-@@ -389,6 +391,8 @@
- coff-apollo.c \
- coff-arm.c \
- coff-aux.c \
-+ coff-avr.c \
-+ coff-ext-avr.c \
- coff-h8300.c \
- coff-h8500.c \
- coff-i386.c \
-@@ -988,13 +992,13 @@
- bfdver.h: $(srcdir)/version.h $(srcdir)/Makefile.in
- @echo "creating $@"
- @bfd_version=`echo "$(VERSION)" | sed -e 's/\([^\.]*\)\.*\([^\.]*\)\.*\([^\.]*\)\.*\([^\.]*\)\.*\([^\.]*\).*/\1.00\2.00\3.00\4.00\5/' -e 's/\([^\.]*\)\..*\(..\)\..*\(..\)\..*\(..\)\..*\(..\)$$/\1\2\3\4\5/'` ;\
-- bfd_version_string="\"$(VERSION)\"" ;\
-+ bfd_version_string="\"$(VERSION) + coff-avr-patch (20050630)\"" ;\
- bfd_soversion="$(VERSION)" ;\
- bfd_version_package="\"$(PKGVERSION)\"" ;\
- report_bugs_to="\"$(REPORT_BUGS_TO)\"" ;\
- if test "x$(RELEASE)" = x ; then \
- bfd_version_date=`sed -n -e 's/.*DATE //p' < $(srcdir)/version.h` ;\
-- bfd_version_string="\"$(VERSION).$${bfd_version_date}\"" ;\
-+ bfd_version_string="\"$(VERSION).$${bfd_version_date} + coff-avr-patch (20050630)\"" ;\
- bfd_soversion="$(VERSION).$${bfd_version_date}" ;\
- fi ;\
- sed -e "s,@bfd_version@,$$bfd_version," \
-@@ -1198,6 +1202,12 @@
- $(INCDIR)/coff/internal.h $(INCDIR)/coff/m68k.h $(INCDIR)/coff/external.h \
- coff-m68k.c $(INCDIR)/hashtab.h libcoff.h $(INCDIR)/bfdlink.h \
- coffcode.h coffswap.h
-+coff-avr.lo: coff-avr.c $(INCDIR)/filenames.h $(INCDIR)/coff/avr.h \
-+ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
-+ libcoff.h $(INCDIR)/bfdlink.h coffcode.h coffswap.h
-+coff-ext-avr.lo: coff-ext-avr.c $(INCDIR)/filenames.h $(INCDIR)/coff/avr.h \
-+ $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
-+ libcoff.h $(INCDIR)/bfdlink.h coffcode.h coffswap.h
- coff-h8300.lo: coff-h8300.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \
- $(INCDIR)/bfdlink.h genlink.h $(INCDIR)/coff/h8300.h \
- $(INCDIR)/coff/external.h $(INCDIR)/coff/internal.h \
---- ./bfd/coff-ext-avr.c.orig 2009-01-06 17:45:34.000000000 +0100
-+++ ./bfd/coff-ext-avr.c 2009-01-06 17:45:34.000000000 +0100
-@@ -0,0 +1,428 @@
-+/* BFD back-end for Atmel AVR "extended" COFF files.
-+ Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2003
-+ Free Software Foundation, Inc.
-+ This is mostly the same as avr-coff, except of the presence of the
-+ COFF optional header.
-+
-+This file is part of BFD, the Binary File Descriptor library.
-+
-+This program is free software; you can redistribute it and/or modify
-+it under the terms of the GNU General Public License as published by
-+the Free Software Foundation; either version 2 of the License, or
-+(at your option) any later version.
-+
-+This program is distributed in the hope that it will be useful,
-+but WITHOUT ANY WARRANTY; without even the implied warranty of
-+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-+GNU General Public License for more details.
-+
-+You should have received a copy of the GNU General Public License
-+along with this program; if not, write to the Free Software
-+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-+
-+#include "bfd.h"
-+#include "sysdep.h"
-+#include "libbfd.h"
-+
-+#define AVR_EXT_COFF 1
-+#include "coff/avr.h"
-+
-+#include "coff/internal.h"
-+
-+#include "libcoff.h"
-+
-+static bfd_reloc_status_type coff_ext_avr_reloc
-+ PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
-+static reloc_howto_type *coff_ext_avr_rtype_to_howto
-+ PARAMS ((bfd *, asection *, struct internal_reloc *,
-+ struct coff_link_hash_entry *, struct internal_syment *,
-+ bfd_vma *));
-+static const bfd_target * coff_ext_avr_object_p PARAMS ((bfd *));
-+
-+#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
-+/* The page size is a guess based on ELF. */
-+
-+#define COFF_PAGE_SIZE 0x1000
-+
-+/* For some reason when using avr COFF the value stored in the .text
-+ section for a reference to a common symbol is the value itself plus
-+ any desired offset. Ian Taylor, Cygnus Support. */
-+
-+/* If we are producing relocateable output, we need to do some
-+ adjustments to the object file that are not done by the
-+ bfd_perform_relocation function. This function is called by every
-+ reloc type to make any required adjustments. */
-+
-+static bfd_reloc_status_type
-+coff_ext_avr_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
-+ error_message)
-+ bfd *abfd;
-+ arelent *reloc_entry;
-+ asymbol *symbol;
-+ PTR data;
-+ asection *input_section ATTRIBUTE_UNUSED;
-+ bfd *output_bfd;
-+ char **error_message ATTRIBUTE_UNUSED;
-+{
-+ symvalue diff;
-+
-+ if (output_bfd == (bfd *) NULL)
-+ return bfd_reloc_continue;
-+
-+ if (bfd_is_com_section (symbol->section))
-+ {
-+ /* We are relocating a common symbol. The current value in the
-+ object file is ORIG + OFFSET, where ORIG is the value of the
-+ common symbol as seen by the object file when it was compiled
-+ (this may be zero if the symbol was undefined) and OFFSET is
-+ the offset into the common symbol (normally zero, but may be
-+ non-zero when referring to a field in a common structure).
-+ ORIG is the negative of reloc_entry->addend, which is set by
-+ the CALC_ADDEND macro below. We want to replace the value in
-+ the object file with NEW + OFFSET, where NEW is the value of
-+ the common symbol which we are going to put in the final
-+ object file. NEW is symbol->value. */
-+ diff = symbol->value + reloc_entry->addend;
-+ }
-+ else
-+ {
-+ /* For some reason bfd_perform_relocation always effectively
-+ ignores the addend for a COFF target when producing
-+ relocateable output. This seems to be always wrong for 860
-+ COFF, so we handle the addend here instead. */
-+ diff = reloc_entry->addend;
-+ }
-+
-+#define DOIT(x) \
-+ x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
-+
-+ if (diff != 0)
-+ {
-+ reloc_howto_type *howto = reloc_entry->howto;
-+ unsigned char *addr = (unsigned char *) data + reloc_entry->address;
-+
-+ switch (howto->size)
-+ {
-+ case 0:
-+ {
-+ char x = bfd_get_8 (abfd, addr);
-+ DOIT (x);
-+ bfd_put_8 (abfd, x, addr);
-+ }
-+ break;
-+
-+ case 1:
-+ {
-+ short x = bfd_get_16 (abfd, addr);
-+ DOIT (x);
-+ bfd_put_16 (abfd, (bfd_vma) x, addr);
-+ }
-+ break;
-+
-+ case 2:
-+ {
-+ long x = bfd_get_32 (abfd, addr);
-+ DOIT (x);
-+ bfd_put_32 (abfd, (bfd_vma) x, addr);
-+ }
-+ break;
-+
-+ default:
-+ abort ();
-+ }
-+ }
-+
-+ /* Now let bfd_perform_relocation finish everything up. */
-+ return bfd_reloc_continue;
-+}
-+
-+#ifndef PCRELOFFSET
-+#define PCRELOFFSET FALSE
-+#endif
-+
-+static reloc_howto_type howto_table[] =
-+{
-+ EMPTY_HOWTO (0),
-+ EMPTY_HOWTO (1),
-+ EMPTY_HOWTO (2),
-+ EMPTY_HOWTO (3),
-+ EMPTY_HOWTO (4),
-+ EMPTY_HOWTO (5),
-+ HOWTO (R_DIR32, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "dir32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ TRUE), /* pcrel_offset */
-+ /* {7}, */
-+ HOWTO (R_IMAGEBASE, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "rva32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ FALSE), /* pcrel_offset */
-+ EMPTY_HOWTO (010),
-+ EMPTY_HOWTO (011),
-+ EMPTY_HOWTO (012),
-+ EMPTY_HOWTO (013),
-+ EMPTY_HOWTO (014),
-+ EMPTY_HOWTO (015),
-+ EMPTY_HOWTO (016),
-+ HOWTO (R_RELBYTE, /* type */
-+ 0, /* rightshift */
-+ 0, /* size (0 = byte, 1 = short, 2 = long) */
-+ 8, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "8", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x000000ff, /* src_mask */
-+ 0x000000ff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_RELWORD, /* type */
-+ 0, /* rightshift */
-+ 1, /* size (0 = byte, 1 = short, 2 = long) */
-+ 16, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "16", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x0000ffff, /* src_mask */
-+ 0x0000ffff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_RELLONG, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ FALSE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_bitfield, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_PCRBYTE, /* type */
-+ 0, /* rightshift */
-+ 0, /* size (0 = byte, 1 = short, 2 = long) */
-+ 8, /* bitsize */
-+ TRUE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_signed, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "DISP8", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x000000ff, /* src_mask */
-+ 0x000000ff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_PCRWORD, /* type */
-+ 0, /* rightshift */
-+ 1, /* size (0 = byte, 1 = short, 2 = long) */
-+ 16, /* bitsize */
-+ TRUE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_signed, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "DISP16", /* name */
-+ TRUE, /* partial_inplace */
-+ 0x0000ffff, /* src_mask */
-+ 0x0000ffff, /* dst_mask */
-+ PCRELOFFSET), /* pcrel_offset */
-+ HOWTO (R_PCRLONG, /* type */
-+ 0, /* rightshift */
-+ 2, /* size (0 = byte, 1 = short, 2 = long) */
-+ 32, /* bitsize */
-+ TRUE, /* pc_relative */
-+ 0, /* bitpos */
-+ complain_overflow_signed, /* complain_on_overflow */
-+ coff_ext_avr_reloc, /* special_function */
-+ "DISP32", /* name */
-+ TRUE, /* partial_inplace */
-+ 0xffffffff, /* src_mask */
-+ 0xffffffff, /* dst_mask */
-+ PCRELOFFSET) /* pcrel_offset */
-+};
-+
-+/* Turn a howto into a reloc nunmber */
-+
-+#define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
-+#define BADMAG(x) AVRBADMAG(x)
-+#define AVR 1 /* Customize coffcode.h */
-+
-+#define RTYPE2HOWTO(cache_ptr, dst) \
-+ (cache_ptr)->howto = howto_table + (dst)->r_type;
-+
-+/* For AVR COFF a STYP_NOLOAD | STYP_BSS section is part of a shared
-+ library. On some other COFF targets STYP_BSS is normally
-+ STYP_NOLOAD. */
-+#define BSS_NOLOAD_IS_SHARED_LIBRARY
-+
-+/* Compute the addend of a reloc. If the reloc is to a common symbol,
-+ the object file contains the value of the common symbol. By the
-+ time this is called, the linker may be using a different symbol
-+ from a different object file with a different value. Therefore, we
-+ hack wildly to locate the original symbol from this file so that we
-+ can make the correct adjustment. This macro sets coffsym to the
-+ symbol from the original file, and uses it to set the addend value
-+ correctly. If this is not a common symbol, the usual addend
-+ calculation is done, except that an additional tweak is needed for
-+ PC relative relocs.
-+ FIXME: This macro refers to symbols and asect; these are from the
-+ calling function, not the macro arguments. */
-+
-+#define CALC_ADDEND(abfd, ptr, reloc, cache_ptr) \
-+ { \
-+ coff_symbol_type *coffsym = (coff_symbol_type *) NULL; \
-+ if (ptr && bfd_asymbol_bfd (ptr) != abfd) \
-+ coffsym = (obj_symbols (abfd) \
-+ + (cache_ptr->sym_ptr_ptr - symbols)); \
-+ else if (ptr) \
-+ coffsym = coff_symbol_from (abfd, ptr); \
-+ if (coffsym != (coff_symbol_type *) NULL \
-+ && coffsym->native->u.syment.n_scnum == 0) \
-+ cache_ptr->addend = - coffsym->native->u.syment.n_value; \
-+ else if (ptr && bfd_asymbol_bfd (ptr) == abfd \
-+ && ptr->section != (asection *) NULL) \
-+ cache_ptr->addend = - (ptr->section->vma + ptr->value); \
-+ else \
-+ cache_ptr->addend = 0; \
-+ if (ptr && howto_table[reloc.r_type].pc_relative) \
-+ cache_ptr->addend += asect->vma; \
-+ }
-+
-+/* We use the special COFF backend linker. */
-+#define coff_relocate_section _bfd_coff_generic_relocate_section
-+
-+static reloc_howto_type *
-+coff_ext_avr_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
-+ bfd *abfd ATTRIBUTE_UNUSED;
-+ asection *sec;
-+ struct internal_reloc *rel;
-+ struct coff_link_hash_entry *h;
-+ struct internal_syment *sym;
-+ bfd_vma *addendp;
-+{
-+
-+ reloc_howto_type *howto;
-+
-+ howto = howto_table + rel->r_type;
-+
-+ if (howto->pc_relative)
-+ *addendp += sec->vma;
-+
-+ if (sym != NULL && sym->n_scnum == 0 && sym->n_value != 0)
-+ {
-+ /* This is a common symbol. The section contents include the
-+ size (sym->n_value) as an addend. The relocate_section
-+ function will be adding in the final value of the symbol. We
-+ need to subtract out the current size in order to get the
-+ correct result. */
-+
-+ BFD_ASSERT (h != NULL);
-+
-+ /* I think we *do* want to bypass this. If we don't, I have seen some data
-+ parameters get the wrong relcation address. If I link two versions
-+ with and without this section bypassed and then do a binary comparison,
-+ the addresses which are different can be looked up in the map. The
-+ case in which this section has been bypassed has addresses which correspond
-+ to values I can find in the map. */
-+ *addendp -= sym->n_value;
-+ }
-+
-+ /* If the output symbol is common (in which case this must be a
-+ relocateable link), we need to add in the final size of the
-+ common symbol. */
-+ if (h != NULL && h->root.type == bfd_link_hash_common)
-+ *addendp += h->root.u.c.size;
-+
-+ return howto;
-+}
-+
-+#define coff_rtype_to_howto coff_ext_avr_rtype_to_howto
-+
-+#ifndef bfd_pe_print_pdata
-+#define bfd_pe_print_pdata NULL
-+#endif
-+
-+#include "coffcode.h"
-+
-+static const bfd_target *
-+coff_ext_avr_object_p(a)
-+ bfd *a;
-+{
-+ return coff_object_p (a);
-+}
-+
-+const bfd_target
-+#ifdef TARGET_SYM
-+ TARGET_SYM =
-+#else
-+ avrextcoff_vec =
-+#endif
-+{
-+#ifdef TARGET_NAME
-+ TARGET_NAME,
-+#else
-+ "coff-ext-avr", /* name */
-+#endif
-+ bfd_target_coff_flavour,
-+ BFD_ENDIAN_LITTLE, /* data byte order is little */
-+ BFD_ENDIAN_LITTLE, /* header byte order is little */
-+
-+ (HAS_RELOC | EXEC_P | /* object flags */
-+ HAS_LINENO | HAS_DEBUG |
-+ HAS_SYMS | HAS_LOCALS | WP_TEXT),
-+
-+ (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
-+ 0, /* leading char */
-+ '/', /* ar_pad_char */
-+ 15, /* ar_max_namelen */
-+
-+ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
-+ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
-+ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
-+ bfd_getl64, bfd_getl_signed_64, bfd_putl64,
-+ bfd_getl32, bfd_getl_signed_32, bfd_putl32,
-+ bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
-+
-+/* Note that we allow an object file to be treated as a core file as well. */
-+ {_bfd_dummy_target, coff_ext_avr_object_p, /* bfd_check_format */
-+ bfd_generic_archive_p, coff_ext_avr_object_p},
-+ {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
-+ bfd_false},
-+ {bfd_false, coff_write_object_contents, /* bfd_write_contents */
-+ _bfd_write_archive_contents, bfd_false},
-+
-+ BFD_JUMP_TABLE_GENERIC (coff),
-+ BFD_JUMP_TABLE_COPY (coff),
-+ BFD_JUMP_TABLE_CORE (_bfd_nocore),
-+ BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
-+ BFD_JUMP_TABLE_SYMBOLS (coff),
-+ BFD_JUMP_TABLE_RELOCS (coff),
-+ BFD_JUMP_TABLE_WRITE (coff),
-+ BFD_JUMP_TABLE_LINK (coff),
-+ BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
-+
-+ NULL,
-+
-+ COFF_SWAP_TABLE
-+};
---- ./bfd/coffcode.h.orig 2008-08-05 05:03:46.000000000 +0200
-+++ ./bfd/coffcode.h 2009-01-06 17:45:34.000000000 +0100
-@@ -1,3 +1,4 @@
-+
- /* Support for the generic parts of most COFF variants, for BFD.
- Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-@@ -1777,6 +1778,17 @@
- coff->relocbase = 0;
- coff->local_toc_sym_map = 0;
-
-+ /* These members communicate important constants about the symbol
-+ table to GDB's symbol-reading code. These `constants'
-+ unfortunately vary among coff implementations... */
-+ coff->local_n_btmask = N_BTMASK;
-+ coff->local_n_btshft = N_BTSHFT;
-+ coff->local_n_tmask = N_TMASK;
-+ coff->local_n_tshift = N_TSHIFT;
-+ coff->local_symesz = bfd_coff_symesz (abfd);
-+ coff->local_auxesz = bfd_coff_auxesz (abfd);
-+ coff->local_linesz = bfd_coff_linesz (abfd);
-+
- /* make_abs_section(abfd);*/
-
- return TRUE;
-@@ -1801,17 +1813,6 @@
-
- coff->sym_filepos = internal_f->f_symptr;
-
-- /* These members communicate important constants about the symbol
-- table to GDB's symbol-reading code. These `constants'
-- unfortunately vary among coff implementations... */
-- coff->local_n_btmask = N_BTMASK;
-- coff->local_n_btshft = N_BTSHFT;
-- coff->local_n_tmask = N_TMASK;
-- coff->local_n_tshift = N_TSHIFT;
-- coff->local_symesz = bfd_coff_symesz (abfd);
-- coff->local_auxesz = bfd_coff_auxesz (abfd);
-- coff->local_linesz = bfd_coff_linesz (abfd);
--
- coff->timestamp = internal_f->f_timdat;
-
- obj_raw_syment_count (abfd) =
-@@ -1938,6 +1939,11 @@
- }
- break;
- #endif
-+#ifdef AVRMAGIC
-+ case AVRMAGIC:
-+ arch = bfd_arch_avr;
-+ break;
-+#endif
- #ifdef MC68MAGIC
- case MC68MAGIC:
- case M68MAGIC:
-@@ -2734,6 +2740,13 @@
- return TRUE;
- #endif
-
-+#ifdef AVRMAGIC
-+ case bfd_arch_avr:
-+ *magicp = AVRMAGIC;
-+ return TRUE;
-+ break;
-+#endif
-+
- #ifdef PPCMAGIC
- case bfd_arch_powerpc:
- *magicp = PPCMAGIC;
-@@ -3530,6 +3543,11 @@
- section.s_page = coff_get_section_load_page (current);
- #endif
+diff -Nruw include/coff/internal.h include/coff/internal.h
+--- include/coff/internal.h 2009-09-02 12:51:39.000000000 +0530
++++ include/coff/internal.h 2010-02-10 17:35:58.378349600 +0530
+@@ -646,6 +646,8 @@
-+#ifdef AVR
-+ /* AVR uses s_paddr the way GNU uses s_vaddr, and effectively
-+ ignores s_vaddr. */
-+ section.s_paddr = current->vma;
-+#endif
- #ifdef COFF_WITH_PE
- section.s_paddr = 0;
- #endif
-@@ -3874,6 +3892,17 @@
- internal_a.magic = ZMAGIC;
- #endif
+ };
-+#ifdef AVR
-+ /* a.out is a dummy for non-extended COFF */
-+ internal_a.magic = AVRAOUTMAGIC;
-+ /* Upper nibble of f_flags must be set for historical reasons.
-+ The upper byte remains blank on coff-avr, so undo the F_AR32WR
-+ setting performed above. */
-+ internal_f.f_flags |= F_JUNK;
-+ internal_f.f_flags &= ~F_UNUSED;
-+#define __A_MAGIC_SET__
-+#endif /* AVR */
++#define NAUXENTS 10 /* number of pre-allocated aux entries */
+
- #if defined(PPC_PE)
- #define __A_MAGIC_SET__
- internal_a.magic = IMAGE_NT_OPTIONAL_HDR_MAGIC;
-@@ -3941,8 +3970,16 @@
- #endif
- }
-
-+#ifdef AVR_EXT_COFF
-+ /* Note that we do not set F_PTRINFO because the GNU toolchain
-+ doesn't provide any information about the target of a pointer,
-+ so we cannot derive which section our pointer target would be
-+ in. */
-+ internal_a.vstamp = F_FULLPATHS | F_STRUCTINFO;
-+#else
- /* FIXME: Does anybody ever set this to another value? */
- internal_a.vstamp = 0;
-+#endif
-
- /* Now should write relocs, strings, syms. */
- obj_sym_filepos (abfd) = sym_base;
-@@ -4128,22 +4165,29 @@
- char * buff;
- bfd_size_type amount = bfd_coff_aoutsz (abfd);
-
-- buff = bfd_malloc (amount);
-- if (buff == NULL)
-- return FALSE;
-+ /* Do not attempt to malloc() zero bytes. According to the
-+ C standard, the behaviour is implementation-defined, and
-+ malloc() might return NULL in that case, which would confuse
-+ us to assume an error where it actually isn't. */
-+ if (amount != 0)
-+ {
-+ buff = bfd_malloc (amount);
-+ if (buff == NULL)
-+ return FALSE;
-
-- coff_swap_aouthdr_out (abfd, & internal_a, buff);
-- amount = bfd_bwrite (buff, amount, abfd);
-+ coff_swap_aouthdr_out (abfd, & internal_a, buff);
-+ amount = bfd_bwrite (buff, amount, abfd);
-
-- free (buff);
-+ free (buff);
-
-- if (amount != bfd_coff_aoutsz (abfd))
-- return FALSE;
-+ if (amount != bfd_coff_aoutsz (abfd))
-+ return FALSE;
+ /********************** RELOCATION DIRECTIVES **********************/
- #ifdef COFF_IMAGE_WITH_PE
-- if (! coff_apply_checksum (abfd))
-- return FALSE;
-+ if (! coff_apply_checksum (abfd))
-+ return FALSE;
- #endif
-+ }
- }
- #ifdef RS6000COFF_C
- else
-@@ -4500,6 +4544,10 @@
- /* In PE, 0x69 (105) denotes a weak external symbol. */
- case C_NT_WEAK:
- #endif
-+#ifdef AVR
-+ /* Some AVR COFF compilers handle EXTDEF like EXT. */
-+ case C_EXTDEF: /* external definition */
-+#endif
- switch (coff_classify_symbol (abfd, &src->u.syment))
- {
- case COFF_SYMBOL_GLOBAL:
-@@ -4723,7 +4771,9 @@
- && src->u.syment.n_scnum == 0)
- break;
- /* Fall through. */
-+#if !defined(AVR)
- case C_EXTDEF: /* External definition. */
-+#endif
- case C_ULABEL: /* Undefined label. */
- case C_USTATIC: /* Undefined static. */
- #ifndef COFF_WITH_PE
---- ./bfd/coffswap.h.orig 2007-07-03 16:26:40.000000000 +0200
-+++ ./bfd/coffswap.h 2009-01-06 17:45:34.000000000 +0100
-@@ -383,7 +383,11 @@
- void * ext1,
- int type,
- int class,
-- int indx,
-+ int indx
-+#if defined(AVR) && __GNUC__
-+ __attribute__((unused))
-+#endif
-+ ,
- int numaux,
- void * in1)
- {
-@@ -409,9 +413,13 @@
- #else
- if (numaux > 1)
- {
-+#if defined(AVR)
-+ memcpy (in->x_file.x_fname, ext->x_file.x_fname, sizeof (AUXENT));
-+#else
- if (indx == 0)
- memcpy (in->x_file.x_fname, ext->x_file.x_fname,
- numaux * sizeof (AUXENT));
-+#endif
- }
- else
- memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
+ struct internal_reloc