by ignoring globals from __TEXT,__cstring,cstring_literals during instrumenation.
Add a regression test.

llvm-svn: 203916
This commit is contained in:
Alexander Potapenko 2014-03-14 10:41:49 +00:00
parent 4d97203add
commit b76ea32834
3 changed files with 35 additions and 3 deletions

View File

@ -0,0 +1,23 @@
// Regression test for
// https://code.google.com/p/address-sanitizer/issues/detail?id=274.
// RUN: %clang_asan %s -framework Foundation -o %t
// RUN: %t 2>&1 | FileCheck %s
#import <Foundation/Foundation.h>
#include <stdio.h>
int main() {
NSString* version_file = @"MAJOR=35\n";
int major = 0, minor = 0, build = 0, patch = 0;
NSScanner* scanner = [NSScanner scannerWithString:version_file];
NSString *res = nil;
if ([scanner scanString:@"MAJOR=" intoString:nil] &&
[scanner scanInt:&major]) {
res = [NSString stringWithFormat:@"%d.%d.%d.%d",
major, minor, build, patch];
}
printf("%s\n", [res UTF8String]);
// CHECK: 35.0.0.0
return 0;
}

View File

@ -81,6 +81,9 @@ if config.compiler_id == 'GNU':
# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']
if config.host_os == 'Darwin':
config.suffixes.append('.mm')
# AddressSanitizer tests are currently supported on Linux and Darwin only.
if config.host_os not in ['Linux', 'Darwin']:
config.unsupported = True

View File

@ -895,7 +895,7 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) {
// our redzones get broken.
if ((G->getName().find("\01L_OBJC_") == 0) ||
(G->getName().find("\01l_OBJC_") == 0)) {
DEBUG(dbgs() << "Ignoring \\01L_OBJC_* global: " << *G);
DEBUG(dbgs() << "Ignoring \\01L_OBJC_* global: " << *G << "\n");
return false;
}
@ -906,7 +906,7 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) {
// them.
if ((Section.find("__OBJC,") == 0) ||
(Section.find("__DATA, __objc_") == 0)) {
DEBUG(dbgs() << "Ignoring ObjC runtime global: " << *G);
DEBUG(dbgs() << "Ignoring ObjC runtime global: " << *G << "\n");
return false;
}
// See http://code.google.com/p/address-sanitizer/issues/detail?id=32
@ -918,7 +918,13 @@ bool AddressSanitizerModule::ShouldInstrumentGlobal(GlobalVariable *G) {
// Therefore there's no point in placing redzones into __DATA,__cfstring.
// Moreover, it causes the linker to crash on OS X 10.7
if (Section.find("__DATA,__cfstring") == 0) {
DEBUG(dbgs() << "Ignoring CFString: " << *G);
DEBUG(dbgs() << "Ignoring CFString: " << *G << "\n");
return false;
}
// The linker merges the contents of cstring_literals and removes the
// trailing zeroes.
if (Section.find("__TEXT,__cstring,cstring_literals") == 0) {
DEBUG(dbgs() << "Ignoring a cstring literal: " << *G << "\n");
return false;
}
}