Frage

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?

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
scroll top