|
LLVM 24.0.0git
|
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"#include "InstrumentationOptions.h"#include "llvm/ADT/ArrayRef.h"#include "llvm/ADT/DenseMap.h"#include "llvm/ADT/DepthFirstIterator.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/SmallVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/ADT/StringExtras.h"#include "llvm/ADT/StringRef.h"#include "llvm/ADT/Twine.h"#include "llvm/Analysis/GlobalsModRef.h"#include "llvm/Analysis/MemoryBuiltins.h"#include "llvm/Analysis/StackSafetyAnalysis.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/BinaryFormat/MachO.h"#include "llvm/Demangle/Demangle.h"#include "llvm/IR/Argument.h"#include "llvm/IR/Attributes.h"#include "llvm/IR/BasicBlock.h"#include "llvm/IR/Comdat.h"#include "llvm/IR/Constant.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DIBuilder.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DebugInfoMetadata.h"#include "llvm/IR/DebugLoc.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/EHPersonalities.h"#include "llvm/IR/Function.h"#include "llvm/IR/GlobalAlias.h"#include "llvm/IR/GlobalValue.h"#include "llvm/IR/GlobalVariable.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/InlineAsm.h"#include "llvm/IR/InstVisitor.h"#include "llvm/IR/InstrTypes.h"#include "llvm/IR/Instruction.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Intrinsics.h"#include "llvm/IR/LLVMContext.h"#include "llvm/IR/MDBuilder.h"#include "llvm/IR/Metadata.h"#include "llvm/IR/Module.h"#include "llvm/IR/Type.h"#include "llvm/IR/Use.h"#include "llvm/IR/Value.h"#include "llvm/MC/MCSectionMachO.h"#include "llvm/Support/Casting.h"#include "llvm/Support/Debug.h"#include "llvm/Support/ErrorHandling.h"#include "llvm/Support/MathExtras.h"#include "llvm/Support/ModRef.h"#include "llvm/Support/raw_ostream.h"#include "llvm/TargetParser/Triple.h"#include "llvm/Transforms/Instrumentation/AddressSanitizerCommon.h"#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"#include "llvm/Transforms/Utils/ASanStackFrameLayout.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"#include "llvm/Transforms/Utils/Instrumentation.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Transforms/Utils/ModuleUtils.h"#include "llvm/Transforms/Utils/PromoteMemToReg.h"#include <algorithm>#include <cassert>#include <cstddef>#include <cstdint>#include <iomanip>#include <limits>#include <sstream>#include <string>#include <tuple>#include <utility>Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "asan" |
Functions | |
| STATISTIC (NumInstrumentedReads, "Number of instrumented reads") | |
| STATISTIC (NumInstrumentedWrites, "Number of instrumented writes") | |
| STATISTIC (NumOptimizedAccessesToGlobalVar, "Number of optimized accesses to global vars") | |
| STATISTIC (NumOptimizedAccessesToStackVar, "Number of optimized accesses to stack vars") | |
| static ShadowMapping | getShadowMapping (const InstrumentationOptions &Opts, const Triple &TargetTriple, int LongSize, bool IsKasan) |
| static uint64_t | getRedzoneSizeForScale (int MappingScale) |
| static uint64_t | GetCtorAndDtorPriority (Triple &TargetTriple) |
| static Twine | genName (StringRef suffix) |
| static size_t | TypeStoreSizeToSizeIndex (uint32_t TypeSize) |
| static bool | GlobalWasGeneratedByCompiler (GlobalVariable *G) |
Check if G has been created by a trusted compiler pass. | |
| static bool | isUnsupportedAMDGPUAddrspace (Value *Addr) |
| static bool | isSupportedAddrspace (const InstrumentationOptions &Opts, const Triple &TargetTriple, Value *Addr) |
| static bool | isPointerOperand (Value *V) |
| static bool | isInterestingPointerComparison (Instruction *I) |
| static bool | isInterestingPointerSubtraction (Instruction *I) |
| static bool | isPointerPairOperand (Value *V, Type *IntptrTy) |
| static void | doInstrumentAddress (AddressSanitizer *Pass, Instruction *I, Instruction *InsertBefore, Value *Addr, MaybeAlign Alignment, unsigned Granularity, TypeSize TypeStoreSize, bool IsWrite, Value *SizeArgument, bool UseCalls, uint32_t Exp, RuntimeCallInserter &RTCI) |
| static int | StackMallocSizeClass (uint64_t LocalStackSize) |
| static void | findStoresToUninstrumentedArgAllocas (AddressSanitizer &ASan, Instruction &InsBefore, SmallVectorImpl< Instruction * > &InitInsts) |
Collect instructions in the entry block after InsBefore which initialize permanent storage for a function argument. | |
| static StringRef | getAllocaName (AllocaInst *AI) |
| #define DEBUG_TYPE "asan" |
Definition at line 97 of file AddressSanitizer.cpp.
|
static |
Definition at line 1469 of file AddressSanitizer.cpp.
References llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), I, and llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::isScalable().
|
static |
Collect instructions in the entry block after InsBefore which initialize permanent storage for a function argument.
These instructions must remain in the entry block so that uninitialized values do not appear in backtraces. An added benefit is that this conserves spill slots. This does not move stores before instrumented / "interesting" allocas.
Definition at line 3256 of file AddressSanitizer.cpp.
References llvm::cast(), llvm::dyn_cast(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::isa(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::Store.
Definition at line 438 of file AddressSanitizer.cpp.
References kAsanGenPrefix.
|
static |
Definition at line 3304 of file AddressSanitizer.cpp.
References llvm::cast(), llvm::Instruction::getMetadata(), llvm::Value::getName(), llvm::Instruction::hasMetadata(), llvm::isa(), and llvm::MDNode::operands().
Definition at line 431 of file AddressSanitizer.cpp.
References llvm::Triple::isOSEmscripten(), kAsanCtorAndDtorPriority, kAsanEmscriptenCtorAndDtorPriority, and uint64_t.
|
static |
Definition at line 425 of file AddressSanitizer.cpp.
References uint64_t.
|
static |
Definition at line 220 of file AddressSanitizer.cpp.
References llvm::Triple::aarch64, llvm::Triple::aarch64_be, llvm::Triple::getArch(), llvm::Triple::isABIN32(), llvm::Triple::isAMDGPU(), llvm::Triple::isAndroid(), llvm::Triple::isARM(), llvm::Triple::isBPF(), llvm::Triple::isDriverKit(), llvm::Triple::isiOS(), llvm::Triple::isLoongArch64(), llvm::Triple::isMacOSX(), llvm::Triple::isMIPS32(), llvm::Triple::isMIPS64(), llvm::Triple::isOSFreeBSD(), llvm::Triple::isOSFuchsia(), llvm::Triple::isOSHaiku(), llvm::Triple::isOSLinux(), llvm::Triple::isOSNetBSD(), llvm::Triple::isOSWindows(), llvm::Triple::isPS(), llvm::Triple::isThumb(), llvm::Triple::isWasm(), llvm::Triple::isWatchOS(), kAArch64_ShadowOffset64, kDefaultShadowOffset32, kDefaultShadowOffset64, kDefaultShadowScale, kDynamicShadowSentinel, kFreeBSD_ShadowOffset32, kFreeBSD_ShadowOffset64, kFreeBSDAArch64_ShadowOffset64, kFreeBSDKasan_ShadowOffset64, kLinuxKasan_ShadowOffset64, kLoongArch64_ShadowOffset64, kMIPS32_ShadowOffset32, kMIPS64_ShadowOffset64, kMIPS_ShadowOffsetN32, kNetBSD_ShadowOffset32, kNetBSD_ShadowOffset64, kNetBSDKasan_ShadowOffset64, kPPC64_ShadowOffset64, kPS_ShadowOffset64, kRISCV64_ShadowOffset64, kSmallX86_64ShadowOffsetAlignMask, kSmallX86_64ShadowOffsetBase, kSystemZ_ShadowOffset64, kWebAssemblyShadowOffset, kWindowsShadowOffset32, kWindowsShadowOffset64, llvm::Triple::ppc64, llvm::Triple::ppc64le, llvm::Triple::riscv64, llvm::Triple::systemz, and llvm::Triple::x86_64.
Referenced by llvm::getAddressSanitizerParams().
|
static |
Check if G has been created by a trusted compiler pass.
Definition at line 1107 of file AddressSanitizer.cpp.
References G, kAsanGenPrefix, kODRGenPrefix, and kSanCovGenPrefix.
|
static |
Definition at line 1385 of file AddressSanitizer.cpp.
References llvm::dyn_cast(), I, and isPointerOperand().
|
static |
Definition at line 1399 of file AddressSanitizer.cpp.
References llvm::dyn_cast(), I, and isPointerOperand().
Definition at line 1378 of file AddressSanitizer.cpp.
References llvm::isa().
Definition at line 1423 of file AddressSanitizer.cpp.
References llvm::Type::getScalarSizeInBits(), and llvm::Type::isIntOrIntVectorTy().
|
static |
Definition at line 1134 of file AddressSanitizer.cpp.
References llvm::cast(), llvm::Type::getPointerAddressSpace(), llvm::Type::getScalarType(), llvm::Value::getType(), llvm::is_contained(), llvm::Triple::isAMDGPU(), and isUnsupportedAMDGPUAddrspace().
Definition at line 1125 of file AddressSanitizer.cpp.
References llvm::cast(), llvm::Type::getPointerAddressSpace(), llvm::Type::getScalarType(), and llvm::Value::getType().
Referenced by isSupportedAddrspace().
|
static |
Definition at line 3149 of file AddressSanitizer.cpp.
References assert(), kMaxStackMallocSize, kMinStackMallocSize, llvm_unreachable, and uint64_t.
| STATISTIC | ( | NumInstrumentedReads | , |
| "Number of instrumented reads" | ) |
| STATISTIC | ( | NumInstrumentedWrites | , |
| "Number of instrumented writes" | ) |
| STATISTIC | ( | NumOptimizedAccessesToGlobalVar | , |
| "Number of optimized accesses to global vars" | ) |
| STATISTIC | ( | NumOptimizedAccessesToStackVar | , |
| "Number of optimized accesses to stack vars" | ) |
References llvm::Offset, and uint64_t.
Definition at line 1100 of file AddressSanitizer.cpp.
References assert(), llvm::countr_zero(), and kNumberOfAccessSizes.
Definition at line 112 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
|
constexpr |
Definition at line 193 of file AddressSanitizer.cpp.
Referenced by llvm::ASanAccessInfo::ASanAccessInfo().
|
constexpr |
Definition at line 192 of file AddressSanitizer.cpp.
Referenced by llvm::ASanAccessInfo::ASanAccessInfo(), and llvm::ASanAccessInfo::ASanAccessInfo().
Definition at line 187 of file AddressSanitizer.cpp.
Definition at line 180 of file AddressSanitizer.cpp.
Definition at line 179 of file AddressSanitizer.cpp.
Definition at line 181 of file AddressSanitizer.cpp.
Definition at line 182 of file AddressSanitizer.cpp.
Definition at line 176 of file AddressSanitizer.cpp.
Definition at line 177 of file AddressSanitizer.cpp.
Definition at line 136 of file AddressSanitizer.cpp.
Referenced by GetCtorAndDtorPriority().
Definition at line 138 of file AddressSanitizer.cpp.
Referenced by GetCtorAndDtorPriority().
Definition at line 159 of file AddressSanitizer.cpp.
Referenced by genName(), and GlobalWasGeneratedByCompiler().
Definition at line 168 of file AddressSanitizer.cpp.
Definition at line 153 of file AddressSanitizer.cpp.
Definition at line 149 of file AddressSanitizer.cpp.
Definition at line 134 of file AddressSanitizer.cpp.
Definition at line 135 of file AddressSanitizer.cpp.
Definition at line 170 of file AddressSanitizer.cpp.
Definition at line 147 of file AddressSanitizer.cpp.
Definition at line 163 of file AddressSanitizer.cpp.
Definition at line 151 of file AddressSanitizer.cpp.
Definition at line 152 of file AddressSanitizer.cpp.
Definition at line 145 of file AddressSanitizer.cpp.
Definition at line 140 of file AddressSanitizer.cpp.
Definition at line 142 of file AddressSanitizer.cpp.
Definition at line 139 of file AddressSanitizer.cpp.
Referenced by llvm::AMDGPU::generateCrashCode().
Definition at line 162 of file AddressSanitizer.cpp.
Definition at line 173 of file AddressSanitizer.cpp.
Definition at line 158 of file AddressSanitizer.cpp.
Definition at line 156 of file AddressSanitizer.cpp.
Definition at line 155 of file AddressSanitizer.cpp.
Definition at line 148 of file AddressSanitizer.cpp.
Definition at line 164 of file AddressSanitizer.cpp.
Definition at line 146 of file AddressSanitizer.cpp.
Definition at line 141 of file AddressSanitizer.cpp.
Definition at line 143 of file AddressSanitizer.cpp.
Definition at line 150 of file AddressSanitizer.cpp.
|
constexpr |
Definition at line 191 of file AddressSanitizer.cpp.
Referenced by llvm::ASanAccessInfo::ASanAccessInfo().
|
constexpr |
Definition at line 190 of file AddressSanitizer.cpp.
Referenced by llvm::ASanAccessInfo::ASanAccessInfo(), and llvm::ASanAccessInfo::ASanAccessInfo().
Definition at line 131 of file AddressSanitizer.cpp.
Definition at line 100 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 101 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 99 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 102 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 115 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 116 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 117 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 118 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
|
constexpr |
Definition at line 195 of file AddressSanitizer.cpp.
Referenced by llvm::ASanAccessInfo::ASanAccessInfo().
|
constexpr |
Definition at line 194 of file AddressSanitizer.cpp.
Referenced by llvm::ASanAccessInfo::ASanAccessInfo(), and llvm::ASanAccessInfo::ASanAccessInfo().
Definition at line 106 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 113 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
|
static |
Definition at line 154 of file AddressSanitizer.cpp.
Definition at line 130 of file AddressSanitizer.cpp.
Referenced by StackMallocSizeClass().
Definition at line 129 of file AddressSanitizer.cpp.
Referenced by StackMallocSizeClass().
Definition at line 110 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 111 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 109 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 119 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 120 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 121 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 185 of file AddressSanitizer.cpp.
Referenced by TypeSizeToSizeIndex(), TypeSizeToSizeIndex(), and TypeStoreSizeToSizeIndex().
Definition at line 160 of file AddressSanitizer.cpp.
Referenced by GlobalWasGeneratedByCompiler().
Definition at line 107 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 122 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 132 of file AddressSanitizer.cpp.
|
static |
Definition at line 114 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 161 of file AddressSanitizer.cpp.
Referenced by GlobalWasGeneratedByCompiler().
Definition at line 105 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 104 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 108 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 124 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
Definition at line 123 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().
|
static |
Definition at line 127 of file AddressSanitizer.cpp.
Referenced by getShadowMapping().