@@ -201,8 +201,8 @@ static cl::opt<bool> ClRecover(
201
201
202
202
static cl::opt<bool > ClInsertVersionCheck (
203
203
" asan-guard-against-version-mismatch" ,
204
- cl::desc (" Guard against compiler/runtime version mismatch." ),
205
- cl::Hidden, cl:: init(true ));
204
+ cl::desc (" Guard against compiler/runtime version mismatch." ), cl::Hidden,
205
+ cl::init(true ));
206
206
207
207
// This flag may need to be replaced with -f[no-]asan-reads.
208
208
static cl::opt<bool > ClInstrumentReads (" asan-instrument-reads" ,
@@ -323,10 +323,9 @@ static cl::opt<unsigned> ClRealignStack(
323
323
324
324
static cl::opt<int > ClInstrumentationWithCallsThreshold (
325
325
" asan-instrumentation-with-call-threshold" ,
326
- cl::desc (
327
- " If the function being instrumented contains more than "
328
- " this number of memory accesses, use callbacks instead of "
329
- " inline checks (-1 means never use callbacks)." ),
326
+ cl::desc (" If the function being instrumented contains more than "
327
+ " this number of memory accesses, use callbacks instead of "
328
+ " inline checks (-1 means never use callbacks)." ),
330
329
cl::Hidden, cl::init(7000 ));
331
330
332
331
static cl::opt<std::string> ClMemoryAccessCallbackPrefix (
@@ -644,8 +643,9 @@ namespace {
644
643
// / AddressSanitizer: instrument the code in module to find memory bugs.
645
644
struct AddressSanitizer {
646
645
AddressSanitizer (Module &M, const StackSafetyGlobalInfo *SSGI,
647
- bool CompileKernel = false , bool Recover = false ,
648
- bool UseAfterScope = false ,
646
+ int InstrumentationWithCallsThreshold,
647
+ uint32_t MaxInlinePoisoningSize, bool CompileKernel = false ,
648
+ bool Recover = false , bool UseAfterScope = false ,
649
649
AsanDetectStackUseAfterReturnMode UseAfterReturn =
650
650
AsanDetectStackUseAfterReturnMode::Runtime)
651
651
: CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
@@ -654,7 +654,14 @@ struct AddressSanitizer {
654
654
UseAfterScope(UseAfterScope || ClUseAfterScope),
655
655
UseAfterReturn(ClUseAfterReturn.getNumOccurrences() ? ClUseAfterReturn
656
656
: UseAfterReturn),
657
- SSGI(SSGI) {
657
+ SSGI(SSGI),
658
+ InstrumentationWithCallsThreshold(
659
+ ClInstrumentationWithCallsThreshold.getNumOccurrences() > 0
660
+ ? ClInstrumentationWithCallsThreshold
661
+ : InstrumentationWithCallsThreshold),
662
+ MaxInlinePoisoningSize(ClMaxInlinePoisoningSize.getNumOccurrences() > 0
663
+ ? ClMaxInlinePoisoningSize
664
+ : MaxInlinePoisoningSize) {
658
665
C = &(M.getContext ());
659
666
DL = &M.getDataLayout ();
660
667
LongSize = M.getDataLayout ().getPointerSizeInBits ();
@@ -773,17 +780,22 @@ struct AddressSanitizer {
773
780
774
781
FunctionCallee AMDGPUAddressShared;
775
782
FunctionCallee AMDGPUAddressPrivate;
783
+ int InstrumentationWithCallsThreshold;
784
+ uint32_t MaxInlinePoisoningSize;
776
785
};
777
786
778
787
class ModuleAddressSanitizer {
779
788
public:
780
- ModuleAddressSanitizer (Module &M, bool CompileKernel = false ,
781
- bool Recover = false , bool UseGlobalsGC = true ,
782
- bool UseOdrIndicator = false ,
789
+ ModuleAddressSanitizer (Module &M, bool InsertVersionCheck ,
790
+ bool CompileKernel = false , bool Recover = false ,
791
+ bool UseGlobalsGC = true , bool UseOdrIndicator = false ,
783
792
AsanDtorKind DestructorKind = AsanDtorKind::Global,
784
793
AsanCtorKind ConstructorKind = AsanCtorKind::Global)
785
794
: CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
786
795
: CompileKernel),
796
+ InsertVersionCheck (ClInsertVersionCheck.getNumOccurrences() > 0
797
+ ? ClInsertVersionCheck
798
+ : InsertVersionCheck),
787
799
Recover(ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover),
788
800
UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC && !this ->CompileKernel),
789
801
// Enable aliases as they should have no downside with ODR indicators.
@@ -852,6 +864,7 @@ class ModuleAddressSanitizer {
852
864
int GetAsanVersion (const Module &M) const ;
853
865
854
866
bool CompileKernel;
867
+ bool InsertVersionCheck;
855
868
bool Recover;
856
869
bool UseGlobalsGC;
857
870
bool UsePrivateAlias;
@@ -1150,18 +1163,18 @@ AddressSanitizerPass::AddressSanitizerPass(
1150
1163
1151
1164
PreservedAnalyses AddressSanitizerPass::run (Module &M,
1152
1165
ModuleAnalysisManager &MAM) {
1153
- ModuleAddressSanitizer ModuleSanitizer (M, Options.CompileKernel ,
1154
- Options.Recover , UseGlobalGC,
1155
- UseOdrIndicator, DestructorKind,
1156
- ConstructorKind);
1166
+ ModuleAddressSanitizer ModuleSanitizer (
1167
+ M, Options.InsertVersionCheck , Options.CompileKernel , Options.Recover ,
1168
+ UseGlobalGC, UseOdrIndicator, DestructorKind, ConstructorKind);
1157
1169
bool Modified = false ;
1158
1170
auto &FAM = MAM.getResult <FunctionAnalysisManagerModuleProxy>(M).getManager ();
1159
1171
const StackSafetyGlobalInfo *const SSGI =
1160
1172
ClUseStackSafety ? &MAM.getResult <StackSafetyGlobalAnalysis>(M) : nullptr ;
1161
1173
for (Function &F : M) {
1162
- AddressSanitizer FunctionSanitizer (M, SSGI, Options.CompileKernel ,
1163
- Options.Recover , Options.UseAfterScope ,
1164
- Options.UseAfterReturn );
1174
+ AddressSanitizer FunctionSanitizer (
1175
+ M, SSGI, Options.InstrumentationWithCallsThreshold ,
1176
+ Options.MaxInlinePoisoningSize , Options.CompileKernel , Options.Recover ,
1177
+ Options.UseAfterScope , Options.UseAfterReturn );
1165
1178
const TargetLibraryInfo &TLI = FAM.getResult <TargetLibraryAnalysis>(F);
1166
1179
Modified |= FunctionSanitizer.instrumentFunction (F, &TLI);
1167
1180
}
@@ -2591,7 +2604,7 @@ bool ModuleAddressSanitizer::instrumentModule(Module &M) {
2591
2604
} else {
2592
2605
std::string AsanVersion = std::to_string (GetAsanVersion (M));
2593
2606
std::string VersionCheckName =
2594
- ClInsertVersionCheck ? (kAsanVersionCheckNamePrefix + AsanVersion) : " " ;
2607
+ InsertVersionCheck ? (kAsanVersionCheckNamePrefix + AsanVersion) : " " ;
2595
2608
std::tie (AsanCtorFunction, std::ignore) =
2596
2609
createSanitizerCtorAndInitFunctions (M, kAsanModuleCtorName ,
2597
2610
kAsanInitName , /* InitArgTypes=*/ {},
@@ -2893,9 +2906,9 @@ bool AddressSanitizer::instrumentFunction(Function &F,
2893
2906
}
2894
2907
}
2895
2908
2896
- bool UseCalls = (ClInstrumentationWithCallsThreshold >= 0 &&
2909
+ bool UseCalls = (InstrumentationWithCallsThreshold >= 0 &&
2897
2910
OperandsToInstrument.size () + IntrinToInstrument.size () >
2898
- (unsigned )ClInstrumentationWithCallsThreshold );
2911
+ (unsigned )InstrumentationWithCallsThreshold );
2899
2912
const DataLayout &DL = F.getParent ()->getDataLayout ();
2900
2913
ObjectSizeOpts ObjSizeOpts;
2901
2914
ObjSizeOpts.RoundToAlign = true ;
@@ -3069,7 +3082,7 @@ void FunctionStackPoisoner::copyToShadow(ArrayRef<uint8_t> ShadowMask,
3069
3082
for (; j < End && ShadowMask[j] && Val == ShadowBytes[j]; ++j) {
3070
3083
}
3071
3084
3072
- if (j - i >= ClMaxInlinePoisoningSize ) {
3085
+ if (j - i >= ASan. MaxInlinePoisoningSize ) {
3073
3086
copyToShadowInline (ShadowMask, ShadowBytes, Done, i, IRB, ShadowBase);
3074
3087
IRB.CreateCall (AsanSetShadowFunc[Val],
3075
3088
{IRB.CreateAdd (ShadowBase, ConstantInt::get (IntptrTy, i)),
0 commit comments