https://sourceware.org/bugzilla/show_bug.cgi?id=21382

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
Created attachment 9992
  --> https://sourceware.org/bugzilla/attachment.cgi?id=9992&action=edit
A patch

This will introduce false reference from a shared library which isn't used
otherwise.

Before the change:

[hjl@gnu-6 pr15146a]$ cat foo.c 
extern int xxx;

int
bar (void)
{
  return xxx;
}

int
main ()
{ 
  return 0;
}
[hjl@gnu-6 pr15146a]$ cat yyy.c 
extern void bar (void);

void
zzz ()
{
  bar ();
}
[hjl@gnu-6 pr15146a]$ cat xxx.c 
int xxx  = 3;
[hjl@gnu-6 pr15146a]$ make
gcc -flto -O2   -c -o foo.o foo.c
gcc -shared -fPIC -o libxxx.so xxx.c
gcc -shared -fPIC -o libyyy.so yyy.c libxxx.so
gcc -flto -O2 -Wl,--as-needed  -o x foo.o libyyy.so -Wl,-rpath-link,.
[hjl@gnu-6 pr15146a]$ 

after:

[hjl@gnu-6 pr15146a]$ gcc -flto -O2 -Wl,--as-needed  -o x foo.o libyyy.so
-Wl,-rpath-link,. -B./
/tmp/ccQlE2wY.ltrans0.ltrans.o: In function `bar':
<artificial>:(.text+0x2): undefined reference to `xxx'
collect2: error: ld returned 1 exit status
[hjl@gnu-6 pr15146a]$ 

Gold also failed:

[hjl@gnu-6 pr15146a]$ gcc -flto -O2 -Wl,--as-needed  -o x foo.o libyyy.so
-Wl,-rpath-link,. -fuse-ld=gold
/tmp/ccLftUeD.ltrans0.ltrans.o:<artificial>:function bar: error: undefined
reference to 'xxx'
collect2: error: ld returned 1 exit status
[hjl@gnu-6 pr15146a]$

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to