[llvm-commits] [llvm] r115643 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/alias.s
Rafael Espindola
rafael.espindola at gmail.com
Tue Oct 5 11:01:23 PDT 2010
Author: rafael
Date: Tue Oct 5 13:01:23 2010
New Revision: 115643
URL: http://llvm.org/viewvc/llvm-project?rev=115643&view=rev
Log:
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.
Added:
llvm/trunk/test/MC/ELF/alias.s
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=115643&r1=115642&r2=115643&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Tue Oct 5 13:01:23 2010
@@ -692,6 +692,29 @@
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 @@
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 @@
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 @@
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()];
Added: llvm/trunk/test/MC/ELF/alias.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/alias.s?rev=115643&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/alias.s (added)
+++ llvm/trunk/test/MC/ELF/alias.s Tue Oct 5 13:01:23 2010
@@ -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)
More information about the llvm-commits
mailing list