diff options
author | Bill Wendling <isanbard@gmail.com> | 2012-01-10 08:46:39 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2012-01-10 08:46:39 +0000 |
commit | 86131f2c8d35dd75fd563b0b64c659bfa7e5268e (patch) | |
tree | 81e7f32c07db546c49023753f79274b9a267be77 | |
parent | 430f3f1bd6b89b4d4c1bcc8e7182f76b651f6963 (diff) | |
download | bcm5719-llvm-86131f2c8d35dd75fd563b0b64c659bfa7e5268e.tar.gz bcm5719-llvm-86131f2c8d35dd75fd563b0b64c659bfa7e5268e.zip |
The `-fwritable-strings' flag doesn't make the backing store strings of all
CFStrings writable.
The strings (both Unicode and ASCII) should reside in a read-only section. E.g.,
__TEXT,__cstring instead of __DATA,__data. This is done by making the global
variable created for the strings constant despite the value of that flag.
<rdar://problem/10657500>
llvm-svn: 147845
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 16 | ||||
-rw-r--r-- | clang/test/CodeGen/cfstring.c | 10 |
2 files changed, 16 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 9e772b40c45..76918dd4484 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1848,24 +1848,20 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { llvm::Constant *C = llvm::ConstantArray::get(VMContext, Entry.getKey().str()); llvm::GlobalValue::LinkageTypes Linkage; - bool isConstant; - if (isUTF16) { + if (isUTF16) // FIXME: why do utf strings get "_" labels instead of "L" labels? Linkage = llvm::GlobalValue::InternalLinkage; - // Note: -fwritable-strings doesn't make unicode CFStrings writable, but - // does make plain ascii ones writable. - isConstant = true; - } else { + else // FIXME: With OS X ld 123.2 (xcode 4) and LTO we would get a linker error // when using private linkage. It is not clear if this is a bug in ld // or a reasonable new restriction. Linkage = llvm::GlobalValue::LinkerPrivateLinkage; - isConstant = !Features.WritableStrings; - } + // Note: -fwritable-strings doesn't make the backing store strings of + // CFStrings writable. (See <rdar://problem/10657500>) llvm::GlobalVariable *GV = - new llvm::GlobalVariable(getModule(), C->getType(), isConstant, Linkage, C, - ".str"); + new llvm::GlobalVariable(getModule(), C->getType(), /*isConstant=*/true, + Linkage, C, ".str"); GV->setUnnamedAddr(true); if (isUTF16) { CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy); diff --git a/clang/test/CodeGen/cfstring.c b/clang/test/CodeGen/cfstring.c index 1f0977f0398..9d98b56e6b8 100644 --- a/clang/test/CodeGen/cfstring.c +++ b/clang/test/CodeGen/cfstring.c @@ -1,4 +1,14 @@ // RUN: %clang_cc1 -emit-llvm %s -o %t + +// <rdar://problem/10657500>: Check that the backing store of CFStrings are +// constant with the -fwritable-strings flag. +// +// RUN: %clang_cc1 -fwritable-strings -emit-llvm %s -o - | FileCheck %s +// +// CHECK: @.str = linker_private unnamed_addr constant [14 x i8] c"Hello, World!\00", align 1 +// CHECK: @.str1 = linker_private unnamed_addr constant [7 x i8] c"yo joe\00", align 1 +// CHECK: @.str3 = linker_private unnamed_addr constant [16 x i8] c"Goodbye, World!\00", align 1 + #define CFSTR __builtin___CFStringMakeConstantString void f() { |