Don't fudge p_vaddr when PHDR in segment
authorAlan Modra <amodra@gmail.com>
Mon, 12 Dec 2016 22:59:47 +0000 (09:29 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 12 Dec 2016 23:07:37 +0000 (09:37 +1030)
RX does horrible fudges to PT_LOAD p_vaddr, that affect the testsuite
and mean the target won't support dynamic objects.  The latter
probably doesn't matter too much since RX is an embedded target, but
it's easy to stop some of the fudges in order to reduce special cases
for RX in the testsuite.  The changes make sense in isolation too.

bfd/
* elf32-rx.c (elf32_rx_modify_program_headers): Don't adjust
segments that include the ELF file header or program headers.
ld/
* testsuite/ld-elf/flags1.d: Run for RX.
* testsuite/ld-scripts/phdrs.exp: Likewise.
* testsuite/ld-scripts/pr14962.d: Likewise.
* testsuite/ld-scripts/pr14962-2.d: Likewise.

bfd/ChangeLog
bfd/elf32-rx.c
ld/ChangeLog
ld/testsuite/ld-elf/flags1.d
ld/testsuite/ld-scripts/phdrs.exp
ld/testsuite/ld-scripts/pr14962-2.d
ld/testsuite/ld-scripts/pr14962.d

index 1c1dd90e75ed70aaf95ad34be85a07ffa60ec2a1..b461ebeb205e49ec3afcea79737a09d8721cfef8 100644 (file)
@@ -1,3 +1,8 @@
+2016-12-13  Alan Modra  <amodra@gmail.com>
+
+       * elf32-rx.c (elf32_rx_modify_program_headers): Don't adjust
+       segments that include the ELF file header or program headers.
+
 2016-12-08  Alan Modra  <amodra@gmail.com>
 
        PR ld/20932
index f5377c06e638b118f2af35fb1c1cb55b0b54de40..72ea7fdfc6f606d614f51625e143b10b361efaa6 100644 (file)
@@ -3200,9 +3200,11 @@ rx_elf_object_p (bfd * abfd)
   int i;
   unsigned int u;
   Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr;
-  int nphdrs = elf_elfheader (abfd)->e_phnum;
+  Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd);
+  int nphdrs = ehdr->e_phnum;
   sec_ptr bsec;
   static int saw_be = FALSE;
+  bfd_vma end_phdroff;
 
   /* We never want to automatically choose the non-swapping big-endian
      target.  The user can only get that explicitly, such as with -I
@@ -3227,6 +3229,17 @@ rx_elf_object_p (bfd * abfd)
      corresponds (based on matching file offsets) and use its VMA
      information to reconstruct the p_vaddr field we clobbered when we
      wrote it out.  */
+  /* If PT_LOAD headers include the ELF file header or program headers
+     then the PT_LOAD header does not start with some section contents.
+     Making adjustments based on the difference between sh_offset and
+     p_offset is nonsense in such cases.  Exclude them.  Note that
+     since standard linker scripts for RX do not use SIZEOF_HEADERS,
+     the linker won't normally create PT_LOAD segments covering the
+     headers so this is mainly for passing the ld testsuite.
+     FIXME.  Why are we looking at non-PT_LOAD headers here?  */
+  end_phdroff = ehdr->e_ehsize;
+  if (ehdr->e_phoff != 0)
+    end_phdroff = ehdr->e_phoff + nphdrs * ehdr->e_phentsize;
   for (i=0; i<nphdrs; i++)
     {
       for (u=0; u<elf_tdata(abfd)->num_elf_sections; u++)
@@ -3234,6 +3247,7 @@ rx_elf_object_p (bfd * abfd)
          Elf_Internal_Shdr *sec = elf_tdata(abfd)->elf_sect_ptr[u];
 
          if (phdr[i].p_filesz
+             && phdr[i].p_offset >= end_phdroff
              && phdr[i].p_offset <= (bfd_vma) sec->sh_offset
              && sec->sh_size > 0
              && sec->sh_type != SHT_NOBITS
index c4dadfc81d9c628ccce0240a2e2c12332ee727bb..08d5a69e3099853a9f45a96dc3023e55db7a1d5d 100644 (file)
@@ -1,3 +1,10 @@
+2016-12-13  Alan Modra  <amodra@gmail.com>
+
+       * testsuite/ld-elf/flags1.d: Run for RX.
+       * testsuite/ld-scripts/phdrs.exp: Likewise.
+       * testsuite/ld-scripts/pr14962.d: Likewise.
+       * testsuite/ld-scripts/pr14962-2.d: Likewise.
+
 2016-12-08  Alan Modra  <amodra@gmail.com>
 
        * configure: Regenerate.
index aadf936c1e19cc820e683dad944abcd4eaf75971..6cd8b3f3832bea949992a6a031af562c5fac04ff 100644 (file)
@@ -2,7 +2,6 @@
 #ld: -Tflags1.ld
 #objcopy_linked_file: --set-section-flags .post_text_reserve=contents,alloc,load,readonly,code
 #readelf: -S --wide
-#notarget: rx-*-*
 
 #...
 Section Headers:
index 9bdc90e54446fdfebc31612e031ebeb4e29fddd1..152d629a52940d4700df67c60743ae0f5b463ee6 100644 (file)
@@ -59,14 +59,6 @@ if ![ld_simple_link $ld tmpdir/phdrs $ldopt] {
     set exec_output [prune_warnings $exec_output]
     verbose -log $exec_output
 
-    # The RX port sets the p_paddr of loadable segments to 0 in order
-    # to be compatible with Renesas tools.  When an RX executable is
-    # loaded into a BFD based tool the code tries to reconstruct the
-    # correct vaddr and paddr values.  This is not always possible
-    # however and this test is one example of where the reconstruction
-    # fails.
-    setup_xfail rx-*-*
-    
     if [regexp $phdrs_regexp $exec_output] {
        pass $testname
     } else {
index 7dd244ecedd07855170bf5b5ad5ef51876e054ed..dad84a3d899e7cfc1e42845a18785f1e21d16371 100644 (file)
@@ -1,7 +1,7 @@
 #ld: -T pr14962-2.t
 #source: pr14962a.s
 #nm: -n
-#notarget: rx-*-* frv-*-*linux*
+#notarget: frv-*-*linux*
 
 #...
 0+2000 [AT] _start
index 06b223e29e5506f6430b53b59ba6661613550525..ba7dd58f3e23854ef58724caa77e7a7038b4e64a 100644 (file)
@@ -2,7 +2,7 @@
 #source: pr14962a.s
 #source: pr14962b.s
 #nm: -n
-#notarget: rx-*-* mmix-knuth-mmixware
+#notarget: mmix-knuth-mmixware
 # The reference to x would normally generate a cross-reference error
 # but the linker script converts x to absolute to avoid the error.
 
This page took 0.04711 seconds and 4 git commands to generate.