Add target hook for setting symbol prefix and section of unicode
string literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68363 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index ce55ec8..5f5ba60 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -658,6 +658,14 @@
return IsConstant ? "\01LC" : "\01lC";
}
+ virtual const char *getUnicodeStringSymbolPrefix() const {
+ return "__utf16_string_";
+ }
+
+ virtual const char *getUnicodeStringSection() const {
+ return "__TEXT,__ustring";
+ }
+
virtual const char *getCFStringSymbolPrefix() const {
return "\01LC";
}
@@ -810,6 +818,14 @@
return IsConstant ? "\01LC" : "\01lC";
}
+ virtual const char *getUnicodeStringSymbolPrefix() const {
+ return "__utf16_string_";
+ }
+
+ virtual const char *getUnicodeStringSection() const {
+ return "__TEXT,__ustring";
+ }
+
virtual const char *getCFStringSymbolPrefix() const {
return "\01L_unnamed_cfstring_";
}
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index fa475ce..1132c3f 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -1082,13 +1082,31 @@
CurField = NextField;
NextField = *Field++;
llvm::Constant *C = llvm::ConstantArray::get(str);
+
+ const char *Sect, *Prefix;
+ bool isConstant;
+ if (isUTF16) {
+ Prefix = getContext().Target.getUnicodeStringSymbolPrefix();
+ Sect = getContext().Target.getUnicodeStringSection();
+ // FIXME: Why does GCC not set constant here?
+ isConstant = false;
+ } else {
+ Prefix = getContext().Target.getStringSymbolPrefix(true);
+ Sect = getContext().Target.getCFStringDataSection();
+ // FIXME: -fwritable-strings should probably affect this, but we
+ // are following gcc here.
+ isConstant = true;
+ }
llvm::GlobalVariable *GV =
- new llvm::GlobalVariable(C->getType(), true,
+ new llvm::GlobalVariable(C->getType(), isConstant,
llvm::GlobalValue::InternalLinkage,
- C, getContext().Target.getStringSymbolPrefix(true),
- &getModule());
- if (const char *Sect = getContext().Target.getCFStringDataSection())
+ C, Prefix, &getModule());
+ if (Sect)
GV->setSection(Sect);
+ if (isUTF16) {
+ unsigned Align = getContext().getTypeAlign(getContext().ShortTy)/8;
+ GV->setAlignment(Align);
+ }
appendFieldAndPadding(*this, Fields, CurField, NextField,
llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2),
CFRD, STy);