diff options
author | Alan Modra <amodra@gmail.com> | 2015-02-14 18:38:32 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2015-02-14 23:41:54 +1030 |
commit | ce875075f9c8acc57bb0ec516ae3ba50064e52b7 (patch) | |
tree | e3957d0a0a9b9931194f532155acd9386bcc71a3 /bfd/archive.c | |
parent | 0a60f874dc25306c48fab8f7655813eb1bfeca8f (diff) | |
download | gdb-ce875075f9c8acc57bb0ec516ae3ba50064e52b7.zip gdb-ce875075f9c8acc57bb0ec516ae3ba50064e52b7.tar.gz gdb-ce875075f9c8acc57bb0ec516ae3ba50064e52b7.tar.bz2 |
PR ld/17973 LTO file syms
LTO output objects have an STT_FILE symbol using the name of the file,
a temporary file. This results in executables that can't be exactly
reproduced, so the file name needs to be dropped. We don't want to
lose all file symbols when linking a mix of lto and non-lto objects as
a file symbol can be used to figure which source file generated a
given local symbol. So lto output objects need to be marked.
I chose to mark lto output objects with a new bfd flag. This flag is
also used to fix a bug in the link-once handling; An object being
loaded after "loading_lto_outputs" is set might be one extracted from
an archive to satisfy new references from lto objects, not an lto
object itself.
The new flag is copied from archive to elements, and the same done
for no_export. This fixes a bug in that --exclude-libs doesn't work
with thin archives. I'm not completely happy with this part of the
patch and may revist this to avoid the hack in
_bfd_look_for_bfd_in_cache.
PR ld/17973
include/
* bfdlink.h (struct bfd_link_info): Delete loading_lto_outputs.
bfd/
* bfd.c (struct bfd): Add lto_output.
* linker.c (_bfd_handle_already_linked): Explicitly test for
objects added by the lto plugin.
* opncls.c (_bfd_new_bfd_contained_in): Copy lto_output and
no_export flags from archive.
* archive.c (open_nested_file): New function, setting lto_output
and no_export, extracted from..
(find_nested_archive): ..here. Flip params. Rename from
_bfd_find_nested_archive.
(_bfd_get_elt_at_filepos): Correct var typo. Use open_nested_file.
(_bfd_look_for_bfd_in_cache): Copy no_export.
* elflink.c (elf_link_add_object_symbols): Remove now unnecessary
my_archive->no_export test.
(elf_link_input_bfd): Drop existing lto_output STT_FILE syms.
Don't use the file name when adding lto_output STT_FILE sym.
* bfd-in2.h: Regenerate.
ld/
* ldlang.h (struct lang_input_statement_flags): Add lto_output.
* ldlang.c (lang_process): Don't set loading_lto_outputs.
* ldfile.c (ldfile_try_open_bfd): Transfer entry flags.lto_output
to bfd.
* plugin.c (add_input_file, add_input_library): Set flags.lto_output.
Diffstat (limited to 'bfd/archive.c')
-rw-r--r-- | bfd/archive.c | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/bfd/archive.c b/bfd/archive.c index cc4c52f..3899d84 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -311,8 +311,12 @@ _bfd_look_for_bfd_in_cache (bfd *arch_bfd, file_ptr filepos) struct ar_cache *entry = (struct ar_cache *) htab_find (hash_table, &m); if (!entry) return NULL; - else - return entry->arbfd; + + /* Unfortunately this flag is set after checking that we have + an archive, and checking for an archive means one element has + sneaked into the cache. */ + entry->arbfd->no_export = arch_bfd->no_export; + return entry->arbfd; } else return NULL; @@ -375,10 +379,27 @@ _bfd_add_bfd_to_archive_cache (bfd *arch_bfd, file_ptr filepos, bfd *new_elt) } static bfd * -_bfd_find_nested_archive (bfd *arch_bfd, const char *filename) +open_nested_file (const char *filename, bfd *archive) { - bfd *abfd; const char *target; + bfd *n_bfd; + + target = NULL; + if (!archive->target_defaulted) + target = archive->xvec->name; + n_bfd = bfd_openr (filename, target); + if (n_bfd != NULL) + { + n_bfd->lto_output = archive->lto_output; + n_bfd->no_export = archive->no_export; + } + return n_bfd; +} + +static bfd * +find_nested_archive (const char *filename, bfd *arch_bfd) +{ + bfd *abfd; /* PR 15140: Don't allow a nested archive pointing to itself. */ if (filename_cmp (filename, arch_bfd->filename) == 0) @@ -394,10 +415,7 @@ _bfd_find_nested_archive (bfd *arch_bfd, const char *filename) if (filename_cmp (filename, abfd->filename) == 0) return abfd; } - target = NULL; - if (!arch_bfd->target_defaulted) - target = arch_bfd->xvec->name; - abfd = bfd_openr (filename, target); + abfd = open_nested_file (filename, arch_bfd); if (abfd) { abfd->archive_next = arch_bfd->nested_archives; @@ -626,12 +644,12 @@ bfd * _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos) { struct areltdata *new_areldata; - bfd *n_nfd; + bfd *n_bfd; char *filename; - n_nfd = _bfd_look_for_bfd_in_cache (archive, filepos); - if (n_nfd) - return n_nfd; + n_bfd = _bfd_look_for_bfd_in_cache (archive, filepos); + if (n_bfd) + return n_bfd; if (0 > bfd_seek (archive, filepos, SEEK_SET)) return NULL; @@ -643,8 +661,6 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos) if (bfd_is_thin_archive (archive)) { - const char *target; - /* This is a proxy entry for an external file. */ if (! IS_ABSOLUTE_PATH (filename)) { @@ -660,7 +676,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos) { /* This proxy entry refers to an element of a nested archive. Locate the member of that archive and return a bfd for it. */ - bfd *ext_arch = _bfd_find_nested_archive (archive, filename); + bfd *ext_arch = find_nested_archive (filename, archive); if (ext_arch == NULL || ! bfd_check_format (ext_arch, bfd_archive)) @@ -668,57 +684,55 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos) free (new_areldata); return NULL; } - n_nfd = _bfd_get_elt_at_filepos (ext_arch, new_areldata->origin); - if (n_nfd == NULL) + n_bfd = _bfd_get_elt_at_filepos (ext_arch, new_areldata->origin); + if (n_bfd == NULL) { free (new_areldata); return NULL; } - n_nfd->proxy_origin = bfd_tell (archive); - return n_nfd; + n_bfd->proxy_origin = bfd_tell (archive); + return n_bfd; } + /* It's not an element of a nested archive; open the external file as a bfd. */ - target = NULL; - if (!archive->target_defaulted) - target = archive->xvec->name; - n_nfd = bfd_openr (filename, target); - if (n_nfd == NULL) + n_bfd = open_nested_file (filename, archive); + if (n_bfd == NULL) bfd_set_error (bfd_error_malformed_archive); } else { - n_nfd = _bfd_create_empty_archive_element_shell (archive); + n_bfd = _bfd_create_empty_archive_element_shell (archive); } - if (n_nfd == NULL) + if (n_bfd == NULL) { free (new_areldata); return NULL; } - n_nfd->proxy_origin = bfd_tell (archive); + n_bfd->proxy_origin = bfd_tell (archive); if (bfd_is_thin_archive (archive)) { - n_nfd->origin = 0; + n_bfd->origin = 0; } else { - n_nfd->origin = n_nfd->proxy_origin; - n_nfd->filename = xstrdup (filename); + n_bfd->origin = n_bfd->proxy_origin; + n_bfd->filename = xstrdup (filename); } - n_nfd->arelt_data = new_areldata; + n_bfd->arelt_data = new_areldata; /* Copy BFD_COMPRESS and BFD_DECOMPRESS flags. */ - n_nfd->flags |= archive->flags & (BFD_COMPRESS | BFD_DECOMPRESS); + n_bfd->flags |= archive->flags & (BFD_COMPRESS | BFD_DECOMPRESS); - if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_nfd)) - return n_nfd; + if (_bfd_add_bfd_to_archive_cache (archive, filepos, n_bfd)) + return n_bfd; free (new_areldata); - n_nfd->arelt_data = NULL; + n_bfd->arelt_data = NULL; return NULL; } |