]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - bfd/opncls.c
Fix a conflict between the linker's need to rename some PE format input libraries...
[thirdparty/binutils-gdb.git] / bfd / opncls.c
index 4fb79324c0ad39a6606790f459b369157e00090a..a5bc2de3648135e2a304041b169c7c1d827f1b87 100644 (file)
@@ -1,5 +1,5 @@
 /* opncls.c -- open and close a BFD.
-   Copyright (C) 1990-2021 Free Software Foundation, Inc.
+   Copyright (C) 1990-2022 Free Software Foundation, Inc.
 
    Written by Cygnus Support.
 
@@ -1032,6 +1032,8 @@ bfd_alloc (bfd *abfd, bfd_size_type size)
   ret = objalloc_alloc ((struct objalloc *) abfd->memory, ul_size);
   if (ret == NULL)
     bfd_set_error (bfd_error_no_memory);
+  else
+    abfd->alloc_size += size;
   return ret;
 }
 
@@ -2105,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;
 }