]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas: make .nops output visible in listing
authorJan Beulich <jbeulich@suse.com>
Mon, 23 Oct 2023 08:36:36 +0000 (10:36 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 23 Oct 2023 08:36:36 +0000 (10:36 +0200)
Due to using a different frag type (in turn due to storing data
differently), making the resulting code appear in listings requires
special handling.

gas/as.h
gas/listing.c
gas/testsuite/gas/i386/i386.exp
gas/testsuite/gas/i386/nop-1.l [new file with mode: 0644]
gas/write.c

index 99ffe77afd27cdd63e533e9b0e9d5bf1fd40ee4d..46dd0d0776d608f502fce8ca4c8a33e33b51fab3 100644 (file)
--- 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
index 54fedbb1e76cab06510227bf6c0fc1800ccbd8dc..00ec9ca23468cfd87523d09c4a84c165c9d64c17 100644 (file)
@@ -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;
     }
index 1072c07e4c7865f55800b8f250c3dbd5ef38604e..1d9e29783fe0722147d7c6ccf9c1bdd7a91df4be 100644 (file)
@@ -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 (file)
index 0000000..a818708
--- /dev/null
@@ -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
index 573a667da2206b07c4a98f46d700775e5dd8526a..20ba3f8bd84eecea817be17acae50932a72c5625 100644 (file)
@@ -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;
        }