From: Nathan Froyd <froydnj@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] avoid strict-aliasing warnings in gdbserver/linux-x86-low.c
Date: Wed, 27 Apr 2011 01:40:00 -0000 [thread overview]
Message-ID: <20110427014014.GB23480@codesourcery.com> (raw)
I was compiling with a combined tree this evening when the build stopped
with:
/home/froydnj/src/combined-tree/gdb/gdbserver/linux-x86-low.c: In function âamd64_emit_constâ:
/home/froydnj/src/combined-tree/gdb/gdbserver/linux-x86-low.c:1822:3:
error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
...and several other similar errors. I don't know why, exactly; I've
been compiling with a combined tree for quite some time and this is the
first problem I've had.
Anyway, the below patch addresses the problem by using memcpy instead,
which is transformed into the same code by the compiler.
Tested on x86_64-unknown-linux-gnu. OK to commit?
-Nathan
gdb/gdbserver/
* linux-x86-low.c (amd64_emit_const): Call memcpy instead of
casting pointers.
(amd64_emit_reg, amd64_emit_int_call_1, amd64_emit_void_call_2):
(i386_emit_const, i386_emit_reg, i386_emit_int_call_1):
(i386_emit_void_call_2): Likewise.
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 88f177d..027a563 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -1819,7 +1819,7 @@ amd64_emit_const (LONGEST num)
i = 0;
buf[i++] = 0x48; buf[i++] = 0xb8; /* mov $<n>,%rax */
- *((LONGEST *) (&buf[i])) = num;
+ memcpy (&buf[i], &num, sizeof (num));
i += 8;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
@@ -1876,7 +1876,7 @@ amd64_emit_reg (int reg)
buildaddr = current_insn_ptr;
i = 0;
buf[i++] = 0xbe; /* mov $<n>,%esi */
- *((int *) (&buf[i])) = reg;
+ memcpy (&buf[i], ®, sizeof (reg));
i += 4;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
@@ -1959,7 +1959,7 @@ amd64_emit_int_call_1 (CORE_ADDR fn, int arg1)
buildaddr = current_insn_ptr;
i = 0;
buf[i++] = 0xbf; /* movl $<n>,%edi */
- *((int *) (&buf[i])) = arg1;
+ memcpy (&buf[i], &arg1, sizeof (arg1));
i += 4;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
@@ -1978,7 +1978,7 @@ amd64_emit_void_call_2 (CORE_ADDR fn, int arg1)
buildaddr = current_insn_ptr;
i = 0;
buf[i++] = 0xbf; /* movl $<n>,%edi */
- *((int *) (&buf[i])) = arg1;
+ memcpy (&buf[i], &arg1, sizeof (arg1));
i += 4;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
@@ -2301,18 +2301,19 @@ static void
i386_emit_const (LONGEST num)
{
unsigned char buf[16];
- int i, hi;
+ int i, hi, lo;
CORE_ADDR buildaddr = current_insn_ptr;
i = 0;
buf[i++] = 0xb8; /* mov $<n>,%eax */
- *((int *) (&buf[i])) = (num & 0xffffffff);
+ lo = num & 0xffffffff;
+ memcpy (&buf[i], &lo, sizeof (lo));
i += 4;
hi = ((num >> 32) & 0xffffffff);
if (hi)
{
buf[i++] = 0xbb; /* mov $<n>,%ebx */
- *((int *) (&buf[i])) = hi;
+ memcpy (&buf[i], &hi, sizeof (hi));
i += 4;
}
else
@@ -2351,7 +2352,7 @@ i386_emit_reg (int reg)
buildaddr = current_insn_ptr;
i = 0;
buf[i++] = 0xb8; /* mov $<n>,%eax */
- *((int *) (&buf[i])) = reg;
+ memcpy (&buf[i], ®, sizeof (reg));
i += 4;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
@@ -2451,7 +2452,7 @@ i386_emit_int_call_1 (CORE_ADDR fn, int arg1)
buf[i++] = 0xc7; /* movl $<arg1>,(%esp) */
buf[i++] = 0x04;
buf[i++] = 0x24;
- *((int *) (&buf[i])) = arg1;
+ memcpy (&buf[i], &arg1, sizeof (arg1));
i += 4;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
@@ -2486,7 +2487,7 @@ i386_emit_void_call_2 (CORE_ADDR fn, int arg1)
buf[i++] = 0xc7; /* movl $<arg1>,(%esp) */
buf[i++] = 0x04;
buf[i++] = 0x24;
- *((int *) (&buf[i])) = arg1;
+ memcpy (&buf[i], &arg1, sizeof (arg1));
i += 4;
append_insns (&buildaddr, i, buf);
current_insn_ptr = buildaddr;
next reply other threads:[~2011-04-27 1:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 1:40 Nathan Froyd [this message]
2011-04-27 10:24 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110427014014.GB23480@codesourcery.com \
--to=froydnj@codesourcery.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox