diff options
author | Reid Kleckner <rnk@google.com> | 2018-06-11 16:49:43 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-06-11 16:49:43 +0000 |
commit | 3513fdcc0fa16ef7933b43a129de568b161ab628 (patch) | |
tree | bdfae1a546aa381370f264142429e942f15ce427 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | ae7179414d0dc5404c583b08f8d54fc77f7baaf0 (diff) | |
download | bcm5719-llvm-3513fdcc0fa16ef7933b43a129de568b161ab628.tar.gz bcm5719-llvm-3513fdcc0fa16ef7933b43a129de568b161ab628.zip |
[MS] Use mangled names and comdats for string merging with ASan
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.
llvm-svn: 334417
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 19cfffd81c4..814eda4381b 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -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 { |