LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 04-16-2015, 10:07 AM   #1
Lennie
Member
 
Registered: Aug 2012
Location: Sweden
Distribution: LFS, built with pacman
Posts: 374

Rep: Reputation: 85
Illegal instruction when compiling some packages


I have compiled my system with -march=core2 -mtune=corei7 to run on two machines, one with core2-duo and one with i7. On the core2 machine when I compile some packages it errors out with Illegal instruction. The same packages can be compiled on the i7 machine. I recompiled the core system (the LFS packages) as generic 64-bit, but I still get the same errors. It is only some packages that gives this errors, other compiles fine. Here are some examples:

curl:
Code:
configure: Configured to build curl/libcurl:

  curl version:     7.40.0
  Host setup:       x86_64-unknown-linux-gnu
  Install prefix:   /usr
  Compiler:         gcc
  SSL support:      enabled (OpenSSL)
  SSH support:      no      (--with-libssh2)
  zlib support:     enabled
  GSS-API support:  no      (--with-gssapi)
  TLS-SRP support:  enabled
  resolver:         POSIX threaded
  IPv6 support:     no      (--enable-ipv6)
  Unix sockets support: enabled
  IDN support:      enabled
  Build libcurl:    Shared=yes, Static=no
  Built-in manual:  enabled
  --libcurl option: enabled (--disable-libcurl-option)
  Verbose errors:   enabled (--disable-verbose)
  SSPI support:     no      (--enable-sspi)
  ca cert bundle:   /etc/ssl/ca-bundle.crt
  ca cert path:     no
  LDAP support:     enabled (OpenLDAP)
  LDAPS support:    enabled
  RTSP support:     enabled
  RTMP support:     enabled (librtmp)
  metalink support: no      (--with-libmetalink)
  HTTP2 support:    disabled (--with-nghttp2)
  Protocols:        DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS LDAP LDAPS POP3 POP3S RTMP RTSP SMB SMBS SMTP SMTPS TELNET TFTP

Making all in lib
make[1]: Entering directory '/tmp/curl/src/curl-7.40.0/lib'
make  all-am
make[2]: Entering directory '/tmp/curl/src/curl-7.40.0/lib'
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H   -I../include/curl -I../include -I../include -I../lib -I../lib  -DBUILDING_LIBCURL      -O2 -march=x86-64 -mtune=generic -pthread  -MT libcurl_la-file.lo -MD -MP -MF .deps/libcurl_la-file.Tpo -c -o libcurl_la-file.lo `test -f 'file.c' || echo './'`file.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I../include/curl -I../include -I../include -I../lib -I../lib -DBUILDING_LIBCURL -O2 -march=x86-64 -mtune=generic -pthread -MT libcurl_la-file.lo -MD -MP -MF .deps/libcurl_la-file.Tpo -c file.c  -fPIC -DPIC -o .libs/libcurl_la-file.o
mv -f .deps/libcurl_la-file.Tpo .deps/libcurl_la-file.Plo
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H   -I../include/curl -I../include -I../include -I../lib -I../lib  -DBUILDING_LIBCURL      -O2 -march=x86-64 -mtune=generic -pthread  -MT libcurl_la-timeval.lo -MD -MP -MF .deps/libcurl_la-timeval.Tpo -c -o libcurl_la-timeval.lo `test -f 'timeval.c' || echo './'`timeval.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I../include/curl -I../include -I../include -I../lib -I../lib -DBUILDING_LIBCURL -O2 -march=x86-64 -mtune=generic -pthread -MT libcurl_la-timeval.lo -MD -MP -MF .deps/libcurl_la-timeval.Tpo -c timeval.c  -fPIC -DPIC -o .libs/libcurl_la-timeval.o
timeval.c: In function 'curlx_tvdiff_secs':
timeval.c:133:7: internal compiler error: Illegal instruction
       (double)(newer.tv_usec-older.tv_usec)/1000000.0;
       ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Makefile:1129: recipe for target 'libcurl_la-timeval.lo' failed
