[llvm-commits] [llvm] r116484 - in /llvm/trunk: lib/MC/ELFObjectWriter.cpp test/MC/ELF/alias.s test/MC/ELF/undef.s
Rafael Espindola
rafael.espindola at gmail.com
Thu Oct 14 09:34:44 PDT 2010
Author: rafael
Date: Thu Oct 14 11:34:44 2010
New Revision: 116484
URL: http://llvm.org/viewvc/llvm-project?rev=116484&view=rev
Log:
Remove some code duplication.
Modified:
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/test/MC/ELF/alias.s
llvm/trunk/test/MC/ELF/undef.s
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=116484&r1=116483&r2=116484&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Thu Oct 14 11:34:44 2010
@@ -781,7 +781,7 @@
StringMap<uint64_t> StringIndexMap;
StringTable += '\x00';
- // Add the data for local symbols.
+ // Add the data for the symbols.
for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
ie = Asm.symbol_end(); it != ie; ++it) {
const MCSymbol &Symbol = it->getSymbol();
@@ -789,48 +789,6 @@
if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol)))
continue;
- if (!isLocal(*it))
- continue;
-
- uint64_t &Entry = StringIndexMap[Symbol.getName()];
- if (!Entry) {
- Entry = StringTable.size();
- StringTable += Symbol.getName();
- StringTable += '\x00';
- }
-
- ELFSymbolData MSD;
- MSD.SymbolData = it;
- MSD.StringIndex = Entry;
-
- if (Symbol.isAbsolute()) {
- MSD.SectionIndex = ELF::SHN_ABS;
- LocalSymbolData.push_back(MSD);
- } else {
- 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);
- }
- }
-
- // Now add non-local symbols.
- for (MCAssembler::symbol_iterator it = Asm.symbol_begin(),
- ie = Asm.symbol_end(); it != ie; ++it) {
- const MCSymbol &Symbol = it->getSymbol();
-
- if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol)))
- continue;
-
- if (isLocal(*it))
- continue;
-
uint64_t &Entry = StringIndexMap[Symbol.getName()];
if (!Entry) {
Entry = StringTable.size();
@@ -841,11 +799,18 @@
ELFSymbolData MSD;
MSD.SymbolData = it;
MSD.StringIndex = Entry;
+ bool Local = isLocal(*it);
- // FIXME: There is duplicated code with the local case.
if (it->isCommon()) {
+ assert(!Local);
MSD.SectionIndex = ELF::SHN_COMMON;
ExternalSymbolData.push_back(MSD);
+ } else if (Symbol.isAbsolute()) {
+ MSD.SectionIndex = ELF::SHN_ABS;
+ if (Local)
+ LocalSymbolData.push_back(MSD);
+ else
+ ExternalSymbolData.push_back(MSD);
} else if (Symbol.isVariable()) {
const MCExpr *Value = Symbol.getVariableValue();
assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented");
@@ -854,22 +819,26 @@
if (RefSymbol.isDefined()) {
MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection());
assert(MSD.SectionIndex && "Invalid section index!");
- ExternalSymbolData.push_back(MSD);
+ if (Local)
+ LocalSymbolData.push_back(MSD);
+ else
+ ExternalSymbolData.push_back(MSD);
}
} else if (Symbol.isUndefined()) {
+ assert(!Local);
MSD.SectionIndex = ELF::SHN_UNDEF;
// FIXME: Undefined symbols are global, but this is the first place we
// are able to set it.
if (GetBinding(*it) == ELF::STB_LOCAL)
SetBinding(*it, ELF::STB_GLOBAL);
UndefinedSymbolData.push_back(MSD);
- } else if (Symbol.isAbsolute()) {
- MSD.SectionIndex = ELF::SHN_ABS;
- ExternalSymbolData.push_back(MSD);
} else {
MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
assert(MSD.SectionIndex && "Invalid section index!");
- ExternalSymbolData.push_back(MSD);
+ if (Local)
+ LocalSymbolData.push_back(MSD);
+ else
+ ExternalSymbolData.push_back(MSD);
}
}
Modified: llvm/trunk/test/MC/ELF/alias.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/alias.s?rev=116484&r1=116483&r2=116484&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/alias.s (original)
+++ llvm/trunk/test/MC/ELF/alias.s Thu Oct 14 11:34:44 2010
@@ -25,7 +25,7 @@
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 2
-// CHECK-NEXT: (('st_name', 19) # 'bar4'
+// CHECK-NEXT: (('st_name', 34) # 'bar4'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 2)
// CHECK-NEXT: ('st_other', 0)
@@ -43,7 +43,7 @@
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 4
-// CHECK-NEXT: (('st_name', 9) # 'foo3'
+// CHECK-NEXT: (('st_name', 19) # 'foo3'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)
@@ -52,7 +52,7 @@
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 5
-// CHECK-NEXT: (('st_name', 14) # 'foo4'
+// CHECK-NEXT: (('st_name', 29) # 'foo4'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 2)
// CHECK-NEXT: ('st_other', 0)
@@ -67,7 +67,7 @@
// CHECK: # Symbol 8
// CHECK-NEXT: (('st_name', 0) # ''
// CHECK: # Symbol 9
-// CHECK-NEXT: (('st_name', 34) # 'bar3'
+// CHECK-NEXT: (('st_name', 24) # 'bar3'
// CHECK-NEXT: ('st_bind', 1)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)
@@ -75,7 +75,7 @@
// CHECK-NEXT: ('st_value', 0)
// CHECK-NEXT: ('st_size', 0)
// CHECK: # Symbol 10
-// CHECK-NEXT: (('st_name', 29) # 'bar2'
+// CHECK-NEXT: (('st_name', 14) # 'bar2'
// CHECK-NEXT: ('st_bind', 1)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)
Modified: llvm/trunk/test/MC/ELF/undef.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/undef.s?rev=116484&r1=116483&r2=116484&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/undef.s (original)
+++ llvm/trunk/test/MC/ELF/undef.s Thu Oct 14 11:34:44 2010
@@ -22,7 +22,7 @@
// CHECK-NEXT: # Symbol 0
// CHECK-NEXT: (('st_name', 0) # ''
// CHECK: # Symbol 1
-// CHECK-NEXT: (('st_name', 1) # '.Lsym8'
+// CHECK-NEXT: (('st_name', 13) # '.Lsym8'
// CHECK: # Symbol 2
// CHECK-NEXT: (('st_name', 0) # ''
// CHECK: # Symbol 3
@@ -32,9 +32,9 @@
// CHECK: # Symbol 5
// CHECK-NEXT: (('st_name', 0) # ''
// CHECK: # Symbol 6
-// CHECK-NEXT: (('st_name', 8) # '.Lsym1'
+// CHECK-NEXT: (('st_name', 1) # '.Lsym1'
// CHECK: # Symbol 7
-// CHECK-NEXT: (('st_name', 15) # 'sym6'
+// CHECK-NEXT: (('st_name', 8) # 'sym6'
// CHECK-NEXT: ('st_bind', 1)
// CHECK-NEXT: ('st_type', 1)
// CHECK-NEXT: ('st_other', 0)
More information about the llvm-commits
mailing list