This is the mail archive of the
mailing list for the GCC project.
Re: --as-needed and --no-add-needed linker options
- From: Ian Lance Taylor <iant at google dot com>
- To: ali hagigat <hagigatali at gmail dot com>
- Cc: binutils at sourceware dot org, gcc-help at gcc dot gnu dot org
- Date: Wed, 29 Dec 2010 10:40:34 -0800
- Subject: Re: --as-needed and --no-add-needed linker options
- References: <AANLkTikefsuTyu_gfYTi-Vcvdm-TghuoupMBsSqraLxx@mail.gmail.com>
ali hagigat <firstname.lastname@example.org> writes:
> I do not understand the necessity of introducing the options of
> --as-needed and --no-add-needed!
> Why adding or not adding DT_NEEDED tag is so important that two
> separate options are considered for ld?
When the DT_NEEDED tag is used, it means that the dynamic linker must
find the shared library at runtime. If no symbols are required from the
shared library, then the effort expended to find it is wasted. The
--no-add-needed option directs the linker to only add a DT_NEEDED tag if
some symbol from the shared library is used by the program.
This is normally used with -lgcc, the supporting library used by gcc.
On many targets, for many programs, no symbols are required from -lgcc.
On some targets, for some programs, symbols are required. Therefore,
gcc uses --no-as-needed -lgcc --as-needed. This tells the linker to
only add a DT_NEEDED tag for -lgcc if some symbol is actually required.
The --no-as-needed option is not actually necessary, and the program
will normally work just fine if you don't use it. It's purely an
> I wonder if anybody can explain this tag and the situation when a
> dynamic library references a symbol in another dynamic library.
> If i create a dynamic library with some external references and then
> link it with my program, what happens after executing my program?
I assume that the above information suffices to answer these questions.