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
274 views
in Technique[技术] by (71.8m points)

linkage - What are ld-linux.so.2 and linux-gate.so.1?

When I run ldd program I get an output of the form

    linux-gate.so.1 =>  (0xb77ae000)
    libstdc++.so.6 => /lib/libstdc++.so.6 (0xb76bc000)
    libm.so.6 => /lib/libm.so.6 (0xb7691000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7674000)
    libc.so.6 => /lib/libc.so.6 (0xb74c2000)
    /lib/ld-linux.so.2 (0xb77af000)

Can you explain the output and the reason linux-gate.so.1 and ld-linux.so.2 show differently than other entries? What are their roles?

question from:https://stackoverflow.com/questions/19981862/what-are-ld-linux-so-2-and-linux-gate-so-1

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

1 Reply

0 votes
by (71.8m points)

I hope that you're not asking about the main entries, which are stating that for the requested library libm.so.6 it was found in the file /lib/libm.so.6, for example, but are asking about the two outliers.

Why are they displayed differently? for linux-gate.so.1 it's because it's not actually a file on-disk - it's exposed by the kernel as the mechanism for making system calls. For /lib/ld-linux.so.2 it's because this is the program interpreter that is used for actually running the application.

There's a pretty good blog entry describing the linux-gate.so, and it explains it pretty well.

For /lib/ld-linux.so.2, you have to understand a little of what happens when you launch an ELF binary. The short answer is that the kernel handler for these types of binaries uses this file for the purposes of launching the application.

The main purpose of this program is to map the binary into memory, load any referenced libraries in the program (e.g. the libm.so.6 previously mentioned), and then hand off control to the starting address of the binary being executed.

This program is defined as part of the structure of the ELF file, in the INTERP section of the program header. For 32bit linux binaries, this is the typical name of the 32bit interpreter. For 64bit binaries, you'll find it is typically called ld-linux-x86_64.so.2 (for 64bit x86 platforms).

You can determine this information yourself using readelf -l, and the INTERP section:

INTERP         0x0000000000000238 0x0000000000400238 0x0000000000400238
               0x000000000000001c 0x000000000000001c  R      1
    [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]

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

...