From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-pf1-x42b.google.com with SMTP id d2e1a72fcca58-63b5465fc13so3602673b3a.3 for ; Tue, 02 May 2023 23:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683093773; x=1685685773; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=oUIeX9dny8LZCKcAcje3Pghm7WbAVRPnlvYSk4iz9+Y=; b=TKMdgQhdiAXFSCdWF48xFX8+Y3rjPAkM5Q8gHpR9UV4ZcdJMDqvpC+ymETBdlpb+sZ 8DQX2rrUv1RfqAtPZyzFmtjop1Q8raToM3C3Pr1WoBJJ80LKYAvNllfw0vox9HUJmr3Y zIDI8BPFjvveop5jqks0qeGODteORJ+mNcqKvX/JlGQc+srMRAwtLmle9kRZreNz0crD 69EZRNvTZkEmmswLyBvSCK/U9Iehgm1m4TUiBu0FAimOH5Ko/RuqNZFSiSr9xCsfKx1W M8e4uLYcV4WwqlWniR6+7XxELNxbmwJ2wf3NbShAQLa4ZqPaD5NJnf7X7Bg9s3RAxp12 ISmA== 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-Google-Smtp-Source: ACHHUZ6piaJm8VHzcgori52VYbwsAiAACoqTkxgQBj1+3kUOZTLYpxM6y//ApcTP4y5uE3JVWISSYA== 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 From: Alan Modra To: binutils@sourceware.org Subject: Move bfd_elf_bfd_from_remote_memory to opncls.c Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 List-Id: 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) { -- Alan Modra Australia Development Lab, IBM