[PATCH 2/2]: bfd: make aoutx.h self-contained

Gunther Nikl gnikl@justmail.de
Tue May 26 16:16:24 GMT 2020


The generic a.out backend support in aoutx.h requires definitions for QMAGIC
and BMAGIC. Both defines are provided by "aout/aout64.h" for a 32bit target.
Other users of aoutx.h have to provide a definition for both defines themself.
This patch makes aoutx.h self-contained with the macro N_IS_QMAGIC from
"aout/aout64.h" and by defining a similiar macro for BMAGIC. The remaining
reference to QMAGIC is replaced with a third macro: N_SET_QMAGIC. All macros
are conditionally defined depending on whether QMAGIC and BMAGIC are defined.
With this change of aoutx.h the dummy defines in aout64.c can be removed.


-- cut --
2020-05-XX  Gunther Nikl  <gnikl@justmail.de>

	* aout64.c (BMAGIC, QMAGIC): Do not define.
	* aoutx.h (N_IS_BMAGIC, N_SET_QMAGIC): New defines.
	(NAME (aout, some_aout_object_p)): Use N_IS_QMAGIC and N_IS_BMAGIC
	to check the file format.
	(adjust_z_magic): Use N_SET_QMAGIC to set file format.

diff --git a/bfd/aout64.c b/bfd/aout64.c
index 5b43a14270..73e3cc7afe 100644
--- a/bfd/aout64.c
+++ b/bfd/aout64.c
@@ -21,12 +21,4 @@
 
 #define ARCH_SIZE 64
 
-/* aoutx.h requires definitions for BMAGIC and QMAGIC.  */
-#ifndef BMAGIC
-#define BMAGIC 0
-#endif
-#ifndef QMAGIC
-#define QMAGIC 0
-#endif
-
 #include "aoutx.h"
diff --git a/bfd/aoutx.h b/bfd/aoutx.h
index 9ffb3fe861..6ee93e104f 100644
--- a/bfd/aoutx.h
+++ b/bfd/aoutx.h
@@ -128,6 +128,18 @@ DESCRIPTION
 #include "aout/stab_gnu.h"
 #include "aout/ar.h"
 
+#ifdef BMAGIC
+#define N_IS_BMAGIC(x) (N_MAGIC (x) == BMAGIC)
+#else
+#define N_IS_BMAGIC(x) (0)
+#endif
+
+#ifdef QMAGIC
+#define N_SET_QMAGIC(x) N_SET_MAGIC (x, QMAGIC)
+#else
+#define N_SET_QMAGIC(x) do { /**/ } while (0)
+#endif
+
 /*
 SUBSECTION
 	Relocations
@@ -492,7 +504,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
       abfd->flags |= D_PAGED | WP_TEXT;
       adata (abfd).magic = z_magic;
     }
-  else if (N_MAGIC (execp) == QMAGIC)
+  else if (N_IS_QMAGIC (execp))
     {
       abfd->flags |= D_PAGED | WP_TEXT;
       adata (abfd).magic = z_magic;
@@ -503,8 +515,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
       abfd->flags |= WP_TEXT;
       adata (abfd).magic = n_magic;
     }
-  else if (N_MAGIC (execp) == OMAGIC
-	   || N_MAGIC (execp) == BMAGIC)
+  else if (N_MAGIC (execp) == OMAGIC || N_IS_BMAGIC (execp))
     adata (abfd).magic = o_magic;
   else
     /* Should have been checked with N_BADMAG before this routine
@@ -1026,7 +1037,7 @@ adjust_z_magic (bfd *abfd, struct internal_exec *execp)
   if (ztih && (!abdp || (abdp && !abdp->exec_header_not_counted)))
     execp->a_text += adata (abfd).exec_bytes_size;
   if (obj_aout_subformat (abfd) == q_magic_format)
-    N_SET_MAGIC (execp, QMAGIC);
+    N_SET_QMAGIC (execp);
   else
     N_SET_MAGIC (execp, ZMAGIC);

-- cut --


More information about the Binutils mailing list