]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdw: dwarf_frame_register takes an array of at least 3 Dwarf_Ops
authorMark Wielaard <mark@klomp.org>
Mon, 19 Oct 2020 08:17:59 +0000 (10:17 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 26 Oct 2020 21:44:07 +0000 (22:44 +0100)
GCC11 will warn about a mismatch in the declaration of dwarf_frame_register:

dwarf_frame_register.c:37:61: error: argument 3 of type ‘Dwarf_Op *’
  declared as a pointer [-Werror=array-parameter=]
   37 | dwarf_frame_register (Dwarf_Frame *fs, int regno, Dwarf_Op *ops_mem,
      |                                                   ~~~~~~~~~~^~~~~~~
libdw.h:1068:43: note: previously declared as an array ‘Dwarf_Op[3]’
 1068 |                                  Dwarf_Op ops_mem[3],
      |                                  ~~~~~~~~~^~~~~~~~~~

When fixing that it will show an actual bug in the addrcfi testcase:

addrcfi.c:98:16: error: ‘dwarf_frame_register’ accessing 96 bytes in a
  region of size 64 [-Werror=stringop-overflow=]
   98 |   int result = dwarf_frame_register (stuff->frame, regno, ops_mem, &ops, &nops);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
addrcfi.c:98:16: note: referencing argument 3 of type ‘Dwarf_Op *’
 1069 | extern int dwarf_frame_register (Dwarf_Frame *frame, int regno,
      |            ^~~~~~~~~~~~~~~~~~~~

Fix the declaration, fix the bug and add an extra comment to the description
in libdw.h.

Signed-off-by: Mark Wielaard <mark@klomp.org>
libdw/ChangeLog
libdw/dwarf_frame_register.c
libdw/libdw.h
tests/ChangeLog
tests/addrcfi.c

index 1ac4e8a97b39ea90a27bb04b4569e6a1a500643a..731c7e79be2dc6319090a9ffc23e918d7e484e49 100644 (file)
@@ -1,3 +1,10 @@
+2020-10-19  Mark Wielaard  <mark@klomp.org>
+
+       * dwarf_frame_register.c (dwarf_frame_register): Declare ops_mem
+       as array of (at least) 3 elements.
+       * libdw.h (dwarf_frame_register): Add extra explanation of ops_mem
+       argument.
+
 2020-10-23  Tom Tromey  <tom@tromey.com>
 
        * memory-access.h (read_3ubyte_unaligned_inc): Call
index d0159fb86b4d6c1aa9d8bd8e1e06f70862888acb..bcf3fa03045910e040c56226972d06bfaea2f0f6 100644 (file)
@@ -34,7 +34,7 @@
 #include <dwarf.h>
 
 int
-dwarf_frame_register (Dwarf_Frame *fs, int regno, Dwarf_Op *ops_mem,
+dwarf_frame_register (Dwarf_Frame *fs, int regno, Dwarf_Op ops_mem[3],
                      Dwarf_Op **ops, size_t *nops)
 {
   /* Maybe there was a previous error.  */
index 1a4e15a169dea532c76446c0effd2da522614600..f63cab1ba881871c5dc54953e7e7573ebabcbc03 100644 (file)
@@ -1061,9 +1061,11 @@ extern int dwarf_frame_cfa (Dwarf_Frame *frame, Dwarf_Op **ops, size_t *nops)
    caller's REGNO is "same_value", i.e. this frame did not change it;
    ask the caller frame where to find it.
 
-   For common simple expressions *OPS is OPS_MEM.  For arbitrary DWARF
-   expressions in the CFI, *OPS is an internal pointer that can be used as
-   long as the Dwarf_CFI used to create FRAME remains alive.  */
+   For common simple expressions *OPS is OPS_MEM (which is a caller
+   owned array for at least 3 Dwarf_Ops).  For arbitrary DWARF
+   expressions in the CFI, *OPS is an internal pointer that can be
+   used as long as the Dwarf_CFI used to create FRAME remains
+   alive.  */
 extern int dwarf_frame_register (Dwarf_Frame *frame, int regno,
                                 Dwarf_Op ops_mem[3],
                                 Dwarf_Op **ops, size_t *nops)
index 43714ff113bc80248a197b31888cb46d15763957..e9d1e2606d680ab8d313a2223ba50adf02434bfb 100644 (file)
@@ -1,3 +1,7 @@
+2020-10-19  Mark Wielaard  <mark@klomp.org>
+
+       * addrcfi.c (print_register): Make ops_mem 3 elements.
+
 2020-10-19  Mark Wielaard  <mark@klomp.org>
 
        * testfile60.bz2: Removed.
index 589b8513ca658c11800e18879a5a4aece82b6d5d..2b7d7bd0a1487467ddf0cdd2adcc6f5aa9cad0a1 100644 (file)
@@ -92,7 +92,7 @@ print_register (void *arg,
 
   printf ("\t%s reg%u (%s%s): ", setname, regno, prefix, regname);
 
-  Dwarf_Op ops_mem[2];
+  Dwarf_Op ops_mem[3];
   Dwarf_Op *ops;
   size_t nops;
   int result = dwarf_frame_register (stuff->frame, regno, ops_mem, &ops, &nops);