This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] sim: mips: workaround 32-bit addr sign extensions


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b36d953bced0a4fecdde1823abac70ed7038ee95

commit b36d953bced0a4fecdde1823abac70ed7038ee95
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Tue Jan 12 01:39:47 2016 -0500

    sim: mips: workaround 32-bit addr sign extensions
    
    The mips bfd will sign extend 32-bit addresses into 64-bit values,
    so if the entry happens to be 0x80000000 or higher, it is turned to
    0xffffffff80000000 which points to memory that doesn't exist.
    
    This wasn't an issue until commit 26f8bf63bf36f9062a5cc1afacf71462a
    as all addresses were automatically truncated there in the translate
    function to 32-bits.  When we cleaned up that code, the full 64-bits
    were checked leading to many test failures for mips-sde-elf targets
    and such.

Diff:
---
 sim/mips/ChangeLog |  6 ++++++
 sim/mips/interp.c  | 13 ++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/sim/mips/ChangeLog b/sim/mips/ChangeLog
index 918c4c0..60af116 100644
--- a/sim/mips/ChangeLog
+++ b/sim/mips/ChangeLog
@@ -1,3 +1,9 @@
+2016-01-12  Mike Frysinger  <vapier@gentoo.org>
+
+	* interp.c: Include elf-bfd.h.
+	(sim_create_inferior): Truncate pc to 32-bits when EI_CLASS is
+	ELFCLASS32.
+
 2016-01-10  Mike Frysinger  <vapier@gentoo.org>
 
 	* config.in, configure: Regenerate.
diff --git a/sim/mips/interp.c b/sim/mips/interp.c
index 61ff400..9dbac8c 100644
--- a/sim/mips/interp.c
+++ b/sim/mips/interp.c
@@ -55,6 +55,7 @@ code on the hardware.
 #include "getopt.h"
 #include "libiberty.h"
 #include "bfd.h"
+#include "elf-bfd.h"
 #include "gdb/callback.h"   /* GDB simulator callback interface */
 #include "gdb/remote-sim.h" /* GDB simulator interface */
 
@@ -1020,7 +1021,17 @@ sim_create_inferior (SIM_DESC sd, struct bfd *abfd,
       for (cpu_nr = 0; cpu_nr < sim_engine_nr_cpus (sd); cpu_nr++)
 	{
 	  sim_cpu *cpu = STATE_CPU (sd, cpu_nr);
-	  CPU_PC_SET (cpu, (unsigned64) bfd_get_start_address (abfd));
+	  sim_cia pc = bfd_get_start_address (abfd);
+
+	  /* We need to undo brain-dead bfd behavior where it sign-extends
+	     addresses that are supposed to be unsigned.  See the mips bfd
+	     sign_extend_vma setting.  We have to check the ELF data itself
+	     in order to handle o32 & n32 ABIs.  */
+	  if (abfd->tdata.elf_obj_data->elf_header->e_ident[EI_CLASS] ==
+	      ELFCLASS32)
+	    pc = (unsigned32) pc;
+
+	  CPU_PC_SET (cpu, pc);
 	}
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]