public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Move mips_refhi_list to bfd tdata
@ 2023-01-09 23:19 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-01-09 23:19 UTC (permalink / raw)
  To: binutils

Similar to commit c799eddb3512, but for mips-ecoff.  mips-ecoff is
marked obsolete, but we still allow reading of these object files in
a number of mips targets.

	* coff-mips.c (struct mips_hi, mips_refhi_list): Delete.
	(mips_refhi_reloc, mips_reflo_reloc): Access mips_refhi_list
	in ecoff_data.
	* ecoff.c (_bfd_ecoff_close_and_cleanup): New function.
	* libecoff.h (struct mips_hi): Moved from coff-mips.c.
	(struct ecoff_tdata): Add mips_refhi_list.
	(_bfd_ecoff_close_and_cleanup): Declare.

diff --git a/bfd/coff-mips.c b/bfd/coff-mips.c
index 79cbc20a03d..fdc0771979d 100644
--- a/bfd/coff-mips.c
+++ b/bfd/coff-mips.c
@@ -423,19 +423,8 @@ mips_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED,
    reloc.  This extension permits gcc to output the HI and LO relocs
    itself.  */
 
-struct mips_hi
-{
-  struct mips_hi *next;
-  bfd_byte *addr;
-  bfd_vma addend;
-};
-
-/* FIXME: This should not be a static variable.  */
-
-static struct mips_hi *mips_refhi_list;
-
 static bfd_reloc_status_type
-mips_refhi_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+mips_refhi_reloc (bfd *abfd,
 		  arelent *reloc_entry,
 		  asymbol *symbol,
 		  void * data,
@@ -480,8 +469,8 @@ mips_refhi_reloc (bfd *abfd ATTRIBUTE_UNUSED,
     return bfd_reloc_outofrange;
   n->addr = (bfd_byte *) data + reloc_entry->address;
   n->addend = relocation;
-  n->next = mips_refhi_list;
-  mips_refhi_list = n;
+  n->next = ecoff_data (abfd)->mips_refhi_list;
+  ecoff_data (abfd)->mips_refhi_list = n;
 
   if (output_bfd != (bfd *) NULL)
     reloc_entry->address += input_section->output_offset;
@@ -502,11 +491,11 @@ mips_reflo_reloc (bfd *abfd,
 		  bfd *output_bfd,
 		  char **error_message)
 {
-  if (mips_refhi_list != NULL)
+  if (ecoff_data (abfd)->mips_refhi_list != NULL)
     {
       struct mips_hi *l;
 
-      l = mips_refhi_list;
+      l = ecoff_data (abfd)->mips_refhi_list;
       while (l != NULL)
 	{
 	  unsigned long insn;
@@ -549,7 +538,7 @@ mips_reflo_reloc (bfd *abfd,
 	  l = next;
 	}
 
-      mips_refhi_list = NULL;
+      ecoff_data (abfd)->mips_refhi_list = NULL;
     }
 
   /* Now do the REFLO reloc in the usual way.  */
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 228394a5046..717d2fa2c75 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -109,6 +109,21 @@ _bfd_ecoff_mkobject_hook (bfd *abfd, void * filehdr, void * aouthdr)
   return (void *) ecoff;
 }
 
+bool
+_bfd_ecoff_close_and_cleanup (bfd *abfd)
+{
+  struct ecoff_tdata *tdata = ecoff_data (abfd);
+
+  if (tdata != NULL && bfd_get_format (abfd) == bfd_object)
+    while (tdata->mips_refhi_list != NULL)
+      {
+	struct mips_hi *ref = tdata->mips_refhi_list;
+	tdata->mips_refhi_list = ref->next;
+	free (ref);
+      }
+  return _bfd_generic_close_and_cleanup (abfd);
+}
+
 /* Initialize a new section.  */
 
 bool
diff --git a/bfd/libecoff.h b/bfd/libecoff.h
index 9db5012292b..12664b890c4 100644
--- a/bfd/libecoff.h
+++ b/bfd/libecoff.h
@@ -80,6 +80,13 @@ struct ecoff_backend_data
   members of the embedded bfd_coff_backend_data struct.  */
 #define ECOFF_NO_LONG_SECTION_NAMES (false), _bfd_ecoff_no_long_sections
 
+struct mips_hi
+{
+  struct mips_hi *next;
+  bfd_byte *addr;
+  bfd_vma addend;
+};
+
 /* This is the target specific information kept for ECOFF files.  */
 
 #define ecoff_data(abfd) ((abfd)->tdata.ecoff_obj_data)
@@ -148,6 +155,8 @@ typedef struct ecoff_tdata
      ecoff_compute_section_file_positions is called.  */
   bool rdata_in_text;
 
+  /* Used by coff-mips.c to track REFHI relocs for pairing with REFLO.  */
+  struct mips_hi *mips_refhi_list;
 } ecoff_data_type;
 
 /* Each canonical asymbol really looks like this.  */
@@ -234,7 +243,7 @@ extern bool _bfd_ecoff_slurp_symbolic_info
 
 extern bool _bfd_ecoff_write_object_contents (bfd *);
 
-#define	_bfd_ecoff_close_and_cleanup _bfd_generic_close_and_cleanup
+extern bool _bfd_ecoff_close_and_cleanup (bfd *);
 #define _bfd_ecoff_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
 extern bool _bfd_ecoff_new_section_hook
   (bfd *, asection *);

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-09 23:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09 23:19 Move mips_refhi_list to bfd tdata Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).