aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0c75cf1..cd278e6 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3092,19 +3092,19 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
llvm::Constant *Zero = llvm::Constant::getNullValue(Int32Ty);
llvm::Constant *Zeros[] = { Zero, Zero };
llvm::Value *V;
-
+
// If we don't already have it, get __CFConstantStringClassReference.
if (!CFConstantStringClassRef) {
llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);
Ty = llvm::ArrayType::get(Ty, 0);
- llvm::Constant *GV = CreateRuntimeVariable(Ty,
- "__CFConstantStringClassReference");
+ llvm::Constant *GV =
+ CreateRuntimeVariable(Ty, "__CFConstantStringClassReference");
// Decay array -> ptr
V = llvm::ConstantExpr::getGetElementPtr(Ty, GV, Zeros);
CFConstantStringClassRef = V;
- }
- else
+ } else {
V = CFConstantStringClassRef;
+ }
QualType CFTy = getContext().getCFConstantStringType();
@@ -3117,8 +3117,8 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
// Flags.
llvm::Type *Ty = getTypes().ConvertType(getContext().UnsignedIntTy);
- Fields[1] = isUTF16 ? llvm::ConstantInt::get(Ty, 0x07d0) :
- llvm::ConstantInt::get(Ty, 0x07C8);
+ Fields[1] = isUTF16 ? llvm::ConstantInt::get(Ty, 0x07d0)
+ : llvm::ConstantInt::get(Ty, 0x07C8);
// String pointer.
llvm::Constant *C = nullptr;
@@ -3139,18 +3139,17 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
GV->setUnnamedAddr(true);
// Don't enforce the target's minimum global alignment, since the only use
// of the string is via this class initializer.
- // FIXME: We set the section explicitly to avoid a bug in ld64 224.1. Without
- // it LLVM can merge the string with a non unnamed_addr one during LTO. Doing
- // that changes the section it ends in, which surprises ld64.
- if (isUTF16) {
- CharUnits Align = getContext().getTypeAlignInChars(getContext().ShortTy);
- GV->setAlignment(Align.getQuantity());
- GV->setSection("__TEXT,__ustring");
- } else {
- CharUnits Align = getContext().getTypeAlignInChars(getContext().CharTy);
- GV->setAlignment(Align.getQuantity());
- GV->setSection("__TEXT,__cstring,cstring_literals");
- }
+ CharUnits Align = isUTF16
+ ? getContext().getTypeAlignInChars(getContext().ShortTy)
+ : getContext().getTypeAlignInChars(getContext().CharTy);
+ GV->setAlignment(Align.getQuantity());
+
+ // FIXME: We set the section explicitly to avoid a bug in ld64 224.1.
+ // Without it LLVM can merge the string with a non unnamed_addr one during
+ // LTO. Doing that changes the section it ends in, which surprises ld64.
+ if (getTarget().getTriple().getObjectFormat() == llvm::Triple::MachO)
+ GV->setSection(isUTF16 ? "__TEXT,__ustring"
+ : "__TEXT,__cstring,cstring_literals");
// String.
Fields[2] =
@@ -3171,8 +3170,20 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
GV = new llvm::GlobalVariable(getModule(), C->getType(), true,
llvm::GlobalVariable::PrivateLinkage, C,
"_unnamed_cfstring_");
- GV->setSection("__DATA,__cfstring");
GV->setAlignment(Alignment.getQuantity());
+ switch (getTarget().getTriple().getObjectFormat()) {
+ case llvm::Triple::UnknownObjectFormat:
+ llvm_unreachable("unknown file format");
+ case llvm::Triple::COFF:
+ GV->setSection(".rdata.cfstring");
+ break;
+ case llvm::Triple::ELF:
+ GV->setSection(".rodata.cfstring");
+ break;
+ case llvm::Triple::MachO:
+ GV->setSection("__DATA,__cfstring");
+ break;
+ }
Entry.second = GV;
return ConstantAddress(GV, Alignment);