This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Old aout64.h bug


Some time ago I became sufficiently annoyed at nm failures when
running the testsuite on arm-aout to investigate.  These ones:

Running /src/binutils-current/ld/testsuite/ld-scripts/defined.exp ...
ERROR: tmpdir/def: nm failed
Running /src/binutils-current/ld/testsuite/ld-scripts/dynamic-sections.exp ...
Running /src/binutils-current/ld/testsuite/ld-scripts/empty-address.exp ...
FAIL: ld-scripts/empty-address-1
FAIL: ld-scripts/empty-address-2a
FAIL: ld-scripts/empty-address-2b
FAIL: ld-scripts/empty-address-3a
FAIL: ld-scripts/empty-address-3b
FAIL: ld-scripts/empty-address-3c
Running /src/binutils-current/ld/testsuite/ld-scripts/empty-aligned.exp ...
Running /src/binutils-current/ld/testsuite/ld-scripts/empty-orphan.exp ...
Running /src/binutils-current/ld/testsuite/ld-scripts/expr.exp ...
Running /src/binutils-current/ld/testsuite/ld-scripts/extern.exp ...
ERROR: tmpdir/extern: nm failed

What I found was that the nm failures were being caused by the
N_SHARED_LIB definition in include/aout/aout64.h, which resolves to
true for executables without any text (admittedly only likely to occur
in testsuites).  For ZMAGIC executables with N_SHARED_LIB true,
N_TXTOFF, the file offset of the text segment, resolves to zero.
That can only be correct when the text size at least covers the exec
header.  Otherwise BFD thinks N_DATOFF is inside the exec header, and
similarly misplaces all the following sections including the symbol
table.  So we need to add a test "a_text >= EXEC_BYTES_SIZE" to
N_SHARED_LIB.  That's what I did in my old fix.

This patch tidies things a little further by moving the fixed
N_SHARED_LIB definition to aout/sun4.h.  As the comment says,
N_SHARED_LIB is for sun shared libs so I believe this is the correct
location.  Supporting evidence is the number of places that no longer
need "#define N_SHARED_LIB 0".

include/aout/
	* aout64.h (N_SHARED_LIB): Define as zero if not already defined.
	* sun4.h (N_SHARED_LIB): Define.
	* hp300hpux.h (N_SHARED_LIB): Don't define.
bfd/
	* aout-cris.c (N_SHARED_LIB): Don't define.
	* hp300bsd.c (N_SHARED_LIB): Don't define.
	* i386bsd.c (N_SHARED_LIB): Don't define.
	* i386linux.c (N_SHARED_LIB): Don't define.
	* i386lynx.c (N_SHARED_LIB): Don't define.
	* m68klinux.c (N_SHARED_LIB): Don't define.
	* m88kmach3.c (N_SHARED_LIB): Don't define.
	* mipsbsd.c (N_SHARED_LIB): Don't define.
	* newsos3.c (N_SHARED_LIB): Don't define.
	* pc532-mach.c (N_SHARED_LIB): Don't define.
	* pdp11.c (N_SHARED_LIB): Don't define.
	* sparclinux.c (N_SHARED_LIB): Don't define.
	* vaxbsd.c (N_SHARED_LIB): Don't define.

Index: include/aout/aout64.h
===================================================================
RCS file: /cvs/src/src/include/aout/aout64.h,v
retrieving revision 1.8
diff -u -p -r1.8 aout64.h
--- include/aout/aout64.h	10 May 2005 10:21:09 -0000	1.8
+++ include/aout/aout64.h	2 Oct 2009 14:10:25 -0000
@@ -1,6 +1,6 @@
 /* `a.out' object-file definitions, including extensions to 64-bit fields
 
-   Copyright 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2001, 2003, 2009 Free Software Foundation, Inc.
 
    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
@@ -141,11 +141,7 @@ struct external_exec 
 /* Sun shared libraries, not linux.  This macro is only relevant for ZMAGIC
    files.  */
 #ifndef N_SHARED_LIB
