@@ -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 (
@@ -645,8 +644,9 @@ namespace {
645
644
// / AddressSanitizer: instrument the code in module to find memory bugs.
646
645
struct AddressSanitizer {
647
646
AddressSanitizer (Module &M, const StackSafetyGlobalInfo *SSGI,
648
- bool CompileKernel = false , bool Recover = false ,
649
- bool UseAfterScope = false ,
647
+ int InstrumentationWithCallsThreshold,
648
+ uint32_t MaxInlinePoisoningSize, bool CompileKernel = false ,
649
+ bool Recover = false , bool UseAfterScope = false ,
650
650
AsanDetectStackUseAfterReturnMode UseAfterReturn =
651
651
AsanDetectStackUseAfterReturnMode::Runtime)
652
652
: CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
@@ -655,7 +655,14 @@ struct AddressSanitizer {
655
655
UseAfterScope(UseAfterScope || ClUseAfterScope),
656
656
UseAfterReturn(ClUseAfterReturn.getNumOccurrences() ? ClUseAfterReturn
657
657
: UseAfterReturn),
658
- SSGI(SSGI) {
658
+ SSGI(SSGI),
659
+ InstrumentationWithCallsThreshold(
660
+ ClInstrumentationWithCallsThreshold.getNumOccurrences() > 0
661
+ ? ClInstrumentationWithCallsThreshold
662
+ : InstrumentationWithCallsThreshold),
663
+ MaxInlinePoisoningSize(ClMaxInlinePoisoningSize.getNumOccurrences() > 0
664
+ ? ClMaxInlinePoisoningSize
665
+ : MaxInlinePoisoningSize) {
659
666
C = &(M.getContext ());
660
667
DL = &M.getDataLayout ();
661
668
LongSize = M.getDataLayout ().getPointerSizeInBits ();
@@ -774,17 +781,22 @@ struct AddressSanitizer {
774
781
775
782
FunctionCallee AMDGPUAddressShared;
776
783
FunctionCallee AMDGPUAddressPrivate;
784
+ int InstrumentationWithCallsThreshold;
785
+ uint32_t MaxInlinePoisoningSize;
777
786
};
778
787
779
788
class ModuleAddressSanitizer {
780
789
public:
781
- ModuleAddressSanitizer (Module &M, bool CompileKernel = false ,
782
- bool Recover = false , bool UseGlobalsGC = true ,
783
- bool UseOdrIndicator = true ,
790
+ ModuleAddressSanitizer (Module &M, bool InsertVersionCheck ,
791
+ bool CompileKernel = false , bool Recover = false ,
792
+ bool UseGlobalsGC = true , bool UseOdrIndicator = true ,
784
793
AsanDtorKind DestructorKind = AsanDtorKind::Global,
785
794
AsanCtorKind ConstructorKind = AsanCtorKind::Global)
786
795
: CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
787
796
: CompileKernel),
797
+ InsertVersionCheck (ClInsertVersionCheck.getNumOccurrences() > 0
798
+ ? ClInsertVersionCheck
799
+ : InsertVersionCheck),
788
800
Recover(ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover),
789
801
UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC && !this ->CompileKernel),
790
802
// Enable aliases as they should have no downside with ODR indicators.
@@ -858,6 +870,7 @@ class ModuleAddressSanitizer {
858
870
int GetAsanVersion (const Module &M) const ;
859
871
860
872
bool CompileKernel;
873
+ bool InsertVersionCheck;
861
874
bool Recover;
862
875
bool UseGlobalsGC;
863
876
bool UsePrivateAlias;
@@ -1157,18 +1170,18 @@ AddressSanitizerPass::AddressSanitizerPass(
1157
1170
1158
1171
PreservedAnalyses AddressSanitizerPass::run (Module &M,
1159
1172
ModuleAnalysisManager &MAM) {
1160
- ModuleAddressSanitizer ModuleSanitizer (M, Options.CompileKernel ,
1161
- Options.Recover , UseGlobalGC,
1162
- UseOdrIndicator, DestructorKind,
1163
- ConstructorKind);
1173
+ ModuleAddressSanitizer ModuleSanitizer (
1174
+ M, Options.InsertVersionCheck , Options.CompileKernel , Options.Recover ,
1175
+ UseGlobalGC, UseOdrIndicator, DestructorKind, ConstructorKind);
1164
1176
bool Modified = false ;
1165
1177
auto &FAM = MAM.getResult <FunctionAnalysisManagerModuleProxy>(M).getManager ();
1166
1178
const StackSafetyGlobalInfo *const SSGI =
1167
1179
ClUseStackSafety ? &MAM.getResult <StackSafetyGlobalAnalysis>(M) : nullptr ;
1168
1180
for (Function &F : M) {
1169
- AddressSanitizer FunctionSanitizer (M, SSGI, Options.CompileKernel ,
1170
- Options.Recover , Options.UseAfterScope ,
1171
- Options.UseAfterReturn );
1181
+ AddressSanitizer FunctionSanitizer (
1182
+ M, SSGI, Options.InstrumentationWithCallsThreshold ,
1183
+ Options.MaxInlinePoisoningSize , Options.CompileKernel , Options.Recover ,
1184
+ Options.UseAfterScope , Options.UseAfterReturn );
1172
1185
const TargetLibraryInfo &TLI = FAM.getResult <TargetLibraryAnalysis>(F);
1173
1186
Modified |= FunctionSanitizer.instrumentFunction (F, &TLI);
1174
1187
}
@@ -2593,7 +2606,7 @@ bool ModuleAddressSanitizer::instrumentModule(Module &M) {
2593
2606
} else {
2594
2607
std::string AsanVersion = std::to_string (GetAsanVersion (M));
2595
2608
std::string VersionCheckName =
2596
- ClInsertVersionCheck ? (kAsanVersionCheckNamePrefix + AsanVersion) : " " ;
2609
+ InsertVersionCheck ? (kAsanVersionCheckNamePrefix + AsanVersion) : " " ;
2597
2610
std::tie (AsanCtorFunction, std::ignore) =
2598
2611
createSanitizerCtorAndInitFunctions (M, kAsanModuleCtorName ,
2599
2612
kAsanInitName , /* InitArgTypes=*/ {},
@@ -2892,9 +2905,9 @@ bool AddressSanitizer::instrumentFunction(Function &F,
2892
2905
}
2893
2906
}
2894
2907
2895
- bool UseCalls = (ClInstrumentationWithCallsThreshold >= 0 &&
2908
+ bool UseCalls = (InstrumentationWithCallsThreshold >= 0 &&
2896
2909
OperandsToInstrument.size () + IntrinToInstrument.size () >
2897
- (unsigned )ClInstrumentationWithCallsThreshold );
2910
+ (unsigned )InstrumentationWithCallsThreshold );
2898
2911
const DataLayout &DL = F.getParent ()->getDataLayout ();
2899
2912
ObjectSizeOpts ObjSizeOpts;
2900
2913
ObjSizeOpts.RoundToAlign = true ;
@@ -3068,7 +3081,7 @@ void FunctionStackPoisoner::copyToShadow(ArrayRef<uint8_t> ShadowMask,
3068
3081
for (; j < End && ShadowMask[j] && Val == ShadowBytes[j]; ++j) {
3069
3082
}
3070
3083
3071
- if (j - i >= ClMaxInlinePoisoningSize ) {
3084
+ if (j - i >= ASan. MaxInlinePoisoningSize ) {
3072
3085
copyToShadowInline (ShadowMask, ShadowBytes, Done, i, IRB, ShadowBase);
3073
3086
IRB.CreateCall (AsanSetShadowFunc[Val],
3074
3087
{IRB.CreateAdd (ShadowBase, ConstantInt::get (IntptrTy, i)),
0 commit comments