linux命令“文件”显示“对于GNU / Linux 2.6.24” [英] linux command "file" shows "for GNU/Linux 2.6.24"

查看:208
本文介绍了linux命令“文件”显示“对于GNU / Linux 2.6.24”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



输出结果如下所示:

  proj_out:ELF 32位LSB可执行文件,英特尔80386,版本1(SYSV),静态链接,用于GNU / Linux 2.6.24,BuildID [sha1] = 0x23d9f966854e09d721c6110d505247483dae02fe,剥离

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

  for GNU / Linux 2.6.24 

file 命令还是我必须做任何事情来编译我的项目针对较新的Linux内核?



谢谢

解决方案

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



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



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



@REALFREE:您可以尝试以下实验。也许它会
帮助你掌握发生了什么:

 
$ uname -r
3.10-2 -amd64
$ gcc -Wall -Werror hello.c -o hello
$ readelf - 注释./hello
显示在文件偏移量0x0000021c处发现的长度为0x00000020的注释:
所有者数据大小说明
GNU 0x00000010 NT_GNU_ABI_TAG(ABI版本标签)
操作系统:Linux,ABI:2.6.32

有关 ABI标记的信息包含在名为 的elf
段中。编译程序时,这些信息由链接器
编写。它与C库的ABI标签匹配。

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ )
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.6
显示文件偏移量0x00000294处的长度为0x00000020的笔记:
PropriétaireTaille desdonnées描述
GNU 0x00000010 NT_GNU_ABI_TAG(abiquette de ABI)
OS:Linux,ABI:2.6.32

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


I always use the file command to check the file type, mostly after I compile a new project to make sure everything is fine.

The output is something similar to this below:

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

My question is since my Linux Kernel is updated to 3.0+, why does it still shows it is compiled for older versions of Linux?

for GNU/Linux 2.6.24

Is it anything related to file command or do I have to do anything to compile my project against newer Linux Kernel?

Thanks

解决方案

The kernel version displayed by file on an executable has nothing to do with the kernel installed on your system. It matches the C library the program was linked with at build time.

Your C compiler targets a specific C library (usually glibc). In turn, the C library targets a kernel API (i.e. the C library is built for a specific kernel). That is the version displayed by file.

You don't have to worry about the mimatch between the kernel version displayed by file and the kernel version installed on your machine.

@REALFREE: you can try the following experiment. Maybe it will help you get a grasp of what's going on:

$ uname -r
3.10-2-amd64
$ gcc -Wall -Werror hello.c -o hello
$ readelf --notes ./hello
Displaying 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

The information about the ABI tag is contained in an elf segment called NOTE. This information is written by the linker when the program is compiled. It matches the ABI tag of the C library.

$ 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.6
Displaying 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

In order to build the C library, you have to select a kernel version. Here, the C library was compiled for a 2.6.32 kernel but it also works with more recent kernels. However, if the program is run on a kernel older than 2.6.32, a kernel too old warning is displayed.

这篇关于linux命令“文件”显示“对于GNU / Linux 2.6.24”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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