Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1731710rwr; Fri, 28 Apr 2023 00:37:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5gnBk7OhALlxxT/Ohsfx0lU+fO3lWrKF/rqJG+XNRkZlanIZvoO4Nfdy0V10NAadh9RLKG X-Received: by 2002:a17:90b:4c43:b0:247:6c32:37e5 with SMTP id np3-20020a17090b4c4300b002476c3237e5mr4568174pjb.13.1682667456222; Fri, 28 Apr 2023 00:37:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682667456; cv=none; d=google.com; s=arc-20160816; b=IVO162HX2+7xJQIi//4y77Y9xdo70RUxMMujaAdVs7UUL2hkM6ioa3r6qYg8+2q9Gn s5PX26Sb4x4OLAp4E8oK/+BN3IrxiE2FR/ypP+eer2+bjertL7tP3QuFNcm0c7HIWcIt zxztMwn2366m4P3LONPKFNfXWpalTVNqmqvtnavB+CfL01s03uhvfHdNL8kd/bOsswsB OyJ4NCfDW7F0HLODeRWjMy/3T5vHefZLb+t04cFfuz2obi6XcOrl6M1JSifVgvMuCPaY IgCIi1mDzR3islW/+4tSgUvi7hUsXSHyrCUhN/7wC749aYHyiS9EYM5UanynHHi50/CW go1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=M+xwCY3iuEdKLaah89YYTe1ZadCgsK5vi7YFGlO9zYk=; b=eDs+byON79B1MkDKLNOLQf1G7hyxpjNG9XNMBK5zWVTGb2WyC0S8PBOfXzY/CmX1Pu pwPXOmyycXYybzZqAIi36IvEQkXcDX/rjFbM06LR/XoNoUE9ipypkUZeWzYViRY2ubBU V6caW1YRHSZeG5cPvQ22jdEJBJXsXXxeKo5ZCYjn+MzDyBZC2oj484FWO50FUOi8TAjo 4MZSP5YH063m6jU9esXThbJboYWglJz1WIN0b2NW7x0pBR/LgnPY91gds0hlfOevMYR6 xJOC401FNpaEeyjF3RP2U3dtWyGD01cgkiJ4sPn2u+EnY1mwK0CMuCWLNtjbU3Ct2j33 HmfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UgK6yNYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020aa79574000000b0063b235abe2fsi21028007pfq.64.2023.04.28.00.37.22; Fri, 28 Apr 2023 00:37:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UgK6yNYq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345500AbjD1HaM (ORCPT + 99 others); Fri, 28 Apr 2023 03:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbjD1HaK (ORCPT ); Fri, 28 Apr 2023 03:30:10 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 293372689 for ; Fri, 28 Apr 2023 00:30:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BCDB260A0F for ; Fri, 28 Apr 2023 07:30:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 26796C433EF for ; Fri, 28 Apr 2023 07:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682667009; bh=EZT+y/OIOW2KXt81ZyXZENqGfhYKcx4a5ivqT4UgSYY=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=UgK6yNYqLKgHll6zEz8WGxCTGSIg09NP7qXAqkgTslxf+zrobLG6kJA6cmzqOC7pl nHyUjLBrz4rYWKwRaSXHZXy67krrwJMFIJY8TmAdOQlNcwKTOBGpTEHaoYyXYTY3w0 jk518XMuYMmTKLjyPxlhKyYmious7Rj7kR2iMiY2GmvWIVY9jWbLxXsN3fFHzixL/g H8R35YkpDKQQr1+lDL/LxqdrDshTcYy/gfqqMQ7eyPg414zd3Wuz1fea0FcWYmfiTM 10gc6yR15a4L7IwwS5xrlJdgF8+ZJ57fhKLVCDHNOTtBhawzubjylARG2soFlTvoTh 442R0a39sNQyA== Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-4f00c33c3d6so2449842e87.2 for ; Fri, 28 Apr 2023 00:30:09 -0700 (PDT) X-Gm-Message-State: AC+VfDzjoNDMNWt59wuGJFWDjy/u5HsxzKR0cKhjWf5OGTyUFLB9KQnb 3HgI9UFux57FY7gDwC0oMVi+EVlcd78kTQuyCOw= X-Received: by 2002:a2e:2c11:0:b0:2a7:7f4a:3035 with SMTP id s17-20020a2e2c11000000b002a77f4a3035mr1212433ljs.16.1682667007198; Fri, 28 Apr 2023 00:30:07 -0700 (PDT) MIME-Version: 1.0 References: <20230428050442.180913-1-maskray@google.com> In-Reply-To: <20230428050442.180913-1-maskray@google.com> From: Ard Biesheuvel Date: Fri, 28 Apr 2023 08:29:56 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] arm64: lds: move .got section out of .text To: Fangrui Song Cc: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bill Wendling , Nick Desaulniers Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Fangrui, On Fri, 28 Apr 2023 at 06:05, Fangrui Song wrote: > > Currently, the .got section is placed within the output section .text. > However, when .got is non-empty, the SHF_WRITE flag is set when linked > by lld. GNU ld recognizes .text as a special section and ignores the > SHF_WRITE flag. By renaming .text, we can also get the SHF_WRITE flag. > > Conventionally, the .got section is placed just before .got.plt (which > should be empty and omitted in the kernel). Therefore, we move the .got > section to a conventional location (between .text and .data) and remove > the unneeded `. = ALIGN(16)`. > > Signed-off-by: Fangrui Song > --- > arch/arm64/kernel/vmlinux.lds.S | 20 ++++++++++---------- > 1 file changed, 10 insertions(+), 10 deletions(-) > > diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S > index b9202c2ee18e..2bcb3b30db41 100644 > --- a/arch/arm64/kernel/vmlinux.lds.S > +++ b/arch/arm64/kernel/vmlinux.lds.S > @@ -181,18 +181,8 @@ SECTIONS > KPROBES_TEXT > HYPERVISOR_TEXT > *(.gnu.warning) > - . = ALIGN(16); > - *(.got) /* Global offset table */ > } > > - /* > - * Make sure that the .got.plt is either completely empty or it > - * contains only the lazy dispatch entries. > - */ > - .got.plt : { *(.got.plt) } > - ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, > - "Unexpected GOT/PLT entries detected!") > - > . = ALIGN(SEGMENT_ALIGN); > _etext = .; /* End of text section */ > > @@ -247,6 +237,16 @@ SECTIONS > > . = ALIGN(SEGMENT_ALIGN); > __inittext_end = .; > + > + .got : { *(.got) } This is the .init region, which gets freed and unmapped after boot. If the GOT is non-empty, it needs to remain mapped, so we cannot place it here. We have the same issue with the .rodata section, which incorporates variables marked as __ro_after_init, which are not const qualified. So given that .rodata is already emitted as WA, and we cannot do anything about that, let's move the GOT in there. > + /* > + * Make sure that the .got.plt is either completely empty or it > + * contains only the lazy dispatch entries. > + */ > + .got.plt : { *(.got.plt) } > + ASSERT(SIZEOF(.got.plt) == 0 || SIZEOF(.got.plt) == 0x18, > + "Unexpected GOT/PLT entries detected!") > + > __initdata_begin = .; > > init_idmap_pg_dir = .; > -- > 2.40.1.495.gc816e09b53d-goog >