Change AR for ELF so that common symbols are not included in archive map.
authorNick Clifton <nickc@redhat.com>
Fri, 10 Dec 1999 01:41:22 +0000 (01:41 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 10 Dec 1999 01:41:22 +0000 (01:41 +0000)
Change LD for ELF so that archive elements whoes archive map contains a
 reference to a common symbol will get linkled in.
Add new field to bfd_target structure and initialise it for all bfd targets.

19 files changed:
bfd/ChangeLog
bfd/aout-target.h
bfd/aout-tic30.c
bfd/archive.c
bfd/bfd-in2.h
bfd/bfd.c
bfd/coff-alpha.c
bfd/coff-rs6000.c
bfd/elf64-mips.c
bfd/elflink.h
bfd/elfxx-target.h
bfd/ieee.c
bfd/libbfd-in.h
bfd/libbfd.h
bfd/libecoff.h
bfd/oasys.c
bfd/som.c
bfd/targets.c
bfd/vms.c

index 4355d515336d4b33fb711c3e6a4473f2e9e11b7a..c4c6aa86a6e00b6c8cddeef417e20ff13e5f4523 100644 (file)
@@ -1,3 +1,38 @@
+1999-12-09  Nick Clifton  <nickc@cygnus.com>
+
+       * elflink.h (elf_link_add_archive_symbols): Add an archive
+        element even if contains a symbol which is currently only
+        considered to be a common.
+
+       * targets.c (struct bfd_target): Add new field
+       _bfd_allow_commons_in_armap.
+       * bfd-in2.h:Regenerate.
+
+       * libbfd-in2.h (_bfd_noarchive_allow_commons_in_armap):
+       Define.
+        (_bfd_archive_bsd_allow_commons_in_armap): Define.
+       * libbfd.h: Regenerate.
+
+       * elfxx-target.h: If using COFF archive map, override
+       definition of allow_commons_in_armap and replace with
+       bfd_false.
+
+       * archive.c (bfd_compute_and_write_armap): Do not place common
+       symbols into the archive map unless _bfd_allow_commons_in_armap
+       returns true.
+
+       * aout-target.h (MY_allow_commons_in_armap): Define.
+       * aout-tic30.h (MY_allow_commons_in_armap): Define.
+       * bfd.c (bfd_allow_commons_in_armap): Define.
+       * coff-alpha.h (alpha_ecoff_allow_commons_in_armap): Define.
+       * coff-rs6000.h (xcoff_allow_commons_in_armap): Define.
+       * elf64-mips.c (bfd_elf64_allow_commons_in_armap): Define.
+       * ieee.c (ieee_ecoff_allow_commons_in_armap): Define.
+       * libecoff.h (_bfd_ecoff_allow_commons_in_armap): Define.
+       * oasys.c (oasys_allow_commons_in_armap): Define.
+       * som.c (som_allow_commons_in_armap): Define.
+       * vms.c (vms_allow_commons_in_armap): Define.
+
 1999-12-07  Jim Blandy  <jimb@cygnus.com>
 
        Add support for SSE registers in ELF core files.
index 5ca50ac5682634c383017fcb196b01e061580c1a..0650c4c2feacb0a4fdbeb82a722ebeb03c99396c 100644 (file)
@@ -421,6 +421,9 @@ MY_bfd_final_link (abfd, info)
 #ifndef MY_update_armap_timestamp
 #define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
 #endif
+#ifndef MY_allow_commons_in_armap
+#define MY_allow_commons_in_armap _bfd_archive_bsd_allow_commons_in_armap
+#endif
 
 /* No core file defined here -- configure in trad-core.c separately.  */
 #ifndef        MY_core_file_failing_command
index 0dcae0c25bc27cb6f669661f297ee89a85461a5a..f39e5c39315f30425c4ac7dd4d28906431ab32c7 100644 (file)
@@ -851,6 +851,9 @@ tic30_aout_set_arch_mach (abfd, arch, machine)
 #ifndef MY_update_armap_timestamp
 #define MY_update_armap_timestamp _bfd_archive_bsd_update_armap_timestamp
 #endif
+#ifndef MY_allow_commons_in_armap
+#define MY_allow_commons_in_armap _bfd_archive_bsd_allow_commons_in_armap
+#endif
 
 /* No core file defined here -- configure in trad-core.c separately.  */
 #ifndef        MY_core_file_failing_command
index 19293af4573d5b15cff62a64a8387be62c0294ff..3390a1c2635335db4f04a30233fd7d6ffb4fe1a0 100644 (file)
@@ -1804,16 +1804,19 @@ _bfd_compute_and_write_armap (arch, elength)
                {
                  flagword flags = (syms[src_count])->flags;
                  asection *sec = syms[src_count]->section;
+                 size_t namelen;
+                 struct orl *new_map;
 
-                 if ((flags & BSF_GLOBAL ||
-                      flags & BSF_WEAK ||
-                      flags & BSF_INDIRECT ||
-                      bfd_is_com_section (sec))
-                     && ! bfd_is_und_section (sec))
+                 if (bfd_is_und_section (sec))
+                   continue;
+                 else if (bfd_is_com_section (sec))
                    {
-                     size_t namelen;
-                     struct orl *new_map;
-
+                     if (! bfd_allow_commons_in_armap (arch))
+                       continue;
+                   }
+                 else if ((flags & (BSF_GLOBAL | BSF_WEAK | BSF_INDIRECT)) == 0)
+                   continue;
+                 
                      /* This symbol will go into the archive header */
                      if (orl_count == orl_max)
                        {
@@ -1842,7 +1845,6 @@ _bfd_compute_and_write_armap (arch, elength)
 
                      stridx += namelen + 1;
                      ++orl_count;
-                   }
                }
            }
 
