2016-08-25 2 views
9

非常に古いlibcバージョンの組み込みシステムに対して、ライブラリ依存性のないカール(スタンドアローン版)をビルドしたいと思います。スタンドアロンのカールリードをsegfaultにする

現在のカールgithubのから、私はこのコマンドでコンパイル設定:make期に続いて

./configure --disable-shared --enable-static-nss --prefix=/tmp/curl LDFLAGS='-static -static-libgcc -Wl,-Bstatic -lc' LIBS='-lc -lssl -lcrypto -lz -ldl' 
[...] 
curl version:  7.50.2-DEV 
    Host setup:  x86_64-pc-linux-gnu 
    Install prefix: /tmp/curl 
    Compiler:   gcc 
    SSL support:  enabled (OpenSSL) 
    SSH support:  no  (--with-libssh2) 
    zlib support:  enabled 
    GSS-API support: no  (--with-gssapi) 
    TLS-SRP support: enabled 
    resolver:   default (--enable-ares/--enable-threaded-resolver) 
    IPv6 support:  enabled 
    Unix sockets support: enabled 
    IDN support:  no  (--with-{libidn,winidn}) 
    Build libcurl: Shared=no, Static=yes 
    Built-in manual: enabled 
    --libcurl option: enabled (--disable-libcurl-option) 
    Verbose errors: enabled (--disable-verbose) 
    SSPI support:  no  (--enable-sspi) 
    ca cert bundle: /etc/ssl/certs/ca-certificates.crt 
    ca cert path:  no 
    ca fallback:  no 
    LDAP support:  no  (--enable-ldap/--with-ldap-lib/--with-lber-lib) 
    LDAPS support: no  (--enable-ldaps) 
    RTSP support:  enabled 
    RTMP support:  no  (--with-librtmp) 
    metalink support: no  (--with-libmetalink) 
    PSL support:  no  (libpsl not found) 
    HTTP2 support: disabled (--with-nghttp2) 
    Protocols:  DICT FILE FTP FTPS GOPHER HTTP HTTPS IMAP IMAPS POP3 POP3S RTSP SMB SMBS SMTP SMTPS TELNET TFTP 

を、私は次の警告を得る:

curl-tool_homedir.o: In function `homedir': 
tool_homedir.c:(.text+0x60): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
../lib/.libs/libcurl.a(libcurl_la-netrc.o): In function `Curl_parsenetrc': 
netrc.c:(.text+0x3c3): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
../lib/.libs/libcurl.a(libcurl_la-curl_addrinfo.o): In function `Curl_getaddrinfo_ex': 
curl_addrinfo.c:(.text+0x73): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libcrypto.a(fips.o): In function `verify_checksums': 
(.text+0x4e6): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking 

私はmake installを継続して行うことができます最終的なバイナリを取得します。

バイナリには依存関係がありません:

$ ldd /tmp/curl/bin/curl 
    not a dynamic executable 
$ nm /tmp/curl/bin/curl | grep " U " 
$ 

をしかし、バイナリがまったく機能していません。

$ /tmp/curl/bin/curl -version 
Segmentation fault (core dumped) 

あなたは根本的な原因の問題の任意のアイデアを持っていますか?

EDIT 1: GDB出力:

(gdb) run 
Starting program: /tmp/curl/bin/curl 

Program received signal SIGSEGV, Segmentation fault. 
0x0000000000000000 in ??() 

EDIT 2:

$ nm /tmp/curl/bin/curl | grep getpwuid 
0000000000655770 T getpwuid 
00000000006558f0 T __getpwuid_r 
00000000006558f0 W getpwuid_r 
00000000006558f0 T __new_getpwuid_r 
0000000000663cf0 T __nscd_getpwuid_r 

たぶん問題はWから来ている:

記号Wであります弱いシンボルtha tは、特に弱いオブジェクトシンボルである としてタグ付けされていません。ウィークに定義されたシンボルが の通常定義シンボルとリンクされている場合、通常の定義シンボルが使用され、 エラーは発生しません。弱い未定義のシンボルがリンクされ、シンボルが ではない場合、弱いシンボルの値はエラーなしでゼロになります。

EDIT 3: 私はgetpwuidに同じ警告を得たが、バイナリが動作しているリンクSSL削除する場合:

./configure --disable-shared --enable-static-nss --prefix=/tmp/curl LDFLAGS='-static -static-libgcc -Wl,-Bstatic,-lc' 

ldd /tmp/curl/bin/curl 
    not a dynamic executable 
/tmp/curl/bin/curl --version 
curl 7.50.2-DEV (x86_64-pc-linux-gnu) libcurl/7.50.2-DEV zlib/1.2.8 
Protocols: dict file ftp gopher http imap pop3 rtsp smtp telnet tftp 
Features: IPv6 Largefile libz UnixSockets 

nm /tmp/curl/bin/curl | grep getpwuid 
00000000004f52d0 T getpwuid 
00000000004f5450 T __getpwuid_r 
00000000004f5450 W getpwuid_r 
00000000004f5450 T __new_getpwuid_r 
0000000000502cd0 T __nscd_getpwuid_r 

をしかし、私は問題のように、HTTPSをサポートするためにSSLを追加する必要がありますまだ開いています。

EDIT 4: 問題は直接nssにリンクされています。奇妙な点は、./configure --prefix=/tmp/curl --disable-shared --enable-static-nss LDFLAGS='-static -static-libgcc -Wl,-Bstatic' LIBS='-ls'が動作するスタンドアロンの実行可能ファイルを生成しますが、SSLは使用しないことです。 nssの問題は、SSLのリンクが原因です。

+0

デバッグしようとします。何が起きているのかが分かります。 –

+0

私はリンクの問題を疑うが、どうすればより深くデバッグすることができますか? – Julio

+0

'gdb/tmp/curl/bin/curl'だけです。しかし、あなたは正しいかもしれません。あなたのシステムに1つ以上のコンパイラがありますか? –

答えて

1

openssl https://www.openssl.org/のソース開発版を引き出し、スタティックリンケージ用に再コンパイルします( '.so'ではなく '.a'で終わります)。その後、作成したopenssl静的ライブラリにリンクして、カールを再構築します。

libsslが問題を引き起こしていることは知っていますが、唯一のライブラリではないかもしれません。あなたに問題を与えている次のライブラリを見つけたら、同じことをしてください:ソース開発版を引っ張って、静的リンケージのために再構築してください。