From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7686 invoked by alias); 6 May 2011 00:46:46 -0000 Received: (qmail 7676 invoked by uid 22791); 6 May 2011 00:46:45 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from mel.act-europe.fr (HELO mel.act-europe.fr) (194.98.77.210) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 06 May 2011 00:46:31 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 71D50CB024B; Fri, 6 May 2011 02:46:29 +0200 (CEST) Received: from mel.act-europe.fr ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8Y5WIUhvKEmv; Fri, 6 May 2011 02:46:26 +0200 (CEST) Received: from cognac.eu.adacore.com (cognac.act-europe.fr [10.10.1.38]) by mel.act-europe.fr (Postfix) with ESMTP id 7B7D9CB01D3; Fri, 6 May 2011 02:46:26 +0200 (CEST) Received: by cognac.eu.adacore.com (Postfix, from userid 560) id 7A370EA83CA; Fri, 6 May 2011 02:46:26 +0200 (CEST) From: Jerome Guitton To: gdb-patches@sourceware.org Cc: Jerome Guitton Subject: [RFA] sparc-solaris stack-checking - new prologue sequence Date: Fri, 06 May 2011 00:46:00 -0000 Message-Id: <1304642774-21950-1-git-send-email-guitton@adacore.com> Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00170.txt.bz2 This patch should fix gdb.base/stack-checking.exp on sparc-solaris. GCC generates some new sequences for stack checking, we just need to recognize them. Compare: sethi ,%g1 sub %sp, %g1, %g1 sethi , %g4 sub %g1, %g4, %g4 cmp %g1, %g4 be add %g1, -, %g1 ba st [%g0, [%g1]] clr [%g4 - some immediate] with this new sequence: sethi ,%g1 sethi , %g4 sub %sp, %g1, %g1 sub %g1, %g4, %g4 cmp %g1, %g4 be add %g1, -, %g1 ba st [%g0, [%g1 - 0]] [clr [%g4 - some immediate]] Two differences: * first, the probing loop has been slightly reordered; * second, to clear a memory location, GCC may now generate "st %g0, [%g1+0]" instead of "st %g0, [%g1]". The same effect, but a different instruction format. Also, the last probe may not be generated if the probe loop leaves no remainder. I cannot run the testsuite on sparc solaris, as it crashes the machine pretty badly. We ought to identify the test that causes this crash. I could run stack-checking.exp and check that it fixes one regression though. And I tested against AdaCore's testsuite, which is already a fairly good insurance that this patch is safe. OK to apply? gdb/ChangeLog: * sparc-tdep.c (sparc_skip_stack_check): Recognize a new instruction sequence for probing loops. --- gdb/sparc-tdep.c | 68 +++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 52 insertions(+), 16 deletions(-) diff --git a/gdb/sparc-tdep.c b/gdb/sparc-tdep.c index 1039bd8..947d812 100644 --- a/gdb/sparc-tdep.c +++ b/gdb/sparc-tdep.c @@ -609,9 +609,28 @@ sparc_skip_stack_check (const CORE_ADDR start_pc) CORE_ADDR pc = start_pc; unsigned long insn; int offset_stack_checking_sequence = 0; + int probing_loop = 0; /* With GCC, all stack checking sequences begin with the same two - instructions. */ + instructions, plus an optional one in the case of a probing loop: + + sethi ,%g1 + sub %sp, %g1, %g1 + + or: + + sethi ,%g1 + sethi , %g4 + sub %sp, %g1, %g1 + + or: + + sethi ,%g1 + sub %sp, %g1, %g1 + sethi , %g4 + + If the optional instruction is found (setting g4), assume that a + probing loop will follow. */ /* sethi ,%g1 */ insn = sparc_fetch_instruction (pc); @@ -619,9 +638,17 @@ sparc_skip_stack_check (const CORE_ADDR start_pc) if (!(X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 1)) return start_pc; - /* sub %sp, %g1, %g1 */ + /* optional: sethi , %g4 */ insn = sparc_fetch_instruction (pc); pc = pc + 4; + if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4) + { + probing_loop = 1; + insn = sparc_fetch_instruction (pc); + pc = pc + 4; + } + + /* sub %sp, %g1, %g1 */ if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x4 && !X_I(insn) && X_RD (insn) == 1 && X_RS1 (insn) == 14 && X_RS2 (insn) == 1)) return start_pc; @@ -629,6 +656,14 @@ sparc_skip_stack_check (const CORE_ADDR start_pc) insn = sparc_fetch_instruction (pc); pc = pc + 4; + /* optional: sethi , %g4 */ + if ((X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4)) + { + probing_loop = 1; + insn = sparc_fetch_instruction (pc); + pc = pc + 4; + } + /* First possible sequence: [first two instructions above] clr [%g1 - some immediate] */ @@ -680,22 +715,21 @@ sparc_skip_stack_check (const CORE_ADDR start_pc) } /* Third sequence: A probing loop. - [first two instructions above] - sethi , %g4 + [first three instructions above] sub %g1, %g4, %g4 cmp %g1, %g4 be add %g1, -, %g1 ba clr [%g1] + + And an optional last probe for the remainder: + clr [%g4 - some immediate] */ - /* sethi , %g4 */ - else if (X_OP (insn) == 0 && X_OP2 (insn) == 0x4 && X_RD (insn) == 4) + if (probing_loop) { /* sub %g1, %g4, %g4 */ - insn = sparc_fetch_instruction (pc); - pc = pc + 4; if (!(X_OP (insn) == 2 && X_OP3 (insn) == 0x4 && !X_I(insn) && X_RD (insn) == 4 && X_RS1 (insn) == 1 && X_RS2 (insn) == 4)) return start_pc; @@ -726,22 +760,24 @@ sparc_skip_stack_check (const CORE_ADDR start_pc) if (!(X_OP (insn) == 0 && X_COND (insn) == 0x8)) return start_pc; - /* clr [%g1] */ + /* clr [%g1] (st %g0, [%g1] or st %g0, [%g1+0]) */ insn = sparc_fetch_instruction (pc); pc = pc + 4; - if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && !X_I(insn) - && X_RD (insn) == 0 && X_RS1 (insn) == 1)) + if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 + && X_RD (insn) == 0 && X_RS1 (insn) == 1 + && (!X_I(insn) || X_SIMM13 (insn) == 0))) return start_pc; - /* clr [%g4 - some immediate] */ + /* We found a valid stack-check sequence, return the new PC. */ + + /* optional: clr [%g4 - some immediate] */ insn = sparc_fetch_instruction (pc); pc = pc + 4; if (!(X_OP (insn) == 3 && X_OP3(insn) == 0x4 && X_I(insn) && X_RS1 (insn) == 4 && X_RD (insn) == 0)) - return start_pc; - - /* We found a valid stack-check sequence, return the new PC. */ - return pc; + return pc - 4; + else + return pc; } /* No stack check code in our prologue, return the start_pc. */ -- 1.7.0.2