Blame SOURCES/gdb-rhbz2042257-ftbs-updates.patch

ed07ac
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
ed07ac
From: Keith Seitz <keiths@redhat.com>
ed07ac
Date: Wed, 26 Jan 2022 08:56:18 -0800
ed07ac
Subject: gdb-rhbz2042257-ftbs-updates.patch
ed07ac
MIME-Version: 1.0
ed07ac
Content-Type: text/plain; charset=UTF-8
ed07ac
Content-Transfer-Encoding: 8bit
ed07ac
ed07ac
;; Fix build problems.
ed07ac
;; (RHBZ 2042257, Keith Seitz, Andrew Burgess)
ed07ac
ed07ac
1) Reference array of structs instead of first member during memcpy
ed07ac
ed07ac
aarch64-tdep.c defines the following macro:
ed07ac
ed07ac
        do  \
ed07ac
          { \
ed07ac
            unsigned int mem_len = LENGTH; \
ed07ac
            if (mem_len) \
ed07ac
              { \
ed07ac
                MEMS =  XNEWVEC (struct aarch64_mem_r, mem_len);  \
ed07ac
                memcpy(&MEMS->len, &RECORD_BUF[0], \
ed07ac
                       sizeof(struct aarch64_mem_r) * LENGTH); \
ed07ac
              } \
ed07ac
          } \
ed07ac
          while (0)
ed07ac
ed07ac
This is simlpy allocating a new array and copying it. However, for
ed07ac
the destination address, it is actually copying into the first member
ed07ac
of the first element of the array (`&MEMS->len"). This elicits a
ed07ac
warning with GCC 12:
ed07ac
ed07ac
../../binutils-gdb/gdb/aarch64-tdep.c: In function ‘int aarch64_process_record(gdbarch*, regcache*, CORE_ADDR)’:
ed07ac
../../binutils-gdb/gdb/aarch64-tdep.c:3711:23: error: writing 16 bytes into a region of size 8 [-Werror=stringop-overflow=]
ed07ac
 3711 |                 memcpy(&MEMS->len, &RECORD_BUF[0], \
ed07ac
      |                       ^
ed07ac
../../binutils-gdb/gdb/aarch64-tdep.c:4394:3: note: in expansion of macro ‘MEM_ALLOC’
ed07ac
 4394 |   MEM_ALLOC (aarch64_insn_r->aarch64_mems, aarch64_insn_r->mem_rec_count,
ed07ac
      |   ^~~~~~~~~
ed07ac
../../binutils-gdb/gdb/aarch64-tdep.c:3721:12: note: destination object ‘aarch64_mem_r::len’ of size 8
ed07ac
 3721 |   uint64_t len;    /* Record length.  */
ed07ac
      |            ^~~
ed07ac
ed07ac
The simple fix is to reference the array, `MEMS' as the destination of the copy.
ed07ac
ed07ac
Tested by rebuilding.
ed07ac
ed07ac
2)     Fix build with current GCC: EL_EXPLICIT(location) always non-NULL
ed07ac
ed07ac
    Compiling GDB with current GCC (1b4a63593b) runs into this:
ed07ac
ed07ac
      src/gdb/location.c: In function 'int event_location_empty_p(const event_location*)':
ed07ac
      src/gdb/location.c:963:38: error: the address of 'event_location::<unnamed union>::explicit_loc' will never be NULL [-Werror=address]
ed07ac
        963 |       return (EL_EXPLICIT (location) == NULL
ed07ac
            |                                      ^
ed07ac
      src/gdb/location.c:57:30: note: 'event_location::<unnamed union>::explicit_loc' declared here
ed07ac
         57 |     struct explicit_location explicit_loc;
ed07ac
            |                              ^~~~~~~~~~~~
ed07ac
ed07ac
    GCC is right, EL_EXPLICIT is defined as returning the address of an
ed07ac
    union field:
ed07ac
ed07ac
          /* An explicit location.  */
ed07ac
          struct explicit_location explicit_loc;
ed07ac
      #define EL_EXPLICIT(P) (&((P)->u.explicit_loc))
ed07ac
ed07ac
    and thus must always be non-NULL.
ed07ac
ed07ac
diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
ed07ac
--- a/gdb/aarch64-tdep.c
ed07ac
+++ b/gdb/aarch64-tdep.c
ed07ac
@@ -3666,7 +3666,7 @@ When on, AArch64 specific debugging is enabled."),
ed07ac
 	    if (mem_len) \
ed07ac
 	      { \
ed07ac
 		MEMS =  XNEWVEC (struct aarch64_mem_r, mem_len);  \
ed07ac
-		memcpy(&MEMS->len, &RECORD_BUF[0], \
ed07ac
+		memcpy(MEMS, &RECORD_BUF[0], \
ed07ac
 		       sizeof(struct aarch64_mem_r) * LENGTH); \
ed07ac
 	      } \
ed07ac
 	  } \
ed07ac
diff --git a/gdb/location.c b/gdb/location.c
ed07ac
--- a/gdb/location.c
ed07ac
+++ b/gdb/location.c
ed07ac
@@ -960,12 +960,11 @@ event_location_empty_p (const struct event_location *location)
ed07ac
       return 0;
ed07ac
 
ed07ac
     case EXPLICIT_LOCATION:
ed07ac
-      return (EL_EXPLICIT (location) == NULL
ed07ac
-	      || (EL_EXPLICIT (location)->source_filename == NULL
ed07ac
-		  && EL_EXPLICIT (location)->function_name == NULL
ed07ac
-		  && EL_EXPLICIT (location)->label_name == NULL
ed07ac
-		  && (EL_EXPLICIT (location)->line_offset.sign
ed07ac
-		      == LINE_OFFSET_UNKNOWN)));
ed07ac
+      return (EL_EXPLICIT (location)->source_filename == NULL
ed07ac
+	      && EL_EXPLICIT (location)->function_name == NULL
ed07ac
+	      && EL_EXPLICIT (location)->label_name == NULL
ed07ac
+	      && (EL_EXPLICIT (location)->line_offset.sign
ed07ac
+		  == LINE_OFFSET_UNKNOWN));
ed07ac
 
ed07ac
     case PROBE_LOCATION:
ed07ac
       return EL_PROBE (location) == NULL;