Search code examples
linuxcompilationinstallationlinkerglibc

Why an installed Centos system uses ld.2.17, yet compiling the same version of glibc-2.17 produces ld.so


I am confused on the relationship between ld.so and ld-2.17.so. Specifically, why is /lib64/ld-linux-x86-64.so.2 linked to ld-2.17.so in a fresh installed version, and then if I build the same version of glibc (2.17) the resulting build directory shows a different linked file? I have not installed any of the new glib 2.17 executables, only built them in the prescribed glibc-build diirectory.

This is a fresh install of Centos 7.6 from the current downloadable media available at one of the centos.org mirrors.

$ uname -a
Linux localhost.localdomain 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

The glibc version is

$ ldd --version

ldd (GNU libc) 2.17
Copyright (C) 2012 Free Software Foundation, Inc.

And the installed linkers that I am aware of.

$ ls -lt /lib64/ld*

lrwxrwxrwx. 1 root root     10 Sep 15 17:43 /lib64/ld-linux-x86-64.so.2 -> ld-2.17.so
-rwxr-xr-x. 1 root root 163400 Oct 30  2018 /lib64/ld-2.17.so

After downloading glibc-2.17.tar.gz, unpacking, creating the glibc-build directory and running configure, all of which appeared to have worked properly, I can see the following -

$ ls -lt ~build-glibc/elf/ld*

lrwxrwxrwx. 1 root root       5 Sep 16 07:25 ld-linux-x86-64.so.2 -> ld.so
-rwxr-xr-x. 1 root root  850208 Sep 16 07:25 ld.so

ld.so and ld-2.17.so are both linked to ld-linux-x86-64.so.2 but are much different size. They seem to both be of type "ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked,". If they serve the same purpose (which I don't know that they do) why is there a name and size discrepency?

My goal is to add a few printk statements to ~/elf/rtld.c in order to better understand what it does and copy the resulting executable, which I think would be ~/elf/ld.so since they live in the same directory, into the lib64 directory. I have no idea if this will work or not but I would like to understand if ld.so and ld-2.17.so are somehow interchangeable before going further. Or maybe I am looking at a completely incorrect resulting executable for changes made to rtld.c?


Solution

  • I've learned that ld.so is the result of "make", and ld-2.17.so is the result of "make install". This seems to have been proven by setting a test directory before configuring and making the new glibc-2.17.

    From the glibc-build directory -

    ../glibc-2.17/configure --prefix ~/glibc-build/test
    make
    make install
    

    and finding ld-2.17.so in test/lib.

    I am still unsure of why the difference in size or why the new ld-2.17.so core dumps during boot, or how/if one can install a new ld-2.17.so in /lib64, but those are separate questions.