From 51c892357c62187fa462745acca179c26ccb66b8 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 27 May 2009 13:31:23 +0000 Subject: [PATCH] bfd/ * elf32-ppc.c (ppc_elf_relax_section): Work with a partial link. * bout.c (b_out_bfd_relax_section): Reject relocatable links. * elf32-m10300.c (mn10300_elf_relax_section): Likewise. * elf32-avr.c (elf32_avr_relax_section): Likewise. * elf32-frv.c (elf32_avr_relax_section): Likewise. * elf32-xtensa.c (elf_xtensa_relax_section): Likewise. * elf64-mmix.c (mmix_elf_relax_section): Likewise. * elfxx-ia64.c (elfNN_ia64_relax_section): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_relax_section): Likewise. * reloc.c (bfd_generic_relax_section): Likewise. * reloc16.c (bfd_coff_reloc16_relax_section): Likewise. * vms.c (vms_bfd_relax_section): Likewise. ld/ * ldmain.c (main): Don't reject --relax -r. * ld.texinfo (PowerPC ELF32): Document behaviour of relaxing partial links. ld/testsuite/ * ld-powerpc/vxworks-relax-2.s: New. * ld-powerpc/vxworks-relax-2.rd: New. * ld-powerpc/powerpc.exp: Add it. --- bfd/ChangeLog | 16 ++++++++++++++++ bfd/bout.c | 4 ++++ bfd/elf-m10300.c | 4 ++++ bfd/elf32-avr.c | 4 ++++ bfd/elf32-frv.c | 4 ++++ bfd/elf32-ppc.c | 42 ++++++++++++++++++++++++++++++++++++++++-- bfd/elf32-xtensa.c | 4 ++++ bfd/elf64-mmix.c | 4 ++++ bfd/elfxx-ia64.c | 4 ++++ bfd/elfxx-sparc.c | 4 ++++ bfd/reloc.c | 4 ++++ bfd/reloc16.c | 4 ++++ bfd/vms.c | 4 ++++ 13 files changed, 100 insertions(+), 2 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8d2283e34e..e7f6f3bf17 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,19 @@ +2009-05-27 Nathan Sidwell + + * elf32-ppc.c (ppc_elf_relax_section): Work with a partial + link. + * bout.c (b_out_bfd_relax_section): Reject relocatable links. + * elf32-m10300.c (mn10300_elf_relax_section): Likewise. + * elf32-avr.c (elf32_avr_relax_section): Likewise. + * elf32-frv.c (elf32_avr_relax_section): Likewise. + * elf32-xtensa.c (elf_xtensa_relax_section): Likewise. + * elf64-mmix.c (mmix_elf_relax_section): Likewise. + * elfxx-ia64.c (elfNN_ia64_relax_section): Likewise. + * elfxx-sparc.c (_bfd_sparc_elf_relax_section): Likewise. + * reloc.c (bfd_generic_relax_section): Likewise. + * reloc16.c (bfd_coff_reloc16_relax_section): Likewise. + * vms.c (vms_bfd_relax_section): Likewise. + 2009-05-26 H.J. Lu * elf-bfd.h (_bfd_elf_is_ifunc_symbol): New. diff --git a/bfd/bout.c b/bfd/bout.c index f4800d5acd..485371d393 100644 --- a/bfd/bout.c +++ b/bfd/bout.c @@ -1145,6 +1145,10 @@ b_out_bfd_relax_section (bfd *abfd, arelent **reloc_vector = NULL; long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section); + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + if (reloc_size < 0) return FALSE; diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index d41906ce19..d3270c5dbb 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -2073,6 +2073,10 @@ mn10300_elf_relax_section (bfd *abfd, asection *section = sec; bfd_vma align_gap_adjustment; + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + /* Assume nothing changes. */ *again = FALSE; diff --git a/bfd/elf32-avr.c b/bfd/elf32-avr.c index 9190db35d5..1b66123745 100644 --- a/bfd/elf32-avr.c +++ b/bfd/elf32-avr.c @@ -1634,6 +1634,10 @@ elf32_avr_relax_section (bfd *abfd, static Elf_Internal_Rela *last_reloc = NULL; struct elf32_avr_link_hash_table *htab; + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + htab = avr_link_hash_table (link_info); if (htab == NULL) return FALSE; diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c index 01e15f9604..fdf96a5bfc 100644 --- a/bfd/elf32-frv.c +++ b/bfd/elf32-frv.c @@ -5738,6 +5738,10 @@ elf32_frvfdpic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, { struct _frvfdpic_dynamic_got_plt_info gpinfo; + if (info->relocatable) + (*info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + /* If we return early, we didn't change anything. */ *again = FALSE; diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index e15f88e747..dcf33cc3da 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -5661,6 +5661,12 @@ ppc_elf_relax_section (bfd *abfd, || isec->reloc_count == 0) return TRUE; + /* We cannot represent the required PIC relocs in the output, so don't + do anything. The linker doesn't support mixing -shared and -r + anyway. */ + if (link_info->relocatable && link_info->shared) + return TRUE; + trampoff = (isec->size + 3) & (bfd_vma) -4; /* Space for a branch around any trampolines. */ trampoff += 4; @@ -5726,7 +5732,7 @@ ppc_elf_relax_section (bfd *abfd, } isym = isymbuf + ELF32_R_SYM (irel->r_info); if (isym->st_shndx == SHN_UNDEF) - continue; /* We can't do anything with undefined symbols. */ + tsec = bfd_und_section_ptr; else if (isym->st_shndx == SHN_ABS) tsec = bfd_abs_section_ptr; else if (isym->st_shndx == SHN_COMMON) @@ -5779,6 +5785,12 @@ ppc_elf_relax_section (bfd *abfd, tsec = h->root.u.def.section; toff = h->root.u.def.value; } + else if (h->root.type == bfd_link_hash_undefined + || h->root.type == bfd_link_hash_undefweak) + { + tsec = bfd_und_section_ptr; + toff = 0; + } else continue; @@ -5838,7 +5850,12 @@ ppc_elf_relax_section (bfd *abfd, reladdr = isec->output_section->vma + isec->output_offset + roff; /* If the branch is in range, no need to do anything. */ - if (symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) + if (tsec != bfd_und_section_ptr + && (!link_info->relocatable + /* A relocatable link may have sections moved during + final link, so do not presume they remain in range. */ + || tsec->output_section == isec->output_section) + && symaddr - reladdr + max_branch_offset < 2 * max_branch_offset) continue; /* Look for an existing fixup to this address. */ @@ -6048,6 +6065,27 @@ ppc_elf_relax_section (bfd *abfd, free (internal_relocs); *again = changes != 0; + if (!*again && link_info->relocatable) + { + /* Convert the internal relax relocs to external form. */ + for (irel = internal_relocs; irel < irelend; irel++) + if (ELF32_R_TYPE (irel->r_info) == R_PPC_RELAX32) + { + unsigned long r_symndx = ELF32_R_SYM (irel->r_info); + + /* Rewrite the reloc and convert one of the trailing nop + relocs to describe this relocation. */ + BFD_ASSERT (ELF32_R_TYPE (irelend[-1].r_info) == R_PPC_NONE); + /* The relocs are at the bottom 2 bytes */ + irel[0].r_offset += 2; + memmove (irel + 1, irel, (irelend - irel - 1) * sizeof (*irel)); + irel[0].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_HA); + irel[1].r_offset += 4; + irel[1].r_info = ELF32_R_INFO (r_symndx, R_PPC_ADDR16_LO); + irel++; + } + } + return TRUE; error_return: diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index 0315c2ff4f..09e81ad82e 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -6638,6 +6638,10 @@ elf_xtensa_relax_section (bfd *abfd, static bfd_boolean relocations_analyzed = FALSE; xtensa_relax_info *relax_info; + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + if (!relocations_analyzed) { /* Do some overall initialization for relaxation. */ diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c index 479304769a..9669fdb669 100644 --- a/bfd/elf64-mmix.c +++ b/bfd/elf64-mmix.c @@ -2590,6 +2590,10 @@ mmix_elf_relax_section (abfd, sec, link_info, again) /* Assume nothing changes. */ *again = FALSE; + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + /* We don't have to do anything if this section does not have relocs, or if this is not a code section. */ if ((sec->flags & SEC_RELOC) == 0 diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c index b6f103a7e7..c7cfbe9295 100644 --- a/bfd/elfxx-ia64.c +++ b/bfd/elfxx-ia64.c @@ -786,6 +786,10 @@ elfNN_ia64_relax_section (bfd *abfd, asection *sec, one pass. */ *again = FALSE; + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + /* Don't even try to relax for non-ELF outputs. */ if (!is_elf_hash_table (link_info->hash)) return FALSE; diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index 6449f3b764..9acdfc4d3c 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -2453,6 +2453,10 @@ _bfd_sparc_elf_relax_section (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED, bfd_boolean *again) { + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + *again = FALSE; sec_do_relax (section) = 1; return TRUE; diff --git a/bfd/reloc.c b/bfd/reloc.c index 5e10e7ed70..66fb672dba 100644 --- a/bfd/reloc.c +++ b/bfd/reloc.c @@ -5291,6 +5291,10 @@ bfd_generic_relax_section (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED, bfd_boolean *again) { + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + *again = FALSE; return TRUE; } diff --git a/bfd/reloc16.c b/bfd/reloc16.c index b4087cbd58..85a39ca19a 100644 --- a/bfd/reloc16.c +++ b/bfd/reloc16.c @@ -157,6 +157,10 @@ bfd_coff_reloc16_relax_section (abfd, input_section, link_info, again) arelent **reloc_vector = NULL; long reloc_count; + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + /* We only do global relaxation once. It is not safe to do it multiple times (see discussion of the "shrinks" array below). */ *again = FALSE; diff --git a/bfd/vms.c b/bfd/vms.c index ac03480278..251b95cbd6 100644 --- a/bfd/vms.c +++ b/bfd/vms.c @@ -1914,6 +1914,10 @@ vms_bfd_relax_section (bfd * abfd ATTRIBUTE_UNUSED, struct bfd_link_info *link_info ATTRIBUTE_UNUSED, bfd_boolean *again ATTRIBUTE_UNUSED) { + if (link_info->relocatable) + (*link_info->callbacks->einfo) + (_("%P%F: --relax and -r may not be used together\n")); + #if VMS_DEBUG vms_debug (1, "vms_bfd_relax_section (%p, %s, %p, )\n", abfd, section->name, link_info); -- 2.11.0