From: Yao Qi <yao@codesourcery.com>
To: gdb-patches@sourceware.org
Subject: Re: [patch i386, 2/2] skip insns generated by -fstack-protector
Date: Fri, 24 Dec 2010 09:36:00 -0000 [thread overview]
Message-ID: <4D145CE6.4020005@codesourcery.com> (raw)
In-Reply-To: <4D145811.4060805@codesourcery.com>
[-- Attachment #1: Type: text/plain, Size: 672 bytes --]
On 12/24/2010 04:21 PM, Yao Qi wrote:
> Patch 2 is about handling i386 stack protector insns during prologue
> analysis. Without patch 1, patch 2 doesn't work in some cases.
Here is a prologue generated by GCC, instructions on [1] are for stack
protector.
push %ebp
mov %esp,%ebp
and $0xfffffff0,%esp
add $0xffffff80,%esp
mov %gs:0x14,%eax // <---- [1]
mov %eax,0x7c(%esp) // <---- [1]
xor %eax,%eax // <---- [1]
Compared with instructions for arm stack protector, i386's counterpart
is relatively simpler. This patch is to handle them in prologue
parsing. Comments are welcome.
--
Yao Qi
[-- Attachment #2: i386_skip_stack_protector_1224.patch --]
[-- Type: text/x-patch, Size: 1884 bytes --]
gdb/
* i386-tdep.c (i386_skip_stack_protector) New.
(i386_analyze_prologue): Chain i386_skip_stack_protector.
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8c6f896..ee40603 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -1455,6 +1455,35 @@ i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
return pc;
}
+/* Check whether PC points at code that for stack protector, which
+ is usually a sequence of three instructions,
+
+ mov %gs:0x14,%eax
+ mov %eax,0x7c(%esp)
+ xor %eax,%eax
+
+ If so, returns the address of the first instruction after the
+ stack protector code or CURRENT_PC, whichever is smaller.
+ Otherwise, return PC. */
+
+static CORE_ADDR
+i386_skip_stack_protector (CORE_ADDR pc, CORE_ADDR current_pc)
+{
+ gdb_byte buf[12];
+ if (target_read_memory (pc, buf, sizeof buf))
+ return pc;
+
+ /* Instruction `mov %gs:0x14,%eax' can be regarded as `fingerprint' of a
+ sequence of code for stack protector, since it is unique and can't be
+ found elsewhere. */
+ if (/* mov %gs:0x14,%eax. */
+ buf[0] != 0x65 && buf[1] != 0xa1 && buf[2] != 14
+ && buf[10] != 0x31 /* xor %eax,%eax. */)
+ return pc;
+
+ return min (pc + 12, current_pc);
+}
+
/* Do a full analysis of the prologue at PC and update CACHE
accordingly. Bail out early if CURRENT_PC is reached. Return the
address where the analysis stopped.
@@ -1493,7 +1522,9 @@ i386_analyze_prologue (struct gdbarch *gdbarch,
pc = i386_skip_probe (pc);
pc = i386_analyze_stack_align (pc, current_pc, cache);
pc = i386_analyze_frame_setup (gdbarch, pc, current_pc, cache);
- return i386_analyze_register_saves (pc, current_pc, cache);
+ pc = i386_analyze_register_saves (pc, current_pc, cache);
+ pc = i386_skip_stack_protector (pc, current_pc);
+ return pc;
}
/* Return PC of first real instruction. */
next prev parent reply other threads:[~2010-12-24 8:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-24 8:42 [patch i386, 0/2] " Yao Qi
2010-12-24 9:15 ` Yao Qi
2010-12-24 11:28 ` Andreas Schwab
2010-12-25 14:03 ` Yao Qi
2010-12-24 9:36 ` Yao Qi [this message]
2011-01-04 15:22 ` [PING patch " Yao Qi
2011-01-13 11:56 ` Yao Qi
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=4D145CE6.4020005@codesourcery.com \
--to=yao@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