From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id 586853979FB9 for ; Mon, 19 Dec 2022 09:11:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 586853979FB9 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-ed1-x52c.google.com with SMTP id m21so1449328edc.3 for ; Mon, 19 Dec 2022 01:11:40 -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=kVGKwCvNpZ88aM4p5uBrobe1qd2LDaic2Z2pjFumYoc=; b=Z6jSSN/WISatst6HtwHhLcSEGrz5v3LLgzYcE5ztbAByxZcZewxe+WTBhzIKtParRc x8lXT8P88cb2ugr+QJVTbCMdtufJ3vXJP0fjcTe5DRREjo7e+eYbf+OU40nO5vIkXvGZ XE54RSEN4jR/+iCREUEmzzbermmh1VMqVipyrkqLc72pDf3F2FMm6VQtuLCPJpwRUohm 1VzbDDn2jwjnreB6MFAfx+yS5PAVzlAfAEfxZy/2xTMVHHAq7z37bgovvulqdzB1C1v1 Tqs+EIy9HkABgeJllFgRZI0NW9ABNp8JoJsYLZXoy7otdR3KSxwAXBEC5VQDz3ynEk9+ C+ww== 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=kVGKwCvNpZ88aM4p5uBrobe1qd2LDaic2Z2pjFumYoc=; b=u1ATvxXBUf8uOUtkwzYlrrmEGgfiC9AUmuy/2aP9YG10ukt9cshn89dY2EXZbiejH7 APfoDMv5HstI3CUAtxw8qwb8pUNKIv3FWTbmBHM11YYXk3j5U48ODwnREOFdxxE/M4Pf 9Hth5Bi02oLyvkrp12EgL4bVFotq0IcZB0Qyi8y7eEg8qmLVXUkY/pVqQ4QjxGRdK2mA MN0DSGLKncdmxPJ6H99FwFfirjbE/AYY5YCowXkeW22Oj5XQsVKEQ/E8IHiBBnyDdFEl f0Vfg2cWlpH7JjO7v3xShnUGZ6qvK5+licSoE0UEjzwjAk87lJTUzB9p0mECK21kotzr 1DFg== X-Gm-Message-State: AFqh2kqoUfahFsn+vNLdFJcoIPkVX+kLK6ValmFlhmWC+dQOu8t3bD8z 64uW6lrqs0/UxstNV0riu3oLZodVpboHse+MgJM= X-Google-Smtp-Source: AMrXdXswroYvtzPEvDMgcucYInbVftDJLDsPCSPQvjG0GuoIObzj0eUGYzrU3RSrq74i73ZnPbiKh0ooAObIYyGGBf8= X-Received: by 2002:a05:6402:1f02:b0:477:8b04:d416 with SMTP id b2-20020a0564021f0200b004778b04d416mr899538edb.109.1671441099153; Mon, 19 Dec 2022 01:11:39 -0800 (PST) MIME-Version: 1.0 References: <20221216214310.13155-1-prabhakar.mahadev-lad.rj@bp.renesas.com> <20221218062404.cn75smc4pperrsd7@gmail.com> <156f7916-a542-c8aa-6574-be6f30509cfb@gmail.com> In-Reply-To: <156f7916-a542-c8aa-6574-be6f30509cfb@gmail.com> From: "Lad, Prabhakar" Date: Mon, 19 Dec 2022 09:11:13 +0000 Message-ID: Subject: Re: [RFC PATCH] ld/emulparams: elf32lriscv-defs: Add support tune the text segment start address To: Jeff Law Cc: Fangrui Song , Lad Prabhakar , Palmer Dabbelt , Andrew Waterman , Jim Wilson , Nelson Chu , binutils@sourceware.org, Chris Paterson Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.0 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 Jeff, On Mon, Dec 19, 2022 at 5:00 AM Jeff Law wrote: > > > > 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. > Sounds good to me, For example it would include the RISC-V generic template and we just override the offset in the platform specific conf file. Having said that, I'm not sure of the maintainability of such files and RISC-V maintainers will be OK for such change. I'm curious what Palmer has in his mind on tuning this parameter for huge pages. If that exposes some sort of config option we could use that option to set the offset. > 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. > :-) Cheers, Prabhakar