我的平台是64位红帽企业版,
源码如下,
.section .data
output:
.asciz "This is a section %d\n"
.section .text
.globl _start
_start:
call over
push $0
call exit
over:
push %ebp
movl %esp, %ebp
push $2
push $output
call printf
addl $8, %esp
movl %ebp ,%esp
pop %ebp
ret
这样编译
[[email protected] al]$ as simpleCall.S -o simpleCall.o
simpleCall.S: Assembler messages:
simpleCall.S:11: Error: suffix or operands invalid for `push'
simpleCall.S:18: Error: suffix or operands invalid for `pop'
加上 -32
[[email protected] al]$ as simpleCall.S -o simpleCall.o -32
[[email protected] al]$ ld simpleCall.o -o simpleCall -lc
ld: i386 architecture of input file `simpleCall.o' is incompatible with i386:x86-64 output
ld: final link failed: Invalid operation
通过readelf -h 可以看到编译出来的是32位格式的文件。如何正确编译并且能在64平台运行呢。
------解决方案--------------------
看来好象是你汇编生成了32位.o,但是连接默认输出64位可执行文件。你加上 -A i386 -b elf32-i386 命令行参数试试。