Bug 18628

Summary: gold IFUNC testsuite failures with GCC 5
Product: binutils Reporter: H.J. Lu <hjl.tools>
Component: goldAssignee: Cary Coutant <ccoutant>
Status: RESOLVED FIXED    
Severity: normal CC: amodra, ian, rafael
Priority: P2    
Version: 2.26   
Target Milestone: 2.26   
Host: Target:
Build: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 18521    
Attachments: A patch

Description H.J. Lu 2015-07-06 17:33:17 UTC
On Fedora 22/x86-64, gold on master branch at

commit 8a13d42d99390c36d5e7884b509e6bb92ec72e3c
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Mon Jul 6 13:10:56 2015 -0400

    search_struct_field: remove OFFSET parameter

is miscompiled by GCC 5, gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC):

FAIL: script_test_1
FAIL: script_test_11
FAIL: ifuncmain1
FAIL: ifuncmain1pic
FAIL: ifuncmain1vispic
FAIL: ifuncmain1vis
FAIL: ifuncmain1pie
FAIL: ifuncmain1vispie
FAIL: ifuncmain3

GCC 4.8.4 generates working gold.
Comment 1 Alan Modra 2015-07-08 09:33:14 UTC
This isn't a miscompilation of gold itself, but rather of the testcases.  You can prove this quite easily by building gold with gcc-5, running "make check" to reproduce the test failures, then "rm testsuite/script_test_1* testsuite/ifunc*" before running "make check" with an older gcc.
Comment 2 H.J. Lu 2015-07-13 20:04:24 UTC
I opened PR 18663 to track:

FAIL: script_test_1
FAIL: script_test_11

The IFUNC test issue is

[hjl@gnu-6 pr18628]$ readelf -r ifuncmod1.so

Relocation section '.rela.dyn' at offset 0x390 contains 7 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000001828  000100000006 R_X86_64_GLOB_DAT foo()            foo + 0
000000001838  000200000006 R_X86_64_GLOB_DAT foo_hidden()     foo_hidden + 0
000000001848  000300000006 R_X86_64_GLOB_DAT foo_protected()  foo_protected + 0
000000001818  000400000006 R_X86_64_GLOB_DAT 0000000000001880 global + 0
000000001820  000600000006 R_X86_64_GLOB_DAT 0000000000000000 ret_foo + 0
000000001830  000800000006 R_X86_64_GLOB_DAT 0000000000000000 ret_foo_hidden + 0
000000001840  000a00000006 R_X86_64_GLOB_DAT 0000000000000000 ret_foo_protected + 0

Relocation section '.rela.plt' at offset 0x438 contains 3 entries:
  Offset          Info           Type           Sym. Value    Sym. Name + Addend
000000001868  000100000007 R_X86_64_JUMP_SLO foo()            foo + 0
000000001870  000000000025 R_X86_64_IRELATIV                    520
000000001878  000000000025 R_X86_64_IRELATIV                    550
[hjl@gnu-6 pr18628]$ readelf -s ifuncmod1.so | grep global
     4: 0000000000001880     4 OBJECT  GLOBAL PROTECTED   12 global
    10: 0000000000001880     4 OBJECT  GLOBAL PROTECTED   12 global
[hjl@gnu-6 pr18628]$ 

GCC 5 will generate relocation for protected symbol:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248

It is undefined to access protected symbol in IFUNC selector function
inside a DSO.
Comment 3 H.J. Lu 2015-07-13 20:06:23 UTC
Created attachment 8434 [details]
A patch

This works for me.
Comment 4 Cary Coutant 2015-07-22 02:14:38 UTC
Duplicate of PR 18521.

*** This bug has been marked as a duplicate of bug 18521 ***
Comment 5 H.J. Lu 2015-07-22 02:17:13 UTC
Reopen
Comment 6 H.J. Lu 2015-07-22 02:17:55 UTC
*** Bug 18521 has been marked as a duplicate of this bug. ***
Comment 7 H.J. Lu 2015-07-22 02:19:20 UTC
This bug report has analysis and a patch is posted at

https://sourceware.org/ml/binutils/2015-07/msg00098.html
Comment 8 Sourceware Commits 2015-07-22 10:41:47 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cd78ea777c35c497fcc0f20d162789296dc0a44d

commit cd78ea777c35c497fcc0f20d162789296dc0a44d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Jul 22 03:35:47 2015 -0700

    Mark global with hidden attribute
    
    GCC 5 will generate a relocation for protected symbol:
    
    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65248
    
    when compiling for a shared library.  It is undefined to access protected
    symbol in IFUNC selector function inside a shared library.
    
    	PR gold/18628
    	* testsuite/ifuncdep2.c (global): Change protected to hidden.
    	* testsuite/ifuncmod1.c (global): Likewise.
    	* testsuite/ifuncmod5.c (global): Likewise.
Comment 9 H.J. Lu 2015-07-22 10:44:43 UTC
Fixed.