index 93c9b7e815813cf38dd21db81f57989f161f4c92..8a6cbd361c28c1214908c1277580f1b6eebc8515 100644 (file)
@@ -2713,6 +2713,9 @@ bfd_set_private_flags PARAMS ((bfd *abfd, flagword flags));
 #define bfd_update_armap_timestamp(abfd) \
         BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
 
+#define bfd_allow_commons_in_armap(abfd) \
+        BFD_SEND (abfd, _bfd_allow_commons_in_armap, (abfd))
+
 #define bfd_set_arch_mach(abfd, arch, mach)\
         BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
 
@@ -2920,7 +2923,8 @@ CAT(NAME,_read_ar_hdr),\
 CAT(NAME,_openr_next_archived_file),\
 CAT(NAME,_get_elt_at_index),\
 CAT(NAME,_generic_stat_arch_elt),\
-CAT(NAME,_update_armap_timestamp)
+CAT(NAME,_update_armap_timestamp), \
+CAT(NAME,_allow_commons_in_armap)
   boolean  (*_bfd_slurp_armap) PARAMS ((bfd *));
   boolean  (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
   boolean  (*_bfd_construct_extended_name_table)
@@ -2931,13 +2935,14 @@ CAT(NAME,_update_armap_timestamp)
                               struct orl *map,
                               unsigned int orl_count, 
                               int stridx));
