共有オブジェクトを生成できるコードジェネレーターへのインターフェイスを作成しました。セクションヘッダーテーブルのサポートを実装する必要はありませんが、ELFファイル形式の大部分の複雑さが残っているためです。
GNU ldは、共有オブジェクトに対してリンクするためにセクションヘッダーを使用します。これは、セクションヘッダーのない共有オブジェクトに対してgccリンクを配置しようとすると、ライブラリにシンボルが存在していてもldがシンボルを見つけられないため、失敗することを意味します。
特定のシンボルが見つからない場合でも、リンクを成功させるためにコンパイラーをだますために使用できるトリックはありますか?
トラブルについての説明は次のとおりです。
cheery@ruttunen:~/Documents/g386$ gcc dev/shared_test.c -L. -lshared -m32
/tmp/cc6qBViY.o: In function `main':
shared_test.c:(.text+0xa): undefined reference to `example_function'
collect2: ld returned 1 exit status
cheery@ruttunen:~/Documents/g386$ cat dev/shared_test.c
// gcc shared_test.c -L. -lshared -m32
// LD_LIBRARY_PATH=. ./a.out
#include <stdio.h>
extern int example_function();
int main(){
printf("hello %d\n", example_function());
}
cheery@ruttunen:~/Documents/g386$ readelf -D -s libshared.so
Symbol table for image:
Num Buc: Value Size Type Bind Vis Ndx Name
2 0: 00800164 0 FUNC GLOBAL DEFAULT ABS example_function
1 0: 008000ac 0 OBJECT GLOBAL DEFAULT ABS _DYNAMIC