This is the mail archive of the binutils@sourceware.org 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: Linker does not detect unresolved symbol


It seems like a linker bug. I opened a bug report at

http://sourceware.org/bugzilla/show_bug.cgi?id=11218

H.J.
--
On Mon, Jan 25, 2010 at 3:10 AM, Stern, Eli <eli.stern@ti.com> wrote:
> In the constellation described below, the linker does not detect an unresolved symbol. This is only detected at run-time.
> Seems to me the problem arises from the use of "-ffunction-sections" and "--gc-sections".
>
> The problem was detected with the following tool releases:
> - gcc 4.2.0, binutils 2.19
> - gcc 3.4.6, binutils 2.15.92.0.2
>
>
> Is this a bug or a misuse of the tools?
>
> Suppose the following files:
>
> a.c: This file is compiled using "-ffunction-sections", then "ar" is used to create a statis library.
> extern void unresolved_detected_at_runtime_not_at_linktime(void);
> void bar_in_a(void)
> {
> ? ?;
> }
>
> void call_unresolved(void)
> {
> ? ?unresolved_detected_at_runtime_not_at_linktime();
> }
>
> so.c: This file is compiled to create a shared library.
> extern void unresolved_detected_at_runtime_not_at_linktime(void);
> void foo_in_so(void)
> {
> ? ?unresolved_detected_at_runtime_not_at_linktime();
> }
>
>
> main.c:
> extern void bar_in_a();
> extern void foo_in_so(void);
> int main(int argc, char *argv[])
> {
> ? ?foo_in_so();
> ? ?bar_in_a();
>
> ? ?return 0;
> }
>
> Note that the symbol "unresolved_detected_at_runtime_not_at_linktime" is not defined at all.
>
> Use the following script to build:
> #!/bin/bash -x
> gcc -ffunction-sections -c a.c -o a.o
> ar rc a.a a.o
> gcc -fPIC -c so.c -o so.o
> gcc -shared -o so.so so.o
> gcc -c main.c -o main.o
> gcc -o main main.o -Wl,--gc-sections a.a ./so.so
>
> All goes well (actually, not so well, since the linker failed to detect an unresolved symbol), till we try to run the executable:
>
> $ ./main
> ./main: symbol lookup error: ./so.so: undefined symbol: unresolved_detected_at_runtime_not_at_linktime
> $
>
>
> Thanx
>
> Eli Stern
>
>
>



-- 
H.J.


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