bfd/
authorNathan Sidwell <nathan@codesourcery.com>
Wed, 27 May 2009 13:31:24 +0000 (13:31 +0000)
committerNathan Sidwell <nathan@codesourcery.com>
Wed, 27 May 2009 13:31:24 +0000 (13:31 +0000)
* 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.

20 files changed:
bfd/ChangeLog
bfd/bout.c
bfd/elf-m10300.c
bfd/elf32-avr.c
bfd/elf32-frv.c
bfd/elf32-ppc.c
bfd/elf32-xtensa.c
bfd/elf64-mmix.c
bfd/elfxx-ia64.c
bfd/elfxx-sparc.c
bfd/reloc.c
bfd/reloc16.c
bfd/vms.c
ld/ChangeLog
ld/ld.texinfo
ld/ldmain.c
ld/testsuite/ChangeLog
ld/testsuite/ld-powerpc/powerpc.exp
ld/testsuite/ld-powerpc/vxworks-relax-2.rd [new file with mode: 0644]
ld/testsuite/ld-powerpc/vxworks-relax-2.s [new file with mode: 0644]

index 8d2283e34e83f63f37a663d27fb5574c5d87ee62..e7f6f3bf17f56670357c355d52fc7769a621d5b0 100644 (file)
@@ -1,3 +1,19 @@
+2009-05-27  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * 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  <hongjiu.lu@intel.com>
 
        * elf-bfd.h (_bfd_elf_is_ifunc_symbol): New.
index f4800d5acdc2664b192bfcd0dd1e53c76e9a9c0f..485371d393ac9031dd2484c70fe4d2fcd80eebbe 100644 (file)
@@ -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;
 
index d41906ce1983645e6a6782c132675fa41f616a15..d3270c5dbb87ec502d73ab964d06a4b0f28512a0 100644 (file)
@@ -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;
 
index 9190db35d5b7d8759805c79caf2b2b93737a801e..1b6612374564550f9af3956c51d6eda2313d4bd8 100644 (file)
@@ -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;
index 01e15f9604430f54be6e69c80ce34c5558f572e4..fdf96a5bfc6327d1238c6098be7193e2f3e3a804 100644 (file)
@@ -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;
 
index e15f88e7479a31589a09773b1ecc505626a0669b..dcf33cc3daa8b58a3b80936bf6930c2b0e05d5fa 100644 (file)
@@ -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:
index 0315c2ff4f49b7a12052fadc03333e7e2cc42a9c..09e81ad82eeba1bead1d51cb23d043f7558b3cf3 100644 (file)
@@ -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.  */
index 479304769a79296771da3eaf58419ba6cdedddd0..9669fdb6698c86903590880cf3cff83f9edd32b9 100644 (file)
@@ -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
index b6f103a7e7ea50113ce2ab4e012fda6175e5f6c4..c7cfbe929567e7fd85b1848cc867930c99efbf17 100644 (file)
@@ -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;
index 6449f3b764e6b6ce91a7f548ca0173a3050ec9f2..9acdfc4d3c948cac83ecbb8768db3cd4638d3d8f 100644 (file)
@@ -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;
index 5e10e7ed7084b71b73a352a8d93f9c5ffb924cdf..66fb672dba39d575acbf139c5a2350de68c0899e 100644 (file)
@@ -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;
 }
index b4087cbd58abd09e3609ff03abc1a2e45233184d..85a39ca19a74936a7ce1b7c984c3b0e250422570 100644 (file)
@@ -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;
index ac03480278d3875be97538bebf4e193f9f70a870..251b95cbd615ff7d0b0b66c466d55076eb360890 100644 (file)
--- 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, <ret>)\n",
             abfd, section->name, link_info);
index b996d65d2394238eb1d462a39f8fb9ba4de83f42..9c02e69ea22360ff1e884542f4ee12b292477116 100644 (file)
@@ -1,3 +1,9 @@
+2009-05-26  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * ldmain.c (main): Don't reject --relax -r.
+       * ld.texinfo (PowerPC ELF32): Document behaviour of relaxing
+       partial links.
+
 2009-05-26  Nick Clifton  <nickc@redhat.com>
 
        * po/id.po: Updated Indonesian translation.
