强制GNU链接器生成32位精灵可执行文件

时间:2022-02-09 03:05:56

Hi I am currently generating x86 assembly for a compiler that I am writing and am having some trouble linking the file on my 64-bit VM (the assembly code is 32 bit).

你好,我正在为我正在编写的编译器生成x86程序集,并且在将文件链接到我的64位VM(程序集代码是32位)时遇到了一些麻烦。

I was able to assemble the object file fine with this command:

我可以用以下命令很好地组装对象文件:

as --32 mult.S -o mult.o

but I can't seem to find any options for ld that make it generate a 32-bit ELF file:

但是我似乎找不到任何选项可以让ld生成一个32位的ELF文件:

ld <some-option?> mult.o -o mult

Any help would be great.

任何帮助都是好的。

1 个解决方案

#1


19  

ld <some-option?> mult.o -o mult

ld <一些期权?> 相乘。o - o相乘

ld -m elf_i386 mult.o -o mult

You can get a list of available architectures with:

您可以通过以下方式获得可用体系结构列表:

ld -V

Sample output:

样例输出:

GNU ld (GNU Binutils for Ubuntu) 2.24
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe

However, that shouldn't be necessary: ld looks at the first object, and should automatically select emulation based on the format of that object.

但是,这不应该是必需的:ld查看第一个对象,并且应该根据该对象的格式自动选择仿真。

#1


19  

ld <some-option?> mult.o -o mult

ld <一些期权?> 相乘。o - o相乘

ld -m elf_i386 mult.o -o mult

You can get a list of available architectures with:

您可以通过以下方式获得可用体系结构列表:

ld -V

Sample output:

样例输出:

GNU ld (GNU Binutils for Ubuntu) 2.24
  Supported emulations:
   elf_x86_64
   elf32_x86_64
   elf_i386
   i386linux
   elf_l1om
   elf_k1om
   i386pep
   i386pe

However, that shouldn't be necessary: ld looks at the first object, and should automatically select emulation based on the format of that object.

但是,这不应该是必需的:ld查看第一个对象,并且应该根据该对象的格式自动选择仿真。