xcoff free_cached_info

Message ID acTdWzhC1hvO_fjx@squeak.grove.modra.org
State New
Headers
Series xcoff free_cached_info |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 fail Patch failed to apply

Commit Message

Alan Modra March 26, 2026, 7:16 a.m. UTC
  Most coff/pe formats allow reading of core files as objects, and so
use struct coff_tdata (or an extension of that struct) in the bfd
tdata field for core files.  The xcoff backend uses an entirely
different tdata struct for core files, and therefore can't use
_bfd_coff_free_cached_info.

	* coff-rs6000.c (_bfd_xcoff_bfd_free_cached_info): New function.
	(_bfd_xcoff_bfd_free_cached_info): Don't define.
	* coff64-rs6000.c (rs6000_xcoff64_vec): Use the above.
	(rs6000_xcoff64_aix_vec): Likewise.
	* libxcoff.h (_bfd_xcoff_bfd_free_cached_info): Declare.
  

Comments

Aditya Kamath March 26, 2026, 10:12 a.m. UTC | #1
Thank you Alan.

I have tested the same. Thank you for the fix.

Have a nice day ahead.

Regards,
Aditya.



From: Alan Modra <amodra@gmail.com>
Date: Thursday, 26 March 2026 at 12:46 PM
To: Aditya Vidyadhar Kamath <akamath996@gmail.com>
Cc: binutils@sourceware.org <binutils@sourceware.org>, Aditya Kamath <Aditya.Kamath1@ibm.com>, SANGAMESH MALLAYYA <sangamesh.swamy@in.ibm.com>
Subject: [EXTERNAL] xcoff free_cached_info

Most coff/pe formats allow reading of core files as objects, and so
use struct coff_tdata (or an extension of that struct) in the bfd
tdata field for core files.  The xcoff backend uses an entirely
different tdata struct for core files, and therefore can't use
_bfd_coff_free_cached_info.

        * coff-rs6000.c (_bfd_xcoff_bfd_free_cached_info): New function.
        (_bfd_xcoff_bfd_free_cached_info): Don't define.
        * coff64-rs6000.c (rs6000_xcoff64_vec): Use the above.
        (rs6000_xcoff64_aix_vec): Likewise.
        * libxcoff.h (_bfd_xcoff_bfd_free_cached_info): Declare.

diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 00e0f5442f7..b69b881e684 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -2868,7 +2868,17 @@ _bfd_xcoff_sizeof_headers (bfd *abfd,

   return size;
 }
-
+
+bool
+_bfd_xcoff_bfd_free_cached_info (bfd *abfd)
+{
+  /* xcoff bfd_core does not have a coff_tdata.  */
+  if (bfd_get_format (abfd) == bfd_object)
+    return _bfd_coff_free_cached_info (abfd);
+
+  return _bfd_generic_bfd_free_cached_info (abfd);
+}
+
 /* Routines to swap information in the XCOFF .loader section.  If we
    ever need to write an XCOFF loader, this stuff will need to be
    moved to another file shared by the linker (which XCOFF calls the
@@ -4462,7 +4472,6 @@ const struct xcoff_dwsect_name xcoff_dwsect_names[] = {

 /* For generic entry points.  */
 #define _bfd_xcoff_close_and_cleanup coff_close_and_cleanup
-#define _bfd_xcoff_bfd_free_cached_info coff_bfd_free_cached_info
 #define _bfd_xcoff_new_section_hook coff_new_section_hook
 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents

diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index f6a60433e62..50de9a04476 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -2623,7 +2623,7 @@ const bfd_target rs6000_xcoff64_vec =

     /* Generic */
     coff_close_and_cleanup,
-    coff_bfd_free_cached_info,
+    _bfd_xcoff_bfd_free_cached_info,
     coff_new_section_hook,
     _bfd_generic_get_section_contents,

@@ -2893,7 +2893,7 @@ const bfd_target rs6000_xcoff64_aix_vec =

     /* Generic */
     coff_close_and_cleanup,
-    coff_bfd_free_cached_info,
+    _bfd_xcoff_bfd_free_cached_info,
     coff_new_section_hook,
     _bfd_generic_get_section_contents,

diff --git a/bfd/libxcoff.h b/bfd/libxcoff.h
index e6b87975ff6..7a43b349f5a 100644
--- a/bfd/libxcoff.h
+++ b/bfd/libxcoff.h
@@ -315,4 +315,5 @@ extern enum xcoff_stub_type bfd_xcoff_type_of_stub
 extern struct xcoff_stub_hash_entry *bfd_xcoff_get_stub_entry
   (asection *, struct xcoff_link_hash_entry *, struct bfd_link_info *);

+extern bool _bfd_xcoff_bfd_free_cached_info (bfd *) ATTRIBUTE_HIDDEN;
 #endif /* LIBXCOFF_H */

--
Alan Modra
  

Patch

diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 00e0f5442f7..b69b881e684 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -2868,7 +2868,17 @@  _bfd_xcoff_sizeof_headers (bfd *abfd,
 
   return size;
 }
-
+
+bool
+_bfd_xcoff_bfd_free_cached_info (bfd *abfd)
+{
+  /* xcoff bfd_core does not have a coff_tdata.  */
+  if (bfd_get_format (abfd) == bfd_object)
+    return _bfd_coff_free_cached_info (abfd);
+
+  return _bfd_generic_bfd_free_cached_info (abfd);
+}
+
 /* Routines to swap information in the XCOFF .loader section.  If we
    ever need to write an XCOFF loader, this stuff will need to be
    moved to another file shared by the linker (which XCOFF calls the
@@ -4462,7 +4472,6 @@  const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
 
 /* For generic entry points.  */
 #define _bfd_xcoff_close_and_cleanup coff_close_and_cleanup
-#define _bfd_xcoff_bfd_free_cached_info coff_bfd_free_cached_info
 #define _bfd_xcoff_new_section_hook coff_new_section_hook
 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
 
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index f6a60433e62..50de9a04476 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -2623,7 +2623,7 @@  const bfd_target rs6000_xcoff64_vec =
 
     /* Generic */
     coff_close_and_cleanup,
-    coff_bfd_free_cached_info,
+    _bfd_xcoff_bfd_free_cached_info,
     coff_new_section_hook,
     _bfd_generic_get_section_contents,
 
@@ -2893,7 +2893,7 @@  const bfd_target rs6000_xcoff64_aix_vec =
 
     /* Generic */
     coff_close_and_cleanup,
-    coff_bfd_free_cached_info,
+    _bfd_xcoff_bfd_free_cached_info,
     coff_new_section_hook,
     _bfd_generic_get_section_contents,
 
diff --git a/bfd/libxcoff.h b/bfd/libxcoff.h
index e6b87975ff6..7a43b349f5a 100644
--- a/bfd/libxcoff.h
+++ b/bfd/libxcoff.h
@@ -315,4 +315,5 @@  extern enum xcoff_stub_type bfd_xcoff_type_of_stub
 extern struct xcoff_stub_hash_entry *bfd_xcoff_get_stub_entry
   (asection *, struct xcoff_link_hash_entry *, struct bfd_link_info *);
 
+extern bool _bfd_xcoff_bfd_free_cached_info (bfd *) ATTRIBUTE_HIDDEN;
 #endif /* LIBXCOFF_H */