什么是海湾合作委员会的错误消息,"错误:不支持的`MOV'&QUOT ;,意味着什么呢? [英] What does the GCC error message, "Error: unsupported for `mov'", mean?
问题描述
我只是想编译一些简单的例子,code我从一本书上键入的,和GCC给我上面的错误。这里是我的code:
$猫-n TEST.CPP 1#定义READ_COMMAND 3
2
3#定义MSG_LENGTH 128
4
5#包括LT&;&stdlib.h中GT;
6#包括LT&;&stdio.h中GT;
7
8 INT主(INT ARGC,CHAR * ARG [])
9 {
10 INT syslog_command = READ_COMMAND;
11 INT bytes_to_read = MSG_LENGTH;
12 INT RETVAL;
13字符缓冲区[MSG_LENGTH]
14
15 ASM挥发性(
16MOVL%1 %% EBX \\ n \\ t的
17MOVL%2 %% ECX \\ n \\ t的
18MOVL%3 %% EDX \\ n \\ t的
19MOVL $ 103 %% EAX \\ n \\ t的
20INT $ 128个\\ n \\ t的
21MOVL EAX %%,%0
22:= R(RETVAL)
23:M(syslog_command),R(缓冲液),M(bytes_to_read)
24:%eax中,%EBX,%ECX,%EDX);
25,如果(RETVAL大于0)的printf(%S \\ n,缓冲区);
26
27}
28
29
在code应该调用的syslog()
系统调用从内核中读取的最后一个128字节的printk()
环形缓冲区。这里是我的操作系统和系统配置的一些信息:
的uname -a
:
的Linux 3.2.0-26泛型#41 Ubuntu的SMP周四6月14日17时49分24秒UTC 2012 x86_64的x86_64的x86_64的GNU / Linux的
块引用>
的gcc -v
:使用内置的规格。
COLLECT_GCC = GCC
COLLECT_LTO_WRAPPER = / usr / lib目录/ GCC / x86_64的-Linux的GNU / 4.6 / LTO-包装
目标:x86_64的-Linux的GNU
配置有:../src/configure -v --with-pkgversion ='的Ubuntu / Linaro的4.6.3-1ubuntu5'--with-bugurl =文件:///usr/share/doc/gcc-4.6 /README.Bugs --enable-语言= C,C ++,FORTRAN,objc,OBJ-C ++ - preFIX =的/ usr --program后缀= -4.6 --enable-共享--enable-连接的构建-id --with-系统的zlib --libexecdir = / usr / lib目录--without-包括-gettext的--enable-线程= POSIX --with-GXX-包括-DIR = / usr / include目录/ C ++ / 4.6 - -libdir = / usr / lib目录--enable-NLS --with-SYSROOT = / --enable-clocale = GNU --enable-libstdcxx调试--enable-libstdcxx时间= YES --enable-GNU-unique-对象--enable-插件--enable-objc-GC --disable-werror --with拱-32 = i686的--with调整=通用--enable-检查=发行--build = x86_64的-Linux的GNU主机= x86_64的Linux的GNU的--target = x86_64的-Linux的GNU
块引用>线程模型:POSIXgcc版本4.6.3(Ubuntu的/ Linaro的4.6.3-1ubuntu5)
继承人的完整的错误:
$ GCC TEST.CPPTEST.CPP:汇编的消息:TEST.CPP:25:错误:不支持的`MOV'
解决方案您正试图编译32位汇编code在64位机器上。内联汇编你列表编译为:
MOVL -24(RBP%),EBX%
MOVL%RSI,ECX%LT&; ---这里的错误
MOVL -28(RBP%),EDX%
MOVL $ 103%EAX
诠释$ 128个
MOVL%eax中,%r12d如你所见,你试图存储一个64位寄存器的32位寄存器,这是违法的。更重要的是,这不是64位ABI系统调用协议无论是。
试着用
-m32
编译迫使32位ABI。I am just trying to compile some simple example code I typed in from a book, and GCC gives me the above error. Here's my code:
$ cat -n test.cpp 1 #define READ_COMMAND 3 2 3 #define MSG_LENGTH 128 4 5 #include <stdlib.h> 6 #include <stdio.h> 7 8 int main(int argc, char *arg[]) 9 { 10 int syslog_command = READ_COMMAND; 11 int bytes_to_read = MSG_LENGTH; 12 int retval; 13 char buffer[MSG_LENGTH]; 14 15 asm volatile( 16 "movl %1, %%ebx\n\t" 17 "movl %2, %%ecx\n\t" 18 "movl %3, %%edx\n\t" 19 "movl $103, %%eax\n\t" 20 "int $128\n\t" 21 "movl %%eax, %0" 22 :"=r" (retval) 23 :"m"(syslog_command),"r"(buffer),"m"(bytes_to_read) 24 :"%eax","%ebx","%ecx","%edx"); 25 if (retval > 0) printf("%s\n", buffer); 26 27 } 28 29
The code is supposed to invoke the
syslog()
system call to read the last 128 bytes from the kernelprintk()
ring buffer. Here is some information about my OS and system configuration:
uname -a
:Linux 3.2.0-26-generic #41-Ubuntu SMP Thu Jun 14 17:49:24 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
gcc -v
:Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
Heres the full error:
$ gcc test.cpp test.cpp: Assembler messages: test.cpp:25: Error: unsupported for `mov'
解决方案You are attempting to compile 32-bit assembly code on a 64-bit machine. The inline assembly you list compiles to:
movl -24(%rbp), %ebx movl %rsi, %ecx <--- error here movl -28(%rbp), %edx movl $103, %eax int $128 movl %eax, %r12d
As you can see, you're attempting to store a 64-bit register in a 32-bit register, which is illegal. More importantly, this isn't the 64-bit ABI system call protocol either.
Try compiling with
-m32
to force 32-bit ABI.这篇关于什么是海湾合作委员会的错误消息,&QUOT;错误:不支持的`MOV'&QUOT ;,意味着什么呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!