klee调试版的安装调试笔记

备注:在安装klee调试版本的过程中,遇到很多问题,将其略微整理了下,供后来人参考。

安装LLVM等配套软件

  • 此过程详见文档Building KLEE (LLVM 3.4)
  • 以下只记录在操作"Working with KLEE source code"中"Setting up a debug build of KLEE"一节时,我遇到的问题.

配置configure

  1. configure的前后可以添加什么参数,其实是可以在configure文件中查到的
  2. 执行configure配置命令
configure命令:
CXXFLAGS="-g -O0" CFLAGS="-g -O0" LDFLAGS="-ldl -pthread -ltinfo" ./configure with_llvm_build_mode="check" LLVM_BUILD_MODE="Debug"  --with-llvmsrc=../llvm-3.4-src --with-llvmobj="/home/ccc/program/llvm-3.4-build/" --with-stp=../stp   --with-llvmcxx=/home/ccc/program/llvm-3.4-install/bin/clang++ --with-llvmcc=/home/ccc/program/llvm-3.4-install/bin/clang --with-uclibc=/home/ccc/program/klee-uclibc --enable-posix-runtime --with-runtime=Debug+Asserts

出错 "configure: error: Could not autodetect build mode",在configure文件中搜索相应的字符串,找到如下代码

if test X${with_llvm_build_mode} = Xcheck ; then
  llvm_configs="`ls -1 $llvm_obj/*/bin/llvm-config 2>/dev/null | head -n 1`"
  if test -x "$llvm_configs" ; then
    llvm_build_mode="`$llvm_configs --build-mode`"
  else
    as_fn_error $? "Could not autodetect build mode" "$LINENO" 5
  fi
else
  llvm_configs="`echo $llvm_obj/*/bin/llvm-config`"
  if test -x "$llvm_obj/$with_llvm_build_mode/bin/llvm-config" ; then
    llvm_build_mode=$with_llvm_build_mode
  else
    as_fn_error $? "Invalid build mode: $llvm_build_mode" "$LINENO" 5
  fi
fi

这是由于"ls -1 $llvm_obj/*/bin/llvm-config 2" 无法返回正确结果,修改为"ls -1 $llvm_obj/bin/llvm-config 2"
再次执行configure命令,出现错误"checking C LLVM Bitcode compiler works... configure: error: Could not find llvm-dis
",搜索该字符串,根据相关的if逻辑,找到代码:

if test -x "$llvm_obj/$llvm_build_mode/bin/llvm-dis" ; then

这是由于我机器上的$llvm_obj的目录机构中,bin文件夹上层没有$llvm_build_mode目录,为此替换所有的"$llvm_build_mode/bin/"为"bin/"
再次执行configure命令,无报错结束.

编译连接过程make

发现生成的是Release+Asserts文件夹,而不是我期望的Debug+Asserts,并且出现"/home/ccc/program/klee-ccc/Makefile.rules:934: *** llvm-config --libs failed. Stop.",去Makefile.rules的934行,根据逻辑上溯,发现

LLVMLibDir  := $(LLVM_OBJ_ROOT)/$(LLVM_BUILD_MODE)/lib
LLVMToolDir := $(LLVM_OBJ_ROOT)/$(LLVM_BUILD_MODE)/bin
LLVMExmplDir:= $(LLVM_OBJ_ROOT)/$(LLVM_BUILD_MODE)/examples

这还是和之前遇到找不到llvm-config一样的问题,修改为

LLVMLibDir  := $(LLVM_OBJ_ROOT)/lib
LLVMToolDir := $(LLVM_OBJ_ROOT)/bin
LLVMExmplDir:= $(LLVM_OBJ_ROOT)/examples

再次make,成功编译,但出现链接错误

