This is the mail archive of the binutils@sources.redhat.com 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]

[PATCH] Fix --as-needed for MIPS.


As noted in these threads:

http://sourceware.org/ml/binutils/2005-07/msg00476.html
http://sourceware.org/ml/binutils/2005-07/msg00490.html

ld --as-needed seems to be broken for my mipsel-linux cross tool chain.

Quoting from the e-mail threads:

<quote>

It seems that the linker thinks that any shared object that references the magic _gp_disp symbol actually provides it. Since all mips objects reference _gp_disp, ld thinks that all shared objects are required to resolve all the other _gp_disp references. This causes all shared objects specified with --as-needed to be deemed needed and get a DT_NEEDED entry.

The linker automagically resolves _gp_disp so this symbol should not cause a shared library to be needed.

I hope that makes at least a little sense.

I suspect that the problem is mips specific as _gp_disp handling is mips specific.

And:

Here is my current plan:

$ mipsel-linux-readelf -s -D -W /usr/local/mipsel-linux-3.4.3/lib/libc-2.3.3.so | grep SECTION
131 324: 0019bfb0 0 SECTION GLOBAL DEFAULT ABS _gp_disp



This seems to be where ld thinks that _gp_disp is defined by shared objects.


I can detect this special case in _bfd_mips_elf_add_symbol_hook() and cause it to be ignored, thus solving the problem.

Does this seem like a reasonable course of action?

I am not sure how that dynamic symbol got into the shared objects in the first place. I suppose if the proper solution was to not put it there in the first place, I could fix that and rebuild the world. But that would be much more work.

</quote>

The attached patch seems to correct the problem.

Tested with a cross build running on i686-pc-linux configured as:

../src/configure --target=mipsel-linux --prefix=/usr/local/mipsel-linux-3.4.3 --with-sysroot=/usr/local/mipsel-linux-3.4.3

make -k check with no regressions.

2005-07-29 David Daney <ddaney@avtrex.com>

	* elfxx-mips.c (_bfd_mips_elf_add_symbol_hook):  Ignore _gp_disp
	if it is not in the *UND* section.

O.K. to commit?

David Daney
Index: elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.146
diff -c -p -r1.146 elfxx-mips.c
*** elfxx-mips.c	8 Jul 2005 06:20:05 -0000	1.146
--- elfxx-mips.c	29 Jul 2005 04:03:03 -0000
*************** _bfd_mips_elf_add_symbol_hook (bfd *abfd
*** 5414,5419 ****
--- 5414,5430 ----
        return TRUE;
      }
  
+   /* Shared objects may have a dynamic symbol '_gp_disp' defined as
+      a SECTION *ABS*.  This causes ld to think it can resolve _gp_disp
+      by setting a DT_NEEDED for the shared object.  Since _gp_disp is
+      a magic symbol resolved by the linker, we ignore this bogus definition
+      of _gp_disp. */
+   if ((strcmp (*namep, "_gp_disp") == 0) && !bfd_is_und_section (*secp))
+     {
+       *namep = NULL;
+       return TRUE;
+     }
+ 
    switch (sym->st_shndx)
      {
      case SHN_COMMON:

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