Correctly handle references to section symbols.
[oota-llvm.git] / lib / MC / MCContext.cpp
index 9d8a57e55f6cda00c1d423d80a5afa597333b798..3ac8d658873f3107c823eab592111cb8ceb43175 100644 (file)
@@ -113,6 +113,23 @@ MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
   return Sym;
 }
 
+MCSymbol *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
+  MCSymbol *&Sym = SectionSymbols[&Section];
+  if (Sym)
+    return Sym;
+
+  StringRef Name = Section.getSectionName();
+  StringMapEntry<bool> *NameEntry = &UsedNames.GetOrCreateValue(Name);
+  NameEntry->setValue(true);
+  Sym = new (*this) MCSymbol(NameEntry->getKey(), /*isTemporary*/ false);
+
+  StringMapEntry<MCSymbol*> &Entry = Symbols.GetOrCreateValue(Name);
+  if (!Entry.getValue())
+    Entry.setValue(Sym);
+
+  return Sym;
+}
+
 MCSymbol *MCContext::CreateSymbol(StringRef Name) {
   // Determine whether this is an assembler temporary or normal label, if used.
   bool isTemporary = false;