-1

I appreciate this might be a really dumb question. Is there a name for the process in which machine code gets laid out in an ELF file or Mach-O file?

I’d like to know more about that process, but I’m unsure what to search for.

‘Linking’ seems to be the wrong word because building object files happens before that.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Rol
  • 501
  • 4
  • 13
  • the object is just a container for bytes as is the final binary and that binary can be stored in multiple different incompatible formats yet contain the same relevant information. linking takes objects in some form of container file and links them together into something ideally useful and saves them in some form of container file. – old_timer Apr 10 '21 at 02:05
  • I would call it "saving the data to a file" – old_timer Apr 10 '21 at 02:06

1 Answers1

1

Are you talking about starting with a flat binary file and using objcopy to create a .o with that code as the .text section? I'm not aware of a standard term for that, so pick something descriptive like "wrapping it in object-file metadata".

If you mean starting with asm source, then that's just part of assembling. So if you want to be specific, you'd say "assembling into an object file", instead of "assemble into a flat binary".

In fact, assembling into a flat binary basically involves linking if the machine code references any absolute addresses (like mov edi, symbol in NASM syntax, for nasm -fbin). Instead of just creating relocation entries for symbols, the assembler has to choose an absolute address as a reference point to figure out the absolute address of every label in the file. That's normally the linker's job.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Yes. I’m talking about the former. I actually didn’t know about Linux’s object copy, and I was wondering if there was a standard way of “wrapping in object-file metadata” across UNIX OSes – Rol Apr 09 '21 at 23:32
  • @Rol: GNU binutils is portable to most Unixes, so that would be one of the standard ways. – Peter Cordes Apr 09 '21 at 23:33
  • Does GNU binutils have backends for MachO? – Rol Apr 09 '21 at 23:34
  • @Rol: Oh right, maybe not, forgot about that modern Unix! But hopefully `llvm-objcopy` does. – Peter Cordes Apr 09 '21 at 23:38
  • even within the unix world but the operating system authors get to choose or invent whatever file format they want, and then need to figure a way to create that binary. Even if many use elf that doesnt make it a standard. Wondering what the real question here is... – old_timer Apr 10 '21 at 02:03