summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Hsieh <andrewhsieh@google.com>2012-01-13 20:31:35 -0800
committerAndrew Hsieh <andrewhsieh@google.com>2012-01-13 20:31:35 -0800
commit9ed73923af9db7283a8c76b5dfa2dda5b732a852 (patch)
tree61e5ee4b97f446aa00fb74aa8b19bf7761ee24f3
parente0766885c735fd9872cf64295ed5dfb512f4f65f (diff)
downloadlinkloader-9ed73923af9db7283a8c76b5dfa2dda5b732a852.tar.gz
Remove hard-wired dependency on __mips__ in ELFSymbol_CRTP<>::getAddress()
Change-Id: I5bc2eca34c6548b0ea678280ef8f017383c869d0
-rw-r--r--android/librsloader.cpp4
-rw-r--r--include/ELFSymbol.h2
-rw-r--r--include/impl/ELFObject.hxx14
-rw-r--r--include/impl/ELFSymbol.hxx7
-rw-r--r--main.cpp4
5 files changed, 17 insertions, 14 deletions
diff --git a/android/librsloader.cpp b/android/librsloader.cpp
index 6a7b519..1d468dd 100644
--- a/android/librsloader.cpp
+++ b/android/librsloader.cpp
@@ -77,7 +77,9 @@ extern "C" void *rsloaderGetSymbolAddress(RSExecRef object_,
return NULL;
}
- return symbol->getAddress(false);
+ int machine = object->getHeader()->getMachine();
+
+ return symbol->getAddress(machine, false);
}
extern "C" size_t rsloaderGetSymbolSize(RSExecRef object_, char const *name) {
diff --git a/include/ELFSymbol.h b/include/ELFSymbol.h
index 1b1e218..92dc3c7 100644
--- a/include/ELFSymbol.h
+++ b/include/ELFSymbol.h
@@ -116,7 +116,7 @@ public:
return st_size;
}
- void *getAddress(bool autoAlloc = true) const;
+ void *getAddress(int machine, bool autoAlloc = true) const;
void setAddress(void *addr) {
my_addr = addr;
diff --git a/include/impl/ELFObject.hxx b/include/impl/ELFObject.hxx
index ceac7be..a51828d 100644
--- a/include/impl/ELFObject.hxx
+++ b/include/impl/ELFObject.hxx
@@ -142,7 +142,7 @@ relocateARM(void *(*find_sym)(void *context, char const *name),
Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
Inst_t P = (Inst_t)(int64_t)inst;
Inst_t A = 0;
- Inst_t S = (Inst_t)(int64_t)sym->getAddress();
+ Inst_t S = (Inst_t)(int64_t)sym->getAddress(EM_ARM);
switch (rel->getType()) {
default:
@@ -163,7 +163,7 @@ relocateARM(void *(*find_sym)(void *context, char const *name),
A = (Inst_t)(int64_t)SIGN_EXTEND(*inst & 0xFFFFFF, 24);
#undef SIGN_EXTEND
- void *callee_addr = sym->getAddress();
+ void *callee_addr = sym->getAddress(EM_ARM);
switch (sym->getType()) {
default:
@@ -177,7 +177,7 @@ relocateARM(void *(*find_sym)(void *context, char const *name),
if (callee_addr == 0) {
rsl_assert(0 && "We should get function address at previous "
- "sym->getAddress() function call.");
+ "sym->getAddress(EM_ARM) function call.");
abort();
}
break;
@@ -274,7 +274,7 @@ relocateX86_64(void *(*find_sym)(void *context, char const *name),
Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
Inst_t P = (Inst_t)(int64_t)inst;
Inst_t A = (Inst_t)(int64_t)rel->getAddend();
- Inst_t S = (Inst_t)(int64_t)sym->getAddress();
+ Inst_t S = (Inst_t)(int64_t)sym->getAddress(EM_X86_64);
if (S == 0) {
S = (Inst_t)(int64_t)find_sym(context, sym->getName());
@@ -325,7 +325,7 @@ relocateX86_32(void *(*find_sym)(void *context, char const *name),
Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
Inst_t P = (Inst_t)(uintptr_t)inst;
Inst_t A = (Inst_t)(uintptr_t)*inst;
- Inst_t S = (Inst_t)(uintptr_t)sym->getAddress();
+ Inst_t S = (Inst_t)(uintptr_t)sym->getAddress(EM_386);
if (S == 0) {
S = (Inst_t)(uintptr_t)find_sym(context, sym->getName());
@@ -369,7 +369,7 @@ relocateMIPS(void *(*find_sym)(void *context, char const *name),
Inst_t *inst = (Inst_t *)&(*text)[rel->getOffset()];
Inst_t P = (Inst_t)(uintptr_t)inst;
Inst_t A = (Inst_t)(uintptr_t)*inst;
- Inst_t S = (Inst_t)(uintptr_t)sym->getAddress();
+ Inst_t S = (Inst_t)(uintptr_t)sym->getAddress(EM_MIPS);
bool need_stub = false;
@@ -462,7 +462,7 @@ relocateMIPS(void *(*find_sym)(void *context, char const *name),
*inst &= 0xFFFF0000;
A = A & 0xFFFF;
if (strcmp (sym->getName(), "_gp_disp") == 0) {
- S = (Inst_t)sym->getAddress();
+ S = (Inst_t)sym->getAddress(EM_MIPS);
}
*inst |= ((S + A) & 0xFFFF);
break;
diff --git a/include/impl/ELFSymbol.hxx b/include/impl/ELFSymbol.hxx
index 01c84cc..b3c6087 100644
--- a/include/impl/ELFSymbol.hxx
+++ b/include/impl/ELFSymbol.hxx
@@ -119,7 +119,7 @@ inline void ELFSymbol_CRTP<Bitwidth>::print(bool shouldPrintHeader) const {
}
template <unsigned Bitwidth>
-void *ELFSymbol_CRTP<Bitwidth>::getAddress(bool autoAlloc) const {
+void *ELFSymbol_CRTP<Bitwidth>::getAddress(int machine, bool autoAlloc) const {
if (my_addr != 0) {
return my_addr;
}
@@ -200,10 +200,9 @@ void *ELFSymbol_CRTP<Bitwidth>::getAddress(bool autoAlloc) const {
break;
case SHN_UNDEF:
-#if defined(mips) || defined(__mips__) || defined(MIPS) || defined(_MIPS_)
- if (strcmp(getName(), "_gp_disp") == 0) // OK for MIPS
+ if (machine == EM_MIPS && strcmp(getName(), "_gp_disp") == 0) // OK for MIPS
break;
-#endif
+
case SHN_ABS:
case SHN_XINDEX:
rsl_assert(0 && "STT_OBJECT with special st_shndx.");
diff --git a/main.cpp b/main.cpp
index f7df146..2ead7ec 100644
--- a/main.cpp
+++ b/main.cpp
@@ -159,7 +159,9 @@ void dump_and_run_object(Archiver &AR, int argc, char **argv) {
out() << "relocate finished!\n";
out().flush();
- void *main_addr = symtab->getByName("main")->getAddress();
+ int machine = object->getHeader()->getMachine();
+
+ void *main_addr = symtab->getByName("main")->getAddress(machine);
out() << "main address: " << main_addr << "\n";
out().flush();