make[2]: *** [libcurl_la-timeval.lo] Error 1
make[2]: Leaving directory '/tmp/curl/src/curl-7.40.0/lib'
Makefile:703: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/tmp/curl/src/curl-7.40.0/lib'
Makefile:849: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1
The part of the code that causes the error:
Code:
double curlx_tvdiff_secs(struct timeval newer, struct timeval older)
{
  if(newer.tv_sec != older.tv_sec)
    return (double)(newer.tv_sec-older.tv_sec)+
      (double)(newer.tv_usec-older.tv_usec)/1000000.0;
  else
    return (double)(newer.tv_usec-older.tv_usec)/1000000.0;
}
sudo:
Code:
/bin/sh ../../libtool --mode=compile gcc -c -I../../include -I../.. -I. -I. -I../.. -DLIBDIR=\"/usr/lib\" -D__STDC_WANT_LIB_EXT1__=1 -O2 -march=x86-64 -mtune=generic -fvisibility=hidden -fPIE -fstack-protector-strong -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 -D_PATH_SUDOERS=\"/etc/sudoers\" -DSUDOERS_UID=0 -DSUDOERS_GID=0 -DSUDOERS_MODE=0440 -DLOCALEDIR=\"/usr/share/locale\" ./timestamp.c
libtool: compile:  gcc -c -I../../include -I../.. -I. -I. -I../.. -DLIBDIR=\"/usr/lib\" -D__STDC_WANT_LIB_EXT1__=1 -O2 -march=x86-64 -mtune=generic -fvisibility=hidden -fstack-protector-strong -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 -D_PATH_SUDOERS=\"/etc/sudoers\" -DSUDOERS_UID=0 -DSUDOERS_GID=0 -DSUDOERS_MODE=0440 -DLOCALEDIR=\"/usr/share/locale\" ./timestamp.c  -fPIC -DPIC -o .libs/timestamp.o
./timestamp.c: In function ‘timestamp_status’:
./timestamp.c:490:5: internal compiler error: Illegal instruction
     timeout.tv_nsec = ((60.0 * def_timestamp_timeout) - (double)timeout.tv_sec)
     ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Makefile:1046: recipe for target 'timestamp.lo' failed
make[1]: *** [timestamp.lo] Error 1
make[1]: Leaving directory '/tmp/sudo/src/sudo-1.8.12/plugins/sudoers'
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2
The part of the code that causes the error:
Code:
/* Compare stored time stamp with current time. */
    sudo_timespecsub(&timestamp_key.ts, &entry.ts, &diff);
    timeout.tv_sec = 60 * def_timestamp_timeout;
    timeout.tv_nsec = ((60.0 * def_timestamp_timeout) - (double)timeout.tv_sec)
    * 1000000000.0;
    if (sudo_timespeccmp(&diff, &timeout, <)) {
    status = TS_CURRENT;
groff:
Code:
In file included from color.cpp:23:0:
/tmp/groff/src/groff-1.22.3/src/include/lib.h:163:1: internal compiler error: Illegal instruction
 const double PI = 3.14159265358979323846;
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
/tmp/groff/src/groff-1.22.3/Makefile.comm:94: recipe for target 'color.o' failed
make[2]: *** [color.o] Error 1
make[2]: Leaving directory '/tmp/groff/src/groff-1.22.3/src/libs/libgroff'
Makefile:820: recipe for target 'src/libs/libgroff' failed
make[1]: *** [src/libs/libgroff] Error 2
make[1]: Leaving directory '/tmp/groff/src/groff-1.22.3'
Makefile:801: recipe for target 'all' failed
make: *** [all] Error 2
binutils:
Code:
gcc -DHAVE_CONFIG_H -I. -I../../binutils-2.25/binutils  -I. -I../../binutils-2.25/binutils -I../bfd -I../../binutils-2.25/binutils/../bfd -I../../binutils-2.25/binutils/../include -DLOCALEDIR="\"/usr/share/locale\"" -Dbin_dummy_emulation=bin_vanilla_emulation  -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -O2 -march=x86-64 -mtune=generic -MT readelf.o -MD -MP -MF .deps/readelf.Tpo -c -o readelf.o ../../binutils-2.25/binutils/readelf.c
../../binutils-2.25/binutils/readelf.c: In function ‘process_symbol_table’:
../../binutils-2.25/binutils/readelf.c:10406:5: internal compiler error: Illegal instruction
     counts[0], (counts[0] * 100.0) / nbuckets);
     ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Makefile:932: recipe for target 'readelf.o' failed
make[4]: *** [readelf.o] Error 1
make[4]: Leaving directory '/tmp/binutils/src/binutils-build/binutils'
Makefile:974: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory '/tmp/binutils/src/binutils-build/binutils'
Makefile:625: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/tmp/binutils/src/binutils-build/binutils'
Makefile:3482: recipe for target 'all-binutils' failed
make[1]: *** [all-binutils] Error 2
make[1]: Leaving directory '/tmp/binutils/src/binutils-build'
Makefile:832: recipe for target 'all' failed
make: *** [all] Error 2
The part of the code that causes the error:
Code:
if (nbuckets > 0)
    {
      unsigned long i;
      printf ("      0  %-10lu (%5.1f%%)\n",
          counts[0], (counts[0] * 100.0) / nbuckets);
      for (i = 1; i <= maxlength; ++i)
        {
          nzero_counts += counts[i] * i;
          printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
              i, counts[i], (counts[i] * 100.0) / nbuckets,
              (nzero_counts * 100.0) / nsyms);
        }
    }
bison:
Code:
lib/hash.c:134:5: internal compiler error: Illegal instruction
     DEFAULT_GROWTH_THRESHOLD,
     ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Makefile:3461: recipe for target 'lib/hash.o' failed
make[2]: *** [lib/hash.o] Error 1
make[2]: Leaving directory '/tmp/bison/src/bison-3.0.4'
Makefile:4522: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/tmp/bison/src/bison-3.0.4'
Makefile:2625: recipe for target 'all' failed
make: *** [all] Error 2
The part of the code that causes the error:
Code:
#define DEFAULT_GROWTH_THRESHOLD 0.8f
#define DEFAULT_GROWTH_FACTOR 1.414f

