This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Rename read_ubyte_unaligned_inc to read_addr_unaligned_inc


- The behavior of this function has been changed to read only
  address-sized quantities, i.e. the size of 2 is no longer allowed.
  (Size of 1 never was.)  The two outstanding uses, both in readelf.c,
  which actually do use this call to read address-sized units, were
  updated, rejecting fields that indicate weird address sizes.

- The three related calls, read_sbyte_unaligned_inc,
  read_ubyte_unaligned and read_sbyte_unaligned were dropped.  There
  are currently no uses for these calls.

Signed-off-by: Petr Machata <pmachata@redhat.com>
---
 libdw/ChangeLog       |    8 ++++++++
 libdw/memory-access.h |   24 ++++--------------------
 src/ChangeLog         |    6 ++++++
 src/readelf.c         |   16 +++++++++-------
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index cc44004..410b31a 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,11 @@
+2014-09-12  Petr Machata  <pmachata@redhat.com>
+
+	* memory-access.h (read_ubyte_unaligned_inc): Allow only 4- and
+	8-byte quantities.  Consequently, rename to...
+	(read_addr_unaligned_inc): ... this.
+	(read_sbyte_unaligned_inc, read_ubyte_unaligned): Drop.
+	(read_sbyte_unaligned): Drop.
+
 2014-09-10  Petr Machata  <pmachata@redhat.com>
 
 	* dwarf_getlocation.c (attr_ok): Also accept
diff --git a/libdw/memory-access.h b/libdw/memory-access.h
index f41f783..6a4ce88 100644
--- a/libdw/memory-access.h
+++ b/libdw/memory-access.h
@@ -219,17 +219,6 @@ read_8sbyte_unaligned_1 (bool other_byte_order, const void *p)
 #endif	/* allow unaligned */
 
 
-#define read_ubyte_unaligned(Nbytes, Dbg, Addr) \
-  ((Nbytes) == 2 ? read_2ubyte_unaligned (Dbg, Addr)			      \
-   : (Nbytes) == 4 ? read_4ubyte_unaligned (Dbg, Addr)			      \
-   : read_8ubyte_unaligned (Dbg, Addr))
-
-#define read_sbyte_unaligned(Nbytes, Dbg, Addr) \
-  ((Nbytes) == 2 ? read_2sbyte_unaligned (Dbg, Addr)			      \
-   : (Nbytes) == 4 ? read_4sbyte_unaligned (Dbg, Addr)			      \
-   : read_8sbyte_unaligned (Dbg, Addr))
-
-
 #define read_2ubyte_unaligned_inc(Dbg, Addr) \
   ({ uint16_t t_ = read_2ubyte_unaligned (Dbg, Addr);			      \
      Addr = (__typeof (Addr)) (((uintptr_t) (Addr)) + 2);		      \
@@ -258,14 +247,9 @@ read_8sbyte_unaligned_1 (bool other_byte_order, const void *p)
      t_; })
 
 
-#define read_ubyte_unaligned_inc(Nbytes, Dbg, Addr) \
-  ((Nbytes) == 2 ? read_2ubyte_unaligned_inc (Dbg, Addr)		      \
-   : (Nbytes) == 4 ? read_4ubyte_unaligned_inc (Dbg, Addr)		      \
-   : read_8ubyte_unaligned_inc (Dbg, Addr))
-
-#define read_sbyte_unaligned_inc(Nbytes, Dbg, Addr) \
-  ((Nbytes) == 2 ? read_2sbyte_unaligned_inc (Dbg, Addr)		      \
-   : (Nbytes) == 4 ? read_4sbyte_unaligned_inc (Dbg, Addr)		      \
-   : read_8sbyte_unaligned_inc (Dbg, Addr))
+#define read_addr_unaligned_inc(Nbytes, Dbg, Addr)			\
+  (assert ((Nbytes) == 4 || (Nbytes) == 8),				\
+    ((Nbytes) == 4 ? read_4ubyte_unaligned_inc (Dbg, Addr)		\
+     : read_8ubyte_unaligned_inc (Dbg, Addr)))
 
 #endif	/* memory-access.h */
diff --git a/src/ChangeLog b/src/ChangeLog
index 986b341..aa98608 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2014-09-12  Petr Machata  <pmachata@redhat.com>
+
+	* readelf.c (encoded_ptr_size): In the switch statement, change
+	magic constants 3 and 4 to DW_EH_PE_* counterparts.  Still accept
+	0.  Print diagnostic for anything else.
+
 2014-08-25  Josh Stone  <jistone@redhat.com>
 
 	* Makefile.am: Prevent premature @AR@ replacement in a sed expression.
diff --git a/src/readelf.c b/src/readelf.c
index 6bbe436..7b43a65 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -5026,15 +5026,17 @@ encoded_ptr_size (int encoding, unsigned int ptr_size)
 {
   switch (encoding & 7)
     {
-    case 2:
-      return 2;
-    case 3:
+    case DW_EH_PE_udata4:
       return 4;
-    case 4:
+    case DW_EH_PE_udata8:
       return 8;
-    default:
+    case 0:
       return ptr_size;
     }
+
+  fprintf (stderr, "Unsupported pointer encoding: %#x, "
+	   "assuming pointer size of %d.\n", encoding, ptr_size);
+  return ptr_size;
 }
 
 
@@ -5455,9 +5457,9 @@ print_debug_frame_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
 
 	  const unsigned char *base = readp;
 	  // XXX There are sometimes relocations for this value
-	  initial_location = read_ubyte_unaligned_inc (ptr_size, dbg, readp);
+	  initial_location = read_addr_unaligned_inc (ptr_size, dbg, readp);
 	  Dwarf_Word address_range
-	    = read_ubyte_unaligned_inc (ptr_size, dbg, readp);
+	    = read_addr_unaligned_inc (ptr_size, dbg, readp);
 
 	  /* pcrel for an FDE address is relative to the runtime
 	     address of the start_address field itself.  Sign extend
-- 
1.7.6.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]