This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC PATCH 3/4] [BFD] Relocate aux entries for NT weak externals


Currently the tagndx for NT weak externals are not relocated when
creating a relocatable object which breaks relocations when doing the
final link of the relocatable object.

For the following example:

    a.c:
        void foo(void);

            int main()
            {
                    foo();
                    return 0;
            }

    b.c:
            #include <stdio.h>

            void __attribute__((weak)) foo(void)
            {
                    printf("%s weak\n", __func__);
            }

$ i686-w64-mingw32-ld -r -o r.o a.o b.o

This is how the symbol table looks for b.o:

$ i686-w64-mingw32-objdump -x b.o | grep -A 2 '[.*].*foo'
[ 13](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 .weak._foo.
[ 14](sec  0)(fl 0x00)(ty  20)(scl 105) (nx 1) 0x00000000 _foo

And this is how the symbol table table looks for r.o:

$ i686-w64-mingw32-objdump -x r.o | grep -A 2 '[.*].*foo'
[ 35](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000018 .weak._foo.
[ 36](sec  0)(fl 0x00)(ty  20)(scl 105) (nx 1) 0x00000000 _foo
AUX lnno 1 size 0x0 tagndx 13

As you can see the AUX entry for _foo is wrong in r.o, it should be 35
but it is 13.

The patch uses the sym_indeces array to relocate the AUX entries for
weak externals in _bfd_coff_link_input_bfd. Note that we only do this
in the case of relocatable output because weak external relocation
handling (_bfd_coff_generic_relocate_section) use the tagndx relative
to the input object.

bfd/

2015-10-22  Octavian Purdila <octavian.purdila@intel.com>

    * cofflink.c (_bfd_coff_link_input_bfd): relocate AUX entries for
      weak externals when generating relocatable objects
---
 bfd/ChangeLog  |  5 +++++
 bfd/cofflink.c | 14 +++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index e7b117c..c91c5cb 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-22  Octavian Purdila <octavian.purdila@intel.com>
+
+	* cofflink.c (_bfd_coff_link_input_bfd): relocate AUX entries for
+	weak externals when generating relocatable objects
+
 2015-10-22 Octavian Purdila <octavian.purdila@intel.com>
 
 	* cofflink.c (coff_link_add_symbols): fixup the symbol class and
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 7f539fa..4c421d4 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -1945,7 +1945,8 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
       if ((*indexp < 0
 	   || (bfd_size_type) *indexp < syment_base)
 	  && (*sym_hash == NULL
-	      || (*sym_hash)->auxbfd != input_bfd))
+	      || (*sym_hash)->auxbfd != input_bfd)
+	  && isymp->n_sclass != C_NT_WEAK)
 	esym += add * isymesz;
       else
 	{
@@ -2015,8 +2016,15 @@ _bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
 		      auxp->x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
 		    }
 		}
-	      else if ((isymp->n_sclass != C_STAT || isymp->n_type != T_NULL)
-		       && isymp->n_sclass != C_NT_WEAK)
+	      else if (isymp->n_sclass == C_NT_WEAK)
+	        {
+		    long *tagndx = &auxp->x_sym.x_tagndx.l;
+
+		    if (bfd_link_relocatable (flaginfo->info) &&
+			flaginfo->sym_indices[*tagndx] > 0)
+		      *tagndx = flaginfo->sym_indices[*tagndx];
+		}
+	      else if (isymp->n_sclass != C_STAT || isymp->n_type != T_NULL)
 		{
 		  unsigned long indx;
 
-- 
2.1.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]