[uClibc]Understanding the dynamic linking process for MIPS...

Steven J. Hill sjhill at cotw.com
Thu Mar 14 20:53:54 UTC 2002


I have been pulling my hair out trying to get the MIPS dynamic
linker going. Hopefully some people can clarify a few things for
me and make sure I am on the right track.

The main file for the uClibc dynamic linker is 'ldso/ldso/ldso.c'
which corresponds with the file 'elf/rtld.c' in glibc. Also, the
function DL_BOOT which is the entry point of the uClibc dynamic
linker, corresponds with the entry point '_dl_start'. Furthermore,
the file function '_dl_get_ready_to_run' in uClibc is almost
equivalent with the function '_dl_start_final' in glibc. Hopefully
my correlations are correct.

Given the above information, if you look in 'rtld.c' of glibc, you
will notice in the function '_dl_start' that this code:

    #ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
       ELF_MACHINE_BEFORE_RTLD_RELOC (bootstrap_map.l_info);
    #endif

MIPS and IA64 are the only architectures that have this function.
In my case (MIPS), the code does some work on the GOT for the
dynamic linker (ldso) before calling ELF_DYNAMIC_RELOCATE to
relocate the linker code in glibc. In the case of uClibc, it
would appear that once the GOT is found in 'DL_BOOT', that the
relocation is done in an architecture indepedent way inside the
'DL_BOOT' function. Am I correct?

Second, the macro function 'INIT_GOT' for uClibc should contain
code to initialize a GOT for an application being started up. This
is never used when bootstrapping the dynamic linker itself, right?
In the glibc code, 'sysdeps/mips/dl-machine.h' there is a function
'elf_machine_got_rel'. This code should be cut and pasted into the
INIT_GOT function if I understand things correctly.

Finally, according to my understanding of the code, this is how
the mapping of functions from glibc to the uClibc architecture
should work:
                    GLIBC                          uClibc
          -------------------------   --------------------------------
    FILE: sysdeps/mips/dl-machine.h   ld_sysdeps.h
FUNCTION: elf_machine_got_rel         INIT_GOT

    FILE: sysdeps/mips/dl-machine.h   elfinterp.c
FUNCTION: __dl_runtime_resolve        _dl_linux_resolver

    FILE: sysdeps/mips/dl-machine.h   elfinterp.c
FUNCTION: elf_machine_rel             _dl_parse_relocation_information

    FILE: sysdeps/mips/dl-machine.h   boot1_arch.h
FUNCTION: RTLD_START                  _dl_boot

This should be pretty close to being correct. Please set me straight
if any of the above sounds unreasonable. Thanks.

-Steve

-- 
 Steven J. Hill - Embedded SW Engineer



More information about the uClibc mailing list