-#if defined (TEXT_START_ADDR) && TEXT_START_ADDR == 0
 #define N_SHARED_LIB(x) (0)
-#else
-#define N_SHARED_LIB(x) ((x).a_entry < TEXT_START_ADDR)
-#endif
 #endif
 
 /* Returning 0 not TEXT_START_ADDR for OMAGIC and NMAGIC is based on
Index: include/aout/hp300hpux.h
===================================================================
RCS file: /cvs/src/src/include/aout/hp300hpux.h,v
retrieving revision 1.4
diff -u -p -r1.4 hp300hpux.h
--- include/aout/hp300hpux.h	18 Sep 2001 10:00:23 -0000	1.4
+++ include/aout/hp300hpux.h	2 Oct 2009 14:10:25 -0000
@@ -1,5 +1,5 @@
 /* Special version of <a.out.h> for use under hp-ux.
-   Copyright 1988, 1993, 1995, 2001 Free Software Foundation, Inc. */
+   Copyright 1988, 1993, 1995, 2001, 2009 Free Software Foundation, Inc. */
 
 struct hp300hpux_exec_bytes
 {
@@ -114,6 +114,3 @@ struct hp300hpux_header_extension
 #define TARGET_PAGE_SIZE 0x1000
 #define SEGMENT_SIZE 0x1000
 #define TEXT_START_ADDR 0
-
-#undef N_SHARED_LIB
-#define N_SHARED_LIB(x)  ( 0 /* no shared libraries */ )
Index: include/aout/sun4.h
===================================================================
RCS file: /cvs/src/src/include/aout/sun4.h,v
retrieving revision 1.3
diff -u -p -r1.3 sun4.h
--- include/aout/sun4.h	10 May 2005 10:21:09 -0000	1.3
+++ include/aout/sun4.h	2 Oct 2009 14:10:25 -0000
@@ -1,6 +1,6 @@
 /* SPARC-specific values for a.out files 
 
-   Copyright 2001 Free Software Foundation, Inc.
+   Copyright 2001, 2009 Free Software Foundation, Inc.
 
    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
@@ -43,6 +43,9 @@
    expected text address.  These kludges have gotta go!
    For linked files, should reflect reality if we know it.  */
 
+#define N_SHARED_LIB(x) ((x).a_entry < TEXT_START_ADDR \
+			 && (x).a_text >= EXEC_BYTES_SIZE)
+
 /* This differs from the version in aout64.h (which we override by defining
    it here) only for NMAGIC (we return TEXT_START_ADDR+EXEC_BYTES_SIZE;
    they return 0).  */
Index: bfd/aout-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/aout-cris.c,v
retrieving revision 1.15
diff -u -p -r1.15 aout-cris.c
--- bfd/aout-cris.c	3 Jul 2007 14:26:39 -0000	1.15
+++ bfd/aout-cris.c	2 Oct 2009 14:10:31 -0000
@@ -1,5 +1,5 @@
 /* BFD backend for CRIS a.out binaries.
-   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2007
+   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2009
    Free Software Foundation, Inc.
    Contributed by Axis Communications AB.
    Written by Hans-Peter Nilsson.
@@ -57,11 +57,6 @@
 #define TARGET_PAGE_SIZE SEGMENT_SIZE
 #define TARGETNAME "a.out-cris"
 
-/* N_SHARED_LIB gets this reasonable default as of 1999-07-12, but we
-   have to work with 2.9.1.  Note that N_SHARED_LIB is used in a
-   SUN-specific context, not applicable to CRIS.  */
-#define N_SHARED_LIB(x) 0
-
 /* The definition here seems not used; just provided as a convention.  */
 #define DEFAULT_ARCH bfd_arch_cris
 
Index: bfd/hp300bsd.c
===================================================================
RCS file: /cvs/src/src/bfd/hp300bsd.c,v
retrieving revision 1.9
diff -u -p -r1.9 hp300bsd.c
--- bfd/hp300bsd.c	2 Sep 2009 07:18:37 -0000	1.9
+++ bfd/hp300bsd.c	2 Oct 2009 14:10:51 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for HP 9000/300 (68000-based) machines running BSD Unix.
-   Copyright 1992, 1994, 1995, 2001, 2003, 2005, 2007
+   Copyright 1992, 1994, 1995, 2001, 2003, 2005, 2007, 2009
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -22,7 +22,6 @@
 #define TARGET_IS_BIG_ENDIAN_P
 #define N_HEADER_IN_TEXT(x) 0
 #define ENTRY_CAN_BE_ZERO
-#define N_SHARED_LIB(x) 0 /* Avoids warning */
 #define TEXT_START_ADDR 0
 #define TARGET_PAGE_SIZE 4096
 #define SEGMENT_SIZE TARGET_PAGE_SIZE
Index: bfd/i386bsd.c
===================================================================
RCS file: /cvs/src/src/bfd/i386bsd.c,v
retrieving revision 1.8
diff -u -p -r1.8 i386bsd.c
--- bfd/i386bsd.c	2 Sep 2009 07:18:37 -0000	1.8
+++ bfd/i386bsd.c	2 Oct 2009 14:10:51 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for i386 a.out binaries under BSD.
-   Copyright 1990, 1991, 1992, 1993, 1994, 2001, 2005, 2007
+   Copyright 1990, 1991, 1992, 1993, 1994, 2001, 2005, 2007, 2009
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -30,7 +30,6 @@
 
 /* ZMAGIC files start at address 0.  This does not apply to QMAGIC.  */
 #define TEXT_START_ADDR 0
-#define N_SHARED_LIB(x) 0
 
 #define	TARGET_PAGE_SIZE	4096
 #define	SEGMENT_SIZE	TARGET_PAGE_SIZE
Index: bfd/i386linux.c
===================================================================
RCS file: /cvs/src/src/bfd/i386linux.c,v
retrieving revision 1.22
diff -u -p -r1.22 i386linux.c
--- bfd/i386linux.c	2 Sep 2009 07:18:37 -0000	1.22
+++ bfd/i386linux.c	2 Oct 2009 14:10:51 -0000
@@ -1,6 +1,6 @@
 /* BFD back-end for linux flavored i386 a.out binaries.
    Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2001, 2002, 2003,
-   2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -23,7 +23,6 @@
 #define ZMAGIC_DISK_BLOCK_SIZE 1024
 #define	SEGMENT_SIZE TARGET_PAGE_SIZE
 #define TEXT_START_ADDR	0x0
-#define N_SHARED_LIB(x) 0
 
 #define MACHTYPE_OK(mtype) ((mtype) == M_386 || (mtype) == M_UNKNOWN)
 
Index: bfd/i386lynx.c
===================================================================
RCS file: /cvs/src/src/bfd/i386lynx.c,v
retrieving revision 1.15
diff -u -p -r1.15 i386lynx.c
--- bfd/i386lynx.c	2 Sep 2009 07:18:37 -0000	1.15
+++ bfd/i386lynx.c	2 Oct 2009 14:10:51 -0000
@@ -1,6 +1,6 @@
 /* BFD back-end for i386 a.out binaries under LynxOS.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2001, 2002,
-   2003, 2005, 2007 Free Software Foundation, Inc.
+   2003, 2005, 2007, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -19,8 +19,6 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
-#define N_SHARED_LIB(x) 0
-
 #define TEXT_START_ADDR 0
 #define TARGET_PAGE_SIZE 4096
 #define SEGMENT_SIZE TARGET_PAGE_SIZE
Index: bfd/m68klinux.c
===================================================================
RCS file: /cvs/src/src/bfd/m68klinux.c,v
retrieving revision 1.24
diff -u -p -r1.24 m68klinux.c
--- bfd/m68klinux.c	2 Sep 2009 07:18:37 -0000	1.24
+++ bfd/m68klinux.c	2 Oct 2009 14:10:53 -0000
@@ -1,6 +1,6 @@
 /* BFD back-end for linux flavored m68k a.out binaries.
    Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -23,7 +23,6 @@
 #define ZMAGIC_DISK_BLOCK_SIZE 1024
 #define	SEGMENT_SIZE TARGET_PAGE_SIZE
 #define TEXT_START_ADDR	0x0
-#define N_SHARED_LIB(x) 0
 
 #define MACHTYPE_OK(mtype) ((mtype) == M_68020 || (mtype) == M_UNKNOWN)
 
Index: bfd/m88kmach3.c
===================================================================
RCS file: /cvs/src/src/bfd/m88kmach3.c,v
retrieving revision 1.9
diff -u -p -r1.9 m88kmach3.c
--- bfd/m88kmach3.c	2 Sep 2009 07:18:37 -0000	1.9
+++ bfd/m88kmach3.c	2 Oct 2009 14:10:53 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for Motorola m88k a.out (Mach 3) binaries.
-   Copyright 1990, 1991, 1993, 1994, 1995, 2001, 2003, 2005, 2007
+   Copyright 1990, 1991, 1993, 1994, 1995, 2001, 2003, 2005, 2007, 2009
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -23,7 +23,6 @@
 #define SEGMENT_SIZE	0x20000
 #define TEXT_START_ADDR	0
 #define N_HEADER_IN_TEXT(x)	1 		/* (N_MAGIG(x) == ZMAGIC) */
