Bug 1066760 - Add base address and fall back to system dladdr in __wrap_dladdr; r=froydnj
authorJim Chen <nchen@mozilla.com>
Wed, 24 Sep 2014 14:12:54 -0400
changeset 206960 4aafc40bcd62ad4e289fa28ed0269ef33e52b399
parent 206959 d2a102f1ef78f1d62f52754568b4426f2deeb8ab
child 206961 421c30629ac5bca71a03dead2a7d8889609e188d
push id49580
push usernchen@mozilla.com
push dateWed, 24 Sep 2014 18:16:58 +0000
treeherdermozilla-inbound@4cf6c10a0ab9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1066760
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1066760 - Add base address and fall back to system dladdr in __wrap_dladdr; r=froydnj
mozglue/linker/CustomElf.h
mozglue/linker/ElfLoader.cpp
mozglue/linker/ElfLoader.h
--- a/mozglue/linker/CustomElf.h
+++ b/mozglue/linker/CustomElf.h
@@ -31,16 +31,17 @@ public:
                                                const char *path, int flags);
 
   /**
    * Inherited from LibHandle
    */
   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;
 
--- a/mozglue/linker/ElfLoader.cpp
+++ b/mozglue/linker/ElfLoader.cpp
@@ -85,19 +85,21 @@ int
   reinterpret_cast<LibHandle *>(handle)->ReleaseDirectRef();
   return 0;
 }
 
 int
 __wrap_dladdr(void *addr, Dl_info *info)
 {
   RefPtr<LibHandle> handle = ElfLoader::Singleton.GetHandleByPtr(addr);
-  if (!handle)
-    return 0;
+  if (!handle) {
+    return dladdr(addr, info);
+  }
   info->dli_fname = handle->GetPath();
+  info->dli_fbase = handle->GetBase();
   return 1;
 }
 
 int
 __wrap_dl_iterate_phdr(dl_phdr_cb callback, void *data)
 {
   if (!ElfLoader::Singleton.dbg)
     return -1;
--- a/mozglue/linker/ElfLoader.h
+++ b/mozglue/linker/ElfLoader.h
@@ -113,16 +113,21 @@ public:
 
   /**
    * Returns whether the given address is part of the virtual address space
    * covered by the loaded library.
    */
   virtual bool Contains(void *addr) const = 0;
 
   /**
+   * Returns the base address of the loaded library.
+   */
+  virtual void *GetBase() const = 0;
+
+  /**
    * Returns the file name of the library without the containing directory.
    */
   const char *GetName() const;
 
   /**
    * Returns the full path of the library, when available. Otherwise, returns
    * the file name.
    */
@@ -262,16 +267,17 @@ public:
   static mozilla::TemporaryRef<LibHandle> Load(const char *path, int flags);
 
   /**
    * Inherited from LibHandle
    */
   virtual ~SystemElf();
   virtual void *GetSymbolPtr(const char *symbol) const;
   virtual bool Contains(void *addr) const { return false; /* UNIMPLEMENTED */ }
+  virtual void *GetBase() const { return nullptr; /* UNIMPLEMENTED */ }
 
 #ifdef __ARM_EABI__
   virtual const void *FindExidx(int *pcount) const;
 #endif
 
 protected:
   virtual Mappable *GetMappable() const;