From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) by sourceware.org (Postfix) with ESMTPS id 75C9D3858D35 for ; Tue, 15 Sep 2020 06:17:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 75C9D3858D35 Received: by mail-il1-x142.google.com with SMTP id y2so1902442ilp.7 for ; Mon, 14 Sep 2020 23:17:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=3ERMDk9IeOOH1XthzCwwHiUGKd0260tHTUrdhnujxWo=; b=tI2OnUeYnfcBSgRNF7vrUP9s8Ok9QvUz+qds5S0yv5lFYywQxzkb4rc929gCJ8PQjj omOhOniS4bQSCVH+5YGtOADN89XpHgXMK4Sku/sZTdBzkvYBwsGLUNSQZx5Q2COd9EBs zxsoS09IrRWftYjkxXPyzJt8m2z6MPVZS99prDxW2cpFfyHjfO+6EUvZVMMu4I6zttNr gMn8PuwzDs9yAaPH8ngj/8Rd92aJHcm0r0kPN2miivcYNUR+ycqNc79kyanJX2PqWyyB D/nrawLgtf41XH1jWP7KLSi07Anj0/FeGyL/Zxyq3AemWQ5ufR3tGeGfuYaoi05XebnF hImw== X-Gm-Message-State: AOAM5330paEhMc1L3dyRoxZaNiDKKfnou+KzM+TGLg+OsrdGb1unXCSA CvyAJKQrYgZi5omRYsrLqWB4lFVdfd0YF9PLI2/e1IkwPRzA X-Google-Smtp-Source: ABdhPJw6z/X2j1TvMSrAINFDqI2/EX1uEh2Bkp4ipJOn4lYHYQUXk0PdYeMXASoKaAwkHJ8f/uLqN+t0EB0eUoXxgNo= X-Received: by 2002:a92:d60b:: with SMTP id w11mr14905211ilm.53.1600150675738; Mon, 14 Sep 2020 23:17:55 -0700 (PDT) MIME-Version: 1.0 From: Anatoly Parshintsev Date: Tue, 15 Sep 2020 09:17:45 +0300 Message-ID: Subject: [PATCH] bfd: verilog hex dump backend should handle 64-bit addresses To: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Sep 2020 06:17:57 -0000 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 * 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