From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id 6961239915BF for ; Mon, 19 Dec 2022 05:00:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6961239915BF 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-x1033.google.com with SMTP id hd14-20020a17090b458e00b0021909875bccso12986781pjb.1 for ; Sun, 18 Dec 2022 21:00:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=k9rspBcf+Lkm6xRdxls+R2YPLRCYU2SuBjR1AqNfU9Y=; b=YzMRUWsa9tMMJTKHSDgE5+1oI6nsqG1h57qiGOIBfrcl4BPmNg8jid41Huj966c48m maOTUAbkAP22nvkVM4SOZa/mjRSXSa29NxMxrAzkXJLrjPVBj1ia1Iz44sHPyMiZgqMf L/hH/ArunmdXvAis5+RpA++7BXcRdpTF5DR+OiLWU88OLchFKqKr8IaAXPbcPahfKXmk RcgyVPSflJZobM5ZVj7MnG+SeiBseCZojINcEc8BPgRN0t/dQG0oqZ3dVs/+IwfHtmaq 91ffH7TpqGfVXbVGtjEvowhL7ppZscfbGvYgF/LikGCDoXBisqSbdGPkuol9YBhET5Q+ aM+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc: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=k9rspBcf+Lkm6xRdxls+R2YPLRCYU2SuBjR1AqNfU9Y=; b=PmWq2j6b7hBovrMAV57OUKm10nWCy3dMJRwgizTlUXtAA+7r4exIwi9jYnJRv3Bp0P /Laogyg66yjbAXMaZR2jYuD0dFMCeJihsKtrZTN/8xuZVHlsA4kNqy+2/uzOatVppfJI g11jnymHsifx2Ef4P/DXyIUuuBAlFA9KH36YI8aEMa91kyKRg93gc87HcepX2Rql+xCc NMc2y7AFxM2q9klVtKp5eAvwmVyNAsdCLzuNPG3iq76AuJqgIT6e2QCOr7R7CWzxBQkW KhCut8HURFrMZl2VeoPrMS1OvDv7PLT3W2NnbrgPoltVAQW2CxNQFTe9t4+loyY+7pVw By2g== X-Gm-Message-State: AFqh2kp1HknMxLF/ydOahJVG4R3HdxqbgiuscC5mDcW6DtAXbwhafBc/ k+Zbg/h1VJtTVs1gMSCqsvM= X-Google-Smtp-Source: AMrXdXt+5PbMxzawn81dLQDmedTHwglTtUfpVGrlNnm8BT30OO8MC+Ey9oGLv4j98l1x0S6OiURVBA== X-Received: by 2002:a17:902:70cb:b0:191:cd3:aa74 with SMTP id l11-20020a17090270cb00b001910cd3aa74mr9093929plt.24.1671426056184; Sun, 18 Dec 2022 21:00:56 -0800 (PST) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id n13-20020a170903110d00b00186b3c3e2dasm5935887plh.155.2022.12.18.21.00.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 18 Dec 2022 21:00:55 -0800 (PST) Message-ID: <156f7916-a542-c8aa-6574-be6f30509cfb@gmail.com> Date: Sun, 18 Dec 2022 22:00:54 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [RFC PATCH] ld/emulparams: elf32lriscv-defs: Add support tune the text segment start address Content-Language: en-US To: "Lad, Prabhakar" , Fangrui Song Cc: Lad Prabhakar , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , binutils@sourceware.org References: <20221216214310.13155-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20221218062404.cn75smc4pperrsd7@gmail.com> From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 12/18/22 15:44, Lad, Prabhakar via Binutils wrote: > Hi Fangrui, > > Thank you for the feedback. > > On Sun, Dec 18, 2022 at 6:24 AM Fangrui Song wrote: >> >> On 2022-12-16, Lad Prabhakar via Binutils wrote: >>> On the RISC-V architecture the TEXT_START_ADDR defaults to 0x10000. On >>> some RISC-V platforms we want to set this offset to something else. So >>> this patch provides a way to tune the text segment start address. >>> elf32lriscv-defs.sh now checks for DEFAULT_TEXT_START_ADDR variable and >>> if being set it overrides TEXT_START_ADDR to the value set by >>> DEFAULT_TEXT_START_ADDR or else defaults to 0x10000. >>> >>> Renesas RZ/Five RISC-V SoC has Instruction local memory and Data local >>> memory (ILM & DLM) which maps between region 0x30000 - 0x4FFFF. When the >>> virtual address falls in this range the MMU doesn't trigger a page >>> fault and assumes the virtual address as physical address and causes >>> undesired behaviours of statically applications/libraries. Hence introduce >>> an option to tune the TEXT_START_ADDR. >>> >>> Signed-off-by: Lad Prabhakar >>> --- >>> Hi All, >>> >>> This patch is inspired from the current ld/emulparams/nds32elf_linux.sh file >>> where similar approach is being used and DEFAULT_TEXT_START_ADDR variable is >>> checked to adjust the TEXT_START_ADDR for the platform. >>> >>> I am not sure if this is the right approach the above issue has been discussed >>> on the ML [0]. >>> >>> [0] https://sourceware.org/pipermail/binutils/2022-November/124813.html >>> >>> Cheers, >>> Prabhakar >>> --- >>> ld/emulparams/elf32lriscv-defs.sh | 6 +++++- >>> 1 file changed, 5 insertions(+), 1 deletion(-) >>> >>> diff --git a/ld/emulparams/elf32lriscv-defs.sh b/ld/emulparams/elf32lriscv-defs.sh >>> index b823cedacab..026aef4714b 100644 >>> --- a/ld/emulparams/elf32lriscv-defs.sh >>> +++ b/ld/emulparams/elf32lriscv-defs.sh >>> @@ -27,7 +27,11 @@ case "$target" in >>> esac >>> >>> IREL_IN_PLT= >>> -TEXT_START_ADDR=0x10000 >>> +if [ -z ${DEFAULT_TEXT_START_ADDR+x} ]; then >>> + TEXT_START_ADDR=0x10000 >>> +else >>> + TEXT_START_ADDR=$DEFAULT_TEXT_START_ADDR >>> +fi >>> MAXPAGESIZE="CONSTANT (MAXPAGESIZE)" >>> COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)" >>> >>> -- >>> 2.17.1 >>> >> >> Changing ld does not look like a good change to me. This tuning can be >> placed at the compiler driver side as that is the usual place to tune >> these things. We can ask users to specify -Wl,-Ttext-segment= (with lld >> use --image-base= instead) . > With the above approach we will have to target each and individual > application/library that is statically compiled. > >> If that is inconvenient, with Clang you can >> add the option to a configuration file >> (https://clang.llvm.org/docs/UsersManual.html#configuration-files). >> With GCC there may be an option to add a fragment to the default specs >> file. > I'm more specifically concerned about yocto/debian builds which use > GCC. With the proposed approach the changes are central and we can > make sure everything will fall in place for yocto/debian rootfs builds > with a single change. > > Also what I get from Palmer is that moving forward we want to adjust > the TEXT_START_ADDR based on the page size (Huge page). Another approach here is to consider this system independent of the other risc-v platforms and give it its own emulation template rather than polluting the generic risc-v template with this issue. I'm leery of including these bits in the generic risc-v code given it's really working around, umm, quirks, mis-features or whatever we might want to call them. Jeff