From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id D03023948A77 for ; Thu, 13 Jan 2022 12:52:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D03023948A77 Received: by mail-pl1-x62c.google.com with SMTP id b3so568021plc.7 for ; Thu, 13 Jan 2022 04:52:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=U0cH+xvUtSxloYfVH6iGtlOm4AyRrcNBLEBArn07AMI=; b=H35OXGAm3y9oh/ktbKBRE4+8DybXW8jst8tXmxClPWehyEcWoqVOB7XyvPIYWOy/Ew PSI6u6zqS/wRoeyr/mBadcg41Ap3sqlT7K4DHyCZYtNp3InIYbuoi0jptYU5wD7wCFhz 3H8FpUTkiMXUvjZzY3bDwawMF2n5FxnhadJySMrpNRc3qYShKzwEpOdws+jBuqpA7+os 3m1lQscynohJ92w+z/CAlcnkqdOmDTxmriNmAatVxsCg0n3T0zN/zpaCH9gC/IWq/PZy dUtvXfTrQHdgjNmJzpenJqhRFt7ha7yotT9klFKV6FaTc1atABfxQMd/mDTxaSRM07tG pcfA== X-Gm-Message-State: AOAM530KZ83qdE5cLDQkk31HRqXaMI00P4szNrGNnUFUGr7TvP8UNNQW F7B3HcbduUQps9K3viQxYmXwJwmxcd8= X-Google-Smtp-Source: ABdhPJy0rLD3Y+CG4SWuu6HBDFWNqVe/rFqECPzFp7Ja4auH5BeWJNiQiiw/0T7xAiNiEmw61EyvhA== X-Received: by 2002:a17:90b:3907:: with SMTP id ob7mr4937470pjb.176.1642078377992; Thu, 13 Jan 2022 04:52:57 -0800 (PST) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id d12sm3072251pfv.172.2022.01.13.04.52.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jan 2022 04:52:57 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 5ACCA1140EEC; Thu, 13 Jan 2022 23:22:54 +1030 (ACDT) Date: Thu, 13 Jan 2022 23:22:54 +1030 From: Alan Modra To: "H.J. Lu" Cc: binutils@sourceware.org Subject: Re: [PATCH] elf: Remove the 1-page gap before the RELRO segment Message-ID: References: <20220111021241.1937265-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220111021241.1937265-1-hjl.tools@gmail.com> X-Spam-Status: No, score=-3032.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2022 12:53:00 -0000 On Mon, Jan 10, 2022 at 06:12:41PM -0800, H.J. Lu via Binutils wrote: > The existing RELRO scheme may leave a 1-page gap before the RELRO segment > and align the end of the RELRO segment to the page size: > > [18] .eh_frame PROGBITS 408fa0 008fa0 005e80 00 A 0 0 8 > [19] .init_array INIT_ARRAY 410de0 00fde0 000008 08 WA 0 0 8 > [20] .fini_array FINI_ARRAY 410de8 00fde8 000008 08 WA 0 0 8 > [21] .dynamic DYNAMIC 410df0 00fdf0 000200 10 WA 7 0 8 > [22] .got PROGBITS 410ff0 00fff0 000010 08 WA 0 0 8 > [23] .got.plt PROGBITS 411000 010000 000048 08 WA 0 0 8 Do you know what is going wrong with the relro section layout for this to occur? In this particular case, the end of the read-only segment is at 0x408fa0 + 0x5e80 = 0x40ee20. My guess is that layout of the following rw sections starts on the next page plus current offset within page, the standard choice to minimise disk pages. ie. We start at 0x40fe20. Then discover that this puts .got.plt at 0x40fe20 + 8 + 8 + 0x200 + 0x10 = 0x40f040. However, we want this to be on a page boundary so that the relro segment ends on a page boundary. So we bump 0x40f040 up to 0x411000 and calculate backwards from there to arrive at .init_array with a vma of 0x410de0. Resulting in the 0x40f000 page being unused. If instead we start relro layout on the next page, we'd start laying out at 0x40f000 rather than 0x40fe20. I think that would be the correct thing to do rather than fixing up afterwards as your patch does. -- Alan Modra Australia Development Lab, IBM