1

Context: I am currently debugging an issue where the binaries generated in one machine (liked with lpthread) causes pthread related bugs when tried in another machine.

libtest.so is a shared library which seems to contain multiple versions of GLIBC_ . Is that expected ?. How it happens ? It was linked using "-shared -lpthread -fPIC -soname=xxxx" option.

$objdump -T libtest.so | grep GLIBC_

... 
00000000      DF *UND*  0000008d  GLIBC_2.1   popen
...
00000000      DF *UND*  0000002c  GLIBC_2.0   syslog
00000000      DF *UND*  00000020  GLIBC_2.0   pthread_exit
00000000      DF *UND*  0000009f  GLIBC_2.0   __xstat
00000000      DF *UND*  000000bb  GLIBC_2.3.2 pthread_cond_signal
00000000      DF *UND*  000000c9  GLIBC_2.0   vsprintf
...
Lunar Mushrooms
  • 8,358
  • 18
  • 66
  • 88

2 Answers2

4

Each symbol has its own history.

When a symbol hasn't be modified (signature, behavor) it keeps the default version eg. GLIBC_2.0. Symbols modified are attributed the current version of the library at that time, for example popen() behavor was modified in GLIBC_2.1, pthread_cond_signal() was modified in GLIBC_2.3.2.

Your program get linked with the latest version of each symbol. The version is recorded, and if you run your program against a newer GLIBC, your program will not use newer symbol version, but the one available at link time: this ensure to have the expected behavor at runtime: no surprise.

Yann Droneaud
  • 5,277
  • 1
  • 23
  • 39
  • what if the system where the .so file runs does not have GLIBC_2.3.2 , and only have GLIBC_2.0 ? Will it report error or use GLIBC_2.0 instead ? – Lunar Mushrooms Jun 21 '12 at 13:50
  • 1
    @LunarMushrooms It will report an error at runtime: symbol not found. – Yann Droneaud Jun 21 '12 at 13:52
  • Have a look at http://stackoverflow.com/questions/2856438/how-can-i-link-to-a-specific-glibc-version?rq=1 or http://stackoverflow.com/questions/4032373/linking-against-an-old-version-of-libc-to-provide-greater-application-coverage?rq=1 – Yann Droneaud Jun 21 '12 at 13:54
0

That is because those methods exist in different .so's. glibc is a collection of .so's. I believe pthread_exit is in libpthread.so and popen is in libc.so

Andrew T Finnell
  • 13,417
  • 3
  • 33
  • 49
  • Ok. For example "GLIBC_2.3.2 pthread_cond_signal" expects GLIBC_2.3.2 version of pthread to be available, right ? What if another machine has a different version of pthread when I copied this libtest.so into that machine ? Will it work ? How to I know the second machine uses GLIBC_2.3.2 ? – Lunar Mushrooms Jun 21 '12 at 13:30