我正在尝试使用从llvm源代码编译的clang9在clang site上编译DataFlow Sanitizer示例。
但是,我收到错误消息,指出未定义几种类型(在stdint.h中定义)。我已经确认它们已定义,并且编译器可以在stdint.h的/ usr / local / include路径中找到它们。
要进行故障排除,我还在源代码中包含了stdint.h并声明了uint16_t变量tm,但它仍然表示无法识别类型。 示例程序:
#include <stdint.h>
#include <sanitizer/dfsan_interface.h>
#include <assert.h>
int main(void) {
uint16_t tm;
int i = 1;
dfsan_label i_label = dfsan_create_label("i", 0);
dfsan_set_label(i_label, &i, sizeof(i));
int j = 2;
dfsan_label j_label = dfsan_create_label("j", 0);
dfsan_set_label(j_label, &j, sizeof(j));
int k = 3;
dfsan_label k_label = dfsan_create_label("k", 0);
dfsan_set_label(k_label, &k, sizeof(k));
dfsan_label ij_label = dfsan_get_label(i + j);
assert(dfsan_has_label(ij_label, i_label));
assert(dfsan_has_label(ij_label, j_label));
assert(!dfsan_has_label(ij_label, k_label));
dfsan_label ijk_label = dfsan_get_label(i + j + k);
assert(dfsan_has_label(ijk_label, i_label));
assert(dfsan_has_label(ijk_label, j_label));
assert(dfsan_has_label(ijk_label, k_label));
return 0;
}
详细的错误消息:
user@box:~/Desktop/test$ clang -v -fsanitize=dataflow dfsOne.cpp
user@box:~/Desktop/test$ clang -v -fsanitize=dataflow dfsOne.cpp
clang version 9.0.0 (https://github.com/llvm/llvm-project.git 2ba0e2518b96392f9f2352d10fc5a27bbbc92fa9)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user/Desktop/tools/llvm-project/build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Candidate multilib: .;@m64
Selected multilib: .;@m64
"/usr/local/bin/clang-9" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name dfsOne.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/local/lib/clang/9.0.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward -internal-isystem /usr/local/include -internal-isystem /usr/local/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /home/user/Desktop/test -ferror-limit 19 -fmessage-length 0 -fsanitize=dataflow -fsanitize-blacklist=/usr/local/lib/clang/9.0.0/share/dfsan_abilist.txt -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -faddrsig -o /tmp/dfsOne-2ed122.o -x c++ dfsOne.cpp
clang -cc1 version 9.0.0 based upon LLVM 9.0.0svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/x86_64-linux-gnu/c++/8
/usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/backward
/usr/local/include
/usr/local/lib/clang/9.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
In file included from dfsOne.cpp:3:
In file included from /usr/local/include/sanitizer/dfsan_interface.h:18:
/usr/local/include/sanitizer/common_interface_defs.h:33:5: error: unknown type name 'intptr_t'
intptr_t coverage_fd;
^
/usr/local/include/sanitizer/common_interface_defs.h:60:3: error: unknown type name 'uint16_t'
uint16_t __sanitizer_unaligned_load16(const void *p);
^
/usr/local/include/sanitizer/common_interface_defs.h:61:3: error: unknown type name 'uint32_t'
uint32_t __sanitizer_unaligned_load32(const void *p);
^
/usr/local/include/sanitizer/common_interface_defs.h:62:3: error: unknown type name 'uint64_t'
uint64_t __sanitizer_unaligned_load64(const void *p);
^
/usr/local/include/sanitizer/common_interface_defs.h:63:47: error: unknown type name 'uint16_t'
void __sanitizer_unaligned_store16(void *p, uint16_t x);
^
/usr/local/include/sanitizer/common_interface_defs.h:64:47: error: unknown type name 'uint32_t'
void __sanitizer_unaligned_store32(void *p, uint32_t x);
^
/usr/local/include/sanitizer/common_interface_defs.h:65:47: error: unknown type name 'uint64_t'
void __sanitizer_unaligned_store64(void *p, uint64_t x);
^
In file included from dfsOne.cpp:3:
/usr/local/include/sanitizer/dfsan_interface.h:24:9: error: unknown type name 'uint16_t'
typedef uint16_t dfsan_label;
^
dfsOne.cpp:7:2: error: unknown type name 'uint16_t'
uint16_t tm;
^
9 errors generated.
我还尝试使用以下CmakeLists.txt文件通过cmake进行构建(虽然存在相同错误,但我使用的是cmake 3.5.1):
cmake_minimum_required (VERSION 2.6)
project (EXAMPLE)
add_executable(dfsOne dfsOne.cpp)
SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
SET (CMAKE_C_COMPILER "/home/user/Desktop/tools/llvm-project/build/bin/clang")
SET (CMAKE_C_FLAGS "-fsanitize=dataflow")
有什么想法为什么即使我导入了stdint.h编译器也不知道类型?