diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 84862811a9c..41fb0645c81 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -246,24 +246,25 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) { const MCSection *TargetLoweringObjectFileELF:: SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang, const TargetMachine &TM) const { + unsigned Flags = getELFSectionFlags(Kind); + // If we have -ffunction-section or -fdata-section then we should emit the // global value to a uniqued section specifically for it. - bool EmitUniquedSection; - if (Kind.isText()) - EmitUniquedSection = TM.getFunctionSections(); - else - EmitUniquedSection = TM.getDataSections(); + bool EmitUniquedSection = false; + if (!(Flags & ELF::SHF_MERGE) && !Kind.isCommon()) { + if (Kind.isText()) + EmitUniquedSection = TM.getFunctionSections(); + else + EmitUniquedSection = TM.getDataSections(); + } - // If this global is linkonce/weak and the target handles this by emitting it - // into a 'uniqued' section name, create and return the section now. - if ((EmitUniquedSection && !Kind.isCommon()) || GV->hasComdat()) { + if (EmitUniquedSection || GV->hasComdat()) { StringRef Prefix = getSectionPrefixForGlobal(Kind); SmallString<128> Name(Prefix); TM.getNameWithPrefix(Name, GV, Mang, true); StringRef Group = ""; - unsigned Flags = getELFSectionFlags(Kind); if (const Comdat *C = getELFComdat(GV)) { Flags |= ELF::SHF_GROUP; Group = C->getName(); diff --git a/test/CodeGen/X86/global-sections.ll b/test/CodeGen/X86/global-sections.ll index 24be27161f4..29bf9963b2d 100644 --- a/test/CodeGen/X86/global-sections.ll +++ b/test/CodeGen/X86/global-sections.ll @@ -121,7 +121,7 @@ define void @F1() { ; LINUX: G7: ; LINUX: .asciz "abcdefghi" -; LINUX-SECTIONS: .section .rodata.G7,"aMS",@progbits,1 +; LINUX-SECTIONS: .section .rodata.str1.1,"aMS",@progbits,1 ; LINUX-SECTIONS: .globl G7 ; WIN32-SECTIONS: .section .rdata,"rd",one_only,_G7 @@ -182,7 +182,7 @@ define void @F1() { @G14 = private unnamed_addr constant [4 x i8] c"foo\00", align 1 ; LINUX-SECTIONS: .type .LG14,@object # @G14 -; LINUX-SECTIONS: .section .rodata..LG14,"aMS",@progbits,1 +; LINUX-SECTIONS: .section .rodata.str1.1,"aMS",@progbits,1 ; LINUX-SECTIONS: .LG14: ; LINUX-SECTIONS: .asciz "foo" ; LINUX-SECTIONS: .size .LG14, 4 @@ -206,7 +206,7 @@ define void @F1() { ; DARWIN64: .section __TEXT,__const ; DARWIN64: _G15: -; LINUX-SECTIONS: .section .rodata.G15,"aM",@progbits,8 +; LINUX-SECTIONS: .section .rodata.cst8,"aM",@progbits,8 ; LINUX-SECTIONS: G15: ; WIN32-SECTIONS: .section .rdata,"rd",one_only,_G15