...
make[2]: Entering directory `/home/ccc/program/klee-ccc/tools/klee'
llvm[2]: Compiling Debug.cpp for Release+Asserts build
llvm[2]: Compiling main.cpp for Release+Asserts build
llvm[2]: Linking Release+Asserts executable klee (without symbols)
/home/ccc/program/llvm-3.4-build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): In function `llvm::sys::DynamicLibrary::getPermanentLibrary(char const*, std::string*)':
/home/ccc/program/llvm-3.4-src/lib/Support/DynamicLibrary.cpp:60: undefined reference to `dlopen'
/home/ccc/program/llvm-3.4-src/lib/Support/DynamicLibrary.cpp:62: undefined reference to `dlerror'
/home/ccc/program/llvm-3.4-src/lib/Support/DynamicLibrary.cpp:79: undefined reference to `dlclose'
/home/ccc/program/llvm-3.4-build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): In function `llvm::sys::DynamicLibrary::getAddressOfSymbol(char const*)':
/home/ccc/program/llvm-3.4-src/lib/Support/DynamicLibrary.cpp:87: undefined reference to `dlsym'
/home/ccc/program/llvm-3.4-build/lib/libLLVMSupport.a(DynamicLibrary.cpp.o): In function `llvm::sys::DynamicLibrary::SearchForAddressOfSymbol(char const*)':
/home/ccc/program/llvm-3.4-src/lib/Support/DynamicLibrary.cpp:128: undefined reference to `dlsym'
/home/ccc/program/llvm-3.4-build/lib/libLLVMSupport.a(Process.cpp.o): In function `terminalHasColors':
/home/ccc/program/llvm-3.4-src/lib/Support/Unix/Process.inc:273: undefined reference to `setupterm'
/home/ccc/program/llvm-3.4-src/lib/Support/Unix/Process.inc:291: undefined reference to `tigetnum'
/home/ccc/program/llvm-3.4-src/lib/Support/Unix/Process.inc:295: undefined reference to `set_curterm'
/home/ccc/program/llvm-3.4-src/lib/Support/Unix/Process.inc:296: undefined reference to `del_curterm'
/home/ccc/program/llvm-3.4-build/lib/libLLVMSupport.a(Signals.cpp.o): In function `llvm::sys::PrintStackTrace(_IO_FILE*)':
/home/ccc/program/llvm-3.4-src/lib/Support/Unix/Signals.inc:278: undefined reference to `dladdr'
/home/ccc/program/llvm-3.4-src/lib/Support/Unix/Signals.inc:290: undefined reference to `dladdr'
collect2: error: ld returned 1 exit status
make[2]: *** [/home/ccc/program/klee-ccc/Release+Asserts/bin/klee] Error 1
make[2]: Leaving directory `/home/ccc/program/klee-ccc/tools/klee'
make[1]: *** [klee/.makeall] Error 2
make[1]: Leaving directory `/home/ccc/program/klee-ccc/tools'
make: *** [all] Error 1

这些链接的库其实再configure命令中其实已经赋值了,该命令会修改Makefile.config相应变量为"LDFLAGS := -ldl -pthread -ltinfo -g",为什么还有这个错误,说明makefile之间的连接存在问题(这是经过1天半时间不断的折腾才发现的),去往tools/klee/makefile,在文件中添加"LIBS += $(LDFLAGS)"

  • 再次make,发现tools/klee连接聪哥了,但是tools/kleaver出现了同样的链接错误,去往tools/kleaver/makefile,在文件中添加"LIBS += $(LDFLAGS)",再次make,成功!,再次回到上面遗留的一个问题,为什么生成了完整的Release+Asserts文件夹,而Debug+Asserts文件夹中只有lib文件夹,lib文件夹中的文件还是残缺的,Release+Asserts中klee程序是release版还是debug版?

  • Debug版在哪?

    • 首先这是链接过程配置问题,根据make输出中的"(without symbols)"信息,我们搜索此字符串,在Makefile.rules中发现代码段
    ifndef KEEP_SYMBOLS
      Strip := $(PLATFORMSTRIPOPTS)
      StripWarnMsg := "(without symbols)"
      Install.StripFlag += -s
    endif
    

    查看KEEP_SYMBOLS的继承关系,通过打印"$(info $(ENABLE_OPTIMIZED))",发现该值有时候为0,有时候为1,在Makefile.common中有"override ENABLE_OPTIMIZED := $(RUNTIME_ENABLE_OPTIMIZED)",在configure文件中会根据${with_runtime} 给其赋值

    # Check whether --with-runtime was given.
    if test "${with_runtime+set}" = set; then :
      withval=$with_runtime;
    else
      withval=default
    fi
    
    if test X"${withval}" = Xdefault; then
       with_runtime=Release+Asserts
    fi
    
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking runtime configuration" >&5
    $as_echo_n "checking runtime configuration... " >&6; }
    if test X${with_runtime} = XRelease; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: Release" >&5
    $as_echo "Release" >&6; }
        RUNTIME_ENABLE_OPTIMIZED=1
    
        RUNTIME_DISABLE_ASSERTIONS=1
    
        RUNTIME_DEBUG_SYMBOLS=
    
    elif test X${with_runtime} = XRelease+Asserts; then
        { $as_echo "$as_me:${as_lineno-$LINENO}: result: Release+Asserts" >&5
    $as_echo "Release+Asserts" >&6; }
        RUNTIME_ENABLE_OPTIMIZED=1
    
        RUNTIME_DISABLE_ASSERTIONS=0
    
        RUNTIME_DEBUG_SYMBOLS=
    
    elif test X${with_runtime} = XDebug; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: Debug" >&5
    $as_echo "Debug" >&6; }
       RUNTIME_ENABLE_OPTIMIZED=0
    
       RUNTIME_DISABLE_ASSERTIONS=1
    
       RUNTIME_DEBUG_SYMBOLS=1
    
    elif test X${with_runtime} = XDebug+Asserts; then
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: Debug+Asserts" >&5
    $as_echo "Debug+Asserts" >&6; }
       RUNTIME_ENABLE_OPTIMIZED=0
    
       RUNTIME_DISABLE_ASSERTIONS=0
    
       RUNTIME_DEBUG_SYMBOLS=1
    
    else
       as_fn_error $? "invalid configuration: ${with_runtime}" "$LINENO" 5
    fi
    

但是打印$withval,结果是"Debug+Asserts",继续找RUNTIME_ENABLE_OPTIMIZED和ENABLE_OPTIMIZED的值定义,在Makefile.common中发现include $(LLVM_OBJ_ROOT)/Makefile.config,在该文件中发现

# When ENABLE_OPTIMIZED is enabled, LLVM code is optimized and output is put
# into the "Release" directories. Otherwise, LLVM code is not optimized and
# output is put in the "Debug" directories.
#ENABLE_OPTIMIZED = 1
ENABLE_OPTIMIZED=1

原来该llvmobj直接设置为了优化模式,这也是KLEE官方文档"Working with KLEE source code"中提到的

Note that KLEE depends on LLVM and STP. If you need to debug KLEE’s calls to that code, then you will need to build LLVM/STP with debug support too

我其实早注意这句,也重新编译过LLVM,并且在本llvmobj中bin目录下运行llvm-config --build-mode,返回的也是"Debgu"值,这2者为什么不一致?这个问题先放一放,将上面的ENABLE_OPTIMIZED=1修改为0,重新make,成功生成完整的Debug+Asserts.

补充点知识

在configrue文件中打印语句:

echo ==============1=============
echo $变量

在makefile中打印

$(info $(VARNAME))
$(warning
$(error
$(echo  )
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,319评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,801评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,567评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,156评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,019评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,090评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,500评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,192评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,474评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,566评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,338评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,212评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,572评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,890评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,169评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,478评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,661评论 2 335

推荐阅读更多精彩内容