bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/21382] --as-needed cannot be combined with -flto


From: hjl.tools at gmail dot com
Subject: [Bug ld/21382] --as-needed cannot be combined with -flto
Date: Thu, 13 Apr 2017 19:30:37 +0000

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:

address@hidden pr15146a]$ cat foo.c 
extern int xxx;

int
bar (void)
{
  return xxx;
}

int
main ()
{ 
  return 0;
}
address@hidden pr15146a]$ cat yyy.c 
extern void bar (void);

void
zzz ()
{
  bar ();
}
address@hidden pr15146a]$ cat xxx.c 
int xxx  = 3;
address@hidden 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,.
address@hidden pr15146a]$ 

after:

address@hidden 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
address@hidden pr15146a]$ 

Gold also failed:

address@hidden 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
address@hidden pr15146a]$

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]