summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2012-02-02 12:00:12 -0800
committerStephen Hines <srhines@google.com>2012-02-02 12:00:12 -0800
commit50b814ae8797a929bc0416d6a97e3551b24eaf30 (patch)
tree180c9d0b379e5ca46de20a2fe21949532073ddef
parentef50fd4ab703ef72552405a0637a0a121aee563c (diff)
downloadlinkloader-50b814ae8797a929bc0416d6a97e3551b24eaf30.tar.gz
Check for unresolved symbols before returning executable.
BUG=5955072 Change-Id: Ia2a260003ba2e8ca0bfb68154fb5f306148ac5a0
-rw-r--r--android/librsloader.cpp3
-rw-r--r--include/ELFObject.h8
-rw-r--r--include/impl/ELFObject.hxx15
3 files changed, 25 insertions, 1 deletions
diff --git a/android/librsloader.cpp b/android/librsloader.cpp
index 1d468dd..4128d24 100644
--- a/android/librsloader.cpp
+++ b/android/librsloader.cpp
@@ -51,6 +51,9 @@ rsloaderCreateExec(unsigned char const *buf,
//object->print();
object->relocate(find_symbol, find_symbol_context);
+ if (object->getMissingSymbols()) {
+ return NULL;
+ }
return wrap(object.take());
}
diff --git a/include/ELFObject.h b/include/ELFObject.h
index 3bacd88..d715d51 100644
--- a/include/ELFObject.h
+++ b/include/ELFObject.h
@@ -41,6 +41,8 @@ private:
unsigned char *SHNCommonDataPtr;
size_t SHNCommonDataFreeSize;
+ bool missingSymbols;
+
// TODO: Need refactor!
bool initSHNCommonDataSize(size_t SHNCommonDataSize) {
rsl_assert(!SHNCommonDataPtr && "Can't init twice.");
@@ -54,7 +56,7 @@ private:
}
private:
- ELFObject() : SHNCommonDataPtr(NULL) { }
+ ELFObject() : SHNCommonDataPtr(NULL), missingSymbols(false) { }
public:
template <typename Archiver>
@@ -74,6 +76,10 @@ public:
ELFSectionTy const *getSectionByName(std::string const &str) const;
ELFSectionTy *getSectionByName(std::string const &str);
+ inline bool getMissingSymbols() const {
+ return missingSymbols;
+ }
+
void *allocateSHNCommonData(size_t size, size_t align = 1) {
rsl_assert(size > 0 && align != 0);
diff --git a/include/impl/ELFObject.hxx b/include/impl/ELFObject.hxx
index a51828d..a16ea45 100644
--- a/include/impl/ELFObject.hxx
+++ b/include/impl/ELFObject.hxx
@@ -188,6 +188,9 @@ relocateARM(void *(*find_sym)(void *context, char const *name),
if (callee_addr == 0) {
callee_addr = find_sym(context, sym->getName());
+ if (!callee_addr) {
+ missingSymbols = true;
+ }
sym->setAddress(callee_addr);
}
break;
@@ -228,6 +231,9 @@ relocateARM(void *(*find_sym)(void *context, char const *name),
if (S==0 && sym->getType() == STT_NOTYPE)
{
void *ext_sym = find_sym(context, sym->getName());
+ if (!ext_sym) {
+ missingSymbols = true;
+ }
S = (Inst_t)(uintptr_t)ext_sym;
sym->setAddress(ext_sym);
}
@@ -278,6 +284,9 @@ relocateX86_64(void *(*find_sym)(void *context, char const *name),
if (S == 0) {
S = (Inst_t)(int64_t)find_sym(context, sym->getName());
+ if (!S) {
+ missingSymbols = true;
+ }
sym->setAddress((void *)S);
}
@@ -329,6 +338,9 @@ relocateX86_32(void *(*find_sym)(void *context, char const *name),
if (S == 0) {
S = (Inst_t)(uintptr_t)find_sym(context, sym->getName());
+ if (!S) {
+ missingSymbols = true;
+ }
sym->setAddress((void *)S);
}
@@ -376,6 +388,9 @@ relocateMIPS(void *(*find_sym)(void *context, char const *name),
if (S == 0 && strcmp (sym->getName(), "_gp_disp") != 0) {
need_stub = true;
S = (Inst_t)(uintptr_t)find_sym(context, sym->getName());
+ if (!S) {
+ missingSymbols = true;
+ }
sym->setAddress((void *)S);
}