aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/TargetAsmInfo.cpp
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2008-07-09 13:22:46 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2008-07-09 13:22:46 +0000
commit265c5259ab98b5a4f9f25fbe9f2e470d0933cb38 (patch)
treef496abd2342944b0ea9b211ecabd178c383dd33f /lib/Target/TargetAsmInfo.cpp
parent6d8294209287eb36951f8445abe1129e015cd312 (diff)
Provide general hook for section name calculation
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53304 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/TargetAsmInfo.cpp')
-rw-r--r--lib/Target/TargetAsmInfo.cpp39
1 files changed, 35 insertions, 4 deletions
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 6967ebe486..0b810c77cf 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -257,12 +257,43 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
std::string
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
+ unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
+
+ std::string Name;
+
+ // 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
+ Name = SelectSectionForGlobal(GV);
+ }
+
+ Name += PrintSectionFlags(flags);
+ return Name;
+}
+
+// Lame default implementation. Calculate the section name for global.
+std::string
+TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind kind = SectionKindForGlobal(GV);
- if (kind == SectionKind::Text)
- return getTextSection();
- else if (kind == SectionKind::BSS && getBSSSection())
- return getBSSSection();
+ if (GV->hasLinkOnceLinkage() ||
+ GV->hasWeakLinkage() ||
+ GV->hasCommonLinkage())
+ return UniqueSectionForGlobal(GV, kind);
+ else {
+ if (kind == SectionKind::Text)
+ return getTextSection();
+ else if (kind == SectionKind::BSS && getBSSSection())
+ return getBSSSection();
+ else if (getReadOnlySection() &&
+ (kind == SectionKind::ROData ||
+ kind == SectionKind::RODataMergeConst ||
+ kind == SectionKind::RODataMergeStr))
+ return getReadOnlySection();
+ }
return getDataSection();
}