[asan] when creating string constants, set unnamed_attr and align 1 so that equal...
authorKostya Serebryany <kcc@google.com>
Mon, 18 Mar 2013 09:38:39 +0000 (09:38 +0000)
committerKostya Serebryany <kcc@google.com>
Mon, 18 Mar 2013 09:38:39 +0000 (09:38 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@177264 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/AddressSanitizer.cpp
test/Instrumentation/AddressSanitizer/do-not-instrument-internal-globals.ll

index 614dc210a03b84357d02e6cb112f188d41c893b7..92b42ee64b008de130a50b56748f162dae80e621 100644 (file)
@@ -531,9 +531,12 @@ static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
 // Create a constant for Str so that we can pass it to the run-time lib.
 static GlobalVariable *createPrivateGlobalForString(Module &M, StringRef Str) {
   Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
-  return new GlobalVariable(M, StrConst->getType(), true,
+  GlobalVariable *GV = new GlobalVariable(M, StrConst->getType(), true,
                             GlobalValue::PrivateLinkage, StrConst,
                             kAsanGenPrefix);
+  GV->setUnnamedAddr(true);  // Ok to merge these.
+  GV->setAlignment(1);  // Strings may not be merged w/o setting align 1.
+  return GV;
 }
 
 static bool GlobalWasGeneratedByAsan(GlobalVariable *G) {
index 2efd6b1e0d128e134d613ab97300ee51d9266ca9..0928c494154ef44918a03810546f2496487f4e75 100644 (file)
@@ -14,6 +14,7 @@ entry:
 
 declare void @_Z3fooPi(i32*)
 ; We create one global string constant for the stack frame above.
+; It should have unnamed_addr and align 1.
 ; Make sure we don't create any other global constants.
-; CHECK: = private constant
-; CHECK-NOT: = private constant
+; CHECK: = private unnamed_addr constant{{.*}}align 1
+; CHECK-NOT: = private unnamed_addr constant