public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sim: fix BFD_VMA format arguments on 32-bit hosts
@ 2022-05-21  7:59 Sergei Trofimovich
  2022-06-07  5:15 ` Mike Frysinger
  0 siblings, 1 reply; 3+ messages in thread
From: Sergei Trofimovich @ 2022-05-21  7:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Sergei Trofimovich

From: Sergei Trofimovich <siarheit@google.com>

Noticed format mismatch when attempted to build gdb on i686-linux-gnu
in --enable-64-bit-bfd mode:

    sim/../../sim/cris/sim-if.c:576:28:
        error: format '%lx' expects argument of type 'long unsigned int',
        but argument 4 has type 'bfd_size_type' {aka 'long long unsigned int'} [-Werror=format=]
      576 |       sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,0x%lx",
          |                            ^~~~~~~~~~~~~~~~~~~
      577 |          interp_load_addr, interpsiz);
          |                            ~~~~~~~~~
          |                            |
          |                            bfd_size_type {aka long long unsigned int}

While at it fixed format string for time-related types.
---
 sim/cris/sim-if.c   | 10 ++++++----
 sim/m32c/syscalls.c |  4 ++--
 sim/rx/syscalls.c   |  4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 5b1240f041f..d7c1005fcac 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -257,7 +257,8 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
 
       if (verbose)
 	sim_io_printf (sd,
-		       "Loading segment at 0x%" BFD_VMA_FMT "x, size 0x%lx\n",
+		       "Loading segment at 0x%" BFD_VMA_FMT "x, "
+		       "size 0x%" BFD_VMA_FMT "x\n",
 		       lma, phdr[i].p_filesz);
 
       if (bfd_seek (abfd, phdr[i].p_offset, SEEK_SET) != 0
@@ -265,7 +266,7 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
 	{
 	  sim_io_eprintf (sd,
 			  "%s: could not read segment at 0x%" BFD_VMA_FMT "x, "
-			  "size 0x%lx\n",
+			  "size 0x%" BFD_VMA_FMT "x\n",
 			  STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
 	  free (buf);
 	  return FALSE;
@@ -275,7 +276,7 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
 	{
 	  sim_io_eprintf (sd,
 			  "%s: could not load segment at 0x%" BFD_VMA_FMT "x, "
-			  "size 0x%lx\n",
+			  "size 0x%" BFD_VMA_FMT "x\n",
 			  STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
 	  free (buf);
 	  return FALSE;
@@ -572,7 +573,8 @@ cris_handle_interpreter (SIM_DESC sd, struct bfd *abfd)
 	 memory area, so we go via a temporary area.  Luckily, the
 	 interpreter is supposed to be small, less than 0x40000
 	 bytes.  */
-      sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,0x%lx",
+      sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,"
+		       "0x%" BFD_VMA_FMT "x",
 		       interp_load_addr, interpsiz);
 
       /* Now that memory for the interpreter is defined, load it.  */
diff --git a/sim/m32c/syscalls.c b/sim/m32c/syscalls.c
index 27d4e8f737f..1fb976172c1 100644
--- a/sim/m32c/syscalls.c
+++ b/sim/m32c/syscalls.c
@@ -299,8 +299,8 @@ m32c_syscall (int id)
 
 	rv = gettimeofday (&tv, 0);
 	if (trace)
-	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
-		  tv.tv_usec, tvaddr);
+	  printf ("gettimeofday: %lld sec %lld usec to 0x%x\n",
+		  (long long)tv.tv_sec, (long long)tv.tv_usec, tvaddr);
 	mem_put_si (tvaddr, tv.tv_sec);
 	mem_put_si (tvaddr + 4, tv.tv_usec);
 	put_reg (r0, rv);
diff --git a/sim/rx/syscalls.c b/sim/rx/syscalls.c
index 285d4573da1..2d23e23c6f4 100644
--- a/sim/rx/syscalls.c
+++ b/sim/rx/syscalls.c
@@ -270,8 +270,8 @@ rx_syscall (int id)
 
 	rv = gettimeofday (&tv, 0);
 	if (trace)
-	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
-		  tv.tv_usec, tvaddr);
+	  printf ("gettimeofday: %lld sec %lld usec to 0x%x\n",
+		  (long long)tv.tv_sec, (long long)tv.tv_usec, tvaddr);
 	mem_put_si (tvaddr, tv.tv_sec);
 	mem_put_si (tvaddr + 4, tv.tv_usec);
 	put_reg (1, rv);
-- 
2.36.0


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

* Re: [PATCH] sim: fix BFD_VMA format arguments on 32-bit hosts
  2022-05-21  7:59 [PATCH] sim: fix BFD_VMA format arguments on 32-bit hosts Sergei Trofimovich
@ 2022-06-07  5:15 ` Mike Frysinger
  2022-06-08  6:43   ` [PATCH v2] " Sergei Trofimovich
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Frysinger @ 2022-06-07  5:15 UTC (permalink / raw)
  To: Sergei Trofimovich; +Cc: gdb-patches, Sergei Trofimovich

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

On 21 May 2022 08:59, Sergei Trofimovich via Gdb-patches wrote:
> --- a/sim/cris/sim-if.c
> +++ b/sim/cris/sim-if.c

these BFD_VMA_FMT changes look fine

> --- a/sim/m32c/syscalls.c
> +++ b/sim/m32c/syscalls.c
>
> -	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
> -		  tv.tv_usec, tvaddr);
> +	  printf ("gettimeofday: %lld sec %lld usec to 0x%x\n",
> +		  (long long)tv.tv_sec, (long long)tv.tv_usec, tvaddr);
>
> --- a/sim/rx/syscalls.c
> +++ b/sim/rx/syscalls.c
>
> -	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
> -		  tv.tv_usec, tvaddr);
> +	  printf ("gettimeofday: %lld sec %lld usec to 0x%x\n",
> +		  (long long)tv.tv_sec, (long long)tv.tv_usec, tvaddr);

i think using explicit 64-bit types (i.e. int64_t) rather than long long
would be better.  it's what we used in other places so far (like the sim
callback APIs).
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* [PATCH v2] sim: fix BFD_VMA format arguments on 32-bit hosts
  2022-06-07  5:15 ` Mike Frysinger
