From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Move bfd_elf_bfd_from_remote_memory to opncls.c
Date: Wed, 3 May 2023 15:32:48 +0930 [thread overview]
Message-ID: <ZFH5CJb/dZFBG9hD@squeak.grove.modra.org> (raw)
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);
-\f
-/* 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);
-\f
-/* 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,
}
}
\f
-/* 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);
-}
-\f
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
reply other threads:[~2023-05-03 6:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZFH5CJb/dZFBG9hD@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).