6

.interp共有ライブラリをセグメントでコンパイルしたい。

#include <stdio.h>

int foo(int argc, char** argv) {

    printf("Hello, world!\n");
    return 0;

}

次のコマンドを使用しています。

gcc -c -o test.o test.c
ld --dynamic-linker=blah -shared -o test.so test.o

オプションを渡さなかったかのように、INTERP セグメントなしで終了し--dynamic-linker=blahます。で確認してくださいreadelf -l test.so。実行可能ファイルをビルドするとき、リンカーはオプションを正しく処理し、INTERP セグメントをプログラム ヘッダーに配置します。共有ライブラリでも機能させるにはどうすればよいですか?

4

3 に答える 3

3

ld doesn't include a .interp section if -shared is used, as @MichaelDillon already said. You can however provide this section yourself.

const char interp_section[] __attribute__((section(".interp"))) = "/path/to/dynamic/linker";

The line above will save the string "/path/to/dynamic/linker" in the .interp section using GCC attributes.

If you're trying to build a shared object that's also executable by itself, check this question out. It has a more comprehensive description of the process.

于 2015-07-21T23:44:58.020 に答える
1

INTERP セグメントは、最初に ELF インタープリター (ld.so) をロードする必要があるバイナリーにのみ入ります。ELF インタープリターは共有ライブラリーがロードされる前に既にロードされているため、共有ライブラリーにはINTERP セグメントがありません。

于 2011-07-14T06:26:15.930 に答える
0

ほとんどの Linux システムでは、ldconfig はシステムの起動ごとに実行され、共有ライブラリを含むディレクトリを検索するために /etc/ld.so.conf 内の定義を検索します。ファイル /etc/ld.so.cache には、共有ライブラリ sonames とライブラリの完全パスのマッピングがあります。この記事を読むことを検討してください: http://grahamwideman.wordpress.com/2009/02/09/the-linux-loader-and-how-it-finds-libraries/#comment-164

于 2012-04-13T04:28:15.337 に答える