强制GNU链接器生成32位ELF可执行文件 [英] Force GNU linker to generate 32 bit ELF executables

查看:243
本文介绍了强制GNU链接器生成32位ELF可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我目前正在为我正在编写的编译器生成x86程序集,并且在链接我的64位VM(程序集代码为32位)上的文件时遇到一些麻烦.

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

但我似乎找不到ld的任何选项来使其生成32位ELF文件:

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

任何帮助都会很棒.

推荐答案

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

示例输出:

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

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

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

这篇关于强制GNU链接器生成32位ELF可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