Subject: Getting rid of sh5 support in sh3 binutils and gdb?
To: None <tech-toolchain@NetBSD.org>
From: Valeriy E. Ushakov <uwe@ptc.spbu.ru>
List: tech-toolchain
Date: 11/24/2006 06:52:06
--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

[cc'ed to port lists, reply-to set to tech-toolchain, please follow up there]

GNU toolchain seems to insists on including sh5 support for sh*-*
targets, so we end up with sh5 support in sh3 toolchain.

That adds a bit of bloat, but that's not the main problem.

The problem is trying to make gdb6 build.

See gdb/infptrace.c:child_xfer_memory.  When we configure gdb6 for sh3
target (sh{,le}--netbsdelf) sh5 support gets sucked in, causing
bfd_vma to be 64-bit, hence gdb's CORE_ADDR is 64-bit, and then gcc
complains when CORE_ADDR is passed to ptrace() where a poitner is
expected.

Attached patch teaches gdb to not include sh5 support for sh3 targets.
I don't know why toolchain people made the decision to include sh5
support by default, i don't think this is usually the case for either
sparc (vs sparc64), i386 (vs amd64), ppc (vs ppc64) - where 64 bit
variant needs to be requested explicitely.

With this patch gdb6 for sh3 passes mknative + in-tree cross-build.
I haven't tested sh5 build yet.

I wonder if we should also apply relevant parts to binutils as well.


Summary of changes:

bfd/config.bfd

    Move sh64 vectors ito targ64_selvecs for netbsd targets that are
    not explicitely sh5- or sh64-, so that they are enabled only if
    explicitely requested.  This is what is done for most other arches
    with 32/64 bit variants (grep for targ64_selvecs)

opcodes/configure{,.in}

    Do not add sh5 support for netbsd sh* targets unless the target is
    explicitely sh5* or sh64* (to match the config.bfd change)

gdb/sh-tdep.c

    Wrap the only sh5 reference (calling sh64_gdbarch_init() that is
    in sh64-tdep.c) into #ifdef BFD64.

    BTW, config/sh/nbsd.mt doesn't include sh64-tdep.c anyway.


Comments?

SY, Uwe
-- 
uwe@ptc.spbu.ru                         |       Zu Grunde kommen
http://snark.ptc.spbu.ru/~uwe/          |       Ist zu Grunde gehen

--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gdb6.diff"

Index: bfd/config.bfd
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/bfd/config.bfd,v
retrieving revision 1.3
diff -u -r1.3 config.bfd
--- bfd/config.bfd	2 Jul 2006 21:04:40 -0000	1.3
+++ bfd/config.bfd	24 Nov 2006 03:02:53 -0000
@@ -1166,14 +1166,14 @@
     targ_defvec=bfd_elf32_shlnbsd_vec
     targ_selvecs="bfd_elf32_shnbsd_vec shcoff_vec shlcoff_vec"
 #ifdef BFD64
-    targ_selvecs="${targ_selvecs} bfd_elf32_sh64lnbsd_vec bfd_elf32_sh64nbsd_vec bfd_elf64_sh64lnbsd_vec bfd_elf64_sh64nbsd_vec"
+    targ64_selvecs="bfd_elf32_sh64lnbsd_vec bfd_elf32_sh64nbsd_vec bfd_elf64_sh64lnbsd_vec bfd_elf64_sh64nbsd_vec"
 #endif
     ;;
   sh*-*-netbsdelf*)
     targ_defvec=bfd_elf32_shnbsd_vec
     targ_selvecs="bfd_elf32_shlnbsd_vec shcoff_vec shlcoff_vec"
 #ifdef BFD64
-    targ_selvecs="${targ_selvecs} bfd_elf32_sh64lnbsd_vec bfd_elf32_sh64nbsd_vec bfd_elf64_sh64lnbsd_vec bfd_elf64_sh64nbsd_vec"
+    targ64_selvecs="bfd_elf32_sh64lnbsd_vec bfd_elf32_sh64nbsd_vec bfd_elf64_sh64lnbsd_vec bfd_elf64_sh64nbsd_vec"
 #endif
     ;;
 
Index: opcodes/configure.in
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/opcodes/configure.in,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 configure.in
--- opcodes/configure.in	2 Jul 2006 20:22:09 -0000	1.1.1.2
+++ opcodes/configure.in	24 Nov 2006 03:02:53 -0000
@@ -206,6 +206,14 @@
 	  # specified, as in sh3-elf, sh3b-linux-gnu, etc.
 	  # Include it just for ELF targets, since the SH5 bfd:s are ELF only.
 	  for t in $target $canon_targets; do
+	    # For NetBSD we do NOT want SH5 support unless sh5 or sh64
+	    # is specified
+	    case $t in
+	      sh5*-* | sh64*-*) # let the case below handle it
+				;;
+	      sh*-*-netbsdelf* | sh*l*-*-netbsdelf*)
+				break;;
+	      esac;
 	    case $t in
 	      all |  sh5*-* | sh64*-* | sh-*-*elf* | shl*-*-*elf* | \
 	      sh-*-linux* | shl-*-linux*)
Index: opcodes/configure
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/opcodes/configure,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 configure
--- opcodes/configure	2 Jul 2006 20:22:09 -0000	1.1.1.2
+++ opcodes/configure	24 Nov 2006 03:03:01 -0000
@@ -8854,6 +8854,14 @@
 	  # specified, as in sh3-elf, sh3b-linux-gnu, etc.
 	  # Include it just for ELF targets, since the SH5 bfd:s are ELF only.
 	  for t in $target $canon_targets; do
+	    # For NetBSD we do NOT want SH5 support unless sh5 or sh64
+	    # is specified
+	    case $t in
+	      sh5*-* | sh64*-*) # let the case below handle it
+				;;
+	      sh*-*-netbsdelf* | sh*l*-*-netbsdelf*)
+				break;;
+	      esac;
 	    case $t in
 	      all |  sh5*-* | sh64*-* | sh-*-*elf* | shl*-*-*elf* | \
 	      sh-*-linux* | shl-*-linux*)
Index: gdb/sh-tdep.c
===================================================================
RCS file: /cvsroot/src/gnu/dist/gdb6/gdb/sh-tdep.c,v
retrieving revision 1.1.1.2
diff -u -r1.1.1.2 sh-tdep.c
--- gdb/sh-tdep.c	2 Jul 2006 20:15:05 -0000	1.1.1.2
+++ gdb/sh-tdep.c	24 Nov 2006 03:03:02 -0000
@@ -2485,10 +2485,12 @@
       sh_show_regs = sh4_nofpu_show_regs;
       break;
 
+#ifdef BFD64
     case bfd_mach_sh5:
       sh_show_regs = sh64_show_regs;
       /* SH5 is handled entirely in sh64-tdep.c */
       return sh64_gdbarch_init (info, arches);
+#endif
     }
 
   /* If there is already a candidate, use it.  */

--Q68bSM7Ycu6FN28Q--