diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-05-30 16:23:07 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2016-05-30 16:23:07 +0000 |
commit | f7444e645beec5f9aa7d52f28539affbcfee6f38 (patch) | |
tree | 2478425c262bed62271f0fba595046f35ea3f52c /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 6885229cb8f5e6115784469ea55afc254cd549bb (diff) | |
download | bcm5719-llvm-f7444e645beec5f9aa7d52f28539affbcfee6f38.tar.gz bcm5719-llvm-f7444e645beec5f9aa7d52f28539affbcfee6f38.zip |
CodeGen: tweak CFConstantStrings for COFF and ELF
Adjust the constant CFString emission to emit into more appropriate sections on
ELF and COFF targets. It would previously try to use MachO section names
irrespective of the file format.
llvm-svn: 271211
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 0c75cf111b1..cd278e65c15 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); |