index fbda2657fe8a1a3f065829bb5518619b1734bf37..57286ba9c31ed19245761a4bcdd1ef6c672fc359 100644 (file)
@@ -6284,7 +6284,10 @@ displacement, which may result in @command{ld} giving
 @samp{--relax} enables the generation of trampolines that can access
 the entire 32-bit address space.  These trampolines are inserted at
 section boundaries, so may not themselves be reachable if an input
-section exceeds 33M in size.
+section exceeds 33M in size.  You may combine @samp{-r} and
+@samp{--relax} to add trampolines in a partial link.  In that case
+both branches to undefined symbols and inter-section branches are also
+considered potentially out of range, and trampolines inserted.
 
 @cindex PowerPC ELF32 options
 @table @option
index 7cb4fc9e99c6a6d3fab2dc3a1608494d19704de9..3b8fed63116774edec688d0b582b6278f7bf6ac5 100644 (file)
@@ -294,8 +294,6 @@ main (int argc, char **argv)
     {
       if (command_line.check_section_addresses < 0)
        command_line.check_section_addresses = 0;
-      if (command_line.relax)
-       einfo (_("%P%F: --relax and -r may not be used together\n"));
       if (link_info.shared)
        einfo (_("%P%F: -r and -shared may not be used together\n"));
     }
index 06b10c34229fd7136f9e2021f5daa4c980ce3001..9d54d034df06aea7b77ca8014593bc551723625f 100644 (file)
@@ -1,3 +1,9 @@
+2009-05-26  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * ld-powerpc/vxworks-relax-2.s: New.
+       * ld-powerpc/vxworks-relax-2.rd: New.
+       * ld-powerpc/powerpc.exp: Add it.
+
 2009-05-22  Hans-Peter Nilsson  <hp@axis.com>
 
        * ld-scripts/rgn-over7.d: Adjust expected message for recent change.
index 2ed41f27127ab26203fe89fdd9ff4822a720e53d..bc63a467fbe1c1a2bfd3dafbd73a62b7d0a41c30 100644 (file)
@@ -54,6 +54,11 @@ if {[istarget "*-*-vxworks"]} {
         "-mregnames" {vxworks-relax.s}
         {{readelf --relocs vxworks-relax.rd}}
         "vxworks-relax"}
+       {"VxWorks relocatable relax test"
+        "-Tvxworks1.ld -r --relax -q"
+        "-mregnames" {vxworks-relax-2.s}
+        {{readelf --relocs vxworks-relax-2.rd}}
+        "vxworks-relax-2"}
     }
     run_ld_link_tests $ppcvxtests
     run_dump_test "vxworks1-static"
diff --git a/ld/testsuite/ld-powerpc/vxworks-relax-2.rd b/ld/testsuite/ld-powerpc/vxworks-relax-2.rd
new file mode 100644 (file)
index 0000000..02eb964
--- /dev/null
@@ -0,0 +1,11 @@
+
+Relocation section '.rela.text' at offset 0x[0-9a-f]+ contains 8 entries:
+ Offset     Info    Type            Sym.Value  Sym. Name \+ Addend
+00000016  00000106 R_PPC_ADDR16_HA   00000000   .text \+ 4000034
+0000001a  00000104 R_PPC_ADDR16_LO   00000000   .text \+ 4000034
+00000006  00000106 R_PPC_ADDR16_HA   00000000   .text \+ 4000034
+0000000a  00000104 R_PPC_ADDR16_LO   00000000   .text \+ 4000034
+00000026  00000506 R_PPC_ADDR16_HA   00000000   undefined \+ 0
+0000002a  00000504 R_PPC_ADDR16_LO   00000000   undefined \+ 0
+0400003e  00000606 R_PPC_ADDR16_HA   00000000   _start \+ 0
+04000042  00000604 R_PPC_ADDR16_LO   00000000   _start \+ 0
diff --git a/ld/testsuite/ld-powerpc/vxworks-relax-2.s b/ld/testsuite/ld-powerpc/vxworks-relax-2.s
new file mode 100644 (file)
index 0000000..4e58124
--- /dev/null
@@ -0,0 +1,14 @@
+       .globl  _start
+_start:
+       bl      elsewhere
+       lis 9,elsewhere@ha
+        la 0,elsewhere@l(9)
+       bl      undefined
+
+
+       .section .far,"ax",@progbits
+elsewhere:
+       bl      _start
+
+       .section .pad
+       .space 0x4000000