public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] gas: make .nops output visible in listing
@ 2023-10-23  8:37 Jan Beulich
  0 siblings, 0 replies; only message in thread
From: Jan Beulich @ 2023-10-23  8:37 UTC (permalink / raw)
  To: bfd-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a0094f1a70e1d5a7a8124e7c988fc1ddd1886f19

commit a0094f1a70e1d5a7a8124e7c988fc1ddd1886f19
Author: Jan Beulich <jbeulich@suse.com>
Date:   Mon Oct 23 10:36:36 2023 +0200

    gas: make .nops output visible in listing
    
    Due to using a different frag type (in turn due to storing data
    differently), making the resulting code appear in listings requires
    special handling.

Diff:
---
 gas/as.h                        |  4 +++-
 gas/listing.c                   | 22 ++++++++++++++++++++++
 gas/testsuite/gas/i386/i386.exp |  1 +
 gas/testsuite/gas/i386/nop-1.l  | 39 +++++++++++++++++++++++++++++++++++++++
 gas/write.c                     |  7 ++++++-
 5 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/gas/as.h b/gas/as.h
index 99ffe77afd2..46dd0d0776d 100644
--- a/gas/as.h
+++ b/gas/as.h
@@ -247,7 +247,9 @@ enum _relax_state
      1 constant byte: no-op fill control byte.  */
   rs_space_nop,
 
-  /* Similar to rs_fill.  It is used to implement .nop directive .  */
+  /* Similar to rs_fill.  It is used to implement .nops directive.
+     When listings are enabled, fr_opcode gets the buffer assigned, once
+     that's available.  */
   rs_fill_nop,
 
   /* A DWARF leb128 value; only ELF uses this.  The subtype is 0 for
diff --git a/gas/listing.c b/gas/listing.c
index 54fedbb1e76..00ec9ca2346 100644
--- a/gas/listing.c
+++ b/gas/listing.c
@@ -815,6 +815,28 @@ calc_hex (list_info_type *list)
 		var_rep_idx = var_rep_max;
 	    }
 	}
+      else if (frag_ptr->fr_type == rs_fill_nop && frag_ptr->fr_opcode)
+	{
+	  gas_assert (!octet_in_frag);
+
+	  /* Print as many bytes from fr_opcode as is sensible.  */
+	  while (octet_in_frag < (unsigned int) frag_ptr->fr_offset
+		 && data_buffer_size < MAX_BYTES - 3)
+	    {
+	      if (address == ~(unsigned int) 0)
+		address = frag_ptr->fr_address / OCTETS_PER_BYTE;
+
+	      sprintf (data_buffer + data_buffer_size,
+		       "%02X",
+		       frag_ptr->fr_opcode[octet_in_frag] & 0xff);
+	      data_buffer_size += 2;
+
+	      octet_in_frag++;
+	    }
+
+	  free (frag_ptr->fr_opcode);
+	  frag_ptr->fr_opcode = NULL;
+	}
 
       frag_ptr = frag_ptr->fr_next;
     }
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index 1072c07e4c7..1d9e29783fe 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -598,6 +598,7 @@ if [gas_32_check] then {
     run_list_test "inval-pseudo" "-al"
     run_dump_test "nop-1"
     run_dump_test "nop-1-suffix"
+    run_list_test "nop-1" "-aln"
     run_dump_test "nop-2"
     run_dump_test "optimize-1"
     run_dump_test "optimize-1a"
diff --git a/gas/testsuite/gas/i386/nop-1.l b/gas/testsuite/gas/i386/nop-1.l
new file mode 100644
index 00000000000..a8187086692
--- /dev/null
+++ b/gas/testsuite/gas/i386/nop-1.l
@@ -0,0 +1,39 @@
+[ 	]*[0-9]+[ 	]+\.text
+[ 	]*[0-9]+[ 	]+single:
+[ 	]*[0-9]+[ 	]+\.nops 0
+[ 	]*[0-9]+[ 	]+.... 90[ 	]+nop
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+pseudo_1:
+[ 	]*[0-9]+[ 	]+.... 90[ 	]+\.nops 1
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+pseudo_8:
+[ 	]*[0-9]+[ 	]+.... 2E8DB426[ 	]+\.nops 8
+[ 	]*[0-9]+[ 	]+00000000 *
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+pseudo_8_4:
+[ 	]*[0-9]+[ 	]+.... 8D742600[ 	]+\.nops 8, 4
+[ 	]*[0-9]+[ 	]+8D742600 *
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+pseudo_20:
+[ 	]*[0-9]+[ 	]+.... 2E8DB426[ 	]+\.nops 20
+[ 	]*[0-9]+[ 	]+00000000 *
+[ 	]*[0-9]+[ 	]+2E8DB426 *
+[ 	]*[0-9]+[ 	]+00000000 *
+[ 	]*[0-9]+[ 	]+8D742600 *
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+pseudo_30:
+[ 	]*[0-9]+[ 	]+.... EB1C2E8D[ 	]+\.nops 30
+[ 	]*[0-9]+[ 	]+B4260000 *
+[ 	]*[0-9]+[ 	]+00002E8D *
+[ 	]*[0-9]+[ 	]+B4260000 *
+[ 	]*[0-9]+[ 	]+00002E8D *
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+pseudo_129:
+[ 	]*[0-9]+[ 	]+.... EB7F2E8D[ 	]+\.nops 129
+[ 	]*[0-9]+[ 	]+B4260000 *
+[ 	]*[0-9]+[ 	]+00002E8D *
+[ 	]*[0-9]+[ 	]+B4260000 *
+[ 	]*[0-9]+[ 	]+00002E8D *
+[ 	]*[0-9]+[ 	]*
+[ 	]*[0-9]+[ 	]+end:
+#pass
diff --git a/gas/write.c b/gas/write.c
index 573a667da22..20ba3f8bd84 100644
--- a/gas/write.c
+++ b/gas/write.c
@@ -1682,7 +1682,12 @@ write_contents (bfd *abfd ATTRIBUTE_UNUSED,
 			  bfd_get_filename (stdoutput),
 			  bfd_errmsg (bfd_get_error ()));
 	      offset += count;
-	      free (buf);
+#ifndef NO_LISTING
+	      if (listing & LISTING_LISTING)
+		f->fr_opcode = buf;
+	      else
+#endif
+		free (buf);
 	    }
 	  continue;
 	}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-10-23  8:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-23  8:37 [binutils-gdb] gas: make .nops output visible in listing Jan Beulich

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