How to determine version of glibc (glibcxx) binary will depend on?
Asked Answered
W

2

15

It's well known that glibc (and, as far as I know, glibstd++ also) uses symbol versioning mechanism. (For the details refer: How can I link to a specific glibc version.)

The question is how to determine exact versions of GLIBC and GLIBCXX will be chosen by linker for names from libc and libstdc++? For example, how to get something like this:

time -> time@GLIBC_2_5
...
gethostbyname -> gethostbyname@GLIBC_2_3

Why do we need this? It seems to me that it can be useful if you want to minimize required versions of glibc/libstdc++.

Woodrum answered 8/8, 2010 at 20:50 Comment(1)
IIRC dso-howto (akkadia.org/drepper/dsohowto.pdf) had a section on using linker scripts for that.Boots
R
32

One thing you can try is running objdump -T on your binary. For example, here's how to see that the /usr/sbin/nordvpnd binary on my system depends on GLIBC version at least 2.18:

$ objdump -T /usr/sbin/nordvpnd | grep GLIBC | sed 's/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -Vu      
2.2.5
2.3
2.3.2
2.3.3
2.3.4
2.4
2.7
2.8
2.9
2.10
2.14
2.15
2.16
2.17
2.18

If you are considering linking to older versions of symbols, be aware that these older versions may depend on older, different structures or other definitions as well. To avoid this, compile and link with older, matching header files and libraries.

Rehabilitation answered 8/8, 2010 at 22:38 Comment(3)
Thanks, jilles. It works. One more question, how to get location in code from which dynamic symbol is called? I mean, for example, if 'objdump -T' returns some entry, say GLIBCXX_3.4.9 Insert_, how to understand which functions in sources use this symbol?Woodrum
hmm, I don't really know a better solution than running objdump -t over all the .o files and checking which ones contain references to the function. It seems that this can be done better as the linker knows where an unresolved symbol was used.Rehabilitation
I would only add that for shared libraries "objdump -T" does not work and I am using the solution "ldd -v somelibrary.so" (-v is important) which was described on askubuntu.com/questions/163138/…Hummel
S
5
objdump -T  bin-file | grep -Eo 'GLIBC_\S+' | sort -u
Saylor answered 22/5, 2023 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.