Invalid Operand for Code W

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.


Share this content on:

Facebooktwittergoogle_plusredditpinterestlinkedinmailFacebooktwittergoogle_plusredditpinterestlinkedinmail

3 comments

Leave a Reply

Your email address will not be published. Required fields are marked *