[PATCH] BFD/XCOFF: Fix storage class setting for weak defined symbols

Maciej W. Rozycki macro@mips.com
Mon Jul 16 05:41:00 GMT 2018


Fix an issue with commit 8602d4fea60d ("Add AIX weak support"), 
<https://sourceware.org/ml/binutils/2009-03/msg00189.html>, and use the 
correct condition to set the storage class for weak defined symbols.

The context here is as follows:

  else if ((h->root.type == bfd_link_hash_defined
            || h->root.type == bfd_link_hash_defweak)
           && h->smclas == XMC_XO)
    {
      BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
      isym.n_value = h->root.u.def.value;
      isym.n_scnum = N_UNDEF;
      if (h->root.type == bfd_link_hash_undefweak
          && C_WEAKEXT == C_AIX_WEAKEXT)
        isym.n_sclass = C_WEAKEXT;
      else
        isym.n_sclass = C_EXT;
      aux.x_csect.x_smtyp = XTY_ER;
    }

so clearly the inner condition can never be true.  Correct the condition 
then to check for the `bfd_link_hash_defweak' symbol type instead.

	bfd/
	* xcofflink.c (xcoff_write_global_symbol): Fix a symbol type 
	check for defined weak symbols.
---
Hi Richard,

 Spotted in the course of PR ld/21375 work.  Regression-tested with the
`powerpc-ibm-aix5.2.0' target.  I think a test case would be due, but I 
can't afford writing one at this time, sorry.  OK to apply?

 BTW your XCOFF maintainer's address looks out of date to me.

  Maciej
---
 bfd/xcofflink.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: binutils/bfd/xcofflink.c
===================================================================
--- binutils.orig/bfd/xcofflink.c	2018-07-13 21:45:54.000000000 +0100
+++ binutils/bfd/xcofflink.c	2018-07-13 21:49:54.561733638 +0100
@@ -5592,7 +5592,7 @@ xcoff_write_global_symbol (struct bfd_ha
       BFD_ASSERT (bfd_is_abs_section (h->root.u.def.section));
       isym.n_value = h->root.u.def.value;
       isym.n_scnum = N_UNDEF;
-      if (h->root.type == bfd_link_hash_undefweak
+      if (h->root.type == bfd_link_hash_defweak
 	  && C_WEAKEXT == C_AIX_WEAKEXT)
 	isym.n_sclass = C_WEAKEXT;
       else



More information about the Binutils mailing list