【发布时间】:2019-09-30 23:15:57
【问题描述】:
我试图在 LLVM 代码中设置一个断点,该断点生成跳转表以响应 -fsanitize=cfi-icall 标志。
我尝试通过clang -flto -fsanitize=cfi-icall indirect.c -o indirect 运行下面的indirect.c,生成的目标文件显然包含x86 中的跳转表。此外,发出的中间位码文件包含字符串“CFI Canonical Jump Tables”,该字符串仅存在于llvm/lib/Transforms/IPO/LowerTypeTests.cpp 和llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp 中。但是,我已经构建了 clang 并使用调试符号从源代码中选择,并且无法在 GDB 或 LLDB 中的任何一个文件中找到相关代码。该代码更有可能在LowerTypeTests.cpp 中,因为这是跳转表构造代码发生的地方。这是我正在使用的代码:
indirect.c:
int foo (int a) {
return 2 * a;
};
int bar (int a) {
return 3 * a;
}
int main(int argc, char* argv[]) {
int (*func)(int) = foo;
int (*func2)(int) = bar;
int c = func(2);
}
x86 中的跳转表:
0000000000400510 <__typeid__ZTSFiiE_global_addr>:
400510: e9 6b ff ff ff jmpq 400480 <foo.cfi>
400515: cc int3
400516: cc int3
400517: cc int3
0000000000400518 <bar>:
400518: e9 73 ff ff ff jmpq 400490 <bar.cfi>
40051d: cc int3
40051e: cc int3
40051f: cc int3
LowerTypeTests.cpp中的相关代码:
bool lowertypetests::isJumpTableCanonical(Function *F) {
if (F->isDeclarationForLinker())
return false;
auto *CI = mdconst::extract_or_null<ConstantInt>(
F->getParent()->getModuleFlag("CFI Canonical Jump Tables"));
if (!CI || CI->getZExtValue() != 0)
return true;
return F->hasFnAttribute("cfi-canonical-jump-table");
}
在 CodeGenModule.cpp 中:
if (LangOpts.Sanitize.has(SanitizerKind::CFIICall)) {
getModule().addModuleFlag(llvm::Module::Override,
"CFI Canonical Jump Tables",
CodeGenOpts.SanitizeCfiCanonicalJumpTables);
}
如果有人可以帮助我在 GDB 或 LLDB 中触发此代码,我将不胜感激!
【问题讨论】:
标签: c++ c llvm llvm-clang llvm-ir