public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] bfd: Use size_t for length argument totarget_read_memory function passed into bfd_elf_bfd_from_remote_memory
@ 2012-05-28  9:05 Siddhesh Poyarekar
  2012-05-28 11:03 ` Alan Modra
  2012-06-01 18:24 ` Hans-Peter Nilsson
  0 siblings, 2 replies; 16+ messages in thread
From: Siddhesh Poyarekar @ 2012-05-28  9:05 UTC (permalink / raw)
  To: binutils, gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1508 bytes --]

Hi,

The target_read_memory function pointer that
bfd_elf_bfd_from_remote_memory accepts current accepts int for length.
I have attached a patch which changes this argument to size_t. This
change is needed because I'm looking to make analogous changes in gdb to
ensure consistency of storage sizes passed across functions to ensure
that larger values are not truncated.

I could write a wrapper around or cast the function pointer explicitly,
but as Jan Kratochvil suggested, it would be cleaner to just make a
change in bfd since it should be taking size_t values anyway. The
conversation thread is here for reference:

http://sourceware.org/ml/gdb-patches/2012-05/msg00909.html

Attached are two patches, the first being changes to bfd and the second
is the change I need to make in gdb to make it work with the changes in
bfd.

Regards,
Siddhesh

bfd/ChangeLog:

2012-05-28  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* bfd-in.h (bfd_elf_bfd_from_remote_memory): Make LEN argument
	of target_read_memory as size_t.
	* bfd-in2.h: Regenerate.
	* elf-bfd.h (elf_backend_bfd_from_remote_memory): Make LEN
	  argument of target_read_memory as size_t.
	(_bfd_elf32_bfd_from_remote_memory): Likewise.
	(_bfd_elf64_bfd_from_remote_memory): Likewise.
	* elf.c (bfd_elf_bfd_from_remote_memory): Likewise.
	* enfcode.h (NAME): Likewise.

gdb/ChangeLog:

2012-05-28  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* target.c (target_read_memory): Make LEN argument as size_t.
	* target.h (target_read_memory): Likewise.

[-- Attachment #2: 0001-bfd-changes-for-target_read_memory.patch --]
[-- Type: text/x-patch, Size: 3176 bytes --]

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index a61e721..9617428 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -698,7 +698,7 @@ 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, int len));
+   int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, size_t 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 efd542f..585a54a 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -705,7 +705,7 @@ 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, int len));
+   int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, size_t 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 5426c93..fcfb42a 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1186,7 +1186,7 @@ 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, int len));
+      int (*target_read_memory) (bfd_vma vma, bfd_byte *myaddr, size_t len));
 
   /* This function is used by `_bfd_elf_get_synthetic_symtab';
      see elf.c.  */
@@ -2260,10 +2260,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 *, int));
+   int (*target_read_memory) (bfd_vma, bfd_byte *, size_t));
 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 *, int));
+   int (*target_read_memory) (bfd_vma, bfd_byte *, size_t));
 
 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 c5b04ac..7a06fb4 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -9556,7 +9556,7 @@ bfd_elf_bfd_from_remote_memory
   (bfd *templ,
    bfd_vma ehdr_vma,
    bfd_vma *loadbasep,
-   int (*target_read_memory) (bfd_vma, bfd_byte *, int))
+   int (*target_read_memory) (bfd_vma, bfd_byte *, size_t))
 {
   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 c985c63..2c8fe2b 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 *, int))
+   int (*target_read_memory) (bfd_vma, bfd_byte *, size_t))
 {
   Elf_External_Ehdr x_ehdr;	/* Elf file header, external form */
   Elf_Internal_Ehdr i_ehdr;	/* Elf file header, internal form */
-- 
1.7.7.6


[-- Attachment #3: 0002-gdb-changes-for-target_read_memory.patch --]
[-- Type: text/x-patch, Size: 1043 bytes --]

diff --git a/gdb/target.c b/gdb/target.c
index 151209e..91b4b47 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1756,7 +1756,7 @@ target_xfer_partial (struct target_ops *ops,
    it makes no progress, and then return how much was transferred).  */
 
 int
-target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len)
+target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, size_t len)
 {
   /* Dispatch to the topmost target, not the flattened current_target.
      Memory accesses check target->to_has_(all_)memory, and the
diff --git a/gdb/target.h b/gdb/target.h
index f80fba0..f3ef33a 100644
--- a/gdb/target.h
+++ b/gdb/target.h
@@ -996,7 +996,8 @@ extern void target_dcache_invalidate (void);
 
 extern int target_read_string (CORE_ADDR, char **, int, int *);
 
-extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len);
+extern int target_read_memory (CORE_ADDR memaddr, gdb_byte *myaddr,
+			       size_t len);
 
 extern int target_read_stack (CORE_ADDR memaddr, gdb_byte *myaddr, int len);
 
-- 
1.7.7.6


^ permalink raw reply	[flat|nested] 16+ messages in thread
* [PATCH] bfd: Use size_t for length argument totarget_read_memory function passed into bfd_elf_bfd_from_remote_memory
@ 2012-05-28  9:04 Siddhesh Poyarekar
  0 siblings, 0 replies; 16+ messages in thread
From: Siddhesh Poyarekar @ 2012-05-28  9:04 UTC (permalink / raw)
  To: binutils, gdb-patches

Hi,

The target_read_memory function pointer that
bfd_elf_bfd_from_remote_memory accepts current accepts int for length.
I have attached a patch which changes this argument to size_t. This
change is needed because I'm looking to make analogous changes in gdb to
ensure consistency of storage sizes passed across functions to ensure
that larger values are not truncated.

I could write a wrapper around or cast the function pointer explicitly,
but as Jan Kratochvil suggested, it would be cleaner to just make a
change in bfd since it should be taking size_t values anyway. The
conversation thread is here for reference:

http://sourceware.org/ml/gdb-patches/2012-05/msg00909.html

Attached are two patches, the first being changes to bfd and the second
is the change I need to make in gdb to make it work with the changes in
bfd.

Regards,
Siddhesh

bfd/ChangeLog:

2012-05-28  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* bfd-in.h (bfd_elf_bfd_from_remote_memory): Make LEN argument
	of target_read_memory as size_t.
	* bfd-in2.h: Regenerate.
	* elf-bfd.h (elf_backend_bfd_from_remote_memory): Make LEN
	  argument of target_read_memory as size_t.
	(_bfd_elf32_bfd_from_remote_memory): Likewise.
	(_bfd_elf64_bfd_from_remote_memory): Likewise.
	* elf.c (bfd_elf_bfd_from_remote_memory): Likewise.
	* enfcode.h (NAME): Likewise.

gdb/ChangeLog:

2012-05-28  Siddhesh Poyarekar  <siddhesh@redhat.com>

	* target.c (target_read_memory): Make LEN argument as size_t.
	* target.h (target_read_memory): Likewise.

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-06-04 14:37 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-28  9:05 [PATCH] bfd: Use size_t for length argument totarget_read_memory function passed into bfd_elf_bfd_from_remote_memory Siddhesh Poyarekar
2012-05-28 11:03 ` Alan Modra
2012-05-28 11:11   ` Siddhesh Poyarekar
2012-05-28 21:29   ` Jan Kratochvil
2012-06-01 18:06   ` [commit bfd+gdb] " Jan Kratochvil
2012-06-01 18:24 ` Hans-Peter Nilsson
2012-06-01 19:54   ` Siddhesh Poyarekar
2012-06-01 20:31   ` Jan Kratochvil
2012-06-01 21:05     ` [patch#2] " Jan Kratochvil
2012-06-01 21:21       ` Hans-Peter Nilsson
2012-06-04  5:10       ` Hans-Peter Nilsson
2012-06-04  5:25         ` Jan Kratochvil
2012-06-04  6:23           ` Hans-Peter Nilsson
2012-06-04 12:11             ` Alan Modra
2012-06-04 14:37               ` [commit] " Jan Kratochvil
  -- strict thread matches above, loose matches on Subject: below --
2012-05-28  9:04 [PATCH] " Siddhesh Poyarekar

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).