summaryrefslogtreecommitdiffstats
path: root/libdw/memory-access.h
diff options
context:
space:
mode:
authorMark Wielaard <[email protected]>2017-12-26 11:52:06 +0100
committerMark Wielaard <[email protected]>2018-01-01 22:48:56 +0100
commitbfb2117387eb98eae4f0aace7c32061a27483adc (patch)
tree829e1e40297a219f4e315edfcc711f780ba0b4f1 /libdw/memory-access.h
parent68cd423edbba61af902eed2abe85578f1c134a25 (diff)
libdw: New get_uleb128_unchecked to use with already checked Dwarf_Abbrev.
When creating a Dwarf_Abbrev in dwarf_getabbrev (__libdw_getabbrev) we already check it is fully readable from the .debug_abbrev section. So whenever we reread it later using the attrp pointer we don't have to check it again. Introduce get_uleb128_unchecked to use for ulebs we know are safe to read directly. Signed-off-by: Mark Wielaard <[email protected]>
Diffstat (limited to 'libdw/memory-access.h')
-rw-r--r--libdw/memory-access.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/libdw/memory-access.h b/libdw/memory-access.h
index afb651fc..ed68bdb9 100644
--- a/libdw/memory-access.h
+++ b/libdw/memory-access.h
@@ -87,8 +87,26 @@ __libdw_get_uleb128 (const unsigned char **addrp, const unsigned char *end)
return UINT64_MAX;
}
+static inline uint64_t
+__libdw_get_uleb128_unchecked (const unsigned char **addrp)
+{
+ uint64_t acc = 0;
+
+ /* Unroll the first step to help the compiler optimize
+ for the common single-byte case. */
+ get_uleb128_step (acc, *addrp, 0);
+
+ const size_t max = len_leb128 (uint64_t);
+ for (size_t i = 1; i < max; ++i)
+ get_uleb128_step (acc, *addrp, i);
+ /* Other implementations set VALUE to UINT_MAX in this
+ case. So we better do this as well. */
+ return UINT64_MAX;
+}
+
/* Note, addr needs to me smaller than end. */
#define get_uleb128(var, addr, end) ((var) = __libdw_get_uleb128 (&(addr), end))
+#define get_uleb128_unchecked(var, addr) ((var) = __libdw_get_uleb128_unchecked (&(addr)))
/* The signed case is similar, but we sign-extend the result. */