Subject: Fixes for binutils-2.7/bfd. (FYI)
To: None <tech-toolchain@NetBSD.ORG>
From: Gordon W. Ross <gwr@mc.com>
List: tech-toolchain
Date: 04/07/1997 18:05:04
[ I just sent this to <ian@cygnus.com> FYI. -gwr ]

From: gwr (Gordon W. Ross)
Date: Mon, 7 Apr 97 17:55:06 EDT
To: ian@cygnus.com
Cc: gwr@netbsd.org
Subject: Fixes for binutils-2.7/bfd. Too late?

I've heard (from pk@cs.few.eur.nl) that binutils-2.8 is iminent.
Might it be possible to slip these fixes into the release?
Some are trivial (bfd/targets.c) and some are necessary for
correct operation in NetBSD (bfd/netbsd.h).

Thanks,
Gordon Ross <gwr@netbsd.org>


BFD changes for NetBSD based on binutils-2.7:

Add a missing target declaration.
diff -c ./bfd/targets.c.orig ./bfd/targets.c
*** ./bfd/targets.c.orig	Thu Jul  4 12:30:40 1996
--- ./bfd/targets.c	Mon Apr  7 17:37:22 1997
***************
*** 584,589 ****
--- 584,590 ----
  extern const bfd_target hpux_core_vec;
  extern const bfd_target hppabsd_core_vec;
  extern const bfd_target irix_core_vec;
+ extern const bfd_target netbsd_core_vec;
  extern const bfd_target osf_core_vec;
  extern const bfd_target sco_core_vec;
  extern const bfd_target trad_core_vec;

Use the traditional m68k segment size, which is
preferred on some kernels and harmless on others.
This also makes helps when recognizing kernels with
non-standard link addresses that also have the entry
point near the start of text but not the first page.

diff -c ./bfd/m68knetbsd.c.orig ./bfd/m68knetbsd.c
*** ./bfd/m68knetbsd.c.orig	Thu Jul  4 12:19:34 1996
--- ./bfd/m68knetbsd.c	Mon Apr  7 17:35:37 1997
***************
*** 20,27 ****
  #define BYTES_IN_WORD	4
  #define TARGET_IS_BIG_ENDIAN_P
  
! #define	TARGET_PAGE_SIZE	8192
! #define	SEGMENT_SIZE	8192
  
  #define DEFAULT_ARCH	bfd_arch_m68k
  #define MACHTYPE_OK(mtype) \
--- 20,28 ----
  #define BYTES_IN_WORD	4
  #define TARGET_IS_BIG_ENDIAN_P
  
! /* Stick with the traditional m68k values. */
! #define	TARGET_PAGE_SIZE  0x2000	/*   8K */
! #define	SEGMENT_SIZE     0x20000	/* 128K */
  
  #define DEFAULT_ARCH	bfd_arch_m68k
  #define MACHTYPE_OK(mtype) \

Let NetBSD handle a.out with a non-standard link address.
diff -c ./bfd/netbsd.h.orig ./bfd/netbsd.h
*** ./bfd/netbsd.h.orig	Thu Jul  4 12:19:38 1996
--- ./bfd/netbsd.h	Mon Apr  7 17:32:49 1997
***************
*** 38,43 ****
--- 38,47 ----
  	((exec).a_info = \
  	 ((exec).a_info & 0x03ffffff) | ((flags & 0x03f) << 26))
  
+ #ifndef SEGMENT_SIZE
+ #define SEGMENT_SIZE TARGET_PAGE_SIZE
+ #endif
+ 
  #include "bfd.h"
  #include "sysdep.h"
  #include "libbfd.h"
***************
*** 48,58 ****
--- 52,153 ----
  #define SWAP_MAGIC(ext) bfd_getb32 (ext)
  
  
+ #define MY_callback MY(callback)
+ static const bfd_target * MY(callback) PARAMS ((bfd *abfd));
+ 
  #define MY_write_object_contents MY(write_object_contents)
  static boolean MY(write_object_contents) PARAMS ((bfd *abfd));
  #define MY_text_includes_header 1
  
  #include "aout-target.h"
