如何检查libc版本? [英] How to check libc version?

查看:916
本文介绍了如何检查libc版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与为何pclose会过早返回?我想找出 libc 的哪个版本用于交叉编译的可执行文件。存在以下限制,这些限制使检查特定gcc编译器的glibc版本的答案不适用



  • 一种检查 libc 版本的建议方法是使用<$ c在 gnu / libc-version.h 中声明的$ c> gnu_get_libc_version()函数。我的跨工具链不包含 libc-version.h



  • 另一个建议解决方案是使用打印文件名 gcc 选项。链接的问题中的这个答案对我不起作用:




  $ /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc -print-file-name = libc.so 
libc.so
$
$ /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc -print-file-name = foo.bar
foo.bar
$#我真的没有foo.bar文件



  • 另一种建议的解决方案是code> ldd --version 。我的目标平台没有 ldd


  $ ldd 
sh:无法执行 ldd:无此类文件或目录



  • 另一种建议的解决方案是查看 __ GLIBC __ __ GLIBC_MINOR __ ,但这些似乎也来自 libc-version.h ,如上所述,它在我的跨工具链中不存在。


我的跨工具链似乎只提供 libc.a ,而不提供 libc.so

我尝试通过 /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-运行该 libc.a nm 字符串 grepping(不区分大小写)以表示版本和 libc


我最后尝试的方法是 strings /path/to/toolchains/ARM-cortex-m3-4.4 / bin / arm-uclinuxeabi-gcc | grep GLIBC ,它给了我:

  GLIBC_2.3 
GLIBC_2.2
GLIBC_2。 1
GLIBC_2.0
EGLIBC配置说明符,用于多库用途。

但是该解决方案并没有得到很高的评价,并且还提出了一条评论,表明它并没有真正给您带来版。 我不太了解这个答案或它的回应性评论,所以我不知道该怎么做。


问题:已给出综上所述,是否有确定的方法可以确定用于此跨平台交叉编译的libc版本?

解决方案

您可能正在处理glibc以外的libc变体。有多个 libc的不同实现,例如musl或uclibc。


这是一个Bash脚本,可以检测您的编译器是使用glibc还是uclibc,并告诉您版本是否可以检测到。

  GCC_FEATURES = $(gcc -dM -E-<<< #include< features.h>)

如果grep -q __UCLIBC__< ; $ {GCC_FEATURES};然后
echo uClibc
grep #define __UCLIBC_MAJOR__ <<< " $ {GCC_FEATURES}"
grep #define __UCLIBC_MINOR__ <<< " $ {GCC_FEATURES}"
grep #define __UCLIBC_SUBLEVEL__ <<< " $ {GCC_FEATURES}"
elif grep -q __GLIBC__<<< $ {GCC_FEATURES};然后
echo glibc
grep #define __GLIBC__ <<< " $ {GCC_FEATURES}"
grep #define __GLIBC_MINOR__ <<< " $ {GCC_FEATURES}"
else
回显其他。
fi

Source 。)


如果您正在使用musl,很遗憾,此脚本会报告其他。无法使用预处理器宏检测musl,并且这是有意的。 p>

This question is related to Why does pclose return prematurely?. I'd like to find out what version of libc is used for a cross-compiled executable. There are limitations, described below, that make the answers at Check glibc version for a particular gcc compiler not apply.

  • One proposed way to check the libc version is to use the gnu_get_libc_version() function declared in gnu/libc-version.h. My cross-toolchain does not include libc-version.h.

  • Another proposed solution is to use the -print-file-name gcc option. This answer in the linked question just flat-out didn't work for me:

$ /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc -print-file-name=libc.so
libc.so
$
$ /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc -print-file-name=foo.bar
foo.bar
$ # I really do not have a foo.bar file in existence

  • Another proposed solution is to just do ldd --version. My target platform doesn't have ldd:

$ ldd
sh: can't execute 'ldd': No such file or directory

  • Another proposed solution is to look at __GLIBC__ and __GLIBC_MINOR__ -- but these also appear to come from libc-version.h, which doesn't exist in my cross-toolchain, as described above.

My cross-toolchain seems to only provide libc.a, not libc.so.
I tried running that libc.a through /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-nm and strings grepping (case-insensitive) for "version" and "libc" but did not find anything that looked like an identifying version.

The last thing I tried was strings /path/to/toolchains/ARM-cortex-m3-4.4/bin/arm-uclinuxeabi-gcc | grep GLIBC, which gave me:

GLIBC_2.3
GLIBC_2.2
GLIBC_2.1
GLIBC_2.0
EGLIBC configuration specifier, serves multilib purposes.

But that solution wasn't highly upvoted, and it also has a comment suggesting that it doesn't really give you the version. I don't really understand this answer or its responding comment, so I don't know what to make of its validity.

Question: given all the above, is there any definitive way to determine the libc version used for cross-compiling for this cross-platform?

解决方案

You might be dealing with a variant of libc other than glibc. There are multiple different implementations of libc, such as musl or uclibc.

Here's a Bash script which can detect whether your compiler is using glibc or uclibc, and tells you the version if it detects either.

GCC_FEATURES=$(gcc -dM -E - <<< "#include <features.h>")

if grep -q __UCLIBC__ <<< "${GCC_FEATURES}"; then
    echo "uClibc"
    grep "#define __UCLIBC_MAJOR__" <<< "${GCC_FEATURES}"
    grep "#define __UCLIBC_MINOR__" <<< "${GCC_FEATURES}"
    grep "#define __UCLIBC_SUBLEVEL__" <<< "${GCC_FEATURES}"
elif grep -q __GLIBC__ <<< "${GCC_FEATURES}"; then
    echo "glibc"
    grep "#define __GLIBC__" <<< "${GCC_FEATURES}"
    grep "#define __GLIBC_MINOR__" <<< "${GCC_FEATURES}"
else
    echo "something else"
fi

(Source.)

If you're using musl, unfortunately this script will report "something else." There's no way to detect musl with a preprocessor macro, and this is intentional.

这篇关于如何检查libc版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