summaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-08-03 13:31:57 +0100
committerNick Clifton <nickc@redhat.com>2022-08-03 13:31:57 +0100
commita6ad7914429a22d3d835bd998b032212b776a08a (patch)
treed81caa6275932745dedefa9f17d391454a84a19f /bfd
parent8b8da1a9f31941fa167c9f2bd2a80cdd1dccb452 (diff)
Fix a conflict between the linker's need to rename some PE format input libraries and the BFD library's file caching mechanism.
PR 29389 bfd * bfd.c (BFD_CLOSED_BY_CACHE): New bfd flag. * cache.c (bfd_cache_delete): Set BFD_CLOSED_BY_DELETE on the closed bfd. (bfd_cache_lookup_worker): Clear BFD_CLOSED_BY_DELETE on the newly reopened bfd. * opncls.c (bfd_set_filename): Refuse to change the name of a bfd that has been closed by bfd_cache_delete. Mark changed bfds as uncacheable. * bfd-in2.h: Regenerate. ld * ldlang.h (lang_input_statement_struct): Add sort_key field. * emultempl/pe.em (after_open): If multiple import libraries refer to the same bfd, store their names in the sort_key field. * emultempl/pep.em (after_open): Likewise. * ldlang.c (sort_filename): New function. Returns the filename to be used when sorting input files. (wild_sort): Use the sort_filename function.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog13
-rw-r--r--bfd/bfd-in2.h2
-rw-r--r--bfd/bfd.c2
-rw-r--r--bfd/cache.c8
-rw-r--r--bfd/opncls.c24
5 files changed, 44 insertions, 5 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index afabbc0f56..cb1f48ba48 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,16 @@
+2022-08-03 Nick Clifton <nickc@redhat.com>
+
+ PR 29389
+ * bfd.c (BFD_CLOSED_BY_CACHE): New bfd flag.
+ * cache.c (bfd_cache_delete): Set BFD_CLOSED_BY_DELETE on the
+ closed bfd.
+ (bfd_cache_lookup_worker): Clear BFD_CLOSED_BY_DELETE on the newly
+ reopened bfd.
+ * opncls.c (bfd_set_filename): Refuse to change the name of a bfd
+ that has been closed by bfd_cache_delete. Mark changed bfds as
+ uncacheable.
+ * bfd-in2.h: Regenerate.
+
2022-07-29 Nick Clifton <nickc@redhat.com>
PR 29424
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 91ada0e3a9..a95e4a24ca 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -6638,6 +6638,8 @@ struct bfd
/* Put pathnames into archives (non-POSIX). */
#define BFD_ARCHIVE_FULL_PATH 0x100000
+#define BFD_CLOSED_BY_CACHE 0x200000
+
/* Flags bits to be saved in bfd_preserve_save. */
#define BFD_FLAGS_SAVED \
(BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_LINKER_CREATED \
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 3e85e171e3..5e5272b908 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -176,6 +176,8 @@ CODE_FRAGMENT
. {* Put pathnames into archives (non-POSIX). *}
.#define BFD_ARCHIVE_FULL_PATH 0x100000
.
+.#define BFD_CLOSED_BY_CACHE 0x200000
+.
. {* Flags bits to be saved in bfd_preserve_save. *}
.#define BFD_FLAGS_SAVED \
. (BFD_IN_MEMORY | BFD_COMPRESS | BFD_DECOMPRESS | BFD_LINKER_CREATED \
diff --git a/bfd/cache.c b/bfd/cache.c
index 8a6d359a78..73b68c7aff 100644
--- a/bfd/cache.c
+++ b/bfd/cache.c
@@ -177,6 +177,7 @@ bfd_cache_delete (bfd *abfd)
abfd->iostream = NULL;
--open_files;
+ abfd->flags |= BFD_CLOSED_BY_CACHE;
return ret;
}
@@ -265,10 +266,13 @@ bfd_cache_lookup_worker (bfd *abfd, enum cache_flag flag)
&& !(flag & CACHE_NO_SEEK_ERROR))
bfd_set_error (bfd_error_system_call);
else
- return (FILE *) abfd->iostream;
+ {
+ abfd->flags &= ~BFD_CLOSED_BY_CACHE;
+ return (FILE *) abfd->iostream;
+ }
/* xgettext:c-format */
- _bfd_error_handler (_("reopening %pB: %s\n"),
+ _bfd_error_handler (_("reopening %pB: %s"),
abfd, bfd_errmsg (bfd_get_error ()));
return NULL;
}
diff --git a/bfd/opncls.c b/bfd/opncls.c
index f0ca9048f6..a5bc2de364 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -2107,10 +2107,28 @@ bfd_set_filename (bfd *abfd, const char *filename)
{
size_t len = strlen (filename) + 1;
char *n = bfd_alloc (abfd, len);
- if (n)
+
+ if (n == NULL)
+ return NULL;
+
+ if (abfd->filename != NULL)
{
- memcpy (n, filename, len);
- abfd->filename = n;
+ /* PR 29389. If we attempt to rename a file that has been closed due
+ to caching, then we will not be able to reopen it later on. */
+ if (abfd->iostream == NULL && (abfd->flags & BFD_CLOSED_BY_CACHE))
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return NULL;
+ }
+
+ /* Similarly if we attempt to close a renamed file because the
+ cache is now full, we will not be able to reopen it later on. */
+ if (abfd->iostream != NULL)
+ abfd->cacheable = 0;
}
+
+ memcpy (n, filename, len);
+ abfd->filename = n;
+
return n;
}