[parted-devel] --as-needed linker option causes trouble with -lreadline/-ltermcap

Bruno Haible bruno at clisp.org
Sun Mar 29 07:25:00 UTC 2009


Ralf Wildenhues wrote:
> Anyway, I thought CVS binutils had a patch to deal with this setup,
> but reading the ld/NEWS entry, I'm not so sure anymore whether it
> is sufficient:
> 
>   * --as-needed now links in a dynamic library if it satisfies undefined
>     symbols in regular objects, or in other dynamic libraries.  In the
>     latter case the library is not linked if it is found in a DT_NEEDED
>     entry of one of the libraries already linked.

Yes, that's it. The doc of ld from version 2.16.1 to 2.19 says:

  `--as-needed'
  `--no-as-needed'
       This option affects ELF DT_NEEDED tags for dynamic libraries
       mentioned on the command line after the `--as-needed' option.
       Normally, the linker will add a DT_NEEDED tag for each dynamic
       library mentioned on the command line, regardless of whether the
       library is actually needed.  `--as-needed' causes DT_NEEDED tags
       to only be emitted for libraries that satisfy some symbol
       reference from regular objects which is undefined at the point
                 ^^^^^^^^^^^^^^^^^^^^
       that the library was linked.

It is the restriction to "regular objects" which makes ld answer the
question "Should a dependency to libtermcap be included?" with "no".

In CVS binutils, the last sentence is augmented:

                                    `--as-needed' causes DT_NEEDED tags
       to only be emitted for libraries that satisfy some symbol
       reference from regular objects which is undefined at the point
       that the library was linked, or, if the library is not found in
       the DT_NEEDED lists of other libraries linked up to that point,
       a reference from another dynamic library.

So, ld was enhanced to handle precisely the case with libncurses.

Bruno



More information about the parted-devel mailing list