Use bfd_get_filename throughout ld
authorAlan Modra <amodra@gmail.com>
Tue, 19 May 2020 03:27:15 +0000 (12:57 +0930)
committerAlan Modra <amodra@gmail.com>
Tue, 19 May 2020 03:27:15 +0000 (12:57 +0930)
* emultempl/beos.em (sort_by_file_name): Use bfd_get_filename
rather than accessing bfd->filename directly.
* emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
* emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
* emultempl/spuelf.em (embedded_spu_file): Likewise.
* ldlang.c (input_statement_is_archive_path, wild_sort),
(check_excluded_libs): Likewise.
* ldmain.c (add_archive_element): Likewise.
* ldmisc.c (vfinfo): Likewise.
* pe-dll.c (auto_export, generate_edata, pe_create_import_fixup),
(pe_dll_generate_implib, pe_process_import_defs): Likewise.
* plugin.c (plugin_object_p): Likewise.

ld/ChangeLog
ld/emultempl/beos.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/emultempl/spuelf.em
ld/ldlang.c
ld/ldmain.c
ld/ldmisc.c
ld/pe-dll.c
ld/plugin.c

index b719d456fb0b9c06acb16706b52d9a82ec0effe8..730517124e919eab11f8fea7a3fdd3b23af0be94 100644 (file)
@@ -1,3 +1,18 @@
+2020-05-19  Alan Modra  <amodra@gmail.com>
+
+       * emultempl/beos.em (sort_by_file_name): Use bfd_get_filename
+       rather than accessing bfd->filename directly.
+       * emultempl/pe.em (gld_${EMULATION_NAME}_after_open): Likewise.
+       * emultempl/pep.em (gld_${EMULATION_NAME}_after_open): Likewise.
+       * emultempl/spuelf.em (embedded_spu_file): Likewise.
+       * ldlang.c (input_statement_is_archive_path, wild_sort),
+       (check_excluded_libs): Likewise.
+       * ldmain.c (add_archive_element): Likewise.
+       * ldmisc.c (vfinfo): Likewise.
+       * pe-dll.c (auto_export, generate_edata, pe_create_import_fixup),
+       (pe_dll_generate_implib, pe_process_import_defs): Likewise.
+       * plugin.c (plugin_object_p): Likewise.
+
 2020-05-18  Douglas B Rupp  <rupp@adacore.com>
 
        * ldemul.h (ldemul_print_symbol): New.
index 442ff1222c6e4ddfd2a6e5ab363788295f5f2a48..4da5eeef6d2376eb93269ce243d1dbecf9382660 100644 (file)
@@ -400,12 +400,13 @@ sort_by_file_name (const void *a, const void *b)
   asection *sb = (*rb)->section;
   int i, a_sec, b_sec;
 
-  i = filename_cmp (sa->owner->my_archive->filename,
-                   sb->owner->my_archive->filename);
+  i = filename_cmp (bfd_get_filename (sa->owner->my_archive),
+                   bfd_get_filename (sb->owner->my_archive));
   if (i != 0)
     return i;
 
-  i = filename_cmp (sa->owner->filename, sb->owner->filename);
+  i = filename_cmp (bfd_get_filename (sa->owner),
+                   bfd_get_filename (sb->owner));
   if (i != 0)
     return i;
   /* the tail idata4/5 are the only ones without relocs to an
index 3dd36de373dbb7c57f6503a0f252645a7cfe5cce..fe65d2b266e5c49ad521a5a49078061e81fef146 100644 (file)
@@ -1338,7 +1338,7 @@ gld_${EMULATION_NAME}_after_open (void)
       bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
 
       for (a = link_info.input_bfds; a; a = a->link.next)
-       printf ("*%s\n",a->filename);
+       printf ("*%s\n", bfd_get_filename (a));
     }
 #endif
 
@@ -1599,7 +1599,7 @@ gld_${EMULATION_NAME}_after_open (void)
                       members, so look for the first element with a .dll
                       extension, and use that for the remainder of the
                       comparisons.  */
-                   pnt = strrchr (is3->the_bfd->filename, '.');
+                   pnt = strrchr (bfd_get_filename (is3->the_bfd), '.');
                    if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
                      break;
                  }
@@ -1616,12 +1616,12 @@ gld_${EMULATION_NAME}_after_open (void)
                      {
                        /* Skip static members, ie anything with a .obj
                           extension.  */
-                       pnt = strrchr (is2->the_bfd->filename, '.');
+                       pnt = strrchr (bfd_get_filename (is2->the_bfd), '.');
                        if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
                          continue;
 
-                       if (filename_cmp (is3->the_bfd->filename,
-                                         is2->the_bfd->filename))
+                       if (filename_cmp (bfd_get_filename (is3->the_bfd),
+                                         bfd_get_filename (is2->the_bfd)))
                          {
                            is_ms_arch = 0;
                            break;
@@ -1633,7 +1633,7 @@ gld_${EMULATION_NAME}_after_open (void)
            /* This fragment might have come from an .obj file in a Microsoft
               import, and not an actual import record. If this is the case,
               then leave the filename alone.  */
-           pnt = strrchr (is->the_bfd->filename, '.');
+           pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
 
            if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
              {
@@ -1655,11 +1655,10 @@ gld_${EMULATION_NAME}_after_open (void)
                else /* sentinel */
                  seq = 'c';
 
-
                /* PR 25993: It is possible that is->the_bfd-filename == is->filename.
                   In which case calling bfd_set_filename on one will free the memory
                   pointed to by the other.  */
-               if (is->filename == is->the_bfd->filename)
+               if (is->filename == bfd_get_filename (is->the_bfd))
                  {
                    new_name = xmalloc (strlen (is->filename) + 3);
                    sprintf (new_name, "%s.%c", is->filename, seq);
@@ -1668,8 +1667,10 @@ gld_${EMULATION_NAME}_after_open (void)
                  }
                else
                  {
-                   new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
-                   sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
+                   new_name
+                     = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3);
+                   sprintf (new_name, "%s.%c",
+                            bfd_get_filename (is->the_bfd), seq);
                    bfd_set_filename (is->the_bfd, new_name);
 
                    new_name = xmalloc (strlen (is->filename) + 3);
index 39ddd8f23ec1208882c40606c19ec5e540734d67..699b86501c55a325d8348420dd34817f41364341 100644 (file)
@@ -1327,7 +1327,7 @@ gld_${EMULATION_NAME}_after_open (void)
       bfd_hash_traverse (&link_info.hash->table, pr_sym, NULL);
 
       for (a = link_info.input_bfds; a; a = a->link.next)
-       printf ("*%s\n",a->filename);
+       printf ("*%s\n", bfd_get_filename (a));
     }
 #endif
 
@@ -1567,7 +1567,7 @@ gld_${EMULATION_NAME}_after_open (void)
                       members, so look for the first element with a .dll
                       extension, and use that for the remainder of the
                       comparisons.  */
-                   pnt = strrchr (is3->the_bfd->filename, '.');
+                   pnt = strrchr (bfd_get_filename (is3->the_bfd), '.');
                    if (pnt != NULL && filename_cmp (pnt, ".dll") == 0)
                      break;
                  }
@@ -1584,12 +1584,12 @@ gld_${EMULATION_NAME}_after_open (void)
                      {
                        /* Skip static members, ie anything with a .obj
                           extension.  */
-                       pnt = strrchr (is2->the_bfd->filename, '.');
+                       pnt = strrchr (bfd_get_filename (is2->the_bfd), '.');
                        if (pnt != NULL && filename_cmp (pnt, ".obj") == 0)
                          continue;
 
-                       if (filename_cmp (is3->the_bfd->filename,
-                                         is2->the_bfd->filename))
+                       if (filename_cmp (bfd_get_filename (is3->the_bfd),
+                                         bfd_get_filename (is2->the_bfd)))
                          {
                            is_ms_arch = 0;
                            break;
@@ -1601,7 +1601,7 @@ gld_${EMULATION_NAME}_after_open (void)
            /* This fragment might have come from an .obj file in a Microsoft
               import, and not an actual import record. If this is the case,
               then leave the filename alone.  */
-           pnt = strrchr (is->the_bfd->filename, '.');
+           pnt = strrchr (bfd_get_filename (is->the_bfd), '.');
 
            if (is_ms_arch && (filename_cmp (pnt, ".dll") == 0))
              {
@@ -1626,7 +1626,7 @@ gld_${EMULATION_NAME}_after_open (void)
                /* PR 25993: It is possible that is->the_bfd-filename == is->filename.
                   In which case calling bfd_set_filename on one will free the memory
                   pointed to by the other.  */
-               if (is->filename == is->the_bfd->filename)
+               if (is->filename == bfd_get_filename (is->the_bfd))
                  {
                    new_name = xmalloc (strlen (is->filename) + 3);
                    sprintf (new_name, "%s.%c", is->filename, seq);
@@ -1635,8 +1635,10 @@ gld_${EMULATION_NAME}_after_open (void)
                  }
                else
                  {
-                   new_name = xmalloc (strlen (is->the_bfd->filename) + 3);
-                   sprintf (new_name, "%s.%c", is->the_bfd->filename, seq);
+                   new_name
+                     = xmalloc (strlen (bfd_get_filename (is->the_bfd)) + 3);
+                   sprintf (new_name, "%s.%c",
+                            bfd_get_filename (is->the_bfd), seq);
                    bfd_set_filename (is->the_bfd, new_name);
 
                    new_name = xmalloc (strlen (is->filename) + 3);
index baaf44f3b464c83b59fbf290d6d6636d71c47903..56beb84f99c0045c3a39dbc0485176d05f477e2b 100644 (file)
@@ -500,7 +500,7 @@ embedded_spu_file (lang_input_statement_type *entry, const char *flags)
     return FALSE;
 
   /* Use the filename as the symbol marking the program handle struct.  */
-  sym = base_name (entry->the_bfd->filename);
+  sym = base_name (bfd_get_filename (entry->the_bfd));
 
   handle = xstrdup (sym);
   for (p = handle; *p; ++p)
@@ -532,7 +532,7 @@ embedded_spu_file (lang_input_statement_type *entry, const char *flags)
   cmd[0] = EMBEDSPU;
   cmd[1] = flags;
   cmd[2] = handle;
-  cmd[3] = entry->the_bfd->filename;
+  cmd[3] = bfd_get_filename (entry->the_bfd);
   cmd[4] = oname;
   cmd[5] = NULL;
   if (verbose)
index 35791e4e2c015cc83c9388e2ee815a99638ef794..3d653d460d0a69812b10a175282852a19fbcc10b 100644 (file)
@@ -232,7 +232,7 @@ input_statement_is_archive_path (const char *file_spec, char *sep,
 
       if (sep != file_spec)
        {
-         const char *aname = f->the_bfd->my_archive->filename;
+         const char *aname = bfd_get_filename (f->the_bfd->my_archive);
          *sep = 0;
          match = name_match (file_spec, aname) == 0;
          *sep = link_info.path_separator;
@@ -294,7 +294,7 @@ walk_wild_file_in_exclude_list (struct name_list *exclude_list,
       else if (file->the_bfd != NULL
               && file->the_bfd->my_archive != NULL
               && name_match (list_tmp->name,
-                             file->the_bfd->my_archive->filename) == 0)
+                             bfd_get_filename (file->the_bfd->my_archive)) == 0)
        return TRUE;
     }
 
@@ -2776,7 +2776,7 @@ wild_sort (lang_wild_statement_type *wild,
            }
          else
            {
-             ln = ls->section->owner->filename;
+             ln = bfd_get_filename (ls->section->owner);
              la = FALSE;
            }
 
@@ -2791,7 +2791,7 @@ wild_sort (lang_wild_statement_type *wild,
              if (fa)
                fn = file->filename;
              if (la)
-               ln = ls->section->owner->filename;
+               ln = bfd_get_filename (ls->section->owner);
 
              i = filename_cmp (fn, ln);
              if (i > 0)
@@ -2986,7 +2986,7 @@ check_excluded_libs (bfd *abfd)
   while (lib)
     {
       int len = strlen (lib->name);
-      const char *filename = lbasename (abfd->filename);
+      const char *filename = lbasename (bfd_get_filename (abfd));
 
       if (strcmp (lib->name, "ALL") == 0)
        {
index 54d3ee39cc828746d6114661e2ccdf32f1def8c8..04a3f7a5117801ca7fa6ec35757966bdeaa01017 100644 (file)
@@ -815,8 +815,8 @@ add_archive_element (struct bfd_link_info *info,
   input = (lang_input_statement_type *)
       xcalloc (1, sizeof (lang_input_statement_type));
   input->header.type = lang_input_statement_enum;
-  input->filename = abfd->filename;
-  input->local_sym_name = abfd->filename;
+  input->filename = bfd_get_filename (abfd);
+  input->local_sym_name = bfd_get_filename (abfd);
   input->the_bfd = abfd;
 
   parent = bfd_usrdata (abfd->my_archive);
index b714b97105369e638f00041079f64ee3d6ff86c5..cc090a5101033d3929a9bb1904d8745e4d3acadf 100644 (file)
@@ -456,10 +456,11 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                    fprintf (fp, "%s generated", program_name);
                  else if (abfd->my_archive != NULL
                           && !bfd_is_thin_archive (abfd->my_archive))
-                   fprintf (fp, "%s(%s)", abfd->my_archive->filename,
-                            abfd->filename);
+                   fprintf (fp, "%s(%s)",
+                            bfd_get_filename (abfd->my_archive),
+                            bfd_get_filename (abfd));
                  else
-                   fprintf (fp, "%s", abfd->filename);
+                   fprintf (fp, "%s", bfd_get_filename (abfd));
                }
              else if (*fmt == 'I')
                {
@@ -472,7 +473,8 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bfd_boolean is_warning)
                  if (i->the_bfd != NULL
                      && i->the_bfd->my_archive != NULL
                      && !bfd_is_thin_archive (i->the_bfd->my_archive))
-                   fprintf (fp, "(%s)%s", i->the_bfd->my_archive->filename,
+                   fprintf (fp, "(%s)%s",
+                            bfd_get_filename (i->the_bfd->my_archive),
                             i->local_sym_name);
                  else
                    fprintf (fp, "%s", i->filename);
index 0ed21facd07dd5a12f29817b32ad2c47fd1a4e92..60504293f35878e0518185e2495db6c70777aa8e 100644 (file)
@@ -560,7 +560,7 @@ auto_export (bfd *abfd, def_file *d, const char *n)
   const char * libname = NULL;
 
   if (abfd && abfd->my_archive)
-    libname = lbasename (abfd->my_archive->filename);
+    libname = lbasename (bfd_get_filename (abfd->my_archive));
 
   key.name = key.its_name = (char *) n;
 
@@ -594,7 +594,7 @@ auto_export (bfd *abfd, def_file *d, const char *n)
 
       /* Next, exclude symbols from certain startup objects.  */
 
-      if (abfd && (p = lbasename (abfd->filename)))
+      if (abfd && (p = lbasename (bfd_get_filename (abfd))))
        {
          afptr = autofilter_objlist;
          while (afptr->name)
@@ -655,7 +655,7 @@ auto_export (bfd *abfd, def_file *d, const char *n)
        }
       else if (ex->type == EXCLUDEFORIMPLIB)
        {
-         if (filename_cmp (abfd->filename, ex->string) == 0)
+         if (filename_cmp (bfd_get_filename (abfd), ex->string) == 0)
            return 0;
        }
       else if (strcmp (n, ex->string) == 0)
@@ -1079,7 +1079,7 @@ generate_edata (bfd *abfd, struct bfd_link_info *info ATTRIBUTE_UNUSED)
     dll_name = pe_def_file->name;
   else
     {
-      dll_name = abfd->filename;
+      dll_name = bfd_get_filename (abfd);
 
       for (dlnp = dll_name; *dlnp; dlnp++)
        if (*dlnp == '\\' || *dlnp == '/' || *dlnp == ':')
@@ -2767,7 +2767,7 @@ pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name,
       if (!(name_thunk_sym && name_thunk_sym->type == bfd_link_hash_defined))
        {
          b = make_singleton_name_thunk (name, link_info.output_bfd);
-         add_bfd_to_link (b, b->filename, &link_info);
+         add_bfd_to_link (b, bfd_get_filename (b), &link_info);
 
          /* If we ever use autoimport, we have to cast text section writable.  */
          config.text_read_only = FALSE;
@@ -2778,7 +2778,7 @@ pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name,
        {
          b = make_import_fixup_entry (name, fixup_name, symname,
                                       link_info.output_bfd);
-         add_bfd_to_link (b, b->filename, &link_info);
+         add_bfd_to_link (b, bfd_get_filename (b), &link_info);
        }
     }
 
@@ -2794,12 +2794,12 @@ pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name,
 
       b = make_runtime_pseudo_reloc (name, fixup_name, addend, rel->howto->bitsize,
                                     link_info.output_bfd);
-      add_bfd_to_link (b, b->filename, &link_info);
+      add_bfd_to_link (b, bfd_get_filename (b), &link_info);
 
       if (runtime_pseudo_relocs_created++ == 0)
        {
          b = pe_create_runtime_relocator_reference (link_info.output_bfd);
-         add_bfd_to_link (b, b->filename, &link_info);
+         add_bfd_to_link (b, bfd_get_filename (b), &link_info);
        }
     }
 
@@ -2855,7 +2855,7 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_
        {
          if (ex->type != EXCLUDEFORIMPLIB)
            continue;
-         found = (filename_cmp (ex->string, ibfd->filename) == 0);
+         found = (filename_cmp (ex->string, bfd_get_filename (ibfd)) == 0);
        }
       /* If it matched, we must open a fresh BFD for it (the original
         input BFD is still needed for the DLL's final link) and add
@@ -2863,10 +2863,11 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_
       if (found)
        {
          bfd *newbfd = bfd_openr (ibfd->my_archive
-               ? ibfd->my_archive->filename : ibfd->filename, NULL);
+                                  ? bfd_get_filename (ibfd->my_archive)
+                                  : bfd_get_filename (ibfd), NULL);
          if (!newbfd)
            {
-             einfo (_("%X%P: bfd_openr %s: %E\n"), ibfd->filename);
+             einfo (_("%X%P: bfd_openr %s: %E\n"), bfd_get_filename (ibfd));
              return;
            }
          if (ibfd->my_archive)
@@ -2879,19 +2880,22 @@ pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_
              if (!bfd_check_format_matches (arbfd, bfd_archive, NULL))
                {
                  einfo (_("%X%P: %s(%s): can't find member in non-archive file"),
-                   ibfd->my_archive->filename, ibfd->filename);
+                        bfd_get_filename (ibfd->my_archive),
+                        bfd_get_filename (ibfd));
                  return;
                }
              newbfd = NULL;
              while ((newbfd = bfd_openr_next_archived_file (arbfd, newbfd)) != 0)
                {
-                 if (filename_cmp (newbfd->filename, ibfd->filename) == 0)
+                 if (filename_cmp (bfd_get_filename (newbfd),
+                                   bfd_get_filename (ibfd)) == 0)
                    break;
                }
              if (!newbfd)
                {
                  einfo (_("%X%P: %s(%s): can't find member in archive"),
-                   ibfd->my_archive->filename, ibfd->filename);
+                        bfd_get_filename (ibfd->my_archive),
+                        bfd_get_filename (ibfd));
                  return;
                }
            }
@@ -3248,7 +3252,7 @@ pe_process_import_defs (bfd *output_bfd, struct bfd_link_info *linfo)
              if (!do_this_dll)
                {
                  bfd *ar_head = make_head (output_bfd);
-                 add_bfd_to_link (ar_head, ar_head->filename, linfo);
+                 add_bfd_to_link (ar_head, bfd_get_filename (ar_head), linfo);
                  do_this_dll = 1;
                }
              exp.internal_name = imp[i].internal_name;
@@ -3261,13 +3265,13 @@ pe_process_import_defs (bfd *output_bfd, struct bfd_link_info *linfo)
              exp.flag_data = imp[i].data;
              exp.flag_noname = exp.name ? 0 : 1;
              one = make_one (&exp, output_bfd, (! exp.flag_data) && include_jmp_stub);
-             add_bfd_to_link (one, one->filename, linfo);
+             add_bfd_to_link (one, bfd_get_filename (one), linfo);
            }
        }
       if (do_this_dll)
        {
          bfd *ar_tail = make_tail (output_bfd);
-         add_bfd_to_link (ar_tail, ar_tail->filename, linfo);
+         add_bfd_to_link (ar_tail, bfd_get_filename (ar_tail), linfo);
        }
 
       free (dll_symname);
index 4ef4a236650ce97b51ed6bd7edd5369a035f18f6..60beacd06276c292312aede9f3c78e301ce5663f 100644 (file)
@@ -1191,7 +1191,7 @@ plugin_object_p (bfd *ibfd)
 
   /* We create a dummy BFD, initially empty, to house whatever symbols
      the plugin may want to add.  */
-  abfd = plugin_get_ir_dummy_bfd (ibfd->filename, ibfd);
+  abfd = plugin_get_ir_dummy_bfd (bfd_get_filename (ibfd), ibfd);
 
   input = bfd_alloc (abfd, sizeof (*input));
   if (input == NULL)
@@ -1201,7 +1201,7 @@ plugin_object_p (bfd *ibfd)
   if (!bfd_plugin_open_input (ibfd, &file))
     return NULL;
 
-  if (file.name == ibfd->filename)
+  if (file.name == bfd_get_filename (ibfd))
     {
       /* We must copy filename attached to ibfd if it is not an archive
         member since it may be freed by bfd_close below.  */
@@ -1217,7 +1217,7 @@ plugin_object_p (bfd *ibfd)
   input->use_mmap = FALSE;
   input->offset = file.offset;
   input->filesize = file.filesize;
-  input->name = plugin_strdup (abfd, ibfd->filename);
+  input->name = plugin_strdup (abfd, bfd_get_filename (ibfd));
 
   claimed = 0;
 
This page took 0.034827 seconds and 4 git commands to generate.