Subject: bin/6893: gdb dumps core on NetBSD/alpha 1.3.3
To: None <gnats-bugs@gnats.netbsd.org>
From: No Spam <sopwith!nospam@parsely.rain.com>
List: netbsd-bugs
Date: 01/28/1999 00:44:50
>Number:         6893
>Category:       bin
>Synopsis:       gdb dumps core on NetBSD/alpha 1.3.3
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 27 16:50:01 1999
>Last-Modified:
>Originator:     Snoopy
>Organization:
	
>Release:        1.3.3
>Environment:
	
System: NetBSD sopwith 1.3.3 NetBSD 1.3.3 (GENERIC) #7: Fri Dec 11 21:32:58 PST 1998 ross@zeta:/usr/src/sys/arch/alpha/compile/GENERIC alpha


>Description:

	I am attemptng to get xemacs-20.4 running on NetBSD/alpha.
	(The NetBSD package system has xemacs turned off for Alpha, but it is
	easy enough to get it to build, unlike earlier versions.  Diffs below)

	gdb core dumps when attempting to look at the xemacs core dump.


$ gdb ./xemacs
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.16 (alpha-netbsd), Copyright 1996 Free Software Foundation, Inc...Segmentation fault (core dumped)
$ /usr/bin/gdb /usr/bin/gdb gdb.core
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.16 (alpha-netbsd), Copyright 1996 Free Software Foundation, Inc...(no debugging symbols found)...
Core was generated by `gdb'.
Program terminated with signal 11, Segmentation fault.

warning: Hit heuristic-fence-post without finding

warning: enclosing function for address 0x160625a04
This warning occurs if you are debugging a function without any symbols
(for example, in a stripped executable).  In that case, you may wish to
increase the size of the search with the `set heuristic-fence-post' command.

Otherwise, you told GDB there was a function where there isn't one, or
(more likely) you have encountered a bug in GDB.
#0  0x160625a04 in ?? ()
(gdb) where
#0  0x160625a04 in ?? ()
#1  0x1200341f4 in _init ()
#2  0x1200341f4 in _init ()
warning: Hit heuristic-fence-post without finding
warning: enclosing function for address 0x120228840
(gdb) quit
$

	
>How-To-Repeat:
	
	Diffs for the xemacs package to get it to build:

