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
Related and possible duplicate for dfly: libgcc/61309
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.
$ /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
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.
Does it work with GCC 6?
This is related to PR 61309 and PR 67424.
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.
Created attachment 41317 [details] Unbreak NetBSD following r243219 This patch works for me.
(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.
(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.
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
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
Fixed for trunk and GCC 7.3 (GCC 6 and 5 does not have this problem).
FWIW, I get this on 8.2 on Linux.