+2018-07-19  Jan Beulich  <jbeulich@suse.com>
+
+       * Makefile.am: Change dependencies and rule for
+       $(srcdir)/i386-init.h.
+       * Makefile.in: Re-generate.
+       * i386-gen.c (process_i386_opcodes): New local variable
+       "marker". Drop opening of input file. Recognize marker and line
+       number directives.
+       * i386-opc.tbl (OPCODE_I386_H): Define.
+       (i386-opc.h): Include it.
+       (None): Undefine.
+
 2018-07-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/23418
 
 $(srcdir)/i386-tbl.h: $(srcdir)/i386-init.h
        @echo $@
 
-$(srcdir)/i386-init.h: @MAINT@ i386-gen$(EXEEXT_FOR_BUILD) i386-opc.tbl i386-reg.tbl
-       ./i386-gen$(EXEEXT_FOR_BUILD) --srcdir $(srcdir)
+$(srcdir)/i386-init.h: @MAINT@ i386-gen$(EXEEXT_FOR_BUILD) i386-opc.tbl i386-reg.tbl i386-opc.h
+       $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) - \
+               < $(srcdir)/i386-opc.tbl \
+               | ./i386-gen$(EXEEXT_FOR_BUILD) --srcdir $(srcdir)
 
 i386-opc.lo: $(srcdir)/i386-tbl.h
 
 
 $(srcdir)/i386-tbl.h: $(srcdir)/i386-init.h
        @echo $@
 
-$(srcdir)/i386-init.h: @MAINT@ i386-gen$(EXEEXT_FOR_BUILD) i386-opc.tbl i386-reg.tbl
-       ./i386-gen$(EXEEXT_FOR_BUILD) --srcdir $(srcdir)
+$(srcdir)/i386-init.h: @MAINT@ i386-gen$(EXEEXT_FOR_BUILD) i386-opc.tbl i386-reg.tbl i386-opc.h
+       $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) - \
+               < $(srcdir)/i386-opc.tbl \
+               | ./i386-gen$(EXEEXT_FOR_BUILD) --srcdir $(srcdir)
 
 i386-opc.lo: $(srcdir)/i386-tbl.h
 
 
   htab_t opcode_hash_table;
   struct opcode_hash_entry **opcode_array;
   unsigned int opcode_array_size = 1024;
-  int lineno = 0;
+  int lineno = 0, marker = 0;
 
   filename = "i386-opc.tbl";
-  fp = fopen (filename, "r");
-
-  if (fp == NULL)
-    fail (_("can't find i386-opc.tbl for reading, errno = %s\n"),
-         xstrerror (errno));
+  fp = stdin;
 
   i = 0;
   opcode_array = (struct opcode_hash_entry **)
       switch (p[0])
        {
        case '#':
+         if (!strcmp("### MARKER ###", buf))
+           marker = 1;
+         else
+           {
+             /* Since we ignore all included files (we only care about their
+                #define-s here), we don't need to monitor filenames.  The final
+                line number directive is going to refer to the main source file
+                again.  */
+             char *end;
+             unsigned long ln;
+
+             p = remove_leading_whitespaces (p + 1);
+             if (!strncmp(p, "line", 4))
+               p += 4;
+             ln = strtoul (p, &end, 10);
+             if (ln > 1 && ln < INT_MAX
+                 && *remove_leading_whitespaces (end) == '"')
+               lineno = ln - 1;
+           }
          /* Ignore comments.  */
        case '\0':
          continue;
          break;
        default:
+         if (!marker)
+           continue;
          break;
        }
 
 
 // Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
 // 02110-1301, USA.
 
+#define OPCODE_I386_H
+#include "i386-opc.h"
+#undef None
+
+### MARKER ###
+
 // Move instructions.
 // We put the 64bit displacement first and we only mark constants
 // larger than 32bit as Disp64.