LLVM  14.0.0git
Macros | Functions | Variables
HWAddressSanitizer.cpp File Reference
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/StackSafetyAnalysis.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/InstVisitor.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/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/PassRegistry.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizerCommon.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include <sstream>
Include dependency graph for HWAddressSanitizer.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "hwasan"
 

Functions

 INITIALIZE_PASS_BEGIN (HWAddressSanitizerLegacyPass, "hwasan", "HWAddressSanitizer: detect memory bugs using tagged addressing.", false, false) INITIALIZE_PASS_END(HWAddressSanitizerLegacyPass
 
static unsigned getPointerOperandIndex (Instruction *I)
 
static size_t TypeSizeToSizeIndex (uint32_t TypeSize)
 
static uint64_t getAllocaSizeInBytes (const AllocaInst &AI)
 
static bool maybeReachableFromEachOther (const SmallVectorImpl< IntrinsicInst * > &Insts, const DominatorTree &DT)
 
static DenseSet< GlobalVariable * > getExcludedGlobals (Module &M)
 

Variables

const char kHwasanModuleCtorName [] = "hwasan.module_ctor"
 
const char kHwasanNoteName [] = "hwasan.note"
 
const char kHwasanInitName [] = "__hwasan_init"
 
const char kHwasanPersonalityThunkName [] = "__hwasan_personality_thunk"
 
const char kHwasanShadowMemoryDynamicAddress []
 
static const size_t kNumberOfAccessSizes = 5
 
static const size_t kDefaultShadowScale = 4
 
static const uint64_t kDynamicShadowSentinel
 
static const unsigned kShadowBaseAlignment = 32
 
static cl::opt< std::string > ClMemoryAccessCallbackPrefix ("hwasan-memory-access-callback-prefix", cl::desc("Prefix for memory access callbacks"), cl::Hidden, cl::init("__hwasan_"))
 
static cl::opt< bool > ClInstrumentWithCalls ("hwasan-instrument-with-calls", cl::desc("instrument reads and writes with callbacks"), cl::Hidden, cl::init(false))
 
static cl::opt< bool > ClInstrumentReads ("hwasan-instrument-reads", cl::desc("instrument read instructions"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClInstrumentWrites ("hwasan-instrument-writes", cl::desc("instrument write instructions"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClInstrumentAtomics ("hwasan-instrument-atomics", cl::desc("instrument atomic instructions (rmw, cmpxchg)"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClInstrumentByval ("hwasan-instrument-byval", cl::desc("instrument byval arguments"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClRecover ("hwasan-recover", cl::desc("Enable recovery mode (continue-after-error)."), cl::Hidden, cl::init(false))
 
static cl::opt< bool > ClInstrumentStack ("hwasan-instrument-stack", cl::desc("instrument stack (allocas)"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClUseStackSafety ("hwasan-use-stack-safety", cl::Hidden, cl::init(true), cl::Hidden, cl::desc("Use Stack Safety analysis results"), cl::Optional)
 
static cl::opt< size_t > ClMaxLifetimes ("hwasan-max-lifetimes-for-alloca", cl::Hidden, cl::init(3), cl::ReallyHidden, cl::desc("How many lifetime ends to handle for a single alloca."), cl::Optional)
 
static cl::opt< bool > ClUseAfterScope ("hwasan-use-after-scope", cl::desc("detect use after scope within function"), cl::Hidden, cl::init(false))
 
static cl::opt< bool > ClUARRetagToZero ("hwasan-uar-retag-to-zero", cl::desc("Clear alloca tags before returning from the function to allow " "non-instrumented and instrumented function calls mix. When set " "to false, allocas are retagged before returning from the " "function to detect use after return."), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClGenerateTagsWithCalls ("hwasan-generate-tags-with-calls", cl::desc("generate new tags with runtime library calls"), cl::Hidden, cl::init(false))
 
static cl::opt< bool > ClGlobals ("hwasan-globals", cl::desc("Instrument globals"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
 
static cl::opt< intClMatchAllTag ("hwasan-match-all-tag", cl::desc("don't report bad accesses via pointers with this tag"), cl::Hidden, cl::init(-1))
 
static cl::opt< bool > ClEnableKhwasan ("hwasan-kernel", cl::desc("Enable KernelHWAddressSanitizer instrumentation"), cl::Hidden, cl::init(false))
 
static cl::opt< uint64_tClMappingOffset ("hwasan-mapping-offset", cl::desc("HWASan shadow mapping offset [EXPERIMENTAL]"), cl::Hidden, cl::init(0))
 
static cl::opt< bool > ClWithIfunc ("hwasan-with-ifunc", cl::desc("Access dynamic shadow through an ifunc global on " "platforms that support this"), cl::Hidden, cl::init(false))
 
static cl::opt< bool > ClWithTls ("hwasan-with-tls", cl::desc("Access dynamic shadow through an thread-local pointer on " "platforms that support this"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClRecordStackHistory ("hwasan-record-stack-history", cl::desc("Record stack frames with tagged allocations " "in a thread-local ring buffer"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClInstrumentMemIntrinsics ("hwasan-instrument-mem-intrinsics", cl::desc("instrument memory intrinsics"), cl::Hidden, cl::init(true))
 
static cl::opt< bool > ClInstrumentLandingPads ("hwasan-instrument-landing-pads", cl::desc("instrument landing pads"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
 
static cl::opt< bool > ClUseShortGranules ("hwasan-use-short-granules", cl::desc("use short granules in allocas and outlined checks"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
 
static cl::opt< bool > ClInstrumentPersonalityFunctions ("hwasan-instrument-personality-functions", cl::desc("instrument personality functions"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
 
static cl::opt< bool > ClInlineAllChecks ("hwasan-inline-all-checks", cl::desc("inline all checks"), cl::Hidden, cl::init(false))
 
static cl::opt< bool > ClUsePageAliases ("hwasan-experimental-use-page-aliases", cl::desc("Use page aliasing in HWASan"), cl::Hidden, cl::init(false))
 
 hwasan
 
HWAddressSanitizer __pad0__
 
HWAddressSanitizer false
 

Detailed Description

This file is a part of HWAddressSanitizer, an address sanity checker based on tagged addressing.

Definition in file HWAddressSanitizer.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "hwasan"

Definition at line 62 of file HWAddressSanitizer.cpp.

Function Documentation

◆ getAllocaSizeInBytes()

static uint64_t getAllocaSizeInBytes ( const AllocaInst AI)
static

◆ getExcludedGlobals()

static DenseSet<GlobalVariable *> getExcludedGlobals ( Module M)
static

◆ getPointerOperandIndex()

static unsigned getPointerOperandIndex ( Instruction I)
static

Definition at line 851 of file HWAddressSanitizer.cpp.

References I, llvm::report_fatal_error(), and SI.

Referenced by FindAllMemoryUses().

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( HWAddressSanitizerLegacyPass  ,
"hwasan"  ,
"HWAddressSanitizer: detect memory bugs using tagged addressing."  ,
false  ,
false   
)

◆ maybeReachableFromEachOther()

static bool maybeReachableFromEachOther ( const SmallVectorImpl< IntrinsicInst * > &  Insts,
const DominatorTree DT 
)
static

Definition at line 1322 of file HWAddressSanitizer.cpp.

References ClMaxLifetimes, I, and llvm::isPotentiallyReachable().

◆ TypeSizeToSizeIndex()

static size_t TypeSizeToSizeIndex ( uint32_t  TypeSize)
static

Variable Documentation

◆ __pad0__

HWAddressSanitizer __pad0__

Definition at line 477 of file HWAddressSanitizer.cpp.

◆ ClEnableKhwasan

cl::opt<bool> ClEnableKhwasan("hwasan-kernel", cl::desc("Enable KernelHWAddressSanitizer instrumentation"), cl::Hidden, cl::init(false))
static

◆ ClGenerateTagsWithCalls

cl::opt<bool> ClGenerateTagsWithCalls("hwasan-generate-tags-with-calls", cl::desc("generate new tags with runtime library calls"), cl::Hidden, cl::init(false))
static

◆ ClGlobals

cl::opt<bool> ClGlobals("hwasan-globals", cl::desc("Instrument globals"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
static

◆ ClInlineAllChecks

cl::opt<bool> ClInlineAllChecks("hwasan-inline-all-checks", cl::desc("inline all checks"), cl::Hidden, cl::init(false))
static

◆ ClInstrumentAtomics

cl::opt<bool> ClInstrumentAtomics("hwasan-instrument-atomics", cl::desc("instrument atomic instructions (rmw, cmpxchg)"), cl::Hidden, cl::init(true))
static

◆ ClInstrumentByval

cl::opt<bool> ClInstrumentByval("hwasan-instrument-byval", cl::desc("instrument byval arguments"), cl::Hidden, cl::init(true))
static

◆ ClInstrumentLandingPads

cl::opt<bool> ClInstrumentLandingPads("hwasan-instrument-landing-pads", cl::desc("instrument landing pads"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
static

◆ ClInstrumentMemIntrinsics

cl::opt<bool> ClInstrumentMemIntrinsics("hwasan-instrument-mem-intrinsics", cl::desc("instrument memory intrinsics"), cl::Hidden, cl::init(true))
static

◆ ClInstrumentPersonalityFunctions

cl::opt<bool> ClInstrumentPersonalityFunctions("hwasan-instrument-personality-functions", cl::desc("instrument personality functions"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
static

◆ ClInstrumentReads

cl::opt<bool> ClInstrumentReads("hwasan-instrument-reads", cl::desc("instrument read instructions"), cl::Hidden, cl::init(true))
static

◆ ClInstrumentStack

cl::opt<bool> ClInstrumentStack("hwasan-instrument-stack", cl::desc("instrument stack (allocas)"), cl::Hidden, cl::init(true))
static

◆ ClInstrumentWithCalls

cl::opt<bool> ClInstrumentWithCalls("hwasan-instrument-with-calls", cl::desc("instrument reads and writes with callbacks"), cl::Hidden, cl::init(false))
static

◆ ClInstrumentWrites

cl::opt<bool> ClInstrumentWrites("hwasan-instrument-writes", cl::desc("instrument write instructions"), cl::Hidden, cl::init(true))
static

◆ ClMappingOffset

cl::opt<uint64_t> ClMappingOffset("hwasan-mapping-offset", cl::desc("HWASan shadow mapping offset [EXPERIMENTAL]"), cl::Hidden, cl::init(0))
static

◆ ClMatchAllTag

cl::opt<int> ClMatchAllTag("hwasan-match-all-tag", cl::desc("don't report bad accesses via pointers with this tag"), cl::Hidden, cl::init(-1))
static

◆ ClMaxLifetimes

cl::opt<size_t> ClMaxLifetimes("hwasan-max-lifetimes-for-alloca", cl::Hidden, cl::init(3), cl::ReallyHidden, cl::desc("How many lifetime ends to handle for a single alloca."), cl::Optional)
static

◆ ClMemoryAccessCallbackPrefix

cl::opt<std::string> ClMemoryAccessCallbackPrefix("hwasan-memory-access-callback-prefix", cl::desc("Prefix for memory access callbacks"), cl::Hidden, cl::init("__hwasan_"))
static

◆ ClRecordStackHistory

cl::opt<bool> ClRecordStackHistory("hwasan-record-stack-history", cl::desc("Record stack frames with tagged allocations " "in a thread-local ring buffer"), cl::Hidden, cl::init(true))
static

◆ ClRecover

cl::opt<bool> ClRecover("hwasan-recover", cl::desc("Enable recovery mode (continue-after-error)."), cl::Hidden, cl::init(false))
static

◆ ClUARRetagToZero

cl::opt<bool> ClUARRetagToZero("hwasan-uar-retag-to-zero", cl::desc("Clear alloca tags before returning from the function to allow " "non-instrumented and instrumented function calls mix. When set " "to false, allocas are retagged before returning from the " "function to detect use after return."), cl::Hidden, cl::init(true))
static

◆ ClUseAfterScope

cl::opt<bool> ClUseAfterScope("hwasan-use-after-scope", cl::desc("detect use after scope within function"), cl::Hidden, cl::init(false))
static

◆ ClUsePageAliases

cl::opt<bool> ClUsePageAliases("hwasan-experimental-use-page-aliases", cl::desc("Use page aliasing in HWASan"), cl::Hidden, cl::init(false))
static

◆ ClUseShortGranules

cl::opt<bool> ClUseShortGranules("hwasan-use-short-granules", cl::desc("use short granules in allocas and outlined checks"), cl::Hidden, cl::init(false), cl::ZeroOrMore)
static

◆ ClUseStackSafety

cl::opt<bool> ClUseStackSafety("hwasan-use-stack-safety", cl::Hidden, cl::init(true), cl::Hidden, cl::desc("Use Stack Safety analysis results"), cl::Optional)
static

◆ ClWithIfunc

cl::opt<bool> ClWithIfunc("hwasan-with-ifunc", cl::desc("Access dynamic shadow through an ifunc global on " "platforms that support this"), cl::Hidden, cl::init(false))
static

◆ ClWithTls

cl::opt<bool> ClWithTls("hwasan-with-tls", cl::desc("Access dynamic shadow through an thread-local pointer on " "platforms that support this"), cl::Hidden, cl::init(true))
static

◆ false

HWAddressSanitizer false

Definition at line 477 of file HWAddressSanitizer.cpp.

◆ hwasan

hwasan

Definition at line 476 of file HWAddressSanitizer.cpp.

◆ kDefaultShadowScale

const size_t kDefaultShadowScale = 4
static

Definition at line 75 of file HWAddressSanitizer.cpp.

◆ kDynamicShadowSentinel

const uint64_t kDynamicShadowSentinel
static
Initial value:

Definition at line 76 of file HWAddressSanitizer.cpp.

◆ kHwasanInitName

const char kHwasanInitName[] = "__hwasan_init"

Definition at line 66 of file HWAddressSanitizer.cpp.

◆ kHwasanModuleCtorName

const char kHwasanModuleCtorName[] = "hwasan.module_ctor"

Definition at line 64 of file HWAddressSanitizer.cpp.

◆ kHwasanNoteName

const char kHwasanNoteName[] = "hwasan.note"

Definition at line 65 of file HWAddressSanitizer.cpp.

◆ kHwasanPersonalityThunkName

const char kHwasanPersonalityThunkName[] = "__hwasan_personality_thunk"

Definition at line 67 of file HWAddressSanitizer.cpp.

◆ kHwasanShadowMemoryDynamicAddress

const char kHwasanShadowMemoryDynamicAddress[]
Initial value:
=
"__hwasan_shadow_memory_dynamic_address"

Definition at line 69 of file HWAddressSanitizer.cpp.

◆ kNumberOfAccessSizes

const size_t kNumberOfAccessSizes = 5
static

Definition at line 73 of file HWAddressSanitizer.cpp.

Referenced by TypeSizeToSizeIndex().

◆ kShadowBaseAlignment

const unsigned kShadowBaseAlignment = 32
static

Definition at line 79 of file HWAddressSanitizer.cpp.

llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340