-#define N_SHARED_LIB(x) 0
 
 #define N_TXTSIZE(x)	((x).a_text)
 
Index: bfd/mipsbsd.c
===================================================================
RCS file: /cvs/src/src/bfd/mipsbsd.c,v
retrieving revision 1.20
diff -u -p -r1.20 mipsbsd.c
--- bfd/mipsbsd.c	2 Sep 2009 07:18:37 -0000	1.20
+++ bfd/mipsbsd.c	2 Oct 2009 14:10:53 -0000
@@ -1,6 +1,6 @@
 /* BFD backend for MIPS BSD (a.out) binaries.
    Copyright 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
-   2005, 2007 Free Software Foundation, Inc.
+   2005, 2007, 2009 Free Software Foundation, Inc.
    Written by Ralph Campbell.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -23,7 +23,6 @@
 
 /* #define ENTRY_CAN_BE_ZERO */
 #define N_HEADER_IN_TEXT(x) 1
-#define N_SHARED_LIB(x) 0
 #define N_TXTADDR(x) \
     (N_MAGIC(x) != ZMAGIC ? (x).a_entry :	/* object file or NMAGIC */\
 	    TEXT_START_ADDR + EXEC_BYTES_SIZE	/* no padding */\
Index: bfd/newsos3.c
===================================================================
RCS file: /cvs/src/src/bfd/newsos3.c,v
retrieving revision 1.10
diff -u -p -r1.10 newsos3.c
--- bfd/newsos3.c	2 Sep 2009 07:18:37 -0000	1.10
+++ bfd/newsos3.c	2 Oct 2009 14:10:53 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for NewsOS3 (Sony, 68k) binaries.
-   Copyright 1990, 1991, 1994, 1995, 2000, 2001, 2003, 2005, 2007
+   Copyright 1990, 1991, 1994, 1995, 2000, 2001, 2003, 2005, 2007, 2009
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -29,7 +29,6 @@
 #define MY(OP) CONCAT2 (newsos3_,OP)
 #define TARGETNAME "a.out-newsos3"
 #define ENTRY_CAN_BE_ZERO
-#define N_SHARED_LIB(x) 0 /* Avoids warning when compiled with -Wall.  */
 #define DEFAULT_ARCH bfd_arch_m68k
 #define TARGET_IS_BIG_ENDIAN_P
 #define N_HEADER_IN_TEXT(x) 0
Index: bfd/pc532-mach.c
===================================================================
RCS file: /cvs/src/src/bfd/pc532-mach.c,v
retrieving revision 1.12
diff -u -p -r1.12 pc532-mach.c
--- bfd/pc532-mach.c	2 Sep 2009 07:18:37 -0000	1.12
+++ bfd/pc532-mach.c	2 Oct 2009 14:10:53 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for Mach3/532 a.out-ish binaries.
-   Copyright 1990, 1991, 1992, 1994, 1995, 2000, 2001, 2002, 2005, 2007
+   Copyright 1990, 1991, 1992, 1994, 1995, 2000, 2001, 2002, 2005, 2007, 2009
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -46,7 +46,6 @@
 
 #define	SEGMENT_SIZE	TARGET_PAGE_SIZE
 
-#define N_SHARED_LIB(x) 0
 #define SEGMENT_SIZE TARGET_PAGE_SIZE
 #define DEFAULT_ARCH bfd_arch_ns32k
 
Index: bfd/pdp11.c
===================================================================
RCS file: /cvs/src/src/bfd/pdp11.c,v
retrieving revision 1.41
diff -u -p -r1.41 pdp11.c
--- bfd/pdp11.c	29 Aug 2009 22:10:58 -0000	1.41
+++ bfd/pdp11.c	2 Oct 2009 14:10:56 -0000
@@ -58,9 +58,6 @@
 /* The header is not included in the text segment.  */
 #define N_HEADER_IN_TEXT(x)	0
 
-/* There are no shared libraries.  */
-#define N_SHARED_LIB(x) 	0
-
 /* There is no flags field.  */
 #define N_FLAGS(exec)		0
 
Index: bfd/sparclinux.c
===================================================================
RCS file: /cvs/src/src/bfd/sparclinux.c,v
retrieving revision 1.24
diff -u -p -r1.24 sparclinux.c
--- bfd/sparclinux.c	2 Sep 2009 07:18:37 -0000	1.24
+++ bfd/sparclinux.c	2 Oct 2009 14:10:58 -0000
@@ -1,6 +1,6 @@
 /* BFD back-end for linux flavored sparc a.out binaries.
    Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -23,7 +23,6 @@
 #define ZMAGIC_DISK_BLOCK_SIZE	1024
 #define SEGMENT_SIZE		TARGET_PAGE_SIZE
 #define TEXT_START_ADDR		0x0
-#define N_SHARED_LIB(x)		0
 
 #define MACHTYPE_OK(mtype) ((mtype) == M_SPARC || (mtype) == M_UNKNOWN)
 
Index: bfd/vaxbsd.c
===================================================================
RCS file: /cvs/src/src/bfd/vaxbsd.c,v
retrieving revision 1.7
diff -u -p -r1.7 vaxbsd.c
--- bfd/vaxbsd.c	2 Sep 2009 07:18:37 -0000	1.7
+++ bfd/vaxbsd.c	2 Oct 2009 14:10:58 -0000
@@ -1,5 +1,5 @@
 /* BFD back-end for BSD and Ultrix/VAX (1K page size) a.out-ish binaries.
-   Copyright 2002, 2003, 2005, 2007 Free Software Foundation, Inc.
+   Copyright 2002, 2003, 2005, 2007, 2009 Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
 
@@ -20,7 +20,6 @@
 
 #define N_HEADER_IN_TEXT(x) 0
 #define ENTRY_CAN_BE_ZERO
-#define N_SHARED_LIB(x) 0 /* Avoids warning */
 #define TEXT_START_ADDR 0
 #define TARGET_PAGE_SIZE 1024
 #define SEGMENT_SIZE TARGET_PAGE_SIZE

-- 
Alan Modra
Australia Development Lab, IBM


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