我正试图将KLEE与一些Swift代码一起使用。为了简单起见,我创建了一个基本的hello-world文件。
我能够成功编译Swift文件(使用klee_make_symbolic
(,但当我试图实际运行KLEE时遇到了问题。以下是我遵循的步骤:
- 创建
main.swift
(下面的文件内容( - 编译成比特码-
swiftc -import-objc-header /home/klee/klee_src/include/klee/klee.h main.swift -emit-bc -target x86_64-pc-linux-gnu
- 运行
klee main.bc
当我运行步骤3中的命令时,我会收到许多警告和错误:
KLEE: output directory is "/home/klee/klee-out-3"
KLEE: Using STP solver backend
KLEE: WARNING: undefined reference to function: $sSPMa
KLEE: WARNING: undefined reference to variable: $sSPyxGs8_PointersMc
KLEE: WARNING: undefined reference to function: $sSS1poiyS2S_SStFZ
KLEE: WARNING: undefined reference to function: $sSS21_builtinStringLiteral17utf8CodeUnitCount7isASCIISSBp_BwBi1_tcfC
KLEE: WARNING: undefined reference to variable: $sSSN
KLEE: WARNING: undefined reference to function: $sSSySSxcs25LosslessStringConvertibleRzlufC
KLEE: WARNING: undefined reference to variable: $sSiN
KLEE: WARNING: undefined reference to variable: $sSis25LosslessStringConvertiblesWP
KLEE: WARNING: undefined reference to function: $ss27_allocateUninitializedArrayySayxG_BptBwlFyp_Tg5
KLEE: WARNING: undefined reference to function: $ss40_convertConstStringToUTF8PointerArgumentyyXlSg_xtSSs01_F0RzlF
KLEE: WARNING: undefined reference to variable: $ss4Int8VN
KLEE: WARNING: undefined reference to function: $ss5print_9separator10terminatoryypd_S2StF
KLEE: WARNING: undefined reference to function: swift_beginAccess
KLEE: WARNING: undefined reference to function: swift_bridgeObjectRelease
KLEE: WARNING: undefined reference to function: swift_endAccess
KLEE: WARNING: undefined reference to function: swift_getWitnessTable
KLEE: WARNING: undefined reference to function: swift_release
KLEE: ERROR: Unable to load symbol($sSiN) while initializing globals
我还尝试用--libc-uclibc
(完整命令:klee --libc=uclibc main.bc
(运行KLEE,它解决了警告,但给我带来了一个不同的错误:
KLEE: NOTE: Using klee-uclibc : /tmp/klee_build90stp_z3/runtime/lib/klee-uclibc.bca
KLEE: output directory is "/home/klee/klee-out-0"
KLEE: Using STP solver backend
error: Appending variables with different alignment need to be linked!
main.swift
func helloWorld(i: Int) -> String {
return "Hello World " + String(i)
}
var a = 0
klee_make_symbolic(&a, MemoryLayout<Int>.size, "a")
print(helloWorld(i: a))
之前没有看到有人试图将KLEE与Swift一起使用,祝你好运!然而,您似乎需要编写Swift运行时的基本实现,类似于klee-libc和uclebc。例如,签名位于Swift的存储库中。