2

gcc 6.2.0 までは、非再配置可能アセンブラー コードのリンクは問題になりませんでした。これを開始した正確なバージョンはわかりませんが、gcc 5.4.0 (およびそれ以下) では次のように動作しました。

$ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto

ただし、gcc 6.2.0 では:

$ gcc -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto
/usr/bin/ld: ../../../lib/libribs2_ssl.a(context_asm.o): relocation R_X86_64_32S against symbol `current_ctx' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

静的リンクを強制しようとすると、別の問題が発生します。

$ gcc -static -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto -ldl
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../obj/httpget.o: In function `main':
/home/nir/ribs2/examples/httpget/src/httpget.c:194: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

gethostbyname() を使用すると、プログラムのセグメンテーション違反が発生します (ただし、それ以外の場合は機能します)。

また、静的と動的を混在させようとしてもうまくいきません。

$ gcc -o httpget -Wl,-Bstatic ../obj/httpget.o ../../../lib/libribs2_ssl.a -Wl,-Bdynamic -lssl -lcrypto
/usr/bin/ld: ../../../lib/libribs2_ssl.a(context_asm.o): relocation R_X86_64_32S against symbol `current_ctx' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

何か案は?プロジェクトへのリンク: https://github.com/niryeffet/ribs2

4

1 に答える 1

3

@Jester からのヒントのおかげで、LDFLAGS に -no-pie (-fno-PIE ではない) を追加することで問題が解決しました。

gcc -no-pie -o httpget ../obj/httpget.o ../../../lib/libribs2_ssl.a -lssl -lcrypto

この変更は gcc 5.4 でも機能します。デフォルトが変更されたようです。

アップデート:

これはそれを説明しています。https://wiki.ubuntu.com/SecurityTeam/PIEから

Ubuntu 16.10 では、追加のコンパイラ強化策として、amd64 と ppc64le でデフォルトで PIE と即時バインディングを有効にしました。これにより、これらのプラットフォームでの ASLR の有効性が大幅に向上します。

于 2016-10-25T18:34:20.920 に答える