From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aye.elm.relay.mailchannels.net (aye.elm.relay.mailchannels.net [23.83.212.6]) by sourceware.org (Postfix) with ESMTPS id E0481388451B for ; Thu, 6 Oct 2022 18:21:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0481388451B Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 67D5B820AC6; Thu, 6 Oct 2022 18:21:13 +0000 (UTC) Received: from pdx1-sub0-mail-a307 (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id D02198200C5; Thu, 6 Oct 2022 18:21:12 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1665080472; a=rsa-sha256; cv=none; b=N5SmekvjDqwrAK9kES5rGTrkSbRUTxw3Yp84mivYIW+PbgCTvXb6zZs4T2ukwwJIONpc56 Q1K8f1uP7N0zdS7zI7y0/Bb1m0X6lWwjNgYlrYKMhu2x8U3KOhjlc2m3ST6FoOLU8GlM1m Jb2dabgADCwG8z9ZTlFWdAj+WIcJGlPDm1/2/9MBIUo80OWmm7Xw+PdtllSED4GKWQKMGw vDL7HJYBBSbvY/KTPYXppJrwbLQLak9qgh8MWhL9SdFANsFWg31wx8QJkNPXuo6eDIFIMA Tpyxex2wkguaIUW543WXc8Xhb+CBYhfGnMgBWFOgwaFBOnodS78a+zNcnOQ6pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1665080472; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gS8WN14/QYMydmOA7tKgimh5sZvB46qigqAlVo6kMAg=; b=kReVvtC2a5BdNuYValcMB5hzqCBs4A1qwH6FvTWGU3C2pg0uLGWXUQ0h86j26bXUc2qUxt 6CPW6UmkpTNSDe/4YFt3OcckIfzOF0CsYU4r/U+jtL1MfFmowVlJykAPk0Un5aKXXdSmBz vuEfljSI+J6ukPkoiq+k+A5WvB5mQFk3MOP2aIqAhoC8judxJMmg5xdNVS6llbSxue91Rl zd56L4KxV32unBgxE6AD/EIH+VE3T91Csig+/Q++rxOse8svyvwl+CbnvB2sIYNzGVC2kg 4quRjsTGSDhvxW9EZthAWITiE3NfNVlUbhsWm+V5rqqYtNqtZBTPTQuaYNda/A== ARC-Authentication-Results: i=1; rspamd-7c485dd8cf-5v8k9; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Harbor-Keen: 331ffc3f43b6340d_1665080473205_2764314159 X-MC-Loop-Signature: 1665080473205:1817329758 X-MC-Ingress-Time: 1665080473205 Received: from pdx1-sub0-mail-a307 (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.183.82 (trex/6.7.1); Thu, 06 Oct 2022 18:21:13 +0000 Received: from [192.168.0.182] (bras-base-toroon4834w-grc-23-76-68-24-82.dsl.bell.ca [76.68.24.82]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a307 (Postfix) with ESMTPSA id 4Mk0BH330DzVL; Thu, 6 Oct 2022 11:21:10 -0700 (PDT) Message-ID: <05cc7966-d9fe-3241-d48b-35457ea094a4@sourceware.org> Date: Thu, 6 Oct 2022 14:21:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: [PATCH] csu: Fix static when PIE is enabled but static PIE is not supported (BZ #29575) Content-Language: en-US To: Adhemerval Zanella Netto , libc-alpha@sourceware.org, John Paul Adrian Glaubitz References: <20221005170851.2350343-1-adhemerval.zanella@linaro.org> <83026992-a7dc-61a5-b684-c1b7ea76107c@sourceware.org> From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1172.7 required=5.0 tests=BAYES_00,BODY_8BITS,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 2022-10-06 14:09, Adhemerval Zanella Netto wrote: > > > On 05/10/22 16:04, Siddhesh Poyarekar wrote: >> >> >> On 2022-10-05 13:08, Adhemerval Zanella wrote: >>> On architectures where static PIE is not supported, both libc and >>> static binaries are built still with -fPIE and -DPIC.  It leads to >>> wrong code for some architectures (for instance sparc). >>> >>> This patch only enables -DPIC for .o files iff static-pie is also >>> supported.  Since the same rule is used for both libc.a objects and >>> installed binaries, the -fno-pie is added if static-pie is not >>> supported (with a strategy similar to how stack protector is >>> disabled for some architectures). >>> >>> Checked on x86_64-linux-gnu (with and without --disable-static-pie) >>> and I also checked on sparc64-linux-gnu to verify that static binaries >>> are not broken and both binaries and tests continue to be built >>> for PIE. >>> --- >> >> It should be --disable-default-pie.  Can you please check again and confirm? > > My mistake, I did use --disable-default-pie (the config.make files on > sparc64 build differs for build-pie-default). OK then it looks good with the typo fixed. Thanks, Sid > >> >> Thanks, >> Sid >> >>>   Makeconfig            | 15 +++++++++++++++ >>>   Makerules             |  7 +++++++ >>>   csu/Makefile          |  4 ++++ >>>   stdio-common/Makefile |  4 ++-- >>>   4 files changed, 28 insertions(+), 2 deletions(-) >>> >>> diff --git a/Makeconfig b/Makeconfig >>> index 842f49eb58..4b0d9003cd 100644 >>> --- a/Makeconfig >>> +++ b/Makeconfig >>> @@ -404,6 +404,9 @@ else >>>   # for PIE to support exception. >>>   static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text >>>   endif # have-static-pie >>> +else >>> +no-static-pie = $(no-pie-ccflag) >>> +no-pic-flag = -UPIC >>>   endif # enable-static-pie >>>   endif # build-pie-default >>>   @@ -901,6 +904,18 @@ define elide-stack-protector >>>   $(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector)) >>>   endef >>>   +# If static-pie is not supported, add the compiler option to avoid building it >>> +# for pie and to remove the PIC define.  The first argument is the extension >>> +# (.o, .os, .oS) and the second is a list of routines that this path should be >>> +# applied to. >>> +define elide-pie >>> +$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-static-pie)) >>> +endef >>> +# Smae as elide-pie, but remove the PIC flag. >> >> s/Smae/Same/ >> > > Ack. > >>> +define elide-pic-flag >>> +$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-pic-flag)) >>> +endef >>> + >>>   # The program that makes Emacs-style TAGS files. >>>   ETAGS    := etags >>>   diff --git a/Makerules b/Makerules >>> index 09c0cf8357..0fcaf565eb 100644 >>> --- a/Makerules >>> +++ b/Makerules >>> @@ -1239,6 +1239,13 @@ tests += $(foreach t,$(tests-time64),$(t)) >>>   xtests += $(foreach t,$(xtests-time64),$(t)) >>>   endif >>>   +# Disable static-pie for libc.a if target does not support it. >>> +CFLAGS-.o += $(call elide-pie,.o,$(routines)) >>> +CFLAGS-.op += $(call elide-pie,.op,$(routines)) >>> +# And also remove the PIC flag. >>> +CPPFLAGS-.o += $(call elide-pic-flag,.o,$(routines)) >>> +CPPFLAGS-.op += $(call elide-pic-flag,.op,$(routines)) >> >> All static routines.  OK. >> >>> + >>>   # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is >>>   # that almost all internal declarations from config.h, libc-symbols.h, and >>>   # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code. >>> diff --git a/csu/Makefile b/csu/Makefile >>> index f71a5eb6c6..62a819608f 100644 >>> --- a/csu/Makefile >>> +++ b/csu/Makefile >>> @@ -66,6 +66,10 @@ CFLAGS-.os += $(call elide-stack-protector,.os,$(filter-out \ >>>                            $(ssp-safe.os), \ >>>                            $(routines) $(extra-no-ssp))) >>>   +# Remove PIC flag for init objects. >>> +CPPFLAGS-.o += $(call elide-pic-flag,.o,$(basename $(extra-objs))) >>> +CPPFLAGS-.op += $(call elide-pic-flag,.op,$(basename $(extra-objs))) >>> + >> >> crt* too.  OK. >> >>>   ifeq (yes,$(build-shared)) >>>   extra-objs += S$(start-installed-name) gmon-start.os >>>   ifneq ($(start-installed-name),$(static-start-installed-name)) >>> diff --git a/stdio-common/Makefile b/stdio-common/Makefile >>> index 9c98c02884..6eee9ba73c 100644 >>> --- a/stdio-common/Makefile >>> +++ b/stdio-common/Makefile >>> @@ -265,7 +265,7 @@ $(objpfx)errlist-data-aux-shared.S: errlist-data-gen.c >>>     $(objpfx)errlist-data-aux.S: errlist-data-gen.c >>>       $(make-target-directory) >>> -    $(compile-command.c) $(pie-default) $(no-stack-protector) -S >>> +    $(compile-command.c) $(pic-cppflags) $(pic-ccflag) $(no-stack-protector) -S >>>     ifndef no_deps >>>   -include $(objpfx)errlist-data-aux.S.d $(objpfx)errlist-data-aux-shared.S.d >>> @@ -280,7 +280,7 @@ $(objpfx)siglist-aux-shared.S: siglist-gen.c >>>     $(objpfx)siglist-aux.S: siglist-gen.c >>>       $(make-target-directory) >>> -    $(compile-command.c) $(pie-default) $(no-stack-protector) -S >>> +    $(compile-command.c) $(pic-cppflags) $(pic-ccflag) $(no-stack-protector) -S >>>     ifndef no_deps >>>   -include $(objpfx)siglist-aux.S.d $(objpfx)siglist-aux-shared.S.d >