mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-14 11:08:06 +00:00
adding ctor function skipping in LTO fixed map mode
This commit is contained in:
@ -30,6 +30,7 @@ sending a mail to <afl-users+subscribe@googlegroups.com>.
|
|||||||
reporting)
|
reporting)
|
||||||
- LTO: switch default to the dynamic memory map, set AFL_LLVM_MAP_ADDR
|
- LTO: switch default to the dynamic memory map, set AFL_LLVM_MAP_ADDR
|
||||||
for a fixed map address (eg. 0x10000)
|
for a fixed map address (eg. 0x10000)
|
||||||
|
- LTO: skipping ctors and ifuncs in fix map address instrumentation
|
||||||
- LTO: autodictionary mode is a default
|
- LTO: autodictionary mode is a default
|
||||||
- LTO: instrim instrumentation disabled, only classic support used
|
- LTO: instrim instrumentation disabled, only classic support used
|
||||||
as it is always better
|
as it is always better
|
||||||
|
@ -218,43 +218,43 @@
|
|||||||
|
|
||||||
/* Die with a verbose non-OS fatal error message. */
|
/* Die with a verbose non-OS fatal error message. */
|
||||||
|
|
||||||
#define FATAL(x...) \
|
#define FATAL(x...) \
|
||||||
do { \
|
do { \
|
||||||
\
|
\
|
||||||
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD \
|
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD \
|
||||||
"\n[-] PROGRAM ABORT : " cRST x); \
|
"\n[-] PROGRAM ABORT : " cRST x); \
|
||||||
SAYF(cLRD "\n Location : " cRST "%s(), %s:%u\n\n", __func__, \
|
SAYF(cLRD "\n Location : " cRST "%s(), %s:%u\n\n", __func__, \
|
||||||
__FILE__, __LINE__); \
|
__FILE__, __LINE__); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
\
|
\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Die by calling abort() to provide a core dump. */
|
/* Die by calling abort() to provide a core dump. */
|
||||||
|
|
||||||
#define ABORT(x...) \
|
#define ABORT(x...) \
|
||||||
do { \
|
do { \
|
||||||
\
|
\
|
||||||
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD \
|
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD \
|
||||||
"\n[-] PROGRAM ABORT : " cRST x); \
|
"\n[-] PROGRAM ABORT : " cRST x); \
|
||||||
SAYF(cLRD "\n Stop location : " cRST "%s(), %s:%u\n\n", __func__, \
|
SAYF(cLRD "\n Stop location : " cRST "%s(), %s:%u\n\n", __func__, \
|
||||||
__FILE__, __LINE__); \
|
__FILE__, __LINE__); \
|
||||||
abort(); \
|
abort(); \
|
||||||
\
|
\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Die while also including the output of perror(). */
|
/* Die while also including the output of perror(). */
|
||||||
|
|
||||||
#define PFATAL(x...) \
|
#define PFATAL(x...) \
|
||||||
do { \
|
do { \
|
||||||
\
|
\
|
||||||
fflush(stdout); \
|
fflush(stdout); \
|
||||||
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD \
|
SAYF(bSTOP RESET_G1 CURSOR_SHOW cRST cLRD \
|
||||||
"\n[-] SYSTEM ERROR : " cRST x); \
|
"\n[-] SYSTEM ERROR : " cRST x); \
|
||||||
SAYF(cLRD "\n Stop location : " cRST "%s(), %s:%u\n", __func__, \
|
SAYF(cLRD "\n Stop location : " cRST "%s(), %s:%u\n", __func__, \
|
||||||
__FILE__, __LINE__); \
|
__FILE__, __LINE__); \
|
||||||
SAYF(cLRD " OS message : " cRST "%s\n", strerror(errno)); \
|
SAYF(cLRD " OS message : " cRST "%s\n", strerror(errno)); \
|
||||||
exit(1); \
|
exit(1); \
|
||||||
\
|
\
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/* Die with FATAL() or PFATAL() depending on the value of res (used to
|
/* Die with FATAL() or PFATAL() depending on the value of res (used to
|
||||||
|
@ -229,17 +229,65 @@ bool AFLLTOPass::runOnModule(Module &M) {
|
|||||||
Constant *r = IF.getResolver();
|
Constant *r = IF.getResolver();
|
||||||
StringRef r_name = cast<Function>(r->getOperand(0))->getName();
|
StringRef r_name = cast<Function>(r->getOperand(0))->getName();
|
||||||
if (!be_quiet)
|
if (!be_quiet)
|
||||||
fprintf(stderr, "Found an ifunc with name %s that points to resolver function %s, we cannot instrument this, putting it into a block list.\n",
|
fprintf(stderr,
|
||||||
|
"Warning: Found an ifunc with name %s that points to resolver "
|
||||||
|
"function %s, we cannot instrument this, putting it into a "
|
||||||
|
"block list.\n",
|
||||||
ifunc_name.str().c_str(), r_name.str().c_str());
|
ifunc_name.str().c_str(), r_name.str().c_str());
|
||||||
|
|
||||||
module_block_list.push_back(r_name.str());
|
module_block_list.push_back(r_name.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// next up: ctors run before __afl_init()
|
GlobalVariable *GV = M.getNamedGlobal("llvm.global_ctors");
|
||||||
|
if (GV && !GV->isDeclaration() && !GV->hasLocalLinkage()) {
|
||||||
|
|
||||||
// TODO
|
ConstantArray *InitList = dyn_cast<ConstantArray>(GV->getInitializer());
|
||||||
|
|
||||||
|
if (InitList) {
|
||||||
|
|
||||||
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
|
|
||||||
|
if (ConstantStruct *CS =
|
||||||
|
dyn_cast<ConstantStruct>(InitList->getOperand(i))) {
|
||||||
|
|
||||||
|
if (CS->getNumOperands() >= 2) {
|
||||||
|
|
||||||
|
if (CS->getOperand(1)->isNullValue())
|
||||||
|
break; // Found a null terminator, stop here.
|
||||||
|
|
||||||
|
ConstantInt *CI = dyn_cast<ConstantInt>(CS->getOperand(0));
|
||||||
|
int Priority = CI ? CI->getSExtValue() : 0;
|
||||||
|
|
||||||
|
Constant *FP = CS->getOperand(1);
|
||||||
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(FP))
|
||||||
|
if (CE->isCast()) FP = CE->getOperand(0);
|
||||||
|
if (Function *F = dyn_cast<Function>(FP)) {
|
||||||
|
|
||||||
|
if (!F->isDeclaration() &&
|
||||||
|
strncmp(F->getName().str().c_str(), "__afl", 5) != 0 &&
|
||||||
|
Priority <= 5) {
|
||||||
|
|
||||||
|
if (!be_quiet)
|
||||||
|
fprintf(stderr,
|
||||||
|
"Warning: Found constructor function %s with prio "
|
||||||
|
"%u, we cannot instrument this, putting it into a "
|
||||||
|
"block list.\n",
|
||||||
|
F->getName().str().c_str(), Priority);
|
||||||
|
module_block_list.push_back(F->getName().str());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,8 +316,10 @@ bool AFLLTOPass::runOnModule(Module &M) {
|
|||||||
if (fname.compare(bname) == 0) {
|
if (fname.compare(bname) == 0) {
|
||||||
|
|
||||||
if (!be_quiet)
|
if (!be_quiet)
|
||||||
WARNF("Skipping instrumentation of ifunc resolver function %s",
|
WARNF(
|
||||||
fname.c_str());
|
"Skipping instrumentation of dangerous early running function "
|
||||||
|
"%s",
|
||||||
|
fname.c_str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user