Invalid Operand for Code W

Part of a series of articles on Unstumping the Internet.


Published 14 August 2009, last modified 15 August 2009.

Question

What does it mean when I encounter the compiler error “invalid operand for code w”?

Answer

Chances are, if you got this error then you were cross-compiling, probably from an x86 or x86_64 host to an ARM target. The error most likely occurred when you used, directly or indirectly, a network byte order translation function from the C library like htons(), or ntohl().

This error occurs because the program that you are trying to compile is including headers from the host system, rather than from the cross-compiled target environment. You should check the configure script and makefiles for the program to make sure that they do not contain hard-coded references to /usr/include or any other include paths, and also that they do not rely on the --prefix option to the configure script for setting include paths. Often, the --prefix argument is given not as an absolute path but relative to root, which will eventually be the target root during installation, but during compilation it will continue to refer to the host root.

The reason you get such a strange error is because the network byte order translation functions in GCC are aliases for the __bswap_* functions in bits/byteswap.h. These are implemented as preprocessor macros that contain inline assembly. Unless you also happen to be compiling on an ARM system, this is not going to be ARM assembly. The compiler is trying to parse the rorw (“rotate word right”) x86 instruction as the ror (“rotate right”) ARM instruction, and is becoming very confused when it encounters the unexpected w.



2 Comments »

  1. Thank you! Wasted a lot of time on this…

    Comment by Ioana — 20 June 2012 @ 06:18

  2. Thank you for your valuable article

    Comment by Niranja Arjuna — 19 December 2012 @ 00:52

RSS feed for comments on this post. TrackBack URL

Leave a comment