gpt4 book ai didi

c++ - 如何知道用于构建 linux 的 gcc 版本?

转载 作者:IT王子 更新时间:2023-10-29 00:18:12 26 4
gpt4 key购买 nike

我使用 OpenWRT。它是嵌入式系统的 Linux 发行版

我想知道编译linux的gcc版本

我在网上做了一些研究,但没有结果。

我尝试对 linux OpenWRT 中的一些现有二进制文件(如 wget)执行这些命令

strings -a <default binary> | grep "GCC"
strings -a <default binary> | grep "gcc"

但是我没有得到任何结果

甚至

strings -a  /lib/libgcc_s.so.1 | grep  "gcc"
strings -a /lib/libuClibc-0.9.30.1.so | grep "gcc"

没有给出任何结果

有没有办法知道使用 gcc 构建整个 linux(对于用户空间和内核空间)?

最佳答案

对于程序,如果您的系统正在使用 ELF,它会出现在 ELF 可执行文件的 .comment 部分。

$ cat main.cint main() { }$ gcc main.c$ objdump -s -j .comment a.outa.out:     file format elf64-x86-64Contents of section .comment: 0000 00474343 3a202844 65626961 6e20342e  .GCC: (Debian 4. 0010 372e322d 35292034 2e372e32 00474343  7.2-5) 4.7.2.GCC 0020 3a202844 65626961 6e20342e 342e372d  : (Debian 4.4.7- 0030 33292034 2e342e37 00                 3) 4.4.7.       

用于编译内核的编译器可以从/proc/version中的字符串中得到,例如:

$ cat /proc/versionLinux version 3.8.5 (...) (gcc version 4.7.2 (Debian 4.7.2-5) ) ...

重要警告

.comment 部分是可选的。当可执行文件被捆绑到一个包中时,许多发行版会将它从可执行文件中删除。该部分将放在单独的调试包中。

例如,在我的系统上:

$ objdump -s -j .comment /usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0/usr/lib/x86_64-linux-gnu/libcurl.so.4.2.0:     file format elf64-x86-64objdump: section '.comment' mentioned in a -j option, but not found in any inputfile

安装 libcurl3-dbg 包后,我们通过 GNU 调试链接获得了一个带有剥离部分的图像:

$ objdump -s -j .comment  \    /usr/lib/debug/.build-id/8c/4ae0ad17a4e76bab47c487047490061bd49de3.debug/usr/lib/debug/.build-id/8c/4ae0ad17a4e76bab47c487047490061bd49de3.debug:    file format elf64-x86-64Contents of section .comment: 0000 4743433a 20284465 6269616e 20342e37  GCC: (Debian 4.7 0010 2e322d35 2920342e 372e3200           .2-5) 4.7.2.    

关于c++ - 如何知道用于构建 linux 的 gcc 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16033385/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com