From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 30DD43947C38 for ; Fri, 28 Jan 2022 20:50:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 30DD43947C38 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-106-iKXplaWYNiC36DrtBfURAw-1; Fri, 28 Jan 2022 15:50:38 -0500 X-MC-Unique: iKXplaWYNiC36DrtBfURAw-1 Received: by mail-qv1-f69.google.com with SMTP id 3-20020ad45b83000000b00423e8603906so7196197qvp.1 for ; Fri, 28 Jan 2022 12:50:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:organization:in-reply-to :content-transfer-encoding; bh=Y486URIr8dTA3A2QoI1jUo0ZFmXPAe+A4Xl6PPEVKtU=; b=v6+8c4fttsRa9eIHLQi61sy3TUrzymfEDS1pd96GkQMa7DV1gRNutpC3Y2jt4HP5mU +iqO/WZ4ix9o4mAP9I/b463awF/BKU8ZHWw2HhMT3BmV8fjswPXOAea9zYRMCqjg/WsN 9DOGFQroSaM3RfITzpuKNJmEiFbTYzv85jAsaoi0gFHh12vpjTod7+0EuU/sWzCE1wog AREG0sVJmLi5Eb6mCpNfwdo9oTHVxD9Nc2BmUyHVOj/9VQRZaX6R62aQpIbitt/LKFA9 eHm8I/vr9cnKxkG92F3yDDlTjesnRwctAmWmwJa9A+FY02lLaGGeQIxyKAJI/zNtj1ih vILA== X-Gm-Message-State: AOAM531sppBIq6CFJWT2GE8bt+2Rnk2UFrzIH+WfmjTeit/ePquePASt f+NleCuQdhtqq8KOFOOgBX/FKwImHfZfCygrA7yXD50AfQTdqyaEaof/INliW1lWGqtXoTUnuey iIqJkhe8NBFaxWMEN06E8 X-Received: by 2002:ac8:4e41:: with SMTP id e1mr7358409qtw.369.1643403037944; Fri, 28 Jan 2022 12:50:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzCABT02NlQ42w5O0LBCdELfummVtukb4LPN1X3TZ0xlBA8eplwpIJARtAyCLY547CaMOMYsg== X-Received: by 2002:ac8:4e41:: with SMTP id e1mr7358398qtw.369.1643403037733; Fri, 28 Jan 2022 12:50:37 -0800 (PST) Received: from [192.168.0.241] (135-23-175-80.cpe.pppoe.ca. [135.23.175.80]) by smtp.gmail.com with ESMTPSA id l1sm3975243qkp.100.2022.01.28.12.50.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jan 2022 12:50:37 -0800 (PST) Message-ID: <97e93b5d-8100-e576-a4bf-d7cd703c9093@redhat.com> Date: Fri, 28 Jan 2022 15:50:36 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] mips: pldd: support DT_MIPS_RLD_MAP and DT_MIPS_RLD_MAP_REL To: Adhemerval Zanella , libc-alpha@sourceware.org References: <046da3ae8fc57687b5a9480381904d3f53b1010f.camel@mengyan1223.wang> <31decb16-c634-183a-a82d-6710157216af@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <31decb16-c634-183a-a82d-6710157216af@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Jan 2022 20:50:41 -0000 On 1/28/22 15:48, Adhemerval Zanella via Libc-alpha wrote: > > > On 28/01/2022 17:45, H.J. Lu via Libc-alpha wrote: >> On Fri, Jan 28, 2022 at 10:57 AM Xi Ruoyao via Libc-alpha >> wrote: >>> >>> MIPS uses DT_MIPS_RLD_MAP and DT_MIPS_RLD_MAP_REL for accessing r_debug, >>> instead of DT_DEBUG. >>> --- >>> elf/pldd-xx.c | 67 ++++++++++++++++++++++++++++++++++++++++----------- >>> 1 file changed, 53 insertions(+), 14 deletions(-) >>> >>> diff --git a/elf/pldd-xx.c b/elf/pldd-xx.c >>> index 1cdfb49c53..ec397f00e5 100644 >>> --- a/elf/pldd-xx.c >>> +++ b/elf/pldd-xx.c >>> @@ -22,6 +22,12 @@ >>> #define EW_(e, w, t) EW__(e, w, _##t) >>> #define EW__(e, w, t) e##w##t >>> >>> +#if CLASS == 32 >>> +typedef Elf32_Word E(val_type); >>> +#else >>> +typedef Elf64_Xword E(val_type); >>> +#endif >>> + >>> struct E(link_map) >>> { >>> EW(Addr) l_addr; >>> @@ -70,6 +76,35 @@ _Static_assert (offsetof (struct r_debug, r_map) >>> == offsetof (struct E(r_debug), r_map), "r_map"); >>> #endif >>> >>> +static EW(Addr) >>> +E(r_debug_offset) (EW(Dyn) *d, int memfd, EW(Addr) d_addr) >>> +{ >>> +#ifdef __mips__ >>> + EW(Addr) ptr; >>> + >>> + switch (d->d_tag) >>> + { >>> + case DT_MIPS_RLD_MAP_REL: >>> + ptr = d_addr + d->d_un.d_val; >>> + break; >>> + case DT_MIPS_RLD_MAP: >>> + ptr = d->d_un.d_ptr; >>> + break; >>> + default: >>> + return 0; >>> + } >>> + >>> + if (pread (memfd, &ptr, sizeof (ptr), ptr) != sizeof (ptr)) >>> + return 0; >>> + >>> + return ptr; >>> +#else >>> + if (d->d_tag == DT_DEBUG) >>> + return (off_t) d->d_un.d_ptr; >>> + >>> + return 0; >>> +#endif >>> +} >>> >>> static int >>> >>> @@ -126,21 +161,25 @@ E(find_maps) (const char *exe, int memfd, pid_t pid, void *auxv, >>> != p[i].p_filesz) >>> error (EXIT_FAILURE, 0, gettext ("cannot read dynamic section")); >>> >>> - /* Search for the DT_DEBUG entry. */ >>> + /* Search for the r_debug struct. */ >>> for (unsigned int j = 0; j < p[i].p_filesz / sizeof (EW(Dyn)); ++j) >>> - if (dyn[j].d_tag == DT_DEBUG && dyn[j].d_un.d_ptr != 0) >>> - { >>> - struct E(r_debug) r; >>> - if (pread (memfd, &r, sizeof (r), dyn[j].d_un.d_ptr) >>> - != sizeof (r)) >>> - error (EXIT_FAILURE, 0, gettext ("cannot read r_debug")); >>> - >>> - if (r.r_map != 0) >>> - { >>> - list = r.r_map; >>> - break; >>> - } >>> - } >>> + { >>> + EW(Addr) d_addr = offset + p[i].p_vaddr + sizeof (EW(Dyn)) * j; >>> + EW(Addr) off = E(r_debug_offset)(&dyn[j], memfd, d_addr); >>> + if (off != 0) >>> + { >>> + struct E(r_debug) r; >>> + if (pread (memfd, &r, sizeof (r), off) >>> + != sizeof (r)) >>> + error (EXIT_FAILURE, 0, gettext ("cannot read r_debug")); >>> + >>> + if (r.r_map != 0) >>> + { >>> + list = r.r_map; >>> + break; >>> + } >>> + } >>> + } >>> >>> free (dyn); >>> break; >>> -- >>> 2.35.0 >>> >>> >> >> I think a header file to access r_debug works better. MIPS can provide >> one to override the generic header file. >> > > Agreed, I think we should avoid arch specific defines (__mips__) on generic > code. Ah! I see, the objection if about arch-defines in tests. Yes, lets clean that up. -- Cheers, Carlos.