From 5621fe5443da23112170235dd5cac161e5c75e65 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 19 Oct 2020 10:17:59 +0200 Subject: [PATCH] libdw: dwarf_frame_register takes an array of at least 3 Dwarf_Ops MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- libdw/ChangeLog | 7 +++++++ libdw/dwarf_frame_register.c | 2 +- libdw/libdw.h | 8 +++++--- tests/ChangeLog | 4 ++++ tests/addrcfi.c | 2 +- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 1ac4e8a..731c7e7 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,10 @@ +2020-10-19 Mark Wielaard + + * 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 * memory-access.h (read_3ubyte_unaligned_inc): Call diff --git a/libdw/dwarf_frame_register.c b/libdw/dwarf_frame_register.c index d0159fb..bcf3fa0 100644 --- a/libdw/dwarf_frame_register.c +++ b/libdw/dwarf_frame_register.c @@ -34,7 +34,7 @@ #include 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. */ diff --git a/libdw/libdw.h b/libdw/libdw.h index 1a4e15a..f63cab1 100644 --- a/libdw/libdw.h +++ b/libdw/libdw.h @@ -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) diff --git a/tests/ChangeLog b/tests/ChangeLog index 43714ff..e9d1e26 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,9 @@ 2020-10-19 Mark Wielaard + * addrcfi.c (print_register): Make ops_mem 3 elements. + +2020-10-19 Mark Wielaard + * testfile60.bz2: Removed. * Makefile.am (EXTRA_DIST): Remove testfile60.bz2. * run-allregs.sh: Remove tilegx testfile60 testcase. diff --git a/tests/addrcfi.c b/tests/addrcfi.c index 589b851..2b7d7bd 100644 --- a/tests/addrcfi.c +++ b/tests/addrcfi.c @@ -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); -- 2.7.4