aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp17
-rw-r--r--llvm/lib/MC/MCContext.cpp21
2 files changed, 23 insertions, 15 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 01b7148..68c3cb1 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -375,9 +375,24 @@ uint64_t ELFObjectWriter::SymbolValue(const MCSymbol &Sym,
void ELFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
const MCAsmLayout &Layout) {
+ // Section symbols are used as definitions for undefined symbols with matching
+ // names. If there are multiple sections with the same name, the first one is
+ // used.
+ for (const MCSection &Sec : Asm) {
+ const MCSymbol *Begin = Sec.getBeginSymbol();
+ if (!Begin)
+ continue;
+
+ const MCSymbol *Alias = Asm.getContext().lookupSymbol(Begin->getName());
+ if (!Alias || !Alias->isUndefined())
+ continue;
+
+ Renames.insert(
+ std::make_pair(cast<MCSymbolELF>(Alias), cast<MCSymbolELF>(Begin)));
+ }
+
// The presence of symbol versions causes undefined symbols and
// versions declared with @@@ to be renamed.
-
for (const MCSymbol &A : Asm.symbols()) {
const auto &Alias = cast<MCSymbolELF>(A);
// Not an alias.
diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp
index 96e24de..e326738 100644
--- a/llvm/lib/MC/MCContext.cpp
+++ b/llvm/lib/MC/MCContext.cpp
@@ -124,19 +124,9 @@ MCSymbolELF *MCContext::getOrCreateSectionSymbol(const MCSectionELF &Section) {
return Sym;
StringRef Name = Section.getSectionName();
-
- MCSymbol *&OldSym = Symbols[Name];
- if (OldSym && OldSym->isUndefined()) {
- Sym = cast<MCSymbolELF>(OldSym);
- return Sym;
- }
-
- auto NameIter = UsedNames.insert(std::make_pair(Name, true)).first;
+ auto NameIter = UsedNames.insert(std::make_pair(Name, false)).first;
Sym = new (&*NameIter, *this) MCSymbolELF(&*NameIter, /*isTemporary*/ false);
- if (!OldSym)
- OldSym = Sym;
-
return Sym;
}
@@ -192,9 +182,12 @@ MCSymbol *MCContext::createSymbol(StringRef Name, bool AlwaysAddSuffix,
raw_svector_ostream(NewName) << NextUniqueID++;
}
auto NameEntry = UsedNames.insert(std::make_pair(NewName, true));
- if (NameEntry.second) {
- // Ok, we found a name. Have the MCSymbol object itself refer to the copy
- // of the string that is embedded in the UsedNames entry.
+ if (NameEntry.second || !NameEntry.first->second) {
+ // Ok, we found a name.
+ // Mark it as used for a non-section symbol.
+ NameEntry.first->second = true;
+ // Have the MCSymbol object itself refer to the copy of the string that is
+ // embedded in the UsedNames entry.
return createSymbolImpl(&*NameEntry.first, IsTemporary);
}
assert(IsTemporary && "Cannot rename non-temporary symbols");