[asan] Remove -fsanitize-address-zero-base-shadow command line

flag from clang, and disable zero-base shadow support on all platforms
where it is not the default behavior.

- It is completely unused, as far as we know.
- It is ABI-incompatible with non-zero-base shadow, which means all
objects in a process must be built with the same setting. Failing to
do so results in a segmentation fault at runtime.
- It introduces a backward dependency of compiler-rt on user code,
which is uncommon and complicates testing.

This is the LLVM part of a larger change.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199371 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evgeniy Stepanov 2014-01-16 10:19:12 +00:00
parent 43a785be50
commit 6d49eafb00
2 changed files with 16 additions and 26 deletions

View File

@ -66,11 +66,9 @@ ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
// Insert AddressSanitizer (address sanity checking) instrumentation // Insert AddressSanitizer (address sanity checking) instrumentation
FunctionPass *createAddressSanitizerFunctionPass( FunctionPass *createAddressSanitizerFunctionPass(
bool CheckInitOrder = true, bool CheckUseAfterReturn = false, bool CheckInitOrder = true, bool CheckUseAfterReturn = false,
bool CheckLifetime = false, StringRef BlacklistFile = StringRef(), bool CheckLifetime = false, StringRef BlacklistFile = StringRef());
bool ZeroBaseShadow = false);
ModulePass *createAddressSanitizerModulePass( ModulePass *createAddressSanitizerModulePass(
bool CheckInitOrder = true, StringRef BlacklistFile = StringRef(), bool CheckInitOrder = true, StringRef BlacklistFile = StringRef());
bool ZeroBaseShadow = false);
// Insert MemorySanitizer instrumentation (detection of uninitialized reads) // Insert MemorySanitizer instrumentation (detection of uninitialized reads)
FunctionPass *createMemorySanitizerPass(bool TrackOrigins = false, FunctionPass *createMemorySanitizerPass(bool TrackOrigins = false,

View File

@ -234,8 +234,7 @@ struct ShadowMapping {
bool OrShadowOffset; bool OrShadowOffset;
}; };
static ShadowMapping getShadowMapping(const Module &M, int LongSize, static ShadowMapping getShadowMapping(const Module &M, int LongSize) {
bool ZeroBaseShadow) {
llvm::Triple TargetTriple(M.getTargetTriple()); llvm::Triple TargetTriple(M.getTargetTriple());
bool IsAndroid = TargetTriple.getEnvironment() == llvm::Triple::Android; bool IsAndroid = TargetTriple.getEnvironment() == llvm::Triple::Android;
bool IsMacOSX = TargetTriple.getOS() == llvm::Triple::MacOSX; bool IsMacOSX = TargetTriple.getOS() == llvm::Triple::MacOSX;
@ -252,15 +251,15 @@ static ShadowMapping getShadowMapping(const Module &M, int LongSize,
// 1/8-th of the address space. // 1/8-th of the address space.
Mapping.OrShadowOffset = !IsPPC64 && !ClShort64BitOffset; Mapping.OrShadowOffset = !IsPPC64 && !ClShort64BitOffset;
Mapping.Offset = (IsAndroid || ZeroBaseShadow) ? 0 : Mapping.Offset = IsAndroid ? 0 :
(LongSize == 32 ? (LongSize == 32 ?
(IsMIPS32 ? kMIPS32_ShadowOffset32 : kDefaultShadowOffset32) : (IsMIPS32 ? kMIPS32_ShadowOffset32 : kDefaultShadowOffset32) :
IsPPC64 ? kPPC64_ShadowOffset64 : kDefaultShadowOffset64); IsPPC64 ? kPPC64_ShadowOffset64 : kDefaultShadowOffset64);
if (!ZeroBaseShadow && ClShort64BitOffset && IsX86_64 && !IsMacOSX) { if (!IsAndroid && ClShort64BitOffset && IsX86_64 && !IsMacOSX) {
assert(LongSize == 64); assert(LongSize == 64);
Mapping.Offset = kDefaultShort64bitShadowOffset; Mapping.Offset = kDefaultShort64bitShadowOffset;
} }
if (!ZeroBaseShadow && ClMappingOffsetLog >= 0) { if (!IsAndroid && ClMappingOffsetLog >= 0) {
// Zero offset log is the special case. // Zero offset log is the special case.
Mapping.Offset = (ClMappingOffsetLog == 0) ? 0 : 1ULL << ClMappingOffsetLog; Mapping.Offset = (ClMappingOffsetLog == 0) ? 0 : 1ULL << ClMappingOffsetLog;
} }
@ -284,15 +283,13 @@ struct AddressSanitizer : public FunctionPass {
AddressSanitizer(bool CheckInitOrder = true, AddressSanitizer(bool CheckInitOrder = true,
bool CheckUseAfterReturn = false, bool CheckUseAfterReturn = false,
bool CheckLifetime = false, bool CheckLifetime = false,
StringRef BlacklistFile = StringRef(), StringRef BlacklistFile = StringRef())
bool ZeroBaseShadow = false)
: FunctionPass(ID), : FunctionPass(ID),
CheckInitOrder(CheckInitOrder || ClInitializers), CheckInitOrder(CheckInitOrder || ClInitializers),
CheckUseAfterReturn(CheckUseAfterReturn || ClUseAfterReturn), CheckUseAfterReturn(CheckUseAfterReturn || ClUseAfterReturn),
CheckLifetime(CheckLifetime || ClCheckLifetime), CheckLifetime(CheckLifetime || ClCheckLifetime),
BlacklistFile(BlacklistFile.empty() ? ClBlacklistFile BlacklistFile(BlacklistFile.empty() ? ClBlacklistFile
: BlacklistFile), : BlacklistFile) {}
ZeroBaseShadow(ZeroBaseShadow) {}
virtual const char *getPassName() const { virtual const char *getPassName() const {
return "AddressSanitizerFunctionPass"; return "AddressSanitizerFunctionPass";
} }
@ -329,7 +326,6 @@ struct AddressSanitizer : public FunctionPass {
bool CheckUseAfterReturn; bool CheckUseAfterReturn;
bool CheckLifetime; bool CheckLifetime;
SmallString<64> BlacklistFile; SmallString<64> BlacklistFile;
bool ZeroBaseShadow;
LLVMContext *C; LLVMContext *C;
DataLayout *TD; DataLayout *TD;
@ -354,13 +350,11 @@ struct AddressSanitizer : public FunctionPass {
class AddressSanitizerModule : public ModulePass { class AddressSanitizerModule : public ModulePass {
public: public:
AddressSanitizerModule(bool CheckInitOrder = true, AddressSanitizerModule(bool CheckInitOrder = true,
StringRef BlacklistFile = StringRef(), StringRef BlacklistFile = StringRef())
bool ZeroBaseShadow = false)
: ModulePass(ID), : ModulePass(ID),
CheckInitOrder(CheckInitOrder || ClInitializers), CheckInitOrder(CheckInitOrder || ClInitializers),
BlacklistFile(BlacklistFile.empty() ? ClBlacklistFile BlacklistFile(BlacklistFile.empty() ? ClBlacklistFile
: BlacklistFile), : BlacklistFile) {}
ZeroBaseShadow(ZeroBaseShadow) {}
bool runOnModule(Module &M); bool runOnModule(Module &M);
static char ID; // Pass identification, replacement for typeid static char ID; // Pass identification, replacement for typeid
virtual const char *getPassName() const { virtual const char *getPassName() const {
@ -378,7 +372,6 @@ class AddressSanitizerModule : public ModulePass {
bool CheckInitOrder; bool CheckInitOrder;
SmallString<64> BlacklistFile; SmallString<64> BlacklistFile;
bool ZeroBaseShadow;
OwningPtr<SpecialCaseList> BL; OwningPtr<SpecialCaseList> BL;
SetOfDynamicallyInitializedGlobals DynamicallyInitializedGlobals; SetOfDynamicallyInitializedGlobals DynamicallyInitializedGlobals;
@ -536,9 +529,9 @@ INITIALIZE_PASS(AddressSanitizer, "asan",
false, false) false, false)
FunctionPass *llvm::createAddressSanitizerFunctionPass( FunctionPass *llvm::createAddressSanitizerFunctionPass(
bool CheckInitOrder, bool CheckUseAfterReturn, bool CheckLifetime, bool CheckInitOrder, bool CheckUseAfterReturn, bool CheckLifetime,
StringRef BlacklistFile, bool ZeroBaseShadow) { StringRef BlacklistFile) {
return new AddressSanitizer(CheckInitOrder, CheckUseAfterReturn, return new AddressSanitizer(CheckInitOrder, CheckUseAfterReturn,
CheckLifetime, BlacklistFile, ZeroBaseShadow); CheckLifetime, BlacklistFile);
} }
char AddressSanitizerModule::ID = 0; char AddressSanitizerModule::ID = 0;
@ -546,9 +539,8 @@ INITIALIZE_PASS(AddressSanitizerModule, "asan-module",
"AddressSanitizer: detects use-after-free and out-of-bounds bugs." "AddressSanitizer: detects use-after-free and out-of-bounds bugs."
"ModulePass", false, false) "ModulePass", false, false)
ModulePass *llvm::createAddressSanitizerModulePass( ModulePass *llvm::createAddressSanitizerModulePass(
bool CheckInitOrder, StringRef BlacklistFile, bool ZeroBaseShadow) { bool CheckInitOrder, StringRef BlacklistFile) {
return new AddressSanitizerModule(CheckInitOrder, BlacklistFile, return new AddressSanitizerModule(CheckInitOrder, BlacklistFile);
ZeroBaseShadow);
} }
static size_t TypeSizeToSizeIndex(uint32_t TypeSize) { static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
@ -926,7 +918,7 @@ bool AddressSanitizerModule::runOnModule(Module &M) {
C = &(M.getContext()); C = &(M.getContext());
int LongSize = TD->getPointerSizeInBits(); int LongSize = TD->getPointerSizeInBits();
IntptrTy = Type::getIntNTy(*C, LongSize); IntptrTy = Type::getIntNTy(*C, LongSize);
Mapping = getShadowMapping(M, LongSize, ZeroBaseShadow); Mapping = getShadowMapping(M, LongSize);
initializeCallbacks(M); initializeCallbacks(M);
DynamicallyInitializedGlobals.Init(M); DynamicallyInitializedGlobals.Init(M);
@ -1133,7 +1125,7 @@ bool AddressSanitizer::doInitialization(Module &M) {
AsanInitFunction->setLinkage(Function::ExternalLinkage); AsanInitFunction->setLinkage(Function::ExternalLinkage);
IRB.CreateCall(AsanInitFunction); IRB.CreateCall(AsanInitFunction);
Mapping = getShadowMapping(M, LongSize, ZeroBaseShadow); Mapping = getShadowMapping(M, LongSize);
emitShadowMapping(M, IRB); emitShadowMapping(M, IRB);
appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndCtorPriority); appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndCtorPriority);