public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [gdb/testsuite] Fix gdb.arch/i386-avx.exp with clang
@ 2021-11-04 13:55 Tom de Vries
  2021-11-05  9:33 ` Andrew Burgess
  0 siblings, 1 reply; 14+ messages in thread
From: Tom de Vries @ 2021-11-04 13:55 UTC (permalink / raw)
  To: gdb-patches

When running test-case gdb.arch/i386-avx.exp with clang I ran into:
...
(gdb) PASS: gdb.arch/i386-avx.exp: set first breakpoint in main
continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0x000000000040052b in main (argc=1, argv=0x7fffffffd3c8) at i386-avx.c:54^M
54        asm ("vmovaps 0(%0), %%ymm0\n\t"^M
(gdb) FAIL: gdb.arch/i386-avx.exp: continue to breakpoint: \
  continue to first breakpoint in main
...

The problem is that the vmovaps insn requires an 256-bit (or 32-byte aligned
address), and it's only 16-byte aligned:
...
(gdb) p /x $rax
$1 = 0x601030
...

Fix this by copying to a sufficiently aligned address.

Tested on x86_64-linux, with both gcc and clang.
---
 gdb/testsuite/gdb.arch/i386-avx.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.arch/i386-avx.c b/gdb/testsuite/gdb.arch/i386-avx.c
index 4e938399a24..9b5323f9f76 100644
--- a/gdb/testsuite/gdb.arch/i386-avx.c
+++ b/gdb/testsuite/gdb.arch/i386-avx.c
@@ -18,6 +18,9 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <stdio.h>
+#include <stdint.h>
+#include <assert.h>
+#include <string.h>
 #include "nat/x86-cpuid.h"
 
 typedef struct {
@@ -25,7 +28,7 @@ typedef struct {
 } v8sf_t;
 
 
-v8sf_t data[] =
+v8sf_t data_orig[] =
   {
     { {  0.0,  0.125,  0.25,  0.375,  0.50,  0.625,  0.75,  0.875 } },
     { {  1.0,  1.125,  1.25,  1.375,  1.50,  1.625,  1.75,  1.875 } },
@@ -47,10 +50,33 @@ v8sf_t data[] =
 #endif
   };
 
+float data_buf[sizeof (data_orig) * 2 / sizeof (float)];
 
 int
 main (int argc, char **argv)
 {
+  v8sf_t *data;
+
+  /* Initialize data pointer.  */
+  {
+    float *p = data_buf;
+    float *data_buf_end = &data_buf[sizeof (data_buf) / sizeof (*data_buf)];
+    while (((uintptr_t)p & 0x1f) != 0
+	   && p < data_buf_end)
+      p++;
+    data = (v8sf_t *)p;
+  }
+
+  /* Check that data pointer is sufficiently aligned to use vmovaps.  */
+  assert (((uintptr_t)data & 0x1f) == 0);
+
+  /* Check that memcpy does not write out of bounds.  */
+  assert ((void *)data + sizeof (data_orig)
+	  <= (void *)data_buf + sizeof (data_buf));
+
+  /* Initialize data contents.  */
+  memcpy (data, data_orig, sizeof (data_orig));
+
   asm ("vmovaps 0(%0), %%ymm0\n\t"
        "vmovaps 32(%0), %%ymm1\n\t"
        "vmovaps 64(%0), %%ymm2\n\t"

base-commit: edc77c591add0a9c7740a9ed9f7e40358bf65dbf
-- 
2.26.2


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-12-06 15:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-04 13:55 [PATCH] [gdb/testsuite] Fix gdb.arch/i386-avx.exp with clang Tom de Vries
2021-11-05  9:33 ` Andrew Burgess
2021-11-05  9:43   ` Tom de Vries
2021-11-05 11:54     ` Andrew Burgess
2021-11-05 12:23       ` Tom de Vries
2021-11-05 12:55         ` Pedro Alves
2021-11-05 13:15           ` Tom de Vries
2021-11-05 13:20             ` Pedro Alves
2021-11-05 13:35               ` Tom de Vries
2021-11-05 13:52                 ` Andrew Burgess
2021-12-06 15:27                   ` Tom de Vries
2021-11-05 13:54                 ` Pedro Alves
2021-12-06 15:25                   ` Tom de Vries
2021-11-05 12:24       ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).