I am looking into assembler and I am trying to understand the whole compilation process.

During the linking step I use:

ld -m elf_i386 -s -o hello hello.o

Everything works fine, but I do not understand what the -m parameter does.

In the manual it says:

Emulate the emulation linker.

And here it says:

A linker emulation is a "personality" of the linker, which gives the linker default values for the other aspects of the target system.

On the Wikipedia article for the Linker it doesn't even mention the word 'emulation'.

What is the 'emulation', how does it influence the linker and what do I have to keep in mind when selecting the emulation?

  • 1
    Downvoter, what do you think is lacking in the question? What can I add? Commented Jun 28, 2018 at 11:13
  • The manpage is admittedly awful, but is seems like the linked GNU ld doc answers your question. What don't you understand about it?
    – Useless
    Commented Jun 28, 2018 at 12:16
  • 1
    I am trying to find out what the emulation is and how I can know when to use which. other aspects of the target system What system (I guess OS?) and what information? Sample values: hp300bsd', mipslit', sun4'.` When do I use which, and how do I find out which to use? Commented Jun 28, 2018 at 13:22
  • 1
    There's no reason to use anything other than the default unless you're cross-compiling or targetting a non-default linker format on your host platform. If you're doing either, you already know what you need. If you're not, just stick with the default.
    – Useless
    Commented Jun 28, 2018 at 15:26
  • @Useless your comment is a basically a polite way of trying to stifle curiosity Commented Mar 8, 2021 at 17:59

1 Answer 1


Compilers have a compile target that determines what architecture's object code will be produced. Way back in the dark ages, development toolchains were a one-architecture-per-compiler-binary affair, where the compiler and linker produced one kind of result. That changed when GCC was restructured so an installation on one architecture could cross-compile to any other that was supported. GCC adopted the -m (for machine) switch to specify this parameter.

Being part of the same toolchain, the same switch was carried to the linker. Instead of determining machine architecture, -m determines what executable format (among other things) will be produced from the objects and libraries being linked. While the world was making the transition from COFF to ELF, it wasn't unusual to need to link into one or the other without having to build a separate machine to do it. Normally, you set several switches to make the linker produce a file for a given system; since -m in GNU ld serves approximately the same purpose as in GCC, that's why it was used.

Machine architecture isn't the right term since executable formats aren't necessarily machine-architecture-specific. If I had to take a guess at how the documentation got where it did, it would be that someone noticed this, tried to backfit something that began with M, couldn't find anything that would work and decided to go with eMulation.

  • It's possible that GNU ld is specified in terms of emulating the native linker on non-GNU *NIX platforms.
    – Useless
    Commented Jun 28, 2018 at 15:32
  • 1
    @Useless In the pre-GNU ld days, you used whatever linker your platform provided. Those were rarely, if ever, capable of linking to anything other than native and wouldn't have had a switch like that. GCC was what brought cross compilation as standard equipment into the mainstream.
    – Blrfl
    Commented Jun 28, 2018 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.