From patchwork Wed May 3 06:02:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 89572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1103077vqo; Tue, 2 May 2023 23:03:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6QzOMs6xrb/qLKp2oxsm+ErfNj3jGSLtXrBeSySdjXxt6WaK8iI1EAFHc+mBAgMYT1wLHx X-Received: by 2002:a17:907:7245:b0:946:2fa6:3b85 with SMTP id ds5-20020a170907724500b009462fa63b85mr2421004ejc.36.1683093820900; Tue, 02 May 2023 23:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683093820; cv=none; d=google.com; s=arc-20160816; b=ROto2MDyOcJmj1hBag5qKAEQxKDsFtjXhQoQzYa8VTZNTkICV5mqWk7VpVJaH25c7t ZUa3dcdqoWAg9fT81C5fUDFVWz4qYMnV+NIAp1ECYF5t/3QpB4ll6/0GbBHk7X58XZ2+ tpQ2S1eilR7qn2urUeSMXPus+jeWilSzG2W5wNpnwdpR3BEYubNpaDtHZpom2sU4y0PG Q6enMPaT1i9lM3RqmoabfhAGprvZWtPWJ+GRg7k8mExnXbIBd9l/JU3ivqtvNgDUAb1E VxKh3wdgYOmR/0Ciurm2hhsetOws4Lrh4bXIBRATIPMHuugAWjmGz048klKsLxB87Ii1 TGCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=oUIeX9dny8LZCKcAcje3Pghm7WbAVRPnlvYSk4iz9+Y=; b=BVxiSOXcgGEVw06dj8nG5tT3UCdjv4CG+G0WSr9mKFi71vXwGNhfdLfOE4I3971oVA iIhfNz3w5A69l9DPmLaWHyC2WCLVOfg2Qx0fCp/cGBKld3/KBuNzzNxbHqGeSgm4mY8M BnZ9xubdXYdgaXo3pzZwYtUQ+46wxSjkkLIDLAz1KzGo79KqvCADjbfoD+X22dGqHGMx b+VjGvg/ucLRAHUPJjsH4aDGv9vls6L2TbI6JuKkRmCOhlIUteDGG227PLLjfD8Inaks hDArDuoaNsLlFPlmS1hZZIM9dImUUm+1jbKVIuHXeAXevRKB77y8ARuKtbmZGRroFgqu m8XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qbe33MtQ; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id io15-20020a17090780cf00b0094a80dfc956si26093704ejc.711.2023.05.02.23.03.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 23:03:40 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=qbe33MtQ; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6A9143856DE7 for ; Wed, 3 May 2023 06:03:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A9143856DE7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683093784; bh=oUIeX9dny8LZCKcAcje3Pghm7WbAVRPnlvYSk4iz9+Y=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qbe33MtQvpfI7+RC0DL+qZ5kyXYkaIfKg66BUD+H0X+Ep+g+yHw6bP7oc/Evjd/XY fVxR4woD6aFFdB/CpjtBYuJO2iFc9v1mkqdzEPbasgU7/ZoixaUUlzM6RHlnruP8sK LGaRd57iW7ePqO2aX35cptZbFhzxSIsbxGwveptk= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 707D03858C1F for ; Wed, 3 May 2023 06:02:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 707D03858C1F Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-63b5465fc13so3602673b3a.3 for ; Tue, 02 May 2023 23:02:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683093773; x=1685685773; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oUIeX9dny8LZCKcAcje3Pghm7WbAVRPnlvYSk4iz9+Y=; b=MNlTITjd94sqY62BxGacG/ReSW+bZutED86KZEcvQCZPWgrvTRuV9LwayVvFlZpegQ S3HmEgFv2U5u15j/a1qs+eqIqvUWl6fElug6+PQO+lvVf/ugm5kAUfHjmPSunrht0IsO zlhNwG6bo/xlIVQhcCeLkcGBbZng5J/Y+0g/Wq/aLe+6vMLgtDlJ8eo/d0R6oC8ntSk2 jw2hCDwrUPaMhUCmpl3Pqlx6tHvc9fsFe0UwV9iPto8Xx54t+2cFdZwXDHcwrD1IiP8G SsX6PwS2I01KHeGkubCZRi6TtiLzJs+PpYhia4IBzWoBlnFT/TKYQX2jCwKHi6oFFMGS hMVQ== X-Gm-Message-State: AC+VfDwKx+pdH47UR6hCrb8+Nvr0GiTId9LaKCNBiCg8Gor6lF3joFt/ Z+zQHUtCyLimlorDAPD4MgfztM7zMDI= X-Received: by 2002:a05:6a20:9f46:b0:f0:dedb:83b8 with SMTP id ml6-20020a056a209f4600b000f0dedb83b8mr20932027pzb.19.1683093772856; Tue, 02 May 2023 23:02:52 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id bb11-20020a17090b008b00b00246aba3ebabsm478519pjb.45.2023.05.02.23.02.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 23:02:52 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id CF5591142C83; Wed, 3 May 2023 15:32:48 +0930 (ACST) Date: Wed, 3 May 2023 15:32:48 +0930 To: binutils@sourceware.org Subject: Move bfd_elf_bfd_from_remote_memory to opncls.c Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.9 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, 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 server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764851786068161782?= X-GMAIL-MSGID: =?utf-8?q?1764851786068161782?= bfd_elf_bfd_from_remote_memory is just a wrapper, and the function could be implemented for other formats. Move it to opncls.c because it acts a little like some of the other bfd_open* routines. Also give it the usual FUNCTION etc. comment so prototypes and docs are handled automatically. * elf.c (bfd_elf_bfd_from_remote_memory): Move to.. * opncls.c: ..here, add FUNCTION comment. * bfd-in.h (bfd_elf_bfd_from_remote_memory): Delete prototype. * bfd-in2.h: Regenerate. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 0a4da9aa407..889aa45fcdd 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -427,28 +427,6 @@ extern void bfd_free_window (bfd_window *); extern bool bfd_get_file_window (bfd *, file_ptr, bfd_size_type, bfd_window *, bool); - -/* Externally visible ELF routines. */ - -/* Create a new BFD as if by bfd_openr. Rather than opening a file, - reconstruct an ELF file by reading the segments out of remote - memory based on the ELF file header at EHDR_VMA and the ELF program - headers it points to. If non-zero, SIZE is the known extent of the - object. If not null, *LOADBASEP is filled in with the difference - between the VMAs from which the segments were read, and the VMAs - the file headers (and hence BFD's idea of each section's VMA) put - them at. - - The function TARGET_READ_MEMORY is called to copy LEN bytes from - the remote memory at target address VMA into the local buffer at - MYADDR; it should return zero on success or an `errno' code on - failure. TEMPL must be a BFD for a target with the word size and - byte order found in the remote memory. */ -extern bfd *bfd_elf_bfd_from_remote_memory - (bfd *templ, bfd_vma ehdr_vma, bfd_size_type size, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, - bfd_size_type len)); - /* Forward declarations. */ struct ecoff_debug_info; struct ecoff_debug_swap; diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index f5e1c1380c0..470a3cc9d3b 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -434,28 +434,6 @@ extern void bfd_free_window (bfd_window *); extern bool bfd_get_file_window (bfd *, file_ptr, bfd_size_type, bfd_window *, bool); - -/* Externally visible ELF routines. */ - -/* Create a new BFD as if by bfd_openr. Rather than opening a file, - reconstruct an ELF file by reading the segments out of remote - memory based on the ELF file header at EHDR_VMA and the ELF program - headers it points to. If non-zero, SIZE is the known extent of the - object. If not null, *LOADBASEP is filled in with the difference - between the VMAs from which the segments were read, and the VMAs - the file headers (and hence BFD's idea of each section's VMA) put - them at. - - The function TARGET_READ_MEMORY is called to copy LEN bytes from - the remote memory at target address VMA into the local buffer at - MYADDR; it should return zero on success or an `errno' code on - failure. TEMPL must be a BFD for a target with the word size and - byte order found in the remote memory. */ -extern bfd *bfd_elf_bfd_from_remote_memory - (bfd *templ, bfd_vma ehdr_vma, bfd_size_type size, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, - bfd_size_type len)); - /* Forward declarations. */ struct ecoff_debug_info; struct ecoff_debug_swap; @@ -502,6 +480,11 @@ bfd *bfd_openr_iovec (const char *filename, const char *target, bfd *bfd_openw (const char *filename, const char *target); +bfd *bfd_elf_bfd_from_remote_memory + (bfd *templ, bfd_vma ehdr_vma, bfd_size_type size, bfd_vma *loadbasep, + int (*target_read_memory) + (bfd_vma vma, bfd_byte *myaddr, bfd_size_type len)); + bool bfd_close (bfd *abfd); bool bfd_close_all_done (bfd *); diff --git a/bfd/elf.c b/bfd/elf.c index fa7c25ad9dc..94954a8fbb9 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -12863,31 +12863,6 @@ _bfd_elf_section_offset (bfd *abfd, } } -/* Create a new BFD as if by bfd_openr. Rather than opening a file, - reconstruct an ELF file by reading the segments out of remote memory - based on the ELF file header at EHDR_VMA and the ELF program headers it - points to. If not null, *LOADBASEP is filled in with the difference - between the VMAs from which the segments were read, and the VMAs the - file headers (and hence BFD's idea of each section's VMA) put them at. - - The function TARGET_READ_MEMORY is called to copy LEN bytes from the - remote memory at target address VMA into the local buffer at MYADDR; it - should return zero on success or an `errno' code on failure. TEMPL must - be a BFD for an ELF target with the word size and byte order found in - the remote memory. */ - -bfd * -bfd_elf_bfd_from_remote_memory - (bfd *templ, - bfd_vma ehdr_vma, - bfd_size_type size, - bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type)) -{ - return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory) - (templ, ehdr_vma, size, loadbasep, target_read_memory); -} - long _bfd_elf_get_synthetic_symtab (bfd *abfd, long symcount ATTRIBUTE_UNUSED, diff --git a/bfd/opncls.c b/bfd/opncls.c index eabea414467..602dc80a6c4 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -760,6 +760,51 @@ bfd_openw (const char *filename, const char *target) return nbfd; } +/* +FUNCTION + bfd_elf_bfd_from_remote_memory + +SYNOPSIS + bfd *bfd_elf_bfd_from_remote_memory + (bfd *templ, bfd_vma ehdr_vma, bfd_size_type size, bfd_vma *loadbasep, + int (*target_read_memory) + (bfd_vma vma, bfd_byte *myaddr, bfd_size_type len)); + +DESCRIPTION + Create a new BFD as if by bfd_openr. Rather than opening a + file, reconstruct an ELF file by reading the segments out of + remote memory based on the ELF file header at EHDR_VMA and the + ELF program headers it points to. If non-zero, SIZE is the + known extent of the object. If not null, *LOADBASEP is filled + in with the difference between the VMAs from which the + segments were read, and the VMAs the file headers (and hence + BFD's idea of each section's VMA) put them at. + + The function TARGET_READ_MEMORY is called to copy LEN bytes + from the remote memory at target address VMA into the local + buffer at MYADDR; it should return zero on success or an + errno code on failure. TEMPL must be a BFD for an ELF + target with the word size and byte order found in the remote + memory. +*/ + +bfd * +bfd_elf_bfd_from_remote_memory + (bfd *templ, + bfd_vma ehdr_vma, + bfd_size_type size, + bfd_vma *loadbasep, + int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type)) +{ + if (bfd_get_flavour (templ) != bfd_target_elf_flavour) + { + bfd_set_error (bfd_error_invalid_operation); + return NULL; + } + return (*get_elf_backend_data (templ)->elf_backend_bfd_from_remote_memory) + (templ, ehdr_vma, size, loadbasep, target_read_memory); +} + static inline void _maybe_make_executable (bfd * abfd) {