diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 0b810c77cfc..6d2f6437bb0 100644 --- a/lib/Target/TargetAsmInfo.cpp +++ b/lib/Target/TargetAsmInfo.cpp @@ -261,6 +261,9 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { std::string Name; + // FIXME: Should we use some hashing based on section name and just check + // flags? + // Select section name if (GV->hasSection()) { // Honour section already set, if any diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp index 96e452ee284..5e328fb78a3 100644 --- a/lib/Target/X86/X86TargetAsmInfo.cpp +++ b/lib/Target/X86/X86TargetAsmInfo.cpp @@ -313,6 +313,51 @@ X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, } } +std::string +X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { + SectionKind::Kind kind = SectionKindForGlobal(GV); + + if (const Function *F = dyn_cast(GV)) { + switch (F->getLinkage()) { + default: assert(0 && "Unknown linkage type!"); + case Function::InternalLinkage: + case Function::DLLExportLinkage: + case Function::ExternalLinkage: + return getTextSection(); + case Function::WeakLinkage: + case Function::LinkOnceLinkage: + return UniqueSectionForGlobal(F, kind); + } + } else if (const GlobalVariable *GVar = dyn_cast(GV)) { + if (GVar->hasCommonLinkage() || + GVar->hasLinkOnceLinkage() || + GVar->hasWeakLinkage()) + return UniqueSectionForGlobal(GVar, kind); + else { + switch (kind) { + case SectionKind::Data: + return getDataSection(); + case SectionKind::BSS: + // ELF targets usually have BSS sections + return getBSSSection(); + case SectionKind::ROData: + case SectionKind::RODataMergeStr: + case SectionKind::RODataMergeConst: + // FIXME: Temporary + return getReadOnlySection(); + case SectionKind::ThreadData: + // ELF targets usually support TLS stuff + return getTLSDataSection(); + case SectionKind::ThreadBSS: + return getTLSBSSSection(); + default: + assert(0 && "Unsuported section kind for global"); + } + } + } else + assert(0 && "Unsupported global"); +} + std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { std::string Flags = ",\""; @@ -472,67 +517,3 @@ X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM): DataSectionStartSuffix = "\tsegment 'DATA'"; SectionEndDirectiveSuffix = "\tends\n"; } - -std::string X86TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { - SectionKind::Kind kind = SectionKindForGlobal(GV); - unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str()); - std::string Name; - - // FIXME: Should we use some hashing based on section name and just check - // flags? - // FIXME: It seems, that Darwin uses much more sections. - - // Select section name - if (GV->hasSection()) { - // Honour section already set, if any - Name = GV->getSection(); - } else { - // Use default section depending on the 'type' of global - if (const Function *F = dyn_cast(GV)) { - switch (F->getLinkage()) { - default: assert(0 && "Unknown linkage type!"); - case Function::InternalLinkage: - case Function::DLLExportLinkage: - case Function::ExternalLinkage: - Name = getTextSection(); - break; - case Function::WeakLinkage: - case Function::LinkOnceLinkage: - Name = UniqueSectionForGlobal(F, kind); - break; - } - } else if (const GlobalVariable *GVar = dyn_cast(GV)) { - if (GVar->hasCommonLinkage() || - GVar->hasLinkOnceLinkage() || - GVar->hasWeakLinkage()) - Name = UniqueSectionForGlobal(GVar, kind); - else { - switch (kind) { - case SectionKind::Data: - Name = getDataSection(); - break; - case SectionKind::BSS: - Name = (getBSSSection() ? getBSSSection() : getDataSection()); - break; - case SectionKind::ROData: - case SectionKind::RODataMergeStr: - case SectionKind::RODataMergeConst: - // FIXME: Temporary - Name = getDataSection(); - break; - case SectionKind::ThreadData: - Name = (getTLSDataSection() ? getTLSDataSection() : getDataSection()); - break; - case SectionKind::ThreadBSS: - Name = (getTLSBSSSection() ? getTLSBSSSection() : getDataSection()); - default: - assert(0 && "Unsuported section kind for global"); - } - } - } else - assert(0 && "Unsupported global"); - } - - Name += PrintSectionFlags(flags); - return Name; -} diff --git a/lib/Target/X86/X86TargetAsmInfo.h b/lib/Target/X86/X86TargetAsmInfo.h index 85969920115..483b774d6d9 100644 --- a/lib/Target/X86/X86TargetAsmInfo.h +++ b/lib/Target/X86/X86TargetAsmInfo.h @@ -45,6 +45,8 @@ namespace llvm { explicit X86ELFTargetAsmInfo(const X86TargetMachine &TM); virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason, bool Global) const; + + virtual std::string SelectSectionForGlobal(const GlobalValue *GV) const; virtual std::string PrintSectionFlags(unsigned flags) const; };