tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

"Fixing" new ld(1) DT_NEEDED handling



Hey folks,

as discussed on netbsd-users@ I would like to commit the bellow patch.

Assuming test.c is:
--8<--
#include <stdio.h>
#include <term.h>

int main(int argc, char **argv)
{
        int err = 0;
        setupterm(NULL, fileno(stdout), &err);
        printf("my term: %s\n", termname());
        return 0;
}
-->8--

this changes the behaviour from:

cc -Wall -O2 test.c -lcurses
ld: /var/tmp//cciFJZbd.o: undefined reference to symbol 'termname'
ld: note: 'termname' is defined in DSO /usr/lib/libterminfo.so.1 so try adding 
it to the linker command line

where either

        cc -Wall -Wl,--copy-dt-needed -O2 test.c -lcurses

or

        cc -Wall -O2 test.c -lterminfo

worked, to just makeing the --copy-dt-needed default again. Basically it
backs out this change:

2011-08-22  Michael Matz  <matz%suse.de@localhost>

        * ldmain.c (add_DT_NEEDED_for_dynamic): Default to FALSE.
        * ld.texinfo (--copy-dt-needed-entries): Mention new default.

but without fixing the documentation (suggestions for wording there 
appreciated).

While this error catches "real" buglets like in the above example it forces
makefiles to be aware of library internal organizations (like which sub-library
exports what symbol), and also shows some arrogance of the linker: "I know
you told me to -lxyz, but I know better than you!"

Fallout in pkgsrc is noticable, and if you want the stricter behaviour, you
can always pass -Wl,--no-copy-dt-needed.

Comments?

Martin
Index: emultempl/elf32.em
===================================================================
RCS file: /cvsroot/src/external/gpl3/binutils/dist/ld/emultempl/elf32.em,v
retrieving revision 1.7
diff -u -r1.7 elf32.em
--- emultempl/elf32.em  29 Sep 2013 14:03:31 -0000      1.7
+++ emultempl/elf32.em  11 Oct 2013 08:09:55 -0000
@@ -103,6 +103,7 @@
 {
   ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 
's/:.*//'`);
   input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
+  input_flags.add_DT_NEEDED_for_dynamic = TRUE;
   config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; 
else echo FALSE ; fi`;
   config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE 
; else echo FALSE ; fi`;
 }


Home | Main Index | Thread Index | Old Index