-  PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
+  PTR      (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
   bfd *    (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
 #define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i))
   bfd *    (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));
   int      (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
   boolean  (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
-
+  boolean  (*_bfd_allow_commons_in_armap) PARAMS ((bfd *));
+            
    /* Entry points used for symbols.  */
 #define BFD_JUMP_TABLE_SYMBOLS(NAME)\
 CAT(NAME,_get_symtab_upper_bound),\
index e04172fb016a433daae750a280bba009ebf03ddf..f804f324b2b5b4ee3bab52f12f7b790614ff8b98 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1063,6 +1063,9 @@ DESCRIPTION
 .#define bfd_update_armap_timestamp(abfd) \
 .        BFD_SEND (abfd, _bfd_update_armap_timestamp, (abfd))
 .
+.#define bfd_allow_commons_in_armap(abfd) \
+.        BFD_SEND (abfd, _bfd_allow_commons_in_armap, (abfd))
+.
 .#define bfd_set_arch_mach(abfd, arch, mach)\
 .        BFD_SEND ( abfd, _bfd_set_arch_mach, (abfd, arch, mach))
 .
index bc25319f4a64f348f5f1ce21e8356213ed4a90e4..76ef5e2cffe7bcff4495a85679e6234596138f24 100644 (file)
@@ -2036,6 +2036,8 @@ alpha_adjust_headers (abfd, fhdr, ahdr)
 #define alpha_ecoff_write_armap _bfd_ecoff_write_armap
 #define alpha_ecoff_generic_stat_arch_elt _bfd_ecoff_generic_stat_arch_elt
 #define alpha_ecoff_update_armap_timestamp _bfd_ecoff_update_armap_timestamp
+#define alpha_ecoff_allow_commons_in_armap _bfd_true
+
 
 /* A compressed file uses this instead of ARFMAG.  */
 
index 69230001e49bae619446f67476912bab2dfecac6..0ceb7a92c09345520da8b1eb5b9d61d49cd1837d 100644 (file)
@@ -694,6 +694,7 @@ struct xcoff_ar_hdr
 /* XCOFF archives do not have a timestamp.  */
 
 #define xcoff_update_armap_timestamp bfd_true
+#define xcoff_allow_commons_in_armap bfd_true
 
 /* Read in the armap of an XCOFF archive.  */
 
index 6fc0dcdf0e4b9eface34872a59727483f92b3a86..cbc69b271ef8616b10edd85deeb7ade2b6aa8a0f 100644 (file)
@@ -2186,5 +2186,6 @@ const struct elf_size_info mips_elf64_size_info =
                                        _bfd_archive_coff_generic_stat_arch_elt
 #define bfd_elf64_archive_update_armap_timestamp \
                                _bfd_archive_coff_update_armap_timestamp
+#define _bfd_elf64_allow_commons_in_armap bfd_false
 
 #include "elf64-target.h"
index ab679a70d0d3cd6da375a0998dc81f48628e15c3..2a8c3db1e1403bc717f04621621281b0846b3e68 100644 (file)
@@ -200,7 +200,26 @@ elf_link_add_archive_symbols (abfd, info)
          if (h == NULL)
            continue;
 
-         if (h->root.type != bfd_link_hash_undefined)
+         /* We have changed the GNU archiver so that it will only place
+            non-common symbols into its archive map.  Thus if we come across
+            a symbol in the archive map, which is currently considered to be
+            a common symbol, we can safely assume that we should link the
+            element in, in order to get in the definition of the symbol.
+            
+            Previous versions of the archiver would place common symbols into
+            the archive map.  This meant that in order to only link in an
+            element if it contained a *definition* of a common symbol, it
+            would be necessary to read in the element and scan its symbol
+            table - a slow and wasteful process.
+
+            In fact previous versions of this code did not even do that,
+            instead it just unilaterally ignored any symbols in the archive
+            map which were currently marked as common.  So in order to link
+            in an archive element containing the definition of a common
+            symbol it was necessary to have that element also contain the
+            defintion of a currently undefined symbol.  */
+         if (h->root.type != bfd_link_hash_undefined
+             && h->root.type != bfd_link_hash_common)
            {
              if (h->root.type != bfd_link_hash_undefweak)
                defined[i] = true;
index 0a69dd80ee407cbbba7096ed7005223c62599d61..6963d4e5825a27bb0942352ece232ab511eb0366 100644 (file)
@@ -485,6 +485,13 @@ const bfd_target TARGET_BIG_SYM =
 #ifdef bfd_elfNN_archive_functions
       BFD_JUMP_TABLE_ARCHIVE (bfd_elfNN_archive),
 #else
+  /* For ELF based targets we do not want to put common symbols into the
+     archive map.  This is a change from the old behaviour, and it is
+     being done because of a corresponding change in the linker, whereby
+     it will link in any archive element that contains a symbol which is
+     currently common.  (See elflink.h:elf_link_add_archive_symbol).  */
+#undef  _bfd_archive_coff_allow_commons_in_armap
+#define _bfd_archive_coff_allow_commons_in_armap bfd_false
       BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
 #endif
       BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
@@ -580,6 +587,8 @@ const bfd_target TARGET_LITTLE_SYM =
 #ifdef bfd_elfNN_archive_functions
       BFD_JUMP_TABLE_ARCHIVE (bfd_elfNN_archive),
 #else
+#undef  _bfd_archive_coff_allow_commons_in_armap
+#define _bfd_archive_coff_allow_commons_in_armap bfd_false
       BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
 #endif
       BFD_JUMP_TABLE_SYMBOLS (bfd_elfNN),
index 989d7243cbaf3a2edc83786a4cfac2f41968f3d4..f9c9a284bf8e2c0b233a85b353e582dd81ed83db 100644 (file)
@@ -3900,6 +3900,7 @@ ieee_bfd_debug_info_accumulate (abfd, section)
    bfd_true)
 #define ieee_read_ar_hdr bfd_nullvoidptr
 #define ieee_update_armap_timestamp bfd_true
+#define ieee_allow_commons_in_armap bfd_true
 #define ieee_get_elt_at_index _bfd_generic_get_elt_at_index
 
 #define ieee_bfd_is_local_label_name bfd_generic_is_local_label_name
index 79a176d063c473c4eca8f65fbc7e082980f06525..3ea4e8ac49ee58351678bf79911445d675ec12e1 100644 (file)
@@ -211,6 +211,7 @@ extern boolean _bfd_nocore_core_file_matches_executable_p
   ((bfd *(*) PARAMS ((bfd *, symindex))) bfd_nullvoidptr)
 #define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt
 #define _bfd_noarchive_update_armap_timestamp bfd_false
+#define _bfd_noarchive_allow_commons_in_armap bfd_true
 
 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style
    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd).  */
@@ -229,6 +230,7 @@ extern boolean _bfd_archive_bsd_construct_extended_name_table
 #define _bfd_archive_bsd_generic_stat_arch_elt \
   bfd_generic_stat_arch_elt
 extern boolean _bfd_archive_bsd_update_armap_timestamp PARAMS ((bfd *));
+#define _bfd_archive_bsd_allow_commons_in_armap bfd_true
 
 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style
    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff).  */
@@ -247,6 +249,7 @@ extern boolean _bfd_archive_coff_construct_extended_name_table
 #define _bfd_archive_coff_generic_stat_arch_elt \
   bfd_generic_stat_arch_elt
 #define _bfd_archive_coff_update_armap_timestamp bfd_true
+#define _bfd_archive_coff_allow_commons_in_armap bfd_true
 
 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
    support.  Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols).  */
