title: gdb exits with : Program received signal SIGILL, Illegal instruction for a c c++ program compiled with gcc / intel_mkl / gfortran -mavx
body: <p>I have a c and c++ mixed large code that is compiled into static libraries.  I call functions from simgms static library from the given program -
  main.cpp is simple but the executable doesn't run and throws a run-time error Illegal instruction. gdb exits from main() in the very first line -inside main.</p>
  
  <p>Searching about the problem hinted that this could be due to gcc version or incompatibility of libraries with intel_mkl. If anyone had encountered with similar issues, suggestions welcome. Thanks!</p>
  
  <pre><code> #include "simgms_scf.h"
  
   #define c_version
  
   #include &lt;iostream&gt;
  
      int main()
  
      {
  
  
              double ex[] = {130.7093200, 23.8088610,  6.4436083, 5.0331513,  1.1695961,  0.3803890, 3.42525091, 0.62391373, 0.16885540 };
  
              double cs[] = { 0.15432897, 0.53532814, 0.44463454,     -0.09996723, 0.39951283, 0.70011547, 0.15591627, 0.60768372, 0.39195739};
              double *cp = cs, *cd = cs, *cf = cs, *cg = cs, *ch = cs, *ci = cs;
                     .
                     .
                     .
  
                      simgms_scf_c(ex, numBFunc, numOccAlpha, 0, atomCoordinates, nuclearCharges, 0);
  
  
              return 0;
  
  }
  </code></pre>
  
  <p>(This program worked without a problem on windows/Visual Studio. I ported and changed the code to work on linux64)</p>
  
  <p>This is the noteworthy step in building the static library simgms</p>
  
  <pre><code>    %.o: ../%.cpp
      @echo 'Building file: $&lt;'
      @echo 'Invoking: G++ Compiler'
  
   g++ -Wall -mavx -g -O -O1 -std=c++11 -lgfortran  -L/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/lib64 -libstdc -libsupc++ -libtsan -libubsan -libvtv -libquadmath -libgcc_s -libgcj  -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -lmkl_mc -lmkl_sequential -lmkl_gf_ilp64 -lmkl_avx -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core  -L/home/..mypath/simint/lib -lsimint -I/opt/intel/composer_xe_2013.5.192/mkl/include  -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -I/home/..mypath/simint/include -I/home/..mypath/include/simint/debug  -DDEBUG -DMKL_ILP64 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o "$@" "$&lt;"
   @echo 'Finished building: $&lt;'
   @echo ' '
  
  %.o: ../%.c
      @echo 'Building file: $&lt;'
      @echo 'Invoking: GCC Compiler'
   gcc -Wall -mavx -g -O -O1  -lgfortran  -L/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/lib64 -libstdc -libsupc++ -libtsan -libubsan -libvtv -libquadmath -libgcc_s -libgcj  -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -lmkl_mc -lmkl_sequential -lmkl_gf_ilp64 -lmkl_avx -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core  -L/home/..mypath/simint/lib -lsimint -I/opt/intel/composer_xe_2013.5.192/mkl/include  -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -I/home/..mypath/simint/include -I/home/..mypath/include/simint/debug  -DDEBUG -DMKL_ILP64 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -c -o "$@" "$&lt;"
   @echo 'Finished building: 
   $&lt;'        @echo ' '
  </code></pre>
  
  <p>Here is how I create the main executable from main.cpp </p>
  
  <pre><code> gcc -Wall -mavx -g -O -O1 -o main -lgfortran ../main.cpp -L/home/..mypath/Debug -lsimgms -L/home/..mypath/simint -lsimint -L/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64 -lmkl_mc -lmkl_sequential -lmkl_gf_ilp64 -lmkl_avx -lmkl_lapack95_lp64 -lmkl_intel_lp64 -lmkl_core   -I/home/..mypath/simint -I/home/..mypath/include -I/opt/intel/composer_xe_2013.5.192/mkl/include  -I/opt/shared/sw/x86_64-unknown-linux-gnu/gcc/5.3.0-rhel6/include -lpthread -lm -ldl 
  </code></pre>
  
  <p>Here is the gdb trace (What I could get)</p>
  
  <pre><code> (gdb) bt main
   No stack.
   (gdb) b main
   Breakpoint 1 at 0x401906: file ../main.cpp, line 12.
   (gdb) run
   Starting program: /home/...mypah/simgms/Debug/main 
  
   Breakpoint 1, main () at ../main.cpp:12
   12              {
   (gdb) step
   15                      double ex[] = {130.7093200, 23.8088610,  6.4436083, 5.0331513,  1.1695961,  0.3803890, 3.42525091, 0.62391373, 0.16885540 };
   (gdb) step
  
   Program received signal SIGILL, Illegal instruction.
   main () at ../main.cpp:15
   15                      double ex[] = {130.7093200, 23.8088610,  6.4436083, 5.0331513,  1.1695961,  0.3803890, 3.42525091, 0.62391373, 0.16885540 };
  </code></pre>
  
  <p>Dump of assembler code</p>
  
  <pre><code>Breakpoint 1, 0x0000000000401906 in main ()
  (gdb) info line 1
  Line number 1 is out of range for "&lt;built-in&gt;".
  (gdb) disassemble /m
  
  Dump of assembler code for function main:
  =&gt; 0x0000000000401906 &lt;+0&gt;:     sub    $0x1d8,%rsp
  0x000000000040190d &lt;+7&gt;:     vmovsd 0x5b613(%rip),%xmm1        # 0x45cf28
  0x0000000000401915 &lt;+15&gt;:    vmovsd %xmm1,0x180(%rsp)
  0x000000000040191e &lt;+24&gt;:    vmovsd 0x5b60a(%rip),%xmm2        # 0x45cf30
  0x0000000000401926 &lt;+32&gt;:    vmovsd %xmm2,0x188(%rsp)
  0x000000000040192f &lt;+41&gt;:    vmovsd 0x5b601(%rip),%xmm3        # 0x45cf38
  0x0000000000401937 &lt;+49&gt;:    vmovsd %xmm3,0x190(%rsp)
  0x0000000000401940 &lt;+58&gt;:    vmovsd 0x5b5f8(%rip),%xmm4        # 0x45cf40
  0x0000000000401948 &lt;+66&gt;:    vmovsd %xmm4,0x198(%rsp)
  0x0000000000401951 &lt;+75&gt;:    vmovsd 0x5b5ef(%rip),%xmm5        # 0x45cf48
  0x0000000000401959 &lt;+83&gt;:    vmovsd %xmm5,0x1a0(%rsp)
  0x0000000000401962 &lt;+92&gt;:    vmovsd 0x5b5e6(%rip),%xmm6        # 0x45cf50
  0x000000000040196a &lt;+100&gt;:   vmovsd %xmm6,0x1a8(%rsp)
  0x0000000000401973 &lt;+109&gt;:   vmovsd 0x5b5dd(%rip),%xmm7        # 0x45cf58
  0x000000000040197b &lt;+117&gt;:   vmovsd %xmm7,0x1b0(%rsp)
  0x0000000000401984 &lt;+126&gt;:   vmovsd 0x5b5d4(%rip),%xmm1        # 0x45cf60
  0x000000000040198c &lt;+134&gt;:   vmovsd %xmm1,0x1b8(%rsp)
  0x0000000000401995 &lt;+143&gt;:   vmovsd 0x5b5cb(%rip),%xmm2        # 0x45cf68
  0x000000000040199d &lt;+151&gt;:   vmovsd %xmm2,0x1c0(%rsp)
  0x00000000004019a6 &lt;+160&gt;:   vmovsd 0x5b5c2(%rip),%xmm3        # 0x45cf70
  0x00000000004019ae &lt;+168&gt;:   vmovsd %xmm3,0x130(%rsp)
  0x00000000004019b7 &lt;+177&gt;:   vmovsd 0x5b5b9(%rip),%xmm4        # 0x45cf78
  0x00000000004019bf &lt;+185&gt;:   vmovsd %xmm4,0x138(%rsp)
  0x00000000004019c8 &lt;+194&gt;:   vmovsd 0x5b5b0(%rip),%xmm5        # 0x45cf80
  0x00000000004019d0 &lt;+202&gt;:   vmovsd %xmm5,0x140(%rsp)
  0x00000000004019d9 &lt;+211&gt;:   vmovsd 0x5b5a7(%rip),%xmm6        # 0x45cf88
  0x00000000004019e1 &lt;+219&gt;:   vmovsd %xmm6,0x148(%rsp)
  0x00000000004019ea &lt;+228&gt;:   vmovsd 0x5b59e(%rip),%xmm7        # 0x45cf90
  0x00000000004019f2 &lt;+236&gt;:   vmovsd %xmm7,0x150(%rsp)
  0x00000000004019fb &lt;+245&gt;:   vmovsd 0x5b595(%rip),%xmm1        # 0x45cf98
  0x0000000000401a03 &lt;+253&gt;:   vmovsd %xmm1,0x158(%rsp)
  0x0000000000401a0c &lt;+262&gt;:   vmovsd 0x5b58c(%rip),%xmm2        # 0x45cfa0
  0x0000000000401a14 &lt;+270&gt;:   vmovsd %xmm2,0x160(%rsp)
  0x0000000000401a1d &lt;+279&gt;:   vmovsd 0x5b583(%rip),%xmm3        # 0x45cfa8
  0x0000000000401a25 &lt;+287&gt;:   vmovsd %xmm3,0x168(%rsp)
  0x0000000000401a2e &lt;+296&gt;:   vmovsd 0x5b57a(%rip),%xmm4        # 0x45cfb0
  0x0000000000401a36 &lt;+304&gt;:   vmovsd %xmm4,0x170(%rsp)
  0x0000000000401a3f &lt;+313&gt;:   movq   $0x1,0x100(%rsp)
  0x0000000000401a4b &lt;+325&gt;:   movq   $0x1,0x108(%rsp)
  0x0000000000401a57 &lt;+337&gt;:   movq   $0x1,0x110(%rsp)
  0x0000000000401a63 &lt;+349&gt;:   movq   $0x2,0x118(%rsp)
  0x0000000000401a6f &lt;+361&gt;:   movq   $0x2,0x120(%rsp)
  0x0000000000401a7b &lt;+373&gt;:   movq   $0x2,0x128(%rsp)
  0x0000000000401a87 &lt;+385&gt;:   movq   $0x1,0xd0(%rsp)
  0x0000000000401a93 &lt;+397&gt;:   movq   $0x1,0xd8(%rsp)
  0x0000000000401a9f &lt;+409&gt;:   movq   $0x4,0xe0(%rsp)
  0x0000000000401aab &lt;+421&gt;:   movq   $0x4,0xe8(%rsp)
  0x0000000000401ab7 &lt;+433&gt;:   movq   $0x7,0xf0(%rsp)
  0x0000000000401ac3 &lt;+445&gt;:   movq   $0x7,0xf8(%rsp)
  0x0000000000401acf &lt;+457&gt;:   movq   $0x1,0xa0(%rsp)
  0x0000000000401adb &lt;+469&gt;:   movq   $0x1,0xa8(%rsp)
  0x0000000000401ae7 &lt;+481&gt;:   movq   $0x2,0xb0(%rsp)
  0x0000000000401af3 &lt;+493&gt;:   movq   $0x2,0xb8(%rsp)
  0x0000000000401aff &lt;+505&gt;:   movq   $0x1,0xc0(%rsp)
  0x0000000000401b0b &lt;+517&gt;:   movq   $0x1,0xc8(%rsp)
  0x0000000000401b17 &lt;+529&gt;:   movq   $0xd,0x70(%rsp)
  0x0000000000401b20 &lt;+538&gt;:   movq   $0x0,0x78(%rsp)
  ---Type &lt;return&gt; to continue, or q &lt;return&gt; to quit---
  0x0000000000401b29 &lt;+547&gt;:   movq   $0x0,0x80(%rsp)
  0x0000000000401b35 &lt;+559&gt;:   movq   $0x0,0x88(%rsp)
  0x0000000000401b41 &lt;+571&gt;:   movq   $0x0,0x90(%rsp)
  0x0000000000401b4d &lt;+583&gt;:   movq   $0x0,0x98(%rsp)
  0x0000000000401b59 &lt;+595&gt;:   movq   $0x3,0x40(%rsp)
  0x0000000000401b62 &lt;+604&gt;:   movq   $0x3,0x48(%rsp)
  0x0000000000401b6b &lt;+613&gt;:   movq   $0x3,0x50(%rsp)
  0x0000000000401b74 &lt;+622&gt;:   movq   $0x3,0x58(%rsp)
  0x0000000000401b7d &lt;+631&gt;:   movq   $0x3,0x60(%rsp)
  0x0000000000401b86 &lt;+640&gt;:   movq   $0x3,0x68(%rsp)
  0x0000000000401b8f &lt;+649&gt;:   vxorpd %xmm0,%xmm0,%xmm0
  0x0000000000401b93 &lt;+653&gt;:   vmovsd %xmm0,0x10(%rsp)
  0x0000000000401b99 &lt;+659&gt;:   vmovsd 0x5b417(%rip),%xmm5        # 0x45cfb8
  0x0000000000401ba1 &lt;+667&gt;:   vmovsd %xmm5,0x18(%rsp)
  0x0000000000401ba7 &lt;+673&gt;:   vmovsd %xmm0,0x20(%rsp)
  0x0000000000401bad &lt;+679&gt;:   vmovsd 0x5b40b(%rip),%xmm6        # 0x45cfc0
  0x0000000000401bb5 &lt;+687&gt;:   vmovsd %xmm6,0x28(%rsp)
  0x0000000000401bbb &lt;+693&gt;:   vmovsd 0x5b405(%rip),%xmm7        # 0x45cfc8
  0x0000000000401bc3 &lt;+701&gt;:   vmovsd %xmm7,0x30(%rsp)
  0x0000000000401bc9 &lt;+707&gt;:   vmovsd %xmm0,0x38(%rsp)
  0x0000000000401bcf &lt;+713&gt;:   vmovsd 0x5b3f9(%rip),%xmm1        # 0x45cfd0
  0x0000000000401bd7 &lt;+721&gt;:   vmovsd %xmm1,(%rsp)
  0x0000000000401bdc &lt;+726&gt;:   vmovsd 0x5b3f4(%rip),%xmm2        # 0x45cfd8
  0x0000000000401be4 &lt;+734&gt;:   vmovsd %xmm2,0x8(%rsp)
  0x0000000000401bea &lt;+740&gt;:   lea    0x130(%rsp),%rsi
  0x0000000000401bf2 &lt;+748&gt;:   push   %rsp
  0x0000000000401bf3 &lt;+749&gt;:   lea    0x18(%rsp),%rax
  0x0000000000401bf8 &lt;+754&gt;:   push   %rax
  0x0000000000401bf9 &lt;+755&gt;:   pushq  $0x0
  0x0000000000401bfb &lt;+757&gt;:   pushq  $0x4
  0x0000000000401bfd &lt;+759&gt;:   pushq  $0x6
  0x0000000000401bff &lt;+761&gt;:   pushq  $0x1
  0x0000000000401c01 &lt;+763&gt;:   pushq  $0x6
   0x0000000000401c03 &lt;+765&gt;:   lea    0xa8(%rsp),%rax
  0x0000000000401c0b &lt;+773&gt;:   push   %rax
  0x0000000000401c0c &lt;+774&gt;:   lea    0x80(%rsp),%rax
  0x0000000000401c14 &lt;+782&gt;:   push   %rax
  0x0000000000401c15 &lt;+783&gt;:   lea    0xe8(%rsp),%rax
  0x0000000000401c1d &lt;+791&gt;:   push   %rax
  0x0000000000401c1e &lt;+792&gt;:   lea    0x150(%rsp),%rax
  0x0000000000401c26 &lt;+800&gt;:   push   %rax
  0x0000000000401c27 &lt;+801&gt;:   lea    0x128(%rsp),%rax
  0x0000000000401c2f &lt;+809&gt;:   push   %rax
  0x0000000000401c30 &lt;+810&gt;:   push   %rsi
  0x0000000000401c31 &lt;+811&gt;:   push   %rsi
  0x0000000000401c32 &lt;+812&gt;:   mov    %rsi,%r9
  0x0000000000401c35 &lt;+815&gt;:   mov    %rsi,%r8
  0x0000000000401c38 &lt;+818&gt;:   mov    %rsi,%rcx
  0x0000000000401c3b &lt;+821&gt;:   mov    %rsi,%rdx
  0x0000000000401c3e &lt;+824&gt;:   lea    0x1f0(%rsp),%rdi
  0x0000000000401c46 &lt;+832&gt;:   callq  0x401caa &lt;simgms_scf_c&gt;
  0x0000000000401c4b &lt;+837&gt;:   mov    $0x0,%eax
  0x0000000000401c50 &lt;+842&gt;:   add    $0x248,%rsp
  0x0000000000401c57 &lt;+849&gt;:   retq   
  End of assembler dump.
  </code></pre>
  
  <p>(gdb) </p>
  
  <p>Assembler dump after crashing:</p>
  
  <pre><code> Program received signal SIGILL, Illegal instruction.
  0x000000000040190d in main () 
  (gdb) disassemble /m
  Dump of assembler code for function main:
      0x0000000000401906 &lt;+0&gt;:     sub    rsp,0x1d8
    =&gt; 0x000000000040190d &lt;+7&gt;:     vmovsd xmm1,QWORD PTR [rip+0x5b613]        # 0x45cf28
     0x0000000000401915 &lt;+15&gt;:    vmovsd QWORD PTR [rsp+0x180],xmm1
     0x000000000040191e &lt;+24&gt;:    vmovsd xmm2,QWORD PTR [rip+0x5b60a]        # 0x45cf30
     0x0000000000401926 &lt;+32&gt;:    vmovsd QWORD PTR [rsp+0x188],xmm2
  0x000000000040192f &lt;+41&gt;:    vmovsd xmm3,QWORD PTR [rip+0x5b601]        # 0x45cf38
  0x0000000000401937 &lt;+49&gt;:    vmovsd QWORD PTR [rsp+0x190],xmm3
  0x0000000000401940 &lt;+58&gt;:    vmovsd xmm4,QWORD PTR [rip+0x5b5f8]        # 0x45cf40
  0x0000000000401948 &lt;+66&gt;:    vmovsd QWORD PTR [rsp+0x198],xmm4
  0x0000000000401951 &lt;+75&gt;:    vmovsd xmm5,QWORD PTR [rip+0x5b5ef]        # 0x45cf48
  0x0000000000401959 &lt;+83&gt;:    vmovsd QWORD PTR [rsp+0x1a0],xmm5
  0x0000000000401962 &lt;+92&gt;:    vmovsd xmm6,QWORD PTR [rip+0x5b5e6]        # 0x45cf50
  0x000000000040196a &lt;+100&gt;:   vmovsd QWORD PTR [rsp+0x1a8],xmm6
  0x0000000000401973 &lt;+109&gt;:   vmovsd xmm7,QWORD PTR [rip+0x5b5dd]        # 0x45cf58
  0x000000000040197b &lt;+117&gt;:   vmovsd QWORD PTR [rsp+0x1b0],xmm7
  0x0000000000401984 &lt;+126&gt;:   vmovsd xmm1,QWORD PTR [rip+0x5b5d4]        # 0x45cf60
  0x000000000040198c &lt;+134&gt;:   vmovsd QWORD PTR [rsp+0x1b8],xmm1
  0x0000000000401995 &lt;+143&gt;:   vmovsd xmm2,QWORD PTR [rip+0x5b5cb]        # 0x45cf68
  0x000000000040199d &lt;+151&gt;:   vmovsd QWORD PTR [rsp+0x1c0],xmm2
  0x00000000004019a6 &lt;+160&gt;:   vmovsd xmm3,QWORD PTR [rip+0x5b5c2]        # 0x45cf70
  0x00000000004019ae &lt;+168&gt;:   vmovsd QWORD PTR [rsp+0x130],xmm3 
  0x00000000004019b7 &lt;+177&gt;:   vmovsd xmm4,QWORD PTR [rip+0x5b5b9]        # 0x45cf78
  0x00000000004019bf &lt;+185&gt;:   vmovsd QWORD PTR [rsp+0x138],xmm4
  0x00000000004019c8 &lt;+194&gt;:   vmovsd xmm5,QWORD PTR [rip+0x5b5b0]        # 0x45cf80
  0x00000000004019d0 &lt;+202&gt;:   vmovsd QWORD PTR [rsp+0x140],xmm5
  0x00000000004019d9 &lt;+211&gt;:   vmovsd xmm6,QWORD PTR [rip+0x5b5a7]        # 0x45cf88
  0x00000000004019e1 &lt;+219&gt;:   vmovsd QWORD PTR [rsp+0x148],xmm6
  0x00000000004019ea &lt;+228&gt;:   vmovsd xmm7,QWORD PTR [rip+0x5b59e]        # 0x45cf90
  0x00000000004019f2 &lt;+236&gt;:   vmovsd QWORD PTR [rsp+0x150],xmm7
  0x00000000004019fb &lt;+245&gt;:   vmovsd xmm1,QWORD PTR [rip+0x5b595]        # 0x45cf98
  0x0000000000401a03 &lt;+253&gt;:   vmovsd QWORD PTR [rsp+0x158],xmm1
  0x0000000000401a0c &lt;+262&gt;:   vmovsd xmm2,QWORD PTR [rip+0x5b58c]        # 0x45cfa0
  </code></pre>