Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

linux command "file" shows "for GNU/Linux 2.6.24"

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...