]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add support to the assembler for a ".nop" directive which inserts a single no-op...
authorNick Clifton <nickc@redhat.com>
Tue, 15 Sep 2020 09:27:50 +0000 (10:27 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 15 Sep 2020 09:27:50 +0000 (10:27 +0100)
Import from mainline:
2020-09-14  Nick Clifton  <nickc@redhat.com>

* read.c (s_nop): New function.  Handles the .nop directive.
(potable): Add entry for "nop".
(s_nops): Code tidy.
* read.h (s_nop): Add prototype.
* config/tc-bpf.h (md_single_noop_insn): Define.
* config/tc-mmix.h (md_single_noop_insn): Define.
* config/tc-or1k.h (md_single_noop_insn): Define.
* config/tc-ia64.h (md_single_noop_insn): Define.
* write.c (relax_segment): Update error message regarding
non-absolute values passed to .fill and .nops.
* NEWS: Mention the new directive.
* doc/as.texi: Document the new directive.
* doc/internals.texi: Document the new internal macros used to
implement the new directive.
* testsuite/gas/all/nop.s: New test.
* testsuite/gas/all/nop.d: New test control file.
* testsuite/gas/all/gas.exp: Run the new test.
* testsuite/gas/elf/dwarf-5-nop-for-line-table.s: New test.
* testsuite/gas/elf/dwarf-5-nop-for-line-table.d: New test
control file.
* testsuite/gas/elf/elf.exp: Run the new test.
* testsuite/gas/i386/space1.l: Adjust expected output.

17 files changed:
gas/ChangeLog
gas/config/tc-bpf.h
gas/config/tc-ia64.h
gas/config/tc-mmix.h
gas/config/tc-or1k.h
gas/doc/as.texi
gas/doc/internals.texi
gas/read.c
gas/read.h
gas/testsuite/gas/all/gas.exp
gas/testsuite/gas/all/nop.d [new file with mode: 0644]
gas/testsuite/gas/all/nop.s [new file with mode: 0644]
gas/testsuite/gas/elf/dwarf-5-nop-for-line-table.d [new file with mode: 0644]
gas/testsuite/gas/elf/dwarf-5-nop-for-line-table.s [new file with mode: 0644]
gas/testsuite/gas/elf/elf.exp
gas/testsuite/gas/i386/space1.l
gas/write.c

index 89e2dceafba9f48ed287b650549a27ccb05e4f3d..ded386234359aca4d79a9ad5fc6f70d8417c8b6d 100644 (file)
@@ -1,3 +1,31 @@
+2020-09-15  Nick Clifton  <nickc@redhat.com>
+
+       Import from mainline:
+       2020-09-14  Nick Clifton  <nickc@redhat.com>
+
+       * read.c (s_nop): New function.  Handles the .nop directive.
+       (potable): Add entry for "nop".
+       (s_nops): Code tidy.
+       * read.h (s_nop): Add prototype.
+       * config/tc-bpf.h (md_single_noop_insn): Define.
+       * config/tc-mmix.h (md_single_noop_insn): Define.
+       * config/tc-or1k.h (md_single_noop_insn): Define.
+       * config/tc-ia64.h (md_single_noop_insn): Define.
+       * write.c (relax_segment): Update error message regarding
+       non-absolute values passed to .fill and .nops.
+       * NEWS: Mention the new directive.
+       * doc/as.texi: Document the new directive.
+       * doc/internals.texi: Document the new internal macros used to
+       implement the new directive.
+       * testsuite/gas/all/nop.s: New test.
+       * testsuite/gas/all/nop.d: New test control file.
+       * testsuite/gas/all/gas.exp: Run the new test.
+       * testsuite/gas/elf/dwarf-5-nop-for-line-table.s: New test.
+       * testsuite/gas/elf/dwarf-5-nop-for-line-table.d: New test
+       control file.
+       * testsuite/gas/elf/elf.exp: Run the new test.
+       * testsuite/gas/i386/space1.l: Adjust expected output.
+
 2020-09-14  Mark Wielaard  <mark@klomp.org>
 
        Backport from mainline:
index 5765833997ef7f61d1a5ef16ad6421d2ec188e84..cb02d6c13383250d6fcd50ab6239608a4665ef4a 100644 (file)
@@ -48,3 +48,4 @@
 /* Values passed to md_apply_fix don't include the symbol value.  */
 #define MD_APPLY_SYM_VALUE(FIX) 0
 
+#define md_single_noop_insn "mov %r1,%r1"
index e982e57b477c7b39fe0aa13463fb33144888299d..d187bbc9f085373cf2c0f68f010fc941fab8f362 100644 (file)
@@ -327,3 +327,5 @@ typedef struct unwind_record
 #ifdef TE_VMS
 #define DWARF2_VERSION      (dwarf_level < 3 ? 3  : dwarf_level)
 #endif
+
+#define md_single_noop_insn "nop 0"
index f7a54c1de26385cb4c918331835c7b4ac7cddf47..2d8e226dc8029a0f4c2fdb769e8b183c66f874d3 100644 (file)
@@ -228,3 +228,5 @@ extern void mmix_md_do_align (int, char *, int, int);
 
 /* MMIX has global register symbols.  */
 #define TC_GLOBAL_REGISTER_SYMBOL_OK
+
+#define md_single_noop_insn "set $0, $0"
index 0242dd480fb357c92bc4adf7376ba47aaad0303d..b9aa00cb9abf01b39c09128f73075f838c19859c 100644 (file)
@@ -74,3 +74,5 @@ void or1k_elf_final_processing (void);
 #define tc_cfi_frame_initial_instructions \
     or1k_cfi_frame_initial_instructions
 extern void or1k_cfi_frame_initial_instructions (void);
+
+#define md_single_noop_insn "l.nop"
index a3f78342913c0eb353ad91e27e81b738e66aed61..8ce9fb73e2e7303a64e87233dfded8169163d289 100644 (file)
@@ -4459,6 +4459,7 @@ Some machine configurations provide additional directives.
 * MRI::                                @code{.mri @var{val}}
 * Noaltmacro::                  @code{.noaltmacro}
 * Nolist::                      @code{.nolist}
+* Nop::                         @code{.nop}
 * Nops::                        @code{.nops @var{size}[, @var{control}]}
 * Octa::                        @code{.octa @var{bignums}}
 * Offset::                     @code{.offset @var{loc}}
@@ -6167,22 +6168,31 @@ internal counter (which is zero initially).   @code{.list} increments the
 counter, and @code{.nolist} decrements it.  Assembly listings are
 generated whenever the counter is greater than zero.
 
+@node Nop
+@section @code{.nop}
+
+@cindex @code{nop} directive
+@cindex filling memory with no-op instructions
+This directive emits a single no-op instruction.  It is provided on all
+architectures, allowing the creation of architecture neutral tests involving
+actual code.  The size of the generated instruction is target specific.  The
+instruction does affect the generation of DWARF debug line information.
+
 @node Nops
 @section @code{.nops @var{size}[, @var{control}]}
 
 @cindex @code{nops} directive
 @cindex filling memory with no-op instructions
-This directive emits @var{size} bytes filled with no-op instructions.
-@var{size} is absolute expression, which must be a positve value.
-@var{control} controls how no-op instructions should be generated.  If
-the comma and @var{control} are omitted, @var{control} is assumed to be
-zero.
-
-Note: For Intel 80386 and AMD x86-64 targets, @var{control} specifies
-the size limit of a no-op instruction.  The valid values of @var{control}
-are between 0 and 4 in 16-bit mode, between 0 and 7 when tuning for
-older processors in 32-bit mode, between 0 and 11 in 64-bit mode or when
-tuning for newer processors in 32-bit mode.  When 0 is used, the no-op
+This directive emits no-op instructions.  It is specific to the Intel 80386 and
+AMD x86-64 targets.  It takes a @var{size} argument and generates @var{size}
+bytes of no-op instructions.  @var{size} must be absolute and positive.  These
+bytes do not affect the generation of DWARF debug line information.
+
+The optional @var{control} argument specifies a size limit for a single no-op
+instruction.  If not provided then a value of 0 is assumed.  The valid values
+of @var{control} are between 0 and 4 in 16-bit mode, between 0 and 7 when
+tuning for older processors in 32-bit mode, between 0 and 11 in 64-bit mode or
+when tuning for newer processors in 32-bit mode.  When 0 is used, the no-op
 instruction size limit is set to the maximum supported size.
 
 @node Octa
index 23520bdf75bbefb7d8cabe9af073a547a5cb7d82..1230ddd104509fde231c22ae49bff433ff12f8b7 100644 (file)
@@ -1547,6 +1547,16 @@ The function should return the debug format that is preferred by the CPU
 backend.  This format will be used when generating assembler specific debug
 information.
 
+@item md_emit_single_noop_insn
+@itemx md_single_noop_insn
+These macro facilitate the @var{.nop} directive.  If defined the
+@var{md_emit_single_noop_insn) macro provides code to insert a single no-op
+instruction into the output stream.  If this involves calling @var{md_assemble}
+with a fixed string then the alternative macro @var{md_single_noop_insn} can be
+defined, specifying the string to pass.  If neither of these macros are defined
+then the @var{.nop} directive will call @var{md_assemble} with the string
+@option{nop}.
+
 @item md_allow_local_subtract (@var{left}, @var{right}, @var{section})
 If defined, GAS will call this macro when evaluating an expression which is the
 difference of two symbols defined in the same section.  It takes three
index f192cc16d579d05443051fc33fe759bb08d4cc09..69eb19c3784b6766d2fb448087fb1f4888dbdbd7 100644 (file)
@@ -417,6 +417,7 @@ static const pseudo_typeS potable[] = {
   {"noformat", s_ignore, 0},
   {"nolist", listing_list, 0}, /* Turn listing off.  */
   {"nopage", listing_nopage, 0},
+  {"nop", s_nop, 0},
   {"nops", s_nops, 0},
   {"octa", cons, 16},
   {"offset", s_struct, 0},
@@ -3437,6 +3438,43 @@ s_space (int mult)
     mri_comment_end (stop, stopc);
 }
 
+void
+s_nop (int ignore ATTRIBUTE_UNUSED)
+{
+#ifdef md_flush_pending_output
+  md_flush_pending_output ();
+#endif
+
+#ifdef md_cons_align
+  md_cons_align (1);
+#endif
+
+  SKIP_WHITESPACE ();
+  demand_empty_rest_of_line ();
+
+#ifdef md_emit_single_noop
+  md_emit_single_noop;
+#else
+  char * nop;
+
+#ifndef md_single_noop_insn
+#define md_single_noop_insn "nop"
+#endif
+  /* md_assemble might modify its argument, so
+     we must pass it a string that is writeable.  */
+  if (asprintf (&nop, "%s", md_single_noop_insn) < 0)
+    as_fatal ("%s", xstrerror (errno));
+
+  /* Some targets assume that they can update input_line_pointer inside
+     md_assemble, and, worse, that they can leave it assigned to the string
+     pointer that was provided as an argument.  So preserve ilp here.  */
+  char * saved_ilp = input_line_pointer;
+  md_assemble (nop);
+  input_line_pointer = saved_ilp;
+  free (nop);
+#endif
+}
+
 void
 s_nops (int ignore ATTRIBUTE_UNUSED)
 {
@@ -3451,8 +3489,12 @@ s_nops (int ignore ATTRIBUTE_UNUSED)
   md_cons_align (1);
 #endif
 
+  SKIP_WHITESPACE ();
   expression (&exp);
+  /* Note - this expression is tested for an absolute value in
+     write.c:relax_segment().  */
 
+  SKIP_WHITESPACE ();
   if (*input_line_pointer == ',')
     {
       ++input_line_pointer;
@@ -3464,29 +3506,30 @@ s_nops (int ignore ATTRIBUTE_UNUSED)
       val.X_add_number = 0;
     }
 
-  if (val.X_op == O_constant)
+  if (val.X_op != O_constant)
     {
-      if (val.X_add_number < 0)
-       {
-         as_warn (_("negative nop control byte, ignored"));
-         val.X_add_number = 0;
-       }
-
-      if (!need_pass_2)
-       {
-         /* Store the no-op instruction control byte in the first byte
-            of frag.  */
-         char *p;
-         symbolS *sym = make_expr_symbol (&exp);
-         p = frag_var (rs_space_nop, 1, 1, (relax_substateT) 0,
-                       sym, (offsetT) 0, (char *) 0);
-         *p = val.X_add_number;
-       }
+      as_bad (_("unsupported variable nop control in .nops directive"));
+      val.X_op = O_constant;
+      val.X_add_number = 0;
+    }
+  else if (val.X_add_number < 0)
+    {
+      as_warn (_("negative nop control byte, ignored"));
+      val.X_add_number = 0;
     }
-  else
-    as_bad (_("unsupported variable nop control in .nops directive"));
 
   demand_empty_rest_of_line ();
+
+  if (need_pass_2)
+    /* Ignore this directive if we are going to perform a second pass.  */
+    return;
+
+  /* Store the no-op instruction control byte in the first byte of frag.  */
+  char *p;
+  symbolS *sym = make_expr_symbol (&exp);
+  p = frag_var (rs_space_nop, 1, 1, (relax_substateT) 0,
+               sym, (offsetT) 0, (char *) 0);
+  *p = val.X_add_number;
 }
 
 /* This is like s_space, but the value is a floating point number with
index ffcdbb69a7b96518c03f0ba6cd420bb72ef9040e..b2f0d363b138c7bf745f9dd7908ab7aa92633eba 100644 (file)
@@ -207,6 +207,7 @@ extern void s_purgem (int);
 extern void s_rept (int);
 extern void s_set (int);
 extern void s_space (int mult);
+extern void s_nop (int);
 extern void s_nops (int);
 extern void s_stab (int what);
 extern void s_struct (int);
index c782955370ab225f2be4930884743689f39ee535..7ecf26e4e09e09cac3683219a44ed16aa97dce72 100644 (file)
@@ -440,6 +440,7 @@ dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/err-*.s $srcdir/$subdir/warn
 dg-finish
 
 # Set $nop_type appropriately to indicate the NOP instruction mnemonic.
+# Note - this code is made obsolete by the new .nops pseudo-op.
 switch -glob $target_triplet {
     bpf-*-* {
         set nop_type 6
@@ -467,3 +468,5 @@ run_dump_test "org-6"
 run_dump_test "fill-1"
 
 gas_test "pr23938.s" "" "" ".xstabs"
+
+run_dump_test "nop"
diff --git a/gas/testsuite/gas/all/nop.d b/gas/testsuite/gas/all/nop.d
new file mode 100644 (file)
index 0000000..81ac08d
--- /dev/null
@@ -0,0 +1,8 @@
+#objdump: -s -j .text -j "\$TEXT\$"
+#name: Generate NOPs in an architecture neutral manner
+
+.*: +file format .*
+
+Contents of section (\.text|\$TEXT\$):
+ [^ ]* .*
+#pass
diff --git a/gas/testsuite/gas/all/nop.s b/gas/testsuite/gas/all/nop.s
new file mode 100644 (file)
index 0000000..bca3805
--- /dev/null
@@ -0,0 +1,2 @@
+       .text
+       .nop
diff --git a/gas/testsuite/gas/elf/dwarf-5-nop-for-line-table.d b/gas/testsuite/gas/elf/dwarf-5-nop-for-line-table.d
new file mode 100644 (file)
index 0000000..651a1a2
--- /dev/null
@@ -0,0 +1,12 @@
+#as: --gdwarf-5
+#name: Check line table is produced with .nops
+#readelf: -wL
+
+#...
+Contents of the .debug_line section:
+
+CU: .*
+File name.*
+#...
+.*[    ]+[1-8][        ]+0.*
+#pass
diff --git a/gas/testsuite/gas/elf/dwarf-5-nop-for-line-table.s b/gas/testsuite/gas/elf/dwarf-5-nop-for-line-table.s
new file mode 100644 (file)
index 0000000..e3712ff
--- /dev/null
@@ -0,0 +1,3 @@
+       .text
+       .nop
+       .nop
index 155f78efa7f8bed282d753d2f21aa72b69b51315..52c02cffc54e6563adc9be51a7823b40a176ce50 100644 (file)
@@ -276,6 +276,7 @@ if { [is_elf_format] } then {
     run_dump_test "dwarf-5-file0" $dump_opts
     run_dump_test "dwarf-4-cu" $dump_opts
     run_dump_test "dwarf-5-cu" $dump_opts
+    run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
     run_dump_test "pr25917"
     run_dump_test "bss"
     run_dump_test "bad-bss"
index 5b0053ee3790cea8469873792dff8d8ebfbe9925..bf446fa9b12f5a91368fa10b2718b052c58361a0 100644 (file)
@@ -1,9 +1,9 @@
 .*: Assembler messages:
-.*:2: Error: .space specifies non-absolute value
-.*:3: Error: .space specifies non-absolute value
-.*:4: Error: .space specifies non-absolute value
-.*:5: Error: .space specifies non-absolute value
-.*:6: Error: .space specifies non-absolute value
+.*:2: Error: .space, .nops or .fill specifies non-absolute value
+.*:3: Error: .space, .nops or .fill specifies non-absolute value
+.*:4: Error: .space, .nops or .fill specifies non-absolute value
+.*:5: Error: .space, .nops or .fill specifies non-absolute value
+.*:6: Error: .space, .nops or .fill specifies non-absolute value
 GAS LISTING .*
 
 
index 0b43063bbaab76d21fe3bac5fb4643bfff3c72e2..054f27987d51f1732afdc81bbc9e19a95160c53f 100644 (file)
@@ -3017,7 +3017,7 @@ relax_segment (struct frag *segment_frag_root, segT segment, int pass)
                        || ! S_IS_DEFINED (symbolP))
                      {
                        as_bad_where (fragP->fr_file, fragP->fr_line,
-                                     _(".space specifies non-absolute value"));
+                                     _(".space, .nops or .fill specifies non-absolute value"));
                        /* Prevent repeat of this error message.  */
                        fragP->fr_symbol = 0;
                      }