From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1005) id A39AF3857819; Tue, 27 Apr 2021 02:45:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A39AF3857819 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Michael Meissner To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9772] [PATCH] Backport fix for PR target/98952 X-Act-Checkin: gcc X-Git-Author: Michael Meissner X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: dc2e26fad8cc35dfb7a00f2bd758fd7b799f3107 X-Git-Newrev: a633f7f96daac391fe0bc5d87427c0e7cf1ab1b3 Message-Id: <20210427024524.A39AF3857819@sourceware.org> Date: Tue, 27 Apr 2021 02:45:24 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Apr 2021 02:45:24 -0000 https://gcc.gnu.org/g:a633f7f96daac391fe0bc5d87427c0e7cf1ab1b3 commit r10-9772-ga633f7f96daac391fe0bc5d87427c0e7cf1ab1b3 Author: Michael Meissner Date: Mon Apr 26 22:45:02 2021 -0400 [PATCH] Backport fix for PR target/98952 The test in the PowerPC 32-bit trampoline support is backwards. It aborts if the trampoline size is greater than the expected size. It should abort when the trampoline size is less than the expected size. I fixed the test so the operands are reversed. I then folded the load immediate into the compare instruction. I verified this by creating a 32-bit trampoline program and manually changing the size of the trampoline to be 48 instead of 40. The program aborted with the larger size. I updated this code and ran the test again and it passed. I added a test case that runs on PowerPC 32-bit Linux systems and it calls the __trampoline_setup function with a larger buffer size than the compiler uses. The test is not run on 64-bit systems, since the function __trampoline_setup is not called. I also limited the test to just Linux systems, in case trampolines are handled differently in other systems. libgcc/ 2021-04-26 Michael Meissner PR target/98952 * config/rs6000/tramp.S (__trampoline_setup, elfv1 #ifdef): Fix trampoline size comparison in 32-bit by reversing test and combining load immediate with compare. Fix backported from trunk change on 4/23, 886b6c1e8af502b69e3f318b9830b73b88215878. (__trampoline_setup, elfv2 #ifdef): Fix trampoline size comparison in 32-bit by reversing test and combining load immediate with compare. gcc/testsuite/ 2021-04-26 Michael Meissner PR target/98952 * gcc.target/powerpc/pr98952.c: New test. Test backported from trunk change on 4/23, 886b6c1e8af502b69e3f318b9830b73b88215878. Diff: --- gcc/testsuite/gcc.target/powerpc/pr98952.c | 28 ++++++++++++++++++++++++++++ libgcc/config/rs6000/tramp.S | 6 ++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/gcc/testsuite/gcc.target/powerpc/pr98952.c b/gcc/testsuite/gcc.target/powerpc/pr98952.c new file mode 100644 index 00000000000..c487fbc403e --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr98952.c @@ -0,0 +1,28 @@ +/* { dg-do run { target { powerpc*-*-linux* && ilp32 } } } */ +/* { dg-options "-O2" } */ + +/* PR 96983 reported that the test in libgcc's tramp.S was backwards and it + would abort if the trampoline size passed to the function was greater than + the size the runtime was expecting (40). It should abort if the size is less + than 40, not greater than 40. This test creates a call to __trampoline_setup + with a much larger buffer to make sure the function does not abort. + + We do not run this test on 64-bit since __trampoline_setup is not present in + 64-bit systems. + + We only run the test under Linux in case the other systems have some + different variant for __trampoline_setup. */ + +#ifndef SIZE +#define SIZE 100 +#endif + +extern void __trampoline_setup (int *, unsigned, void *, void *); + +int main (void) +{ + int tramp[SIZE / sizeof (int)]; + + __trampoline_setup (tramp, SIZE, 0, 0); + return 0; +} diff --git a/libgcc/config/rs6000/tramp.S b/libgcc/config/rs6000/tramp.S index 9b8fcfe34a3..47f97e93e6a 100644 --- a/libgcc/config/rs6000/tramp.S +++ b/libgcc/config/rs6000/tramp.S @@ -64,8 +64,7 @@ FUNC_START(__trampoline_setup) mflr r11 addi r7,r11,trampoline_initial-4-.LCF0 /* trampoline address -4 */ - li r8,trampoline_size /* verify that the trampoline is big enough */ - cmpw cr1,r8,r4 + cmpwi cr1,r4,trampoline_size /* verify that the trampoline is big enough */ srwi r4,r4,2 /* # words to move */ addi r9,r3,-4 /* adjust pointer for lwzu */ mtctr r4 @@ -150,8 +149,7 @@ FUNC_START(__trampoline_setup) addis 7,2,.LC0@toc@ha ld 7,.LC0@toc@l(7) /* trampoline address -8 */ - li r8,trampoline_size /* verify that the trampoline is big enough */ - cmpw cr1,r8,r4 + cmpwi cr1,r4,trampoline_size /* verify that the trampoline is big enough */ srwi r4,r4,3 /* # doublewords to move */ addi r9,r3,-8 /* adjust pointer for stdu */ mtctr r4