index 26bf7efdedc250d44199fa85afc98944a22fe615..6063dd56184d7314fdf14584d0052690730568c7 100644 (file)
@@ -211,6 +211,7 @@ extern boolean _bfd_nocore_core_file_matches_executable_p
   ((bfd *(*) PARAMS ((bfd *, symindex))) bfd_nullvoidptr)
 #define _bfd_noarchive_generic_stat_arch_elt bfd_generic_stat_arch_elt
 #define _bfd_noarchive_update_armap_timestamp bfd_false
+#define _bfd_noarchive_allow_commons_in_armap bfd_true
 
 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get BSD style
    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd).  */
@@ -229,6 +230,7 @@ extern boolean _bfd_archive_bsd_construct_extended_name_table
 #define _bfd_archive_bsd_generic_stat_arch_elt \
   bfd_generic_stat_arch_elt
 extern boolean _bfd_archive_bsd_update_armap_timestamp PARAMS ((bfd *));
+#define _bfd_archive_bsd_allow_commons_in_armap bfd_true
 
 /* Routines to use for BFD_JUMP_TABLE_ARCHIVE to get COFF style
    archives.  Use BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff).  */
@@ -247,6 +249,7 @@ extern boolean _bfd_archive_coff_construct_extended_name_table
 #define _bfd_archive_coff_generic_stat_arch_elt \
   bfd_generic_stat_arch_elt
 #define _bfd_archive_coff_update_armap_timestamp bfd_true
+#define _bfd_archive_coff_allow_commons_in_armap bfd_true
 
 /* Routines to use for BFD_JUMP_TABLE_SYMBOLS where there is no symbol
    support.  Use BFD_JUMP_TABLE_SYMBOLS (_bfd_nosymbols).  */
