This is the mail archive of the binutils@sources.redhat.com 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]

[tv] Patch: change bfd_target_vector to a pointer


The following change has been used for a while by NetBSD in order to make
bfd_target_vector a pointer rather than an array.

When building libbfd (+libopcodes, libiberty) as a shared object, the symbol
"bfd_target_vector", on NetBSD's a.out file format, has the size of the
whole array.  If the array is increased in size, by adding targets and
recompiling libbfd, the library causes a linker abort in the client programs
because NetBSD's a.out format cannot cope with that change.  (bucomm.c and
objdump.c need to reference this symbol outside of libbfd.)

Additionally, other formats which can cope with the change (most ELF dynamic
linkers) will simply resort to a copy relocation in lieu of the usual
relocations, wasting memory and CPU at every invocation.  A pointer symbol
doesn't have this drawback.

This change simply tweaks the representation of the bfd_target_vector symbol
such that it can be accessed outside of a libbfd shared object without
regard to the array's size.  Since an array symbol and a pointer symbol are
dereferenced with [] in the same way, code making use of bfd_target_vector
is unchanged.

I am the sole author of these changes.  Note that I do not yet have FSF
copyright assignment forms on file, but the size of the changes are rather
small.  I also hereby release this change to the public domain, if that will
assist in its integration.

=====

bfd/ChangeLog entry:

2001-01-31  Todd Vierling  <tv@wasabisystems.com>

	* libbfd-in.h (bfd_target_vector): Change extern array to pointer.
	* libbfd.h (bfd_target_vector): Likewise.
	* targets.c (bfd_target_vector): Rename to _bfd_target_vector and
        make static; create pointer reference named bfd_target_vector.
	(_bfd_target_vector_entries): Calculate this based on the array
	typed _bfd_target_vector.

binutils/ChangeLog entry:

2001-01-31  Todd Vierling  <tv@wasabisystems.com>

	* bucomm.c (bfd_target_vector): Change extern array to pointer.
	* objdump.c (bfd_target_vector): Likewise.

=====

Diff against binutils HEAD (may also be applied to 2.11 branch, if desired,
and even 2.10, with a trivial whitespace conflict on bfd/targets.c):

Index: bfd/libbfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd-in.h,v
retrieving revision 1.10
diff -u -r1.10 libbfd-in.h
--- bfd/libbfd-in.h	2000/12/08 22:50:07	1.10
+++ bfd/libbfd-in.h	2001/01/31 17:02:06
@@ -521,7 +521,7 @@

 /* List of supported target vectors, and the default vector (if
    bfd_default_vector[0] is NULL, there is no default).  */
-extern const bfd_target * const bfd_target_vector[];
+extern const bfd_target * const *bfd_target_vector;
 extern const bfd_target *bfd_default_vector[];

 /* Functions shared by the ECOFF and MIPS ELF backends, which have no
Index: bfd/libbfd.h
===================================================================
RCS file: /cvs/src/src/bfd/libbfd.h,v
retrieving revision 1.31
diff -u -r1.31 libbfd.h
--- bfd/libbfd.h	2001/01/25 20:17:45	1.31
+++ bfd/libbfd.h	2001/01/31 17:02:07
@@ -521,7 +521,7 @@

 /* List of supported target vectors, and the default vector (if
    bfd_default_vector[0] is NULL, there is no default).  */
-extern const bfd_target * const bfd_target_vector[];
+extern const bfd_target * const *bfd_target_vector;
 extern const bfd_target *bfd_default_vector[];

 /* Functions shared by the ECOFF and MIPS ELF backends, which have no
Index: bfd/targets.c
===================================================================
RCS file: /cvs/src/src/bfd/targets.c,v
retrieving revision 1.33
diff -u -r1.33 targets.c
--- bfd/targets.c	2001/01/18 07:47:50	1.33
+++ bfd/targets.c	2001/01/31 17:02:11
@@ -682,7 +682,7 @@
 extern const bfd_target trad_core_vec;
 extern const bfd_target ptrace_core_vec;

-const bfd_target * const bfd_target_vector[] = {
+static const bfd_target * const _bfd_target_vector[] = {

 #ifdef SELECT_VECS

@@ -971,6 +971,7 @@

 	NULL /* end of list marker */
 };
+const bfd_target * const *bfd_target_vector = _bfd_target_vector;

 /* bfd_default_vector[0] contains either the address of the default vector,
    if there is one, or zero if there isn't.  */
@@ -985,7 +986,7 @@
 /* When there is an ambiguous match, bfd_check_format_matches puts the
    names of the matching targets in an array.  This variable is the maximum
    number of entries that the array could possibly need.  */
-const size_t _bfd_target_vector_entries = sizeof (bfd_target_vector)/sizeof (*bfd_target_vector);
+const size_t _bfd_target_vector_entries = sizeof (_bfd_target_vector)/sizeof (*_bfd_target_vector);

 /* This array maps configuration triplets onto BFD vectors.  */

Index: binutils/bucomm.c
===================================================================
RCS file: /cvs/src/src/binutils/bucomm.c,v
retrieving revision 1.6
diff -u -r1.6 bucomm.c
--- binutils/bucomm.c	2000/06/26 23:15:58	1.6
+++ binutils/bucomm.c	2001/01/31 17:02:11
@@ -157,7 +157,7 @@
      const char *name;
      FILE *f;
 {
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   int t;

   if (name == NULL)
Index: binutils/objdump.c
===================================================================
RCS file: /cvs/src/src/binutils/objdump.c,v
retrieving revision 1.32
diff -u -r1.32 objdump.c
--- binutils/objdump.c	2001/01/09 20:25:31	1.32
+++ binutils/objdump.c	2001/01/31 17:02:12
@@ -2644,14 +2644,14 @@
 static void
 display_target_list ()
 {
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   char *dummy_name;
   int t;

   dummy_name = make_temp_file (NULL);
   for (t = 0; bfd_target_vector[t]; t++)
     {
-      bfd_target *p = bfd_target_vector[t];
+      const bfd_target *p = bfd_target_vector[t];
       bfd *abfd = bfd_openw (dummy_name, p->name);
       int a;

@@ -2692,7 +2692,7 @@
      int first;
      int last;
 {
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   int t, a;
   char *dummy_name;

@@ -2710,7 +2710,7 @@
 		bfd_printable_arch_mach (a, 0));
 	for (t = first; t < last && bfd_target_vector[t]; t++)
 	  {
-	    bfd_target *p = bfd_target_vector[t];
+	    const bfd_target *p = bfd_target_vector[t];
 	    boolean ok = true;
 	    bfd *abfd = bfd_openw (dummy_name, p->name);

@@ -2761,7 +2761,7 @@
 display_target_tables ()
 {
   int t, columns;
-  extern bfd_target *bfd_target_vector[];
+  extern const bfd_target *const *bfd_target_vector;
   char *colum;

   columns = 0;

-- 
-- Todd Vierling <tv@wasabisystems.com>  *  Wasabi NetBSD:  Run with it.
-- NetBSD 1.5 now available on CD-ROM  --  http://www.wasabisystems.com/


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