From patchwork Wed Aug 21 12:21:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dragan Mladjenovic X-Patchwork-Id: 34222 Received: (qmail 111193 invoked by alias); 21 Aug 2019 12:22:05 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 111181 invoked by uid 89); 21 Aug 2019 12:22:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_WEB, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: NAM03-CO1-obe.outbound.protection.outlook.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pz83BcKo/vejthyq3vONjImWWeD55H62CIAzyoa7QCoQmJHVL1zbyNxCb2ki0dLSlUCNqb+RHGnkrrG4FWP0T766BKwUYhCZLG8knt0JhXh3FJAC5zFAu31d6lA555Lsf095Q9L7bHDjLfAp6vJ9Y9rC9X1K2RRpaWCzR3W0UA8R1pdwlvEGQohS0dXMU4L9/rmMZilVOcMx4n9es7WQLdiUCLlOTdnVzP1Lw4e2SKoD3rtzliWNO3kCx+wF3ugCT4fI86imOU6cA2WfWHVaUfwwkr96i5y0IYXZrAfB9OjD9kbRtDbYXzbMUBIiRdWRtLMBdwji+wDrGaj8S+bDIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J8OB/3SG/tV+gFhRwj3fy2ZAwJoEl4Gxakfd9AtNWrs=; b=nZDM0/Tw7ZV/xV7W42Fz8I2nHlTSd7WhjbJ8pJv1nx2+xhKslMqH2CLsEjRKiZVBCfKekw0FZnkRvxMJOO2T25mk2LLFbhH3yOOXDSycV6gqaZvzEYgOp2dW0duJCjpBLl+xs17iIET1gz93UKSmfSyF7shzbFCi3zERVBt3lPHh0BlJFa21j7BFLJeXpXxrD4S8t5Dxih+Dxhf4bUyjb9NyDzN3REVuF4tWuDGnatU9BlRaWb2+5NOrfVlrVlybu7XRmiT/mtV2CNLhj6y5s0yOWxQ7NoTdrYRHOivYu6TyGvmJCiv7wUvKvpfn+uyrT+uuFZc49tSIzBs9Gnqdqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wavecomp.com; dmarc=pass action=none header.from=wavecomp.com; dkim=pass header.d=wavecomp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wavecomp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=J8OB/3SG/tV+gFhRwj3fy2ZAwJoEl4Gxakfd9AtNWrs=; b=RJLfZfqzXX3S1rwqgG4OmJ67/RjTo7tEOSfL6ZQsuXnB0s062H/zzoamJiHQiA2FyKOJExL5SrFAwRPIy/BJcvZjdYjISvN3N8bnhHTjiSvevx7CizecQ6wae+jtY7p8IWZYmpeYrrDSci/IqV1HuotHpEyM0Y6A91eswltVK5g= From: Dragan Mladjenovic To: "libc-alpha@sourceware.org" CC: Dragan Mladjenovic , Joseph Myers , Carlos O'Donell , Adhemerval Zanella , "Maciej W . Rozycki" , Faraz Shahbazker Subject: [PATCH v5] Mips support for PT_GNU_STACK Date: Wed, 21 Aug 2019 12:21:58 +0000 Message-ID: <1566390060-15685-1-git-send-email-dmladjenovic@wavecomp.com> authentication-results: spf=none (sender IP is ) smtp.mailfrom=dmladjenovic@wavecomp.com; x-ms-exchange-purlcount: 3 x-ms-exchange-transport-forked: True x-ms-oob-tlc-oobclassifiers: OLM:8882; received-spf: None (protection.outlook.com: wavecomp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PorSX2SZY9NCd1jgCL+jq43M2F2v5u8PSUN7dGz60Rq6Klez1g5sJ5E33vk7AVK8xnZjKjZVqmQUtDXBoHTbeQ1EH10XumBzQZEaIyWmBlE= From: "Dragan Mladjenovic" Hello everyone, This is updated v4 version of the patch as per suggestion in [1]. Best regards, Dragan [1] https://sourceware.org/ml/libc-alpha/2019-08/msg00508.html 2019-08-21 Dragan Mladjenovic * sysdeps/unix/sysv/linux/mips/Makefile (test-xfail-check-execstack): Move under mips-has-gnustack != yes. (CFLAGS-.o*, ASFLAGS-.o*): New rules. Apply -Wa,-execstack if mips-force-execstack == yes. * sysdeps/unix/sysv/linux/mips/configure: Regenerated. * sysdeps/unix/sysv/linux/mips/configure.ac (mips-force-execstack): New var. Set to yes for hard-float builds with minimum_kernel < 4.8.0 or minimum_kernel not set at all. (mips-has-gnustack): New var. Use value of libc_cv_as_noexecstack if mips-force-execstack != yes, otherwise set to no. --- sysdeps/unix/sysv/linux/mips/Makefile | 21 +++++++++++++++----- sysdeps/unix/sysv/linux/mips/configure.ac | 32 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile index 8217f42..03044e7 100644 --- a/sysdeps/unix/sysv/linux/mips/Makefile +++ b/sysdeps/unix/sysv/linux/mips/Makefile @@ -63,14 +63,25 @@ sysdep-dl-routines += dl-static sysdep_routines += dl-vdso endif - -# Supporting non-executable stacks on MIPS requires changes to both -# the Linux kernel and glibc. See -# and -# . +# If the compiler doesn't use GNU.stack note, +# this test is expected to fail. +ifneq ($(mips-has-gnustack),yes) test-xfail-check-execstack = yes endif +endif ifeq ($(subdir),stdlib) gen-as-const-headers += ucontext_i.sym endif + +ifeq ($(mips-force-execstack),yes) +CFLAGS-.o += -Wa,-execstack +CFLAGS-.os += -Wa,-execstack +CFLAGS-.op += -Wa,-execstack +CFLAGS-.oS += -Wa,-execstack + +ASFLAGS-.o += -Wa,-execstack +ASFLAGS-.os += -Wa,-execstack +ASFLAGS-.op += -Wa,-execstack +ASFLAGS-.oS += -Wa,-execstack +endif diff --git a/sysdeps/unix/sysv/linux/mips/configure.ac b/sysdeps/unix/sysv/linux/mips/configure.ac index 9147aa4..3db1b32 100644 --- a/sysdeps/unix/sysv/linux/mips/configure.ac +++ b/sysdeps/unix/sysv/linux/mips/configure.ac @@ -134,3 +134,35 @@ if test -z "$arch_minimum_kernel"; then arch_minimum_kernel=4.5.0 fi fi + +# Check if we are supposed to run on kernels older than 4.8.0. If so, +# force executable stack to avoid potential runtime problems with fpu +# emulation. +# NOTE: The check below assumes that in absence of user-provided minumum_kernel +# we will default to arch_minimum_kernel which is currently less than 4.8.0 for +# all known configurations. If this changes, the check must be updated. +AC_CACHE_CHECK([whether the compiler must use executable stack], + libc_cv_mips_force_execstack, [dnl +libc_cv_mips_force_execstack=no + if test $libc_mips_float = hard; then + if test -n "$minimum_kernel"; then + changequote(,) + min_version=$((`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`)) + changequote([,]) + if test $min_version -lt 264192; then + libc_cv_mips_force_execstack=yes + fi + else + libc_cv_mips_force_execstack=yes + fi + fi]) + +libc_mips_has_gnustack=$libc_cv_as_noexecstack + +if test $libc_cv_mips_force_execstack = yes; then + libc_mips_has_gnustack=no + AC_MSG_WARN([forcing executable stack for pre-4.8.0 Linux kernels]) +fi + +LIBC_CONFIG_VAR([mips-force-execstack],[${libc_cv_mips_force_execstack}]) +LIBC_CONFIG_VAR([mips-has-gnustack],[${libc_mips_has_gnustack}])