===================================================================
RCS file: RCS/config.h,v
retrieving revision 1.1
diff -c -r1.1 config.h
*** config.h	1999/01/20 18:32:47	1.1
--- config.h	1999/01/20 18:33:21
***************
*** 455,461 ****
--- 455,463 ----
     definitions isn't right with 64-bit systems.
  
     (It's NO_UNION_TYPE instead of USE_UNION_TYPE for historical reasons.) */
+ #if ! defined(__alpha__)
  #define NO_UNION_TYPE 1
+ #endif
  
  /* The configuration script defines opsysfile to be the name of the
     s/...h file that describes the system type you are using.



===================================================================
RCS file: RCS/unexelf.c,v
retrieving revision 1.1
diff -c -r1.1 unexelf.c
*** unexelf.c	1999/01/20 07:08:17	1.1
--- unexelf.c	1999/01/20 18:25:10
***************
*** 419,424 ****
--- 419,436 ----
  #include <fcntl.h>
  #ifdef __NetBSD__ /* XXX this is a hack */
  #include "netbsd.elf.h"
+ 
+ /* Need this before including sys/exec_elf.h so that
+  * Elf_Ehdr and friends get setup.
+  */
+ #if ! defined(ELFSIZE)
+ #  if defined(__alpha__)
+ #    define ELFSIZE 64
+ #  else
+ #    define ELFSIZE 32
+ #  endif
+ #endif
+ 
  #include <sys/exec_elf.h>
  #else
  #include <elf.h>
***************
*** 464,476 ****
     */
  
  #define OLD_SECTION_H(n) \
!      (*(Elf32_Shdr *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
  #define NEW_SECTION_H(n) \
!      (*(Elf32_Shdr *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
  #define OLD_PROGRAM_H(n) \
!      (*(Elf32_Phdr *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
  #define NEW_PROGRAM_H(n) \
!      (*(Elf32_Phdr *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
  
  #define PATCH_INDEX(n) \
    do { \
--- 476,488 ----
     */
  
  #define OLD_SECTION_H(n) \
!      (*(Elf_Shdr *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
  #define NEW_SECTION_H(n) \
!      (*(Elf_Shdr *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
  #define OLD_PROGRAM_H(n) \
!      (*(Elf_Phdr *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
  #define NEW_PROGRAM_H(n) \
!      (*(Elf_Phdr *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
  
  #define PATCH_INDEX(n) \
    do { \
***************
*** 512,528 ****
    /* Pointers to the file, program and section headers for the old and new
     * files.
     */
!   Elf32_Ehdr *old_file_h, *new_file_h;
!   Elf32_Phdr *old_program_h, *new_program_h;
!   Elf32_Shdr *old_section_h, *new_section_h;
  
    /* Point to the section name table in the old file */
    char *old_section_names;
  
!   Elf32_Addr old_bss_addr, new_bss_addr;
!   Elf32_Word old_bss_size, new_data2_size;
!   Elf32_Off  new_data2_offset;
!   Elf32_Addr new_data2_addr;
  
    int n, nn, old_bss_index, old_data_index;
    struct stat stat_buf;
--- 524,541 ----
    /* Pointers to the file, program and section headers for the old and new
     * files.
     */
! 
!   Elf_Ehdr *old_file_h, *new_file_h;
!   Elf_Phdr *old_program_h, *new_program_h;
!   Elf_Shdr *old_section_h, *new_section_h;
  
    /* Point to the section name table in the old file */
    char *old_section_names;
  
!   Elf_Addr old_bss_addr, new_bss_addr;
!   Elf_Word old_bss_size, new_data2_size;
!   Elf_Off  new_data2_offset;
!   Elf_Addr new_data2_addr;
  
    int n, nn, old_bss_index, old_data_index;
    struct stat stat_buf;
***************
*** 549,557 ****
  
    /* Get pointers to headers & section names */
  
!   old_file_h = (Elf32_Ehdr *) old_base;
!   old_program_h = (Elf32_Phdr *) ((byte *) old_base + old_file_h->e_phoff);
!   old_section_h = (Elf32_Shdr *) ((byte *) old_base + old_file_h->e_shoff);
    old_section_names = (char *) old_base
      + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset;
  
--- 562,570 ----
  
    /* Get pointers to headers & section names */
  
!   old_file_h = (Elf_Ehdr *) old_base;
!   old_program_h = (Elf_Phdr *) ((byte *) old_base + old_file_h->e_phoff);
!   old_section_h = (Elf_Shdr *) ((byte *) old_base + old_file_h->e_shoff);
    old_section_names = (char *) old_base
      + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset;
  
***************
*** 576,582 ****
    old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
    old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
  #if defined(emacs) || !defined(DEBUG)
!   new_bss_addr = (Elf32_Addr) sbrk (0);
  #else
    new_bss_addr = old_bss_addr + old_bss_size + 0x1234;
  #endif
--- 589,595 ----
    old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
    old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
  #if defined(emacs) || !defined(DEBUG)
!   new_bss_addr = (Elf_Addr) sbrk (0);
  #else
    new_bss_addr = old_bss_addr + old_bss_size + 0x1234;
  #endif
***************
*** 622,630 ****
    if (new_base == (caddr_t) -1)
      fatal ("Can't mmap (%s): errno %d\n", new_name, errno);
  
!   new_file_h = (Elf32_Ehdr *) new_base;
!   new_program_h = (Elf32_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
!   new_section_h = (Elf32_Shdr *)
      ((byte *) new_base + old_file_h->e_shoff + new_data2_size);
  
    /* Make our new file, program and section headers as copies of the
--- 635,643 ----
    if (new_base == (caddr_t) -1)
      fatal ("Can't mmap (%s): errno %d\n", new_name, errno);
  
!   new_file_h = (Elf_Ehdr *) new_base;
!   new_program_h = (Elf_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
!   new_section_h = (Elf_Shdr *)
      ((byte *) new_base + old_file_h->e_shoff + new_data2_size);
  
    /* Make our new file, program and section headers as copies of the
***************
*** 818,826 ****
        if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB
  	  || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM)
  	{
! 	  Elf32_Shdr *spt = &NEW_SECTION_H (nn);
  	  unsigned int num = spt->sh_size / spt->sh_entsize;
! 	  Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H (nn).sh_offset +
  					   new_base);
  	  for (; num--; sym++)
  	    {
--- 831,839 ----
        if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB
  	  || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM)
  	{
! 	  Elf_Shdr *spt = &NEW_SECTION_H (nn);
  	  unsigned int num = spt->sh_size / spt->sh_entsize;
! 	  Elf_Sym * sym = (Elf_Sym *) (NEW_SECTION_H (nn).sh_offset +
  					   new_base);
  	  for (; num--; sym++)
  	    {
***************
*** 838,844 ****
    for (n = new_file_h->e_shnum - 1; n; n--)
      {
        byte *symnames;
!       Elf32_Sym *symp, *symendp;
  
        if (NEW_SECTION_H (n).sh_type != SHT_DYNSYM
  	  && NEW_SECTION_H (n).sh_type != SHT_SYMTAB)
--- 851,857 ----
    for (n = new_file_h->e_shnum - 1; n; n--)
      {
        byte *symnames;
!       Elf_Sym *symp, *symendp;
  
        if (NEW_SECTION_H (n).sh_type != SHT_DYNSYM
  	  && NEW_SECTION_H (n).sh_type != SHT_SYMTAB)
***************
*** 846,853 ****
  
        symnames = ((byte *) new_base
  		  + NEW_SECTION_H (NEW_SECTION_H (n).sh_link).sh_offset);
!       symp = (Elf32_Sym *) (NEW_SECTION_H (n).sh_offset + new_base);
!       symendp = (Elf32_Sym *) ((byte *)symp + NEW_SECTION_H (n).sh_size);
  
        for (; symp < symendp; symp ++)
  	if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0
--- 859,866 ----
  
        symnames = ((byte *) new_base
  		  + NEW_SECTION_H (NEW_SECTION_H (n).sh_link).sh_offset);
!       symp = (Elf_Sym *) (NEW_SECTION_H (n).sh_offset + new_base);
!       symendp = (Elf_Sym *) ((byte *)symp + NEW_SECTION_H (n).sh_size);
  
        for (; symp < symendp; symp ++)
  	if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0
***************
*** 859,865 ****
       that it can undo relocations performed by the runtime linker.  */
    for (n = new_file_h->e_shnum - 1; n; n--)
      {
!       Elf32_Shdr section = NEW_SECTION_H (n);
        switch (section.sh_type) {
        default:
  	break;
--- 872,878 ----
       that it can undo relocations performed by the runtime linker.  */
    for (n = new_file_h->e_shnum - 1; n; n--)
      {
!       Elf_Shdr section = NEW_SECTION_H (n);
        switch (section.sh_type) {
        default:
  	break;
***************
*** 873,885 ****
  	    || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  			".data1"))
  	  {
! 	    Elf32_Addr offset = NEW_SECTION_H (nn).sh_addr -
  	      NEW_SECTION_H (nn).sh_offset;
  	    caddr_t reloc = old_base + section.sh_offset, end;
  	    for (end = reloc + section.sh_size; reloc < end;
  		 reloc += section.sh_entsize)
  	      {
! 		Elf32_Addr addr = ((Elf32_Rel *) reloc)->r_offset - offset;
  		memcpy (new_base + addr, old_base + addr, 4);
  	      }
  	  }
--- 886,898 ----
  	    || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
  			".data1"))
  	  {
! 	    Elf_Addr offset = NEW_SECTION_H (nn).sh_addr -
  	      NEW_SECTION_H (nn).sh_offset;
  	    caddr_t reloc = old_base + section.sh_offset, end;
  	    for (end = reloc + section.sh_size; reloc < end;
  		 reloc += section.sh_entsize)
  	      {
! 		Elf_Addr addr = ((Elf_Rel *) reloc)->r_offset - offset;
  		memcpy (new_base + addr, old_base + addr, 4);
  	      }
  	  }



===================================================================
RCS file: RCS/etags.c,v
retrieving revision 1.1
diff -c -r1.1 etags.c
*** etags.c	1999/01/27 18:35:13	1.1
--- etags.c	1999/01/27 18:43:18
***************
*** 816,824 ****
  
  
  int
! main (argc, argv)
!      int argc;
!      char *argv[];
  {
    int i;
    unsigned int nincluded_files;
--- 816,824 ----
  
  
  int
! main (
!      int argc,
!      char *argv[] )
  {
    int i;
    unsigned int nincluded_files;
***************
*** 1754,1762 ****
  */
  
  static int
! hash (str, len)
!      register char *str;
!      register unsigned int len;
  {
    static unsigned char hash_table[] =
      {
--- 1754,1762 ----
  */
  
  static int
! hash (
!      register char *str,
!      register unsigned int len)
  {
    static unsigned char hash_table[] =
      {
===================================================================
RCS file: RCS/getopt.c,v
retrieving revision 1.1
diff -c -r1.1 getopt.c
*** getopt.c	1999/01/27 18:04:58	1.1
--- getopt.c	1999/01/27 18:33:44
***************
*** 204,210 ****
--- 204,213 ----
  /* Avoid depending on library functions or files
     whose names are inconsistent.  */
  
+ #if ! defined (__NetBSD__)
+ /* NetBSD has a complete prototype in stdlib.h */
  char *getenv ();
+ #endif
  
  static char *
  my_index (const char *str, int chr)




===================================================================
RCS file: RCS/getopt.h,v
retrieving revision 1.1
diff -c -r1.1 getopt.h
*** getopt.h	1999/01/27 18:00:07	1.1
--- getopt.h	1999/01/27 23:49:03
***************
*** 99,105 ****
  #define optional_argument	2
  
  #if defined (__STDC__) && __STDC__
! #ifdef __GNU_LIBRARY__
  /* Many other libraries have conflicting prototypes for getopt, with
     differences in the consts, in stdlib.h.  To avoid compilation
     errors, only prototype getopt for the GNU C library.  */
--- 99,105 ----
  #define optional_argument	2
  
  #if defined (__STDC__) && __STDC__
! #if defined ( __GNU_LIBRARY__) || defined (__NetBSD__)
  /* Many other libraries have conflicting prototypes for getopt, with
     differences in the consts, in stdlib.h.  To avoid compilation
     errors, only prototype getopt for the GNU C library.  */



===================================================================
RCS file: RCS/gnuserv.c,v
retrieving revision 1.1
diff -c -r1.1 gnuserv.c
*** gnuserv.c	1999/01/27 17:57:56	1.1
--- gnuserv.c	1999/01/27 17:58:46
***************
*** 832,840 ****
  
  
  int
! main(argc,argv)
!      int argc;
!      char *argv[];
  {
    int chan;			/* temporary channel number */
  #ifdef INTERNET_DOMAIN_SOCKETS
--- 832,840 ----
  
  
  int
! main(
!      int argc,
!      char *argv[] )
  {
    int chan;			/* temporary channel number */
  #ifdef INTERNET_DOMAIN_SOCKETS



===================================================================
RCS file: RCS/Makefile,v
retrieving revision 1.1
diff -r1.1 Makefile
28c28
< NOT_FOR_ARCHS=	alpha mips	#fails purespace dumping
---
> NOT_FOR_ARCHS=	 mips	#fails purespace dumping

>Fix:
	
>Audit-Trail:
>Unformatted: