From 607b483327fdfc75fb193870b3c4e7445ce3f64d Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 19 May 2020 12:57:15 +0930 Subject: [PATCH] Use bfd_get_filename throughout ld * 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 | 15 +++++++++++++++ ld/emultempl/beos.em | 7 ++++--- ld/emultempl/pe.em | 21 +++++++++++---------- ld/emultempl/pep.em | 20 +++++++++++--------- ld/emultempl/spuelf.em | 4 ++-- ld/ldlang.c | 10 +++++----- ld/ldmain.c | 4 ++-- ld/ldmisc.c | 10 ++++++---- ld/pe-dll.c | 38 +++++++++++++++++++++----------------- ld/plugin.c | 6 +++--- 10 files changed, 80 insertions(+), 55 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index b719d456fb0..730517124e9 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,18 @@ +2020-05-19 Alan Modra + + * 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 * ldemul.h (ldemul_print_symbol): New. diff --git a/ld/emultempl/beos.em b/ld/emultempl/beos.em index 442ff1222c6..4da5eeef6d2 100644 --- a/ld/emultempl/beos.em +++ b/ld/emultempl/beos.em @@ -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 diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 3dd36de373d..fe65d2b266e 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -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); diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index 39ddd8f23ec..699b86501c5 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -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); diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em index baaf44f3b46..56beb84f99c 100644 --- a/ld/emultempl/spuelf.em +++ b/ld/emultempl/spuelf.em @@ -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) diff --git a/ld/ldlang.c b/ld/ldlang.c index 35791e4e2c0..3d653d460d0 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -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) { diff --git a/ld/ldmain.c b/ld/ldmain.c index 54d3ee39cc8..04a3f7a5117 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -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); diff --git a/ld/ldmisc.c b/ld/ldmisc.c index b714b971053..cc090a51010 100644 --- a/ld/ldmisc.c +++ b/ld/ldmisc.c @@ -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); diff --git a/ld/pe-dll.c b/ld/pe-dll.c index 0ed21facd07..60504293f35 100644 --- a/ld/pe-dll.c +++ b/ld/pe-dll.c @@ -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); diff --git a/ld/plugin.c b/ld/plugin.c index 4ef4a236650..60beacd0627 100644 --- a/ld/plugin.c +++ b/ld/plugin.c @@ -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; -- 2.30.2