gpt4 book ai didi

linux 命令 "file"显示 "for GNU/Linux 2.6.24"

转载 作者:IT王子 更新时间:2023-10-29 01:08:57 24 4
gpt4 key购买 nike

我总是使用 file 命令来检查文件类型,主要是在我编译一个新项目以确保一切正常之后。

输出类似于下面的内容:

proj_out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=0x23d9f966854e09d721c6110d505247483dae02fe, stripped

我的问题是,既然我的 Linux 内核已更新到 3.0+,为什么它仍然显示它是为旧版本的 Linux 编译的?

for GNU/Linux 2.6.24

它是否与 file 命令相关,或者我是否需要做任何事情来针对较新的 Linux 内核编译我的项目?

谢谢

最佳答案

file 在可执行文件上显示的内核版本与系统上安装的内核无关。它与程序在构建时链接的 C 库相匹配。

您的 C 编译器针对特定的 C 库(通常是 glibc)。反过来,C 库以内核 API 为目标(即 C 库是为特定内核构建的)。这是 file 显示的版本。

您不必担心文件显示的内核版本与您机器上安装的内核版本不匹配。

@REALFREE:你可以试试下面的实验。也许会帮助您了解正在发生的事情:

$ uname -r3.10-2-amd64$ gcc -Wall -Werror hello.c -o hello$ readelf --notes ./helloDisplaying notes found at file offset 0x0000021c with length 0x00000020:  Owner                 Data size       Description  GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)    OS: Linux, ABI: 2.6.32

关于ABI标签的信息包含在一个elf中名为 NOTE 的片段。此信息由链接器写入程序编译时。它匹配 C 库的 ABI 标记。

$ ldd ./hello        linux-vdso.so.1 (0x00007fffd31fe000)        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5f1a465000)        /lib64/ld-linux-x86-64.so.2 (0x00007f5f1a827000)$ readelf --notes /lib/x86_64-linux-gnu/libc.so.6Displaying notes found at file offset 0x00000294 with length 0x00000020:  Propriétaire        Taille des données        Description  GNU                  0x00000010       NT_GNU_ABI_TAG (étiquette de version ABI)    OS: Linux, ABI: 2.6.32

为了构建C库,你必须选择一个内核版本。在这里,C 库是为 2.6.32 内核编译的,但是它也适用于更新的内核。但是,如果程序在早于 2.6.32 的内核上运行,内核太旧警告显示。

关于linux 命令 "file"显示 "for GNU/Linux 2.6.24",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12236159/

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