动态库、静态库的一些测试

动态库调试

遇到core dump调试

Add "add_compile_options(-g -O0)" to CMakeLists.txt
ulimit -c unlimited
sudo sysctl -w kernel.core_pattern=/home/debug/coredump/core-%e.%p.%h.%t
gdb -c my_core_file
set solib-search-path {LIBPATH}
gdb -c
set solib-search-path /home/shen/commit/gazelle_plugin/native-sql-engine/cpp/build/
bt
#7  0x00007f02c79bbc0a in _mm256_load_si256 (__P=0x7f011c166530)
    at /usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/avxintrin.h:909
#8  sparkcolumnarplugin::columnartorow::ColumnarToRowConverter::Init (this=0x7f011c166ef0, rb=...)
    at /home/shen/commit/gazelle_plugin/native-sql-engine/cpp/src/operators/columnar_to_row_converter_avx512.cc:148
#9  0x00007f02c71d1416 in Java_com_intel_oap_vectorized_ArrowColumnarToRowJniWrapper_nativeConvertColumnarToRow (
    env=0x7f01d40291f8, schema_arr=0x7f02dfffdad8, num_rows=50, buf_addrs=0x7f02dfffdac8, buf_sizes=0x7f02dfffdac0,
    memory_pool_id=139642742916288) at /home/shen/commit/gazelle_plugin/native-sql-engine/cpp/src/jni/jni_wrapper.cc:1368
#10 0x00007f03d9017b94 in ?? ()
#11 0x00007f011c1644c0 in ?? ()
#12 0x00007f02df9fb998 in ?? ()
#13 0x00007f02dfffda60 in ?? ()
#14 0x00007f02df9fc628 in ?? ()
#15 0x0000000000000000 in ?? ()
(gdb) frame 8
#8  sparkcolumnarplugin::columnartorow::ColumnarToRowConverter::Init (this=0x7f011c166ef0, rb=...)
    at /home/shen/commit/gazelle_plugin/native-sql-engine/cpp/src/operators/columnar_to_row_converter_avx512.cc:148
148             offsetarray_1_8x = _mm256_load_si256((__m256i*)&offsetarray[j]);
(gdb) info locals
x8_8x = {34359738376, 34359738376, 34359738376, 34359738376}
length_data = 0x7f011c167220
binary_array = {<std::__shared_ptr<arrow::BinaryArray, (__gnu_cxx::_Lock_policy)2>> = {<std::__shared_ptr_access<arrow::BinaryArray, (__gnu_cxx::_Lock_policy)2, false, false>> = {<No data fields>}, _M_ptr = 0x7f011c167300, _M_refcount = {
      _M_pi = 0x7f011c1672f0}}, <No data fields>}
offsetarray = 0x7f011c166530
x7_8x = {30064771079, 30064771079, 30064771079, 30064771079}
j = 0
offsetarray_1_8x = {139642742916528, 139642742919584, -536882160, 139642742919704}
array = {<std::__shared_ptr<arrow::Array, (__gnu_cxx::_Lock_policy)2>> = {<std::__shared_ptr_access<arrow::Array, (__gnu_cxx::_Lock_policy)2, false, false>> = {<No data fields>}, _M_ptr = 0x7f011c167300, _M_refcount = {
      _M_pi = 0x7f011c1672f0}}, <No data fields>}
i = 0
fixed_size_per_row = 24
total_memory_size = 139650324748208
(gdb)

提高测试效率,直接编译 .so,替换jar 里的动态库

cp ./releases/libspark_columnar_jni.so ./ && jar uvf /home/shen/commit/gazelle_plugin/native-sql-engine/core/target/spark-columnar-core-1.4.0-SNAPSHOT-jar-with-dependencies.jar ./libspark_columnar_jni.so

example
# cat world.c 
#include <stdio.h>

void world(void)
{
    printf("world.\n");
}

# cat hello.c 
#include <stdio.h>

void world(void);

void hello(void)
{
    printf("hello\n");
    world();
}

# cat test.c 
void hello(void);

int main(void)
{
    hello();
    return 0;
}


第一种成功链接方式
# gcc -shared -fPIC world.c -o libworld.so
# gcc -shared -fPIC hello.c -o libhello.so -L ./ -lworld
# gcc test.c -o a.out  -lhello  -L .
/usr/bin/ld: warning: libworld.so, needed by ./libhello.so, not found (try using -rpath or -rpath-link)
# gcc test.c -o a.out  -lhello  -L . -Wl,-rpath .
# ./a.out 
hello
world.
第二种成功链接方式
gcc -shared -fPIC world.c -o libworld.so
gcc -shared -fPIC hello.c -o libhello.so
gcc test.c -o a.out -L ./ -lhello -lworld

ldconfig

ldconfig 默认扫描当前目录的共享库
当应用程序运行时,可以被加载到。

ldconfig通常在系统启动时运行,而当用户安装了一个新的动态链接库时,就需要手工运行这个命令。

静态库的一些测试

错误方式

ar -rc libsworld.a  world.c

这样生成的libsworld.a 大小和 world大小的两倍

!<arch>
world.c/        1586786089  0     0     100644  68        `
#include <stdio.h>

void world(void)
{
    printf("world.\n");
}

而且会报以下错误

error adding symbols: Archive has no index; run ranlib to add one

正确的方式

gcc -c world.c
ar -rc libworld.a  world.o
nm -D

查看是否包含某个函数

$ nm -D libhdfs.so | grep hdfsOpenFile
00000000000070e0 T hdfsOpenFile

FQA

$ ldd libvelox.so 
./libvelox.so: error while loading shared libraries: libarrow.so.1400: file too short

出现这个错误,一般都是ln软链接设置错的问题。
可以在编译环境下 ldd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值