aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2010-10-15 15:39:06 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2010-10-15 15:39:06 +0000
commit5df0b65e8f5ef55f0b515a0b24879f5d117d6042 (patch)
tree191d167bb0ecdf8e59eae496ce36574e72fbe606
parent1dd5a2f4e127a99914359cf39f19b3a9916d6be1 (diff)
downloadexternal_llvm-5df0b65e8f5ef55f0b515a0b24879f5d117d6042.zip
external_llvm-5df0b65e8f5ef55f0b515a0b24879f5d117d6042.tar.gz
external_llvm-5df0b65e8f5ef55f0b515a0b24879f5d117d6042.tar.bz2
Refactor code a bit and avoid creating unnecessary entries in the string
map. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116579 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/MC/ELFObjectWriter.cpp38
-rw-r--r--test/MC/ELF/alias.s10
2 files changed, 24 insertions, 24 deletions
diff --git a/lib/MC/ELFObjectWriter.cpp b/lib/MC/ELFObjectWriter.cpp
index 9a18162..c4281a4 100644
--- a/lib/MC/ELFObjectWriter.cpp
+++ b/lib/MC/ELFObjectWriter.cpp
@@ -789,28 +789,18 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
if (!isInSymtab(Asm, *it, UsedInReloc.count(&Symbol)))
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;
bool Local = isLocal(*it);
+ bool Add = false;
if (it->isCommon()) {
assert(!Local);
MSD.SectionIndex = ELF::SHN_COMMON;
- ExternalSymbolData.push_back(MSD);
+ Add = true;
} else if (Symbol.isAbsolute()) {
MSD.SectionIndex = ELF::SHN_ABS;
- if (Local)
- LocalSymbolData.push_back(MSD);
- else
- ExternalSymbolData.push_back(MSD);
+ Add = true;
} else if (Symbol.isVariable()) {
const MCExpr *Value = Symbol.getVariableValue();
assert (Value->getKind() == MCExpr::SymbolRef && "Unimplemented");
@@ -819,10 +809,7 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
if (RefSymbol.isDefined()) {
MSD.SectionIndex = SectionIndexMap.lookup(&RefSymbol.getSection());
assert(MSD.SectionIndex && "Invalid section index!");
- if (Local)
- LocalSymbolData.push_back(MSD);
- else
- ExternalSymbolData.push_back(MSD);
+ Add = true;
}
} else if (Symbol.isUndefined()) {
assert(!Local);
@@ -831,11 +818,24 @@ void ELFObjectWriterImpl::ComputeSymbolTable(MCAssembler &Asm) {
// are able to set it.
if (GetBinding(*it) == ELF::STB_LOCAL)
SetBinding(*it, ELF::STB_GLOBAL);
- UndefinedSymbolData.push_back(MSD);
+ Add = true;
} else {
MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());
assert(MSD.SectionIndex && "Invalid section index!");
- if (Local)
+ Add = true;
+ }
+
+ if (Add) {
+ uint64_t &Entry = StringIndexMap[Symbol.getName()];
+ if (!Entry) {
+ Entry = StringTable.size();
+ StringTable += Symbol.getName();
+ StringTable += '\x00';
+ }
+ MSD.StringIndex = Entry;
+ if (MSD.SectionIndex == ELF::SHN_UNDEF)
+ UndefinedSymbolData.push_back(MSD);
+ else if (Local)
LocalSymbolData.push_back(MSD);
else
ExternalSymbolData.push_back(MSD);
diff --git a/test/MC/ELF/alias.s b/test/MC/ELF/alias.s
index 604131c..4842d27 100644
--- a/test/MC/ELF/alias.s
+++ b/test/MC/ELF/alias.s
@@ -25,7 +25,7 @@ bar4 = foo4
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 2
-// CHECK-NEXT: (('st_name', 34) # 'bar4'
+// CHECK-NEXT: (('st_name', 29) # 'bar4'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 2)
// CHECK-NEXT: ('st_other', 0)
@@ -43,7 +43,7 @@ bar4 = foo4
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 4
-// CHECK-NEXT: (('st_name', 19) # 'foo3'
+// CHECK-NEXT: (('st_name', 14) # 'foo3'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)
@@ -52,7 +52,7 @@ bar4 = foo4
// CHECK-NEXT: ('st_size', 0)
// CHECK-NEXT: ),
// CHECK-NEXT: # Symbol 5
-// CHECK-NEXT: (('st_name', 29) # 'foo4'
+// CHECK-NEXT: (('st_name', 24) # 'foo4'
// CHECK-NEXT: ('st_bind', 0)
// CHECK-NEXT: ('st_type', 2)
// CHECK-NEXT: ('st_other', 0)
@@ -67,7 +67,7 @@ bar4 = foo4
// CHECK: # Symbol 8
// CHECK-NEXT: (('st_name', 0) # ''
// CHECK: # Symbol 9
-// CHECK-NEXT: (('st_name', 24) # 'bar3'
+// CHECK-NEXT: (('st_name', 19) # 'bar3'
// CHECK-NEXT: ('st_bind', 1)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)
@@ -75,7 +75,7 @@ bar4 = foo4
// CHECK-NEXT: ('st_value', 0)
// CHECK-NEXT: ('st_size', 0)
// CHECK: # Symbol 10
-// CHECK-NEXT: (('st_name', 14) # 'bar2'
+// CHECK-NEXT: (('st_name', 9) # 'bar2'
// CHECK-NEXT: ('st_bind', 1)
// CHECK-NEXT: ('st_type', 0)
// CHECK-NEXT: ('st_other', 0)