How dynamic linker works?

michael_quinlivan_at_hotmail.com
Date: 09/22/05

  • Next message: John Reiser: "Re: How dynamic linker works?"
    Date: 22 Sep 2005 06:08:12 -0700
    
    

    Hi all

    I am trying to get an understanding of the loading and dynamic linking
    process to create my own loader and linker for an OS that I'm writing,
    so that it can run Linux binaries.

    I have read the ELF spec, and have a fairly good understanding of each
    component of an executable and shared object image, except for the
    processes involved in relocation, and how the PLT and GOT work. The
    following is my knowledge on the subject and the questions I have. Any
    info you may have on this or pointers to documentation would be
    helpful.

    1. Linux creates a new process address space and maps the executable
    into memory, according to the segments describes in the program header
    table

    2. It reads the PT-INTERP section, and determines that the dynamic
    linker is required. This is ld-linux.so.* or whatever...

    3. Linux loads ld-linux.so into the processes address space.

    4. Linker is initialised by calling its INIT section (???)

    5. Linkers entry point is called. I assume the entry point is found in
    the ELF header like executables are?? The code will now
    perform the other .so file loads and relocations associated with the
    process. I assum ld-linux initialised itself and performed its own
    relocations during init.

    How does ld-linux know where the executable is mapped? Does Linux pass
    a pointer with this information on the stack to ld-linux???

    Anyway, my biggest question is how are relocations performed? I think
    I understand the PLT and how it acts as a table of jumps staright into
    the linkers fixup routine, which will then modify the PLt so that it
    points to the correct instruction the second time. It is mostly the
    variety of different relocation types that gets me confused, especially
    in regards to the GOT. What do they mean and how are they fixed up.

    Also, not too sure how the hash table works

    Diagrams, examples, algorithms would be helpful as well, or even
    pointers to the most important source code in the glibc library. I
    have looked in the /elf subdir but there are so many files I dont know
    where to start.

    thanks all

    MQ


  • Next message: John Reiser: "Re: How dynamic linker works?"

    Relevant Pages

    • How a linker works (continued)
      ... Some people insisted that I was generalizing too much and there could be C implementations without object files and C implementations that do not link files in separate compilation but just parse and digest each module, making the whole code generation step in the linker, from an unknown representation. ... Here I am speaking about the very common where the compiler produces traditional object files, ... and two types of relocations for the debug information, ...
      (comp.lang.c)
    • Re: Linux Executable with TASM
      ... TASM emits OBJ object files. ... Linux uses ELF executables. ... You need a linker that can read OBJ object files and output ...
      (comp.lang.asm.x86)
    • Compile and gone! (Was: Re: VMS>7.3 Linker Manual - I64 Short Data restriction)
      ... When could one expect to see a new version of the Linker Utility ... the compiler requested address constants. ... relocations that would let the linker fill in the 64-bit literal of a ... time relocations especially for shareable images built that way! ...
      (comp.os.vms)
    • Re: Programs compiled with Intels ASM86 wont run under DOS operating system
      ... >>difference in the function between Intel's linker and other linker? ... The Microsoft .obj format is a mutilated subset of the ... original Intel iAPX86 Relocatable Object File Format. ... there must be no segment relocations left in the .exe ...
      (comp.arch.embedded)
    • RE: Compile and gone! (Was: Re: VMS>7.3 Linker Manual - I64 Short Data restriction)
      ... Don't know what happened between 8.1 and 8.3 with the Linker or whether ... the compiler requested address constants. ... This form of the 'add' instruction ... relocations that would let the linker fill in the 64-bit literal of a ...
      (comp.os.vms)