XCOFF constify

Alan Modra amodra@gmail.com
Wed Dec 16 04:46:01 GMT 2020


There are occasions where it is reasonable to use a macro defining
function parameters, but this isn't one of them.  Use typedefs
instead, which also simplifies declaring a const array of function
pointers.

	* libxcoff.h (struct xcoff_backend_data_rec): Constify
	_xcoff_glink_code.
	(XCOFF_RELOC_FUNCTION_ARGS, XCOFF_COMPLAIN_FUNCTION_ARGS): Delete.
	(xcoff_reloc_function, xcoff_complain_function): New typedef.
	(xcoff_calculate_relocation, xcoff_complain_overflow),
	(xcoff_reloc_type_noop, xcoff_reloc_type_fail),
	(xcoff_reloc_type_pos, xcoff_reloc_type_neg),
	(xcoff_reloc_type_rel, xcoff_reloc_type_toc),
	(xcoff_reloc_type_ba, xcoff_reloc_type_crel): Update declaration.
	* coff-rs6000.c (xcoff_reloc_type_br): Declare using typedef.
	(xcoff_complain_overflow_dont_func): Likewise.
	(xcoff_complain_overflow_bitfield_func): Likewise.
	(xcoff_complain_overflow_signed_func): Likewise.
	(xcoff_complain_overflow_unsigned_func): Likewise.
	(xcoff_calculate_relocation, xcoff_complain_overflow): Constify.
	(xcoff_glink_code): Constify.
	* coff64-rs6000.c (xcoff64_reloc_type_br): Declare using typedef.
	(xcoff64_calculate_relocation, xcoff64_glink_code): Constify.

diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 5e5b182da9..2854f928db 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -148,19 +148,15 @@ static bfd_boolean do_pad (bfd *, unsigned int);
 static bfd_boolean do_copy (bfd *, bfd *);
 
 /* Relocation functions */
-static bfd_boolean xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS);
-
-static bfd_boolean xcoff_complain_overflow_dont_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-static bfd_boolean xcoff_complain_overflow_bitfield_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-static bfd_boolean xcoff_complain_overflow_signed_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-static bfd_boolean xcoff_complain_overflow_unsigned_func
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
-
-bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
-  (XCOFF_RELOC_FUNCTION_ARGS) =
+static xcoff_reloc_function xcoff_reloc_type_br;
+
+static xcoff_complain_function xcoff_complain_overflow_dont_func;
+static xcoff_complain_function xcoff_complain_overflow_bitfield_func;
+static xcoff_complain_function xcoff_complain_overflow_signed_func;
+static xcoff_complain_function xcoff_complain_overflow_unsigned_func;
+
+xcoff_reloc_function *const
+xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION] =
 {
   xcoff_reloc_type_pos,	 /* R_POS   (0x00) */
   xcoff_reloc_type_neg,	 /* R_NEG   (0x01) */
@@ -192,8 +188,8 @@ bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
   xcoff_reloc_type_ba,	 /* R_RBRC  (0x1b) */
 };
 
-bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
-  (XCOFF_COMPLAIN_FUNCTION_ARGS) =
+xcoff_complain_function *const
+xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW] =
 {
   xcoff_complain_overflow_dont_func,
   xcoff_complain_overflow_bitfield_func,
@@ -3981,7 +3977,7 @@ HOWTO (0,			/* type */
    The first word of global linkage code must be modified by filling in
    the correct TOC offset.  */
 
-static unsigned long xcoff_glink_code[9] =
+static const unsigned long xcoff_glink_code[9] =
   {
     0x81820000,	/* lwz r12,0(r2) */
     0x90410014,	/* stw r2,20(r1) */
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index 7185232ce1..6b7cd34b33 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -177,11 +177,10 @@ static bfd_boolean xcoff64_bad_format_hook
   (bfd *, void *);
 
 /* Relocation functions */
-static bfd_boolean xcoff64_reloc_type_br
-  (XCOFF_RELOC_FUNCTION_ARGS);
+static xcoff_reloc_function xcoff64_reloc_type_br;
 
-bfd_boolean (*xcoff64_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
-  (XCOFF_RELOC_FUNCTION_ARGS) =
+xcoff_reloc_function *const
+xcoff64_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION] =
 {
   xcoff_reloc_type_pos,	 /* R_POS   (0x00) */
   xcoff_reloc_type_neg,	 /* R_NEG   (0x01) */
@@ -2539,7 +2538,7 @@ HOWTO (0,			/* type */
        MINUS_ONE,		/* dst_mask */
        FALSE);			/* pcrel_offset */
 
-static unsigned long xcoff64_glink_code[10] =
+static const unsigned long xcoff64_glink_code[10] =
 {
   0xe9820000,	/* ld r12,0(r2) */
   0xf8410028,	/* std r2,40(r1) */
diff --git a/bfd/libxcoff.h b/bfd/libxcoff.h
index cba9afd3e5..c4b69ac1b7 100644
--- a/bfd/libxcoff.h
+++ b/bfd/libxcoff.h
@@ -90,7 +90,7 @@ struct xcoff_backend_data_rec
 
   /* Global linkage.  The first word of global linkage code must be be
      modified by filling in the correct TOC offset.  */
-  unsigned long *_xcoff_glink_code;
+  const unsigned long *_xcoff_glink_code;
 
   /* Size of the global link code in bytes of the xcoff_glink_code table.  */
   unsigned long _xcoff_glink_size;
@@ -210,30 +210,30 @@ struct xcoff_backend_data_rec
 #endif
 #define N_ONES(n) (((((bfd_vma) 1 << ((n) - 1)) - 1) << 1) | 1)
 
-#define XCOFF_RELOC_FUNCTION_ARGS \
-  bfd *, asection *, bfd *, struct internal_reloc *, \
-  struct internal_syment *, struct reloc_howto_struct *, bfd_vma, bfd_vma, \
-  bfd_vma *relocation, bfd_byte *contents
+typedef bfd_boolean xcoff_reloc_function (bfd *, asection *, bfd *,
+					  struct internal_reloc *,
+					  struct internal_syment *,
+					  struct reloc_howto_struct *,
+					  bfd_vma, bfd_vma,
+					  bfd_vma *, bfd_byte *);
 
-#define XCOFF_COMPLAIN_FUNCTION_ARGS \
-  bfd *, bfd_vma, bfd_vma, struct reloc_howto_struct *howto
+typedef bfd_boolean xcoff_complain_function (bfd *, bfd_vma, bfd_vma,
+					     struct reloc_howto_struct *);
 
-extern bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
-  (XCOFF_RELOC_FUNCTION_ARGS);
-extern bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
-  (XCOFF_COMPLAIN_FUNCTION_ARGS);
+extern xcoff_reloc_function *const xcoff_calculate_relocation[];
+extern xcoff_complain_function *const xcoff_complain_overflow[];
 
 #define XCOFF_NO_LONG_SECTION_NAMES  (FALSE), bfd_coff_set_long_section_names_disallowed
 
 /* Relocation functions */
-bfd_boolean xcoff_reloc_type_noop (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_fail (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_pos  (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_neg  (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_rel  (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_toc  (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_ba   (XCOFF_RELOC_FUNCTION_ARGS);
-bfd_boolean xcoff_reloc_type_crel (XCOFF_RELOC_FUNCTION_ARGS);
+extern xcoff_reloc_function xcoff_reloc_type_noop;
+extern xcoff_reloc_function xcoff_reloc_type_fail;
+extern xcoff_reloc_function xcoff_reloc_type_pos;
+extern xcoff_reloc_function xcoff_reloc_type_neg;
+extern xcoff_reloc_function xcoff_reloc_type_rel;
+extern xcoff_reloc_function xcoff_reloc_type_toc;
+extern xcoff_reloc_function xcoff_reloc_type_ba;
+extern xcoff_reloc_function xcoff_reloc_type_crel;
 
 /* Structure to describe dwarf sections.
    Useful to convert from XCOFF section name to flag and vice-versa.

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list