Tidy dwarf1 cached section contents

Alan Modra amodra@gmail.com
Fri Mar 24 10:33:11 GMT 2023


	* dwarf1.c (_bfd_dwarf1_cleanup_debug_info): New function.
	* libbfd-in.h (_bfd_dwarf1_cleanup_debug_info): Declare.
	* elf.c (_bfd_elf_close_and_cleanup): Call it.
	* elf-bfd.h (struct elf_obj_tdata): Make dwarf1_find_line_info
	a void*.
	* libbfd.h: Regenerate.

diff --git a/bfd/dwarf1.c b/bfd/dwarf1.c
index a80d19db7de..d7c50eaa068 100644
--- a/bfd/dwarf1.c
+++ b/bfd/dwarf1.c
@@ -593,3 +593,15 @@ _bfd_dwarf1_find_nearest_line (bfd *abfd,
 
   return false;
 }
+
+void
+_bfd_dwarf1_cleanup_debug_info (bfd *abfd ATTRIBUTE_UNUSED, void **pinfo)
+{
+  struct dwarf1_debug* stash = *pinfo;
+
+  if (stash == NULL)
+    return;
+
+  free (stash->debug_section);
+  free (stash->line_section);
+}
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index dff19822547..2a64a1e6a03 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2070,7 +2070,7 @@ struct elf_obj_tdata
   void *line_info;
 
   /* A place to stash dwarf1 info for this bfd.  */
-  struct dwarf1_debug *dwarf1_find_line_info;
+  void *dwarf1_find_line_info;
 
   /* A place to stash dwarf2 info for this bfd.  */
   void *dwarf2_find_line_info;
diff --git a/bfd/elf.c b/bfd/elf.c
index c9abc2579e5..45e53640e8f 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -9592,6 +9592,7 @@ _bfd_elf_close_and_cleanup (bfd *abfd)
       if (elf_tdata (abfd)->o != NULL && elf_shstrtab (abfd) != NULL)
 	_bfd_elf_strtab_free (elf_shstrtab (abfd));
       _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
+      _bfd_dwarf1_cleanup_debug_info (abfd, &tdata->dwarf1_find_line_info);
       _bfd_stab_cleanup (abfd, &tdata->line_info);
     }
 
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index ff58421f28b..1c9f34bb6d7 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -573,6 +573,10 @@ extern bool _bfd_dwarf1_find_nearest_line
   (bfd *, asymbol **, asection *, bfd_vma,
    const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
 
+/* Clean up the data used to handle DWARF 1 debugging information. */
+extern void _bfd_dwarf1_cleanup_debug_info
+  (bfd *, void **) ATTRIBUTE_HIDDEN;
+
 struct dwarf_debug_section
 {
   const char * uncompressed_name;
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index fa6f2d71b60..d1dc7b912a0 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -579,6 +579,10 @@ extern bool _bfd_dwarf1_find_nearest_line
   (bfd *, asymbol **, asection *, bfd_vma,
    const char **, const char **, unsigned int *) ATTRIBUTE_HIDDEN;
 
+/* Clean up the data used to handle DWARF 1 debugging information. */
+extern void _bfd_dwarf1_cleanup_debug_info
+  (bfd *, void **) ATTRIBUTE_HIDDEN;
+
 struct dwarf_debug_section
 {
   const char * uncompressed_name;

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list