Force GNU linker to generate 32 bit ELF executables

戏子无情 提交于 2020-01-10 09:35:15

问题


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).

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 <some-option?> mult.o -o mult

Any help would be great.


回答1:


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

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.



来源:https://stackoverflow.com/questions/16004206/force-gnu-linker-to-generate-32-bit-elf-executables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!