Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
899 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...