Index: src/IceASanInstrumentation.cpp |
diff --git a/src/IceASanInstrumentation.cpp b/src/IceASanInstrumentation.cpp |
index 589bf1a04f3090c3db04824db05317a8e6a8e145..31327f1b58e2991a7b94ef52d8495b0d9b3e2b44 100644 |
--- a/src/IceASanInstrumentation.cpp |
+++ b/src/IceASanInstrumentation.cpp |
@@ -22,6 +22,7 @@ |
#include "IceTypes.h" |
#include <sstream> |
+#include <unordered_map> |
namespace Ice { |
@@ -30,6 +31,12 @@ constexpr SizeT RzSize = 32; |
const std::string RzPrefix = "__$rz"; |
const llvm::NaClBitcodeRecord::RecordVector RzContents = |
llvm::NaClBitcodeRecord::RecordVector(RzSize, 'R'); |
+ |
+// TODO(tlively): Handle all allocation functions |
+using string_map = std::unordered_map<std::string, std::string>; |
+const string_map FuncSubstitutions = {{"malloc", "__asan_malloc"}, |
Jim Stichnoth
2016/06/17 15:43:05
I'm wondering if you've fully considered how this
Karl
2016/06/17 16:06:02
Thomas and I have discussed this issue. Because th
tlively
2016/06/17 21:39:40
Done.
|
+ {"free", "__asan_free"}}; |
+ |
} // end of anonymous namespace |
// Create redzones around all global variables, ensuring that the initializer |
@@ -113,14 +120,37 @@ ASanInstrumentation::createRz(VariableDeclarationList *List, |
return Rz; |
} |
+void ASanInstrumentation::instrumentCall(LoweringContext &Context, |
+ InstCall *Inst) { |
Jim Stichnoth
2016/06/17 15:43:05
Name the arg Instr, not Inst, since Inst is the na
tlively
2016/06/17 21:39:40
Done.
|
+ if (Inst->getCallTarget()->getKind() != Operand::kConstRelocatable) |
Jim Stichnoth
2016/06/17 15:43:05
I would do something like this:
auto *CallTarget
tlively
2016/06/17 21:39:40
Done.
|
+ return; |
+ |
+ ConstantRelocatable *CallTarget = |
+ static_cast<ConstantRelocatable *>(Inst->getCallTarget()); |
+ std::string TargetName = CallTarget->getName().toStringOrEmpty(); |
+ if (FuncSubstitutions.find(TargetName) == FuncSubstitutions.end()) |
Jim Stichnoth
2016/06/17 15:43:05
Would be nice to do something like
auto Subst =
tlively
2016/06/17 21:39:40
Done.
|
+ return; |
+ |
+ std::string SubName = FuncSubstitutions.find(TargetName)->second; |
+ Constant *Substitution = |
+ Ctx->getConstantExternSym(Ctx->getGlobalString(SubName)); |
+ auto *NewCall = |
+ InstCall::create(Context.getNode()->getCfg(), Inst->getNumArgs(), |
+ Inst->getDest(), Substitution, Inst->isTailcall()); |
+ for (SizeT I = 0, Args = Inst->getNumArgs(); I < Args; ++I) |
+ NewCall->addArg(Inst->getArg(I)); |
+ Context.insert(NewCall); |
+ Inst->setDeleted(); |
+} |
+ |
void ASanInstrumentation::instrumentLoad(LoweringContext &Context, |
- const InstLoad *Inst) { |
+ InstLoad *Inst) { |
instrumentAccess(Context, Inst->getSourceAddress(), |
typeWidthInBytes(Inst->getDest()->getType())); |
} |
void ASanInstrumentation::instrumentStore(LoweringContext &Context, |
- const InstStore *Inst) { |
+ InstStore *Inst) { |
instrumentAccess(Context, Inst->getAddr(), |
typeWidthInBytes(Inst->getData()->getType())); |
} |