]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
Restructure the code to decrease the binary size
authorPetr Machata <pmachata@redhat.com>
Wed, 3 Jun 2009 13:50:03 +0000 (15:50 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 3 Jun 2009 13:50:03 +0000 (15:50 +0200)
libdw/dwarf_ranges.c
libdw/libdwP.h

index 2da713f26b0ce73fc4a86f8006c1f4a338ab46a9..eff9ce4d65436d693f83c575eb5f829ea55e9471 100644 (file)
@@ -62,7 +62,7 @@
     - If an error occurs, don't set anything and return -1.  */
 internal_function int
 __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index,
-                                unsigned char **addr, int width,
+                                unsigned char **addrp, int width,
                                 Dwarf_Addr *beginp, Dwarf_Addr *endp,
                                 Dwarf_Addr *basep)
 {
@@ -70,8 +70,10 @@ __libdw_read_begin_end_pair_inc (Dwarf *dbg, int sec_index,
     = width == 8 ? (Elf64_Addr) -1 : (Elf64_Addr) (Elf32_Addr) -1;
   Dwarf_Addr begin, end;
 
+  unsigned char *addr = *addrp;
   bool begin_relocated = READ_AND_RELOCATE (__libdw_relocate_address, begin);
   bool end_relocated = READ_AND_RELOCATE (__libdw_relocate_address, end);
+  *addrp = addr;
 
   /* Unrelocated escape for begin means base address selection.  */
   if (begin == escape && !begin_relocated)
@@ -170,8 +172,8 @@ dwarf_ranges (Dwarf_Die *die, ptrdiff_t offset, Dwarf_Addr *basep,
     }
   else
     {
-      if (!__libdw_offset_in_section (die->cu->dbg,
-                                     IDX_debug_ranges, offset, 1))
+      if (__libdw_offset_in_section (die->cu->dbg,
+                                    IDX_debug_ranges, offset, 1))
        return -1l;
 
       readp = d->d_buf + offset;
index 027eca84a7ccf6303eda787b04175936a20169e5..8f180ccf3693eceb25a69ca4519971fa0aefbeab 100644 (file)
@@ -53,7 +53,6 @@
 
 #include <libintl.h>
 #include <stdbool.h>
-#include <assert.h>
 
 #include <libdw.h>
 
@@ -429,7 +428,7 @@ extern int __dwarf_errno_internal (void);
 static inline int
 __libdw_relocate_address (Dwarf *dbg __attribute__ ((unused)),
                          int sec_index __attribute__ ((unused)),
-                         void *addr __attribute__ ((unused)),
+                         const void *addr __attribute__ ((unused)),
                          int width __attribute__ ((unused)),
                          Dwarf_Addr *val __attribute__ ((unused)))
 {
@@ -439,7 +438,7 @@ __libdw_relocate_address (Dwarf *dbg __attribute__ ((unused)),
 static inline int
 __libdw_relocate_offset (Dwarf *dbg __attribute__ ((unused)),
                         int sec_index __attribute__ ((unused)),
-                        void *addr __attribute__ ((unused)),
+                        const void *addr __attribute__ ((unused)),
                         int width __attribute__ ((unused)),
                         Dwarf_Off *val __attribute__ ((unused)))
 {
@@ -459,26 +458,26 @@ __libdw_checked_get_data (Dwarf *dbg, int sec_index)
   return data;
 }
 
-static inline bool
+static inline int
 __libdw_offset_in_section (Dwarf *dbg, int sec_index,
                           Dwarf_Off offset, size_t size)
 {
   Elf_Data *data = __libdw_checked_get_data (dbg, sec_index);
   if (data == NULL)
-    return false;
+    return -1;
   if (unlikely (offset > data->d_size)
       || unlikely (data->d_size - offset < size))
     {
       __libdw_seterrno (DWARF_E_INVALID_OFFSET);
-      return false;
+      return -1;
     }
 
-  return true;
+  return 0;
 }
 
 static inline bool
 __libdw_in_section (Dwarf *dbg, int sec_index,
-                   void *addr, size_t size)
+                   const void *addr, size_t size)
 {
   Elf_Data *data = __libdw_checked_get_data (dbg, sec_index);
   if (data == NULL)
@@ -495,17 +494,14 @@ __libdw_in_section (Dwarf *dbg, int sec_index,
 
 #define READ_AND_RELOCATE(RELOC_HOOK, VAL)                             \
   ({                                                                   \
-    if (!__libdw_in_section (dbg, sec_index, *addr, width))            \
+    if (!__libdw_in_section (dbg, sec_index, addr, width))             \
       return -1;                                                       \
                                                                        \
-    unsigned char *orig_addr = *addr;                                  \
+    const unsigned char *orig_addr = addr;                             \
     if (width == 4)                                                    \
-      VAL = read_4ubyte_unaligned_inc (dbg, *addr);                    \
+      VAL = read_4ubyte_unaligned_inc (dbg, addr);                     \
     else                                                               \
-      {                                                                        \
-       assert (width == 8);                                            \
-       VAL = read_8ubyte_unaligned_inc (dbg, *addr);                   \
-      }                                                                        \
+      VAL = read_8ubyte_unaligned_inc (dbg, addr);                     \
                                                                        \
     int status = RELOC_HOOK (dbg, sec_index, orig_addr, width, &VAL);  \
     if (status < 0)                                                    \
@@ -515,29 +511,44 @@ __libdw_in_section (Dwarf *dbg, int sec_index,
 
 static inline int
 __libdw_read_address_inc (Dwarf *dbg,
-                         int sec_index, unsigned char **addr,
+                         int sec_index, unsigned char **addrp,
                          int width, Dwarf_Addr *ret)
 {
-  Dwarf_Addr val;
-  READ_AND_RELOCATE (__libdw_relocate_address, val);
-  *ret = val;
+  unsigned char *addr = *addrp;
+  READ_AND_RELOCATE (__libdw_relocate_address, (*ret));
+  *addrp = addr;
+  return 0;
+}
+
+static inline int
+__libdw_read_address (Dwarf *dbg,
+                     int sec_index, const unsigned char *addr,
+                     int width, Dwarf_Addr *ret)
+{
+  READ_AND_RELOCATE (__libdw_relocate_address, (*ret));
   return 0;
 }
 
 static inline int
 __libdw_read_offset_inc (Dwarf *dbg,
-                        int sec_index, unsigned char **addr,
+                        int sec_index, unsigned char **addrp,
                         int width, Dwarf_Off *ret, int sec_ret,
                         size_t size)
 {
-  Dwarf_Off val;
-  READ_AND_RELOCATE (__libdw_relocate_offset, val);
-
-  if (!__libdw_offset_in_section (dbg, sec_ret, val, size))
-    return -1;
+  unsigned char *addr = *addrp;
+  READ_AND_RELOCATE (__libdw_relocate_offset, (*ret));
+  *addrp = addr;
+  return __libdw_offset_in_section (dbg, sec_ret, *ret, size);
+}
 
-  *ret = val;
-  return 0;
+static inline int
+__libdw_read_offset (Dwarf *dbg,
+                    int sec_index, const unsigned char *addr,
+                    int width, Dwarf_Off *ret, int sec_ret,
+                    size_t size)
+{
+  READ_AND_RELOCATE (__libdw_relocate_offset, (*ret));
+  return __libdw_offset_in_section (dbg, sec_ret, *ret, size);
 }
 
 /* Read up begin/end pair and increment read pointer.
@@ -556,25 +567,6 @@ unsigned char * __libdw_formptr (Dwarf_Attribute *attr, int sec_index,
                                 Dwarf_Off *offsetp)
   internal_function;
 
-static inline int
-__libdw_read_address (Dwarf *dbg,
-                     int sec_index, const unsigned char *addr,
-                     int width, Dwarf_Addr *ret)
-{
-  return __libdw_read_address_inc (dbg, sec_index, (unsigned char **)&addr,
-                                  width, ret);
-}
-
-static inline int
-__libdw_read_offset (Dwarf *dbg,
-                    int sec_index, const unsigned char *addr,
-                    int width, Dwarf_Off *ret, int sec_ret,
-                    size_t size)
-{
-  return __libdw_read_offset_inc (dbg, sec_index, (unsigned char **)&addr,
-                                 width, ret, sec_ret, size);
-}
-
 
 
 /* Aliases to avoid PLTs.  */