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

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