我想用一个.interp段编译一个共享库。
#include <stdio.h>
int foo(int argc, char** argv) {
printf("Hello, world!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用以下命令。
gcc -c -o test.o test.c
ld --dynamic-linker=blah -shared -o test.so test.o
Run Code Online (Sandbox Code Playgroud)
我最终没有INTERP段,就好像我从未通过过该--dynamic-linker=blah选项一样。用检查readelf -l test.so。生成可执行文件时,链接器会正确处理该选项,并将INTERP段放在程序头中。如何使它也适用于共享库?
在glibc(以及我相信的EGLIBC)中,libc.so库有一个main()方法:
$ /lib/i386-linux-gnu/libc.so.6
GNU C Library (Debian GLIBC 2.19-18+deb8u1) stable release version 2.19, by Roland McGrath et al.
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.8.4.
Compiled on a Linux 3.16.7 system on 2015-08-30.
Available extensions:
crypt add-on version 2.1 by Michael Glad …Run Code Online (Sandbox Code Playgroud)