【问题标题】:How can I use Gas ('as') to assemble a 32 bit binary on a 64 bit linux?如何使用 Gas ('as') 在 64 位 linux 上组装 32 位二进制文​​件?
【发布时间】:2011-12-17 03:56:18
【问题描述】:

如何在 64 位 Linux 上使用 Gas ('as') 将源代码组装成 32 位二进制文​​件?

这是为了学习 32 位教程,而无需将所有指针和大量指令更改为四字。

谢谢,

克里斯。

附:我可以在 C 中轻松做到这一点...

chris@chris-linux-desktop:~$ cat test.c
#include "stdio.h"

int main() {
    printf("hello world");
    return 0;
}

chris@chris-linux-desktop:~$ gcc test.c -o test64
chris@chris-linux-desktop:~$ gcc -m32 test.c -o test32
chris@chris-linux-desktop:~$ file test32
test32: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
chris@chris-linux-desktop:~$ file test64
test64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped

【问题讨论】:

  • --32 或将-m32 与 gcc 一起使用

标签: assembly 32bit-64bit


【解决方案1】:

as 与选项“--32”一起使用,例如

as --32 source.s -o objectfile

或者你可以只使用 gcc 来组装和链接一个汇编源文件。 gcc 通过结尾识别它。

gcc -m32 source.s -o executable

【讨论】:

  • 谢谢,我失明了——它在手册页中...目标 i386 选项:[--32|--64] [-n] [-march=CPU[+EXTENSION. ..]] [-mtune=CPU]
【解决方案2】:

您可能还需要使用链接器-m 选项来链接文件,以便为不同的目标架构设置仿真。 ld --help 给出了可能的仿真值列表。

ld -m elf_i386 -o file file.o file2.o ...etc

【讨论】:

    猜你喜欢
    • 2010-11-19
    • 2020-07-06
    • 2011-09-08
    相关资源
    最近更新 更多