@ 2022-06-08  6:43   ` Sergei Trofimovich
  0 siblings, 0 replies; 3+ messages in thread
From: Sergei Trofimovich @ 2022-06-08  6:43 UTC (permalink / raw)
  To: gdb-patches; +Cc: Mike Frysinger, Sergei Trofimovich

From: Sergei Trofimovich <siarheit@google.com>

Noticed format mismatch when attempted to build gdb on i686-linux-gnu
in --enable-64-bit-bfd mode:

    sim/../../sim/cris/sim-if.c:576:28:
        error: format '%lx' expects argument of type 'long unsigned int',
        but argument 4 has type 'bfd_size_type' {aka 'long long unsigned int'} [-Werror=format=]
      576 |       sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,0x%lx",
          |                            ^~~~~~~~~~~~~~~~~~~
      577 |          interp_load_addr, interpsiz);
          |                            ~~~~~~~~~
          |                            |
          |                            bfd_size_type {aka long long unsigned int}

While at it fixed format string for time-related types.
---
Change since v1:
- Used PRId64 / int64_t instead of %lld / long long in format strings.
 sim/cris/sim-if.c   | 10 ++++++----
 sim/m32c/syscalls.c |  4 ++--
 sim/rx/syscalls.c   |  4 ++--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/sim/cris/sim-if.c b/sim/cris/sim-if.c
index 5b1240f041f..d7c1005fcac 100644
--- a/sim/cris/sim-if.c
+++ b/sim/cris/sim-if.c
@@ -257,7 +257,8 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
 
       if (verbose)
 	sim_io_printf (sd,
-		       "Loading segment at 0x%" BFD_VMA_FMT "x, size 0x%lx\n",
+		       "Loading segment at 0x%" BFD_VMA_FMT "x, "
+		       "size 0x%" BFD_VMA_FMT "x\n",
 		       lma, phdr[i].p_filesz);
 
       if (bfd_seek (abfd, phdr[i].p_offset, SEEK_SET) != 0
@@ -265,7 +266,7 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
 	{
 	  sim_io_eprintf (sd,
 			  "%s: could not read segment at 0x%" BFD_VMA_FMT "x, "
-			  "size 0x%lx\n",
+			  "size 0x%" BFD_VMA_FMT "x\n",
 			  STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
 	  free (buf);
 	  return FALSE;
@@ -275,7 +276,7 @@ cris_load_elf_file (SIM_DESC sd, struct bfd *abfd, sim_write_fn do_write)
 	{
 	  sim_io_eprintf (sd,
 			  "%s: could not load segment at 0x%" BFD_VMA_FMT "x, "
-			  "size 0x%lx\n",
+			  "size 0x%" BFD_VMA_FMT "x\n",
 			  STATE_MY_NAME (sd), lma, phdr[i].p_filesz);
 	  free (buf);
 	  return FALSE;
@@ -572,7 +573,8 @@ cris_handle_interpreter (SIM_DESC sd, struct bfd *abfd)
 	 memory area, so we go via a temporary area.  Luckily, the
 	 interpreter is supposed to be small, less than 0x40000
 	 bytes.  */
-      sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,0x%lx",
+      sim_do_commandf (sd, "memory region 0x%" BFD_VMA_FMT "x,"
+		       "0x%" BFD_VMA_FMT "x",
 		       interp_load_addr, interpsiz);
 
       /* Now that memory for the interpreter is defined, load it.  */
diff --git a/sim/m32c/syscalls.c b/sim/m32c/syscalls.c
index 27d4e8f737f..fff4fc93314 100644
--- a/sim/m32c/syscalls.c
+++ b/sim/m32c/syscalls.c
@@ -299,8 +299,8 @@ m32c_syscall (int id)
 
 	rv = gettimeofday (&tv, 0);
 	if (trace)
-	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
-		  tv.tv_usec, tvaddr);
+	  printf ("gettimeofday: %" PRId64 " sec %" PRId64 " usec to 0x%x\n",
+		  (int64_t)tv.tv_sec, (int64_t)tv.tv_usec, tvaddr);
 	mem_put_si (tvaddr, tv.tv_sec);
 	mem_put_si (tvaddr + 4, tv.tv_usec);
 	put_reg (r0, rv);
diff --git a/sim/rx/syscalls.c b/sim/rx/syscalls.c
index 285d4573da1..35ba7d9000b 100644
--- a/sim/rx/syscalls.c
+++ b/sim/rx/syscalls.c
@@ -270,8 +270,8 @@ rx_syscall (int id)
 
 	rv = gettimeofday (&tv, 0);
 	if (trace)
-	  printf ("gettimeofday: %ld sec %ld usec to 0x%x\n", tv.tv_sec,
-		  tv.tv_usec, tvaddr);
+	  printf ("gettimeofday: %" PRId64 " sec %" PRId64 " usec to 0x%x\n",
+		  (int64_t)tv.tv_sec, (int64_t)tv.tv_usec, tvaddr);
 	mem_put_si (tvaddr, tv.tv_sec);
 	mem_put_si (tvaddr + 4, tv.tv_usec);
 	put_reg (1, rv);
-- 
2.36.1


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

end of thread, other threads:[~2022-06-08  6:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-21  7:59 [PATCH] sim: fix BFD_VMA format arguments on 32-bit hosts Sergei Trofimovich
2022-06-07  5:15 ` Mike Frysinger
2022-06-08  6:43   ` [PATCH v2] " Sergei Trofimovich

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