static unsigned
-getELFSectionFlags(SectionKind K) {
+getELFSectionFlags(SectionKind K, bool InCOMDAT) {
unsigned Flags = 0;
if (!K.isMetadata())
if (K.isThreadLocal())
Flags |= ELF::SHF_TLS;
- if (K.isMergeableCString() || K.isMergeableConst())
+ if (!InCOMDAT && (K.isMergeableCString() || K.isMergeableConst()))
Flags |= ELF::SHF_MERGE;
if (K.isMergeableCString())
Kind = getELFKindForNamedSection(SectionName, Kind);
StringRef Group = "";
- unsigned Flags = getELFSectionFlags(Kind);
+ unsigned Flags = getELFSectionFlags(Kind, GV->hasComdat());
if (const Comdat *C = getELFComdat(GV)) {
Group = C->getName();
Flags |= ELF::SHF_GROUP;
const MCSection *TargetLoweringObjectFileELF::
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM) const {
- unsigned Flags = getELFSectionFlags(Kind);
+ unsigned Flags = getELFSectionFlags(Kind, GV->hasComdat());
// If we have -ffunction-section or -fdata-section then we should emit the
// global value to a uniqued section specifically for it.
--- /dev/null
+; RUN: llc < %s -mtriple=i386-unknown-linux | FileCheck %s -check-prefix=LINUX
+; RUN: llc < %s -mtriple=i386-unknown-linux -data-sections | FileCheck %s -check-prefix=LINUX-SECTIONS
+
+$G16 = comdat any
+@G16 = unnamed_addr constant i32 42, comdat
+
+; LINUX: .section .rodata.G16,"aG",@progbits,G16,comdat
+; LINUX-SECTIONS: .section .rodata.G16,"aG",@progbits,G16,comdat