]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Move bfd_elf_bfd_from_remote_memory to opncls.c
authorAlan Modra <amodra@gmail.com>
Wed, 3 May 2023 03:17:15 +0000 (12:47 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 3 May 2023 05:23:28 +0000 (14:53 +0930)
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.

bfd/bfd-in.h
bfd/bfd-in2.h
bfd/elf.c
bfd/opncls.c

index 0a4da9aa407a4d3f8dee12edb8d76e1e8e348d79..889aa45fcddc5fd24ba707331ce39a07019cb90f 100644 (file)
@@ -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;
index f5e1c1380c0fed876e9606987bb6200bf7737dc3..470a3cc9d3b961d13c4cf7b68c0fe75a1fe7bb29 100644 (file)
@@ -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 *);
index fa7c25ad9dc98dc6322934e3a86735bc24fecef7..94954a8fbb99a98456757b18332c39ebcefde60f 100644 (file)
--- 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,
index eabea414467f3d67217bf3165aef573f0231cc72..602dc80a6c4e13f6e5bfadcfb0ec879fdf55cc33 100644 (file)
@@ -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)
 {