Bug 12319 - Undefined reference error with LTO and `--whole-archive'
Summary: Undefined reference error with LTO and `--whole-archive'
Status: RESOLVED WORKSFORME
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-14 17:48 UTC by Dmitry Gorbachev
Modified: 2012-12-07 20:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
testcase (166 bytes, text/plain)
2010-12-14 17:48 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2010-12-14 17:48:07 UTC
Created attachment 5158 [details]
testcase

GCC 4.6.0, LD hjl/lto-mixed.

$ gcc -flto -c bar.c
$ ar cr libbar.a bar.o
$ gcc -flto -fuse-linker-plugin main.c -Wl,--whole-archive libbar.a -Wl,--no-whole-archive foo.c
/tmp/ccacBTCT.ltrans0.ltrans.o: In function `foo.1988':
ccacBTCT.ltrans0.o:(.text+0x14): undefined reference to `bar'
collect2: ld returned 1 exit status
$ gcc -flto -fuse-linker-plugin main.c -Wl,--whole-archive libbar.a -Wl,--no-whole-archive foo.c -DICE
lto1: internal compiler error: in lto_varpool_replace_node, at lto-symtab.c:306
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: i686-pc-linux-gnu-gcc-4.6.0 returned 1 exit status
/usr/local/bin/ld: lto-wrapper failed
collect2: ld returned 1 exit status
Comment 1 H.J. Lu 2010-12-14 18:13:24 UTC
(In reply to comment #0)
> Created attachment 5158 [details]
> testcase
> 
> GCC 4.6.0, LD hjl/lto-mixed.
> 
> $ gcc -flto -c bar.c
> $ ar cr libbar.a bar.o
> $ gcc -flto -fuse-linker-plugin main.c -Wl,--whole-archive libbar.a
> -Wl,--no-whole-archive foo.c
> /tmp/ccacBTCT.ltrans0.ltrans.o: In function `foo.1988':
> ccacBTCT.ltrans0.o:(.text+0x14): undefined reference to `bar'
> collect2: ld returned 1 exit status

On hjl/lto-mixed branch commit 20ad3f1fe442c6378d2ad168b60dd4fbaf95d169
with gcc 4.6 revision 167368, I got

[hjl@gnu-6 pr12319]$ make
/usr/gcc-4.6/bin/gcc -B./ -flto   -c -o bar.o bar.c
ar cr libbar.a bar.o
/usr/gcc-4.6/bin/gcc -B./ -flto -fuse-linker-plugin -o prog  main.c \
	-Wl,--whole-archive libbar.a -Wl,--no-whole-archive foo.c
./prog
[hjl@gnu-6 pr12319]$ 

> $ gcc -flto -fuse-linker-plugin main.c -Wl,--whole-archive libbar.a
> -Wl,--no-whole-archive foo.c -DICE
> lto1: internal compiler error: in lto_varpool_replace_node, at lto-symtab.c:306
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <http://gcc.gnu.org/bugs.html> for instructions.
> lto-wrapper: i686-pc-linux-gnu-gcc-4.6.0 returned 1 exit status

This is a GCC bug.

> /usr/local/bin/ld: lto-wrapper failed
> collect2: ld returned 1 exit status
Comment 2 H.J. Lu 2012-12-07 20:08:32 UTC
Works in 2.23 and tracked by "LTO 14" test.