diff options
author | Anton Korobeynikov <asl@math.spbu.ru> | 2008-07-09 13:23:08 +0000 |
---|---|---|
committer | Anton Korobeynikov <asl@math.spbu.ru> | 2008-07-09 13:23:08 +0000 |
commit | 4260ad3e7dc0909190a14a2d2f0098cb8ade1462 (patch) | |
tree | 30a9c0e36f93f992a3baefa34e079b3dc6f059b6 /lib | |
parent | 265c5259ab98b5a4f9f25fbe9f2e470d0933cb38 (diff) | |
download | external_llvm-4260ad3e7dc0909190a14a2d2f0098cb8ade1462.zip external_llvm-4260ad3e7dc0909190a14a2d2f0098cb8ade1462.tar.gz external_llvm-4260ad3e7dc0909190a14a2d2f0098cb8ade1462.tar.bz2 |
Provide section selection for X86 ELF targets
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53305 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Target/TargetAsmInfo.cpp | 3 | ||||
-rw-r--r-- | lib/Target/X86/X86TargetAsmInfo.cpp | 109 | ||||
-rw-r--r-- | lib/Target/X86/X86TargetAsmInfo.h | 2 |
3 files changed, 50 insertions, 64 deletions
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp index 0b810c7..6d2f643 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 96e452e..5e328fb 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<Function>(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<GlobalVariable>(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<Function>(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<GlobalVariable>(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 8596992..483b774 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; }; |