安装32位支持后无法构建32位程序集

时间:2016-10-07 02:16:15

标签: linux gcc assembly ld gas

我正在尝试在程序集的x86_64平台上构建x86可执行文件。我知道我需要安装x86支持,所以我已经安装了库:

glibc-devel.i386
libstdc++-devel.i386

这允许我通过GCC成功构建和执行32位模式的C程序:

gcc test.c -o test -m32
./test
Hello world!

但是,我无法从汇编中组装x86程序:

$gcc -m32 template.s -o test 
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../../lib/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status

或者替代:

$as --32 template.s -o temp
$ld -melf_i386 temp -lc
ld: skipping incompatible /usr/lib64/libc.so when searching for -lc
ld: warning: cannot find entry symbol _start; defaulting to 00000000080481b0
$./a.out 
-bash: ./a.out: /usr/lib/libc.so.1: bad ELF interpreter: No such file or directory

非常感谢任何帮助。我知道我之前能够运行它,但它已经很长时间了,并且在另一台计算机上。程序template.s如下:

procedure:
        movl    4(%esp), %eax
        ret

main:
        pushl   %ebp
        movl    %esp, %ebp

        pushl   a
        call    procedure

        pushl   %eax
        pushl   $string
        call    printf

        leave
        ret

.section        .rodata
    string:
        .string "result is %d\n"

.section .data
    a:
        .long   -25

0 个答案:

没有答案