public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] bfd: verilog hex dump backend should handle 64-bit addresses
@ 2020-09-13 23:30 Anatoly Parshintsev
  2020-09-14 20:15 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Anatoly Parshintsev @ 2020-09-13 23:30 UTC (permalink / raw)
  To: gdb-patches

I observed that `objcopy -O verilog in.o out.dump` command does truncate
the high part of an 64-bit address. The problem can be demonstrated with
the following sequence of commands (bash):

```
  printf '.section the_section, \"a\"\n.byte 0xff\n' |            \
     as -o /tmp/a.o &&                                            \
     ld --section-start=the_section=0x80000000 --defsym=_start=0  \
     /tmp/a.o -o /tmp/final.o &&                                  \
     objcopy -O verilog  /tmp/final.o /tmp/final.v &&             \
     cat /tmp/final.v

  printf '.section the_section, \"a\"\n.byte 0xff\n' |            \
     as -o /tmp/a.o &&                                            \
     ld --section-start=the_section=0x800000000 --defsym=_start=0 \
     /tmp/a.o -o /tmp/final.o &&                                  \
     objcopy -O verilog  /tmp/final.o /tmp/final.v &&             \
     cat /tmp/final.v
```

The output will be:

```
  @80000000
  FF
  @00000000
  FF
```

This is clearly wrong as the second address gets truncated.

When the suggested patch is applied, the output is expected to be:

```
        @0000000800000000
        FF
```

I've run the existing tests (only Binutils-related; `make check`) to make sure
that no regression is introduced.

I considered extending an existing testsuite, but given that it requires
usage of several tools: as, linker and objcopy - I've discarded the idea
since it seems like the result will be too complex
(compared to the existing objcopy tests).

bfd/ChangeLog:
2020-09-14  Anatoly Parshintsev <kupokupokupopo@gmail.com>

       * verilog.c (verilog_write_address): Properly handle 64-bit addresses
       to avoid truncation of the high part.
---
 bfd/verilog.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/bfd/verilog.c b/bfd/verilog.c
index 9f22bc36bb..a40c89a349 100644
--- a/bfd/verilog.c
+++ b/bfd/verilog.c
@@ -165,12 +165,30 @@ verilog_set_section_contents (bfd *abfd,
 static bfd_boolean
 verilog_write_address (bfd *abfd, bfd_vma address)
 {
+#ifdef BFD64
+  char buffer[20];
+#else
   char buffer[12];
+#endif
+
   char *dst = buffer;
   bfd_size_type wrlen;

   /* Write the address.  */
   *dst++ = '@';
+#ifdef BFD64
+  if (address >= (bfd_vma)1 << 32)
+    {
+      TOHEX (dst, (address >> 56));
+      dst += 2;
+      TOHEX (dst, (address >> 48));
+      dst += 2;
+      TOHEX (dst, (address >> 40));
+      dst += 2;
+      TOHEX (dst, (address >> 32));
+      dst += 2;
+    }
+#endif
   TOHEX (dst, (address >> 24));
   dst += 2;
   TOHEX (dst, (address >> 16));
--
2.20.1

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

* Re: [PATCH] bfd: verilog hex dump backend should handle 64-bit addresses
  2020-09-13 23:30 [PATCH] bfd: verilog hex dump backend should handle 64-bit addresses Anatoly Parshintsev
@ 2020-09-14 20:15 ` Tom Tromey
  2020-09-15  6:08   ` Anatoly Parshintsev
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-09-14 20:15 UTC (permalink / raw)
  To: Anatoly Parshintsev via Gdb-patches; +Cc: Anatoly Parshintsev

>>>>> "Anatoly" == Anatoly Parshintsev via Gdb-patches <gdb-patches@sourceware.org> writes:

Anatoly> I observed that `objcopy -O verilog in.o out.dump` command does truncate
Anatoly> the high part of an 64-bit address. The problem can be demonstrated with
Anatoly> the following sequence of commands (bash):

BFD patches should be sent to the binutils list instead.

Tom

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

* Re: [PATCH] bfd: verilog hex dump backend should handle 64-bit addresses
  2020-09-14 20:15 ` Tom Tromey
@ 2020-09-15  6:08   ` Anatoly Parshintsev
  0 siblings, 0 replies; 3+ messages in thread
From: Anatoly Parshintsev @ 2020-09-15  6:08 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Anatoly Parshintsev via Gdb-patches

My bad. Thanks for pointing that out!

On Mon, 14 Sep 2020 at 23:15, Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> "Anatoly" == Anatoly Parshintsev via Gdb-patches <gdb-patches@sourceware.org> writes:
>
> Anatoly> I observed that `objcopy -O verilog in.o out.dump` command does truncate
> Anatoly> the high part of an 64-bit address. The problem can be demonstrated with
> Anatoly> the following sequence of commands (bash):
>
> BFD patches should be sent to the binutils list instead.
>
> Tom

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

end of thread, other threads:[~2020-09-15  6:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-13 23:30 [PATCH] bfd: verilog hex dump backend should handle 64-bit addresses Anatoly Parshintsev
2020-09-14 20:15 ` Tom Tromey
2020-09-15  6:08   ` Anatoly Parshintsev

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