Bug 1081034 part 1 - Move GetSymbolPtr, Contains and FindExidx from CustomElf to BaseElf. r=nfroyd
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 16 Oct 2014 09:19:46 +0900
changeset 210647 ab905a93d0eace4ca8fd85f8e0abe2fe80f303f2
parent 210646 fd07aa0b6a04cfdffb01505315711a2869f96576
child 210648 349536e12ec038ab93f1d29783216fa1b8b7c40d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersnfroyd
bugs1081034
milestone36.0a1
Bug 1081034 part 1 - Move GetSymbolPtr, Contains and FindExidx from CustomElf to BaseElf. r=nfroyd
mozglue/linker/BaseElf.cpp
mozglue/linker/BaseElf.h
mozglue/linker/CustomElf.cpp
mozglue/linker/CustomElf.h
--- a/mozglue/linker/BaseElf.cpp
+++ b/mozglue/linker/BaseElf.cpp
@@ -18,16 +18,22 @@ BaseElf::Hash(const char *symbol)
     g = h & 0xf0000000;
     h ^= g;
     h ^= g >> 24;
   }
   return h;
 }
 
 void *
+BaseElf::GetSymbolPtr(const char *symbol) const
+{
+  return GetSymbolPtr(symbol, Hash(symbol));
+}
+
+void *
 BaseElf::GetSymbolPtr(const char *symbol, unsigned long hash) const
 {
   const Sym *sym = GetSymbol(symbol, hash);
   void *ptr = nullptr;
   if (sym && sym->st_shndx != SHN_UNDEF)
     ptr = GetPtr(sym->st_value);
   DEBUG_LOG("BaseElf::GetSymbolPtr(%p [\"%s\"], \"%s\") = %p",
             reinterpret_cast<const void *>(this), GetPath(), symbol, ptr);
@@ -48,8 +54,27 @@ BaseElf::GetSymbol(const char *symbol, u
   size_t bucket = hash % buckets.numElements();
   for (size_t y = buckets[bucket]; y != STN_UNDEF; y = chains[y]) {
     if (strcmp(symbol, strtab.GetStringAt(symtab[y].st_name)))
       continue;
     return &symtab[y];
   }
   return nullptr;
 }
+
+bool
+BaseElf::Contains(void *addr) const
+{
+  return base.Contains(addr);
+}
+
+#ifdef __ARM_EABI__
+const void *
+BaseElf::FindExidx(int *pcount) const
+{
+  if (arm_exidx) {
+    *pcount = arm_exidx.numElements();
+    return arm_exidx;
+  }
+  *pcount = 0;
+  return nullptr;
+}
+#endif
--- a/mozglue/linker/BaseElf.h
+++ b/mozglue/linker/BaseElf.h
@@ -39,22 +39,22 @@ public:
   {
   }
 
 protected:
    /**
     * Inherited from LibHandle. Those are temporary and are not supposed to
     * be used.
     */
-   virtual void *GetSymbolPtr(const char *symbol) const { return NULL; };
-   virtual bool Contains(void *addr) const { return false; };
+   virtual void *GetSymbolPtr(const char *symbol) const;
+   virtual bool Contains(void *addr) const;
    virtual void *GetBase() const { return GetPtr(0); }
 
 #ifdef __ARM_EABI__
-  virtual const void *FindExidx(int *pcount) const { return NULL; };
+  virtual const void *FindExidx(int *pcount) const;
 #endif
 
   virtual Mappable *GetMappable() const { return NULL; };
 
 public:
 /* private: */
   /**
    * Returns a pointer relative to the base address where the library is
@@ -91,11 +91,16 @@ public:
   UnsizedArray<Elf::Word> chains;
 
 /* protected: */
   /* String table */
   Elf::Strtab strtab;
 
   /* Symbol table */
   UnsizedArray<Elf::Sym> symtab;
+
+#ifdef __ARM_EABI__
+  /* ARM.exidx information used by FindExidx */
+  Array<uint32_t[2]> arm_exidx;
+#endif
 };
 
 #endif /* BaseElf_h */
--- a/mozglue/linker/CustomElf.cpp
+++ b/mozglue/linker/CustomElf.cpp
@@ -274,22 +274,16 @@ CustomElf::~CustomElf()
   /* Normally, __cxa_finalize is called by the .fini function. However,
    * Android NDK before r6b doesn't do that. Our wrapped cxa_finalize only
    * calls destructors once, so call it in all cases. */
   ElfLoader::__wrap_cxa_finalize(this);
   ElfLoader::Singleton.Forget(this);
 }
 
 void *
-CustomElf::GetSymbolPtr(const char *symbol) const
-{
-  return BaseElf::GetSymbolPtr(symbol, Hash(symbol));
-}
-
-void *
 CustomElf::GetSymbolPtrInDeps(const char *symbol) const
 {
   /* Resolve dlopen and related functions to point to ours */
   if (symbol[0] == 'd' && symbol[1] == 'l') {
     if (strcmp(symbol + 2, "open") == 0)
       return FunctionPtr(__wrap_dlopen);
     if (strcmp(symbol + 2, "error") == 0)
       return FunctionPtr(__wrap_dlerror);
@@ -354,35 +348,16 @@ CustomElf::GetSymbolPtrInDeps(const char
       sym = (*it)->GetSymbolPtr(symbol);
     }
     if (sym)
       return sym;
   }
   return nullptr;
 }
 
-bool
-CustomElf::Contains(void *addr) const
-{
-  return base.Contains(addr);
-}
-
-#ifdef __ARM_EABI__
-const void *
-CustomElf::FindExidx(int *pcount) const
-{
-  if (arm_exidx) {
-    *pcount = arm_exidx.numElements();
-    return arm_exidx;
-  }
-  *pcount = 0;
-  return nullptr;
-}
-#endif
-
 void
 CustomElf::stats(const char *when) const
 {
   mappable->stats(when, GetPath());
 }
 
 bool
 CustomElf::LoadSegment(const Phdr *pt_load) const
--- a/mozglue/linker/CustomElf.h
+++ b/mozglue/linker/CustomElf.h
@@ -30,23 +30,16 @@ public:
    */
   static mozilla::TemporaryRef<LibHandle> Load(Mappable *mappable,
                                                const char *path, int flags);
 
   /**
    * Inherited from LibHandle/BaseElf
    */
   virtual ~CustomElf();
-  virtual void *GetSymbolPtr(const char *symbol) const;
-  virtual bool Contains(void *addr) const;
-  virtual void *GetBase() const { return GetPtr(0); }
-
-#ifdef __ARM_EABI__
-  virtual const void *FindExidx(int *pcount) const;
-#endif
 
 protected:
   virtual Mappable *GetMappable() const;
 
 public:
   /**
    * Shows some stats about the Mappable instance. The when argument is to be
    * used by the caller to give an identifier of the when the stats call is
@@ -156,16 +149,11 @@ private:
 
   /* List of initialization and destruction functions
    * (.init_array/.fini_array) */
   Array<void *> init_array, fini_array;
 
   bool initialized;
 
   bool has_text_relocs;
-
-#ifdef __ARM_EABI__
-  /* ARM.exidx information used by FindExidx */
-  Array<uint32_t[2]> arm_exidx;
-#endif
 };
 
 #endif /* CustomElf_h */