A sufficiently mad compiler optimiser can take undefined behaviour
according to the C standard as an opportunity to remove code.  Since
"data + size" might be seen to be past the end of an array,
calculating such an expression is UB.
_mul_overflow is infrastructure for later patches.
	* bucomm.h (_mul_overflow): Define.
	* dwarf.c (get_encoded_value): Avoid pointer UB.
+2021-05-15  Alan Modra  <amodra@gmail.com>
+
+       * bucomm.h (_mul_overflow): Define.
+       * dwarf.c (get_encoded_value): Avoid pointer UB.
+
 2021-05-13  Alan Modra  <amodra@gmail.com>
 
        PR 27861
 
 
 void *xrealloc (void *, size_t);
 
+#if __GNUC__ >= 7
+#define _mul_overflow(a, b, res) __builtin_mul_overflow (a, b, res)
+#else
+/* Assumes unsigned values.  Careful!  Args evaluated multiple times.  */
+#define _mul_overflow(a, b, res) \
+  ((*res) = (a), (*res) *= (b), (b) != 0 && (*res) / (b) != (a))
+#endif
+
 #endif /* _BUCOMM_H */
 
   unsigned int size = size_of_encoded_value (encoding);
   dwarf_vma val;
 
-  if (data + size >= end)
+  if (data >= end || size > (size_t) (end - data))
     {
       warn (_("Encoded value extends past end of section\n"));
       * pdata = end;