-1

I'm compiling a program on Ubuntu 14.04.3. I then copy it to an Amazon AWS server running Ubuntu 14.04.2. Yet it instantly crashes with Illegal Instruction (it works on the source machine) with the following stacktrace from gdb:

Program received signal SIGILL, Illegal instruction.
...
(gdb) bt
#0  0x000000000093716b in std::vector<int, std::allocator<int> >::_M_fill_insert(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, unsigned long, int const&) ()
#1  0x0000000000706581 in _GLOBAL__sub_I__ZN5abcdf6kfjg446zcadetERKSs ()
#2  0x0000000000b2abad in __libc_csu_init ()
#3  0x00007ffff7106e55 in __libc_start_main (main=0x6fa390 <main>, argc=2, argv=0x7fffffffe668,
    init=0xb2ab60 <__libc_csu_init>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe658)
    at libc-start.c:246
#4  0x0000000000708437 in _start ()

What gives? It appears they are using the same versions of libc.

tkausl
  • 13,686
  • 2
  • 33
  • 50
Claudiu
  • 224,032
  • 165
  • 485
  • 680

1 Answers1

1

Because I am you, I was able to check your compiler flags and found the following among them:

-march=native

As per this answer:

If you use -march then GCC will be free to generate instructions that work on the specified CPU, but not on (typically) earlier CPUs in the architecture family.

I went ahead and recompiled your program without -march=native and it ran on the Amazon server without a hitch. I am not sure why this ever worked before - perhaps because you switched from VirtualBox to VMWare, which upgraded the local VM's processor capabilities beyond that of the Amazon server's, which caused -march=native to start generating incompatible code.

Continuing with that answer, you can alternatively try -mtune for a safe way to optimize the program:

If you use -mtune, then the compiler will generate code that works on any of them, but will favour instruction sequences that run fastest on the specific CPU you indicated.

Community
  • 1
  • 1
Claudiu
  • 224,032
  • 165
  • 485
  • 680
  • 2
    "Because I am you" :) I first though you were sarcastic and implicitly suggesting to OP that his question was incomplete, forcing you to guess things. – YSC Dec 29 '15 at 15:24
  • Yesterday during my excersise on the threadmill, the threadmill abruptly stopped. What happened? Answer - static from my pants discharged on the mill and caused it to reboot (true story, btw). Now I want your upvotes for the very useful insight! – SergeyA Dec 29 '15 at 15:28
  • 1
    @SergeyA: Hah funny story actually :). I realize the question doesn't stand on its own but I think the question + answer pair could be helpful to someone else in the future. Imagine someone (like my past self) googles "illegal instruction" and comes across this page. No upvotes required. – Claudiu Dec 29 '15 at 17:52