From patchwork Thu Dec 15 14:40:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nix X-Patchwork-Id: 706137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tfbhf0X05z9t0q for ; Fri, 16 Dec 2016 01:40:33 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="XbZGBkp5"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-type; q=dns; s=default; b=qJNtc 8ESholESwYftPREURWeTyMc8aUbUcHbLDObKijT0em7tEFW/woVJT8WObIIFwTC4 /lrgJHdzsmvcHYSqfRwKc5px18exF1UwcCsWSleli0/pISgh2nE4+c0FaqnAkdUt 1ke7eiEwraKtTkcin+JZ6NaukR6+Lvo+ECH7A0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:references:date:in-reply-to :message-id:mime-version:content-type; s=default; bh=we3ZtMyYn2u V5wfYE11fGIeVrgA=; b=XbZGBkp55vAz4lOPsOuoQWqJg/EaoDZ10WwKvvaiMkz JjH1SuK5FMwVCfTEnMGdN3vCILw3IwfCejbepzTRaIBpQrs9ZTktgEasvVsI2p+K 6I+W2a+LyrzsUbBpt26P7CUkxMrA3PlxtaRCHK+eDYMODdqgV3PrIKdwT732pTTE = Received: (qmail 4453 invoked by alias); 15 Dec 2016 14:40:26 -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 3769 invoked by uid 89); 15 Dec 2016 14:40:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.6 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=(unknown) X-HELO: mail.esperi.org.uk From: Nix To: Florian Weimer Cc: libc-alpha@sourceware.org, Adhemerval Zanella Subject: Re: [PATCH 08/12] De-PLTize __stack_chk_fail internal calls within libc.so. References: <20161128123228.30856-1-nix@esperi.org.uk> <20161128123228.30856-9-nix@esperi.org.uk> <87y3zhjn1s.fsf@esperi.org.uk> <78b1f109-91e5-4150-4c00-15a86aacb2f7@redhat.com> <87poktjmfn.fsf@esperi.org.uk> Date: Thu, 15 Dec 2016 14:40:10 +0000 In-Reply-To: (Florian Weimer's message of "Thu, 15 Dec 2016 15:33:16 +0100") Message-ID: <87lgvhjlx1.fsf@esperi.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.94 (gnu/linux) MIME-Version: 1.0 X-DCC--Metrics: spindle 1480; Body=3 Fuz1=3 Fuz2=3 On 15 Dec 2016, Florian Weimer uttered the following: > On 12/15/2016 03:29 PM, Nix wrote: >> On 15 Dec 2016, Florian Weimer told this: >>> I wonder if it's better to add something to $(no-stack-protector) and use that in the conditional. >> >> That was my other option, but the total absence of anything in >> configure.ac passing -D made me think twice. >> >> Something like this? (even more untested than the last one, if >> possible -- but adds a new possibility: we can now differentiate between >> "glibc built without stack protector" and "glibc built with stack >> protector but this file doesn't have it" without relying on GCC >> predefined macros. The __WITH_ naming scheme is completely arbitrary >> and I can change it to anything you prefer.) > > WITH_STACK_PROTECTOR (without the leading underscores) looks okay to > me because it's only used at build time. Or you could call it > STACK_PROTECTOR_LEVEL, to match the other variable. That's definitely the best choice, because it means we don't need to change configure.ac as much, and we don't have a confusing mix of nonzero STACK_PROTECTOR_LEVEL and zero WITH_STACK_PROTECTOR (or whatever) in some files. It needs a tiny adjustment of config.h.in to stop it being overridden though. Something like this: diff --git a/config.h.in b/config.h.in index 610fa49..82f95a6 100644 --- a/config.h.in +++ b/config.h.in @@ -52,8 +52,11 @@ __attribute__ ((__optimize__)). */ #undef HAVE_CC_NO_STACK_PROTECTOR -/* The level of stack protection in use for glibc as a whole. */ +/* The level of stack protection in use for glibc as a whole. + May be overridden on a file-by-file basis. */ +#ifndef STACK_PROTECTOR_LEVEL #undef STACK_PROTECTOR_LEVEL +#endif /* Define if the regparm attribute shall be used for local functions (gcc on ix86 only). */ diff --git a/configure.ac b/configure.ac index 2396c1f..a420428 100644 --- a/configure.ac +++ b/configure.ac @@ -638,7 +638,7 @@ LIBC_TRY_CC_OPTION([$CFLAGS $CPPFLAGS -Werror -fstack-protector-all], stack_protector= no_stack_protector= if test "$libc_cv_ssp" = yes; then - no_stack_protector="-fno-stack-protector" + no_stack_protector="-fno-stack-protector -DSTACK_PROTECTOR_LEVEL=0" AC_DEFINE(HAVE_CC_NO_STACK_PROTECTOR) fi diff --git a/sysdeps/generic/symbol-hacks.h b/sysdeps/generic/symbol-hacks.h index 36908b5..15ff56a 100644 --- a/sysdeps/generic/symbol-hacks.h +++ b/sysdeps/generic/symbol-hacks.h @@ -7,5 +7,7 @@ asm ("memcpy = __GI_memcpy"); /* -fstack-protector generates calls to __stack_chk_fail, which need similar adjustments to avoid going through the PLT. */ +# if defined STACK_PROTECTOR_LEVEL && STACK_PROTECTOR_LEVEL > 0 asm ("__stack_chk_fail = __stack_chk_fail_local"); +# endif #endif