GMP doesn't honor march flag

Paul Jähne paul.jaehne at gmx.de
Thu Dec 21 09:48:47 UTC 2017


Hello,

I encountered a problem with GMP when using the march flag.

I build GMP 6.1.1 with march=corei7 or march=westmere with GCC 5.4.0 on 
a server with a Haswell processor (E5-2630 v3). When executing curl 
(version 7.47.0 on Ubuntu 16.04) which uses GMP to retrieve a https 
website on a system with a Westmere Processor (Intel Xeon E5645) it 
crashes with the error: Illegal instruction (core dumped).

I also reproduced it with my laptop (it has a Browadwell i5-5200U). Here 
are the commands I used to built on my laptop:

$ cd /dev/shm
$ wget http://ftp.gnu.org/gnu/gmp/gmp-6.1.1.tar.bz2
$ tar -xjf gmp-6.1.1.tar.bz2
$ cd gmp-6.1.1/
$ CFLAGS="-march=corei7" CPPFLAGS=$CFLAGS CXXFLAGS=$CFLAGS ./configure --enable-cxx
$ make

Then copying the libraries to the server and executing it with the 
selfcompiled GMP:

$ scp .libs/libgmp* user at node015:/libgmptest
$ ssh user at node015
$ LD_LIBRARY_PATH=/home/user/libgmptest/ curl https://github.com
Illegal instruction (core dumped)
$ LD_LIBRARY_PATH=/home/user/libgmptest/ ldd /usr/bin/curl
         linux-vdso.so.1 =>  (0x00007ffd76339000)
         libcurl-gnutls.so.4 => /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 (0x00007f22b9123000)
         libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f22b8f09000)
         libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f22b8cec000)
         libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f22b8922000)
         libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007f22b86ef000)
         librtmp.so.1 => /usr/lib/x86_64-linux-gnu/librtmp.so.1 (0x00007f22b84d3000)
         libnettle.so.6 => /usr/lib/x86_64-linux-gnu/libnettle.so.6 (0x00007f22b829d000)
         libgnutls.so.30 => /usr/lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f22b7f6d000)
         libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f22b7d23000)
         liblber-2.4.so.2 => /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2 (0x00007f22b7b14000)
         libldap_r-2.4.so.2 => /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2 (0x00007f22b78c3000)
         /lib64/ld-linux-x86-64.so.2 (0x00007f22b95bf000)
         libhogweed.so.4 => /usr/lib/x86_64-linux-gnu/libhogweed.so.4 (0x00007f22b7690000)
         *libgmp.so.10 => /home/user/libgmptest/libgmp.so.10 (0x00007f22b73f3000)*
         libp11-kit.so.0 => /usr/lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f22b718f000)
         libtasn1.so.6 => /usr/lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f22b6f7c000)
         libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f22b6caa000)
         libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f22b6a7b000)
         libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f22b6877000)
         libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f22b666c000)
         libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f22b6451000)
         libsasl2.so.2 => /usr/lib/x86_64-linux-gnu/libsasl2.so.2 (0x00007f22b6236000)
         libgssapi.so.3 => /usr/lib/x86_64-linux-gnu/libgssapi.so.3 (0x00007f22b5ff5000)
         libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f22b5ded000)
         libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f22b5be9000)
         libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f22b59e5000)
         libheimntlm.so.0 => /usr/lib/x86_64-linux-gnu/libheimntlm.so.0 (0x00007f22b57dc000)
         libkrb5.so.26 => /usr/lib/x86_64-linux-gnu/libkrb5.so.26 (0x00007f22b5552000)
         libasn1.so.8 => /usr/lib/x86_64-linux-gnu/libasn1.so.8 (0x00007f22b52b0000)
         libhcrypto.so.4 => /usr/lib/x86_64-linux-gnu/libhcrypto.so.4 (0x00007f22b507d000)
         libroken.so.18 => /usr/lib/x86_64-linux-gnu/libroken.so.18 (0x00007f22b4e67000)
         libwind.so.0 => /usr/lib/x86_64-linux-gnu/libwind.so.0 (0x00007f22b4c3e000)
         libheimbase.so.1 => /usr/lib/x86_64-linux-gnu/libheimbase.so.1 (0x00007f22b4a2f000)
         libhx509.so.5 => /usr/lib/x86_64-linux-gnu/libhx509.so.5 (0x00007f22b47e4000)
         libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007f22b450f000)
         libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f22b42d7000)

So my guess is that GMP somehow ignores the march flag and builds for 
the current architecture. Therefore running with the library on older 
architectures fails.

/The GMP version number, and if pre-packaged or patched then say so.
/6.1.1 no modifications/
/

/A test program that makes it possible for us to reproduce the bug. 
Include instructions on how to run the program.
/LD_LIBRARY_PATH=/home/user/libgmptest/ curl https://github.com
(or any other https website)/
/

/A description of what is wrong. If the results are incorrect, in what 
way. If you get a crash, say so.
/curl crashes with illegal instruction
//

/If you get a crash, include a stack backtrace from the debugger if it’s 
informative (‘where’ in gdb, or ‘$C’ in adb).
/not informative
//

/Please do not send core dumps, executables or straces./

/The ‘configure’ options you used when building GMP, if any.
/CFLAGS="-march=corei7" CPPFLAGS=$CFLAGS CXXFLAGS=$CFLAGS ./configure 
--enable-cxx/
/

/The output from ‘configure’, as printed to stdout, with any options used.
/attached as configure.gz/
/

/The name of the compiler and its version. For gcc, get the version with 
‘gcc -v’, otherwise perhaps ‘what `which cc`’, or similar.
/$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 
5.4.0-6ubuntu1~16.04.5' 
--with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs 
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ 
--prefix=/usr --program-suffix=-5 --enable-shared 
--enable-linker-build-id --libexecdir=/usr/lib 
--without-included-gettext --enable-threads=posix --libdir=/usr/lib 
--enable-nls --with-sysroot=/ --enable-clocale=gnu 
--enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-libmpx --enable-plugin 
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk 
--enable-gtk-cairo 
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre 
--enable-java-home 
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 
--with-arch-directory=amd64 
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc 
--enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic 
--enable-checking=release --build=x86_64-linux-gnu 
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)/
/

/The output from running ‘uname -a’.
/laptop: $ uname -a
Linux FIZI-LEX-072 4.13.0-19-generic #22~16.04.1-Ubuntu SMP Mon Dec 4 
15:35:18 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
server: $ uname -a
Linux ribnode015 4.4.0-103-generic #126-Ubuntu SMP Mon Dec 4 16:23:28 
UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

/The output from running ‘./config.guess’, and from running 
‘./configfsf.guess’ (might be the same).
/$ ./config.guess
broadwell-pc-linux-gnu
$ ./configfsf.guess
x86_64-pc-linux-gnu
//

/If the bug is related to ‘configure’, then the compressed contents of 
config.log.
/attached as config.log.gz
//

/If the bug is related to an asm file not assembling, then the contents 
of config.m4 and the offending line or lines from the temporary 
mpn/tmp-<file>.s./
not related to asm

Is there any way to make GMP respect the march flag?

Kind regards

Paul

-------------- next part --------------
A non-text attachment was scrubbed...
Name: configure.gz
Type: application/gzip
Size: 4858 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20171221/035e63db/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: config.log.gz
Type: application/gzip
Size: 36567 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20171221/035e63db/attachment-0003.bin>


More information about the gmp-bugs mailing list