Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | |||||
#include <sstream> | #include <sstream> | ||||
#include <string> | #include <string> | ||||
#include <tuple> | #include <tuple> | ||||
using namespace llvm; | using namespace llvm; | ||||
#define DEBUG_TYPE "asan" | #define DEBUG_TYPE "asan" | ||||
#if defined(OVERRIDE_SHADOW_SCALE) | |||||
static const uint64_t kDefaultShadowScale = OVERRIDE_SHADOW_SCALE; | |||||
#else | |||||
static const uint64_t kDefaultShadowScale = 3; | static const uint64_t kDefaultShadowScale = 3; | ||||
#endif | |||||
static const uint64_t kDefaultShadowOffset32 = 1ULL << 29; | static const uint64_t kDefaultShadowOffset32 = 1ULL << 29; | ||||
static const uint64_t kDefaultShadowOffset64 = 1ULL << 44; | static const uint64_t kDefaultShadowOffset64 = 1ULL << 44; | ||||
static const uint64_t kDynamicShadowSentinel = | static const uint64_t kDynamicShadowSentinel = | ||||
std::numeric_limits<uint64_t>::max(); | std::numeric_limits<uint64_t>::max(); | ||||
static const uint64_t kIOSShadowOffset32 = 1ULL << 30; | static const uint64_t kIOSShadowOffset32 = 1ULL << 30; | ||||
static const uint64_t kIOSSimShadowOffset32 = 1ULL << 30; | static const uint64_t kIOSSimShadowOffset32 = 1ULL << 30; | ||||
static const uint64_t kIOSSimShadowOffset64 = kDefaultShadowOffset64; | static const uint64_t kIOSSimShadowOffset64 = kDefaultShadowOffset64; | ||||
static const uint64_t kSmallX86_64ShadowOffset = 0x7FFF8000; // < 2G. | static const uint64_t kSmallX86_64ShadowOffset = | ||||
0x7FFFFFFF & ~((1 << (12 + kDefaultShadowScale)) - 1); // < 2G. | |||||
static const uint64_t kLinuxKasan_ShadowOffset64 = 0xdffffc0000000000; | static const uint64_t kLinuxKasan_ShadowOffset64 = 0xdffffc0000000000; | ||||
static const uint64_t kPPC64_ShadowOffset64 = 1ULL << 41; | static const uint64_t kPPC64_ShadowOffset64 = 1ULL << 41; | ||||
static const uint64_t kSystemZ_ShadowOffset64 = 1ULL << 52; | static const uint64_t kSystemZ_ShadowOffset64 = 1ULL << 52; | ||||
static const uint64_t kMIPS32_ShadowOffset32 = 0x0aaa0000; | static const uint64_t kMIPS32_ShadowOffset32 = 0x0aaa0000; | ||||
static const uint64_t kMIPS64_ShadowOffset64 = 1ULL << 37; | static const uint64_t kMIPS64_ShadowOffset64 = 1ULL << 37; | ||||
static const uint64_t kAArch64_ShadowOffset64 = 1ULL << 36; | static const uint64_t kAArch64_ShadowOffset64 = 1ULL << 36; | ||||
static const uint64_t kFreeBSD_ShadowOffset32 = 1ULL << 30; | static const uint64_t kFreeBSD_ShadowOffset32 = 1ULL << 30; | ||||
static const uint64_t kFreeBSD_ShadowOffset64 = 1ULL << 46; | static const uint64_t kFreeBSD_ShadowOffset64 = 1ULL << 46; | ||||
▲ Show 20 Lines • Show All 1,838 Lines • ▼ Show 20 Lines | void AddressSanitizerModule::InstrumentGlobalsWithMetadataArray( | ||||
// On platforms that don't have a custom metadata section, we emit an array | // On platforms that don't have a custom metadata section, we emit an array | ||||
// of global metadata structures. | // of global metadata structures. | ||||
ArrayType *ArrayOfGlobalStructTy = | ArrayType *ArrayOfGlobalStructTy = | ||||
ArrayType::get(MetadataInitializers[0]->getType(), N); | ArrayType::get(MetadataInitializers[0]->getType(), N); | ||||
auto AllGlobals = new GlobalVariable( | auto AllGlobals = new GlobalVariable( | ||||
M, ArrayOfGlobalStructTy, false, GlobalVariable::InternalLinkage, | M, ArrayOfGlobalStructTy, false, GlobalVariable::InternalLinkage, | ||||
ConstantArray::get(ArrayOfGlobalStructTy, MetadataInitializers), ""); | ConstantArray::get(ArrayOfGlobalStructTy, MetadataInitializers), ""); | ||||
if (Mapping.Scale > 3) | |||||
AllGlobals->setAlignment(1ULL << Mapping.Scale); | |||||
IRB.CreateCall(AsanRegisterGlobals, | IRB.CreateCall(AsanRegisterGlobals, | ||||
{IRB.CreatePointerCast(AllGlobals, IntptrTy), | {IRB.CreatePointerCast(AllGlobals, IntptrTy), | ||||
ConstantInt::get(IntptrTy, N)}); | ConstantInt::get(IntptrTy, N)}); | ||||
// We also need to unregister globals at the end, e.g., when a shared library | // We also need to unregister globals at the end, e.g., when a shared library | ||||
// gets closed. | // gets closed. | ||||
IRBuilder<> IRB_Dtor = CreateAsanModuleDtor(M); | IRBuilder<> IRB_Dtor = CreateAsanModuleDtor(M); | ||||
▲ Show 20 Lines • Show All 792 Lines • ▼ Show 20 Lines | ASanStackVariableDescription D = {AI->getName().data(), | ||||
AI, | AI, | ||||
0, | 0, | ||||
0}; | 0}; | ||||
SVD.push_back(D); | SVD.push_back(D); | ||||
} | } | ||||
// Minimal header size (left redzone) is 4 pointers, | // Minimal header size (left redzone) is 4 pointers, | ||||
// i.e. 32 bytes on 64-bit platforms and 16 bytes in 32-bit platforms. | // i.e. 32 bytes on 64-bit platforms and 16 bytes in 32-bit platforms. | ||||
size_t MinHeaderSize = ASan.LongSize / 2; | size_t Granularity = 1ULL << Mapping.Scale; | ||||
size_t MinHeaderSize = std::max((size_t)ASan.LongSize / 2, Granularity); | |||||
const ASanStackFrameLayout &L = | const ASanStackFrameLayout &L = | ||||
ComputeASanStackFrameLayout(SVD, 1ULL << Mapping.Scale, MinHeaderSize); | ComputeASanStackFrameLayout(SVD, Granularity, MinHeaderSize); | ||||
// Build AllocaToSVDMap for ASanStackVariableDescription lookup. | // Build AllocaToSVDMap for ASanStackVariableDescription lookup. | ||||
DenseMap<const AllocaInst *, ASanStackVariableDescription *> AllocaToSVDMap; | DenseMap<const AllocaInst *, ASanStackVariableDescription *> AllocaToSVDMap; | ||||
for (auto &Desc : SVD) | for (auto &Desc : SVD) | ||||
AllocaToSVDMap[Desc.AI] = &Desc; | AllocaToSVDMap[Desc.AI] = &Desc; | ||||
// Update SVD with information from lifetime intrinsics. | // Update SVD with information from lifetime intrinsics. | ||||
for (const auto &APC : StaticAllocaPoisonCallVec) { | for (const auto &APC : StaticAllocaPoisonCallVec) { | ||||
▲ Show 20 Lines • Show All 325 Lines • Show Last 20 Lines |