From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id 87D5B3858D37 for ; Thu, 6 Oct 2022 18:09:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 87D5B3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x233.google.com with SMTP id w127so2912397oiw.8 for ; Thu, 06 Oct 2022 11:09:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=jm652JMQ4KEW04IX+Fj0nfQ0DA93bu7RwkbkQz+aR80=; b=eldjvXLPIzZg/3G8NMTbtZPHbZ5az8Z8/sW2uNNmic+jIhDLGdjSCt/tKQOWa5+Vv7 dh1TwWWrN1kSQdkswSUogDDzGwkAg4WYZlj0uQn8KdPcq5JAQVQjSJ3A/oetjDpNRkX1 ToLpfXBtcd1KAfp23vuboAPF3XJwUvjDvgYYMat1gAysW7vn7T7+awHqiFgUF8hGPAl4 v4HeNHGrE2HEst3T+buPbtXpKf9mxRT/wpCdLSp3lGWAeriyUuKNSuQkQs/yKQt0QZZY MHSZp3Kj5f1+gZWstoBR3pJ4ndibk7aUuxNDWaewzMwknVro171IqB1Od7h986U6k2Pr T3eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jm652JMQ4KEW04IX+Fj0nfQ0DA93bu7RwkbkQz+aR80=; b=w5Ee6jt0rDI5O5IItwA9XcVydo6azYddru7GjU3imdxy7LlwKyzFkOOIsbHsDIdoOq zzYNR0mTLtsqIaltg1+WnooGAeX/gmLIfJgV9j1AAxUPBkqXyJbw/2elx7t97TrXGYtm 2jdDezU3fC3lIhPS3eeIRhO5VoBNXBDTixgqf6zKnZqnLtD44W8Wu4T8sz6SlDvU3QPd 3nZ1esDkSNgFzcFQXAjS4LRD9yTOlPV7r+gYRYqLM141g1IXg/5GYZsxLmQZ4/pVZaLH Ixv2XIJQQrLOtgNdwoE20Mz8ce7ddfqeZsuqKixPjPCGuUYEoyakQnRxpsbkw+/AplKs wZPw== X-Gm-Message-State: ACrzQf1jLDlEfFilaz9+m5YuHklq4xA1FZFYPBApvQDE2HajcLGGcVC8 y2Ww69MRuP3YuByKuyx+BEInQQ== X-Google-Smtp-Source: AMsMyM5StGSX7gRMpfv0RW+/Dpk+ex+MzUB6QDYelWZsUrqt8qCMr5+q6J790oSOzJA769RlYV+aOQ== X-Received: by 2002:a05:6808:124e:b0:345:b825:fe9f with SMTP id o14-20020a056808124e00b00345b825fe9fmr461219oiv.142.1665079772492; Thu, 06 Oct 2022 11:09:32 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c2:b87d:70b2:7867:2da9:30d3? ([2804:1b3:a7c2:b87d:70b2:7867:2da9:30d3]) by smtp.gmail.com with ESMTPSA id t33-20020a05687060a100b0013320d9d9casm134674oae.44.2022.10.06.11.09.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Oct 2022 11:09:32 -0700 (PDT) Message-ID: Date: Thu, 6 Oct 2022 15:09:29 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: [PATCH] csu: Fix static when PIE is enabled but static PIE is not supported (BZ #29575) Content-Language: en-US To: Siddhesh Poyarekar , libc-alpha@sourceware.org, John Paul Adrian Glaubitz References: <20221005170851.2350343-1-adhemerval.zanella@linaro.org> <83026992-a7dc-61a5-b684-c1b7ea76107c@sourceware.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <83026992-a7dc-61a5-b684-c1b7ea76107c@sourceware.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 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). > > 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