[...]

/* Use this to initialize or reset a TUNING structure to
   some sensible values. */
static const Hash_tuning default_tuning =
  {
    DEFAULT_SHRINK_THRESHOLD,
    DEFAULT_SHRINK_FACTOR,
    DEFAULT_GROWTH_THRESHOLD,
    DEFAULT_GROWTH_FACTOR,
    false
  };
I can compile the following packages on the core2 machine: acl, attr, autoconf, automake, bash, bc

Any ideas what could be the cause of this problem?
 
Old 04-16-2015, 11:22 AM   #2
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
It is a gcc bug. Report to gcc bugzilla with detailed bug info.
 
Old 04-16-2015, 11:43 AM   #3
Krejzi
Member
 
Registered: Jan 2015
Posts: 215

Rep: Reputation: Disabled
Quote:
Originally Posted by Lennie View Post
I have compiled my system with -march=core2 -mtune=corei7 to run on two machines, one with core2-duo and one with i7. On the core2 machine when I compile some packages it errors out with Illegal instruction.

...

Any ideas what could be the cause of this problem?
If you compiled LFS on the Core i7 system, then GMP will be optimized for that one (it will use -march=corei7 by default). Use --build=x86_64-linux-gnu to optimize it for generic x86_64 linux. Illegal instrution comes from invalid optimizations - optimized to use new functionality from future generations not available in previous one.
 
1 members found this post helpful.
Old 04-16-2015, 12:07 PM   #4
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
There was bug old gmp package where it did not detected correct arch type.

While building it can be corrected before ./configure is run with:

Code:
mv config{fsf,}.guess
mv config{fsf,}.sub
 
Old 04-16-2015, 04:22 PM   #5
ReaperX7
LQ Guru
 
Registered: Jul 2011
Location: California
Distribution: Slackware64-15.0 Multilib
Posts: 6,558
Blog Entries: 15

Rep: Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097Reputation: 2097
One thing about optimizations. If you build for a specific architecture, build for the minimal required optimization of that architecture.

On 32-bit systems, as old as it may be, building for i386 or i486 setting in mtune is never a bad choice. Yes you lose out on some later generation SIMDs but you at least have a working build package. The same goes with x86_64.

Also, using a flag for -O2 rather than -O3 with your C compiler will improve compatibility and reliability of packages.

Over the years I've learned this the hard way... Never build for speed because more than likely, you're going to break something. Build for compatibility and reliability only. Learned that from Slackware, Gentoo, Funtoo, CRUX, and various others.
 
Old 04-16-2015, 06:51 PM   #6
oblo
Member
 
Registered: May 2014
Location: Rome, Italy
Distribution: LFS 7.6
Posts: 55

Rep: Reputation: Disabled
I have a Pentium(R) Dual-Core E5700 @ 3.00GHz and recently i built LFS/BLFS (7.7 SVN) with -O2 -march=core2 -fomit-frame-pointer
No errors here but i unset in Binutils, GCC and Glibc steps (according to book).
 
Old 04-16-2015, 11:13 PM   #7
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
On 32 bit systems even the newer kernel don't run with i386. More generic option would be i586 or i686.

For x86_64 it uses sse2 by default though it can be changed with avx or avx2. Again avx and avx2 are available only in newer processors. Some old 64 bit processors won't support running them.

You can use march as you like but remember they can't be shared/installed on incompatible processors.

If you want to compile for just one system then it is best to use march, mtune for that one.

But we like to run our built piece in all the different systems so it's best to use generic arch and optimizations.

As ReaperX7 said using the default optimizations is best to avoid coding bugs and compatibility issues.
 
Old 04-17-2015, 12:23 PM   #8
Lennie
Member
 
Registered: Aug 2012
Location: Sweden
Distribution: LFS, built with pacman
Posts: 374

Original Poster
Rep: Reputation: 85
Thank you. The problem was solved by recompiling gmp with --build=x86_64-linux-gnu added to the configure options.

The reason it didn't work when I recompiled the core system as core2 and later as generic, was because I had added CFLAGS and CXXFLAGS to the buildscript of gmp to override my default settings, but I hadn't specified that it should be generic, only like CFLAGS="-O2 -fPIC". The reason for that was because in an earlier version of LFS I got Illegal instruction when running make check on mpc if gmp was compiled with -march=core2 -mtune=corei7.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
illegal instruction amartlk Linux - Newbie 4 11-03-2010 12:00 PM
Problems with illegal instruction ligang Linux - Embedded & Single-board computer 12 05-06-2010 02:24 PM
aticonfig illegal instruction tamtam Slackware 14 09-22-2006 08:27 PM
MPlex - Illegal Instruction RySk8er30 Linux - Software 1 01-22-2006 12:50 PM
Illegal instruction madsjakob Linux - Software 0 10-28-2003 07:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 11:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration