From fe78531dcfcd709286a292c7707b987685f61919 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Mon, 4 Jun 2012 14:35:25 +0000 Subject: [PATCH] bfd/ * bfd-in.h (bfd_elf_bfd_from_remote_memory): Make LEN argument of target_read_memory as bfd_size_type. * bfd-in2.h: Regenerate. * elf-bfd.h (elf_backend_bfd_from_remote_memory): Make LEN argument of target_read_memory as bfd_size_type. (_bfd_elf32_bfd_from_remote_memory): Likewise. (_bfd_elf64_bfd_from_remote_memory): Likewise. * elf.c (bfd_elf_bfd_from_remote_memory): Likewise. * elfcode.h (NAME(_bfd_elf,bfd_from_remote_memory)): Likewise. gdb/ * symfile-mem.c: 3 new gdb_static_assert for target_read_memory_bfd parameters. (target_read_memory_bfd): New function. (symbol_file_add_from_memory): Use it. --- bfd/ChangeLog | 12 ++++++++++++ bfd/bfd-in.h | 3 ++- bfd/bfd-in2.h | 3 ++- bfd/elf-bfd.h | 7 ++++--- bfd/elf.c | 2 +- bfd/elfcode.h | 2 +- gdb/ChangeLog | 7 +++++++ gdb/symfile-mem.c | 21 ++++++++++++++++++++- 8 files changed, 49 insertions(+), 8 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e734796297f..9874ff1cf16 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,15 @@ +2012-06-04 Jan Kratochvil + + * bfd-in.h (bfd_elf_bfd_from_remote_memory): Make LEN argument + of target_read_memory as bfd_size_type. + * bfd-in2.h: Regenerate. + * elf-bfd.h (elf_backend_bfd_from_remote_memory): Make LEN + argument of target_read_memory as bfd_size_type. + (_bfd_elf32_bfd_from_remote_memory): Likewise. + (_bfd_elf64_bfd_from_remote_memory): Likewise. + * elf.c (bfd_elf_bfd_from_remote_memory): Likewise. + * elfcode.h (NAME(_bfd_elf,bfd_from_remote_memory)): Likewise. + 2012-06-03 Alan Modra PR binutils/13897 diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 9617428caf5..5300b14dfce 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -698,7 +698,8 @@ extern int bfd_get_elf_phdrs the remote memory. */ extern bfd *bfd_elf_bfd_from_remote_memory (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, size_t len)); + int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, + bfd_size_type len)); extern struct bfd_section *_bfd_elf_tls_setup (bfd *, struct bfd_link_info *); diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 585a54a0d2e..8798ae47ac4 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -705,7 +705,8 @@ extern int bfd_get_elf_phdrs the remote memory. */ extern bfd *bfd_elf_bfd_from_remote_memory (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, size_t len)); + int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, + bfd_size_type len)); extern struct bfd_section *_bfd_elf_tls_setup (bfd *, struct bfd_link_info *); diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 6918d5a129f..889ce128b4b 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1186,7 +1186,8 @@ struct elf_backend_data see elf.c, elfcode.h. */ bfd *(*elf_backend_bfd_from_remote_memory) (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, size_t len)); + int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, + bfd_size_type len)); /* This function is used by `_bfd_elf_get_synthetic_symtab'; see elf.c. */ @@ -2261,10 +2262,10 @@ extern char *elfcore_write_register_note extern bfd *_bfd_elf32_bfd_from_remote_memory (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma, bfd_byte *, size_t)); + int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type)); extern bfd *_bfd_elf64_bfd_from_remote_memory (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma, bfd_byte *, size_t)); + int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type)); extern bfd_vma bfd_elf_obj_attr_size (bfd *); extern void bfd_elf_set_obj_attr_contents (bfd *, bfd_byte *, bfd_vma); diff --git a/bfd/elf.c b/bfd/elf.c index ac7be2c5ec1..d97da9f8ba9 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9571,7 +9571,7 @@ bfd_elf_bfd_from_remote_memory (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma, bfd_byte *, size_t)) + 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, loadbasep, target_read_memory); diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 2c8fe2b4f54..cc55c866d6f 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1615,7 +1615,7 @@ NAME(_bfd_elf,bfd_from_remote_memory) (bfd *templ, bfd_vma ehdr_vma, bfd_vma *loadbasep, - int (*target_read_memory) (bfd_vma, bfd_byte *, size_t)) + int (*target_read_memory) (bfd_vma, bfd_byte *, bfd_size_type)) { Elf_External_Ehdr x_ehdr; /* Elf file header, external form */ Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form */ diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 20fd853f72d..0f5d4d99bb9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2012-06-04 Jan Kratochvil + + * symfile-mem.c: 3 new gdb_static_assert for target_read_memory_bfd + parameters. + (target_read_memory_bfd): New function. + (symbol_file_add_from_memory): Use it. + 2012-06-03 Doug Evans * symtab.c (lookup_global_symbol_from_objfile): Only scan blockvector diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c index 91125e15e5f..45d95a77e67 100644 --- a/gdb/symfile-mem.c +++ b/gdb/symfile-mem.c @@ -55,6 +55,25 @@ #include "auxv.h" #include "elf/common.h" +/* Verify parameters of target_read_memory_bfd and target_read_memory are + compatible. */ + +gdb_static_assert (sizeof (CORE_ADDR) == sizeof (bfd_vma)); +gdb_static_assert (sizeof (gdb_byte) == sizeof (bfd_byte)); +gdb_static_assert (sizeof (size_t) <= sizeof (bfd_size_type)); + +/* Provide bfd/ compatible prototype for target_read_memory. Casting would not + be enough as LEN width may differ. */ + +static int +target_read_memory_bfd (bfd_vma memaddr, bfd_byte *myaddr, bfd_size_type len) +{ + /* MYADDR must be already allocated for the LEN size so it has to fit in + size_t. */ + gdb_assert ((size_t) len == len); + + return target_read_memory (memaddr, myaddr, len); +} /* Read inferior memory at ADDR to find the header of a loaded object file and read its in-core symbols out of inferior memory. TEMPL is a bfd @@ -77,7 +96,7 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name, error (_("add-symbol-file-from-memory not supported for this target")); nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, &loadbase, - target_read_memory); + target_read_memory_bfd); if (nbfd == NULL) error (_("Failed to read a valid object file image from memory.")); -- 2.30.2