Curl 使独立卷曲导致segfault

Curl 使独立卷曲导致segfault,curl,gcc,segmentation-fault,ldd,Curl,Gcc,Segmentation Fault,Ldd,我想为使用非常旧的libc版本的嵌入式系统构建一个独立版本的` curl,它没有任何库依赖(甚至libc) 从当前的curl github,我使用以下命令配置编译: ./configure --disable-shared --enable-static-nss --prefix=/tmp/curl LDFLAGS='-static -static-libgcc -Wl,-Bstatic -lc' LIBS='-lc -lssl -lcrypto -lz -ldl' [...] curl ver

我想为使用非常旧的libc版本的嵌入式系统构建一个独立版本的` curl,它没有任何库依赖(甚至libc)

从当前的curl github,我使用以下命令配置编译:

./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
然后在
make
阶段,我得到以下警告:

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
我可以继续执行
makeinstall
,以获得最终的二进制文件

二进制文件没有依赖关系:

$ 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)
你知道问题的根本原因吗

编辑1: GDB输出:

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

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
编辑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该符号是一个弱符号,未专门标记为 弱的物体符号。当弱定义符号与 正常定义符号,正常定义符号与否一起使用 错误。当链接了弱未定义符号而未链接该符号时 定义后,弱符号的值将变为零,且无任何错误

编辑3: 如果删除SSL链接,我会收到与
getpwuid
相同的警告,但二进制文件正在工作:

./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支持,所以这个问题仍然存在

编辑4: 该问题与nss直接相关。奇怪的是,
/configure--prefix=/tmp/curl--disable shared--enable static nss LDFLAGS='-static-static libgcc-Wl,-Bstatic'LIBS='-ls'
生成了一个独立的可执行文件,但没有SSL。
nss的问题是由于SSL链接造成的。

拉入openssl的源代码开发版本,并重新编译它以进行静态链接(以“.a”而不是“.so”结尾)。然后重建curl,链接到您构建的openssl静态库


您知道libssl给您带来了问题,但它可能不是唯一一个这样做的库。当您发现下一个给您带来问题的库时,请对其执行相同的操作:拉入源代码开发版本并重新构建它以进行静态链接。

尝试调试它。你会知道发生了什么。我怀疑有链接问题,但我如何才能深入调试?只需
gdb/tmp/curl/bin/curl
。但你可能是对的。你的系统中有不止一个编译器吗?我不这么认为。gcc版本为5.4.0构建输出说明:在静态链接的应用程序中使用“…”需要在运行时使用glibc版本中用于链接的共享库。这意味着它可能会崩溃,因为它在运行它的系统上找不到这些库。