+ 
+ /* Set parameters about this a.out file that are machine-dependent.
+    This routine is called from some_aout_object_p just before it returns.  */
+ 
+ static const bfd_target *
+ MY(callback) (abfd)
+      bfd *abfd;
+ {
+   struct internal_exec *execp = exec_hdr (abfd);
+   unsigned int arch_align_power;
+   unsigned long arch_align;
+   unsigned long vma_fix;
+ 
+   /* Calculate the file positions of the parts of a newly read aout header */
+   obj_textsec (abfd)->_raw_size = N_TXTSIZE(*execp);
+ 
+   /* The file offsets of the sections */
+   obj_textsec (abfd)->filepos = N_TXTOFF (*execp);
+   obj_datasec (abfd)->filepos = N_DATOFF (*execp);
+ 
+   /* The file offsets of the relocation info */
+   obj_textsec (abfd)->rel_filepos = N_TRELOFF(*execp);
+   obj_datasec (abfd)->rel_filepos = N_DRELOFF(*execp);
+ 
+   /* The file offsets of the string table and symbol table.  */
+   obj_sym_filepos (abfd) = N_SYMOFF (*execp);
+   obj_str_filepos (abfd) = N_STROFF (*execp);
+ 
+   /* The virtual memory addresses of the sections */
+   obj_textsec (abfd)->vma = N_TXTADDR(*execp);
+   obj_datasec (abfd)->vma = N_DATADDR(*execp);
+   obj_bsssec  (abfd)->vma = N_BSSADDR(*execp);
+ 
+   /*
+    * Correct for non-standard entry point (i.e. kernel).
+    * Most a.out files with a non-standard entry point are
+    * using the a_entry field to represent the load address.
+    * XXX - Why does "aout-target.h" not do this?
+    */
+   if ((execp->a_entry & ~(SEGMENT_SIZE-1)) > N_TXTADDR(*execp)) {
+     vma_fix = (execp->a_entry & ~(SEGMENT_SIZE-1)) - N_TXTADDR(*execp);
+     obj_textsec (abfd)->vma += vma_fix;
+     obj_datasec (abfd)->vma += vma_fix;
+     obj_bsssec  (abfd)->vma += vma_fix;
+   }
+ 
+   /* Make the load addresses the same. */
+   obj_textsec (abfd)->lma = obj_textsec (abfd)->vma;
+   obj_datasec (abfd)->lma = obj_datasec (abfd)->vma;
+   obj_bsssec (abfd)->lma = obj_bsssec (abfd)->vma;
+   
+   /* Determine the architecture and machine type of the object file.  */
+ #ifdef SET_ARCH_MACH
+   SET_ARCH_MACH(abfd, *execp);
+ #else
+   bfd_default_set_arch_mach(abfd, DEFAULT_ARCH, 0);
+ #endif
+ 
+   /* Now that we know the architecture, set the alignments of the
+      sections.  This is normally done by NAME(aout,new_section_hook),
+      but when the initial sections were created the architecture had
+      not yet been set.  However, for backward compatibility, we don't
+      set the alignment power any higher than as required by the size
+      of the section.  */
+   arch_align_power = bfd_get_arch_info (abfd)->section_align_power;
+   arch_align = 1 << arch_align_power;
+   if ((BFD_ALIGN (obj_textsec (abfd)->_raw_size, arch_align)
+        == obj_textsec (abfd)->_raw_size)
+       && (BFD_ALIGN (obj_datasec (abfd)->_raw_size, arch_align)
+ 	  == obj_datasec (abfd)->_raw_size)
+       && (BFD_ALIGN (obj_bsssec (abfd)->_raw_size, arch_align)
+ 	  == obj_bsssec (abfd)->_raw_size))
+     {
+       obj_textsec (abfd)->alignment_power = arch_align_power;
+       obj_datasec (abfd)->alignment_power = arch_align_power;
+       obj_bsssec (abfd)->alignment_power = arch_align_power;
+     }
+ 
+   /* Don't set sizes now -- can't be sure until we know arch & mach.
+      Sizes get set in set_sizes callback, later.  */
+ #if 0
+   adata(abfd).page_size = TARGET_PAGE_SIZE;
+   adata(abfd).segment_size = SEGMENT_SIZE;
+   adata(abfd).exec_bytes_size = EXEC_BYTES_SIZE;
+ #endif
+ 
+   return abfd->xvec;
+ }
  
  /* Write an object file.
     Section contents have already been written.  We write the

Add minimal NetBSD/VAX support.
diff -c ./bfd/vaxnetbsd.c.orig ./bfd/vaxnetbsd.c
*** ./bfd/vaxnetbsd.c.orig	Sat Mar 29 04:13:09 1997
--- ./bfd/vaxnetbsd.c	Sat Mar 29 04:15:59 1997
***************
*** 0 ****
--- 1,36 ----
+ /* BFD back-end for NetBSD/vax a.out-ish binaries.
+    Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
+ 
+ This file is part of BFD, the Binary File Descriptor library.
+ 
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+ 
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU General Public License for more details.
+ 
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ 
+ 	$Id: netbsdvax.c,v 1.1 1995/06/05 15:22:53 ragge Exp $
+ */
+ 
+ #define	BYTES_IN_WORD	4
+ #undef TARGET_IS_BIG_ENDIAN_P
+ 
+ #define	TARGET_PAGE_SIZE	1024
+ #define	SEGMENT_SIZE	TARGET_PAGE_SIZE
+ 
+ #define	DEFAULT_ARCH	bfd_arch_vax
+ #define MACHTYPE_OK(mtype) ((mtype) == M_VAX || (mtype) == M_UNKNOWN)
+ 
+ #define MY(OP) CAT(vaxnetbsd_,OP)
+ /* This needs to start with a.out so GDB knows it is an a.out variant.  */
+ #define TARGETNAME "a.out-vax-netbsd"
+ 
+ #include "netbsd.h"