index 456180544cb7d831baa143658da98819469897cf..cd5dc4923331d017dc85301b9e1ed2ef65d254f0 100644 (file)
@@ -295,6 +295,7 @@ extern boolean _bfd_ecoff_write_armap
 #define _bfd_ecoff_get_elt_at_index _bfd_generic_get_elt_at_index
 #define _bfd_ecoff_generic_stat_arch_elt bfd_generic_stat_arch_elt
 #define _bfd_ecoff_update_armap_timestamp bfd_true
+#define _bfd_ecoff_allow_commons_in_armap bfd_true
 
 extern long _bfd_ecoff_get_symtab_upper_bound PARAMS ((bfd *abfd));
 extern long _bfd_ecoff_get_symtab PARAMS ((bfd *abfd, asymbol **alocation));
index e69053b82823d315af19b9b58fa8c4e58192086d..c654b562c24bf5b7e3a6afb3453a8fab7af5add7 100644 (file)
@@ -1458,6 +1458,7 @@ oasys_sizeof_headers (abfd, exec)
 #define oasys_read_ar_hdr bfd_nullvoidptr
 #define oasys_get_elt_at_index _bfd_generic_get_elt_at_index
 #define oasys_update_armap_timestamp bfd_true
+#define oasys_allow_commons_in_armap bfd_true
 
 #define oasys_bfd_is_local_label_name bfd_generic_is_local_label_name
 #define oasys_get_lineno _bfd_nosymbols_get_lineno
index 6f2b6c3abd6fd66616ee2460f9c30e8b122c7a3a..ef7de6d9f59576699ae52374324f3883b2f6352e 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -6229,6 +6229,7 @@ som_bfd_link_split_section (abfd, sec)
 #define som_construct_extended_name_table \
   _bfd_archive_coff_construct_extended_name_table
 #define som_update_armap_timestamp     bfd_true
+#define som_allow_commons_in_armap     bfd_true
 #define som_bfd_print_private_bfd_data  _bfd_generic_bfd_print_private_bfd_data
 
 #define som_get_lineno                  _bfd_nosymbols_get_lineno
index a50cc595366710df3e06a0ff6b29051dc579a4bf..e621856904a534526070986afdaa525e8fcd6fc4 100644 (file)
@@ -318,7 +318,8 @@ BFD_JUMP_TABLE macros.
 .CAT(NAME,_openr_next_archived_file),\
 .CAT(NAME,_get_elt_at_index),\
 .CAT(NAME,_generic_stat_arch_elt),\
-.CAT(NAME,_update_armap_timestamp)
+.CAT(NAME,_update_armap_timestamp), \
+.CAT(NAME,_allow_commons_in_armap)
 .  boolean  (*_bfd_slurp_armap) PARAMS ((bfd *));
 .  boolean  (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
 .  boolean  (*_bfd_construct_extended_name_table)
@@ -329,12 +330,13 @@ BFD_JUMP_TABLE macros.
 .                              struct orl *map,
 .                              unsigned int orl_count, 
 .                              int stridx));
-.  PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
+.  PTR      (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
 .  bfd *    (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
 .#define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i))
 .  bfd *    (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));
 .  int      (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
 .  boolean  (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
+.  boolean  (*_bfd_allow_commons_in_armap) PARAMS ((bfd *));
 .
 .  {* Entry points used for symbols.  *}
 .#define BFD_JUMP_TABLE_SYMBOLS(NAME)\
index f0ea63ff92d30630de0792c4035075cd642cd259..9f85249791a56cb5af4fa527bc1151d0bf44ffdd 100644 (file)
--- a/bfd/vms.c
+++ b/bfd/vms.c
@@ -127,6 +127,7 @@ static boolean vms_bfd_merge_private_bfd_data PARAMS ((bfd *ibfd, bfd *obfd));
 static boolean vms_bfd_set_private_flags PARAMS ((bfd *abfd, flagword flags));
 
 #define vms_make_empty_symbol _bfd_vms_make_empty_symbol
+#define vms_allow_commons_in_armap bfd_true
 \f
 /*===========================================================================*/