2

I am building using the regular cabal build on my local machine, and the binary works fine. But when I copy the binary to another server for tests (same architecture : x86_64 and same glic and so on, as afar as I can tell) I get illegal instruction when I try to run it.

Is there some flag I should pass to cabal to make it compile a more generic binary maybe ?

Thanks

Ulrar
  • 895
  • 8
  • 17
  • Could you provide full error logs? – duyue Apr 18 '19 at 08:44
  • illegal instruction is the full error log, it's not a compile time error – Ulrar Apr 18 '19 at 08:54
  • 1
    It looks as if the compiler used some CPU instruction which is available on your first machine but not the other one. If those are linux, you could compare `cat /proc/cpuinfo` and observe that some flags are different, pointing to some missing instruction. Also try `file yourExecutable` to confirm it's really a `ELF 64-bit LSB executable, x86-64`. I don't know how to create a more generic binary, however. Maybe you need some llvm flags (if ghc is going through llvm). – chi Apr 18 '19 at 10:02
  • Yes, my local cpu is much more recent than the server's one. I did check with file that the binary is a regular 64 bit executable, it is, I just have no idea how to tell cabal build to use -march=generic -mtune=generic basically, as I would do in C – Ulrar Apr 18 '19 at 10:40
  • You would need to build GHC compiler and library for the target environment. There is a fair amount of information if you search for "cross-compiling Haskell". – Bob Dalgleish Apr 18 '19 at 13:37
  • Can you try to locate the illegal instruction? You can use [this procedure](https://stackoverflow.com/a/40223712/5684257), maybe. – HTNW Apr 18 '19 at 15:55

1 Answers1

0

Unlike with GCC, the GHC compiler has only a handful of options to tune instruction sets, and they're all off by default. The complete list is:

-msse -msse2 -msse3 -msse4 -msse4.2 -mbmi -mbmi2 -mavx -mavx2
-mavx512cd -mavx512er -mavx512f -mavx512pf

but there's no corresponding -mno-sse or similar options to turn them off because, like I say, they're off by default. (Well, actually, on the x86_64 architecture, the -msse and -msse2 flags are technically forced on and can't be disabled.)

So, the problem is probably something else, most likely an incompatible or corrupt library. It might be helpful to run under gdb to get a backtrace and see if you can spot a suspicious library or other obvious cause.

K. A. Buhr
  • 45,621
  • 3
  • 45
  • 71