neodreamerus 发表于 2016-03-07 12:58

一个程序链接时链接了没有用到的动态库会有问题吗?

我发现有个程序链接了没有用到的动态库程序结束时会出现 double free or corruption的错误

MMMIX 发表于 2016-03-07 13:40

neodreamerus 发表于 2016-03-07 12:58 static/image/common/back.gif
我发现有个程序链接了没有用到的动态库

怎么知道没有用到?

yjh777 发表于 2016-03-08 15:05

错误应该跟链接没用到的库 没关系。

ldd -u   看的?

yjh777 发表于 2016-03-08 15:07

$ cat kkk.c
#include <stdio.h>

int main(int argc, char *argv[])
{
        printf("Hello world!\n");
        return 0;
}
$ gcc -Wall kkk.c -lpthread-lm-ltcl
$ ldd a.out
        linux-vdso.so.1 =>(0x00007fffe11bc000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f0d22ffe000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f0d22cfc000)
        libtcl8.5.so => /lib64/libtcl8.5.so (0x00007f0d229d3000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f0d22612000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f0d23230000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f0d2240e000)
$ ./a.out
Hello world!

MMMIX 发表于 2016-03-08 15:44

回复 4# yjh777


    你这 gcc, binutils 是哪个版本的?

yjh777 发表于 2016-03-08 16:21

回复 5# MMMIX $ LANG=C gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
$ rpm -q binutils
binutils-2.23.52.0.1-55.el7.x86_64

MMMIX 发表于 2016-03-08 17:54

回复 6# yjh777


    ld 2.24 的话,未使用的动态库已经不会被链进去了。

yjh777 发表于 2016-03-08 18:05

本帖最后由 yjh777 于 2016-03-08 18:06 编辑

收到,这个好!多谢提醒 :)

neodreamerus 发表于 2016-03-17 12:46

回复 3# yjh777


用ldd看的,确实链接了,而且库里的函数或者数据都没有用到。
ld 版本 2.20.51

程序退出时crash的问题,只要在链接时将没用到的库去掉就可以了。这样程序退出时正常的。
所以我判断是链接了库的问题。

该库为C++库。

yjh777 发表于 2016-03-17 16:54

neodreamerus 发表于 2016-03-17 12:46 static/image/common/back.gif
回复 3# yjh777




谢谢耐心回复,
这样的话 应该是系统的bug吧? 什么系统 工具链、内核的版本?
页: [1]
查看完整版本: 一个程序链接时链接了没有用到的动态库会有问题吗?