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

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