From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 9C5C43A94590 for ; Mon, 19 Dec 2022 09:02:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C5C43A94590 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-ej1-x632.google.com with SMTP id jo4so10926123ejb.7 for ; Mon, 19 Dec 2022 01:02:55 -0800 (PST) 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=kfWKIuad/oQ1PdwhTG5AUWvneGg91EKpeR50+3thLEs=; b=KRutSL/Oge9psaD3ENNHOgQuOvKIarNT7C/y7+ENo6gCr6VEdORCIDnhfMNNOIta2S JQuiCGzN0K9Lgo/M1mpQaxLnE1QlEZ0biqMaGdn1VAuROErRMkY5+oRfHsUPlwCu5SEC tZK4NoMtf4R2aSIMYEexGD7OlXBjR17ZxxbprmAixBflH2mT01Mb9MlAlu3OJAh8KxOZ 3aaiY2O93fghulq7KYOEEtjik5b7+NvEm3+4JxXJMyIniM6aYepJQsY8FW9fP32sD6be pmmCj74StmcvtVkV7N/dtMVk/zROKgihOnQ0NAPK0400clo98YQv4sIMXMPNeO7zCORn nOyw== 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=kfWKIuad/oQ1PdwhTG5AUWvneGg91EKpeR50+3thLEs=; b=c9ENDhG1aUmh6AaI6dd4EC8Q93P3OIOWP5mT8xbk+b/GO3r34wFJ5qGpCTs3kftMQr 6+E+8Hhby31CX65MAuh34YIO7tDYdWnwrLwbmx9re99Jw43/TbuwZT2j2z7daVFzrXVQ zFKy++mtPevjZEHyYzhl1qBtDUgKV9qnmJ76GvqOPwnA/Daz5BHFevHi4vnhw76FtejR Qw3pKVlM+o4CFrJsB7QYmscF3+grOiDQkmsZWjVamFpCEhefcVhXDzs9cQ7vHufFpqa6 rGNwi+ZLFdrPhIsrfExoU2skVQKpbIwGYEnOvCeQBruwEa44jWIlVgT5LXMTbiphtMJj jLEg== X-Gm-Message-State: ANoB5pnJN/lBT7IQOWJ5iCqKAbGxNSdAF3tqiUHgQuzxCFe00gMEzSrS RYULSf4nZLsP9PIJruiN3JLrEMJ+B9J3KBh439w= X-Google-Smtp-Source: AA0mqf4dMxJzcK545ELG2qqRB95DcbJQDxCmZWGDUqpP8ukf5Tm83tTMcdqkPZdq6zb04FtN+lo75Ii1vB1TAlD8mok= X-Received: by 2002:a17:906:1303:b0:7c1:808e:765b with SMTP id w3-20020a170906130300b007c1808e765bmr1737973ejb.196.1671440574009; Mon, 19 Dec 2022 01:02:54 -0800 (PST) MIME-Version: 1.0 References: <20221216214310.13155-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20221218062404.cn75smc4pperrsd7@gmail.com> <20221218230913.b4zac6jsxg6sxywv@gmail.com> In-Reply-To: <20221218230913.b4zac6jsxg6sxywv@gmail.com> From: "Lad, Prabhakar" Date: Mon, 19 Dec 2022 09:02:27 +0000 Message-ID: Subject: Re: [RFC PATCH] ld/emulparams: elf32lriscv-defs: Add support tune the text segment start address To: Fangrui Song , Chris Paterson Cc: Lad Prabhakar , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,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: Hi Fangrui, On Sun, Dec 18, 2022 at 11:09 PM Fangrui Song wrote: > > On 2022-12-18, Lad, Prabhakar 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. > > Sometimes the opposite. With tunable TEXT_START_ADDR you will need to > ensure every user targeting your platform use the value. It's > inconvenient for users who want to use a generic toolchain instead of a > customized one. The emerging popularity of Clang in some part is it > somewhat discourages such configure-time tuning. > Agreed the individual user will have to use the toolchain generated by this change (yocto SDK). On the other hand users can still use the generic toolchain but only for non statically compiled applications. > >> 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). > > I think GCC provides a way to customize its specs file. > If 0x10000 is not a good value, I suggest just changing it to 0x200000 (lld aarch64/x86) or 0x400000 (ld.bfd aarch64/x86). I'll wait for RISC-V maintainers to comment on the above. Cheers, Prabhakar