ld failed because libselinux has undefined reference to gettid@GLIBC_2.30

1.6k views Asked by At

I'm trying to build glibc 2.24 from source. The host OS is WSL Ubuntu 20.04, the compiler is gcc 9.

The ld utility failed when trying to link the nss module of glibc:

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libselinux.so: undefined reference to `gettid@GLIBC_2.30'
collect2: error: ld returned 1 exit status

Seems like libselinux.so contains an undefined symbol gettid@GLIBC_2.30. I examined libselinux.so and found it does:

$ readelf -Ws /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libselinux.so | grep gettid
    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND gettid@GLIBC_2.30 (4)

Since libselinux.so is loaded by ld, I further checked the dependency of ld:

$ ldd /usr/bin/ld
        linux-vdso.so.1 (0x00007fffd365c000)
        libbfd-2.34-system.so => /lib/x86_64-linux-gnu/libbfd-2.34-system.so (0x00007f144c410000)
        libctf.so.0 => /lib/x86_64-linux-gnu/libctf.so.0 (0x00007f144c3f0000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f144c3e0000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f144c1e0000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f144c1c0000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f144c713000)

I found libc.so.6 will be loaded when ld is loaded. But when I further check the symbols defined in libc.so.6, I found gettid@GLIBC_2.30 has already been defined:

$ readelf -Ws /lib/x86_64-linux-gnu/libc.so.6 | grep gettid
  1329: 00000000001231c0    12 FUNC    WEAK   DEFAULT   16 gettid@@GLIBC_2.30

I'm really confused. Why is the undefined reference problem appears? And how should I solve it?

3

There are 3 answers

0
Absoler On

I met the same problem, and I found this patch seems cause this problem, they add a wrapper of gettid

0
Y.Z On

There is an additional @ between:

jonasson@linux:/usr/lib/x86_64-linux-gnu$ readelf -Ws /lib/x86_64-linux-gnu/libc.so.6 | grep gettid
  1332: 0000000000120060    12 FUNC    WEAK   DEFAULT   15 gettid@@GLIBC_2.30

jonasson@linux:/usr/lib/x86_64-linux-gnu$ readelf -Ws /lib/x86_64-linux-gnu/libselinux.so.1 | grep gettid
    13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND gettid@GLIBC_2.30 (4)`
0
yflelion On

The fact that you found libc.so.6 loaded by ld means ld will use functions from this library but don't mean that it will link against it.

If you want ld to link againt this library you have to add -Lpath and -lc. But normally if you link with gcc it will link against libc automatically.