This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: about --no-undefined option
- From: Nick Clifton <nickc at redhat dot com>
- To: Lin George <george4academic at yahoo dot com>
- Cc: binutils at sourceware dot org
- Date: Thu, 11 Jan 2007 15:38:26 +0000
- Subject: Re: about --no-undefined option
- References: <20061215033321.24980.qmail@web32106.mail.mud.yahoo.com>
Hi Lin,
I think there is a high risk if --no-undefined option is not set for linker
when building a shared library.
You probably mean the --no-allow-shlib-undefined option which is
specific to shared libraries.
Since if this option is not set, linker will
not *truly* resolve the dependent imported external symbols (to check whether
they are *truly* exported by other modules in LIBRARY_PATH). It will raise
high risk when run an application with the shared library built in this manner,
since in the runtime, the dependent external symbols may fail to load. Is my
understanding correct?
Yes, although "high risk" might be putting it too forcefully. There is
a risk yes, but there is also an implicit cooperation between the linker
and the run-time loader. It is normally assumed that when an
application is linked against a shared library the user will be running
that application in an environment where the external requirements of
the library can be satisfied.
I am wondering why in most cases, this option is not set for shared library
build for most people? Seems no setting this option has some advantages?
Yes. There are several problems with using --no-allow-shlib-undefined.
Firstly the run-time libraries might not be available at link time.
This is particularly true when cross-compiling. If the option were
enabled when cross-compiling a shared library it would be necessary to
have the entire set of run-time libraries available on the build
machine. (Plus there is the problem that the paths to these run-time
libraries might not match the paths as they exist on the target machine).
The second problem is that some symbols do not exist in the run-time
libraries at all. Instead they are provided by the run-time
environment, which is not necessarily available to the linker. (These
are usually operating system related symbols).
So the current default is to allow unresolved symbols in linked in
shared libraries. This is not dangerous as any truly unresolved symbols
will always be discovered when the executable is run.
Cheers
Nick