aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2016-03-28 20:36:28 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2016-03-28 20:36:28 +0000
commita023f79db19dae6c42ce4240e85630510c20ac91 (patch)
tree7f560eefe0cb296bd4d1313b0e77c054be60dca5 /llvm/lib/MC/ELFObjectWriter.cpp
parentcc8ee8e3a226e160965dd586d22059bc3134337f (diff)
downloadllvm-a023f79db19dae6c42ce4240e85630510c20ac91.zip
llvm-a023f79db19dae6c42ce4240e85630510c20ac91.tar.gz
llvm-a023f79db19dae6c42ce4240e85630510c20ac91.tar.bz2
Handle section vs global name conflict.
This is a fix for PR26941. When there is both a section and a global definition with the same name, the global wins. Section symbols are not added to the symbol table; section references are left undefined and fixed up in the object writer unless they've been satisfied by some other definition. llvm-svn: 264649
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp17
1 files changed, 16 insertions, 1 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.