From a6398cdcfced9c9301d9daffc1e3b78f739dff6b Mon Sep 17 00:00:00 2001 From: Kristina Brooks Date: Mon, 24 Sep 2018 15:26:08 +0000 Subject: [PATCH] Revert "rL342883: [Clang][CodeGen][ObjC]: Fix CoreFoundation on ELF with `-fconstant-cfstrings`." Seems to be causing buildbot failures, need to look into it. llvm-svn: 342893 --- clang/lib/CodeGen/CodeGenModule.cpp | 61 +++++++++++------------------ clang/test/CodeGen/CFStrings.c | 4 +- clang/test/CodeGen/cfstring-elf.c | 34 ---------------- 3 files changed, 25 insertions(+), 74 deletions(-) delete mode 100644 clang/test/CodeGen/cfstring-elf.c diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index baafa98d5c85..85fed525795d 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4109,48 +4109,37 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { llvm::Constant *Zero = llvm::Constant::getNullValue(Int32Ty); llvm::Constant *Zeros[] = { Zero, Zero }; - + // 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 *C = - CreateRuntimeVariable(Ty, "__CFConstantStringClassReference"); - - if (getTriple().isOSBinFormatELF() || getTriple().isOSBinFormatCOFF()) { - llvm::GlobalValue *GV = nullptr; - - if ((GV = dyn_cast(C))) { - IdentifierInfo &II = getContext().Idents.get(GV->getName()); - TranslationUnitDecl *TUDecl = getContext().getTranslationUnitDecl(); - DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); + llvm::GlobalValue *GV = cast( + CreateRuntimeVariable(Ty, "__CFConstantStringClassReference")); - const VarDecl *VD = nullptr; - for (const auto &Result : DC->lookup(&II)) - if ((VD = dyn_cast(Result))) - break; - - if (getTriple().isOSBinFormatELF()) { - if (!VD) - GV->setLinkage(llvm::GlobalValue::ExternalLinkage); - } - else { - if (!VD || !VD->hasAttr()) { - GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); - GV->setLinkage(llvm::GlobalValue::ExternalLinkage); - } else { - GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); - GV->setLinkage(llvm::GlobalValue::ExternalLinkage); - } - } - - setDSOLocal(GV); + if (getTriple().isOSBinFormatCOFF()) { + IdentifierInfo &II = getContext().Idents.get(GV->getName()); + TranslationUnitDecl *TUDecl = getContext().getTranslationUnitDecl(); + DeclContext *DC = TranslationUnitDecl::castToDeclContext(TUDecl); + + const VarDecl *VD = nullptr; + for (const auto &Result : DC->lookup(&II)) + if ((VD = dyn_cast(Result))) + break; + + if (!VD || !VD->hasAttr()) { + GV->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass); + GV->setLinkage(llvm::GlobalValue::ExternalLinkage); + } else { + GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); + GV->setLinkage(llvm::GlobalValue::ExternalLinkage); } } - + setDSOLocal(GV); + // Decay array -> ptr CFConstantStringClassRef = - llvm::ConstantExpr::getGetElementPtr(Ty, C, Zeros); + llvm::ConstantExpr::getGetElementPtr(Ty, GV, Zeros); } QualType CFTy = getContext().getCFConstantStringType(); @@ -4196,11 +4185,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) { if (getTriple().isOSBinFormatMachO()) GV->setSection(isUTF16 ? "__TEXT,__ustring" : "__TEXT,__cstring,cstring_literals"); - // Make sure the literal ends up in .rodata to allow for safe ICF and for - // the static linker to adjust permissions to read-only later on. - else if (getTriple().isOSBinFormatELF()) - GV->setSection(".rodata"); - + // String. llvm::Constant *Str = llvm::ConstantExpr::getGetElementPtr(GV->getValueType(), GV, Zeros); diff --git a/clang/test/CodeGen/CFStrings.c b/clang/test/CodeGen/CFStrings.c index b473dd3ff58c..4edb5ff26e60 100644 --- a/clang/test/CodeGen/CFStrings.c +++ b/clang/test/CodeGen/CFStrings.c @@ -22,7 +22,7 @@ const CFStringRef one = (CFStringRef)__builtin___CFStringMakeConstantString("one const CFStringRef two = (CFStringRef)__builtin___CFStringMakeConstantString("\xef\xbf\xbd\x74\xef\xbf\xbd\x77\xef\xbf\xbd\x6f"); // CHECK-COFF: @.str = private unnamed_addr constant [4 x i8] c"one\00", align 1 -// CHECK-ELF: @.str = private unnamed_addr constant [4 x i8] c"one\00", section ".rodata", align 1 +// CHECK-ELF: @.str = private unnamed_addr constant [4 x i8] c"one\00", align 1 // CHECK-MACHO: @.str = private unnamed_addr constant [4 x i8] c"one\00", section "__TEXT,__cstring,cstring_literals", align 1 // CHECK-COFF: @_unnamed_cfstring_ = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 3 }, section "cfstring", align {{[48]}} @@ -32,7 +32,7 @@ const CFStringRef two = (CFStringRef)__builtin___CFStringMakeConstantString("\xe // CHECK-MACHO64: @_unnamed_cfstring_ = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i64 3 }, section "__DATA,__cfstring", align 8 // CHECK-COFF: @.str.1 = private unnamed_addr constant [7 x i16] [i16 -3, i16 116, i16 -3, i16 119, i16 -3, i16 111, i16 0], align 2 -// CHECK-ELF: @.str.1 = private unnamed_addr constant [7 x i16] [i16 -3, i16 116, i16 -3, i16 119, i16 -3, i16 111, i16 0], section ".rodata", align 2 +// CHECK-ELF: @.str.1 = private unnamed_addr constant [7 x i16] [i16 -3, i16 116, i16 -3, i16 119, i16 -3, i16 111, i16 0], align 2 // CHECK-MACHO: @.str.1 = private unnamed_addr constant [7 x i16] [i16 -3, i16 116, i16 -3, i16 119, i16 -3, i16 111, i16 0], section "__TEXT,__ustring", align 2 // CHECK-COFF: @_unnamed_cfstring_.2 = private global %struct.__NSConstantString_tag { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 2000, i8* bitcast ([7 x i16]* @.str.1 to i8*), i32 6 }, section "cfstring", align {{[48]}} diff --git a/clang/test/CodeGen/cfstring-elf.c b/clang/test/CodeGen/cfstring-elf.c deleted file mode 100644 index 79fd9baa0161..000000000000 --- a/clang/test/CodeGen/cfstring-elf.c +++ /dev/null @@ -1,34 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-elf -DCF_BUILDING_CF -DDECL -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF-IN-CF-DECL -// RUN: %clang_cc1 -triple x86_64-elf -DCF_BUILDING_CF -DDEFN -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF-IN-CF-DEFN -// RUN: %clang_cc1 -triple x86_64-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF -// RUN: %clang_cc1 -triple x86_64-elf -DEXTERN -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF-EXTERN - -// RUN: %clang_cc1 -Os -triple x86_64-elf -DCF_BUILDING_CF -DDECL -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF-IN-CF-DECL -// RUN: %clang_cc1 -Os -triple x86_64-elf -DCF_BUILDING_CF -DDEFN -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF-IN-CF-DEFN -// RUN: %clang_cc1 -Os -triple x86_64-elf -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF -// RUN: %clang_cc1 -Os -triple x86_64-elf -DEXTERN -S -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-CF-EXTERN - - -#if defined(CF_BUILDING_CF) -#if defined(DECL) -extern long __CFConstantStringClassReference[]; -#elif defined(DEFN) -long __CFConstantStringClassReference[32]; -#endif -#else -#if defined(EXTERN) -extern long __CFConstantStringClassReference[]; -#else -long __CFConstantStringClassReference[]; -#endif -#endif - -typedef struct __CFString *CFStringRef; -const CFStringRef string = (CFStringRef)__builtin___CFStringMakeConstantString("string"); - - -// CHECK-CF-IN-CF-DECL: @__CFConstantStringClassReference = external global [0 x i32] -// CHECK-CF-IN-CF-DEFN: @__CFConstantStringClassReference = common global [32 x i64] zeroinitializer, align 16 -// CHECK-CF: @__CFConstantStringClassReference = common global [1 x i64] zeroinitializer, align 8 -// CHECK-CF-EXTERN: @__CFConstantStringClassReference = external global [0 x i32] -// CHECK-CF-EXTERN: @.str = private unnamed_addr constant [7 x i8] c"string\00", section ".rodata", align 1