Author Topic: Any good, complete explanation of what's required to build an elf object file?  (Read 14815 times)

Offline dogman

  • Jr. Member
  • *
  • Posts: 51
Since you guys obviously know how to do this, is this something you figured out in bits and pieces by looking at dumps and Linux source code or is there a place where this is all documented in a cookbook fashion? I have found the elf structures in Linux and some online pages that talk about what's in them but no coherent discussion of how an object file is constructed and what has to be there or why.

Another question is do I understand correctly that all elf object offsets begin at zero and the linker/loader resolves these and adjusts them to correct storage locations at some later time?

Thanks.

Joe

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
I assume you've got the ELF specification, or can find it if you want to. As a "cookbook"... perhaps the Nasm source code, or Fasm source code if you'd prefer to see it in assembly language. There's a macro set in the "asmutils" package from http://asm.sourceforge.net that creates an ELF executable in Nasm's "-f bin" format, but that may be more "minimalist" than what you're looking for.

I think you're correct that offsets start from zero in the linkable object file, but are fixed to their load address (0x8048000)  by the linker. I don't think the loader changes it. I think shared objects (like .dll's) are loaded by sys_mmap, which seems to start at 0x40000000 and work upwards. Since an .so wouldn't know in what order it was loaded, they have to be position independent code. There are some "structures" (I guess you'd call 'em) that help with this. You can read more about it in the Nasm Manual than I understand. :)

Best,
Frank


Offline dogman

  • Jr. Member
  • *
  • Posts: 51
Thanks, I have various versions of elf spec and a bunch of other bits and pieces. One odd thing about open source is that there still seems to be a lot of knowledge that only gets into code and not documented very well otherwise. I'm no good with C or x86 asm so I'm not sure looking at assemblers is going to help. Unless I find anything obvious I'll just try to compare the object file output from various test programs with the elf specs. I guess that's probably how everybody else figured stuff out.