3

I was reading this on SO when I actually started to wonder how the linker resolved especially adresses of symbols in an object file and how it would be organized inside the executable file outputted by the linker.

  • How are variable and function references handled by the linker & compiler as well as by the program itself during run time? Is there an overhead created in the executable file (which maybe could also be manipulated)?

Please feel free to answer with the use of technical vocabulary (that I could look up) if that shortens the answer...


I'm asking with the intent to better understand how an executable file looks like (I already know that it does not consist only of machine code and data.)
Community
  • 1
  • 1
xQuare
  • 1,293
  • 1
  • 12
  • 21
  • 5
    I don't think this set of questions fits into something that can be answered properly. You should research how linkers work if you are really interested, but the basic idea is simple: the compiler leaves references to symbols, the linker finds the symbols and replaces the references with the addresses. Now getting from that high level view into the correct details would take too long. – David Rodríguez - dribeas Sep 18 '13 at 13:33
  • I wouldn't mind the use of technical vocabulary if that would shorten the answer (because then I would know what to search for). But I posted the question already, I will leave it as it is for the time beeing and do as you said. – xQuare Sep 18 '13 at 13:37
  • @DavidRodríguez-dribeas If you already know a good source that explains the workings of a linker (book/internet), would you mind telling me? – xQuare Sep 18 '13 at 13:51
  • I don't have a good reference to provide to you. Sorry. – David Rodríguez - dribeas Sep 18 '13 at 16:12
  • 1
    While the compiler parses your code, it has some information about the variables and functions it sees (name, type, ...). For some variables/functions this information is no longer needed after the compile phase; for others (either because it's not defined in the current translation unit, or because it is visible to other translation units) this information is emitted into a section in the object file: the symbol table. – ninjalj Sep 19 '13 at 08:39
  • 1
    Values of undefined variables/functions are emitted as dummy values (0/-1), either inline in the code or indirectly in a special table (in ELF the GOT, which is a table of function pointers filled at runtime) for functions in shared libraries, and relocation entries (which contain offset of the unresolved reference, relocation type, and symbol) are emitted in special relocation tables. There are also symbol-less relocations for relocations in the same object file, to be able to load the code at different addresses. – ninjalj Sep 19 '13 at 09:03
  • If you won't comment on your downvote, then don't bother giving one, geez. Am I supposed to respell my point/question again or are you telling me that this question is not fit for SO? – xQuare Sep 19 '13 at 10:26
  • Say guys, is this question still too broad? I don't think so. I can't answer my own question (after researching) if this won't be reopened. If this question is not fit for SO then please provide some direction. :/ – xQuare Sep 20 '13 at 20:13

1 Answers1

0

http://netwinder.osuosl.org/users/p/patb/public_html/elf_relocs.html Above article is going to be very helpful to answer your questions regarding to dynamic link and reloc

  • Granted, the question isn't very specific, but posting a link doesn't really answer the question. What happens if that article becomes unavailable? – adamdunson Sep 18 '13 at 17:00