hoist section name uniquing logic up to the top-level SectionForGlobal
implementation, eliminating a dupe.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76953 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index d13a322..e193dd4 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -295,6 +295,18 @@
return getNamedSection(GV->getSection().c_str(), Flags);
}
+ // 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 (GV->isWeakForLinker()) {
+ if (const char *Prefix =
+ getSectionPrefixForUniqueGlobal(SectionKindForGlobal(GV))) {
+ // FIXME: Use mangler interface (PR4584).
+ std::string Name = Prefix+GV->getName();
+ unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
+ return getNamedSection(Name.c_str(), Flags);
+ }
+ }
+
// Use default section depending on the 'type' of global
return SelectSectionForGlobal(GV);
}
@@ -304,19 +316,16 @@
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind Kind = SectionKindForGlobal(GV);
- if (GV->isWeakForLinker()) {
- // FIXME: Use mangler interface (PR4584).
- std::string Name = getSectionPrefixForUniqueGlobal(Kind)+GV->getName();
- unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
- return getNamedSection(Name.c_str(), Flags);
- } else {
- if (Kind == SectionKind::Text)
- return getTextSection();
- else if (isBSS(Kind) && getBSSSection_())
- return getBSSSection_();
- else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
- return getReadOnlySection();
- }
+ if (Kind == SectionKind::Text)
+ return getTextSection();
+
+ if (isBSS(Kind))
+ if (const Section *S = getBSSSection_())
+ return S;
+
+ if (SectionKind::isReadOnly(Kind))
+ if (const Section *S = getReadOnlySection())
+ return S;
return getDataSection();
}
@@ -352,7 +361,6 @@
case SectionKind::ThreadData: return ".gnu.linkonce.td.";
case SectionKind::ThreadBSS: return ".gnu.linkonce.tb.";
}
- return NULL;
}
const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,