Bug 80600 - hidden symbol `__cpu_model' is referenced by DSO
Summary: hidden symbol `__cpu_model' is referenced by DSO
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Krister Walfridsson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-03 03:31 UTC by coypu
Modified: 2019-01-16 17:21 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-netbsd
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-05-03 00:00:00


Attachments
Unbreak NetBSD following r243219 (423 bytes, patch)
2017-05-04 17:42 UTC, coypu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description coypu 2017-05-03 03:31:38 UTC
building a simple fortran hello world:
/usr/bin/ld: a.out: hidden symbol `__cpu_model' in /usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/libgcc.a(cpuinfo.o) is referenced by DSO
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

Trying the test case in target/65612 which sounds related:
mv20.cc:11:5: error: multiversioning needs ifunc which is not supported on this target
Comment 1 coypu 2017-05-03 03:43:09 UTC
Related and possible duplicate for dfly: libgcc/61309
Comment 2 Richard Biener 2017-05-03 07:17:23 UTC
Which DSO referenes it?  __cpu_model is supposed to be defined in the executable via the definition in libgcc.a.

This changed at some point so make sure to build the DSO and the application with the same compiler.
Comment 3 coypu 2017-05-03 08:10:33 UTC
$ /usr/pkg/gcc7/bin/gfortran -Wl,--verbose test.f95 |grep succeeded |sort -u
..
attempt to open /usr/lib/crt0.o succeeded
attempt to open /usr/lib/crtbegin.o succeeded
attempt to open /usr/lib/crtend.o succeeded
attempt to open /usr/lib/crti.o succeeded
attempt to open /usr/lib/crtn.o succeeded
attempt to open /usr/lib/libc.so succeeded
attempt to open /usr/lib/libm.so succeeded
attempt to open /usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/../../../libgcc_s.so succeeded
attempt to open /usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/../../../libgfortran.so succeeded
attempt to open /usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/../../../libquadmath.so succeeded
attempt to open /usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/libgcc.a succeeded
attempt to open /var/tmp//ccCfh5i1.o succeeded

if I 'nm library | grep cpu_model' I get:
/usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/../../../libgcc_s.so:    0000000000214540 b __cpu_model
/usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/../../../libgfortran.so:                  U __cpu_model
/usr/pkg/gcc7/lib/gcc/x86_64--netbsd/7.1.0/libgcc.a:                0000000000000000 B __cpu_model

I got everything (all those) under /usr/pkg/gcc7 from building GCC 7.1.0, it's possible I built it wrong
I hope this is the right information
Comment 4 Richard Biener 2017-05-03 09:37:10 UTC
Ah, so the change made for PR65612 was

Index: libgcc/config.host
===================================================================
--- libgcc/config.host  (revision 222177)
+++ libgcc/config.host  (revision 222178)
@@ -1306,7 +1306,7 @@ i[34567]86-*-linux* | x86_64-*-linux* |
   i[34567]86-*-kfreebsd*-gnu | x86_64-*-kfreebsd*-gnu | \
   i[34567]86-*-knetbsd*-gnu | \
   i[34567]86-*-gnu*)
-       tmake_file="${tmake_file} t-tls i386/t-linux"
+       tmake_file="${tmake_file} t-tls i386/t-linux t-slibgcc-libgcc"
        if test "$libgcc_cv_cfi" = "yes"; then
                tmake_file="${tmake_file} t-stack i386/t-stack-i386"
        fi

but that doesn't include 

x86_64-*-netbsd*)
        tmake_file="${tmake_file} i386/t-crtstuff"
        ;;

CCing author of change and netbsd maintainer.
Comment 5 H.J. Lu 2017-05-03 15:11:59 UTC
Does it work with GCC 6?
Comment 6 H.J. Lu 2017-05-03 16:56:48 UTC
This is related to PR 61309 and PR 67424.
Comment 7 krister.walfridsson 2017-05-03 21:25:08 UTC
Yes, it works with GCC 6, and it used to work with GCC 7.  My guess is that it started to fail with r243219.

I'm at a conference the rest of this week, but I'll fix this as soon as I'm back.
Comment 8 coypu 2017-05-04 17:42:23 UTC
Created attachment 41317 [details]
Unbreak NetBSD following r243219

This patch works for me.
Comment 9 H.J. Lu 2017-05-04 18:28:10 UTC
(In reply to coypu from comment #8)
> Created attachment 41317 [details]
> Unbreak NetBSD following r243219
> 
> This patch works for me.

This may break Linux.  You may want to investigate if this approach:

commit 6e6c7fc1e15525a10f48d4f5ac2edd853e2f5cb7
Author: nsz <nsz@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Nov 11 17:31:07 2016 +0000

    [i386][musl] Add cpuinfo to static libgcc only on *-musl*
    
    The __cpu_indicator_init and __cpu_model symbols are not safe to use
    from shared libgcc_s.so from ifunc resolvers, so since gcc-6, only
    the definitions from static libgcc.a are used, however the symbols
    are kept in libgcc_s as well for backward compatibility (with
    appropriate symbol version).  On targets without such backward
    compatibility concern add cpuinfo to the static library only (this
    avoids running the ctor, reduces libgcc_s size and elf abi concerns
    about the versioned symbols).

works for you.
Comment 10 coypu 2017-05-05 05:01:44 UTC
(In reply to H.J. Lu from comment #9)
> 
> This may break Linux.  You may want to investigate if this approach:
> 
> commit 6e6c7fc1e15525a10f48d4f5ac2edd853e2f5cb7
> Author: nsz <nsz@138bc75d-0d04-0410-961f-82ee72b054a4>
> Date:   Fri Nov 11 17:31:07 2016 +0000
> 
>     [i386][musl] Add cpuinfo to static libgcc only on *-musl*
>     
>     The __cpu_indicator_init and __cpu_model symbols are not safe to use
>     from shared libgcc_s.so from ifunc resolvers, so since gcc-6, only
>     the definitions from static libgcc.a are used, however the symbols
>     are kept in libgcc_s as well for backward compatibility (with
>     appropriate symbol version).  On targets without such backward
>     compatibility concern add cpuinfo to the static library only (this
>     avoids running the ctor, reduces libgcc_s size and elf abi concerns
>     about the versioned symbols).
> 
> works for you.

Thanks. if I understand it correctly, it breaks backwards compatibility, so would rather avoid it. With my (not upstreamable) patch we have a working GCC, so it's not a pressing issue for us, although it seems to affect many other platforms.
Comment 11 Krister Walfridsson 2017-05-14 22:49:35 UTC
Author: kristerw
Date: Sun May 14 22:49:03 2017
New Revision: 248037

URL: https://gcc.gnu.org/viewcvs?rev=248037&root=gcc&view=rev
Log:
PR target/80600 - hidden symbol '__cpu_model' is referenced by DSO

gcc/ChangeLog:

        PR target/80600
        * config/netbsd.h (NETBSD_LIBGCC_SPEC): Always add -lgcc.

libgcc/ChangeLog:

        PR target/80600
        * config.host (*-*-netbsd*): Add t-slibgcc-libgcc to tmake_file.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/netbsd.h
    trunk/libgcc/ChangeLog
    trunk/libgcc/config.host
Comment 12 Krister Walfridsson 2017-09-28 19:18:23 UTC
Author: kristerw
Date: Thu Sep 28 19:17:51 2017
New Revision: 253263

URL: https://gcc.gnu.org/viewcvs?rev=253263&root=gcc&view=rev
Log:
gcc/ChangeLog:

	Backport from mainline
	2017-05-14  Krister Walfridsson  <krister.walfridsson@gmail.com>

	PR target/80600
	* config/netbsd.h (NETBSD_LIBGCC_SPEC): Always add -lgcc.

libgcc/ChangeLog:

	Backport from mainline
	2017-05-14  Krister Walfridsson  <krister.walfridsson@gmail.com>

	PR target/80600
	* config.host (*-*-netbsd*): Add t-slibgcc-libgcc to tmake_file.

Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/config/netbsd.h
    branches/gcc-7-branch/libgcc/ChangeLog
    branches/gcc-7-branch/libgcc/config.host
Comment 13 Krister Walfridsson 2017-09-28 19:54:24 UTC
Fixed for trunk and GCC 7.3 (GCC 6 and 5 does not have this problem).
Comment 14 nightstrike 2018-11-25 02:50:12 UTC
FWIW, I get this on 8.2 on Linux.