-
Notifications
You must be signed in to change notification settings - Fork 56
[SanCov] Support SanitizerCoverage for CHERI purecap binaries #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
9b4aae6
dd86799
7b766aa
c7b4afb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
namespace __sanitizer { | ||
|
||
#if SANITIZER_FREEBSD | ||
void GetMemoryProfile(fill_profile_f cb, uptr *stats) { | ||
void GetMemoryProfile(fill_profile_f cb, usize *stats) { | ||
const int Mib[] = { | ||
CTL_KERN, | ||
KERN_PROC, | ||
|
@@ -49,11 +49,12 @@ void GetMemoryProfile(fill_profile_f cb, uptr *stats) { | |
}; | ||
|
||
struct kinfo_proc InfoProc; | ||
uptr Len = sizeof(InfoProc); | ||
CHECK_EQ(internal_sysctl(Mib, ARRAY_SIZE(Mib), nullptr, (uptr *)&InfoProc, &Len, 0), 0); | ||
usize Len = sizeof(InfoProc); | ||
CHECK_EQ(internal_sysctl(Mib, ARRAY_SIZE(Mib), &InfoProc, &Len, nullptr, 0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks good, would you mind send it upstream? |
||
0); | ||
cb(0, InfoProc.ki_rssize * GetPageSizeCached(), false, stats); | ||
} | ||
#endif | ||
# endif | ||
|
||
void ReadProcMaps(ProcSelfMapsBuff *proc_maps) { | ||
const int Mib[] = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" | ||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/ADT/SmallVector.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/Analysis/GlobalsModRef.h" | ||
#include "llvm/Analysis/PostDominators.h" | ||
#include "llvm/IR/Constant.h" | ||
|
@@ -30,6 +31,7 @@ | |
#include "llvm/IR/Module.h" | ||
#include "llvm/IR/Type.h" | ||
#include "llvm/Support/CommandLine.h" | ||
#include "llvm/Support/Process.h" | ||
#include "llvm/Support/SpecialCaseList.h" | ||
#include "llvm/Support/VirtualFileSystem.h" | ||
#include "llvm/TargetParser/Triple.h" | ||
|
@@ -390,6 +392,11 @@ bool ModuleSanitizerCoverage::instrumentModule( | |
DL = &M.getDataLayout(); | ||
CurModule = &M; | ||
CurModuleUniqueId = getUniqueModuleId(CurModule); | ||
if (CurModuleUniqueId.empty()) { | ||
CurModuleUniqueId = "clangPidTime_" + | ||
llvm::itostr(sys::Process::getProcessId()) + "_" + | ||
llvm::itostr(time(nullptr)); | ||
} | ||
TargetTriple = Triple(M.getTargetTriple()); | ||
FunctionGuardArray = nullptr; | ||
Function8bitCounterArray = nullptr; | ||
|
@@ -724,7 +731,10 @@ GlobalVariable *ModuleSanitizerCoverage::CreateFunctionLocalArrayInSection( | |
ArrayType *ArrayTy = ArrayType::get(Ty, NumElements); | ||
auto Array = new GlobalVariable( | ||
*CurModule, ArrayTy, false, GlobalVariable::PrivateLinkage, | ||
Constant::getNullValue(ArrayTy), "__sancov_gen_"); | ||
Constant::getNullValue(ArrayTy), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this change is needed? Also please avoid hardcoded AS200 checks and use DL.isFatPointer instead. But I am not convinced this change is actually required. |
||
DL->getGlobalsAddressSpace() == 200 | ||
? Twine("__sancov_gen_") + Twine(CurModuleUniqueId) | ||
: "__sancov_gen_"); | ||
|
||
if (TargetTriple.supportsCOMDAT() && | ||
(TargetTriple.isOSBinFormatELF() || !F.isInterposable())) | ||
|
@@ -862,7 +872,10 @@ void ModuleSanitizerCoverage::InjectTraceForSwitch( | |
GlobalVariable *GV = new GlobalVariable( | ||
*CurModule, ArrayOfInt64Ty, false, GlobalVariable::InternalLinkage, | ||
ConstantArray::get(ArrayOfInt64Ty, Initializers), | ||
"__sancov_gen_cov_switch_values"); | ||
DL->getGlobalsAddressSpace() == 200 | ||
? Twine("__sancov_gen_cov_switch_values") + | ||
Twine(CurModuleUniqueId) | ||
: "__sancov_gen_cov_switch_values"); | ||
IRB.CreateCall(SanCovTraceSwitchFunction, | ||
{Cond, IRB.CreatePointerCast(GV, GlobalsInt64PtrTy)}); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong, do you know what is causing those problems?