summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShih-wei Liao <sliao@google.com>2011-07-22 00:36:45 -0700
committerShih-wei Liao <sliao@google.com>2011-07-22 00:47:14 -0700
commitfa06e91015017e8d0627d26a88e2a575643bec11 (patch)
tree1dfd5214f37ace3cb92e02a64455d122cb1f6e3a
parente4742793dcba49887f90011fc7a3a858cf70a8cf (diff)
downloadlinkloader-fa06e91015017e8d0627d26a88e2a575643bec11.tar.gz
Move stubs from ELFObject to ELFSectionProgBits by TDY
Text section problem in BUG=5057160. Tested on x86, crespo and stingray. TODO: Not every section need stub. TODO: May not be able to call getExternFuncCount() every progbits section. TODO: May be too many stubs Note that every .text section should have its own stub. Change-Id: I4a98ed51cc7b171b96840430198bd15409978014
-rw-r--r--include/ELFObject.h11
-rw-r--r--include/ELFSectionProgBits.h12
-rw-r--r--include/impl/ELFObject.hxx2
-rw-r--r--include/impl/ELFSectionProgBits.hxx44
4 files changed, 32 insertions, 37 deletions
diff --git a/include/ELFObject.h b/include/ELFObject.h
index bf7a0d8..db3150e 100644
--- a/include/ELFObject.h
+++ b/include/ELFObject.h
@@ -19,7 +19,6 @@
#include "ELFTypes.h"
#include "MemChunk.h"
-#include "StubLayout.h"
#include "utils/rsl_assert.h"
@@ -38,10 +37,6 @@ private:
llvm::OwningPtr<ELFSectionHeaderTableTy> shtab;
std::vector<ELFSectionTy *> stab;
-#ifdef __arm__
- StubLayout stubs;
-#endif
-
MemChunk SHNCommonData;
unsigned char *SHNCommonDataPtr;
size_t SHNCommonDataFreeSize;
@@ -67,12 +62,6 @@ public:
ELFSectionTy const *getSectionByName(std::string const &str) const;
ELFSectionTy *getSectionByName(std::string const &str);
-#ifdef __arm__
- StubLayout *getStubLayout() {
- return &stubs;
- }
-#endif
-
void *allocateSHNCommonData(size_t size, size_t align = 1) {
rsl_assert(size > 0 && align != 0);
diff --git a/include/ELFSectionProgBits.h b/include/ELFSectionProgBits.h
index 03deef4..54388bc 100644
--- a/include/ELFSectionProgBits.h
+++ b/include/ELFSectionProgBits.h
@@ -21,18 +21,30 @@
#include "ELFSectionBits.h"
#include "ELFSectionHeader.h"
#include "MemChunk.h"
+#include "StubLayout.h"
template <unsigned Bitwidth>
class ELFSectionProgBits : public ELFSectionBits<Bitwidth> {
public:
ELF_TYPE_INTRO_TO_TEMPLATE_SCOPE(Bitwidth);
+private:
+#ifdef __arm__
+ StubLayout stubs;
+#endif
+
public:
template <typename Archiver>
static ELFSectionProgBits *read(Archiver &AR,
ELFObjectTy *owner,
ELFSectionHeaderTy const *sh);
+#ifdef __arm__
+ StubLayout *getStubLayout() {
+ return &stubs;
+ }
+#endif
+
private:
template <typename Archiver>
bool serialize(Archiver &AR) {
diff --git a/include/impl/ELFObject.hxx b/include/impl/ELFObject.hxx
index 83e8aa6..279a850 100644
--- a/include/impl/ELFObject.hxx
+++ b/include/impl/ELFObject.hxx
@@ -191,7 +191,7 @@ relocateARM(void *(*find_sym)(void *context, char const *name),
rsl_assert(0 && "Target address is far from call instruction");
abort();
#else
- void *stub = getStubLayout()->allocateStub(ext_func);
+ void *stub = text->getStubLayout()->allocateStub(ext_func);
if (!stub) {
llvm::errs() << "unable to allocate stub." << "\n";
exit(EXIT_FAILURE);
diff --git a/include/impl/ELFSectionProgBits.hxx b/include/impl/ELFSectionProgBits.hxx
index 8356e71..354878d 100644
--- a/include/impl/ELFSectionProgBits.hxx
+++ b/include/impl/ELFSectionProgBits.hxx
@@ -36,39 +36,33 @@ ELFSectionProgBits<Bitwidth>::read(Archiver &AR,
llvm::OwningPtr<ELFSectionProgBits> result(new ELFSectionProgBits());
- bool is_text_section = strcmp(sh->getName(), ".text") == 0;
-
- if (!is_text_section) {
- if (!result->chunk.allocate(sh->getSize())) {
- return NULL;
- }
-
- } else {
+ // TODO: Not every section needs a stub.
#ifdef __arm__
- StubLayout *stubs = owner->getStubLayout();
+ // Count the extern function symbol
+ ELFSectionSymTabTy const *symtab =
+ static_cast<ELFSectionSymTabTy *>(owner->getSectionByName(".symtab"));
- // Count the extern function symbol
- ELFSectionSymTabTy const *symtab =
- static_cast<ELFSectionSymTabTy *>(owner->getSectionByName(".symtab"));
+ // TODO: May not call this function every progbits section.
+ size_t func_count = symtab->getExternFuncCount();
- size_t func_count = symtab->getExternFuncCount();
+ StubLayout *stubs = result->getStubLayout();
- // Calculate additional stub size
- size_t stub_size = stubs->calcStubTableSize(func_count);
+ // TODO: May be too many stubs.
+ // Calculate additional stub size
+ size_t stub_size = stubs->calcStubTableSize(func_count);
- // Allocate text section
- if (!result->chunk.allocate(sh->getSize() + stub_size)) {
- return NULL;
- }
+ // Allocate progbits section + stub
+ if (!result->chunk.allocate(sh->getSize() + stub_size)) {
+ return NULL;
+ }
- stubs->initStubTable(result->chunk.getBuffer()+sh->getSize(), func_count);
+ stubs->initStubTable(result->chunk.getBuffer()+sh->getSize(), func_count);
#else
- // Allocate text section
- if (!result->chunk.allocate(sh->getSize())) {
- return NULL;
- }
-#endif
+ // Allocate text section
+ if (!result->chunk.allocate(sh->getSize())) {
+ return NULL;
}
+#endif
result->sh = sh;