Bug 12388 - icf_test.sh and icf_safe_test.sh fail
Summary: icf_test.sh and icf_safe_test.sh fail
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gold (show other bugs)
Version: 2.21
: P2 normal
Target Milestone: ---
Assignee: Ian Lance Taylor
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-11 15:33 UTC by Richard Biener
Modified: 2011-07-11 11:27 UTC (History)
2 users (show)

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


Attachments
testcase (1.51 KB, application/x-object)
2011-01-11 15:33 UTC, Richard Biener
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2011-01-11 15:33:33 UTC
Created attachment 5190 [details]
testcase

on x86_64-suse-linux I see

FAIL: icf_test.sh
PASS: icf_keep_unique_test.sh
FAIL: icf_safe_test.sh
PASS: icf_safe_so_test.sh

even though the respective functions in icf_test.o seem to be the same
(attached).
Comment 1 Sriraman Tallam 2011-01-12 02:04:36 UTC
(In reply to comment #0)
> Created attachment 5190 [details]
> testcase
> 
> on x86_64-suse-linux I see
> 
> FAIL: icf_test.sh
> PASS: icf_keep_unique_test.sh
> FAIL: icf_safe_test.sh
> PASS: icf_safe_so_test.sh
> 
> even though the respective functions in icf_test.o seem to be the same
> (attached).

Hi Richard,

  I used this object in my gold build and it works perfectly for me. I guess I need more details. Could you please attach the following files from the testsuite dir of your gold BUILD :

icf_test.stdout
Output of sh -x icf_test.sh

Thanks,
-Sri.
Comment 2 Richard Biener 2011-01-12 10:30:42 UTC
Sure.  Just to add, a readelf on the linked binary shows both respective
functions at different addresses.

icf_test.stdout:

0000000000401748 d _DYNAMIC
0000000000401920 d _GLOBAL_OFFSET_TABLE_
0000000000400628 R _IO_stdin_used
                 w _Jv_RegisterClasses
0000000000400514 T folded_func()
00000000004004f4 T common()
00000000004004ff T kept_func()
0000000000401958 d __CTOR_END__
0000000000401950 d __CTOR_LIST__
...
(I guess the above was the interesting pieces)

shell log:

+ check icf_test.stdout folded_func kept_func
++ grep folded_func icf_test.stdout
++ awk '{print $1}'
+ func_addr_1=0000000000400514
++ grep kept_func icf_test.stdout
++ awk '{print $1}'
+ func_addr_2=00000000004004ff
+ '[' 0000000000400514 '!=' 00000000004004ff ']'
+ echo 'Identical Code Folding failed to fold' folded_func and kept_func
Identical Code Folding failed to fold folded_func and kept_func
+ exit 1

(of course not too interesting with the above fact)

This is from the plain binutils 2.21 release, configured with

../configure 'CFLAGS=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wno-error' 'CXXFLAGS=-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wno-error' --prefix=/usr --libdir=/usr/lib64 --infodir=/usr/share/info --mandir=/usr/share/man --with-bugurl=http://bugs.opensuse.org/ '--with-pkgversion=GNU Binutils; devel:gcc / openSUSE_Factory' --with-separate-debug-dir=/usr/lib/debug --with-pic --build=x86_64-suse-linux --enable-targets=alpha-suse-linux,arm-suse-linux,hppa-suse-linux,hppa64-suse-linux,i686-suse-linux,ia64-suse-linux,m68k-suse-linux,mips-suse-linux,powerpc-suse-linux,powerpc64-suse-linux,s390-suse-linux,s390x-suse-linux,sh4-suse-linux,sparc-suse-linux,sparc64-suse-linux,x86_64-suse-linux,powerpc-macos,powerpc-macos10,spu-elf --enable-plugins --enable-gold --enable-shared

and gold configury patched to simply skip targets it doesn't know
(bah - --enable-targets is shared with all subdir configures but
the list of supported tagets differs ... that sucks).

icf_test.cpp is compiled like

g++ -DHAVE_CONFIG_H -I. -I../../../gold/testsuite -I..  -I../../../gold/testsuite -I../../../gold/testsuite/.. -I../../../gold/testsuite/../../include -I../../../gold/testsuite/../../elfcpp -I.. -DLOCALEDIR="\"/usr/share/locale\""   -W -Wall    -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fmerge-constants -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wno-error -O0 -c -ffunction-sections -g -o icf_test.o ../../../gold/testsuite/icf_test.cc

g++ -W -Wall    -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fmerge-constants -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wno-error   -o icf_test -Bgcctestdir/ -Wl,--icf=all icf_test.o

and g++ is 4.5.2 which is patched to add --build-id to the link command
(-v output):

 /usr/lib64/gcc/x86_64-suse-linux/4.5/collect2 --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o icf_test /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.5/crtbegin.o -Lgcctestdir -L/usr/lib64/gcc/x86_64-suse-linux/4.5 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../.. --icf=all icf_test.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-suse-linux/4.5/crtend.o /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crtn.o

which seems to be the problem(!) - with --build-id manually removed I get

    39: 00000000004004df    21 FUNC    GLOBAL DEFAULT   13 _Z9kept_funcv
    40: 00000000004004df    21 FUNC    GLOBAL DEFAULT   13 _Z11folded_funcv

is there any reason why you do not perform ICF when generating build-ids?
I can't think of any.
Comment 3 Ian Lance Taylor 2011-07-09 05:44:14 UTC
Is this still a problem with current gold?

I don't see why --build-id has anything to do with this.  I'm using a gcc patched to pass --build-id, and the tests pass for me.

If this still fails for you, please attach your icf_test.o file.  Thanks.
Comment 4 Richard Biener 2011-07-11 11:27:55 UTC
The tests now work on the 2.21 branch.  The only gold fail on x86_64 (with GCC 4.6.1) is

PASS: exception_test
/bin/sh: line 1:  9918 Aborted                 "$tst" > exception_static_test.lo
g-t 2>&1
FAIL: exception_static_test

and for i?86 I still get linker fails for them:

g++ -W -Wall    -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fmerge-const
ants -O2 -g -Bgcctestdir/ -static  -o exception_static_test exception_test_main.
o exception_test_1.o exception_test_2.o  -lz 
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(errlist.o):(.deb
ug_info+0x1c3): warning: `sys_errlist' is deprecated; use `strerror' or `strerro
r_r' instead
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(errlist.o):(.deb
ug_info+0x1f1): warning: `sys_nerr' is deprecated; use `strerror' or `strerror_r
' instead
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(elf-init.o): in 
function __libc_csu_irel:elf-init.c:94: error: undefined reference to '__rel_ipl
t_end'
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(elf-init.o): in 
function __libc_csu_irel:elf-init.c:94: error: undefined reference to '__rel_ipl
t_start'
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(elf-init.o): in 
function __libc_csu_irel:../sysdeps/i386/dl-irel.h:36: error: undefined referenc
e to '__rel_iplt_start'
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(elf-init.o): in 
function __libc_csu_irel:../sysdeps/i386/dl-irel.h:33: error: undefined referenc
e to '__rel_iplt_start'
gcctestdir/ld: /usr/lib/gcc/i586-suse-linux/4.6/../../../libc.a(elf-init.o): in 
function __libc_csu_irel:../sysdeps/i386/dl-irel.h:36: error: undefined referenc
e to '__rel_iplt_start'
collect2: ld returned 1 exit status
make[5]: *** [exception_static_test] Error 1

similar for tls_static_test and tls_static_pic_test.