Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 761310

Summary: dev-libs/gmp[asm]: broken on s390 ("libgmp.so: undefined reference to `sdiv_qrnnd'")
Product: Gentoo Linux Reporter: Sam James <sam>
Component: Current packagesAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED FIXED    
Severity: normal CC: s390
Priority: Normal    
Version: unspecified   
Hardware: s390   
OS: Linux   
URL: https://gmplib.org/list-archives/gmp-bugs/2016-December/004039.html
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: mpfr's config.log
mpfr build.log
gmp-6.2.0-r1 build.log
build.log (with tests failing)

Description Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-23 02:49:57 UTC
Created attachment 679278 [details]
mpfr's config.log

dev-libs/mpfr-4.1.0 (and others) fail like so:
>checking usable gmp.h at link time... yes
>checking for GMP_NUMB_BITS and sizeof(mp_limb_t) consistency... yes
>checking for __gmpz_init in -lgmp... no
>configure: error: libgmp not found or uses a different ABI (including static vs shared).
>Please read the INSTALL file -- see "In case of problem".

Within config.log, we see:
>configure:17696: checking for __gmpz_init in -lgmp
>configure:17721: s390-ibm-linux-gnu-gcc -o conftest -O2 -pipe -march=native -fdiagnostics-show-option -frecord-gcc-switches  -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu conftest.c -lgmp   >&5
>/usr/lib/gcc/s390-ibm-linux-gnu/10.2.0/../../../../s390-ibm-linux-gnu/bin/ld: /usr/lib/gcc/s390-ibm-linux-gnu/10.2.0/../../../libgmp.so: undefined reference to `sdiv_qrnnd'
>collect2: error: ld returned 1 exit status

dev-libs/gmp itself builds correctly with both USE=+/- asm. I've seen the same error when linking to gmp when building libtomcrypt (bug 761235) and other packages.
Building gmp with -asm allows GCC, mpfr, and others to build successfully.

As far as I can tell, the same issue occurs with =dev-libs/gmp-6.2.0-r1.

----
Portage 3.0.12 (python 3.8.7-candidate-1, default/linux/s390/17.0, gcc-10.2.0, glibc-2.32-r5, 5.4.8 s390)
=================================================================
System uname: Linux-5.4.8-s390-8561-with-glibc2.0
KiB Mem:     2056924 total,    800708 free
KiB Swap:      99160 total,     74268 free
Timestamp of repository gentoo: Mon, 21 Dec 2020 20:30:01 +0000
Head commit of repository gentoo: a434ce2ae1ebce625d0fca917af68f18b540159c
sh bash 5.1_p4
ld GNU ld (Gentoo 2.35.1 p2) 2.35.1
app-shells/bash:          5.1_p4::gentoo
dev-lang/perl:            5.30.3-r1::gentoo
dev-lang/python:          2.7.18-r5::gentoo, 3.6.12-r1::gentoo, 3.7.9-r1::gentoo, 3.8.7_rc1::gentoo, 3.9.1::gentoo
dev-util/cmake:           3.17.4-r1::gentoo
sys-apps/baselayout:      2.7-r1::gentoo
sys-apps/openrc:          0.42.1::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.69-r5::gentoo
sys-devel/automake:       1.16.3-r1::gentoo
sys-devel/binutils:       2.35.1-r1::gentoo
sys-devel/gcc:            10.2.0-r4::gentoo
sys-devel/gcc-config:     2.3.2-r1::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.10::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r5::gentoo
Repositories:

gentoo
    location: /bound/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts:
    sync-rsync-verify-metamanifest: yes

ACCEPT_KEYWORDS="s390 ~s390"
ACCEPT_LICENSE="@FREE"
CBUILD="s390-ibm-linux-gnu"
CFLAGS="-O2 -pipe -march=native -fdiagnostics-show-option -frecord-gcc-switches"
CHOST="s390-ibm-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -march=native"
DISTDIR="/bound/distfiles"
EMERGE_DEFAULT_OPTS=" --complete-graph --keep-going --with-bdeps=y --deep --with-bdeps=y --complete-graph --deep --keep-going"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe -march=native"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe -march=native"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="C.UTF8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu"
MAKEOPTS="-j3 -l3"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="acl berkdb big-endian bzip2 cli crypt dri fortran gdbm iconv ipv6 ncurses nls nptl openmp pam pcre readline s390 seccomp split-usr ssl tcpd unicode xattr zlib" ABI_S390="32" ADA_TARGET="gnat_2018" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="void libinput" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2 php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python2_7 python3_8" RUBY_TARGETS="ruby25 ruby26" USERLAND="GNU" VIDEO_CARDS="dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-23 02:52:34 UTC
Created attachment 679281 [details]
mpfr build.log

vapier actually had this problem a few years ago: https://gmplib.org/list-archives/gmp-bugs/2016-December/004039.html
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-23 02:55:34 UTC
On installation of either gmp version in tree:

 * Messages for package dev-libs/gmp-6.2.0-r1:

 * QA Notice: Package triggers severe warnings which indicate that it
 *            may exhibit random runtime failures.
 * udiv_w_sdiv.c:57:4: warning: implicit declaration of function �sdiv_qrnnd�; did you mean �udiv_qrnnd�? [-Wimplicit-function-declaration]
 * Please do not file a Gentoo bug and instead report the above QA
 * issues directly to the upstream developers of this software.
 * Homepage: https://gmplib.org/
>>> Auto-cleaning packages...

So, the error makes complete sense. It should really be failing hard at build time.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-23 03:34:24 UTC
Created attachment 679284 [details]
gmp-6.2.0-r1 build.log
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2020-12-23 08:58:53 UTC
Does gmp pass tests while having this deficiency?
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2020-12-23 14:13:55 UTC
Created attachment 679317 [details]
build.log (with tests failing)

(In reply to Sergei Trofimovich from comment #4)
> Does gmp pass tests while having this deficiency?

No, see newly attached log.
Comment 6 Sergei Trofimovich (RETIRED) gentoo-dev 2021-03-01 23:26:10 UTC
I was confused by initially reading the bug as a breakage that happens when you rebuild gmp with USE=asm then USE=-asm.

But you just get invalid gmp on each build, is that correct? I wonder if -march=native causes wrong CPU arch flavour to be detected.

Otherwise we mask USE flips for a long while:

commit 32849ef2e24987dc6d53d3159c3febe8d3ed2852
Author: Mike Frysinger <vapier@gentoo.org>
Date:   Fri Dec 9 13:45:58 2016 -0500

    profiles: s390: force gmp[asm] for now to fix ABI breakage

diff --git a/profiles/arch/s390/package.use.force b/profiles/arch/s390/package.use.force
index 5db5bc85195..46dcb506821 100644
--- a/profiles/arch/s390/package.use.force
+++ b/profiles/arch/s390/package.use.force
@@ -5,3 +5,8 @@
 # Mike Frysinger <vapier@gentoo.org> (16 Mar 2015)
 # Needs dev-lang/luajit tested #499974
 dev-libs/efl oldlua
+
+# Mike Frysinger <vapier@gentoo.org> (09 Dec 2016)
+# The ABI changes when the flag is disabled.  Force it for now.
+# https://gmplib.org/list-archives/gmp-bugs/2016-December/004039.html
+dev-libs/gmp asm
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2021-03-01 23:46:34 UTC
Tried on lgentoo3.s390.dev.gentoo.org and it's indeed a -march=native.
Reproduced on:

$ LANG=C PORTAGE_TMPDIR=${HOME}/tmp LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu" CFLAGS="-O2 -pipe -march=native -fdiagnostics-show-option -frecord-gcc-switches" CXXFLAGS="-O2 -pipe -march=native"  ebuild /var/db/repos/gentoo/dev-libs/gmp/gmp-6.2.1.ebuild clean test
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2021-03-01 23:56:59 UTC
-march=native on that machine expands to
    -march=arch13 -mesa -mhard-dfp -mhtm -mzarch

$ arch=arch13; for t in param target; do cmd="gcc -Q -O2 -march=$arch --help=$t"; diff -U0 <(LANG=C $cmd) <(LANG=C $cmd -march=native); done
--- /dev/fd/61	2021-03-01 18:47:38.000000000 -0500
+++ /dev/fd/60	2021-03-01 18:47:38.000000000 -0500
@@ -9 +9 @@
-  -mesa                       		[enabled]
+  -mesa                       		[disabled]
@@ -16 +16 @@
-  -mhard-dfp                  		[disabled]
+  -mhard-dfp                  		[enabled]
@@ -19 +19 @@
-  -mhtm                       		[disabled]
+  -mhtm                       		[enabled]
@@ -44 +44 @@
-  -mzarch                     		[disabled]
+  -mzarch                     		[enabled]

Of all the above CFLAGS="-O2 -mzarch" seems to be enough to trigger use of undefined symbol.
Comment 9 Sergei Trofimovich (RETIRED) gentoo-dev 2021-03-02 00:18:29 UTC
On C level -mzarch provides 2 extra macros:

$ diff -U0 <(s390-unknown-linux-gnu-gcc -dM -E - </dev/null) <(s390-unknown-linux-gnu-gcc -dM -E - </dev/null -mzarch)
--- /dev/fd/63  2021-03-01 23:58:13.631079627 +0000
+++ /dev/fd/62  2021-03-01 23:58:13.631079627 +0000
@@ -52,0 +53 @@
+#define __zarch__ 1
@@ -321,0 +323 @@
+#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 1

Only __zarch__ looks relevant for gmp.

sdiv_qrnnd() is a macro defined in longlong.h but only for some cases:

#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
  #if defined (__zarch__) || defined (HAVE_HOST_CPU_s390_zarch)
    #define add_ssaaaa(...
    #define sub_ddmmss(
    #if __GMP_GNUC_PREREQ (4,5)
      #define umul_ppmm(
    #else
      #if 0
        #define umul_ppmm(...
      #else
        #define umul_ppmm(...
      #endif /* if 0 */
    #endif
    #if 0
      #define udiv_qrnnd(...
    #else
      #define udiv_qrnnd(...
    #endif /* if 0 */
  #else /* if __zarch__ */
    #define smul_ppmm(...
    #define sdiv_qrnnd(...
  #endif /* if __zarch__ */

Note: sdiv_qrnnd() is not defined for __zarch__ case relying on availability of 64-bit arithmetics.

Only udiv_w_sdiv.c uses the sdiv_qrnnd() and is included only for non-z targets in configure.ac:

  # IBM System/390 and z/Architecture
  S390_PATTERN | S390X_PATTERN)
    if test "$enable_assembly" = "yes" ; then
       extra_functions="udiv_w_sdiv"
    fi

    case $host_cpu in
      s390)
        ;;
      z900 | z900esa)
        AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
        AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
        extra_functions=""
        ;;
      z990 | z990esa)
        AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
        AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
        extra_functions=""
        ;;
      z9 | z9esa)
        AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
        AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
        extra_functions=""
        ;;
      z10 | z10esa)
        AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
        AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
        extra_functions=""
        ;;
      z196 | z196esa)
        AC_DEFINE_UNQUOTED(HAVE_HOST_CPU_s390_$cpu)
        AC_DEFINE(HAVE_HOST_CPU_s390_zarch)
        extra_functions=""
        ;;
      esac

    case $host in
      S390X_PATTERN)
        extra_functions=""
        ;;
      esac

This creates a mismatch between __zarch__ definition and ./configure assumption.
Comment 10 Larry the Git Cow gentoo-dev 2021-03-02 00:33:38 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e9697a383036e80b9d79a038d8b0e879f71db67c

commit e9697a383036e80b9d79a038d8b0e879f71db67c
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2021-03-02 00:29:48 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2021-03-02 00:33:33 +0000

    dev-libs/gmp: fix s390 symbol leak on -mzarch
    
    Reported-by: Sam James
    Bug: https://bugs.gentoo.org/761310
    Package-Manager: Portage-3.0.16, Repoman-3.0.2
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 dev-libs/gmp/files/gmp-6.2.1-no-zarch.patch |  20 ++++++
 dev-libs/gmp/gmp-6.2.1-r1.ebuild            | 108 ++++++++++++++++++++++++++++
 2 files changed, 128 insertions(+)