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]

Re: PATCH: undefined symbols in shared libraries


On Fri, Mar 12, 2004 at 02:58:10PM +1030, Alan Modra wrote:
> On Thu, Mar 11, 2004 at 07:24:15PM -0800, H. J. Lu wrote:
> > I think it meant to say executables and shared libraries instead of
> > static binaries and dynamic binaries. You can't have unresolved
> > references in dynamic binaries.
> 
> But you can.  Even at runtime with lazy dynamic linking.
> 
> $ cat /src/tmp/hello.c
> #include <stdio.h>
> 
> extern void undefined_func (void);
> 
> void foo (void)
> {
>   undefined_func ();
> }
> 
> int main (void)
> {
>   printf ("Hello!\n");
>   return 0;
> }
> $ gcc -O2 -Wl,--warn-unresolved-symbols /src/tmp/hello.c
> /tmp/ccM4Etbq.o(.text+0x5): In function `foo':
> : warning: undefined reference to `undefined_func'
> $ ./a.out
> Hello!

I meant to say you couldn't have unresolved references in dynamic
binaries by default. You can build your testcase as a static binary
with the same result:

bash-2.05b$ gcc x.c -Wl,--warn-unresolved-symbols -static
/tmp/ccSmNBRg.o(.text+0x7): In function `foo':
: warning: undefined reference to `undefined_func'
bash-2.05b$ file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux
2.2.5, statically linked, not stripped
bash-2.05b$ ./a.out
Hello!

Basically, we have executables and shared libraries. We treat static
and dynamic binaries as executables. By default, undefined references
are errors when building executables and ignored for shared libraries.

> 
> 
> This area of code has been patched before, and you're saying it is
> now incorrect and needs yet another patch.  Have you looked at the
> history?  I'm unwilling to approve your patch without some very solid
> justification.  Instead, I think the definition and use of
> unresolved_syms_in_shared_libs and unresolved_syms_in_objects needs to
> be looked at carefully rather than just making bandaid patches.
> 

I think they are quite clear, except for the comments in bfdlink.h.
unresolved_syms_in_shared_libs is for unresolved references in input
shared libraries. unresolved_syms_in_objects is for unresolved
references in input relocatable objects. When building shared libraries,
we allow unresolved references in input relocatable objects by default.
They are disallowed for executables. With "-z defs", we also disallow
unresolved references in input relocatable objects when building
shared library.


H.J.


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