]> granicus.if.org Git - clang/commitdiff
[MS] Use mangled names and comdats for string merging with ASan
authorReid Kleckner <rnk@google.com>
Mon, 11 Jun 2018 16:49:43 +0000 (16:49 +0000)
committerReid Kleckner <rnk@google.com>
Mon, 11 Jun 2018 16:49:43 +0000 (16:49 +0000)
This should reduce the binary size penalty of ASan on Windows. After
r334313, ASan will add red zones to globals in comdats, so we will still
find OOB accesses to string literals.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334417 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp

index 19cfffd81c471b3e6dfc1a1233cecf88e5e0d1e4..814eda4381b546ca179bf9f5b404fa915e08af5b 100644 (file)
@@ -4114,15 +4114,13 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
   StringRef GlobalVariableName;
   llvm::GlobalValue::LinkageTypes LT;
 
-  // Mangle the string literal if the ABI allows for it.  However, we cannot
-  // do this if  we are compiling with ASan or -fwritable-strings because they
-  // rely on strings having normal linkage.
-  if (!LangOpts.WritableStrings &&
-      !LangOpts.Sanitize.has(SanitizerKind::Address) &&
-      getCXXABI().getMangleContext().shouldMangleStringLiteral(S)) {
+  // Mangle the string literal if that's how the ABI merges duplicate strings.
+  // Don't do it if they are writable, since we don't want writes in one TU to
+  // affect strings in another.
+  if (getCXXABI().getMangleContext().shouldMangleStringLiteral(S) &&
+      !LangOpts.WritableStrings) {
     llvm::raw_svector_ostream Out(MangledNameBuffer);
     getCXXABI().getMangleContext().mangleStringLiteral(S, Out);
-
     LT = llvm::GlobalValue::LinkOnceODRLinkage;
     GlobalVariableName = MangledNameBuffer;
   } else {