0

I have a x86_64 machine and want to compile for a machine, which has i586 arch.

I installed: libc6-dev-x32 and libc6-dev:i386

Then I tried to compile a simple hello world like this:

gcc -m32 -march=i586 -mcpu=i586 test.c -o test -static

It works on my machine but on the target I get the illegal instruction error on the CMOVE instruction. So he doesn't know CMOVE.

How can I solve this problem?

Donovaaan
  • 11
  • 5
  • 1
    If I remember correctly cmov is introduced in i686. You need to track down which part of the code is compiled with i686 assumption. – user3528438 Jan 31 '16 at 16:02
  • It is just a hello world. So what could it be there? Can't I tell gcc to not use cmove? – Donovaaan Jan 31 '16 at 16:03
  • My guess is: the libc makes use of the cmove instruction somewhere, and since you link the libc of the build system statically it is used at the target system, too. Does it help to omit `-static`? – Ctx Jan 31 '16 at 16:08
  • related: http://stackoverflow.com/q/32781281 – Robert Harvey Jan 31 '16 at 16:09
  • Another thing: My distro (debian jessie) provides a package "libc6-dev-i386", it should help to link against _that_ version of the glibc. – Ctx Jan 31 '16 at 16:10
  • If that is an i586 machine, it is not x86_**64**. Install i386 libraries and compile for that target. – too honest for this site Jan 31 '16 at 16:24
  • @Olaf the development machine is x86_64 and the target machine is i586 – M.M Jan 31 '16 at 20:12
  • @M.M: Maybe for gcc and/or the libs, i586 implies PPro, not original Pentium instruction set/arch which OP seems to need. So target would either be i486, or i386. Typically, there are either libs for new arch or i386; i486 pre-build installs are more rare. – too honest for this site Jan 31 '16 at 20:22

2 Answers2

2

You statically link against the glibc of your host system, which makes use of the CMOV*-instructions. So compiler switches won't help.

One option is to link against dietlibc:

  • Install the package dietlibc-dev:i386

  • Link against it: diet gcc -m32 -march=i586 -mcpu=i586 test.c -o test -static

Now your binary should not include the offending instructions.

Ctx
  • 18,090
  • 24
  • 36
  • 51
  • It worked fine, but after using fopen() for example I again get the illegal instruction error. What can I do? – Donovaaan Jan 31 '16 at 18:19
  • @Donovaaan It surprises me that the dietlibc-binaries use instructions which your target machine doesn't support. Can you identify which one it is? – Ctx Jan 31 '16 at 18:51
  • I made this: `objdump -D test | grep cmove` and I got this single instruction: `8048ba9: 0f 44 c3 cmove %ebx,%eax`. Is this what you mean? The code is just this: http://pastebin.com/Ar7dM3qe Thank you so much for helping! – Donovaaan Jan 31 '16 at 18:58
  • @Donovaaan Can you upload the binary somewhere? – Ctx Jan 31 '16 at 19:04
  • That's interesting... Indeed this cmove is not present in my dietlibc-binaries and is exactly what causes you trouble again here. Which version do you use? I use 0.33~cvs20120325-6 from debian jessie – Ctx Jan 31 '16 at 19:21
  • My version is: diet version 0.33~cvs20120325-6 on Ubuntu 15.10 :( – Donovaaan Jan 31 '16 at 19:23
  • You could try to install the package from debian jessie on your ubuntu, that should help – Ctx Jan 31 '16 at 19:26
  • @Donovaaan it should work to download this: http://mirror.de.leaseweb.net/debian/pool/main/d/dietlibc/dietlibc-dev_0.33~cvs20120325-6_i386.deb and install it with `dpkg -i` – Ctx Jan 31 '16 at 19:37
0

A quick check on debian / jessie, and command

objdump -D /lib32/libc-2.19.so | grep cmove

reveals that there are cmove instructions there. wikipedia mentions that they were added for pentium pro.

According to this blog

Sept. 2014 update: GCC and other dev tools are now part of the official linux image you can download from Intel Developer Zone.

there should be something available either IoT installers page or Software Downloads for Boards and Kits

Building a cross-compiler toolset could be another option.

J.J. Hakala
  • 6,136
  • 6
  • 27
  • 61