diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2010-10-05 18:01:23 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2010-10-05 18:01:23 +0000 |
| commit | b1d078935756f37e5acba9a3a9331bd5cd573701 (patch) | |
| tree | ec0a08705547e9f57c6090800b6d2ca50d9c68c8 /llvm | |
| parent | 8ccdd25fbd75c507808c74a63f000dedb65dffd5 (diff) | |
| download | bcm5719-llvm-b1d078935756f37e5acba9a3a9331bd5cd573701.tar.gz bcm5719-llvm-b1d078935756f37e5acba9a3a9331bd5cd573701.zip | |
Implement a simple alias case and refactor the code a bit so that the
isInSymtab and isLocal logic in the two loops don't get easily out of sync.
llvm-svn: 115643
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 52 | ||||
| -rw-r--r-- | llvm/test/MC/ELF/alias.s | 22 |
2 files changed, 57 insertions, 17 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index b33b0470308..72a6cbd5ef4 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -692,6 +692,29 @@ ELFObjectWriterImpl::getSymbolIndexInSymbolTable(const MCAssembler &Asm, return SD.getIndex() + NumRegularSections + /* empty symbol */ 1; } +static bool isInSymtab(const MCAssembler &Asm, const MCSymbolData &Data, + bool Used) { + const MCSymbol &Symbol = Data.getSymbol(); + if (!Asm.isSymbolLinkerVisible(Symbol) && !Symbol.isUndefined()) + return false; + + if (!Used && Symbol.isTemporary()) + return false; + + return true; +} + +static bool isLocal(const MCSymbolData &Data) { + if (Data.isExternal()) + return false; + + const MCSymbol &Symbol = Data.getSymbol(); + if (Symbol.isUndefined() && !Symbol.isVariable()) + return false; + + return true; +} + void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { // FIXME: Is this the correct place to do this? if (NeedsGOT) { @@ -718,14 +741,10 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { ie = Asm.symbol_end(); it != ie; ++it) { const MCSymbol &Symbol = it->getSymbol(); - // Ignore non-linker visible symbols. - if (!Asm.isSymbolLinkerVisible(Symbol)) + if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol))) continue; - if (it->isExternal() || Symbol.isUndefined()) - continue; - - if (Symbol.isTemporary() && !UsedInReloc.count(&Symbol)) + if (!isLocal(*it)) continue; uint64_t &Entry = StringIndexMap[Symbol.getName()]; @@ -743,7 +762,14 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { MSD.SectionIndex = ELF::SHN_ABS; LocalSymbolData.push_back(MSD); } else { - MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection()); + const MCSymbol *SymbolP = &Symbol; + if (Symbol.isVariable()) { + const MCExpr *Value = Symbol.getVariableValue(); + assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented"); + const MCSymbolRefExpr *Ref = static_cast<const MCSymbolRefExpr*>(Value); + SymbolP = &Ref->getSymbol(); + } + MSD.SectionIndex = SectionIndexMap.lookup(&SymbolP->getSection()); assert(MSD.SectionIndex && "Invalid section index!"); LocalSymbolData.push_back(MSD); } @@ -754,18 +780,10 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) { ie = Asm.symbol_end(); it != ie; ++it) { const MCSymbol &Symbol = it->getSymbol(); - // Ignore non-linker visible symbols. - if (!Asm.isSymbolLinkerVisible(Symbol) && !Symbol.isUndefined()) - continue; - - if (!it->isExternal() && !Symbol.isUndefined()) - continue; - - if (Symbol.isVariable()) + if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol))) continue; - if (Symbol.isUndefined() && !UsedInReloc.count(&Symbol) - && Symbol.isTemporary()) + if (isLocal(*it)) continue; uint64_t &Entry = StringIndexMap[Symbol.getName()]; diff --git a/llvm/test/MC/ELF/alias.s b/llvm/test/MC/ELF/alias.s new file mode 100644 index 00000000000..5da8635c1f9 --- /dev/null +++ b/llvm/test/MC/ELF/alias.s @@ -0,0 +1,22 @@ +// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | elf-dump | FileCheck %s + +foo: +bar = foo + +// CHECK: # Symbol 1 +// CHECK-NEXT: (('st_name', 5) # 'bar' +// CHECK-NEXT: ('st_bind', 0) +// CHECK-NEXT: ('st_type', 0) +// CHECK-NEXT: ('st_other', 0) +// CHECK-NEXT: ('st_shndx', 1) +// CHECK-NEXT: ('st_value', 0) +// CHECK-NEXT: ('st_size', 0) +// CHECK-NEXT: ), +// CHECK-NEXT: # Symbol 2 +// CHECK-NEXT: (('st_name', 1) # 'foo' +// CHECK-NEXT: ('st_bind', 0) +// CHECK-NEXT: ('st_type', 0) +// CHECK-NEXT: ('st_other', 0) +// CHECK-NEXT: ('st_shndx', 1) +// CHECK-NEXT: ('st_value', 0) +// CHECK-NEXT: ('st_size', 0) |

