Index: bfd/archures.c =================================================================== RCS file: /cvs/src/src/bfd/archures.c,v retrieving revision 1.116 diff -U62 -r1.116 archures.c --- bfd/archures.c 6 Mar 2006 13:42:03 -0000 1.116 +++ bfd/archures.c 1 May 2006 19:44:20 -0000 @@ -275,124 +275,125 @@ .#define bfd_mach_arm_iWMMXt 12 . bfd_arch_ns32k, {* National Semiconductors ns32000 *} . bfd_arch_w65, {* WDC 65816 *} . bfd_arch_tic30, {* Texas Instruments TMS320C30 *} . bfd_arch_tic4x, {* Texas Instruments TMS320C3X/4X *} .#define bfd_mach_tic3x 30 .#define bfd_mach_tic4x 40 . bfd_arch_tic54x, {* Texas Instruments TMS320C54X *} . bfd_arch_tic80, {* TI TMS320c80 (MVP) *} . bfd_arch_v850, {* NEC V850 *} .#define bfd_mach_v850 1 .#define bfd_mach_v850e 'E' .#define bfd_mach_v850e1 '1' . bfd_arch_arc, {* ARC Cores *} .#define bfd_mach_arc_5 5 .#define bfd_mach_arc_6 6 .#define bfd_mach_arc_7 7 .#define bfd_mach_arc_8 8 . bfd_arch_m32c, {* Renesas M16C/M32C. *} .#define bfd_mach_m16c 0x75 .#define bfd_mach_m32c 0x78 . bfd_arch_m32r, {* Renesas M32R (formerly Mitsubishi M32R/D) *} .#define bfd_mach_m32r 1 {* For backwards compatibility. *} .#define bfd_mach_m32rx 'x' .#define bfd_mach_m32r2 '2' . bfd_arch_mn10200, {* Matsushita MN10200 *} . bfd_arch_mn10300, {* Matsushita MN10300 *} .#define bfd_mach_mn10300 300 .#define bfd_mach_am33 330 .#define bfd_mach_am33_2 332 . bfd_arch_fr30, .#define bfd_mach_fr30 0x46523330 . bfd_arch_frv, .#define bfd_mach_frv 1 .#define bfd_mach_frvsimple 2 .#define bfd_mach_fr300 300 .#define bfd_mach_fr400 400 .#define bfd_mach_fr450 450 .#define bfd_mach_frvtomcat 499 {* fr500 prototype *} .#define bfd_mach_fr500 500 .#define bfd_mach_fr550 550 . bfd_arch_mcore, . bfd_arch_ia64, {* HP/Intel ia64 *} .#define bfd_mach_ia64_elf64 64 .#define bfd_mach_ia64_elf32 32 . bfd_arch_ip2k, {* Ubicom IP2K microcontrollers. *} .#define bfd_mach_ip2022 1 .#define bfd_mach_ip2022ext 2 . bfd_arch_iq2000, {* Vitesse IQ2000. *} .#define bfd_mach_iq2000 1 .#define bfd_mach_iq10 2 . bfd_arch_mt, .#define bfd_mach_ms1 1 .#define bfd_mach_mrisc2 2 .#define bfd_mach_ms2 3 . bfd_arch_pj, . bfd_arch_avr, {* Atmel AVR microcontrollers. *} .#define bfd_mach_avr1 1 .#define bfd_mach_avr2 2 .#define bfd_mach_avr3 3 .#define bfd_mach_avr4 4 .#define bfd_mach_avr5 5 +.#define bfd_mach_avr6 6 . bfd_arch_bfin, {* ADI Blackfin *} .#define bfd_mach_bfin 1 . bfd_arch_cr16c, {* National Semiconductor CompactRISC. *} .#define bfd_mach_cr16c 1 . bfd_arch_crx, {* National Semiconductor CRX. *} .#define bfd_mach_crx 1 . bfd_arch_cris, {* Axis CRIS *} .#define bfd_mach_cris_v0_v10 255 .#define bfd_mach_cris_v32 32 .#define bfd_mach_cris_v10_v32 1032 . bfd_arch_s390, {* IBM s390 *} .#define bfd_mach_s390_31 31 .#define bfd_mach_s390_64 64 . bfd_arch_openrisc, {* OpenRISC *} . bfd_arch_mmix, {* Donald Knuth's educational processor. *} . bfd_arch_xstormy16, .#define bfd_mach_xstormy16 1 . bfd_arch_msp430, {* Texas Instruments MSP430 architecture. *} .#define bfd_mach_msp11 11 .#define bfd_mach_msp110 110 .#define bfd_mach_msp12 12 .#define bfd_mach_msp13 13 .#define bfd_mach_msp14 14 .#define bfd_mach_msp15 15 .#define bfd_mach_msp16 16 .#define bfd_mach_msp21 21 .#define bfd_mach_msp31 31 .#define bfd_mach_msp32 32 .#define bfd_mach_msp33 33 .#define bfd_mach_msp41 41 .#define bfd_mach_msp42 42 .#define bfd_mach_msp43 43 .#define bfd_mach_msp44 44 . bfd_arch_xc16x, {* Infineon's XC16X Series. *} .#define bfd_mach_xc16x 1 .#define bfd_mach_xc16xl 2 .#define bfd_mach_xc16xs 3 . bfd_arch_xtensa, {* Tensilica's Xtensa cores. *} .#define bfd_mach_xtensa 1 . bfd_arch_maxq, {* Dallas MAXQ 10/20 *} .#define bfd_mach_maxq10 10 .#define bfd_mach_maxq20 20 . bfd_arch_z80, .#define bfd_mach_z80strict 1 {* No undocumented opcodes. *} .#define bfd_mach_z80 3 {* With ixl, ixh, iyl, and iyh. *} .#define bfd_mach_z80full 7 {* All undocumented instructions. *} .#define bfd_mach_r800 11 {* R800: successor with multiplication. *} . bfd_arch_last . }; */ /* SUBSECTION bfd_arch_info DESCRIPTION This structure contains information on architectures for use within BFD. . .typedef struct bfd_arch_info .{ Index: bfd/bfd-in2.h =================================================================== RCS file: /cvs/src/src/bfd/bfd-in2.h,v retrieving revision 1.387 diff -U62 -r1.387 bfd-in2.h --- bfd/bfd-in2.h 26 Mar 2006 00:38:42 -0000 1.387 +++ bfd/bfd-in2.h 1 May 2006 19:44:24 -0000 @@ -1872,124 +1872,125 @@ #define bfd_mach_arm_iWMMXt 12 bfd_arch_ns32k, /* National Semiconductors ns32000 */ bfd_arch_w65, /* WDC 65816 */ bfd_arch_tic30, /* Texas Instruments TMS320C30 */ bfd_arch_tic4x, /* Texas Instruments TMS320C3X/4X */ #define bfd_mach_tic3x 30 #define bfd_mach_tic4x 40 bfd_arch_tic54x, /* Texas Instruments TMS320C54X */ bfd_arch_tic80, /* TI TMS320c80 (MVP) */ bfd_arch_v850, /* NEC V850 */ #define bfd_mach_v850 1 #define bfd_mach_v850e 'E' #define bfd_mach_v850e1 '1' bfd_arch_arc, /* ARC Cores */ #define bfd_mach_arc_5 5 #define bfd_mach_arc_6 6 #define bfd_mach_arc_7 7 #define bfd_mach_arc_8 8 bfd_arch_m32c, /* Renesas M16C/M32C. */ #define bfd_mach_m16c 0x75 #define bfd_mach_m32c 0x78 bfd_arch_m32r, /* Renesas M32R (formerly Mitsubishi M32R/D) */ #define bfd_mach_m32r 1 /* For backwards compatibility. */ #define bfd_mach_m32rx 'x' #define bfd_mach_m32r2 '2' bfd_arch_mn10200, /* Matsushita MN10200 */ bfd_arch_mn10300, /* Matsushita MN10300 */ #define bfd_mach_mn10300 300 #define bfd_mach_am33 330 #define bfd_mach_am33_2 332 bfd_arch_fr30, #define bfd_mach_fr30 0x46523330 bfd_arch_frv, #define bfd_mach_frv 1 #define bfd_mach_frvsimple 2 #define bfd_mach_fr300 300 #define bfd_mach_fr400 400 #define bfd_mach_fr450 450 #define bfd_mach_frvtomcat 499 /* fr500 prototype */ #define bfd_mach_fr500 500 #define bfd_mach_fr550 550 bfd_arch_mcore, bfd_arch_ia64, /* HP/Intel ia64 */ #define bfd_mach_ia64_elf64 64 #define bfd_mach_ia64_elf32 32 bfd_arch_ip2k, /* Ubicom IP2K microcontrollers. */ #define bfd_mach_ip2022 1 #define bfd_mach_ip2022ext 2 bfd_arch_iq2000, /* Vitesse IQ2000. */ #define bfd_mach_iq2000 1 #define bfd_mach_iq10 2 bfd_arch_mt, #define bfd_mach_ms1 1 #define bfd_mach_mrisc2 2 #define bfd_mach_ms2 3 bfd_arch_pj, bfd_arch_avr, /* Atmel AVR microcontrollers. */ #define bfd_mach_avr1 1 #define bfd_mach_avr2 2 #define bfd_mach_avr3 3 #define bfd_mach_avr4 4 #define bfd_mach_avr5 5 +#define bfd_mach_avr6 6 bfd_arch_bfin, /* ADI Blackfin */ #define bfd_mach_bfin 1 bfd_arch_cr16c, /* National Semiconductor CompactRISC. */ #define bfd_mach_cr16c 1 bfd_arch_crx, /* National Semiconductor CRX. */ #define bfd_mach_crx 1 bfd_arch_cris, /* Axis CRIS */ #define bfd_mach_cris_v0_v10 255 #define bfd_mach_cris_v32 32 #define bfd_mach_cris_v10_v32 1032 bfd_arch_s390, /* IBM s390 */ #define bfd_mach_s390_31 31 #define bfd_mach_s390_64 64 bfd_arch_openrisc, /* OpenRISC */ bfd_arch_mmix, /* Donald Knuth's educational processor. */ bfd_arch_xstormy16, #define bfd_mach_xstormy16 1 bfd_arch_msp430, /* Texas Instruments MSP430 architecture. */ #define bfd_mach_msp11 11 #define bfd_mach_msp110 110 #define bfd_mach_msp12 12 #define bfd_mach_msp13 13 #define bfd_mach_msp14 14 #define bfd_mach_msp15 15 #define bfd_mach_msp16 16 #define bfd_mach_msp21 21 #define bfd_mach_msp31 31 #define bfd_mach_msp32 32 #define bfd_mach_msp33 33 #define bfd_mach_msp41 41 #define bfd_mach_msp42 42 #define bfd_mach_msp43 43 #define bfd_mach_msp44 44 bfd_arch_xc16x, /* Infineon's XC16X Series. */ #define bfd_mach_xc16x 1 #define bfd_mach_xc16xl 2 #define bfd_mach_xc16xs 3 bfd_arch_xtensa, /* Tensilica's Xtensa cores. */ #define bfd_mach_xtensa 1 bfd_arch_maxq, /* Dallas MAXQ 10/20 */ #define bfd_mach_maxq10 10 #define bfd_mach_maxq20 20 bfd_arch_z80, #define bfd_mach_z80strict 1 /* No undocumented opcodes. */ #define bfd_mach_z80 3 /* With ixl, ixh, iyl, and iyh. */ #define bfd_mach_z80full 7 /* All undocumented instructions. */ #define bfd_mach_r800 11 /* R800: successor with multiplication. */ bfd_arch_last }; typedef struct bfd_arch_info { int bits_per_word; int bits_per_address; int bits_per_byte; enum bfd_architecture arch; unsigned long mach; const char *arch_name; const char *printable_name; unsigned int section_align_power; /* TRUE if this is the default machine for the architecture. The default arch should be the first entry for an arch so that Index: bfd/cpu-avr.c =================================================================== RCS file: /cvs/src/src/bfd/cpu-avr.c,v retrieving revision 1.9 diff -U62 -r1.9 cpu-avr.c --- bfd/cpu-avr.c 3 Mar 2006 15:54:23 -0000 1.9 +++ bfd/cpu-avr.c 1 May 2006 19:44:24 -0000 @@ -22,68 +22,71 @@ #include "sysdep.h" #include "libbfd.h" /* This routine is provided two arch_infos and works out which AVR machine which would be compatible with both and returns a pointer to its info structure. */ static const bfd_arch_info_type * compatible (const bfd_arch_info_type * a, const bfd_arch_info_type * b) { /* If a & b are for different architectures we can do nothing. */ if (a->arch != b->arch) return NULL; /* Special case for ATmega[16]03 (avr:3) and ATmega83 (avr:4). */ if ((a->mach == bfd_mach_avr3 && b->mach == bfd_mach_avr4) || (a->mach == bfd_mach_avr4 && b->mach == bfd_mach_avr3)) return NULL; /* So far all newer AVR architecture cores are supersets of previous cores. */ if (a->mach <= b->mach) return b; if (a->mach >= b->mach) return a; /* Never reached! */ return NULL; } #define N(addr_bits, machine, print, default, next) \ { \ 8, /* 8 bits in a word. */ \ addr_bits, /* bits in an address. */ \ 8, /* 8 bits in a byte. */ \ bfd_arch_avr, \ machine, /* Machine number. */ \ "avr", /* Architecture name. */ \ print, /* Printable name. */ \ 1, /* Section align power. */ \ default, /* Is this the default ? */ \ compatible, \ bfd_default_scan, \ next \ } static const bfd_arch_info_type arch_info_struct[] = { /* AT90S1200, ATtiny1x, ATtiny28. */ N (16, bfd_mach_avr1, "avr:1", FALSE, & arch_info_struct[1]), /* AT90S2xxx, AT90S4xxx, AT90S8xxx, ATtiny22. */ N (16, bfd_mach_avr2, "avr:2", FALSE, & arch_info_struct[2]), /* ATmega103, ATmega603. */ N (22, bfd_mach_avr3, "avr:3", FALSE, & arch_info_struct[3]), /* ATmega83, ATmega85. */ N (16, bfd_mach_avr4, "avr:4", FALSE, & arch_info_struct[4]), - /* ATmega161, ATmega163, ATmega32, AT94K. */ - N (22, bfd_mach_avr5, "avr:5", FALSE, NULL) + /* ATmegaXXX. */ + N (22, bfd_mach_avr5, "avr:5", FALSE, & arch_info_struct[5]), + + /* ATmega256x. */ + N (22, bfd_mach_avr6, "avr:6", FALSE, NULL) }; const bfd_arch_info_type bfd_avr_arch = N (16, bfd_mach_avr2, "avr", TRUE, & arch_info_struct[0]); Index: bfd/elf32-avr.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-avr.c,v retrieving revision 1.24 diff -U62 -r1.24 elf32-avr.c --- bfd/elf32-avr.c 3 Mar 2006 15:54:23 -0000 1.24 +++ bfd/elf32-avr.c 1 May 2006 19:44:24 -0000 @@ -1,347 +1,531 @@ /* AVR-specific support for 32-bit ELF Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. Contributed by Denis Chertykov 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include "bfd.h" #include "sysdep.h" #include "libbfd.h" #include "elf-bfd.h" #include "elf/avr.h" +#include "elf32-avr.h" +/* Enable debugging printout at stdout with this variable. */ +bfd_boolean debug_relax = FALSE; + +/* Enable debugging printout at stdout with this variable. */ +bfd_boolean debug_stubs = FALSE; + +/* Hash table initialization and handling. Code is taken from the hppa port + and adapted to the needs of avr. */ + +/* We use two hash tables to hold information for linking avr objects. + + The first is the elf32_avr_link_hash_tablse which is derived from the + stanard ELF linker hash table. We use this as a place to attach the other + hash table and some static information. + + The second is the stub hash table which is derived from the base BFD + hash table. The stub hash table holds the information on the linker + stubs. */ + +struct elf32_avr_stub_hash_entry { + /* Base hash table entry structure. */ + struct bfd_hash_entry bh_root; + + /* Offset within stub_sec of the beginning of this stub. */ + bfd_vma stub_offset; + + /* Given the symbol's value and its section we can determine its final + value when building the stubs (so the stub knows where to jump). */ + bfd_vma target_value; + + /* This way we could mark stubs to be no longer necessary. */ + bfd_boolean is_actually_needed; +}; + +struct elf32_avr_link_hash_table { + + /* The main hash table. */ + struct elf_link_hash_table etab; + + /* The stub hash table. */ + struct bfd_hash_table bstab; + + bfd_boolean no_stubs; + + /* Linker stub bfd. */ + bfd *stub_bfd; + /* The stub section. */ + asection *stub_sec; + + /* Usually 0, unless we are generating code for a bootloader. Will + be initialized by elf32_avr_size_stubs to the vma offset of the + output section associated with the stub section. */ + bfd_vma vector_base; + + /* Assorted information used by elf32_avr_size_stubs. */ + unsigned int bfd_count; + int top_index; + asection **input_list; + Elf_Internal_Sym **all_local_syms; + + /* Tables for mapping vma beyond the 128k boundary to the address of the + corresponding stub. (AMT) + "amt_max_entry_cnt" reflects the number of entries that memory is allocated + for in the "amt_stub_offsets" and "amt_destination_addr" arrays. + "amt_entry_cnt" informs how many of these entries actually contain + useful data. */ + unsigned int amt_entry_cnt; + unsigned int amt_max_entry_cnt; + bfd_vma *amt_stub_offsets; + bfd_vma *amt_destination_addr; +}; + +/* Various hash macros and functions. */ +#define avr_link_hash_table(p) \ + ((struct elf32_avr_link_hash_table *) ((p)->hash)) + +#define avr_stub_hash_entry(ent) \ + ((struct elf32_avr_stub_hash_entry *)(ent)) + +#define avr_stub_hash_lookup(table, string, create, copy) \ + ((struct elf32_avr_stub_hash_entry *) \ + bfd_hash_lookup ((table), (string), (create), (copy))) + +/* Initialize an entry in the stub hash table. */ + +static struct bfd_hash_entry * +stub_hash_newfunc (struct bfd_hash_entry *entry, + struct bfd_hash_table *table, + const char *string) +{ + /* Allocate the structure if it has not already been allocated by a + subclass. */ + if (entry == NULL) + { + entry = bfd_hash_allocate (table, + sizeof (struct elf32_avr_stub_hash_entry)); + if (entry == NULL) + return entry; + } + + /* Call the allocation method of the superclass. */ + entry = bfd_hash_newfunc (entry, table, string); + if (entry != NULL) + { + struct elf32_avr_stub_hash_entry *hsh; + + /* Initialize the local fields. */ + hsh = avr_stub_hash_entry (entry); + hsh->stub_offset = 0; + hsh->target_value = 0; + } + + return entry; +} + +/* Create the derived linker hash table. The AVR ELF port uses the derived + hash table to keep information specific to the AVR ELF linker (without + using static variables). */ + +static struct bfd_link_hash_table * +elf32_avr_link_hash_table_create (bfd *abfd) +{ + struct elf32_avr_link_hash_table *htab; + bfd_size_type amt = sizeof (*htab); + + htab = (struct elf32_avr_link_hash_table *) bfd_malloc (amt); + if (htab == NULL) + return NULL; + + if (!_bfd_elf_link_hash_table_init (&htab->etab, abfd, + _bfd_elf_link_hash_newfunc, + sizeof (struct elf_link_hash_entry))) + { + free (htab); + return NULL; + } + + /* Init the stub hash table too. */ + if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc, + sizeof (struct elf32_avr_stub_hash_entry))) + return NULL; + + htab->stub_bfd = NULL; + htab->stub_sec = NULL; + + /* Initialize the address mapping table. */ + htab->amt_stub_offsets = NULL; + htab->amt_destination_addr = NULL; + htab->amt_entry_cnt = 0; + htab->amt_max_entry_cnt = 0; + + return &htab->etab.root; +} + +/* Free the derived linker hash table. */ + +static void +elf32_avr_link_hash_table_free (struct bfd_link_hash_table *btab) +{ + struct elf32_avr_link_hash_table *htab + = (struct elf32_avr_link_hash_table *) btab; + + /* Free the address mapping table. */ + if (htab->amt_stub_offsets != NULL) + free (htab->amt_stub_offsets); + if (htab->amt_destination_addr != NULL) + free (htab->amt_destination_addr); + + bfd_hash_table_free (&htab->bstab); + _bfd_generic_link_hash_table_free (btab); +} + +/* Returns the address of the corresponding stub if there is one. + Returns otherwise an address higher or equal to 0x020000. */ +static bfd_vma +avr_get_stub_addr (bfd_vma srel, + struct elf32_avr_link_hash_table *htab); + + +/* OK, at this point we are through with handling of the hash + tables. */ + + static reloc_howto_type elf_avr_howto_table[] = { HOWTO (R_AVR_NONE, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_NONE", /* name */ FALSE, /* partial_inplace */ 0, /* src_mask */ 0, /* dst_mask */ FALSE), /* pcrel_offset */ HOWTO (R_AVR_32, /* type */ 0, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 32, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_32", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A 7 bit PC relative relocation. */ HOWTO (R_AVR_7_PCREL, /* type */ 1, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 7, /* bitsize */ TRUE, /* pc_relative */ 3, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_7_PCREL", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ TRUE), /* pcrel_offset */ /* A 13 bit PC relative relocation. */ HOWTO (R_AVR_13_PCREL, /* type */ 1, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 13, /* bitsize */ TRUE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_13_PCREL", /* name */ FALSE, /* partial_inplace */ 0xfff, /* src_mask */ 0xfff, /* dst_mask */ TRUE), /* pcrel_offset */ /* A 16 bit absolute relocation. */ HOWTO (R_AVR_16, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_16", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ - - /* A 16 bit absolute relocation for command address. */ + /* A 16 bit absolute relocation for command address. Will not be + changed when linker stubs are needed. */ HOWTO (R_AVR_16_PM, /* type */ 1, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_bitfield, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_16_PM", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A low 8 bit absolute relocation of 16 bit address. For LDI command. */ HOWTO (R_AVR_LO8_LDI, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_LO8_LDI", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A high 8 bit absolute relocation of 16 bit address. For LDI command. */ HOWTO (R_AVR_HI8_LDI, /* type */ 8, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HI8_LDI", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A high 6 bit absolute relocation of 22 bit address. For LDI command. As well second most significant 8 bit value of a 32 bit link-time constant. */ HOWTO (R_AVR_HH8_LDI, /* type */ 16, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HH8_LDI", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A negative low 8 bit absolute relocation of 16 bit address. For LDI command. */ HOWTO (R_AVR_LO8_LDI_NEG, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_LO8_LDI_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A negative high 8 bit absolute relocation of 16 bit address. For LDI command. */ HOWTO (R_AVR_HI8_LDI_NEG, /* type */ 8, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HI8_LDI_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A negative high 6 bit absolute relocation of 22 bit address. For LDI command. */ HOWTO (R_AVR_HH8_LDI_NEG, /* type */ 16, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HH8_LDI_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A low 8 bit absolute relocation of 24 bit program memory address. - For LDI command. */ + For LDI command. Will not be changed when linker stubs are needed. */ HOWTO (R_AVR_LO8_LDI_PM, /* type */ 1, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_LO8_LDI_PM", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ - /* A high 8 bit absolute relocation of 16 bit program memory address. - For LDI command. */ + /* A low 8 bit absolute relocation of 24 bit program memory address. + For LDI command. Will not be changed when linker stubs are needed. */ HOWTO (R_AVR_HI8_LDI_PM, /* type */ 9, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HI8_LDI_PM", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ - /* A high 8 bit absolute relocation of 24 bit program memory address. - For LDI command. */ + /* A low 8 bit absolute relocation of 24 bit program memory address. + For LDI command. Will not be changed when linker stubs are needed. */ HOWTO (R_AVR_HH8_LDI_PM, /* type */ 17, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HH8_LDI_PM", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ - /* A low 8 bit absolute relocation of a negative 24 bit - program memory address. For LDI command. */ + /* A low 8 bit absolute relocation of 24 bit program memory address. + For LDI command. Will not be changed when linker stubs are needed. */ HOWTO (R_AVR_LO8_LDI_PM_NEG, /* type */ 1, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_LO8_LDI_PM_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ - /* A high 8 bit absolute relocation of a negative 16 bit - program memory address. For LDI command. */ + /* A low 8 bit absolute relocation of 24 bit program memory address. + For LDI command. Will not be changed when linker stubs are needed. */ HOWTO (R_AVR_HI8_LDI_PM_NEG, /* type */ 9, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HI8_LDI_PM_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ - /* A high 8 bit absolute relocation of a negative 24 bit - program memory address. For LDI command. */ + /* A low 8 bit absolute relocation of 24 bit program memory address. + For LDI command. Will not be changed when linker stubs are needed. */ HOWTO (R_AVR_HH8_LDI_PM_NEG, /* type */ 17, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_HH8_LDI_PM_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* Relocation for CALL command in ATmega. */ HOWTO (R_AVR_CALL, /* type */ 1, /* rightshift */ 2, /* size (0 = byte, 1 = short, 2 = long) */ 23, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont,/* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_CALL", /* name */ FALSE, /* partial_inplace */ 0xffffffff, /* src_mask */ 0xffffffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A 16 bit absolute relocation of 16 bit address. For LDI command. */ HOWTO (R_AVR_LDI, /* type */ 0, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 16, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont,/* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_LDI", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A 6 bit absolute relocation of 6 bit offset. For ldd/sdd command. */ HOWTO (R_AVR_6, /* type */ 0, /* rightshift */ 0, /* size (0 = byte, 1 = short, 2 = long) */ 6, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont,/* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_6", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* A 6 bit absolute relocation of 6 bit offset. For sbiw/adiw command. */ HOWTO (R_AVR_6_ADIW, /* type */ 0, /* rightshift */ 0, /* size (0 = byte, 1 = short, 2 = long) */ @@ -362,281 +546,304 @@ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_MS8_LDI", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE), /* pcrel_offset */ /* Negative most significant 8 bit value of a 32 bit link-time constant. */ HOWTO (R_AVR_MS8_LDI_NEG, /* type */ 24, /* rightshift */ 1, /* size (0 = byte, 1 = short, 2 = long) */ 8, /* bitsize */ FALSE, /* pc_relative */ 0, /* bitpos */ complain_overflow_dont, /* complain_on_overflow */ bfd_elf_generic_reloc, /* special_function */ "R_AVR_MS8_LDI_NEG", /* name */ FALSE, /* partial_inplace */ 0xffff, /* src_mask */ 0xffff, /* dst_mask */ FALSE) /* pcrel_offset */ }; /* Map BFD reloc types to AVR ELF reloc types. */ struct avr_reloc_map { bfd_reloc_code_real_type bfd_reloc_val; unsigned int elf_reloc_val; }; static const struct avr_reloc_map avr_reloc_map[] = { { BFD_RELOC_NONE, R_AVR_NONE }, { BFD_RELOC_32, R_AVR_32 }, { BFD_RELOC_AVR_7_PCREL, R_AVR_7_PCREL }, { BFD_RELOC_AVR_13_PCREL, R_AVR_13_PCREL }, { BFD_RELOC_16, R_AVR_16 }, { BFD_RELOC_AVR_16_PM, R_AVR_16_PM }, { BFD_RELOC_AVR_LO8_LDI, R_AVR_LO8_LDI}, { BFD_RELOC_AVR_HI8_LDI, R_AVR_HI8_LDI }, { BFD_RELOC_AVR_HH8_LDI, R_AVR_HH8_LDI }, { BFD_RELOC_AVR_MS8_LDI, R_AVR_MS8_LDI }, { BFD_RELOC_AVR_LO8_LDI_NEG, R_AVR_LO8_LDI_NEG }, { BFD_RELOC_AVR_HI8_LDI_NEG, R_AVR_HI8_LDI_NEG }, { BFD_RELOC_AVR_HH8_LDI_NEG, R_AVR_HH8_LDI_NEG }, { BFD_RELOC_AVR_MS8_LDI_NEG, R_AVR_MS8_LDI_NEG }, { BFD_RELOC_AVR_LO8_LDI_PM, R_AVR_LO8_LDI_PM }, { BFD_RELOC_AVR_HI8_LDI_PM, R_AVR_HI8_LDI_PM }, { BFD_RELOC_AVR_HH8_LDI_PM, R_AVR_HH8_LDI_PM }, { BFD_RELOC_AVR_LO8_LDI_PM_NEG, R_AVR_LO8_LDI_PM_NEG }, { BFD_RELOC_AVR_HI8_LDI_PM_NEG, R_AVR_HI8_LDI_PM_NEG }, { BFD_RELOC_AVR_HH8_LDI_PM_NEG, R_AVR_HH8_LDI_PM_NEG }, { BFD_RELOC_AVR_CALL, R_AVR_CALL }, { BFD_RELOC_AVR_LDI, R_AVR_LDI }, { BFD_RELOC_AVR_6, R_AVR_6 }, { BFD_RELOC_AVR_6_ADIW, R_AVR_6_ADIW } }; + + /* Meant to be filled one day with the wrap around address for the specific device. I.e. should get the value 0x4000 for 16k devices, 0x8000 for 32k devices and so on. We initialize it here with a value of 0x1000000 resulting in that we will never suggest a wrap-around jump during relaxation. The logic of the source code later on assumes that in avr_pc_wrap_around one single bit is set. */ -unsigned int avr_pc_wrap_around = 0x10000000; +bfd_vma avr_pc_wrap_around = 0x10000000; + +/* If this variable holds a value different from zero, the linker relaxation + machine will try to optimize call/ret sequences by a single jump + instruction. This option could be switched off by a linker switch*/ +int avr_replace_call_ret_sequences = 1; /* Calculates the effective distance of a pc relative jump/call. */ static int avr_relative_distance_considering_wrap_around (unsigned int distance) { unsigned int wrap_around_mask = avr_pc_wrap_around - 1; int dist_with_wrap_around = distance & wrap_around_mask; if (dist_with_wrap_around > ((int) (avr_pc_wrap_around >> 1))) dist_with_wrap_around -= avr_pc_wrap_around; return dist_with_wrap_around; } - static reloc_howto_type * bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code) { unsigned int i; for (i = 0; i < sizeof (avr_reloc_map) / sizeof (struct avr_reloc_map); i++) { if (avr_reloc_map[i].bfd_reloc_val == code) return &elf_avr_howto_table[avr_reloc_map[i].elf_reloc_val]; } return NULL; } /* Set the howto pointer for an AVR ELF reloc. */ static void avr_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, Elf_Internal_Rela *dst) { unsigned int r_type; r_type = ELF32_R_TYPE (dst->r_info); BFD_ASSERT (r_type < (unsigned int) R_AVR_max); cache_ptr->howto = &elf_avr_howto_table[r_type]; } static asection * elf32_avr_gc_mark_hook (asection *sec, struct bfd_link_info *info ATTRIBUTE_UNUSED, Elf_Internal_Rela *rel, struct elf_link_hash_entry *h, Elf_Internal_Sym *sym) { if (h != NULL) { switch (ELF32_R_TYPE (rel->r_info)) { default: switch (h->root.type) { case bfd_link_hash_defined: case bfd_link_hash_defweak: return h->root.u.def.section; case bfd_link_hash_common: return h->root.u.c.p->section; default: break; } } } else return bfd_section_from_elf_index (sec->owner, sym->st_shndx); return NULL; } static bfd_boolean elf32_avr_gc_sweep_hook (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *info ATTRIBUTE_UNUSED, asection *sec ATTRIBUTE_UNUSED, const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED) { /* We don't use got and plt entries for avr. */ return TRUE; } /* Look through the relocs for a section during the first phase. Since we don't do .gots or .plts, we just need to consider the virtual table relocs for gc. */ static bfd_boolean elf32_avr_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, const Elf_Internal_Rela *relocs) { Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; const Elf_Internal_Rela *rel; const Elf_Internal_Rela *rel_end; if (info->relocatable) return TRUE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); if (!elf_bad_symtab (abfd)) sym_hashes_end -= symtab_hdr->sh_info; rel_end = relocs + sec->reloc_count; for (rel = relocs; rel < rel_end; rel++) { struct elf_link_hash_entry *h; unsigned long r_symndx; r_symndx = ELF32_R_SYM (rel->r_info); if (r_symndx < symtab_hdr->sh_info) h = NULL; else { h = sym_hashes[r_symndx - symtab_hdr->sh_info]; while (h->root.type == bfd_link_hash_indirect || h->root.type == bfd_link_hash_warning) h = (struct elf_link_hash_entry *) h->root.u.i.link; } } return TRUE; } +static bfd_boolean +avr_stub_is_required_for_16_bit_reloc (bfd_vma relocation) +{ + return (relocation >= 0x020000); +} + /* Perform a single relocation. By default we use the standard BFD routines, but a few relocs, we have to do them ourselves. */ static bfd_reloc_status_type avr_final_link_relocate (reloc_howto_type * howto, - bfd * input_bfd, - asection * input_section, - bfd_byte * contents, - Elf_Internal_Rela * rel, - bfd_vma relocation) + bfd * input_bfd, + asection * input_section, + bfd_byte * contents, + Elf_Internal_Rela * rel, + bfd_vma relocation, + struct elf32_avr_link_hash_table *htab) { bfd_reloc_status_type r = bfd_reloc_ok; bfd_vma x; bfd_signed_vma srel; + bfd_signed_vma reloc_addr; + + bfd_boolean use_stubs = FALSE; + + /* Usually is 0, unless we are generating code for a bootloader. */ + bfd_signed_vma base_addr = htab->vector_base; + + /* Absolute addr of the reloc in the final excecutable. */ + reloc_addr = rel->r_offset + input_section->output_section->vma + + input_section->output_offset; switch (howto->type) { case R_AVR_7_PCREL: contents += rel->r_offset; srel = (bfd_signed_vma) relocation; srel += rel->r_addend; srel -= rel->r_offset; srel -= 2; /* Branch instructions add 2 to the PC... */ srel -= (input_section->output_section->vma + input_section->output_offset); if (srel & 1) return bfd_reloc_outofrange; if (srel > ((1 << 7) - 1) || (srel < - (1 << 7))) return bfd_reloc_overflow; x = bfd_get_16 (input_bfd, contents); x = (x & 0xfc07) | (((srel >> 1) << 3) & 0x3f8); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_13_PCREL: contents += rel->r_offset; srel = (bfd_signed_vma) relocation; srel += rel->r_addend; srel -= rel->r_offset; srel -= 2; /* Branch instructions add 2 to the PC... */ srel -= (input_section->output_section->vma + input_section->output_offset); if (srel & 1) return bfd_reloc_outofrange; srel = avr_relative_distance_considering_wrap_around (srel); /* AVR addresses commands as words. */ srel >>= 1; /* Check for overflow. */ if (srel < -2048 || srel > 2047) { /* Relative distance is too large. */ /* Always apply WRAPAROUND for avr2 and avr4. */ switch (bfd_get_mach (input_bfd)) { case bfd_mach_avr2: case bfd_mach_avr4: break; default: return bfd_reloc_overflow; } } x = bfd_get_16 (input_bfd, contents); x = (x & 0xf000) | (srel & 0xfff); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_LO8_LDI: contents += rel->r_offset; @@ -690,630 +897,795 @@ x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HH8_LDI: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = (srel >> 16) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_MS8_LDI: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = (srel >> 24) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_LO8_LDI_NEG: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = -srel; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HI8_LDI_NEG: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = -srel; srel = (srel >> 8) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HH8_LDI_NEG: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = -srel; srel = (srel >> 16) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_MS8_LDI_NEG: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = -srel; srel = (srel >> 24) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_LO8_LDI_PM: + use_stubs = (!htab->no_stubs); + contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; + + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + { + bfd_vma old_srel = srel; + /* We need to use the address of the stub instead. */ + srel = avr_get_stub_addr (srel,htab); + if (debug_stubs) + printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for " + "reloc at address 0x%x.\n", + (unsigned int) srel, + (unsigned int) old_srel, + (unsigned int) reloc_addr); + } + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + return bfd_reloc_outofrange; if (srel & 1) return bfd_reloc_outofrange; + srel = srel >> 1; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HI8_LDI_PM: + use_stubs = (!htab->no_stubs); contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; + + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + { + bfd_vma old_srel = srel; + /* We need to use the address of the stub instead. */ + srel = avr_get_stub_addr (srel,htab); + if (debug_stubs) + printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for " + "reloc at address 0x%x.\n", + (unsigned int) srel, + (unsigned int) old_srel, + (unsigned int) reloc_addr); + } + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + return bfd_reloc_outofrange; if (srel & 1) return bfd_reloc_outofrange; + srel = srel >> 1; srel = (srel >> 8) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HH8_LDI_PM: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; if (srel & 1) return bfd_reloc_outofrange; srel = srel >> 1; srel = (srel >> 16) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_LO8_LDI_PM_NEG: + use_stubs = (!htab->no_stubs); contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; + + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + { + bfd_vma old_srel = srel; + /* We need to use the address of the stub instead. */ + srel = avr_get_stub_addr (srel,htab); + if (debug_stubs) + printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for " + "reloc at address 0x%x.\n", + (unsigned int) srel, + (unsigned int) old_srel, + (unsigned int) reloc_addr); + } + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + return bfd_reloc_outofrange; + srel = -srel; if (srel & 1) return bfd_reloc_outofrange; srel = srel >> 1; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HI8_LDI_PM_NEG: + use_stubs = (!htab->no_stubs); contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; + + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + { + bfd_vma old_srel = srel; + /* We need to use the address of the stub instead. */ + srel = avr_get_stub_addr (srel,htab); + if (debug_stubs) + printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for " + "reloc at address 0x%x.\n", + (unsigned int) srel, + (unsigned int) old_srel, + (unsigned int) reloc_addr); + } + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + return bfd_reloc_outofrange; + srel = -srel; if (srel & 1) return bfd_reloc_outofrange; srel = srel >> 1; srel = (srel >> 8) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_HH8_LDI_PM_NEG: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; srel = -srel; if (srel & 1) return bfd_reloc_outofrange; srel = srel >> 1; srel = (srel >> 16) & 0xff; x = bfd_get_16 (input_bfd, contents); x = (x & 0xf0f0) | (srel & 0xf) | ((srel << 4) & 0xf00); bfd_put_16 (input_bfd, x, contents); break; case R_AVR_CALL: contents += rel->r_offset; srel = (bfd_signed_vma) relocation + rel->r_addend; if (srel & 1) return bfd_reloc_outofrange; srel = srel >> 1; x = bfd_get_16 (input_bfd, contents); x |= ((srel & 0x10000) | ((srel << 3) & 0x1f00000)) >> 16; bfd_put_16 (input_bfd, x, contents); bfd_put_16 (input_bfd, (bfd_vma) srel & 0xffff, contents+2); break; + case R_AVR_16_PM: + use_stubs = (!htab->no_stubs); + contents += rel->r_offset; + srel = (bfd_signed_vma) relocation + rel->r_addend; + + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + { + bfd_vma old_srel = srel; + /* We need to use the address of the stub instead. */ + srel = avr_get_stub_addr (srel,htab); + if (debug_stubs) + printf ("LD: Using jump stub (at 0x%x) with destination 0x%x for " + "reloc at address 0x%x.\n", + (unsigned int) srel, + (unsigned int) old_srel, + (unsigned int) reloc_addr); + } + if (use_stubs + && avr_stub_is_required_for_16_bit_reloc (srel - base_addr)) + return bfd_reloc_outofrange; + if (srel & 1) + return bfd_reloc_outofrange; + + srel = srel >> 1; + bfd_put_16 (input_bfd, (bfd_vma) srel &0x00ffff, contents); + break; + default: r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents, rel->r_offset, relocation, rel->r_addend); } return r; } /* Relocate an AVR ELF section. */ static bfd_boolean elf32_avr_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, struct bfd_link_info *info, bfd *input_bfd, asection *input_section, bfd_byte *contents, Elf_Internal_Rela *relocs, Elf_Internal_Sym *local_syms, asection **local_sections) { Elf_Internal_Shdr * symtab_hdr; struct elf_link_hash_entry ** sym_hashes; Elf_Internal_Rela * rel; Elf_Internal_Rela * relend; + struct elf32_avr_link_hash_table *htab = avr_link_hash_table (info); if (info->relocatable) return TRUE; symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; sym_hashes = elf_sym_hashes (input_bfd); relend = relocs + input_section->reloc_count; for (rel = relocs; rel < relend; rel ++) { reloc_howto_type * howto; unsigned long r_symndx; Elf_Internal_Sym * sym; asection * sec; struct elf_link_hash_entry * h; bfd_vma relocation; bfd_reloc_status_type r; const char * name; int r_type; /* This is a final link. */ r_type = ELF32_R_TYPE (rel->r_info); r_symndx = ELF32_R_SYM (rel->r_info); howto = elf_avr_howto_table + ELF32_R_TYPE (rel->r_info); h = NULL; sym = NULL; sec = NULL; if (r_symndx < symtab_hdr->sh_info) { sym = local_syms + r_symndx; sec = local_sections [r_symndx]; relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); name = bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name); name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name; } else { bfd_boolean unresolved_reloc, warned; RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, r_symndx, symtab_hdr, sym_hashes, h, sec, relocation, unresolved_reloc, warned); name = h->root.root.string; } r = avr_final_link_relocate (howto, input_bfd, input_section, - contents, rel, relocation); + contents, rel, relocation, htab); if (r != bfd_reloc_ok) { const char * msg = (const char *) NULL; switch (r) { case bfd_reloc_overflow: r = info->callbacks->reloc_overflow (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0, input_bfd, input_section, rel->r_offset); break; case bfd_reloc_undefined: r = info->callbacks->undefined_symbol (info, name, input_bfd, input_section, rel->r_offset, TRUE); break; case bfd_reloc_outofrange: msg = _("internal error: out of range error"); break; case bfd_reloc_notsupported: msg = _("internal error: unsupported relocation error"); break; case bfd_reloc_dangerous: msg = _("internal error: dangerous relocation"); break; default: msg = _("internal error: unknown error"); break; } if (msg) r = info->callbacks->warning (info, msg, name, input_bfd, input_section, rel->r_offset); if (! r) return FALSE; } } return TRUE; } /* The final processing done just before writing out a AVR ELF object file. This gets the AVR architecture right based on the machine number. */ static void bfd_elf_avr_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) { unsigned long val; switch (bfd_get_mach (abfd)) { default: case bfd_mach_avr2: val = E_AVR_MACH_AVR2; break; case bfd_mach_avr1: val = E_AVR_MACH_AVR1; break; case bfd_mach_avr3: val = E_AVR_MACH_AVR3; break; case bfd_mach_avr4: val = E_AVR_MACH_AVR4; break; case bfd_mach_avr5: val = E_AVR_MACH_AVR5; break; + + case bfd_mach_avr6: + val = E_AVR_MACH_AVR6; + break; } elf_elfheader (abfd)->e_machine = EM_AVR; elf_elfheader (abfd)->e_flags &= ~ EF_AVR_MACH; elf_elfheader (abfd)->e_flags |= val; elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED; } /* Set the right machine number. */ static bfd_boolean elf32_avr_object_p (bfd *abfd) { unsigned int e_set = bfd_mach_avr2; if (elf_elfheader (abfd)->e_machine == EM_AVR || elf_elfheader (abfd)->e_machine == EM_AVR_OLD) { int e_mach = elf_elfheader (abfd)->e_flags & EF_AVR_MACH; switch (e_mach) { default: case E_AVR_MACH_AVR2: e_set = bfd_mach_avr2; break; case E_AVR_MACH_AVR1: e_set = bfd_mach_avr1; break; case E_AVR_MACH_AVR3: e_set = bfd_mach_avr3; break; case E_AVR_MACH_AVR4: e_set = bfd_mach_avr4; break; case E_AVR_MACH_AVR5: e_set = bfd_mach_avr5; break; + + case E_AVR_MACH_AVR6: + e_set = bfd_mach_avr6; + break; } } return bfd_default_set_arch_mach (abfd, bfd_arch_avr, e_set); } -/* Enable debugging printout at stdout with a value of 1. */ -#define DEBUG_RELAX 0 - /* Delete some bytes from a section while changing the size of an instruction. The parameter "addr" denotes the section-relative offset pointing just behind the shrinked instruction. "addr+count" point at the first byte just behind the original unshrinked instruction. */ static bfd_boolean elf32_avr_relax_delete_bytes (bfd *abfd, - asection *sec, + asection *sec, bfd_vma addr, - int count) + int count) { Elf_Internal_Shdr *symtab_hdr; unsigned int sec_shndx; bfd_byte *contents; Elf_Internal_Rela *irel, *irelend; Elf_Internal_Rela *irelalign; Elf_Internal_Sym *isym; Elf_Internal_Sym *isymbuf = NULL; Elf_Internal_Sym *isymend; bfd_vma toaddr; struct elf_link_hash_entry **sym_hashes; struct elf_link_hash_entry **end_hashes; unsigned int symcount; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); contents = elf_section_data (sec)->this_hdr.contents; /* The deletion must stop at the next ALIGN reloc for an aligment power larger than the number of bytes we are deleting. */ irelalign = NULL; toaddr = sec->size; irel = elf_section_data (sec)->relocs; irelend = irel + sec->reloc_count; /* Actually delete the bytes. */ if (toaddr - addr - count > 0) memmove (contents + addr, contents + addr + count, (size_t) (toaddr - addr - count)); sec->size -= count; - /* Adjust all the relocs. */ + /* Adjust all the reloc addresses. */ for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++) { - bfd_vma symval; bfd_vma old_reloc_address; bfd_vma shrinked_insn_address; old_reloc_address = (sec->output_section->vma + sec->output_offset + irel->r_offset); shrinked_insn_address = (sec->output_section->vma + sec->output_offset + addr - count); /* Get the new reloc address. */ if ((irel->r_offset > addr && irel->r_offset < toaddr)) { - if (DEBUG_RELAX) + if (debug_relax) printf ("Relocation at address 0x%x needs to be moved.\n" "Old section offset: 0x%x, New section offset: 0x%x \n", (unsigned int) old_reloc_address, (unsigned int) irel->r_offset, (unsigned int) ((irel->r_offset) - count)); irel->r_offset -= count; } - /* The reloc's own addresses are now ok. However, we need to readjust - the reloc's addend if two conditions are met: - 1.) the reloc is relative to a symbol in this section that - is located in front of the shrinked instruction - 2.) symbol plus addend end up behind the shrinked instruction. - - This should happen only for local symbols that are progmem related. */ - - /* Read this BFD's local symbols if we haven't done so already. */ - if (isymbuf == NULL && symtab_hdr->sh_info != 0) - { - isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; - if (isymbuf == NULL) - isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, - symtab_hdr->sh_info, 0, - NULL, NULL, NULL); - if (isymbuf == NULL) - return FALSE; - } - - /* Get the value of the symbol referred to by the reloc. */ - if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) - { - /* A local symbol. */ - Elf_Internal_Sym *isym; - asection *sym_sec; - - isym = isymbuf + ELF32_R_SYM (irel->r_info); - sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); - symval = isym->st_value; - /* If the reloc is absolute, it will not have - a symbol or section associated with it. */ - if (sym_sec) - { - symval += sym_sec->output_section->vma - + sym_sec->output_offset; - - if (DEBUG_RELAX) - printf ("Checking if the relocation's " - "addend needs corrections.\n" - "Address of anchor symbol: 0x%x \n" - "Address of relocation target: 0x%x \n" - "Address of relaxed insn: 0x%x \n", - (unsigned int) symval, - (unsigned int) (symval + irel->r_addend), - (unsigned int) shrinked_insn_address); + } - if (symval <= shrinked_insn_address - && (symval + irel->r_addend) > shrinked_insn_address) + /* The reloc's own addresses are now ok. However, we need to readjust + the reloc's addend, i.e. the reloc's value if two conditions are met: + 1.) the reloc is relative to a symbol in this section that + is located in front of the shrinked instruction + 2.) symbol plus addend end up behind the shrinked instruction. + + The most common case where this happens are relocs relative to + the section-start symbol. + + This step needs to be done for all of the sections of the bfd. */ + + { + struct bfd_section *isec; + for (isec = abfd->sections; isec; isec = isec->next) + { + bfd_vma symval; + bfd_vma shrinked_insn_address; + + shrinked_insn_address = (sec->output_section->vma + + sec->output_offset + addr - count); + + irelend = elf_section_data (isec)->relocs + isec->reloc_count; + for (irel = elf_section_data (isec)->relocs; + irel < irelend; + irel++) + { + /* Read this BFD's local symbols if we haven't done + so already. */ + if (isymbuf == NULL && symtab_hdr->sh_info != 0) + { + isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; + if (isymbuf == NULL) + isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, + symtab_hdr->sh_info, 0, + NULL, NULL, NULL); + if (isymbuf == NULL) + return FALSE; + } + + /* Get the value of the symbol referred to by the reloc. */ + if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) + { + /* A local symbol. */ + Elf_Internal_Sym *isym; + asection *sym_sec; + + isym = isymbuf + ELF32_R_SYM (irel->r_info); + sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); + symval = isym->st_value; + /* If the reloc is absolute, it will not have + a symbol or section associated with it. */ + if (sym_sec == sec) + { + symval += sym_sec->output_section->vma + + sym_sec->output_offset; + + if (debug_relax) + printf ("Checking if the relocation's " + "addend needs corrections.\n" + "Address of anchor symbol: 0x%x \n" + "Address of relocation target: 0x%x \n" + "Address of relaxed insn: 0x%x \n", + (unsigned int) symval, + (unsigned int) (symval + irel->r_addend), + (unsigned int) shrinked_insn_address); + + if (symval <= shrinked_insn_address + && (symval + irel->r_addend) > shrinked_insn_address) + { + irel->r_addend -= count; + + if (debug_relax) + printf ("Relocation's addend needed to be fixed \n"); + } + } + else { - irel->r_addend -= count; - - if (DEBUG_RELAX) - printf ("Anchor symbol and relocation target bracket " - "shrinked insn address.\n" - "Need for new addend : 0x%x\n", - (unsigned int) irel->r_addend); + /* Reference symbol is absolute. No adjustment needed. */ } - } - /* else ... Reference symbol is absolute. No adjustment needed. */ - } - /* else ... Reference symbol is extern. No need for adjusting the addend. */ - } + } + else + { + /* Reference symbol is extern. No need for adjusting + the addend. */ + } + } + } + } /* Adjust the local symbols defined in this section. */ isym = (Elf_Internal_Sym *) symtab_hdr->contents; isymend = isym + symtab_hdr->sh_info; for (; isym < isymend; isym++) { if (isym->st_shndx == sec_shndx && isym->st_value > addr && isym->st_value < toaddr) isym->st_value -= count; } /* Now adjust the global symbols defined in this section. */ symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) - symtab_hdr->sh_info); sym_hashes = elf_sym_hashes (abfd); end_hashes = sym_hashes + symcount; for (; sym_hashes < end_hashes; sym_hashes++) { struct elf_link_hash_entry *sym_hash = *sym_hashes; if ((sym_hash->root.type == bfd_link_hash_defined || sym_hash->root.type == bfd_link_hash_defweak) && sym_hash->root.u.def.section == sec && sym_hash->root.u.def.value > addr && sym_hash->root.u.def.value < toaddr) { sym_hash->root.u.def.value -= count; } } return TRUE; } /* This function handles relaxing for the avr. Many important relaxing opportunities within functions are already realized by the compiler itself. Here we try to replace call (4 bytes) -> rcall (2 bytes) and jump -> rjmp (safes also 2 bytes). As well we now optimize seqences of - call/rcall function - ret to yield - jmp/rjmp function - ret . In case that within a sequence - jmp/rjmp label - ret the ret could no longer be reached it is optimized away. In order to check if the ret is no longer needed, it is checked that the ret's address is not the target of a branch or jump within the same section, it is checked that there is no skip instruction before the jmp/rjmp and that there is no local or global label place at the address of the ret. We refrain from relaxing within sections ".vectors" and ".jumptables" in order to maintain the position of the instructions. There, however, we substitute jmp/call by a sequence rjmp,nop/rcall,nop if possible. (In future one could possibly use the space of the nop for the first instruction of the irq service function. The .jumptables sections is meant to be used for a future tablejump variant for the devices with 3-byte program counter where the table itself contains 4-byte jump instructions whose relative offset must not be changed. */ -static bfd_boolean +static bfd_boolean elf32_avr_relax_section (bfd *abfd, asection *sec, struct bfd_link_info *link_info, bfd_boolean *again) { Elf_Internal_Shdr *symtab_hdr; Elf_Internal_Rela *internal_relocs; Elf_Internal_Rela *irel, *irelend; bfd_byte *contents = NULL; Elf_Internal_Sym *isymbuf = NULL; static asection *last_input_section = NULL; static Elf_Internal_Rela *last_reloc = NULL; + struct elf32_avr_link_hash_table *htab; + + htab = avr_link_hash_table (link_info); /* Assume nothing changes. */ *again = FALSE; + if (sec == htab->stub_sec) + { + + /* We are just relaxing the stub section. Let's again calculate + the size needed. */ + bfd_size_type last_estimated_stub_section_size = htab->stub_sec->size; + + if (debug_relax) + printf ("Relaxing the stub section. Size prior to this pass: %i\n", + (int) last_estimated_stub_section_size); + + elf32_avr_size_stubs (htab->stub_sec->output_section->owner, + link_info, FALSE); + + /* Check if the number of trampolines changed. */ + if (last_estimated_stub_section_size != htab->stub_sec->size) + *again = TRUE; + + if (debug_relax) + printf ("Size of stub section after this pass: %i\n", + (int) htab->stub_sec->size); + + return TRUE; + } + /* We don't have to do anything for a relocatable link, if this section does not have relocs, or if this is not a code section. */ if (link_info->relocatable || (sec->flags & SEC_RELOC) == 0 || sec->reloc_count == 0 || (sec->flags & SEC_CODE) == 0) return TRUE; /* Check if the object file to relax uses internal symbols so that we could fix up the relocations. */ if (!(elf_elfheader (abfd)->e_flags & EF_AVR_LINKRELAX_PREPARED)) return TRUE; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; /* Get a copy of the native relocations. */ internal_relocs = (_bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory)); if (internal_relocs == NULL) goto error_return; if (sec != last_input_section) last_reloc = NULL; last_input_section = sec; /* Walk through the relocs looking for relaxing opportunities. */ irelend = internal_relocs + sec->reloc_count; for (irel = internal_relocs; irel < irelend; irel++) { bfd_vma symval; if ( ELF32_R_TYPE (irel->r_info) != R_AVR_13_PCREL && ELF32_R_TYPE (irel->r_info) != R_AVR_7_PCREL && ELF32_R_TYPE (irel->r_info) != R_AVR_CALL) continue; /* Get the section contents if we haven't done so already. */ if (contents == NULL) { /* Get cached copy if it exists. */ if (elf_section_data (sec)->this_hdr.contents != NULL) contents = elf_section_data (sec)->this_hdr.contents; else { /* Go get them off disk. */ if (! bfd_malloc_and_get_section (abfd, sec, &contents)) goto error_return; } } /* Read this BFD's local symbols if we haven't done so already. */ if (isymbuf == NULL && symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) goto error_return; @@ -1362,488 +1734,491 @@ must tell the rest of the code not to free up this information. It would be possible to instead create a table of changes which have to be made, as is done in coff-mips.c; that would be more work, but would require less memory when the linker is run. */ switch (ELF32_R_TYPE (irel->r_info)) { /* Try to turn a 22-bit absolute call/jump into an 13-bit pc-relative rcall/rjmp. */ case R_AVR_CALL: { bfd_vma value = symval + irel->r_addend; bfd_vma dot, gap; int distance_short_enough = 0; /* Get the address of this instruction. */ dot = (sec->output_section->vma + sec->output_offset + irel->r_offset); /* Compute the distance from this insn to the branch target. */ gap = value - dot; /* If the distance is within -4094..+4098 inclusive, then we can relax this jump/call. +4098 because the call/jump target will be closer after the relaxation. */ if ((int) gap >= -4094 && (int) gap <= 4098) distance_short_enough = 1; /* Here we handle the wrap-around case. E.g. for a 16k device we could use a rjmp to jump from address 0x100 to 0x3d00! In order to make this work properly, we need to fill the vaiable avr_pc_wrap_around with the appropriate value. I.e. 0x4000 for a 16k device. */ { /* Shrinking the code size makes the gaps larger in the case of wrap-arounds. So we use a heuristical safety margin to avoid that during relax the distance gets again too large for the short jumps. Let's assume a typical code-size reduction due to relax for a 16k device of 600 bytes. So let's use twice the typical value as safety margin. */ int rgap; int safety_margin; int assumed_shrink = 600; if (avr_pc_wrap_around > 0x4000) assumed_shrink = 900; safety_margin = 2 * assumed_shrink; rgap = avr_relative_distance_considering_wrap_around (gap); if (rgap >= (-4092 + safety_margin) && rgap <= (4094 - safety_margin)) distance_short_enough = 1; } if (distance_short_enough) { unsigned char code_msb; unsigned char code_lsb; - if (DEBUG_RELAX) + if (debug_relax) printf ("shrinking jump/call instruction at address 0x%x" " in section %s\n\n", (int) dot, sec->name); /* Note that we've changed the relocs, section contents, etc. */ elf_section_data (sec)->relocs = internal_relocs; elf_section_data (sec)->this_hdr.contents = contents; symtab_hdr->contents = (unsigned char *) isymbuf; /* Get the instruction code for relaxing. */ code_lsb = bfd_get_8 (abfd, contents + irel->r_offset); code_msb = bfd_get_8 (abfd, contents + irel->r_offset + 1); /* Mask out the relocation bits. */ code_msb &= 0x94; code_lsb &= 0x0E; if (code_msb == 0x94 && code_lsb == 0x0E) { /* we are changing call -> rcall . */ bfd_put_8 (abfd, 0x00, contents + irel->r_offset); bfd_put_8 (abfd, 0xD0, contents + irel->r_offset + 1); } else if (code_msb == 0x94 && code_lsb == 0x0C) { /* we are changeing jump -> rjmp. */ bfd_put_8 (abfd, 0x00, contents + irel->r_offset); bfd_put_8 (abfd, 0xC0, contents + irel->r_offset + 1); } else abort (); /* Fix the relocation's type. */ irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), R_AVR_13_PCREL); /* Check for the vector section. There we don't want to modify the ordering! */ if (!strcmp (sec->name,".vectors") || !strcmp (sec->name,".jumptables")) { /* Let's insert a nop. */ bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 2); bfd_put_8 (abfd, 0x00, contents + irel->r_offset + 3); } else { /* Delete two bytes of data. */ if (!elf32_avr_relax_delete_bytes (abfd, sec, irel->r_offset + 2, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; } } } default: { unsigned char code_msb; unsigned char code_lsb; bfd_vma dot; code_msb = bfd_get_8 (abfd, contents + irel->r_offset + 1); code_lsb = bfd_get_8 (abfd, contents + irel->r_offset + 0); /* Get the address of this instruction. */ dot = (sec->output_section->vma + sec->output_offset + irel->r_offset); /* Here we look for rcall/ret or call/ret sequences that could be safely replaced by rjmp/ret or jmp/ret */ - if (0xd0 == (code_msb & 0xf0)) + if ((0xd0 == (code_msb & 0xf0)) + && avr_replace_call_ret_sequences) { /* This insn is a rcall. */ unsigned char next_insn_msb = 0; unsigned char next_insn_lsb = 0; if (irel->r_offset + 3 < sec->size) { next_insn_msb = bfd_get_8 (abfd, contents + irel->r_offset + 3); next_insn_lsb = bfd_get_8 (abfd, contents + irel->r_offset + 2); } if ((0x95 == next_insn_msb) && (0x08 == next_insn_lsb)) { /* The next insn is a ret. We now convert the rcall insn into a rjmp instruction. */ code_msb &= 0xef; bfd_put_8 (abfd, code_msb, contents + irel->r_offset + 1); - if (DEBUG_RELAX) + if (debug_relax) printf ("converted rcall/ret sequence at address 0x%x" " into rjmp/ret sequence. Section is %s\n\n", (int) dot, sec->name); *again = TRUE; break; } } else if ((0x94 == (code_msb & 0xfe)) - && (0x0e == (code_lsb & 0x0e))) + && (0x0e == (code_lsb & 0x0e)) + && avr_replace_call_ret_sequences) { /* This insn is a call. */ unsigned char next_insn_msb = 0; unsigned char next_insn_lsb = 0; if (irel->r_offset + 5 < sec->size) { next_insn_msb = bfd_get_8 (abfd, contents + irel->r_offset + 5); next_insn_lsb = bfd_get_8 (abfd, contents + irel->r_offset + 4); } if ((0x95 == next_insn_msb) && (0x08 == next_insn_lsb)) { /* The next insn is a ret. We now convert the call insn into a jmp instruction. */ code_lsb &= 0xfd; bfd_put_8 (abfd, code_lsb, contents + irel->r_offset); - if (DEBUG_RELAX) + if (debug_relax) printf ("converted call/ret sequence at address 0x%x" " into jmp/ret sequence. Section is %s\n\n", (int) dot, sec->name); *again = TRUE; break; } } else if ((0xc0 == (code_msb & 0xf0)) || ((0x94 == (code_msb & 0xfe)) && (0x0c == (code_lsb & 0x0e)))) { /* This insn is a rjmp or a jmp. */ unsigned char next_insn_msb = 0; unsigned char next_insn_lsb = 0; int insn_size; if (0xc0 == (code_msb & 0xf0)) insn_size = 2; /* rjmp insn */ else insn_size = 4; /* jmp insn */ if (irel->r_offset + insn_size + 1 < sec->size) { next_insn_msb = bfd_get_8 (abfd, contents + irel->r_offset + insn_size + 1); next_insn_lsb = bfd_get_8 (abfd, contents + irel->r_offset + insn_size); } if ((0x95 == next_insn_msb) && (0x08 == next_insn_lsb)) { /* The next insn is a ret. We possibly could delete this ret. First we need to check for preceeding sbis/sbic/sbrs or cpse "skip" instructions. */ int there_is_preceeding_non_skip_insn = 1; bfd_vma address_of_ret; address_of_ret = dot + insn_size; - if (DEBUG_RELAX && (insn_size == 2)) + if (debug_relax && (insn_size == 2)) printf ("found rjmp / ret sequence at address 0x%x\n", (int) dot); - if (DEBUG_RELAX && (insn_size == 4)) + if (debug_relax && (insn_size == 4)) printf ("found jmp / ret sequence at address 0x%x\n", (int) dot); /* We have to make sure that there is a preceeding insn. */ if (irel->r_offset >= 2) { unsigned char preceeding_msb; unsigned char preceeding_lsb; preceeding_msb = bfd_get_8 (abfd, contents + irel->r_offset - 1); preceeding_lsb = bfd_get_8 (abfd, contents + irel->r_offset - 2); /* sbic. */ if (0x99 == preceeding_msb) there_is_preceeding_non_skip_insn = 0; /* sbis. */ if (0x9b == preceeding_msb) there_is_preceeding_non_skip_insn = 0; /* sbrc */ if ((0xfc == (preceeding_msb & 0xfe) && (0x00 == (preceeding_lsb & 0x08)))) there_is_preceeding_non_skip_insn = 0; /* sbrs */ if ((0xfe == (preceeding_msb & 0xfe) && (0x00 == (preceeding_lsb & 0x08)))) there_is_preceeding_non_skip_insn = 0; /* cpse */ if (0x10 == (preceeding_msb & 0xfc)) there_is_preceeding_non_skip_insn = 0; if (there_is_preceeding_non_skip_insn == 0) - if (DEBUG_RELAX) + if (debug_relax) printf ("preceeding skip insn prevents deletion of" " ret insn at addr 0x%x in section %s\n", (int) dot + 2, sec->name); } else { /* There is no previous instruction. */ there_is_preceeding_non_skip_insn = 0; } if (there_is_preceeding_non_skip_insn) { /* We now only have to make sure that there is no local label defined at the address of the ret instruction and that there is no local relocation in this section pointing to the ret. */ int deleting_ret_is_safe = 1; unsigned int section_offset_of_ret_insn = irel->r_offset + insn_size; Elf_Internal_Sym *isym, *isymend; unsigned int sec_shndx; sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec); /* Check for local symbols. */ isym = (Elf_Internal_Sym *) symtab_hdr->contents; isymend = isym + symtab_hdr->sh_info; for (; isym < isymend; isym++) { if (isym->st_value == section_offset_of_ret_insn && isym->st_shndx == sec_shndx) { deleting_ret_is_safe = 0; - if (DEBUG_RELAX) + if (debug_relax) printf ("local label prevents deletion of ret " "insn at address 0x%x\n", (int) dot + insn_size); } } /* Now check for global symbols. */ { int symcount; struct elf_link_hash_entry **sym_hashes; struct elf_link_hash_entry **end_hashes; symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym) - symtab_hdr->sh_info); sym_hashes = elf_sym_hashes (abfd); end_hashes = sym_hashes + symcount; for (; sym_hashes < end_hashes; sym_hashes++) { struct elf_link_hash_entry *sym_hash = *sym_hashes; if ((sym_hash->root.type == bfd_link_hash_defined || sym_hash->root.type == bfd_link_hash_defweak) && sym_hash->root.u.def.section == sec - && sym_hash->root.u.def.value == section_offset_of_ret_insn) + && sym_hash->root.u.def.value == + section_offset_of_ret_insn) { deleting_ret_is_safe = 0; - if (DEBUG_RELAX) + if (debug_relax) printf ("global label prevents deletion of " "ret insn at address 0x%x\n", (int) dot + insn_size); } } } /* Now we check for relocations pointing to ret. */ { Elf_Internal_Rela *irel; Elf_Internal_Rela *relend; Elf_Internal_Shdr *symtab_hdr; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; relend = elf_section_data (sec)->relocs + sec->reloc_count; for (irel = elf_section_data (sec)->relocs; irel < relend; irel++) { bfd_vma reloc_target = 0; bfd_vma symval; Elf_Internal_Sym *isymbuf = NULL; /* Read this BFD's local symbols if we haven't done so already. */ if (isymbuf == NULL && symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) break; } /* Get the value of the symbol referred to by the reloc. */ if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) { /* A local symbol. */ Elf_Internal_Sym *isym; asection *sym_sec; isym = isymbuf + ELF32_R_SYM (irel->r_info); sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx); symval = isym->st_value; /* If the reloc is absolute, it will not have a symbol or section associated with it. */ if (sym_sec) { symval += sym_sec->output_section->vma + sym_sec->output_offset; reloc_target = symval + irel->r_addend; } else { reloc_target = symval + irel->r_addend; /* Reference symbol is absolute. */ } } /* else ... reference symbol is extern. */ if (address_of_ret == reloc_target) { deleting_ret_is_safe = 0; - if (DEBUG_RELAX) + if (debug_relax) printf ("ret from " "rjmp/jmp ret sequence at address" " 0x%x could not be deleted. ret" " is target of a relocation.\n", (int) address_of_ret); } } } if (deleting_ret_is_safe) { - if (DEBUG_RELAX) + if (debug_relax) printf ("unreachable ret instruction " "at address 0x%x deleted.\n", (int) dot + insn_size); /* Delete two bytes of data. */ if (!elf32_avr_relax_delete_bytes (abfd, sec, irel->r_offset + insn_size, 2)) goto error_return; /* That will change things, so, we should relax again. Note that this is not required, and it may be slow. */ *again = TRUE; break; } } } } break; } } } if (contents != NULL && elf_section_data (sec)->this_hdr.contents != contents) { if (! link_info->keep_memory) free (contents); else { /* Cache the section contents for elf_link_input_bfd. */ elf_section_data (sec)->this_hdr.contents = contents; } } if (internal_relocs != NULL && elf_section_data (sec)->relocs != internal_relocs) free (internal_relocs); return TRUE; error_return: if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (contents != NULL && elf_section_data (sec)->this_hdr.contents != contents) free (contents); if (internal_relocs != NULL && elf_section_data (sec)->relocs != internal_relocs) free (internal_relocs); return FALSE; } /* This is a version of bfd_generic_get_relocated_section_contents which uses elf32_avr_relocate_section. For avr it's essentially a cut and paste taken from the H8300 port. The author of the relaxation support patch for avr had absolutely no clue what is happening here but found out that this part of the code @@ -1892,88 +2267,737 @@ if (symtab_hdr->sh_info != 0) { isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; if (isymbuf == NULL) isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, symtab_hdr->sh_info, 0, NULL, NULL, NULL); if (isymbuf == NULL) goto error_return; } amt = symtab_hdr->sh_info; amt *= sizeof (asection *); sections = bfd_malloc (amt); if (sections == NULL && amt != 0) goto error_return; isymend = isymbuf + symtab_hdr->sh_info; for (isym = isymbuf, secpp = sections; isym < isymend; ++isym, ++secpp) { asection *isec; if (isym->st_shndx == SHN_UNDEF) isec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) isec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) isec = bfd_com_section_ptr; else isec = bfd_section_from_elf_index (input_bfd, isym->st_shndx); *secpp = isec; } if (! elf32_avr_relocate_section (output_bfd, link_info, input_bfd, input_section, data, internal_relocs, isymbuf, sections)) goto error_return; if (sections != NULL) free (sections); if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (elf_section_data (input_section)->relocs != internal_relocs) free (internal_relocs); } return data; error_return: if (sections != NULL) free (sections); if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) free (isymbuf); if (internal_relocs != NULL && elf_section_data (input_section)->relocs != internal_relocs) free (internal_relocs); return NULL; } +/* Determines the hash entry name for a particular reloc. It consists of + the identifier of the symbol section and the added reloc addend and + symbol offset relative to the section the symbol is attached to. */ +static char * +avr_stub_name (const asection *symbol_section, + const bfd_vma symbol_offset, + const Elf_Internal_Rela *rela) +{ + char *stub_name; + bfd_size_type len; + + len = 8 + 1 + 8 + 1 + 1; + stub_name = bfd_malloc (len); + + sprintf (stub_name, "%08x+%08x", + symbol_section->id & 0xffffffff, + (unsigned int) ((rela->r_addend & 0xffffffff) + symbol_offset)); + + return stub_name; +} + + +/* Returns the address of the corresponding stub if there is one. + Returns otherwise an address above 0x020000. This function + could also be used, if there is no knowledge on the section where + the destination is found. */ +static bfd_vma +avr_get_stub_addr (bfd_vma srel, + struct elf32_avr_link_hash_table *htab) +{ + bfd_vma stub_sec_addr = + (htab->stub_sec->output_section->vma + + htab->stub_sec->output_offset); + + unsigned int index; + for (index = 0; index < htab->amt_max_entry_cnt; index ++) + { + if (htab->amt_destination_addr[index] == srel) + { + return htab->amt_stub_offsets[index] + stub_sec_addr; + } + } + + /* Return an address that could not be reached by 16 bit relocs. */ + return 0x020000; +} + +/* Add a new stub entry to the stub hash. Not all fields of the new + stub entry are initialised. */ + +static struct elf32_avr_stub_hash_entry * +avr_add_stub (const char *stub_name, + struct elf32_avr_link_hash_table *htab) +{ + struct elf32_avr_stub_hash_entry *hsh; + + /* Enter this entry into the linker stub hash table. */ + hsh = avr_stub_hash_lookup (&htab->bstab, stub_name, TRUE, FALSE); + + if (hsh == NULL) + { + (*_bfd_error_handler) (_("%B: cannot create stub entry %s"), + NULL, + stub_name); + return NULL; + } + + hsh->stub_offset = 0; + return hsh; +} + +/* We assume that there is already space allocated for the stub section + contents and that before building the stubs the section size is + initialized to 0. We assume that within the stub hash table entry, + the absolute position of the jmp target has been written in the + target_value field. We write here the offset of the generated jmp insn + relative to the trampoline section start to the stub_offset entry in + the stub hash table entry. */ + +static bfd_boolean +avr_build_one_stub (struct bfd_hash_entry *bh, void *in_arg) +{ + struct elf32_avr_stub_hash_entry *hsh; + struct bfd_link_info *info; + struct elf32_avr_link_hash_table *htab; + bfd *stub_bfd; + bfd_byte *loc; + bfd_vma target; + bfd_vma starget; + + /* Basic opcode */ + bfd_vma jmp_insn = 0x0000940c; + + /* Massage our args to the form they really have. */ + hsh = avr_stub_hash_entry (bh); + + if (!hsh->is_actually_needed) + return TRUE; + + info = (struct bfd_link_info *)in_arg; + + htab = avr_link_hash_table (info); + + target = hsh->target_value; + + /* Make a note of the offset within the stubs for this entry. */ + hsh->stub_offset = htab->stub_sec->size; + loc = htab->stub_sec->contents + hsh->stub_offset; + + stub_bfd = htab->stub_sec->owner; + + if (debug_stubs) + printf ("Building one Stub. Address: 0x%x, Offset: 0x%x\n", + (unsigned int) target, + (unsigned int) hsh->stub_offset); + + /* We now have to add the information on the jump target to the bare + opcode bits already set in jmp_insn. */ + + /* Check for the alignment of the address. */ + if (target & 1) + return FALSE; + + starget = target >> 1; + jmp_insn |= ((starget & 0x10000) | ((starget << 3) & 0x1f00000)) >> 16; + bfd_put_16 (stub_bfd, jmp_insn, loc); + bfd_put_16 (stub_bfd, (bfd_vma) starget & 0xffff, loc+2); + + htab->stub_sec->size += 4; + + /* Now add the entries in the address mapping table if there is still + space left. */ + { + unsigned int nr; + nr = htab->amt_entry_cnt + 1; + if (nr <= htab->amt_max_entry_cnt) + { + htab->amt_entry_cnt = nr; + + htab->amt_stub_offsets[nr - 1] = hsh->stub_offset; + htab->amt_destination_addr[nr - 1] = target; + } + } + + return TRUE; +} + +static bfd_boolean +avr_mark_stub_not_to_be_necessary (struct bfd_hash_entry *bh, + void *in_arg) +{ + struct elf32_avr_stub_hash_entry *hsh; + struct elf32_avr_link_hash_table *htab; + htab = in_arg; + + hsh = avr_stub_hash_entry (bh); + hsh->is_actually_needed = FALSE; + + return TRUE; +} + +static bfd_boolean +avr_size_one_stub (struct bfd_hash_entry *bh, void *in_arg) +{ + struct elf32_avr_stub_hash_entry *hsh; + struct elf32_avr_link_hash_table *htab; + int size; + + /* Massage our args to the form they really have. */ + hsh = avr_stub_hash_entry (bh); + htab = in_arg; + + if (hsh->is_actually_needed) + size = 4; + else + size = 0; + + htab->stub_sec->size += size; + return TRUE; +} + +void +elf32_avr_setup_params (struct bfd_link_info *info, + bfd *avr_stub_bfd, + asection *avr_stub_section, + bfd_boolean no_stubs, + bfd_boolean deb_stubs, + bfd_boolean deb_relax, + bfd_vma pc_wrap_around, + bfd_boolean call_ret_replacement) +{ + struct elf32_avr_link_hash_table *htab = avr_link_hash_table(info); + htab->stub_sec = avr_stub_section; + htab->stub_bfd = avr_stub_bfd; + htab->no_stubs = no_stubs; + + debug_relax = deb_relax; + debug_stubs = deb_stubs; + avr_pc_wrap_around = pc_wrap_around; + avr_replace_call_ret_sequences = call_ret_replacement; +} + + +/* Set up various things so that we can make a list of input sections + for each output section included in the link. Returns -1 on error, + 0 when no stubs will be needed, and 1 on success. It also sets + information on the stubs bfd and the stub section in the info + struct. */ + +int +elf32_avr_setup_section_lists (bfd *output_bfd, + struct bfd_link_info *info) +{ + bfd *input_bfd; + unsigned int bfd_count; + int top_id, top_index; + asection *section; + asection **input_list, **list; + bfd_size_type amt; + struct elf32_avr_link_hash_table *htab = avr_link_hash_table(info); + + if (htab->no_stubs) + return 0; + + /* Count the number of input BFDs and find the top input section id. */ + for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0; + input_bfd != NULL; + input_bfd = input_bfd->link_next) + { + bfd_count += 1; + for (section = input_bfd->sections; + section != NULL; + section = section->next) + { + if (top_id < section->id) + top_id = section->id; + } + } + htab->bfd_count = bfd_count; + + /* We can't use output_bfd->section_count here to find the top output + section index as some sections may have been removed, and + strip_excluded_output_sections doesn't renumber the indices. */ + for (section = output_bfd->sections, top_index = 0; + section != NULL; + section = section->next) + { + if (top_index < section->index) + top_index = section->index; + } + + htab->top_index = top_index; + amt = sizeof (asection *) * (top_index + 1); + input_list = bfd_malloc (amt); + htab->input_list = input_list; + if (input_list == NULL) + return -1; + + /* For sections we aren't interested in, mark their entries with a + value we can check later. */ + list = input_list + top_index; + do + *list = bfd_abs_section_ptr; + while (list-- != input_list); + + for (section = output_bfd->sections; + section != NULL; + section = section->next) + { + if ((section->flags & SEC_CODE) != 0) + input_list[section->index] = NULL; + } + + return 1; +} + + +/* Read in all local syms for all input bfds, and create hash entries + for export stubs if we are building a multi-subspace shared lib. + Returns -1 on error, 0 otherwise. */ + +static int +get_local_syms (bfd *input_bfd, struct bfd_link_info *info) +{ + unsigned int bfd_indx; + Elf_Internal_Sym *local_syms, **all_local_syms; + struct elf32_avr_link_hash_table *htab = avr_link_hash_table (info); + + /* We want to read in symbol extension records only once. To do this + we need to read in the local symbols in parallel and save them for + later use; so hold pointers to the local symbols in an array. */ + bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count; + all_local_syms = bfd_zmalloc (amt); + htab->all_local_syms = all_local_syms; + if (all_local_syms == NULL) + return -1; + + /* Walk over all the input BFDs, swapping in local symbols. + If we are creating a shared library, create hash entries for the + export stubs. */ + for (bfd_indx = 0; + input_bfd != NULL; + input_bfd = input_bfd->link_next, bfd_indx++) + { + Elf_Internal_Shdr *symtab_hdr; + + /* We'll need the symbol table in a second. */ + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + if (symtab_hdr->sh_info == 0) + continue; + + /* We need an array of the local symbols attached to the input bfd. */ + local_syms = (Elf_Internal_Sym *) symtab_hdr->contents; + if (local_syms == NULL) + { + local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, + symtab_hdr->sh_info, 0, + NULL, NULL, NULL); + /* Cache them for elf_link_input_bfd. */ + symtab_hdr->contents = (unsigned char *) local_syms; + } + if (local_syms == NULL) + return -1; + + all_local_syms[bfd_indx] = local_syms; + } + + return 0; +} + +#define ADD_DUMMY_STUBS_FOR_DEBUGGING 0 + +bfd_boolean +elf32_avr_size_stubs (bfd *output_bfd, + struct bfd_link_info *info, + bfd_boolean is_prealloc_run) +{ + struct elf32_avr_link_hash_table *htab; + int stub_changed = 0; + + htab = avr_link_hash_table (info); + + /* At this point we initialize + htab->vector_base + To the start of the text output section. */ + htab->vector_base = htab->stub_sec->output_section->vma; + + if (get_local_syms (info->input_bfds, info)) + { + if (htab->all_local_syms) + goto error_ret_free_local; + return FALSE; + } + + if (ADD_DUMMY_STUBS_FOR_DEBUGGING) + { + struct elf32_avr_stub_hash_entry *test; + test = avr_add_stub ("Hugo",htab); + test->target_value = 0x123456; + test->stub_offset = 13; + + test = avr_add_stub ("Hugo2",htab); + test->target_value = 0x84210; + test->stub_offset = 14; + } + + while (1) + { + bfd *input_bfd; + unsigned int bfd_indx; + + /* We will have to re-generate the stub hash table each time anything + in memory has changed. */ + + bfd_hash_traverse (&htab->bstab, avr_mark_stub_not_to_be_necessary, htab); + for (input_bfd = info->input_bfds, bfd_indx = 0; + input_bfd != NULL; + input_bfd = input_bfd->link_next, bfd_indx++) + { + Elf_Internal_Shdr *symtab_hdr; + asection *section; + Elf_Internal_Sym *local_syms; + + /* We'll need the symbol table in a second. */ + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; + if (symtab_hdr->sh_info == 0) + continue; + + local_syms = htab->all_local_syms[bfd_indx]; + + /* Walk over each section attached to the input bfd. */ + for (section = input_bfd->sections; + section != NULL; + section = section->next) + { + Elf_Internal_Rela *internal_relocs, *irelaend, *irela; + + /* If there aren't any relocs, then there's nothing more + to do. */ + if ((section->flags & SEC_RELOC) == 0 + || section->reloc_count == 0) + continue; + + /* If this section is a link-once section that will be + discarded, then don't create any stubs. */ + if (section->output_section == NULL + || section->output_section->owner != output_bfd) + continue; + + /* Get the relocs. */ + internal_relocs + = _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL, + info->keep_memory); + if (internal_relocs == NULL) + goto error_ret_free_local; + + /* Now examine each relocation. */ + irela = internal_relocs; + irelaend = irela + section->reloc_count; + for (; irela < irelaend; irela++) + { + unsigned int r_type, r_indx; + struct elf32_avr_stub_hash_entry *hsh; + asection *sym_sec; + bfd_vma sym_value; + bfd_vma destination; + struct elf_link_hash_entry *hh; + char *stub_name; + + r_type = ELF32_R_TYPE (irela->r_info); + r_indx = ELF32_R_SYM (irela->r_info); + + /* Only look for 16 bit relocs. No other reloc will need a + stub. */ + if (!((r_type == R_AVR_16_PM) + || (r_type == R_AVR_LO8_LDI_PM) + || (r_type == R_AVR_LO8_LDI_PM_NEG) + || (r_type == R_AVR_HI8_LDI_PM) + || (r_type == R_AVR_HI8_LDI_PM_NEG))) + continue; + + /* Now determine the call target, its name, value, + section. */ + sym_sec = NULL; + sym_value = 0; + destination = 0; + hh = NULL; + if (r_indx < symtab_hdr->sh_info) + { + /* It's a local symbol. */ + Elf_Internal_Sym *sym; + Elf_Internal_Shdr *hdr; + + sym = local_syms + r_indx; + hdr = elf_elfsections (input_bfd)[sym->st_shndx]; + sym_sec = hdr->bfd_section; + if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) + sym_value = sym->st_value; + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else + { + /* It's an external symbol. */ + int e_indx; + + e_indx = r_indx - symtab_hdr->sh_info; + hh = elf_sym_hashes (input_bfd)[e_indx]; + + while (hh->root.type == bfd_link_hash_indirect + || hh->root.type == bfd_link_hash_warning) + hh = (struct elf_link_hash_entry *) + (hh->root.u.i.link); + + if (hh->root.type == bfd_link_hash_defined + || hh->root.type == bfd_link_hash_defweak) + { + sym_sec = hh->root.u.def.section; + sym_value = hh->root.u.def.value; + if (sym_sec->output_section != NULL) + destination = (sym_value + irela->r_addend + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else if (hh->root.type == bfd_link_hash_undefweak) + { + if (! info->shared) + continue; + } + else if (hh->root.type == bfd_link_hash_undefined) + { + if (! (info->unresolved_syms_in_objects == RM_IGNORE + && (ELF_ST_VISIBILITY (hh->other) + == STV_DEFAULT))) + continue; + } + else + { + bfd_set_error (bfd_error_bad_value); + + error_ret_free_internal: + if (elf_section_data (section)->relocs == NULL) + free (internal_relocs); + goto error_ret_free_local; + } + } + + if (!avr_stub_is_required_for_16_bit_reloc ( + destination - htab->vector_base)) + + { + if (!is_prealloc_run) + { + /* We are having a reloc that does't need a stub. */ + continue; + } + else + { + /* We don't right now know if a stub will be needed. + Let's rather be on the safe side. */ + } + } + + /* Get the name of this stub. */ + stub_name = avr_stub_name (sym_sec, sym_value, irela); + + if (!stub_name) + goto error_ret_free_internal; + + + hsh = avr_stub_hash_lookup (&htab->bstab, + stub_name, + FALSE, FALSE); + if (hsh != NULL) + { + /* The proper stub has already been created. Mark it + to be used and write the possibly changed destination + value. */ + hsh->is_actually_needed = TRUE; + hsh->target_value = destination; + free (stub_name); + continue; + } + + hsh = avr_add_stub (stub_name, htab); + if (hsh == NULL) + { + free (stub_name); + goto error_ret_free_internal; + } + + hsh->is_actually_needed = TRUE; + hsh->target_value = destination; + + if (debug_stubs) + printf ("Adding stub with destination 0x%x to the" + " hash table.\n", (unsigned int) destination); + if (debug_stubs) + printf ("(Pre-Alloc run: %i)\n", is_prealloc_run); + + stub_changed = TRUE; + } + + /* We're done with the internal relocs, free them. */ + if (elf_section_data (section)->relocs == NULL) + free (internal_relocs); + } + } + + /* Re-Calculate the number of needed stubs. */ + htab->stub_sec->size = 0; + bfd_hash_traverse (&htab->bstab, avr_size_one_stub, htab); + + if (!stub_changed) + break; + + stub_changed = FALSE; + } + + free (htab->all_local_syms); + return TRUE; + + return 1; + + error_ret_free_local: + free (htab->all_local_syms); + return FALSE; +} + + +/* Build all the stubs associated with the current output file. The + stubs are kept in a hash table attached to the main linker hash + table. We also set up the .plt entries for statically linked PIC + functions here. This function is called via hppaelf_finish in the + linker. */ + +bfd_boolean +elf32_avr_build_stubs (struct bfd_link_info *info) +{ + asection *stub_sec; + struct bfd_hash_table *table; + struct elf32_avr_link_hash_table *htab; + bfd_size_type total_size = 0; + + htab = avr_link_hash_table (info); + + /* In case that there were several stub sections: */ + for (stub_sec = htab->stub_bfd->sections; + stub_sec != NULL; + stub_sec = stub_sec->next) + { + bfd_size_type size; + + /* Allocate memory to hold the linker stubs. */ + size = stub_sec->size; + total_size += size; + + stub_sec->contents = bfd_zalloc (htab->stub_bfd, size); + if (stub_sec->contents == NULL && size != 0) + return FALSE; + stub_sec->size = 0; + } + + /* Allocate memory for the adress mapping table. */ + htab->amt_entry_cnt = 0; + htab->amt_max_entry_cnt = total_size / 4; + htab->amt_stub_offsets = bfd_malloc (sizeof (bfd_vma) + * htab->amt_max_entry_cnt); + htab->amt_destination_addr = + bfd_malloc (sizeof (bfd_vma) + * htab->amt_max_entry_cnt ); + + if (debug_stubs) + printf ("Allocating %i entries in the AMT\n", htab->amt_max_entry_cnt); + + /* Build the stubs as directed by the stub hash table. */ + table = &htab->bstab; + bfd_hash_traverse (table, avr_build_one_stub, info); + + if (debug_stubs) + printf ("Final Stub section Size: %i\n", (int) htab->stub_sec->size); + + return TRUE; +} + #define ELF_ARCH bfd_arch_avr #define ELF_MACHINE_CODE EM_AVR #define ELF_MACHINE_ALT1 EM_AVR_OLD #define ELF_MAXPAGESIZE 1 #define TARGET_LITTLE_SYM bfd_elf32_avr_vec #define TARGET_LITTLE_NAME "elf32-avr" +#define bfd_elf32_bfd_link_hash_table_create elf32_avr_link_hash_table_create +#define bfd_elf32_bfd_link_hash_table_free elf32_avr_link_hash_table_free + #define elf_info_to_howto avr_info_to_howto_rela #define elf_info_to_howto_rel NULL #define elf_backend_relocate_section elf32_avr_relocate_section #define elf_backend_gc_mark_hook elf32_avr_gc_mark_hook #define elf_backend_gc_sweep_hook elf32_avr_gc_sweep_hook #define elf_backend_check_relocs elf32_avr_check_relocs #define elf_backend_can_gc_sections 1 #define elf_backend_rela_normal 1 #define elf_backend_final_write_processing \ bfd_elf_avr_final_write_processing #define elf_backend_object_p elf32_avr_object_p #define bfd_elf32_bfd_relax_section elf32_avr_relax_section #define bfd_elf32_bfd_get_relocated_section_contents \ elf32_avr_get_relocated_section_contents #include "elf32-target.h" Index: gas/config/tc-avr.c =================================================================== RCS file: /cvs/src/src/gas/config/tc-avr.c,v retrieving revision 1.32 diff -U62 -r1.32 tc-avr.c --- gas/config/tc-avr.c 7 Apr 2006 15:18:08 -0000 1.32 +++ gas/config/tc-avr.c 1 May 2006 19:44:24 -0000 @@ -9,256 +9,259 @@ GAS 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, or (at your option) any later version. GAS 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 GAS; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "as.h" #include "safe-ctype.h" #include "subsegs.h" #include "libiberty.h" struct avr_opcodes_s { char * name; char * constraints; int insn_size; /* In words. */ int isa; unsigned int bin_opcode; }; #define AVR_INSN(NAME, CONSTR, OPCODE, SIZE, ISA, BIN) \ {#NAME, CONSTR, SIZE, ISA, BIN}, struct avr_opcodes_s avr_opcodes[] = { #include "opcode/avr.h" {NULL, NULL, 0, 0, 0} }; const char comment_chars[] = ";"; const char line_comment_chars[] = "#"; const char line_separator_chars[] = "$"; const char *md_shortopts = "m:"; struct mcu_type_s { char *name; int isa; int mach; }; /* XXX - devices that don't seem to exist (renamed, replaced with larger ones, or planned but never produced), left here for compatibility. TODO: hide them in show_mcu_list output? */ static struct mcu_type_s mcu_types[] = { {"avr1", AVR_ISA_TINY1, bfd_mach_avr1}, {"avr2", AVR_ISA_TINY2, bfd_mach_avr2}, {"avr3", AVR_ISA_M103, bfd_mach_avr3}, {"avr4", AVR_ISA_M8, bfd_mach_avr4}, {"avr5", AVR_ISA_ALL, bfd_mach_avr5}, + {"avr6", AVR_ISA_ALL, bfd_mach_avr6}, {"at90s1200", AVR_ISA_1200, bfd_mach_avr1}, {"attiny10", AVR_ISA_TINY1, bfd_mach_avr1}, /* XXX -> tn11 */ {"attiny11", AVR_ISA_TINY1, bfd_mach_avr1}, {"attiny12", AVR_ISA_TINY1, bfd_mach_avr1}, {"attiny15", AVR_ISA_TINY1, bfd_mach_avr1}, {"attiny28", AVR_ISA_TINY1, bfd_mach_avr1}, {"at90s2313", AVR_ISA_2xxx, bfd_mach_avr2}, {"at90s2323", AVR_ISA_2xxx, bfd_mach_avr2}, {"at90s2333", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 4433 */ {"at90s2343", AVR_ISA_2xxx, bfd_mach_avr2}, {"attiny22", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 2343 */ {"attiny26", AVR_ISA_2xxx, bfd_mach_avr2}, {"at90s4433", AVR_ISA_2xxx, bfd_mach_avr2}, {"at90s4414", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 8515 */ {"at90s4434", AVR_ISA_2xxx, bfd_mach_avr2}, /* XXX -> 8535 */ {"at90s8515", AVR_ISA_2xxx, bfd_mach_avr2}, {"at90s8535", AVR_ISA_2xxx, bfd_mach_avr2}, {"at90c8534", AVR_ISA_2xxx, bfd_mach_avr2}, {"at86rf401", AVR_ISA_2xxx, bfd_mach_avr2}, {"attiny13", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny2313",AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny261", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny461", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny861", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny24", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny44", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny84", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny25", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny45", AVR_ISA_TINY2, bfd_mach_avr2}, {"attiny85", AVR_ISA_TINY2, bfd_mach_avr2}, {"atmega603", AVR_ISA_M603, bfd_mach_avr3}, /* XXX -> m103 */ {"atmega103", AVR_ISA_M103, bfd_mach_avr3}, {"at43usb320",AVR_ISA_M103, bfd_mach_avr3}, {"at43usb355",AVR_ISA_M603, bfd_mach_avr3}, {"at76c711", AVR_ISA_M603, bfd_mach_avr3}, {"atmega48", AVR_ISA_PWMx, bfd_mach_avr4}, {"atmega8", AVR_ISA_M8, bfd_mach_avr4}, {"atmega83", AVR_ISA_M8, bfd_mach_avr4}, /* XXX -> m8535 */ {"atmega85", AVR_ISA_M8, bfd_mach_avr4}, /* XXX -> m8 */ {"atmega88", AVR_ISA_PWMx, bfd_mach_avr4}, {"atmega8515",AVR_ISA_M8, bfd_mach_avr4}, {"atmega8535",AVR_ISA_M8, bfd_mach_avr4}, {"at90pwm2", AVR_ISA_PWMx, bfd_mach_avr4}, {"at90pwm3", AVR_ISA_PWMx, bfd_mach_avr4}, {"atmega16", AVR_ISA_M323, bfd_mach_avr5}, {"atmega161", AVR_ISA_M161, bfd_mach_avr5}, {"atmega162", AVR_ISA_M323, bfd_mach_avr5}, {"atmega163", AVR_ISA_M161, bfd_mach_avr5}, {"atmega164", AVR_ISA_M323, bfd_mach_avr5}, {"atmega165", AVR_ISA_M323, bfd_mach_avr5}, {"atmega168", AVR_ISA_M323, bfd_mach_avr5}, {"atmega169", AVR_ISA_M323, bfd_mach_avr5}, {"atmega32", AVR_ISA_M323, bfd_mach_avr5}, {"atmega323", AVR_ISA_M323, bfd_mach_avr5}, {"atmega324", AVR_ISA_M323, bfd_mach_avr5}, {"atmega325", AVR_ISA_M323, bfd_mach_avr5}, {"atmega329", AVR_ISA_M323, bfd_mach_avr5}, {"atmega3250",AVR_ISA_M323, bfd_mach_avr5}, {"atmega3290",AVR_ISA_M323, bfd_mach_avr5}, {"atmega406", AVR_ISA_M323, bfd_mach_avr5}, {"atmega64", AVR_ISA_M323, bfd_mach_avr5}, {"atmega640", AVR_ISA_M323, bfd_mach_avr5}, {"atmega644", AVR_ISA_M323, bfd_mach_avr5}, {"atmega128", AVR_ISA_M128, bfd_mach_avr5}, {"atmega1280",AVR_ISA_M128, bfd_mach_avr5}, {"atmega1281",AVR_ISA_M128, bfd_mach_avr5}, {"atmega645", AVR_ISA_M323, bfd_mach_avr5}, {"atmega649", AVR_ISA_M323, bfd_mach_avr5}, {"atmega6450",AVR_ISA_M323, bfd_mach_avr5}, {"atmega6490",AVR_ISA_M323, bfd_mach_avr5}, {"at90can32" ,AVR_ISA_M323, bfd_mach_avr5}, {"at90can64" ,AVR_ISA_M323, bfd_mach_avr5}, {"at90can128",AVR_ISA_M128, bfd_mach_avr5}, {"at90usb646", AVR_ISA_M323, bfd_mach_avr5}, {"at90usb647", AVR_ISA_M323, bfd_mach_avr5}, {"at90usb1286",AVR_ISA_M128, bfd_mach_avr5}, {"at90usb1287",AVR_ISA_M128, bfd_mach_avr5}, {"at94k", AVR_ISA_94K, bfd_mach_avr5}, + {"atmega2560", AVR_ISA_ALL, bfd_mach_avr6}, + {"atmega2561", AVR_ISA_ALL, bfd_mach_avr6}, {NULL, 0, 0} }; /* Current MCU type. */ static struct mcu_type_s default_mcu = {"avr2", AVR_ISA_2xxx,bfd_mach_avr2}; static struct mcu_type_s * avr_mcu = & default_mcu; /* AVR target-specific switches. */ struct avr_opt_s { int all_opcodes; /* -mall-opcodes: accept all known AVR opcodes. */ int no_skip_bug; /* -mno-skip-bug: no warnings for skipping 2-word insns. */ int no_wrap; /* -mno-wrap: reject rjmp/rcall with 8K wrap-around. */ }; static struct avr_opt_s avr_opt = { 0, 0, 0 }; const char EXP_CHARS[] = "eE"; const char FLT_CHARS[] = "dD"; static void avr_set_arch (int); /* The target specific pseudo-ops which we support. */ const pseudo_typeS md_pseudo_table[] = { {"arch", avr_set_arch, 0}, { NULL, NULL, 0} }; #define LDI_IMMEDIATE(x) (((x) & 0xf) | (((x) << 4) & 0xf00)) #define EXP_MOD_NAME(i) exp_mod[i].name #define EXP_MOD_RELOC(i) exp_mod[i].reloc #define EXP_MOD_NEG_RELOC(i) exp_mod[i].neg_reloc #define HAVE_PM_P(i) exp_mod[i].have_pm struct exp_mod_s { char * name; bfd_reloc_code_real_type reloc; bfd_reloc_code_real_type neg_reloc; int have_pm; }; static struct exp_mod_s exp_mod[] = { - {"hh8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 1}, - {"pm_hh8", BFD_RELOC_AVR_HH8_LDI_PM, BFD_RELOC_AVR_HH8_LDI_PM_NEG, 0}, - {"hi8", BFD_RELOC_AVR_HI8_LDI, BFD_RELOC_AVR_HI8_LDI_NEG, 1}, - {"pm_hi8", BFD_RELOC_AVR_HI8_LDI_PM, BFD_RELOC_AVR_HI8_LDI_PM_NEG, 0}, - {"lo8", BFD_RELOC_AVR_LO8_LDI, BFD_RELOC_AVR_LO8_LDI_NEG, 1}, - {"pm_lo8", BFD_RELOC_AVR_LO8_LDI_PM, BFD_RELOC_AVR_LO8_LDI_PM_NEG, 0}, - {"hlo8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 0}, - {"hhi8", BFD_RELOC_AVR_MS8_LDI, BFD_RELOC_AVR_MS8_LDI_NEG, 0}, + {"hh8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 1}, + {"pm_hh8", BFD_RELOC_AVR_HH8_LDI_PM, BFD_RELOC_AVR_HH8_LDI_PM_NEG, 0}, + {"hi8", BFD_RELOC_AVR_HI8_LDI, BFD_RELOC_AVR_HI8_LDI_NEG, 1}, + {"pm_hi8", BFD_RELOC_AVR_HI8_LDI_PM, BFD_RELOC_AVR_HI8_LDI_PM_NEG, 0}, + {"lo8", BFD_RELOC_AVR_LO8_LDI, BFD_RELOC_AVR_LO8_LDI_NEG, 1}, + {"pm_ns_lo8", BFD_RELOC_AVR_LO8_LDI_PM, BFD_RELOC_AVR_LO8_LDI_PM_NEG, 0}, + {"hlo8", BFD_RELOC_AVR_HH8_LDI, BFD_RELOC_AVR_HH8_LDI_NEG, 0}, + {"hhi8", BFD_RELOC_AVR_MS8_LDI, BFD_RELOC_AVR_MS8_LDI_NEG, 0}, }; /* A union used to store indicies into the exp_mod[] array in a hash table which expects void * data types. */ typedef union { void * ptr; int index; } mod_index; /* Opcode hash table. */ static struct hash_control *avr_hash; /* Reloc modifiers hash control (hh8,hi8,lo8,pm_xx). */ static struct hash_control *avr_mod_hash; #define OPTION_MMCU 'm' enum options { OPTION_ALL_OPCODES = OPTION_MD_BASE + 1, OPTION_NO_SKIP_BUG, OPTION_NO_WRAP }; struct option md_longopts[] = { { "mmcu", required_argument, NULL, OPTION_MMCU }, { "mall-opcodes", no_argument, NULL, OPTION_ALL_OPCODES }, { "mno-skip-bug", no_argument, NULL, OPTION_NO_SKIP_BUG }, { "mno-wrap", no_argument, NULL, OPTION_NO_WRAP }, { NULL, no_argument, NULL, 0 } }; size_t md_longopts_size = sizeof (md_longopts); /* Display nicely formatted list of known MCU names. */ static void show_mcu_list (FILE *stream) { int i, x; fprintf (stream, _("Known MCU names:")); x = 1000; for (i = 0; mcu_types[i].name; i++) { int len = strlen (mcu_types[i].name); x += len + 1; if (x < 75) fprintf (stream, " %s", mcu_types[i].name); else { fprintf (stream, "\n %s", mcu_types[i].name); x = len + 2; } } fprintf (stream, "\n"); } Index: gas/config/tc-avr.h =================================================================== RCS file: /cvs/src/src/gas/config/tc-avr.h,v retrieving revision 1.11 diff -U62 -r1.11 tc-avr.h --- gas/config/tc-avr.h 12 Oct 2005 10:56:46 -0000 1.11 +++ gas/config/tc-avr.h 1 May 2006 19:44:24 -0000 @@ -61,62 +61,82 @@ #define TC_CONS_FIX_NEW(FRAG,WHERE,N,EXP) avr_cons_fix_new (FRAG, WHERE, N, EXP) extern void avr_cons_fix_new (fragS *,int, int, expressionS *); /* This should just call either `number_to_chars_bigendian' or `number_to_chars_littleendian', whichever is appropriate. On targets like the MIPS which support options to change the endianness, which function to call is a runtime decision. On other targets, `md_number_to_chars' can be a simple macro. */ #define md_number_to_chars number_to_chars_littleendian /* `md_short_jump_size' `md_long_jump_size' `md_create_short_jump' `md_create_long_jump' If `WORKING_DOT_WORD' is defined, GAS will not do broken word processing (*note Broken words::.). Otherwise, you should set `md_short_jump_size' to the size of a short jump (a jump that is just long enough to jump around a long jmp) and `md_long_jump_size' to the size of a long jump (a jump that can go anywhere in the function), You should define `md_create_short_jump' to create a short jump around a long jump, and define `md_create_long_jump' to create a long jump. */ #define WORKING_DOT_WORD /* If you define this macro, it means that `tc_gen_reloc' may return multiple relocation entries for a single fixup. In this case, the return value of `tc_gen_reloc' is a pointer to a null terminated array. */ #undef RELOC_EXPANSION_POSSIBLE /* No shared lib support, so we don't need to ensure externally visible symbols can be overridden. */ #define EXTERN_FORCE_RELOC 0 /* Values passed to md_apply_fix don't include the symbol value. */ #define MD_APPLY_SYM_VALUE(FIX) 0 /* If you define this macro, it should return the offset between the address of a PC relative fixup and the position from which the PC relative adjustment should be made. On many processors, the base of a PC relative instruction is the next instruction, so this macro would return the length of an instruction. */ #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from_section (FIX, SEC) extern long md_pcrel_from_section (struct fix *, segT); /* The number of bytes to put into a word in a listing. This affects the way the bytes are clumped together in the listing. For example, a value of 2 might print `1234 5678' where a value of 1 would print `12 34 56 78'. The default value is 4. */ #define LISTING_WORD_SIZE 2 /* AVR port uses `$' as a logical line separator */ #define LEX_DOLLAR 0 /* An `.lcomm' directive with no explicit alignment parameter will use this macro to set P2VAR to the alignment that a request for SIZE bytes will have. The alignment is expressed as a power of two. If no alignment should take place, the macro definition should do nothing. Some targets define a `.bss' directive that is also affected by this macro. The default definition will set P2VAR to the truncated power of two of sizes up to eight bytes. */ #define TC_IMPLICIT_LCOMM_ALIGNMENT(SIZE, P2VAR) (P2VAR) = 0 + +/* We don't want gas to fixup the following program memory related relocations. + We will need them in case that we want to do linker relaxation. + We could in principle keep these fixups in gas when not relaxing. + However, there is no serious performance penilty when making the linker + make the fixup work. */ +#define TC_VALIDATE_FIX(FIXP,SEG,SKIP) \ +if (FIXP->fx_r_type == BFD_RELOC_AVR_7_PCREL \ + || FIXP->fx_r_type == BFD_RELOC_AVR_13_PCREL \ + || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM \ + || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM \ + || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM \ + || FIXP->fx_r_type == BFD_RELOC_AVR_LO8_LDI_PM_NEG \ + || FIXP->fx_r_type == BFD_RELOC_AVR_HI8_LDI_PM_NEG \ + || FIXP->fx_r_type == BFD_RELOC_AVR_HH8_LDI_PM_NEG \ + || FIXP->fx_r_type == BFD_RELOC_AVR_16_PM) \ + { \ + goto SKIP; \ + } + Index: include/elf/avr.h =================================================================== RCS file: /cvs/src/src/include/elf/avr.h,v retrieving revision 1.7 diff -U62 -r1.7 avr.h --- include/elf/avr.h 3 Mar 2006 15:25:30 -0000 1.7 +++ include/elf/avr.h 1 May 2006 19:44:26 -0000 @@ -1,67 +1,68 @@ /* AVR ELF support for BFD. Copyright 1999, 2000, 2004 Free Software Foundation, Inc. Contributed by Denis Chertykov 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _ELF_AVR_H #define _ELF_AVR_H #include "elf/reloc-macros.h" /* Processor specific flags for the ELF header e_flags field. */ #define EF_AVR_MACH 0xf /* If bit #7 is set, it is assumed that the elf file uses local symbols as reference for the relocations so that linker relaxation is possible. */ #define EF_AVR_LINKRELAX_PREPARED 0x80 #define E_AVR_MACH_AVR1 1 #define E_AVR_MACH_AVR2 2 #define E_AVR_MACH_AVR3 3 #define E_AVR_MACH_AVR4 4 #define E_AVR_MACH_AVR5 5 +#define E_AVR_MACH_AVR6 6 /* Relocations. */ START_RELOC_NUMBERS (elf_avr_reloc_type) RELOC_NUMBER (R_AVR_NONE, 0) RELOC_NUMBER (R_AVR_32, 1) RELOC_NUMBER (R_AVR_7_PCREL, 2) RELOC_NUMBER (R_AVR_13_PCREL, 3) RELOC_NUMBER (R_AVR_16, 4) RELOC_NUMBER (R_AVR_16_PM, 5) RELOC_NUMBER (R_AVR_LO8_LDI, 6) RELOC_NUMBER (R_AVR_HI8_LDI, 7) RELOC_NUMBER (R_AVR_HH8_LDI, 8) RELOC_NUMBER (R_AVR_LO8_LDI_NEG, 9) RELOC_NUMBER (R_AVR_HI8_LDI_NEG, 10) RELOC_NUMBER (R_AVR_HH8_LDI_NEG, 11) RELOC_NUMBER (R_AVR_LO8_LDI_PM, 12) RELOC_NUMBER (R_AVR_HI8_LDI_PM, 13) RELOC_NUMBER (R_AVR_HH8_LDI_PM, 14) RELOC_NUMBER (R_AVR_LO8_LDI_PM_NEG, 15) RELOC_NUMBER (R_AVR_HI8_LDI_PM_NEG, 16) RELOC_NUMBER (R_AVR_HH8_LDI_PM_NEG, 17) RELOC_NUMBER (R_AVR_CALL, 18) RELOC_NUMBER (R_AVR_LDI, 19) RELOC_NUMBER (R_AVR_6, 20) RELOC_NUMBER (R_AVR_6_ADIW, 21) RELOC_NUMBER (R_AVR_MS8_LDI, 22) RELOC_NUMBER (R_AVR_MS8_LDI_NEG, 23) END_RELOC_NUMBERS (R_AVR_max) #endif /* _ELF_AVR_H */ Index: ld/Makefile.am =================================================================== RCS file: /cvs/src/src/ld/Makefile.am,v retrieving revision 1.209 diff -U62 -r1.209 Makefile.am --- ld/Makefile.am 11 Apr 2006 10:36:26 -0000 1.209 +++ ld/Makefile.am 1 May 2006 19:44:27 -0000 @@ -74,124 +74,125 @@ else \ echo gcc | sed '$(transform)'; \ fi; \ fi` CXX = gcc CXX_FOR_TARGET = ` \ if [ -f $$r/../gcc/xgcc ] ; then \ if [ -f $$r/../newlib/Makefile ] ; then \ echo $$r/../gcc/xgcc -B$$r/../gcc/ -idirafter $$r/../newlib/targ-include -idirafter $${srcroot}/../newlib/libc/include -nostdinc; \ else \ echo $$r/../gcc/xgcc -B$$r/../gcc/; \ fi; \ else \ if [ "@host@" = "@target@" ] ; then \ echo $(CXX); \ else \ echo gcc | sed '$(transform)'; \ fi; \ fi` noinst_PROGRAMS = ld-new info_TEXINFOS = ld.texinfo noinst_TEXINFOS = ldint.texinfo man_MANS = ld.1 AM_MAKEINFOFLAGS = -I $(srcdir) -I $(BFDDIR)/doc TEXI2DVI = texi2dvi -I $(srcdir) -I $(BFDDIR)/doc INCLUDES = -D_GNU_SOURCE -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) -I$(top_srcdir)/../intl -I../intl $(HDEFINES) $(CFLAGS) -DLOCALEDIR="\"$(datadir)/locale\"" BFDLIB = ../bfd/libbfd.la LIBIBERTY = ../libiberty/libiberty.a ALL_EMULATIONS = \ eaixppc.o \ eaixrs6.o \ ealpha.o \ earcelf.o \ earm_epoc_pe.o \ earmaoutb.o \ earmaoutl.o \ earmcoff.o \ earmelf.o \ earmelfb.o \ earmelf_fbsd.o \ earmelf_linux.o \ earmelf_linux_eabi.o \ earmelfb_linux.o \ earmelfb_linux_eabi.o \ earmelf_nbsd.o \ earmelfb_nbsd.o \ earmelf_vxworks.o \ earmnto.o \ earmnbsd.o \ earmpe.o \ earmsymbian.o \ eavr2.o \ eavr1.o \ eavr3.o \ eavr4.o \ eavr5.o \ + eavr6.o \ ecoff_i860.o \ ecoff_sparc.o \ ecrisaout.o \ ecriself.o \ ecrislinux.o \ ed10velf.o \ ed30v_e.o \ ed30v_o.o \ ed30velf.o \ edelta68.o \ eelf32_dlx.o \ eelf32_i960.o \ eelf32_i860.o \ eelf32_sparc.o \ eelf32_sparc_vxworks.o \ eelf32b4300.o \ eelf32bfin.o \ eelf32bfinfd.o \ eelf32cr16c.o \ eelf32bmip.o \ eelf32bmipn32.o \ eelf32btsmip.o \ eelf32crx.o \ eelf32btsmipn32.o \ eelf32ltsmip.o \ eelf32ltsmipn32.o \ eelf32ebmip.o \ eelf32ebmipvxworks.o \ eelf32elmip.o \ eelf32elmipvxworks.o \ eelf32fr30.o \ eelf32frv.o \ eelf32i370.o \ eelf32ip2k.o \ eelf32iq2000.o \ eelf32iq10.o \ eelf32l4300.o \ eelf32lmip.o \ eelf32lppc.o \ eelf32lppcnto.o \ eelf32lppcsim.o \ eelf32m32c.o \ eelf32mcore.o \ eelf32mipswindiss.o \ eelf32mt.o \ eelf32openrisc.o \ eelf32ppc.o \ eelf32ppc_fbsd.o \ eelf32ppclinux.o \ eelf32ppcnto.o \ eelf32ppcsim.o \ eelf32ppcwindiss.o \ eelf32ppcvxworks.o \ eelf32vax.o \ eelf32xc16x.o \ eelf32xc16xl.o \ eelf32xc16xs.o \ eelf32xstormy16.o \ eelf32xtensa.o \ eelf_i386.o \ eelf_i386_be.o \ eelf_i386_chaos.o \ @@ -536,124 +537,128 @@ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} armelf_nbsd "$(tdir_armelf_nbsd)" earmelfb_nbsd.c: $(srcdir)/emulparams/armelfb_nbsd.sh \ $(srcdir)/emulparams/armelf_nbsd.sh \ $(srcdir)/emulparams/armelf.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} armelfb_nbsd "$(tdir_armelfb_nbsd)" earmelf_vxworks.c: $(srcdir)/emulparams/armelf_vxworks.sh \ $(srcdir)/emulparams/vxworks.sh $(srcdir)/emulparams/armelf.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \ $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/elf.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} armelf_vxworks "$(tdir_armelf)" earmaoutb.c: $(srcdir)/emulparams/armaoutb.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/armaout.sc ${GEN_DEPENDS} ${GENSCRIPTS} armaoutb "$(tdir_armaoutb)" earmaoutl.c: $(srcdir)/emulparams/armaoutl.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/armaout.sc ${GEN_DEPENDS} ${GENSCRIPTS} armaoutl "$(tdir_armaoutl)" earmcoff.c: $(srcdir)/emulparams/armcoff.sh \ $(srcdir)/emultempl/armcoff.em $(srcdir)/scripttempl/armcoff.sc ${GEN_DEPENDS} ${GENSCRIPTS} armcoff "$(tdir_armcoff)" earmnbsd.c: $(srcdir)/emulparams/armnbsd.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS} ${GENSCRIPTS} armnbsd "$(tdir_armnbsd)" earmnto.c: $(srcdir)/emulparams/armnto.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} armnto "$(tdir_armnto)" earm_epoc_pe.c: $(srcdir)/emulparams/arm_epoc_pe.sh \ $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/epocpe.sc ${GEN_DEPENDS} ${GENSCRIPTS} arm_epoc_pe "$(tdir_armpe)" earmpe.c: $(srcdir)/emulparams/armpe.sh \ $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS} ${GENSCRIPTS} armpe "$(tdir_armpe)" earmsymbian.c: $(srcdir)/emulparams/armsymbian.sh \ $(srcdir)/emulparams/armelf.sh $(srcdir)/emultempl/elf32.em \ $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/armbpabi.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} armsymbian "$(tdir_armelf)" eavr2.c: $(srcdir)/emulparams/avr2.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr2 "$(tdir_avr2)" eavr1.c: $(srcdir)/emulparams/avr1.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr1 "$(tdir_avr2)" eavr3.c: $(srcdir)/emulparams/avr3.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr3 "$(tdir_avr2)" eavr4.c: $(srcdir)/emulparams/avr4.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr4 "$(tdir_avr2)" eavr5.c: $(srcdir)/emulparams/avr5.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr5 "$(tdir_avr2)" +eavr6.c: $(srcdir)/emulparams/avr6.sh \ + $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ + ${GEN_DEPENDS} + ${GENSCRIPTS} avr6 "$(tdir_avr2)" ecoff_i860.c: $(srcdir)/emulparams/coff_i860.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/i860coff.sc ${GEN_DEPENDS} ${GENSCRIPTS} coff_i860 "$(tdir_coff_i860)" ecoff_sparc.c: $(srcdir)/emulparams/coff_sparc.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/sparccoff.sc ${GEN_DEPENDS} ${GENSCRIPTS} coff_sparc "$(tdir_coff_sparc)" ecrisaout.c: $(srcdir)/emulparams/crisaout.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/crisaout.sc ${GEN_DEPENDS} ${GENSCRIPTS} crisaout "$(tdir_cris)" ecriself.c: $(srcdir)/emulparams/criself.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} criself "$(tdir_cris)" ecrislinux.c: $(srcdir)/emulparams/crislinux.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} crislinux "$(tdir_cris)" ed10velf.c: $(srcdir)/emulparams/d10velf.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elfd10v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d10velf "$(tdir_d10v)" ed30velf.c: $(srcdir)/emulparams/d30velf.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d30velf "$(tdir_d30v)" ed30v_o.c: $(srcdir)/emulparams/d30v_o.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d30v_o "$(tdir_d30v)" ed30v_e.c: $(srcdir)/emulparams/d30v_e.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d30v_e "$(tdir_d30v)" edelta68.c: $(srcdir)/emulparams/delta68.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/delta68.sc ${GEN_DEPENDS} ${GENSCRIPTS} delta68 "$(tdir_delta68)" eelf32bfin.c: $(srcdir)/emulparams/bfin.sh \ $(srcdir)/emultempl/elf32.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32bfin "$(tdir_elf32bfin)" bfin eelf32bfinfd.c: $(srcdir)/emulparams/elf32bfinfd.sh $(srcdir)/emulparams/bfin.sh \ $(srcdir)/emultempl/elf32.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32bfinfd "$(tdir_elf32bfinfd)" elf32bfinfd eelf32_dlx.c: $(srcdir)/emulparams/elf32_dlx.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/dlx.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32_dlx "$(tdir_elf32_dlx)" eelf32xc16x.c: $(srcdir)/emulparams/elf32xc16x.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xc16x "$(tdir_xc16x)" eelf32xc16xl.c: $(srcdir)/emulparams/elf32xc16xl.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xc16xl "$(tdir_xc16xl)" eelf32xc16xs.c: $(srcdir)/emulparams/elf32xc16xs.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xc16xs "$(tdir_xc16xs)" eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/xstormy16.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xstormy16 "$(tdir_xstormy16)" eelf32am33lin.c: $(srcdir)/emulparams/elf32am33lin.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32am33lin "$(tdir_mn10300)" eelf32vax.c: $(srcdir)/emulparams/elf32vax.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} Index: ld/Makefile.in =================================================================== RCS file: /cvs/src/src/ld/Makefile.in,v retrieving revision 1.223 diff -U62 -r1.223 Makefile.in --- ld/Makefile.in 11 Apr 2006 10:36:26 -0000 1.223 +++ ld/Makefile.in 1 May 2006 19:44:28 -0000 @@ -300,124 +300,125 @@ echo $$r/../gcc/xgcc -B$$r/../gcc/; \ fi; \ else \ if [ "@host@" = "@target@" ] ; then \ echo $(CC); \ else \ echo gcc | sed '$(transform)'; \ fi; \ fi` CXX = gcc CXX_FOR_TARGET = ` \ if [ -f $$r/../gcc/xgcc ] ; then \ if [ -f $$r/../newlib/Makefile ] ; then \ echo $$r/../gcc/xgcc -B$$r/../gcc/ -idirafter $$r/../newlib/targ-include -idirafter $${srcroot}/../newlib/libc/include -nostdinc; \ else \ echo $$r/../gcc/xgcc -B$$r/../gcc/; \ fi; \ else \ if [ "@host@" = "@target@" ] ; then \ echo $(CXX); \ else \ echo gcc | sed '$(transform)'; \ fi; \ fi` info_TEXINFOS = ld.texinfo noinst_TEXINFOS = ldint.texinfo man_MANS = ld.1 AM_MAKEINFOFLAGS = -I $(srcdir) -I $(BFDDIR)/doc TEXI2DVI = texi2dvi -I $(srcdir) -I $(BFDDIR)/doc INCLUDES = -D_GNU_SOURCE -I. -I$(srcdir) -I../bfd -I$(BFDDIR) -I$(INCDIR) -I$(top_srcdir)/../intl -I../intl $(HDEFINES) $(CFLAGS) -DLOCALEDIR="\"$(datadir)/locale\"" BFDLIB = ../bfd/libbfd.la LIBIBERTY = ../libiberty/libiberty.a ALL_EMULATIONS = \ eaixppc.o \ eaixrs6.o \ ealpha.o \ earcelf.o \ earm_epoc_pe.o \ earmaoutb.o \ earmaoutl.o \ earmcoff.o \ earmelf.o \ earmelfb.o \ earmelf_fbsd.o \ earmelf_linux.o \ earmelf_linux_eabi.o \ earmelfb_linux.o \ earmelfb_linux_eabi.o \ earmelf_nbsd.o \ earmelfb_nbsd.o \ earmelf_vxworks.o \ earmnto.o \ earmnbsd.o \ earmpe.o \ earmsymbian.o \ eavr2.o \ eavr1.o \ eavr3.o \ eavr4.o \ eavr5.o \ + eavr6.o \ ecoff_i860.o \ ecoff_sparc.o \ ecrisaout.o \ ecriself.o \ ecrislinux.o \ ed10velf.o \ ed30v_e.o \ ed30v_o.o \ ed30velf.o \ edelta68.o \ eelf32_dlx.o \ eelf32_i960.o \ eelf32_i860.o \ eelf32_sparc.o \ eelf32_sparc_vxworks.o \ eelf32b4300.o \ eelf32bfin.o \ eelf32bfinfd.o \ eelf32cr16c.o \ eelf32bmip.o \ eelf32bmipn32.o \ eelf32btsmip.o \ eelf32crx.o \ eelf32btsmipn32.o \ eelf32ltsmip.o \ eelf32ltsmipn32.o \ eelf32ebmip.o \ eelf32ebmipvxworks.o \ eelf32elmip.o \ eelf32elmipvxworks.o \ eelf32fr30.o \ eelf32frv.o \ eelf32i370.o \ eelf32ip2k.o \ eelf32iq2000.o \ eelf32iq10.o \ eelf32l4300.o \ eelf32lmip.o \ eelf32lppc.o \ eelf32lppcnto.o \ eelf32lppcsim.o \ eelf32m32c.o \ eelf32mcore.o \ eelf32mipswindiss.o \ eelf32mt.o \ eelf32openrisc.o \ eelf32ppc.o \ eelf32ppc_fbsd.o \ eelf32ppclinux.o \ eelf32ppcnto.o \ eelf32ppcsim.o \ eelf32ppcwindiss.o \ eelf32ppcvxworks.o \ eelf32vax.o \ eelf32xc16x.o \ eelf32xc16xl.o \ eelf32xc16xs.o \ eelf32xstormy16.o \ eelf32xtensa.o \ eelf_i386.o \ eelf_i386_be.o \ eelf_i386_chaos.o \ @@ -1346,124 +1347,128 @@ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} armelf_nbsd "$(tdir_armelf_nbsd)" earmelfb_nbsd.c: $(srcdir)/emulparams/armelfb_nbsd.sh \ $(srcdir)/emulparams/armelf_nbsd.sh \ $(srcdir)/emulparams/armelf.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} armelfb_nbsd "$(tdir_armelfb_nbsd)" earmelf_vxworks.c: $(srcdir)/emulparams/armelf_vxworks.sh \ $(srcdir)/emulparams/vxworks.sh $(srcdir)/emulparams/armelf.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \ $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/elf.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} armelf_vxworks "$(tdir_armelf)" earmaoutb.c: $(srcdir)/emulparams/armaoutb.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/armaout.sc ${GEN_DEPENDS} ${GENSCRIPTS} armaoutb "$(tdir_armaoutb)" earmaoutl.c: $(srcdir)/emulparams/armaoutl.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/armaout.sc ${GEN_DEPENDS} ${GENSCRIPTS} armaoutl "$(tdir_armaoutl)" earmcoff.c: $(srcdir)/emulparams/armcoff.sh \ $(srcdir)/emultempl/armcoff.em $(srcdir)/scripttempl/armcoff.sc ${GEN_DEPENDS} ${GENSCRIPTS} armcoff "$(tdir_armcoff)" earmnbsd.c: $(srcdir)/emulparams/armnbsd.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS} ${GENSCRIPTS} armnbsd "$(tdir_armnbsd)" earmnto.c: $(srcdir)/emulparams/armnto.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} armnto "$(tdir_armnto)" earm_epoc_pe.c: $(srcdir)/emulparams/arm_epoc_pe.sh \ $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/epocpe.sc ${GEN_DEPENDS} ${GENSCRIPTS} arm_epoc_pe "$(tdir_armpe)" earmpe.c: $(srcdir)/emulparams/armpe.sh \ $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS} ${GENSCRIPTS} armpe "$(tdir_armpe)" earmsymbian.c: $(srcdir)/emulparams/armsymbian.sh \ $(srcdir)/emulparams/armelf.sh $(srcdir)/emultempl/elf32.em \ $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/armbpabi.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} armsymbian "$(tdir_armelf)" eavr2.c: $(srcdir)/emulparams/avr2.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr2 "$(tdir_avr2)" eavr1.c: $(srcdir)/emulparams/avr1.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr1 "$(tdir_avr2)" eavr3.c: $(srcdir)/emulparams/avr3.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr3 "$(tdir_avr2)" eavr4.c: $(srcdir)/emulparams/avr4.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr4 "$(tdir_avr2)" eavr5.c: $(srcdir)/emulparams/avr5.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ ${GEN_DEPENDS} ${GENSCRIPTS} avr5 "$(tdir_avr2)" +eavr6.c: $(srcdir)/emulparams/avr6.sh \ + $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \ + ${GEN_DEPENDS} + ${GENSCRIPTS} avr6 "$(tdir_avr2)" ecoff_i860.c: $(srcdir)/emulparams/coff_i860.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/i860coff.sc ${GEN_DEPENDS} ${GENSCRIPTS} coff_i860 "$(tdir_coff_i860)" ecoff_sparc.c: $(srcdir)/emulparams/coff_sparc.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/sparccoff.sc ${GEN_DEPENDS} ${GENSCRIPTS} coff_sparc "$(tdir_coff_sparc)" ecrisaout.c: $(srcdir)/emulparams/crisaout.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/crisaout.sc ${GEN_DEPENDS} ${GENSCRIPTS} crisaout "$(tdir_cris)" ecriself.c: $(srcdir)/emulparams/criself.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} criself "$(tdir_cris)" ecrislinux.c: $(srcdir)/emulparams/crislinux.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} crislinux "$(tdir_cris)" ed10velf.c: $(srcdir)/emulparams/d10velf.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elfd10v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d10velf "$(tdir_d10v)" ed30velf.c: $(srcdir)/emulparams/d30velf.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d30velf "$(tdir_d30v)" ed30v_o.c: $(srcdir)/emulparams/d30v_o.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d30v_o "$(tdir_d30v)" ed30v_e.c: $(srcdir)/emulparams/d30v_e.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS} ${GENSCRIPTS} d30v_e "$(tdir_d30v)" edelta68.c: $(srcdir)/emulparams/delta68.sh \ $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/delta68.sc ${GEN_DEPENDS} ${GENSCRIPTS} delta68 "$(tdir_delta68)" eelf32bfin.c: $(srcdir)/emulparams/bfin.sh \ $(srcdir)/emultempl/elf32.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32bfin "$(tdir_elf32bfin)" bfin eelf32bfinfd.c: $(srcdir)/emulparams/elf32bfinfd.sh $(srcdir)/emulparams/bfin.sh \ $(srcdir)/emultempl/elf32.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32bfinfd "$(tdir_elf32bfinfd)" elf32bfinfd eelf32_dlx.c: $(srcdir)/emulparams/elf32_dlx.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/dlx.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32_dlx "$(tdir_elf32_dlx)" eelf32xc16x.c: $(srcdir)/emulparams/elf32xc16x.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xc16x "$(tdir_xc16x)" eelf32xc16xl.c: $(srcdir)/emulparams/elf32xc16xl.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xc16xl "$(tdir_xc16xl)" eelf32xc16xs.c: $(srcdir)/emulparams/elf32xc16xs.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xc16xs "$(tdir_xc16xs)" eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \ $(srcdir)/scripttempl/xstormy16.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32xstormy16 "$(tdir_xstormy16)" eelf32am33lin.c: $(srcdir)/emulparams/elf32am33lin.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} ${GENSCRIPTS} elf32am33lin "$(tdir_mn10300)" eelf32vax.c: $(srcdir)/emulparams/elf32vax.sh \ $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS} Index: ld/configure.tgt =================================================================== RCS file: /cvs/src/src/ld/configure.tgt,v retrieving revision 1.187 diff -U62 -r1.187 configure.tgt --- ld/configure.tgt 5 Apr 2006 12:41:57 -0000 1.187 +++ ld/configure.tgt 1 May 2006 19:44:28 -0000 @@ -22,125 +22,125 @@ case "${targ}" in alpha*-*-freebsd* | alpha*-*-kfreebsd*-gnu) targ_emul=elf64alpha_fbsd targ_extra_emuls="elf64alpha alpha" tdir_alpha=`echo ${targ_alias} | sed -e 's/freebsd/freebsdecoff/'` ;; alpha*-*-linuxecoff*) targ_emul=alpha targ_extra_emuls=elf64alpha tdir_elf64alpha=`echo ${targ_alias} | sed -e 's/ecoff//'` ;; alpha*-*-linux-*) targ_emul=elf64alpha targ_extra_emuls=alpha tdir_alpha=`echo ${targ_alias} | sed -e 's/linux/linuxecoff/'` ;; alpha*-*-osf*) targ_emul=alpha ;; alpha*-*-gnu*) targ_emul=elf64alpha ;; alpha*-*-netware*) targ_emul=alpha ;; alpha*-*-netbsd*) targ_emul=elf64alpha_nbsd ;; alpha*-*-openbsd*) targ_emul=elf64alpha ;; arc-*-elf*) targ_emul=arcelf ;; arm-epoc-pe) targ_emul=arm_epoc_pe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; arm-*-wince) targ_emul=armpe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; arm-*-pe) targ_emul=armpe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; arm-*-aout | armel-*-aout) targ_emul=armaoutl ;; armeb-*-aout) targ_emul=armaoutb ;; arm-*-coff) targ_emul=armcoff ;; arm-*-freebsd* | arm-*-kfreebsd*-gnu) targ_emul=armelf_fbsd targ_extra_emuls="armelf" ;; armeb-*-netbsdelf*) targ_emul=armelfb_nbsd; targ_extra_emuls="armelf_nbsd armelf armnbsd" ;; arm-*-netbsdelf*) targ_emul=armelf_nbsd; targ_extra_emuls="armelfb_nbsd armelf armnbsd" ;; arm-*-netbsd*) targ_emul=armnbsd; targ_extra_emuls="armelf armelf_nbsd armelfb_nbsd" ;; arm-*-nto*) targ_emul=armnto ;; arm-*-openbsd*) targ_emul=armnbsd ;; arm-*-rtems*) targ_emul=armelf ;; armeb-*-elf) targ_emul=armelfb ;; arm-*-elf | arm*-*-eabi*) targ_emul=armelf ;; arm*-*-symbianelf*) targ_emul=armsymbian;; arm-*-kaos*) targ_emul=armelf ;; arm9e-*-elf) targ_emul=armelf ;; arm*b-*-linux-*eabi) targ_emul=armelfb_linux_eabi ;; arm*b-*-linux-*) targ_emul=armelfb_linux; targ_extra_emuls=armelfb ;; arm*-*-linux-*eabi) targ_emul=armelf_linux_eabi ;; arm*-*-linux-*) targ_emul=armelf_linux; targ_extra_emuls=armelf ;; arm*-*-uclinux*) targ_emul=armelf_linux; targ_extra_emuls=armelf ;; arm-*-vxworks) targ_emul=armelf_vxworks ;; arm*-*-conix*) targ_emul=armelf ;; thumb-*-linux-* | thumb-*-uclinux*) targ_emul=armelf_linux; targ_extra_emuls=armelf ;; strongarm-*-coff) targ_emul=armcoff ;; strongarm-*-elf) targ_emul=armelf ;; strongarm-*-kaos*) targ_emul=armelf ;; thumb-*-coff) targ_emul=armcoff ;; thumb-*-elf) targ_emul=armelf ;; thumb-epoc-pe) targ_emul=arm_epoc_pe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; thumb-*-pe) targ_emul=armpe ; targ_extra_ofiles="deffilep.o pe-dll.o" ;; xscale-*-coff) targ_emul=armcoff ;; xscale-*-elf) targ_emul=armelf ;; avr-*-*) targ_emul=avr2 - targ_extra_emuls="avr1 avr3 avr4 avr5" + targ_extra_emuls="avr1 avr3 avr4 avr5 avr6" ;; bfin-*-elf) targ_emul=elf32bfin; targ_extra_emuls="elf32bfinfd" ;; bfin-*-uclinux*) targ_emul=elf32bfin; targ_extra_emuls="elf32bfinfd" ;; cr16c-*-elf*) targ_emul=elf32cr16c ;; cris-*-*aout*) targ_emul=crisaout targ_extra_emuls="criself crislinux" targ_extra_libpath=$targ_extra_emuls ;; cris-*-linux-* | crisv32-*-linux-*) targ_emul=crislinux ;; cris-*-* | crisv32-*-*) targ_emul=criself targ_extra_emuls="crisaout crislinux" targ_extra_libpath=$targ_extra_emuls ;; crx-*-elf*) targ_emul=elf32crx ;; d10v-*-*) targ_emul=d10velf ;; d30v-*-*ext*) targ_emul=d30v_e; targ_extra_emuls="d30velf d30v_o" ;; d30v-*-*onchip*) targ_emul=d30v_o; targ_extra_emuls="d30velf d30v_e" ;; d30v-*-*) targ_emul=d30velf; targ_extra_emuls="d30v_e d30v_o" ;; dlx-*-elf*) targ_emul=elf32_dlx ;; fr30-*-*) targ_emul=elf32fr30 ;; frv-*-*linux*) targ_emul=elf32frvfd ;; frv-*-*) targ_emul=elf32frv ; targ_extra_emuls="elf32frvfd" ;; h8300-*-hms* | h8300-*-coff* | h8300-*-rtemscoff*) targ_emul=h8300; targ_extra_emuls="h8300h h8300s h8300hn h8300sn h8300sx h8300sxn" ;; h8300-*-elf* | h8300-*-rtems*) targ_emul=h8300elf; targ_extra_emuls="h8300helf h8300self h8300hnelf h8300snelf h8300sxelf h8300sxnelf" ;; h8500-*-hms* | h8500-*-coff* | h8500-*-rtems*) targ_emul=h8500 targ_extra_emuls="h8500s h8500b h8500m h8500c" ;; hppa*64*-*-linux-*) targ_emul=hppa64linux ;; hppa*64*-*) targ_emul=elf64hppa ;; hppa*-*-linux-*) targ_emul=hppalinux ;; hppa*-*-*elf*) targ_emul=hppaelf ;; hppa*-*-lites*) targ_emul=hppaelf ;; hppa*-*-netbsd*) targ_emul=hppanbsd ;; hppa*-*-openbsd*) targ_emul=hppaobsd ;; i370-*-elf* | i370-*-linux-*) targ_emul=elf32i370 ;; i[3-7]86-*-nto-qnx*) targ_emul=i386nto ;; i[3-7]86-*-vsta) targ_emul=vsta ;; i[3-7]86-*-go32) targ_emul=i386go32 ;; i[3-7]86-*-msdosdjgpp*) targ_emul=i386go32 ;; i[3-7]86-*-aix*) targ_emul=i386coff ;; i[3-7]86-*-sco*) targ_emul=i386coff ;; i[3-7]86-*-isc*) targ_emul=i386coff ;; i[3-7]86-*-lynxos*) targ_emul=i386lynx ;; i[3-7]86-*-coff) targ_emul=i386coff ;; i[3-7]86-*-rtems*) targ_emul=elf_i386 ;; i[3-7]86-*-aros*) targ_emul=elf_i386 ;; i[3-7]86-*-rdos*) targ_emul=elf_i386 ;; i[3-7]86-*-bsd) targ_emul=i386bsd ;; i[3-7]86-*-bsd386) targ_emul=i386bsd ;; i[3-7]86-*-bsdi*) targ_emul=i386bsd ;; Index: ld/emulparams/avr1.sh =================================================================== RCS file: /cvs/src/src/ld/emulparams/avr1.sh,v retrieving revision 1.1 diff -U62 -r1.1 avr1.sh --- ld/emulparams/avr1.sh 16 May 2002 19:51:08 -0000 1.1 +++ ld/emulparams/avr1.sh 1 May 2006 19:44:28 -0000 @@ -1,10 +1,12 @@ ARCH=avr:1 MACHINE= SCRIPT_NAME=avr OUTPUT_FORMAT="elf32-avr" MAXPAGESIZE=1 EMBEDDED=yes -TEMPLATE_NAME=generic +TEMPLATE_NAME=elf32 TEXT_LENGTH=8K DATA_LENGTH=0 +EXTRA_EM_FILE=avrelf + Index: ld/emulparams/avr2.sh =================================================================== RCS file: /cvs/src/src/ld/emulparams/avr2.sh,v retrieving revision 1.1 diff -U62 -r1.1 avr2.sh --- ld/emulparams/avr2.sh 16 May 2002 19:51:08 -0000 1.1 +++ ld/emulparams/avr2.sh 1 May 2006 19:44:28 -0000 @@ -1,10 +1,12 @@ ARCH=avr:2 MACHINE= SCRIPT_NAME=avr OUTPUT_FORMAT="elf32-avr" MAXPAGESIZE=1 EMBEDDED=yes -TEMPLATE_NAME=generic +TEMPLATE_NAME=elf32 TEXT_LENGTH=8K DATA_LENGTH=0xffa0 +EXTRA_EM_FILE=avrelf + Index: ld/emulparams/avr3.sh =================================================================== RCS file: /cvs/src/src/ld/emulparams/avr3.sh,v retrieving revision 1.1 diff -U62 -r1.1 avr3.sh --- ld/emulparams/avr3.sh 16 May 2002 19:51:08 -0000 1.1 +++ ld/emulparams/avr3.sh 1 May 2006 19:44:28 -0000 @@ -1,10 +1,13 @@ ARCH=avr:3 MACHINE= SCRIPT_NAME=avr OUTPUT_FORMAT="elf32-avr" MAXPAGESIZE=1 EMBEDDED=yes -TEMPLATE_NAME=generic +TEMPLATE_NAME=elf32 TEXT_LENGTH=128K DATA_LENGTH=0xffa0 + +EXTRA_EM_FILE=avrelf + Index: ld/emulparams/avr4.sh =================================================================== RCS file: /cvs/src/src/ld/emulparams/avr4.sh,v retrieving revision 1.1 diff -U62 -r1.1 avr4.sh --- ld/emulparams/avr4.sh 16 May 2002 19:51:08 -0000 1.1 +++ ld/emulparams/avr4.sh 1 May 2006 19:44:28 -0000 @@ -1,10 +1,12 @@ ARCH=avr:4 MACHINE= SCRIPT_NAME=avr OUTPUT_FORMAT="elf32-avr" MAXPAGESIZE=1 EMBEDDED=yes -TEMPLATE_NAME=generic +TEMPLATE_NAME=elf32 TEXT_LENGTH=8K DATA_LENGTH=0xffa0 + +EXTRA_EM_FILE=avrelf Index: ld/emulparams/avr5.sh =================================================================== RCS file: /cvs/src/src/ld/emulparams/avr5.sh,v retrieving revision 1.1 diff -U62 -r1.1 avr5.sh --- ld/emulparams/avr5.sh 16 May 2002 19:51:08 -0000 1.1 +++ ld/emulparams/avr5.sh 1 May 2006 19:44:28 -0000 @@ -1,10 +1,11 @@ ARCH=avr:5 MACHINE= SCRIPT_NAME=avr OUTPUT_FORMAT="elf32-avr" MAXPAGESIZE=1 EMBEDDED=yes -TEMPLATE_NAME=generic +TEMPLATE_NAME=elf32 TEXT_LENGTH=128K DATA_LENGTH=0xffa0 +EXTRA_EM_FILE=avrelf Index: ld/scripttempl/avr.sc =================================================================== RCS file: /cvs/src/src/ld/scripttempl/avr.sc,v retrieving revision 1.4 diff -U62 -r1.4 avr.sc --- ld/scripttempl/avr.sc 3 Mar 2006 15:25:31 -0000 1.4 +++ ld/scripttempl/avr.sc 1 May 2006 19:44:28 -0000 @@ -18,144 +18,155 @@ .dynstr ${RELOCATING-0} : { *(.dynstr) } .gnu.version ${RELOCATING-0} : { *(.gnu.version) } .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d) } .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r) } .rel.init ${RELOCATING-0} : { *(.rel.init) } .rela.init ${RELOCATING-0} : { *(.rela.init) } .rel.text ${RELOCATING-0} : { *(.rel.text) ${RELOCATING+*(.rel.text.*)} ${RELOCATING+*(.rel.gnu.linkonce.t*)} } .rela.text ${RELOCATING-0} : { *(.rela.text) ${RELOCATING+*(.rela.text.*)} ${RELOCATING+*(.rela.gnu.linkonce.t*)} } .rel.fini ${RELOCATING-0} : { *(.rel.fini) } .rela.fini ${RELOCATING-0} : { *(.rela.fini) } .rel.rodata ${RELOCATING-0} : { *(.rel.rodata) ${RELOCATING+*(.rel.rodata.*)} ${RELOCATING+*(.rel.gnu.linkonce.r*)} } .rela.rodata ${RELOCATING-0} : { *(.rela.rodata) ${RELOCATING+*(.rela.rodata.*)} ${RELOCATING+*(.rela.gnu.linkonce.r*)} } .rel.data ${RELOCATING-0} : { *(.rel.data) ${RELOCATING+*(.rel.data.*)} ${RELOCATING+*(.rel.gnu.linkonce.d*)} } .rela.data ${RELOCATING-0} : { *(.rela.data) ${RELOCATING+*(.rela.data.*)} ${RELOCATING+*(.rela.gnu.linkonce.d*)} } .rel.ctors ${RELOCATING-0} : { *(.rel.ctors) } .rela.ctors ${RELOCATING-0} : { *(.rela.ctors) } .rel.dtors ${RELOCATING-0} : { *(.rel.dtors) } .rela.dtors ${RELOCATING-0} : { *(.rela.dtors) } .rel.got ${RELOCATING-0} : { *(.rel.got) } .rela.got ${RELOCATING-0} : { *(.rela.got) } .rel.bss ${RELOCATING-0} : { *(.rel.bss) } .rela.bss ${RELOCATING-0} : { *(.rela.bss) } .rel.plt ${RELOCATING-0} : { *(.rel.plt) } .rela.plt ${RELOCATING-0} : { *(.rela.plt) } /* Internal text space or external memory */ .text : { *(.vectors) KEEP(*(.vectors)) + /* For data that needs to reside in the lower 64k of progmem */ + *(.progmem.gcc*) + *(.progmem*) + ${RELOCATING+. = ALIGN(2);} + + ${CONSTRUCTING+ __trampolines_start = . ; } + /* The jump trampolines for the 16-bit limited relocs will reside here. */ + *(.trampolines) + *(.trampolines*) + ${CONSTRUCTING+ __trampolines_end = . ; } + + /* for future tablejump instruction arrays for 3 byte pc devices. + we don't relax jump/call instructions within these sections. */ + *(.jumptables) + *(.jumptables*) + + /* for code that needs to reside in the lower 128k progmem */ + *(.lowtext) + *(.lowtext*) + ${CONSTRUCTING+ __ctors_start = . ; } ${CONSTRUCTING+ *(.ctors) } ${CONSTRUCTING+ __ctors_end = . ; } ${CONSTRUCTING+ __dtors_start = . ; } ${CONSTRUCTING+ *(.dtors) } ${CONSTRUCTING+ __dtors_end = . ; } KEEP(SORT(*)(.ctors)) KEEP(SORT(*)(.dtors)) - /* For data that needs to reside in the lower 64k of progmem */ - *(.progmem.gcc*) - *(.progmem*) - ${RELOCATING+. = ALIGN(2);} - - /* for future tablejump instruction arrays for 3 byte pc devices */ - *(.jumptables) - *(.jumptables*) - /* for code that needs to reside in the lower 128k progmem */ - *(.lowtext) - *(.lowtext*) + /* From this point on, we don't bother about wether the insns are + below or above the 16 bits boundary. */ *(.init0) /* Start here after reset. */ KEEP (*(.init0)) *(.init1) KEEP (*(.init1)) *(.init2) /* Clear __zero_reg__, set up stack pointer. */ KEEP (*(.init2)) *(.init3) KEEP (*(.init3)) *(.init4) /* Initialize data and BSS. */ KEEP (*(.init4)) *(.init5) KEEP (*(.init5)) *(.init6) /* C++ constructors. */ KEEP (*(.init6)) *(.init7) KEEP (*(.init7)) *(.init8) KEEP (*(.init8)) *(.init9) /* Call main(). */ KEEP (*(.init9)) *(.text) ${RELOCATING+. = ALIGN(2);} *(.text.*) ${RELOCATING+. = ALIGN(2);} *(.fini9) /* _exit() starts here. */ KEEP (*(.fini9)) *(.fini8) KEEP (*(.fini8)) *(.fini7) KEEP (*(.fini7)) *(.fini6) /* C++ destructors. */ KEEP (*(.fini6)) *(.fini5) KEEP (*(.fini5)) *(.fini4) KEEP (*(.fini4)) *(.fini3) KEEP (*(.fini3)) *(.fini2) KEEP (*(.fini2)) *(.fini1) KEEP (*(.fini1)) *(.fini0) /* Infinite loop after program termination. */ KEEP (*(.fini0)) ${RELOCATING+ _etext = . ; } } ${RELOCATING+ > text} .data ${RELOCATING-0} : ${RELOCATING+AT (ADDR (.text) + SIZEOF (.text))} { ${RELOCATING+ PROVIDE (__data_start = .) ; } *(.data) *(.data*) *(.rodata) /* We need to include .rodata here if gcc is used */ *(.rodata*) /* with -fdata-sections. */ *(.gnu.linkonce.d*) ${RELOCATING+. = ALIGN(2);} ${RELOCATING+ _edata = . ; } ${RELOCATING+ PROVIDE (__data_end = .) ; } } ${RELOCATING+ > data} .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} : --- /dev/null 2004-10-02 05:17:35.000000000 +0200 +++ bfd/elf32-avr.h 2006-04-30 11:03:04.000000000 +0200 @@ -0,0 +1,48 @@ +/* AVR-specific support for 32-bit ELF. + Copyright 2006 Free Software Foundation, Inc. + + Written by Bjoern Haase + +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., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + + +/* These four functions will be called from the ld back-end. */ + +void +elf32_avr_setup_params (struct bfd_link_info *info, + bfd *avr_stub_bfd, + asection *avr_stub_section, + bfd_boolean no_stubs, + bfd_boolean deb_stubs, + bfd_boolean deb_relax, + bfd_vma pc_wrap_around, + bfd_boolean call_ret_replacement); + +int +elf32_avr_setup_section_lists (bfd *abfd, + struct bfd_link_info *info); + +bfd_boolean +elf32_avr_size_stubs (bfd *output_bfd, + struct bfd_link_info *info, + bfd_boolean is_prealloc_run); + +bfd_boolean +elf32_avr_build_stubs (struct bfd_link_info *info); + + --- /dev/null 2004-10-02 05:17:35.000000000 +0200 +++ ld/emulparams/avr6.sh 2006-04-23 06:31:39.000000000 +0200 @@ -0,0 +1,11 @@ +ARCH=avr:6 +MACHINE= +SCRIPT_NAME=avr +OUTPUT_FORMAT="elf32-avr" +MAXPAGESIZE=1 +EMBEDDED=yes +TEMPLATE_NAME=elf32 + +TEXT_LENGTH=1024K +DATA_LENGTH=0xffa0 +EXTRA_EM_FILE=avrelf --- /dev/null 2004-10-02 05:17:35.000000000 +0200 +++ ld/emultempl/avrelf.em 2006-05-01 08:15:48.277877784 +0200 @@ -0,0 +1,268 @@ +# This shell script emits a C file. -*- C -*- +# Copyright 2006 +# Free Software Foundation, Inc. +# +# This file is part of GLD, the Gnu Linker. +# +# 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., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301 USA. + +# This file is sourced from elf32.em, and defines extra avr-elf +# specific routines. It is used to generate the trampolines for the avr6 +# family devices where one needs to address the issue that it is not possible +# to reach the whole program memory by using 16 bit pointers. + +cat >>e${EMULATION_NAME}.c <the_bfd, + avr_stub_section, + avr_no_stubs, + avr_debug_stubs, + avr_debug_relax, + avr_pc_wrap_around, + avr_replace_call_ret_sequences); +} + + +/* Makes a conservative estimate of the trampoline section size that could + be corrected later on. */ +static void +avr_elf_${EMULATION_NAME}_before_allocation (void) +{ + int ret; + + gld${EMULATION_NAME}_before_allocation (); + + + avr_elf_set_global_bfd_parameters (); + + /* If generating a relocatable output file, then we don't + have to generate the trampolines. */ + if (link_info.relocatable) + return; + + if (!avr_no_stubs) + ret = elf32_avr_setup_section_lists (output_bfd, &link_info); + else + ret = 0; + + if (ret != 0) + { + if (ret < 0) + { + einfo ("%X%P: can not setup the input section list: %E\n"); + return; + } + + /* Call into the BFD backend to do the real "stub"-work. */ + if (!elf32_avr_size_stubs (output_bfd,&link_info,TRUE)) + { + einfo ("%X%P: can not size stub section: %E\n"); + return; + } + } +} + +/* This is called before the input files are opened. We create a new + fake input file to hold the stub section and generate the section itself. */ + +static void +avr_elf_create_output_section_statements (void) +{ + flagword flags; + + stub_file = lang_add_input_file ("linker stubs", + lang_input_file_is_fake_enum, + NULL); + + stub_file->the_bfd = bfd_create ("linker stubs", output_bfd); + if (stub_file->the_bfd == NULL + || !bfd_set_arch_mach (stub_file->the_bfd, + bfd_get_arch (output_bfd), + bfd_get_mach (output_bfd))) + { + einfo ("%X%P: can not create stub BFD %E\n"); + return; + } + + /* Now we add the stub section. */ + + avr_stub_section = bfd_make_section_anyway (stub_file->the_bfd, + ".trampolines"); + if (avr_stub_section == NULL) + goto err_ret; + + flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE + | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP); + if (!bfd_set_section_flags (stub_file->the_bfd, avr_stub_section, flags)) + goto err_ret; + + avr_stub_section->alignment_power = 1; + + ldlang_add_file (stub_file); + + return; + + err_ret: + einfo ("%X%P: can not make stub section: %E\n"); + return; +} + +/* Re-calculates the size of the stubs so that we won't waste space. */ +static void +avr_elf_finish (void) +{ + if (!avr_no_stubs) + { + /* Now build the linker stubs. */ + if (stub_file->the_bfd->sections != NULL) + { + /* Call again the trampoline analyzer to initialize the trampoline + stubs with the correct symbol addresses. Since there could have + been relaxation, the symbol addresses that were found during + first call may no longer be correct. */ + if (!elf32_avr_size_stubs (output_bfd,&link_info,FALSE)) + { + einfo ("%X%P: can not size stub section: %E\n"); + return; + } + if (!elf32_avr_build_stubs (&link_info)) + einfo ("%X%P: can not build stubs: %E\n"); + } + } + + gld${EMULATION_NAME}_finish (); +} + + +EOF + + +PARSE_AND_LIST_PROLOGUE=' + +#define OPTION_NO_CALL_RET_REPLACEMENT 301 +#define OPTION_PMEM_WRAP_AROUND 302 +#define OPTION_NO_STUBS 303 +#define OPTION_DEBUG_STUBS 304 +#define OPTION_DEBUG_RELAX 305 +' + +PARSE_AND_LIST_LONGOPTS=' + { "no-call-ret-replacement", no_argument, + NULL, OPTION_NO_CALL_RET_REPLACEMENT}, + { "pmem-wrap-around", required_argument, + NULL, OPTION_PMEM_WRAP_AROUND}, + { "no-stubs", no_argument, + NULL, OPTION_NO_STUBS}, + { "debug-stubs", no_argument, + NULL, OPTION_DEBUG_STUBS}, + { "debug-relax", no_argument, + NULL, OPTION_DEBUG_RELAX}, +' + +PARSE_AND_LIST_OPTIONS=' + fprintf (file, _(" --pmem-wrap-around= " + "Make the linker relaxation machine assume that a\n" + " " + "program counter wrap-around occures at address\n" + " " + ". Supported values are 16k, 32k and 64k.\n")); + fprintf (file, _(" --no-call-ret-replacement " + "The relaxation machine normally will\n" + " " + "substitute two immediately following call/ret\n" + " " + "instructions by a single jump instruction.\n" + " " + "This option disables this optimization.\n")); + fprintf (file, _(" --no-stubs " + "If the linker detects to attempt to access\n" + " " + "an instruction beyond 128k by a reloc that\n" + " " + "is limited to 128k max, it inserts a jump\n" + " " + "stub. You can de-active this with this switch.\n")); + fprintf (file, _(" --debug-stubs Used for debugging avr-ld.\n")); + fprintf (file, _(" --debug-relax Used for debugging avr-ld.\n")); +' + +PARSE_AND_LIST_ARGS_CASES=' + + case OPTION_PMEM_WRAP_AROUND: + { + /* This variable is defined in the bfd library. */ + if ((!strcmp (optarg,"32k")) + || (!strcmp (optarg,"32K"))) + avr_pc_wrap_around = 32768; + else if ((!strcmp (optarg,"16k")) + || (!strcmp (optarg,"16K"))) + avr_pc_wrap_around = 16384; + else if ((!strcmp (optarg,"64k")) + || (!strcmp (optarg,"64K"))) + avr_pc_wrap_around = 0x10000; + else + return FALSE; + } + break; + + case OPTION_DEBUG_STUBS: + avr_debug_stubs = TRUE; + break; + + case OPTION_DEBUG_RELAX: + avr_debug_relax = TRUE; + break; + + case OPTION_NO_STUBS: + avr_no_stubs = TRUE; + break; + + case OPTION_NO_CALL_RET_REPLACEMENT: + { + /* This variable is defined in the bfd library. */ + avr_replace_call_ret_sequences = FALSE; + } + break; +' + +# +# Put these extra avr-elf routines in ld_${EMULATION_NAME}_emulation +# +LDEMUL_BEFORE_ALLOCATION=avr_elf_${EMULATION_NAME}_before_allocation +LDEMUL_FINISH=avr_elf_finish +LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=avr_elf_create_output_section_statements +