From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from black.elm.relay.mailchannels.net (black.elm.relay.mailchannels.net [23.83.212.19]) by sourceware.org (Postfix) with ESMTPS id BE7383858437 for ; Wed, 5 Oct 2022 19:05:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE7383858437 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 EF912803874; Wed, 5 Oct 2022 19:05:01 +0000 (UTC) Received: from pdx1-sub0-mail-a305 (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 7EAEC8030C9; Wed, 5 Oct 2022 19:05:01 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1664996701; a=rsa-sha256; cv=none; b=L8g/dD8nejWRFEIXZPGfruoSxNAbDoJifK/ZNq3nDyp4jEANog6r/INhLZ4vTJIpHQYAGz CPStUQIDRz9aX0S9/EtbVpbPN5IJTHTJoKWMcl40oXLRKLJbuMffAEl83YW4Bs8sW1B3Sn tuZldvup3wKWMZj9iQVOwt725+xVfoT73YIyutwlrSIfvTSO16MP0GSxw+i9CN3z96iuAY GH6xPxALMsBvolX0Q3com67DMdmRyJAxbYNNDWW4itjnEZGbfwqojaHO08b3Pk4x/i65w5 91OkLxoH55E7DNMBJ2/AFXkTiXPfVPclwqCXuQ8aQupeM8qYpZLbj5aRT96FOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1664996701; 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=XKl0yXP7GHYWj0deeDE++JoiRN6W8HRAQFJRVvQNqdQ=; b=aLMzUFBX9myuTd59WuZm6+h5HTLHsRSYoK7adfjPhAkBrRMfUphq+Z2bazpAZXyWT0PuUL 5dv1b3PprXWfi2tpFqenOyCRyAQY0umxZNZTMQXilUw4ntGVYZp5gAitFc9PIt3BBsgqPF z25yaUs6aq0h3W5/DWUI1MFL+FaPzkTM9mPtnERLd5MjoBPFUFO2invhqWVUCGbp7d1RA4 rDOuLTz8hAA3PUs53UIXalNsDNK4c2Iid07lY8ejTq8/9OvVjCfTrLpg6VDlFE+PzZWzop KJCHw9n8yj46g1TLKOPxbP//UQRvQwfu7Xb+ngkEcyrz6cKz9LXmhwz6Opz7+Q== ARC-Authentication-Results: i=1; rspamd-6d4bb977-7grlg; 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-White-Imminent: 50aa1c0f73df0812_1664996701826_3263136483 X-MC-Loop-Signature: 1664996701826:1693650379 X-MC-Ingress-Time: 1664996701825 Received: from pdx1-sub0-mail-a305 (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.98.207.144 (trex/6.7.1); Wed, 05 Oct 2022 19:05:01 +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)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a305 (Postfix) with ESMTPSA id 4MjPCJ4p7rz4Z; Wed, 5 Oct 2022 12:05:00 -0700 (PDT) Message-ID: <83026992-a7dc-61a5-b684-c1b7ea76107c@sourceware.org> Date: Wed, 5 Oct 2022 15:04:59 -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 , libc-alpha@sourceware.org, John Paul Adrian Glaubitz References: <20221005170851.2350343-1-adhemerval.zanella@linaro.org> From: Siddhesh Poyarekar In-Reply-To: <20221005170851.2350343-1-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1174.1 required=5.0 tests=BAYES_00,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-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? 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/ > +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