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

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