From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 06A2B384D14F for ; Thu, 20 Oct 2022 17:29:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 06A2B384D14F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x1030.google.com with SMTP id q10-20020a17090a304a00b0020b1d5f6975so273146pjl.0 for ; Thu, 20 Oct 2022 10:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=dsbDllMinx+9fzDtgFOPBqcNqxMUKSOwuGW8qNSeMfI=; b=Xj2gH9Idw/h2z+G3BqDtxaGJPptSQSSiqMbzX7reP/5queJJGSMLW2Dc6RR9whtf5R xtnoCaxmj5I3ewiGX9LrT/bf7apBPdKPqEbNEKbHxxNzpmQGDY0r19680cGitMbAVKhF oEaujuNft8PoEkyvnaaXg+aolEpXobe3Ud/+WHf5d6LdDVTAHWpT6X+pnE+txgzA3F7s M1PkQQrEIxPDCRAvMNULHVx88xn6hWuEMOFubqePzHlVeSHaLl1i70JHIs+TfbVP47MZ lSZNj92KZNeLLMyKrfpdNJL31IX3y3HWzMdnqlx0oKEWaShRq6eLya3U+H7rmckVvjVc QYEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dsbDllMinx+9fzDtgFOPBqcNqxMUKSOwuGW8qNSeMfI=; b=2nRrbF/3XXP8pxOXYw7VkKFgQ1x+v9UOrDerAi7xFVsny4GUQB2kRXWEmY+dctNG6f yy62yEA2/Fqd45Vm6tLznFvrefUG83lEtk2WW4YoIZl6K4fDSxoVyl+SU9PNNY8yWR17 So7F56x/ANxwt55DD0r3hhEaELH2+z2/Vv1EEaK5EQduKnelfU3i6o0+08e/gPaspkvY QRRrw2XrmpgSTGP04afUXBL3BI9PjpWXh6hHm1gRZFmslgAuzEf5yAKspC/Z4XhxaMEU gE/sbc2VDGc5MtR+VbRDh3ifPka83De4hgwg/vPglGAkiWygA5jJcAZ8xMQ2Q5nhTIuc WH1w== X-Gm-Message-State: ACrzQf3rV67wp9vIwgHuzpHmJLB7NUVKcswngyOOFKw07Bs7aii8oI4f wnyNEUxOw0IxsOstfaqedXyp6DDYZ89j/CO/2tY= X-Google-Smtp-Source: AMsMyM721hGibtL+JCcW7HYUO+kLGmHPLCEOpD9Aesa1NvwvTEB5tg4pSFXbNKcERCOAU2ZvFW2UU8drNGDPnZXod9c= X-Received: by 2002:a17:902:ef52:b0:17c:f072:95bc with SMTP id e18-20020a170902ef5200b0017cf07295bcmr14867309plx.28.1666286990819; Thu, 20 Oct 2022 10:29:50 -0700 (PDT) MIME-Version: 1.0 References: <578535c7-ecb9-b0c6-f34e-f3292aa6a6a8@gmail.com> In-Reply-To: <578535c7-ecb9-b0c6-f34e-f3292aa6a6a8@gmail.com> From: linted Date: Thu, 20 Oct 2022 13:29:22 -0400 Message-ID: Subject: Re: [PATCH] mips: Add appropriate linker flags when compiling with -static-pie To: Jeff Law Cc: gcc-patches@gcc.gnu.org Content-Type: multipart/alternative; boundary="0000000000002e860a05eb7aac68" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,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: --0000000000002e860a05eb7aac68 Content-Type: text/plain; charset="UTF-8" On Wed, Oct 12, 2022 at 2:18 PM Jeff Law via Gcc-patches < gcc-patches@gcc.gnu.org> wrote: > > On 9/25/22 09:49, linted via Gcc-patches wrote: > > Hello, > > I'm just checking to see if anyone has had a chance to look at this. > > > > Thank you > > > > On Wed, Sep 14, 2022 at 2:09 PM linted wrote: > > > >> Hello, > >> > >> This patch fixes missing flags when compiling with -static-pie on mips. > I > >> made these modifications based on the previously submitted static pie > patch > >> for arm as well as the working code for aarch64. > >> > >> I tested with a host of mips-elf and checked with mips-sim. This patch > was > >> also tested and used with uclibc-ng to generate static pie elfs. > >> > >> This is my first patch for gcc, so please let me know if there is > anything > >> I missed. > >> > >> > >> > >> Signed-off-by: linted > >> --- > >> gcc/config/mips/gnu-user.h | 5 +++-- > >> 1 file changed, 3 insertions(+), 2 deletions(-) > >> > >> diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h > >> index 6aad7192e69..b1c665b7f37 100644 > >> --- a/gcc/config/mips/gnu-user.h > >> +++ b/gcc/config/mips/gnu-user.h > >> @@ -56,11 +56,12 @@ along with GCC; see the file COPYING3. If not see > >> #define GNU_USER_TARGET_LINK_SPEC "\ > >> %{G*} %{EB} %{EL} %{mips*} %{shared} \ > >> %{!shared: \ > >> - %{!static: \ > >> + %{!static:%{!static-pie: \ > >> %{rdynamic:-export-dynamic} \ > >> %{mabi=n32: -dynamic-linker " GNU_USER_DYNAMIC_LINKERN32 "} \ > >> %{mabi=64: -dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \ > >> - %{mabi=32: -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}} \ > >> + %{mabi=32: -dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "}}} \ > >> + %{static-pie:-Bstatic -pie --no-dynamic-linker -z text} \ > >> %{static}} \ > > This is a bit out of my usual areas of expertise. But what I find odd > here is that for -static we essentially do nothing, but for -static-pie > we need "-Bstatic -pie --no-dynamic-linker -z text". Is the -Bstatic > really needed for static-pie And if it is, then wouldn't it be needed > for -static as well? If you look carefully at aarch64, you'll see it > includes -Bstatic for -static. > > > Jeff > This is a really good question. From what I can tell, the linker will treat -Bstatic and -static identically. So when compiling with -static, adding a -Bstatic is redundant since the -static will be passed on to the linker. In the case of -static-pie, we need to explicitly specify -Bstatic so that the linker will know that we want the binary to be statically linked since there is no -static being passed on. I am of the opinion that we should usually be explicit, but in this case, I think it is more prudent to change less code. --0000000000002e860a05eb7aac68--