gdb: remove objfile parameter from get_objfile_bfd_data
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 2 Apr 2021 15:50:45 +0000 (11:50 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 2 Apr 2021 15:51:45 +0000 (11:51 -0400)
I noticed it was unused.  I think that makes sense, as it shows that
objfile_per_bfd_storage is not specific to one objfile (it can be shared
by multiple objfiles that have the same bfd).

There is one thing I wonder though, maybe I'm missing something.  If
the BFD doesn't require relocation, get_objfile_bfd_data stores the
newly allocated object in objfiles_bfd_data, so we can assume that
objfiles_bfd_data is the owner of the object.  When the bfd's refcount
drops to 0, the corresponding objfile_per_bfd_storage object in
objfiles_bfd_data is deleted.

But if the BFD requires relocation, get_objfile_bfd_data returns a newly
allocated object that isn't kept anywhere else (and isn't shared).  So
the objfile becomes the owner of the objfile_per_bfd_storage object.  In
objfile::~objfile, we have this:

    if (obfd)
      gdb_bfd_unref (obfd);
    else
      delete per_bfd;

I'm thinking that obfd could be non-nullptr, and it could require
relocation.  In that case, it would never be freed.  Anyway, that's not
really connected to this patch.

gdb/ChangeLog:

* objfiles.c (get_objfile_bfd_data): Remove objfile parameter,
adjust callers.

Change-Id: Ifa3158074ea6b42686780ba09d0c964b0cf14cf1

gdb/ChangeLog
gdb/objfiles.c

index 3530819cf95d972b3471b46f4ecf23461ec2715e..21cd0f031c2266c3550d89a792693726ea61af67 100644 (file)
@@ -1,3 +1,8 @@
+2021-04-02  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * objfiles.c (get_objfile_bfd_data): Remove objfile parameter,
+       adjust callers.
+
 2021-04-02  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * psympriv.h (struct partial_symtab) <partial_symtab>: Change
index 702900761f38ace98d46efedae28f08c3105cfea..16bbb91c0a64b4396513172569dab67305b0b8b6 100644 (file)
@@ -120,12 +120,10 @@ objfile_per_bfd_storage::~objfile_per_bfd_storage ()
 
 /* Create the per-BFD storage object for OBJFILE.  If ABFD is not
    NULL, and it already has a per-BFD storage object, use that.
-   Otherwise, allocate a new per-BFD storage object.  Note that it is
-   not safe to call this multiple times for a given OBJFILE -- it can
-   only be called when allocating or re-initializing OBJFILE.  */
+   Otherwise, allocate a new per-BFD storage object.  */
 
 static struct objfile_per_bfd_storage *
-get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
+get_objfile_bfd_data (bfd *abfd)
 {
   struct objfile_per_bfd_storage *storage = NULL;
 
@@ -154,7 +152,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
 void
 set_objfile_per_bfd (struct objfile *objfile)
 {
-  objfile->per_bfd = get_objfile_bfd_data (objfile, objfile->obfd);
+  objfile->per_bfd = get_objfile_bfd_data (objfile->obfd);
 }
 
 /* Set the objfile's per-BFD notion of the "main" name and
@@ -363,7 +361,7 @@ objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
       build_objfile_section_table (this);
     }
 
-  per_bfd = get_objfile_bfd_data (this, abfd);
+  per_bfd = get_objfile_bfd_data (abfd);
 }
 
 /* If there is a valid and known entry point, function fills *ENTRY_P with it
This page took 0.028144 seconds and 4 git commands to generate.