public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: Put all emulation options in ldlex.h
@ 2024-01-17 15:46 H.J. Lu
  2024-01-18 15:31 ` H.J. Lu
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2024-01-17 15:46 UTC (permalink / raw)
  To: binutils

For each command line option, parse_args() calls ldemul_parse_args()
to check if the command line option is an emulation option.  But when
there is a conflict between the emulation option value and the default
option value, the default command line option will be processed as if
the emulation option is used.  Remove PARSE_AND_LIST_PROLOGUE and move
all emulation options to ldlex.h to avoid conflicts.

	PR ld/31247
	* ldlex.h (option_values): Add all emulation options.
	* emulparams/elf32mcore.sh (PARSE_AND_LIST_PROLOGUE): Removed.
	* emulparams/plt_unwind.sh (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/aarch64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/alphaelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/armelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/avrelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/bfin.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/cskyelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/hppaelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/ia64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/m68hc1xelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/m68kelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/metagelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/mipself.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/nds32elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/nto.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/ppc32elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/ppc64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/riscvelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/rxelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/s390.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/scoreelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/spuelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/tic6xdsbt.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/vxworks.em (PARSE_AND_LIST_PROLOGUE): Likewise.
	* emultempl/aix.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	(gld${EMULATION_NAME}_read_file): Replace lineno with linenumber.
	* emultempl/beos.em (OPTION_XXX): Removed.
	* emultempl/elf.em: Include "ldlex.h".
	Don't check PARSE_AND_LIST_PROLOGUE.
	(OPTION_XXX): Removed.
	* emultempl/msp430.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	* emultempl/pe.em (OPTION_XXX): Removed.
	* emultempl/pep.em (OPTION_XXX): Likewise.
	* emultempl/ticoff.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	* emultempl/vms.em: Include "ldlex.h".
	(OPTION_XXX): Removed.
	* emultempl/xtensaelf.em (elf32xtensa_size_opt,
	elf32xtensa_no_literal_movement, elf32xtensa_abi): Moved out of
	PARSE_AND_LIST_PROLOGUE.
	(PARSE_AND_LIST_PROLOGUE): Removed.
---
 ld/emulparams/elf32mcore.sh |   4 -
 ld/emulparams/plt_unwind.sh |   5 -
 ld/emultempl/aarch64elf.em  |  10 --
 ld/emultempl/aix.em         |  50 ++-----
 ld/emultempl/alphaelf.em    |   6 -
 ld/emultempl/armelf.em      |  25 ----
 ld/emultempl/avrelf.em      |   9 --
 ld/emultempl/beos.em        |  16 --
 ld/emultempl/bfin.em        |   5 -
 ld/emultempl/cskyelf.em     |   6 -
 ld/emultempl/elf.em         |  22 +--
 ld/emultempl/hppaelf.em     |   5 -
 ld/emultempl/ia64elf.em     |   4 -
 ld/emultempl/m68hc1xelf.em  |   5 -
 ld/emultempl/m68kelf.em     |   4 -
 ld/emultempl/metagelf.em    |   4 -
 ld/emultempl/mipself.em     |  12 --
 ld/emultempl/msp430.em      |   5 +-
 ld/emultempl/nds32elf.em    |  12 --
 ld/emultempl/nto.em         |   8 -
 ld/emultempl/pe.em          |  78 ----------
 ld/emultempl/pep.em         |  73 ---------
 ld/emultempl/ppc32elf.em    |  20 ---
 ld/emultempl/ppc64elf.em    |  35 -----
 ld/emultempl/riscvelf.em    |  10 --
 ld/emultempl/rxelf.em       |   7 -
 ld/emultempl/s390.em        |   4 -
 ld/emultempl/scoreelf.em    |   1 -
 ld/emultempl/spuelf.em      |  24 ---
 ld/emultempl/tic6xdsbt.em   |   6 -
 ld/emultempl/ticoff.em      |   2 +-
 ld/emultempl/vms.em         |   2 +-
 ld/emultempl/vxworks.em     |   6 -
 ld/emultempl/xtensaelf.em   |  14 +-
 ld/ldlex.h                  | 286 ++++++++++++++++++++++++++++++++++++
 35 files changed, 304 insertions(+), 481 deletions(-)

diff --git a/ld/emulparams/elf32mcore.sh b/ld/emulparams/elf32mcore.sh
index 88a8cb6e70b..7d433fc0f2d 100644
--- a/ld/emulparams/elf32mcore.sh
+++ b/ld/emulparams/elf32mcore.sh
@@ -30,10 +30,6 @@ TEMPLATE_NAME=elf
 
 # This code gets inserted into the generic elf32.sc linker script
 # and allows us to define our own command line switches.
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_BASE_FILE		300
-'
-
 PARSE_AND_LIST_LONGOPTS='
   {"base-file", required_argument, NULL, OPTION_BASE_FILE},
 '
diff --git a/ld/emulparams/plt_unwind.sh b/ld/emulparams/plt_unwind.sh
index ab16156415e..beb67260443 100644
--- a/ld/emulparams/plt_unwind.sh
+++ b/ld/emulparams/plt_unwind.sh
@@ -1,10 +1,5 @@
 PLT_UNWIND=yes
 
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_LD_GENERATED_UNWIND_INFO	301
-#define OPTION_NO_LD_GENERATED_UNWIND_INFO 302
-'
-
 PARSE_AND_LIST_LONGOPTS='
   {"ld-generated-unwind-info", no_argument, NULL,
    OPTION_LD_GENERATED_UNWIND_INFO},
diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
index b647909ae63..aa2859d4f73 100644
--- a/ld/emultempl/aarch64elf.em
+++ b/ld/emultempl/aarch64elf.em
@@ -355,16 +355,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_NO_ENUM_SIZE_WARNING	309
-#define OPTION_PIC_VENEER		310
-#define OPTION_STUBGROUP_SIZE		311
-#define OPTION_NO_WCHAR_SIZE_WARNING	312
-#define OPTION_FIX_ERRATUM_835769	313
-#define OPTION_FIX_ERRATUM_843419	314
-#define OPTION_NO_APPLY_DYNAMIC_RELOCS	315
-'
-
 PARSE_AND_LIST_SHORTOPTS=p
 
 PARSE_AND_LIST_LONGOPTS='
diff --git a/ld/emultempl/aix.em b/ld/emultempl/aix.em
index a445c32931d..33857b5d49c 100644
--- a/ld/emultempl/aix.em
+++ b/ld/emultempl/aix.em
@@ -48,6 +48,7 @@ fragment <<EOF
 #include "ldexp.h"
 #include "ldlang.h"
 #include "ldfile.h"
+#include "ldlex.h"
 #include "ldemul.h"
 #include "ldctor.h"
 #include <ldgram.h>
@@ -171,35 +172,6 @@ gld${EMULATION_NAME}_before_parse (void)
 
 /* Handle AIX specific options.  */
 
-enum
-  {
-    OPTION_IGNORE = 300,
-    OPTION_AUTOIMP,
-    OPTION_ERNOTOK,
-    OPTION_EROK,
-    OPTION_EXPALL,
-    OPTION_EXPFULL,
-    OPTION_EXPORT,
-    OPTION_IMPORT,
-    OPTION_INITFINI,
-    OPTION_LOADMAP,
-    OPTION_MAXDATA,
-    OPTION_MAXSTACK,
-    OPTION_MODTYPE,
-    OPTION_NOAUTOIMP,
-    OPTION_NOEXPALL,
-    OPTION_NOEXPFULL,
-    OPTION_NOSTRCMPCT,
-    OPTION_PD,
-    OPTION_PT,
-    OPTION_STRCMPCT,
-    OPTION_UNIX,
-    OPTION_32,
-    OPTION_64,
-    OPTION_LIBPATH,
-    OPTION_NOLIBPATH,
-  };
-
 static void
 gld${EMULATION_NAME}_add_options
   (int ns, char **shortopts, int nl, struct option **longopts,
@@ -1299,7 +1271,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 {
   struct obstack *o;
   FILE *f;
-  int lineno;
+  int linenumber;
   int c;
   bool keep;
   const char *imppath;
@@ -1323,7 +1295,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
   impfile = NULL;
   impmember = NULL;
 
-  lineno = 0;
+  linenumber = 0;
 
   /* Default to 32 and 64 bit mode
      symbols at top of /lib/syscalls.exp do not have a mode modifier and they
@@ -1347,7 +1319,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 	}
 
       obstack_1grow (o, '\0');
-      ++lineno;
+      ++linenumber;
 
       s = (char *) obstack_base (o);
       while (ISSPACE (*s))
@@ -1377,7 +1349,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 	  else if (*s == '(')
 	    einfo (_("%F%P:%s:%d: #! ([member]) is not supported "
 		     "in import files\n"),
-		   filename, lineno);
+		   filename, linenumber);
 	  else
 	    {
 	      char cs;
@@ -1403,7 +1375,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 		  impmember = "";
 		  if (cs != '\0')
 		    einfo (_("%P:%s:%d: warning: syntax error in import file\n"),
-			   filename, lineno);
+			   filename, linenumber);
 		}
 	      else
 		{
@@ -1415,7 +1387,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 		    *s = '\0';
 		  else
 		    einfo (_("%P:%s:%d: warning: syntax error in import file\n"),
-			   filename, lineno);
+			   filename, linenumber);
 		}
 	    }
 
@@ -1451,7 +1423,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 		  if (*se != '\0')
 		    einfo (_("%P:%s%d: warning: syntax error in "
 			     "import/export file\n"),
-			   filename, lineno);
+			   filename, linenumber);
 		}
 
 	      if (s != se)
@@ -1469,7 +1441,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 			{
 			  einfo (_("%P:%s:%d: warning: syntax error in "
 				   "import/export file\n"),
-				 filename, lineno);
+				 filename, linenumber);
 
 			}
 		    }
@@ -1503,7 +1475,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
 						address, imppath, impfile,
 						impmember, syscall_flag))
 		    einfo (_("%X%P:%s:%d: failed to import symbol %s: %E\n"),
-			   filename, lineno, symname);
+			   filename, linenumber, symname);
 		}
 	    }
 	}
@@ -1513,7 +1485,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
   if (obstack_object_size (o) > 0)
     {
       einfo (_("%P:%s:%d: warning: ignoring unterminated last line\n"),
-	     filename, lineno);
+	     filename, linenumber);
       obstack_free (o, obstack_base (o));
     }
 
diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em
index cf32cd4ffa3..0445e798e3d 100644
--- a/ld/emultempl/alphaelf.em
+++ b/ld/emultempl/alphaelf.em
@@ -111,12 +111,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_TASO		300
-#define OPTION_SECUREPLT	(OPTION_TASO + 1)
-#define OPTION_NO_SECUREPLT	(OPTION_SECUREPLT + 1)
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "taso", no_argument, NULL, OPTION_TASO },
   { "secureplt", no_argument, NULL, OPTION_SECUREPLT },
diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
index 7fb1826ebed..8f501aed12a 100644
--- a/ld/emultempl/armelf.em
+++ b/ld/emultempl/armelf.em
@@ -566,31 +566,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_THUMB_ENTRY		301
-#define OPTION_BE8			302
-#define OPTION_TARGET1_REL		303
-#define OPTION_TARGET1_ABS		304
-#define OPTION_TARGET2			305
-#define OPTION_FIX_V4BX			306
-#define OPTION_USE_BLX			307
-#define OPTION_VFP11_DENORM_FIX		308
-#define OPTION_NO_ENUM_SIZE_WARNING	309
-#define OPTION_PIC_VENEER		310
-#define OPTION_FIX_V4BX_INTERWORKING	311
-#define OPTION_STUBGROUP_SIZE		312
-#define OPTION_NO_WCHAR_SIZE_WARNING	313
-#define OPTION_FIX_CORTEX_A8		314
-#define OPTION_NO_FIX_CORTEX_A8		315
-#define OPTION_NO_MERGE_EXIDX_ENTRIES	316
-#define OPTION_FIX_ARM1176		317
-#define OPTION_NO_FIX_ARM1176		318
-#define OPTION_LONG_PLT			319
-#define OPTION_STM32L4XX_FIX		320
-#define OPTION_CMSE_IMPLIB		321
-#define OPTION_IN_IMPLIB		322
-'
-
 PARSE_AND_LIST_SHORTOPTS=p
 
 PARSE_AND_LIST_LONGOPTS='
diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em
index 3fe81004745..792be729299 100644
--- a/ld/emultempl/avrelf.em
+++ b/ld/emultempl/avrelf.em
@@ -232,15 +232,6 @@ avr_finish (void)
 EOF
 
 
-PARSE_AND_LIST_PROLOGUE='
-
-#define OPTION_NO_CALL_RET_REPLACEMENT 301
-#define OPTION_PMEM_WRAP_AROUND	       302
-#define OPTION_NO_STUBS		       303
-#define OPTION_DEBUG_STUBS	       304
-#define OPTION_DEBUG_RELAX	       305
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "no-call-ret-replacement", no_argument,
     NULL, OPTION_NO_CALL_RET_REPLACEMENT},
diff --git a/ld/emultempl/beos.em b/ld/emultempl/beos.em
index 844d4986c2d..29c386c61f8 100644
--- a/ld/emultempl/beos.em
+++ b/ld/emultempl/beos.em
@@ -70,22 +70,6 @@ gld${EMULATION_NAME}_before_parse (void)
 \f
 /* PE format extra command line options.  */
 
-/* Used for setting flags in the PE header. */
-#define OPTION_BASE_FILE		(300  + 1)
-#define OPTION_DLL			(OPTION_BASE_FILE + 1)
-#define OPTION_FILE_ALIGNMENT		(OPTION_DLL + 1)
-#define OPTION_IMAGE_BASE		(OPTION_FILE_ALIGNMENT + 1)
-#define OPTION_MAJOR_IMAGE_VERSION	(OPTION_IMAGE_BASE + 1)
-#define OPTION_MAJOR_OS_VERSION		(OPTION_MAJOR_IMAGE_VERSION + 1)
-#define OPTION_MAJOR_SUBSYSTEM_VERSION	(OPTION_MAJOR_OS_VERSION + 1)
-#define OPTION_MINOR_IMAGE_VERSION	(OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
-#define OPTION_MINOR_OS_VERSION		(OPTION_MINOR_IMAGE_VERSION + 1)
-#define OPTION_MINOR_SUBSYSTEM_VERSION	(OPTION_MINOR_OS_VERSION + 1)
-#define OPTION_SECTION_ALIGNMENT	(OPTION_MINOR_SUBSYSTEM_VERSION + 1)
-#define OPTION_STACK			(OPTION_SECTION_ALIGNMENT + 1)
-#define OPTION_SUBSYSTEM		(OPTION_STACK + 1)
-#define OPTION_HEAP			(OPTION_SUBSYSTEM + 1)
-
 static void
 gld${EMULATION_NAME}_add_options
   (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
diff --git a/ld/emultempl/bfin.em b/ld/emultempl/bfin.em
index eb13055d9ea..4b9be670c62 100644
--- a/ld/emultempl/bfin.em
+++ b/ld/emultempl/bfin.em
@@ -39,11 +39,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_CODE_IN_L1		300
-#define OPTION_DATA_IN_L1		301
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "code-in-l1", no_argument, NULL, OPTION_CODE_IN_L1 },
   { "data-in-l1", no_argument, NULL, OPTION_DATA_IN_L1 },
diff --git a/ld/emultempl/cskyelf.em b/ld/emultempl/cskyelf.em
index 82815e5e7a8..64a6ddf61f8 100644
--- a/ld/emultempl/cskyelf.em
+++ b/ld/emultempl/cskyelf.em
@@ -288,12 +288,6 @@ EOF
 
 # This code gets inserted into the generic elf32.sc linker script
 # and allows us to define our own command line switches.
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_BRANCH_STUB		301
-#define OPTION_NO_BRANCH_STUB		302
-#define OPTION_STUBGROUP_SIZE		303
-'
-
 PARSE_AND_LIST_LONGOPTS='
   {"branch-stub",	no_argument,       NULL, OPTION_BRANCH_STUB},
   {"no-branch-stub",	no_argument,       NULL, OPTION_NO_BRANCH_STUB},
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index 71cec19fdc6..f551225cdac 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -45,6 +45,7 @@ fragment <<EOF
 #include "ldexp.h"
 #include "ldlang.h"
 #include "ldfile.h"
+#include "ldlex.h"
 #include "ldemul.h"
 #include <ldgram.h>
 #include "elf-bfd.h"
@@ -556,28 +557,7 @@ EOF
 fi
 fi
 
-if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
 fragment <<EOF
- $PARSE_AND_LIST_PROLOGUE
-EOF
-fi
-
-fragment <<EOF
-
-enum elf_options
-{
-  OPTION_DISABLE_NEW_DTAGS = 400,
-  OPTION_ENABLE_NEW_DTAGS,
-  OPTION_GROUP,
-  OPTION_EH_FRAME_HDR,
-  OPTION_NO_EH_FRAME_HDR,
-  OPTION_EXCLUDE_LIBS,
-  OPTION_HASH_STYLE,
-  OPTION_BUILD_ID,
-  OPTION_PACKAGE_METADATA,
-  OPTION_AUDIT,
-  OPTION_COMPRESS_DEBUG
-};
 
 static void
 gld${EMULATION_NAME}_add_options
diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em
index 09db0cb07de..45257980831 100644
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -314,11 +314,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_MULTI_SUBSPACE		301
-#define OPTION_STUBGROUP_SIZE		(OPTION_MULTI_SUBSPACE + 1)
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "multi-subspace", no_argument, NULL, OPTION_MULTI_SUBSPACE },
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
diff --git a/ld/emultempl/ia64elf.em b/ld/emultempl/ia64elf.em
index a4657bcf3ac..a74849d1dbb 100644
--- a/ld/emultempl/ia64elf.em
+++ b/ld/emultempl/ia64elf.em
@@ -43,10 +43,6 @@ ia64elf_after_parse (void)
 
 EOF
 
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_ITANIUM			300
-'
-
 PARSE_AND_LIST_LONGOPTS='
     { "itanium", no_argument, NULL, OPTION_ITANIUM},
 '
diff --git a/ld/emultempl/m68hc1xelf.em b/ld/emultempl/m68hc1xelf.em
index 5355b0fc1c0..7aaa78a72d5 100644
--- a/ld/emultempl/m68hc1xelf.em
+++ b/ld/emultempl/m68hc1xelf.em
@@ -322,11 +322,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_NO_TRAMPOLINE		300
-#define OPTION_BANK_WINDOW		301
-'
-
 # The options are repeated below so that no abbreviations are allowed.
 # Otherwise -s matches stub-group-size
 PARSE_AND_LIST_LONGOPTS='
diff --git a/ld/emultempl/m68kelf.em b/ld/emultempl/m68kelf.em
index 0477f1eb23a..30e7d171f6a 100644
--- a/ld/emultempl/m68kelf.em
+++ b/ld/emultempl/m68kelf.em
@@ -200,10 +200,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_GOT	301
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "got", required_argument, NULL, OPTION_GOT},
 '
diff --git a/ld/emultempl/metagelf.em b/ld/emultempl/metagelf.em
index 81ab64c1110..10d3ff10def 100644
--- a/ld/emultempl/metagelf.em
+++ b/ld/emultempl/metagelf.em
@@ -282,10 +282,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_STUBGROUP_SIZE		301
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
 '
diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em
index f8fe4b9767e..3259f654b36 100644
--- a/ld/emultempl/mipself.em
+++ b/ld/emultempl/mipself.em
@@ -232,18 +232,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-enum
-  {
-    OPTION_INSN32 = 301,
-    OPTION_NO_INSN32,
-    OPTION_IGNORE_BRANCH_ISA,
-    OPTION_NO_IGNORE_BRANCH_ISA,
-    OPTION_COMPACT_BRANCHES,
-    OPTION_NO_COMPACT_BRANCHES
-  };
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "insn32", no_argument, NULL, OPTION_INSN32 },
   { "no-insn32", no_argument, NULL, OPTION_NO_INSN32 },
diff --git a/ld/emultempl/msp430.em b/ld/emultempl/msp430.em
index 92402b308a4..2d225317a25 100644
--- a/ld/emultempl/msp430.em
+++ b/ld/emultempl/msp430.em
@@ -39,6 +39,7 @@ fragment <<EOF
 #include "ldexp.h"
 #include "ldlang.h"
 #include "ldfile.h"
+#include "ldlex.h"
 #include "ldemul.h"
 #include "libiberty.h"
 #include <ldgram.h>
@@ -443,10 +444,6 @@ msp430_elf_after_open (void)
     bfd_map_over_sections (abfd, add_region_prefix, NULL);
 }
 
-#define OPTION_CODE_REGION		321
-#define OPTION_DATA_REGION		(OPTION_CODE_REGION + 1)
-#define OPTION_DISABLE_TRANS		(OPTION_CODE_REGION + 2)
-
 static void
 gld${EMULATION_NAME}_add_options
   (int ns, char **shortopts, int nl, struct option **longopts,
diff --git a/ld/emultempl/nds32elf.em b/ld/emultempl/nds32elf.em
index bde9e35de99..260e2a46e5d 100644
--- a/ld/emultempl/nds32elf.em
+++ b/ld/emultempl/nds32elf.em
@@ -132,18 +132,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_BASELINE			301
-#define OPTION_ELIM_GC_RELOCS		(OPTION_BASELINE + 1)
-#define OPTION_FP_AS_GP			(OPTION_BASELINE + 2)
-#define OPTION_NO_FP_AS_GP		(OPTION_BASELINE + 3)
-#define OPTION_REDUCE_FP_UPDATE		(OPTION_BASELINE + 4)
-#define OPTION_NO_REDUCE_FP_UPDATE	(OPTION_BASELINE + 5)
-#define OPTION_EXPORT_SYMBOLS		(OPTION_BASELINE + 6)
-#define OPTION_HYPER_RELAX		(OPTION_BASELINE + 7)
-#define OPTION_TLSDESC_TRAMPOLINE	(OPTION_BASELINE + 8)
-#define OPTION_NO_TLSDESC_TRAMPOLINE	(OPTION_BASELINE + 9)
-'
 PARSE_AND_LIST_LONGOPTS='
   { "mfp-as-gp", no_argument, NULL, OPTION_FP_AS_GP},
   { "mno-fp-as-gp", no_argument, NULL, OPTION_NO_FP_AS_GP},
diff --git a/ld/emultempl/nto.em b/ld/emultempl/nto.em
index de69e132348..7cda6650bc6 100644
--- a/ld/emultempl/nto.em
+++ b/ld/emultempl/nto.em
@@ -190,14 +190,6 @@ EOF
 # parse_args and list_options functions.
 #
 
-PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
-enum nto_options
-{
-  OPTION_STACK = 500,
-  OPTION_LAZY_STACK,
-};
-'
-
 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
   { "stack", required_argument, NULL, OPTION_STACK },
   { "lazy-stack", no_argument, NULL, OPTION_LAZY_STACK },
diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
index c6ed1110595..9ab5e6ef481 100644
--- a/ld/emultempl/pe.em
+++ b/ld/emultempl/pe.em
@@ -235,84 +235,6 @@ fragment <<EOF
 
 /* PE format extra command line options.  */
 
-/* Used for setting flags in the PE header.  */
-enum options
-{
-  OPTION_BASE_FILE = 300 + 1,
-  OPTION_DLL,
-  OPTION_FILE_ALIGNMENT,
-  OPTION_IMAGE_BASE,
-  OPTION_MAJOR_IMAGE_VERSION,
-  OPTION_MAJOR_OS_VERSION,
-  OPTION_MAJOR_SUBSYSTEM_VERSION,
-  OPTION_MINOR_IMAGE_VERSION,
-  OPTION_MINOR_OS_VERSION,
-  OPTION_MINOR_SUBSYSTEM_VERSION,
-  OPTION_SECTION_ALIGNMENT,
-  OPTION_STACK,
-  OPTION_SUBSYSTEM,
-  OPTION_HEAP,
-  OPTION_SUPPORT_OLD_CODE,
-  OPTION_OUT_DEF,
-  OPTION_EXPORT_ALL,
-  OPTION_EXCLUDE_SYMBOLS,
-  OPTION_EXCLUDE_ALL_SYMBOLS,
-  OPTION_KILL_ATS,
-  OPTION_STDCALL_ALIASES,
-  OPTION_ENABLE_STDCALL_FIXUP,
-  OPTION_DISABLE_STDCALL_FIXUP,
-  OPTION_THUMB_ENTRY,
-  OPTION_WARN_DUPLICATE_EXPORTS,
-  OPTION_IMP_COMPAT,
-  OPTION_ENABLE_AUTO_IMAGE_BASE,
-  OPTION_DISABLE_AUTO_IMAGE_BASE,
-  OPTION_DLL_SEARCH_PREFIX,
-  OPTION_NO_DEFAULT_EXCLUDES,
-  OPTION_DLL_ENABLE_AUTO_IMPORT,
-  OPTION_DLL_DISABLE_AUTO_IMPORT,
-  OPTION_ENABLE_EXTRA_PE_DEBUG,
-  OPTION_EXCLUDE_LIBS,
-  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
-  OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
-  OPTION_LARGE_ADDRESS_AWARE,
-  OPTION_DISABLE_LARGE_ADDRESS_AWARE,
-  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1,
-  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
-  OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
-  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
-  OPTION_NO_LEADING_UNDERSCORE,
-  OPTION_LEADING_UNDERSCORE,
-  OPTION_ENABLE_LONG_SECTION_NAMES,
-  OPTION_DISABLE_LONG_SECTION_NAMES,
-/* DLLCharacteristics flags.  */
-  OPTION_DYNAMIC_BASE,
-  OPTION_FORCE_INTEGRITY,
-  OPTION_NX_COMPAT,
-  OPTION_NO_ISOLATION,
-  OPTION_NO_SEH,
-  OPTION_NO_BIND,
-  OPTION_WDM_DRIVER,
-  OPTION_TERMINAL_SERVER_AWARE,
-/* Determinism.  */
-  OPTION_INSERT_TIMESTAMP,
-  OPTION_NO_INSERT_TIMESTAMP,
-  OPTION_BUILD_ID,
-#ifdef PDB_H
-  OPTION_PDB,
-#endif
-  OPTION_ENABLE_RELOC_SECTION,
-  OPTION_DISABLE_RELOC_SECTION,
-/* DLL Characteristics flags.  */
-  OPTION_DISABLE_DYNAMIC_BASE,
-  OPTION_DISABLE_FORCE_INTEGRITY,
-  OPTION_DISABLE_NX_COMPAT,
-  OPTION_DISABLE_NO_ISOLATION,
-  OPTION_DISABLE_NO_SEH,
-  OPTION_DISABLE_NO_BIND,
-  OPTION_DISABLE_WDM_DRIVER,
-  OPTION_DISABLE_TERMINAL_SERVER_AWARE
-};
-
 static void
 gld${EMULATION_NAME}_add_options
   (int ns ATTRIBUTE_UNUSED,
diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
index bd2ee2ede26..00c4ea9e15a 100644
--- a/ld/emultempl/pep.em
+++ b/ld/emultempl/pep.em
@@ -245,79 +245,6 @@ gld${EMULATION_NAME}_before_parse (void)
 \f
 /* PE format extra command line options.  */
 
-/* Used for setting flags in the PE header.  */
-enum options
-{
-  OPTION_BASE_FILE = 300 + 1,
-  OPTION_DLL,
-  OPTION_FILE_ALIGNMENT,
-  OPTION_IMAGE_BASE,
-  OPTION_MAJOR_IMAGE_VERSION,
-  OPTION_MAJOR_OS_VERSION,
-  OPTION_MAJOR_SUBSYSTEM_VERSION,
-  OPTION_MINOR_IMAGE_VERSION,
-  OPTION_MINOR_OS_VERSION,
-  OPTION_MINOR_SUBSYSTEM_VERSION,
-  OPTION_SECTION_ALIGNMENT,
-  OPTION_STACK,
-  OPTION_SUBSYSTEM,
-  OPTION_HEAP,
-  OPTION_SUPPORT_OLD_CODE,
-  OPTION_OUT_DEF,
-  OPTION_EXPORT_ALL,
-  OPTION_EXCLUDE_SYMBOLS,
-  OPTION_EXCLUDE_ALL_SYMBOLS,
-  OPTION_KILL_ATS,
-  OPTION_STDCALL_ALIASES,
-  OPTION_ENABLE_STDCALL_FIXUP,
-  OPTION_DISABLE_STDCALL_FIXUP,
-  OPTION_WARN_DUPLICATE_EXPORTS,
-  OPTION_IMP_COMPAT,
-  OPTION_ENABLE_AUTO_IMAGE_BASE,
-  OPTION_DISABLE_AUTO_IMAGE_BASE,
-  OPTION_DLL_SEARCH_PREFIX,
-  OPTION_NO_DEFAULT_EXCLUDES,
-  OPTION_DLL_ENABLE_AUTO_IMPORT,
-  OPTION_DLL_DISABLE_AUTO_IMPORT,
-  OPTION_ENABLE_EXTRA_PE_DEBUG,
-  OPTION_EXCLUDE_LIBS,
-  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
-  OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
-  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
-  OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
-  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
-  OPTION_NO_LEADING_UNDERSCORE,
-  OPTION_LEADING_UNDERSCORE,
-  OPTION_ENABLE_LONG_SECTION_NAMES,
-  OPTION_DISABLE_LONG_SECTION_NAMES,
-  OPTION_HIGH_ENTROPY_VA,
-  OPTION_DYNAMIC_BASE,
-  OPTION_FORCE_INTEGRITY,
-  OPTION_NX_COMPAT,
-  OPTION_NO_ISOLATION,
-  OPTION_NO_SEH,
-  OPTION_NO_BIND,
-  OPTION_WDM_DRIVER,
-  OPTION_INSERT_TIMESTAMP,
-  OPTION_NO_INSERT_TIMESTAMP,
-  OPTION_TERMINAL_SERVER_AWARE,
-  OPTION_BUILD_ID,
-#ifdef PDB_H
-  OPTION_PDB,
-#endif
-  OPTION_ENABLE_RELOC_SECTION,
-  OPTION_DISABLE_RELOC_SECTION,
-  OPTION_DISABLE_HIGH_ENTROPY_VA,
-  OPTION_DISABLE_DYNAMIC_BASE,
-  OPTION_DISABLE_FORCE_INTEGRITY,
-  OPTION_DISABLE_NX_COMPAT,
-  OPTION_DISABLE_NO_ISOLATION,
-  OPTION_DISABLE_NO_SEH,
-  OPTION_DISABLE_NO_BIND,
-  OPTION_DISABLE_WDM_DRIVER,
-  OPTION_DISABLE_TERMINAL_SERVER_AWARE
-};
-
 static void
 gld${EMULATION_NAME}_add_options
   (int ns ATTRIBUTE_UNUSED,
diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
index 0730a05e75b..12476f44fcf 100644
--- a/ld/emultempl/ppc32elf.em
+++ b/ld/emultempl/ppc32elf.em
@@ -264,26 +264,6 @@ fi
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
-enum ppc32_opt
-{
-  OPTION_NO_TLS_OPT = 321,
-  OPTION_NO_TLS_GET_ADDR_OPT,
-  OPTION_NEW_PLT,
-  OPTION_OLD_PLT,
-  OPTION_PLT_ALIGN,
-  OPTION_NO_PLT_ALIGN,
-  OPTION_NO_INLINE_OPT,
-  OPTION_OLD_GOT,
-  OPTION_STUBSYMS,
-  OPTION_NO_STUBSYMS,
-  OPTION_PPC476_WORKAROUND,
-  OPTION_NO_PPC476_WORKAROUND,
-  OPTION_NO_PICFIXUP,
-  OPTION_VLE_RELOC_FIXUP
-};
-'
-
 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
   { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
   { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
index 533caed2fc2..23905e9bc88 100644
--- a/ld/emultempl/ppc64elf.em
+++ b/ld/emultempl/ppc64elf.em
@@ -684,41 +684,6 @@ fi
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
-enum ppc64_opt
-{
-  OPTION_STUBGROUP_SIZE = 321,
-  OPTION_PLT_STATIC_CHAIN,
-  OPTION_NO_PLT_STATIC_CHAIN,
-  OPTION_PLT_THREAD_SAFE,
-  OPTION_NO_PLT_THREAD_SAFE,
-  OPTION_PLT_ALIGN,
-  OPTION_NO_PLT_ALIGN,
-  OPTION_PLT_LOCALENTRY,
-  OPTION_NO_PLT_LOCALENTRY,
-  OPTION_POWER10_STUBS,
-  OPTION_NO_POWER10_STUBS,
-  OPTION_NO_PCREL_OPT,
-  OPTION_STUBSYMS,
-  OPTION_NO_STUBSYMS,
-  OPTION_SAVRES,
-  OPTION_NO_SAVRES,
-  OPTION_DOTSYMS,
-  OPTION_NO_DOTSYMS,
-  OPTION_NO_TLS_OPT,
-  OPTION_TLS_GET_ADDR_OPT,
-  OPTION_NO_TLS_GET_ADDR_OPT,
-  OPTION_TLS_GET_ADDR_REGSAVE,
-  OPTION_NO_TLS_GET_ADDR_REGSAVE,
-  OPTION_NO_OPD_OPT,
-  OPTION_NO_INLINE_OPT,
-  OPTION_NO_TOC_OPT,
-  OPTION_NO_MULTI_TOC,
-  OPTION_NO_TOC_SORT,
-  OPTION_NON_OVERLAPPING_OPD
-};
-'
-
 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
   { "plt-static-chain", no_argument, NULL, OPTION_PLT_STATIC_CHAIN },
diff --git a/ld/emultempl/riscvelf.em b/ld/emultempl/riscvelf.em
index fe53b2a7a71..afc43ed55dc 100644
--- a/ld/emultempl/riscvelf.em
+++ b/ld/emultempl/riscvelf.em
@@ -31,16 +31,6 @@ EOF
 
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.  */
-PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
-enum risccv_opt
-{
-  OPTION_RELAX_GP = 321,
-  OPTION_NO_RELAX_GP,
-  OPTION_CHECK_ULEB128,
-  OPTION_NO_CHECK_ULEB128,
-};
-'
-
 PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
     { "relax-gp", no_argument, NULL, OPTION_RELAX_GP },
     { "no-relax-gp", no_argument, NULL, OPTION_NO_RELAX_GP },
diff --git a/ld/emultempl/rxelf.em b/ld/emultempl/rxelf.em
index 3b8df6ef665..cc76a274a26 100644
--- a/ld/emultempl/rxelf.em
+++ b/ld/emultempl/rxelf.em
@@ -45,13 +45,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_NO_FLAG_MISMATCH_WARNINGS	301
-#define OPTION_IGNORE_LMA			302
-#define OPTION_NO_IGNORE_LMA			303
-#define OPTION_FLAG_MISMATCH_WARNINGS		304
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "no-flag-mismatch-warnings", no_argument, NULL, OPTION_NO_FLAG_MISMATCH_WARNINGS},
   { "flag-mismatch-warnings", no_argument, NULL, OPTION_FLAG_MISMATCH_WARNINGS},
diff --git a/ld/emultempl/s390.em b/ld/emultempl/s390.em
index 11e7f19bb52..179cbbd98d7 100644
--- a/ld/emultempl/s390.em
+++ b/ld/emultempl/s390.em
@@ -42,10 +42,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_PGSTE	301
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "s390-pgste", no_argument, NULL, OPTION_PGSTE},
 '
diff --git a/ld/emultempl/scoreelf.em b/ld/emultempl/scoreelf.em
index 6238b5e2a19..499a583decd 100644
--- a/ld/emultempl/scoreelf.em
+++ b/ld/emultempl/scoreelf.em
@@ -76,7 +76,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE=''
 PARSE_AND_LIST_SHORTOPTS=
 PARSE_AND_LIST_LONGOPTS=''
 PARSE_AND_LIST_OPTIONS=''
diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em
index cc39435cc3b..2ff41b1e46e 100644
--- a/ld/emultempl/spuelf.em
+++ b/ld/emultempl/spuelf.em
@@ -589,30 +589,6 @@ fi
 # Define some shell vars to insert bits of code into the standard elf
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_SPU_PLUGIN		301
-#define OPTION_SPU_NO_OVERLAYS		(OPTION_SPU_PLUGIN + 1)
-#define OPTION_SPU_COMPACT_STUBS	(OPTION_SPU_NO_OVERLAYS + 1)
-#define OPTION_SPU_STUB_SYMS		(OPTION_SPU_COMPACT_STUBS + 1)
-#define OPTION_SPU_NON_OVERLAY_STUBS	(OPTION_SPU_STUB_SYMS + 1)
-#define OPTION_SPU_LOCAL_STORE		(OPTION_SPU_NON_OVERLAY_STUBS + 1)
-#define OPTION_SPU_STACK_ANALYSIS	(OPTION_SPU_LOCAL_STORE + 1)
-#define OPTION_SPU_STACK_SYMS		(OPTION_SPU_STACK_ANALYSIS + 1)
-#define OPTION_SPU_AUTO_OVERLAY		(OPTION_SPU_STACK_SYMS + 1)
-#define OPTION_SPU_AUTO_RELINK		(OPTION_SPU_AUTO_OVERLAY + 1)
-#define OPTION_SPU_OVERLAY_RODATA	(OPTION_SPU_AUTO_RELINK + 1)
-#define OPTION_SPU_SOFT_ICACHE		(OPTION_SPU_OVERLAY_RODATA + 1)
-#define OPTION_SPU_LINE_SIZE		(OPTION_SPU_SOFT_ICACHE + 1)
-#define OPTION_SPU_NUM_LINES		(OPTION_SPU_LINE_SIZE + 1)
-#define OPTION_SPU_LRLIVE		(OPTION_SPU_NUM_LINES + 1)
-#define OPTION_SPU_NON_IA_TEXT		(OPTION_SPU_LRLIVE + 1)
-#define OPTION_SPU_FIXED_SPACE		(OPTION_SPU_NON_IA_TEXT + 1)
-#define OPTION_SPU_RESERVED_SPACE	(OPTION_SPU_FIXED_SPACE + 1)
-#define OPTION_SPU_EXTRA_STACK		(OPTION_SPU_RESERVED_SPACE + 1)
-#define OPTION_SPU_NO_AUTO_OVERLAY	(OPTION_SPU_EXTRA_STACK + 1)
-#define OPTION_SPU_EMIT_FIXUPS		(OPTION_SPU_NO_AUTO_OVERLAY + 1)
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "plugin", no_argument, NULL, OPTION_SPU_PLUGIN },
   { "soft-icache", no_argument, NULL, OPTION_SPU_SOFT_ICACHE },
diff --git a/ld/emultempl/tic6xdsbt.em b/ld/emultempl/tic6xdsbt.em
index 524e3f73eec..8140ef9c218 100644
--- a/ld/emultempl/tic6xdsbt.em
+++ b/ld/emultempl/tic6xdsbt.em
@@ -165,12 +165,6 @@ EOF
 
 # This code gets inserted into the generic elf32.sc linker script
 # and allows us to define our own command line switches.
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_DSBT_INDEX		300
-#define OPTION_DSBT_SIZE		301
-#define OPTION_NO_MERGE_EXIDX_ENTRIES   302
-'
-
 PARSE_AND_LIST_LONGOPTS='
   {"dsbt-index", required_argument, NULL, OPTION_DSBT_INDEX},
   {"dsbt-size", required_argument, NULL, OPTION_DSBT_SIZE},
diff --git a/ld/emultempl/ticoff.em b/ld/emultempl/ticoff.em
index 4b048bef8f9..fb6cf3a0c2e 100644
--- a/ld/emultempl/ticoff.em
+++ b/ld/emultempl/ticoff.em
@@ -40,12 +40,12 @@ fragment <<EOF
 #include "ldexp.h"
 #include "ldlang.h"
 #include "ldfile.h"
+#include "ldlex.h"
 #include "ldemul.h"
 
 static int coff_version;
 
 /* TI COFF extra command line options */
-#define OPTION_COFF_FORMAT		(300 + 1)
 
 static void
 gld${EMULATION_NAME}_add_options
diff --git a/ld/emultempl/vms.em b/ld/emultempl/vms.em
index 67e9ea641eb..8baacb35a13 100644
--- a/ld/emultempl/vms.em
+++ b/ld/emultempl/vms.em
@@ -24,6 +24,7 @@
 fragment <<EOF
 #include "libiberty.h"
 #include "getopt.h"
+#include "ldlex.h"
 
 static void
 gld${EMULATION_NAME}_before_parse (void)
@@ -125,7 +126,6 @@ vms_place_orphan (asection *s,
 }
 
 /* VMS specific options.  */
-#define OPTION_IDENTIFICATION		(300  + 1)
 
 static void
 gld${EMULATION_NAME}_add_options
diff --git a/ld/emultempl/vxworks.em b/ld/emultempl/vxworks.em
index 00cfeabad3a..307049cfd3a 100644
--- a/ld/emultempl/vxworks.em
+++ b/ld/emultempl/vxworks.em
@@ -55,12 +55,6 @@ vxworks_after_open (void)
 
 EOF
 
-PARSE_AND_LIST_PROLOGUE=$PARSE_AND_LIST_PROLOGUE'
-enum {
-  OPTION_FORCE_DYNAMIC = 501
-};
-'
-
 PARSE_AND_LIST_LONGOPTS=$PARSE_AND_LIST_LONGOPTS'
   {"force-dynamic", no_argument, NULL, OPTION_FORCE_DYNAMIC},
 '
diff --git a/ld/emultempl/xtensaelf.em b/ld/emultempl/xtensaelf.em
index 512935392a9..3508eb7f503 100644
--- a/ld/emultempl/xtensaelf.em
+++ b/ld/emultempl/xtensaelf.em
@@ -39,6 +39,9 @@ static void xtensa_colocate_output_literals (lang_statement_union_type *);
 static void xtensa_strip_inconsistent_linkonce_sections
   (lang_statement_list_type *);
 
+extern int elf32xtensa_size_opt;
+extern int elf32xtensa_no_literal_movement;
+extern int elf32xtensa_abi;
 
 /* This number is irrelevant until we turn on use_literal_pages */
 static bfd_vma xtensa_page_power = 12; /* 4K pages.  */
@@ -1922,17 +1925,6 @@ EOF
 # Define some shell vars to insert bits of code into the standard ELF
 # parse_args and list_options functions.
 #
-PARSE_AND_LIST_PROLOGUE='
-#define OPTION_OPT_SIZEOPT              (300)
-#define OPTION_LITERAL_MOVEMENT		(OPTION_OPT_SIZEOPT + 1)
-#define OPTION_NO_LITERAL_MOVEMENT	(OPTION_LITERAL_MOVEMENT + 1)
-#define OPTION_ABI_WINDOWED		(OPTION_NO_LITERAL_MOVEMENT + 1)
-#define OPTION_ABI_CALL0		(OPTION_ABI_WINDOWED + 1)
-extern int elf32xtensa_size_opt;
-extern int elf32xtensa_no_literal_movement;
-extern int elf32xtensa_abi;
-'
-
 PARSE_AND_LIST_LONGOPTS='
   { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
   { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 161a9d4d8dc..e5ac2fa7fca 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -181,6 +181,292 @@ enum option_values
   OPTION_DISABLE_LINKER_VERSION,
   OPTION_REMAP_INPUTS,
   OPTION_REMAP_INPUTS_FILE,
+  /* Used by emultempl/elf.em, emultempl/pe.em and emultempl/pep.em.  */
+  OPTION_BUILD_ID,
+  OPTION_EXCLUDE_LIBS,
+  /* Used by emulparams/elf32mcore.sh, emultempl/beos.em, emultempl/pe.em
+     and emultempl/pep.em.  */
+  OPTION_BASE_FILE,
+  /* Used by emultempl/ppc32elf.em and emultempl/ppc64elf.em.  */
+  OPTION_NO_INLINE_OPT,
+  OPTION_NO_PLT_ALIGN,
+  OPTION_NO_STUBSYMS,
+  OPTION_NO_TLS_GET_ADDR_OPT,
+  OPTION_NO_TLS_OPT,
+  OPTION_PLT_ALIGN,
+  OPTION_STUBSYMS,
+  /* Used by emultempl/armelf.em and emultempl/tic6xdsbt.em.  */
+  OPTION_NO_MERGE_EXIDX_ENTRIES,
+  /* Used by emultempl/aarch64elf.em and emultempl/armelf.em.  */
+  OPTION_PIC_VENEER,
+  OPTION_NO_ENUM_SIZE_WARNING,
+  OPTION_NO_WCHAR_SIZE_WARNING,
+  /* Used by emultempl/armelf.em and emultempl/pe.em.  */
+  OPTION_THUMB_ENTRY,
+  /* Used by emultempl/beos.em, emultempl/nto.em, emultempl/pe.em and
+     emultempl/pep.em.  */
+  OPTION_STACK,
+  /* Used by emultempl/aarch64elf.em, emultempl/armelf.em,
+     emultempl/cskyelf.em, emultempl/hppaelf.em, emultempl/metagelf.em
+     and emultempl/ppc64elf.em.  */
+  OPTION_STUBGROUP_SIZE,
+  /* Used by emulparams/plt_unwind.sh.  */
+  OPTION_LD_GENERATED_UNWIND_INFO,
+  OPTION_NO_LD_GENERATED_UNWIND_INFO,
+  /* Used by emultempl/aarch64elf.em.  */
+  OPTION_FIX_ERRATUM_835769,
+  OPTION_FIX_ERRATUM_843419,
+  OPTION_NO_APPLY_DYNAMIC_RELOCS,
+  /* Used by emultempl/aix.em.  */
+  OPTION_AUTOIMP,
+  OPTION_ERNOTOK,
+  OPTION_EROK,
+  OPTION_EXPALL,
+  OPTION_EXPFULL,
+  OPTION_EXPORT,
+  OPTION_IMPORT,
+  OPTION_INITFINI,
+  OPTION_LOADMAP,
+  OPTION_MAXDATA,
+  OPTION_MAXSTACK,
+  OPTION_MODTYPE,
+  OPTION_NOAUTOIMP,
+  OPTION_NOEXPALL,
+  OPTION_NOEXPFULL,
+  OPTION_NOSTRCMPCT,
+  OPTION_PD,
+  OPTION_PT,
+  OPTION_STRCMPCT,
+  OPTION_UNIX,
+  OPTION_32,
+  OPTION_64,
+  OPTION_LIBPATH,
+  OPTION_NOLIBPATH,
+  /* Used by emultempl/alphaelf.em.  */
+  OPTION_TASO,
+  OPTION_SECUREPLT,
+  OPTION_NO_SECUREPLT,
+  /* Used by emultempl/armelf.em.  */
+  OPTION_BE8,
+  OPTION_TARGET1_REL,
+  OPTION_TARGET1_ABS,
+  OPTION_TARGET2,
+  OPTION_FIX_V4BX,
+  OPTION_USE_BLX,
+  OPTION_VFP11_DENORM_FIX,
+  OPTION_FIX_V4BX_INTERWORKING,
+  OPTION_FIX_CORTEX_A8,
+  OPTION_NO_FIX_CORTEX_A8,
+  OPTION_FIX_ARM1176,
+  OPTION_NO_FIX_ARM1176,
+  OPTION_LONG_PLT,
+  OPTION_STM32L4XX_FIX,
+  OPTION_CMSE_IMPLIB,
+  OPTION_IN_IMPLIB,
+  /* Used by emultempl/avrelf.em.  */
+  OPTION_NO_CALL_RET_REPLACEMENT,
+  OPTION_PMEM_WRAP_AROUND,
+  OPTION_NO_STUBS,
+  OPTION_DEBUG_STUBS,
+  OPTION_DEBUG_RELAX,
+  /* Used by emultempl/bfin.em.  */
+  OPTION_CODE_IN_L1,
+  OPTION_DATA_IN_L1,
+  /* Used by emultempl/cskyelf.em.  */
+  OPTION_BRANCH_STUB,
+  OPTION_NO_BRANCH_STUB,
+  /* Used by emultempl/elf.em.  */
+  OPTION_DISABLE_NEW_DTAGS,
+  OPTION_ENABLE_NEW_DTAGS,
+  OPTION_GROUP,
+  OPTION_EH_FRAME_HDR,
+  OPTION_NO_EH_FRAME_HDR,
+  OPTION_HASH_STYLE,
+  OPTION_PACKAGE_METADATA,
+  OPTION_AUDIT,
+  OPTION_COMPRESS_DEBUG,
+  /* Used by emultempl/hppaelf.em.  */
+  OPTION_MULTI_SUBSPACE,
+  /* Used by emultempl/ia64elf.em.  */
+  OPTION_ITANIUM,
+  /* Used by emultempl/m68hc1xelf.em.  */
+  OPTION_NO_TRAMPOLINE,
+  OPTION_BANK_WINDOW,
+  /* Used by emultempl/m68kelf.em.  */
+  OPTION_GOT,
+  /* Used by emultempl/mipself.em.  */
+  OPTION_INSN32,
+  OPTION_NO_INSN32,
+  OPTION_IGNORE_BRANCH_ISA,
+  OPTION_NO_IGNORE_BRANCH_ISA,
+  OPTION_COMPACT_BRANCHES,
+  OPTION_NO_COMPACT_BRANCHES,
+  /* Used by emultempl/msp430.em.  */
+  OPTION_CODE_REGION,
+  OPTION_DATA_REGION,
+  OPTION_DISABLE_TRANS,
+  /* Used by emultempl/nds32elf.em.  */
+  OPTION_BASELINE,
+  OPTION_ELIM_GC_RELOCS,
+  OPTION_FP_AS_GP,
+  OPTION_NO_FP_AS_GP,
+  OPTION_REDUCE_FP_UPDATE,
+  OPTION_NO_REDUCE_FP_UPDATE,
+  OPTION_EXPORT_SYMBOLS,
+  OPTION_HYPER_RELAX,
+  OPTION_TLSDESC_TRAMPOLINE,
+  OPTION_NO_TLSDESC_TRAMPOLINE,
+  /* Used by emultempl/nto.em.  */
+  OPTION_LAZY_STACK,
+  /* Used by emultempl/pe.em, emultempl/pep.em and emultempl/beos.em.  */
+  OPTION_DLL,
+  OPTION_FILE_ALIGNMENT,
+  OPTION_IMAGE_BASE,
+  OPTION_MAJOR_IMAGE_VERSION,
+  OPTION_MAJOR_OS_VERSION,
+  OPTION_MAJOR_SUBSYSTEM_VERSION,
+  OPTION_MINOR_IMAGE_VERSION,
+  OPTION_MINOR_OS_VERSION,
+  OPTION_MINOR_SUBSYSTEM_VERSION,
+  OPTION_SECTION_ALIGNMENT,
+  OPTION_SUBSYSTEM,
+  OPTION_HEAP,
+  OPTION_SUPPORT_OLD_CODE,
+  OPTION_OUT_DEF,
+  OPTION_EXPORT_ALL,
+  OPTION_EXCLUDE_SYMBOLS,
+  OPTION_EXCLUDE_ALL_SYMBOLS,
+  OPTION_KILL_ATS,
+  OPTION_STDCALL_ALIASES,
+  OPTION_ENABLE_STDCALL_FIXUP,
+  OPTION_DISABLE_STDCALL_FIXUP,
+  OPTION_WARN_DUPLICATE_EXPORTS,
+  OPTION_IMP_COMPAT,
+  OPTION_ENABLE_AUTO_IMAGE_BASE,
+  OPTION_DISABLE_AUTO_IMAGE_BASE,
+  OPTION_DLL_SEARCH_PREFIX,
+  OPTION_NO_DEFAULT_EXCLUDES,
+  OPTION_DLL_ENABLE_AUTO_IMPORT,
+  OPTION_DLL_DISABLE_AUTO_IMPORT,
+  OPTION_ENABLE_EXTRA_PE_DEBUG,
+  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
+  OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
+  OPTION_LARGE_ADDRESS_AWARE,
+  OPTION_DISABLE_LARGE_ADDRESS_AWARE,
+  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1,
+  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
+  OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
+  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
+  OPTION_NO_LEADING_UNDERSCORE,
+  OPTION_LEADING_UNDERSCORE,
+  OPTION_ENABLE_LONG_SECTION_NAMES,
+  OPTION_DISABLE_LONG_SECTION_NAMES,
+  /* DLLCharacteristics flags.  */
+  OPTION_DYNAMIC_BASE,
+  OPTION_FORCE_INTEGRITY,
+  OPTION_NX_COMPAT,
+  OPTION_NO_ISOLATION,
+  OPTION_NO_SEH,
+  OPTION_NO_BIND,
+  OPTION_WDM_DRIVER,
+  OPTION_TERMINAL_SERVER_AWARE,
+  /* Determinism.  */
+  OPTION_INSERT_TIMESTAMP,
+  OPTION_NO_INSERT_TIMESTAMP,
+  OPTION_PDB,
+  OPTION_ENABLE_RELOC_SECTION,
+  OPTION_DISABLE_RELOC_SECTION,
+  /* DLL Characteristics flags.  */
+  OPTION_DISABLE_DYNAMIC_BASE,
+  OPTION_DISABLE_FORCE_INTEGRITY,
+  OPTION_DISABLE_NX_COMPAT,
+  OPTION_DISABLE_NO_ISOLATION,
+  OPTION_DISABLE_NO_SEH,
+  OPTION_DISABLE_NO_BIND,
+  OPTION_DISABLE_WDM_DRIVER,
+  OPTION_DISABLE_TERMINAL_SERVER_AWARE,
+  /* Used by emultempl/pep.em.  */
+  OPTION_DISABLE_HIGH_ENTROPY_VA,
+  OPTION_HIGH_ENTROPY_VA,
+  /* Used by emultempl/ppc32elf.em.  */
+  OPTION_NEW_PLT,
+  OPTION_OLD_PLT,
+  OPTION_OLD_GOT,
+  OPTION_PPC476_WORKAROUND,
+  OPTION_NO_PPC476_WORKAROUND,
+  OPTION_NO_PICFIXUP,
+  OPTION_VLE_RELOC_FIXUP,
+  /* Used by emultempl/ppc64elf.em.  */
+  OPTION_PLT_STATIC_CHAIN,
+  OPTION_NO_PLT_STATIC_CHAIN,
+  OPTION_PLT_THREAD_SAFE,
+  OPTION_NO_PLT_THREAD_SAFE,
+  OPTION_PLT_LOCALENTRY,
+  OPTION_NO_PLT_LOCALENTRY,
+  OPTION_POWER10_STUBS,
+  OPTION_NO_POWER10_STUBS,
+  OPTION_NO_PCREL_OPT,
+  OPTION_SAVRES,
+  OPTION_NO_SAVRES,
+  OPTION_DOTSYMS,
+  OPTION_NO_DOTSYMS,
+  OPTION_TLS_GET_ADDR_OPT,
+  OPTION_TLS_GET_ADDR_REGSAVE,
+  OPTION_NO_TLS_GET_ADDR_REGSAVE,
+  OPTION_NO_OPD_OPT,
+  OPTION_NO_TOC_OPT,
+  OPTION_NO_MULTI_TOC,
+  OPTION_NO_TOC_SORT,
+  OPTION_NON_OVERLAPPING_OPD,
+  /* Used by emultempl/riscvelf.em.  */
+  OPTION_RELAX_GP,
+  OPTION_NO_RELAX_GP,
+  OPTION_CHECK_ULEB128,
+  OPTION_NO_CHECK_ULEB128,
+  /* Used by emultempl/rxelf.em.  */
+  OPTION_NO_FLAG_MISMATCH_WARNINGS,
+  OPTION_IGNORE_LMA,
+  OPTION_NO_IGNORE_LMA,
+  OPTION_FLAG_MISMATCH_WARNINGS,
+  /* Used by emultempl/s390.em.  */
+  OPTION_PGSTE,
+  /* Used by emultempl/spuelf.em.  */
+  OPTION_SPU_PLUGIN,
+  OPTION_SPU_NO_OVERLAYS,
+  OPTION_SPU_COMPACT_STUBS,
+  OPTION_SPU_STUB_SYMS,
+  OPTION_SPU_NON_OVERLAY_STUBS,
+  OPTION_SPU_LOCAL_STORE,
+  OPTION_SPU_STACK_ANALYSIS,
+  OPTION_SPU_STACK_SYMS,
+  OPTION_SPU_AUTO_OVERLAY,
+  OPTION_SPU_AUTO_RELINK,
+  OPTION_SPU_OVERLAY_RODATA,
+  OPTION_SPU_SOFT_ICACHE,
+  OPTION_SPU_LINE_SIZE,
+  OPTION_SPU_NUM_LINES,
+  OPTION_SPU_LRLIVE,
+  OPTION_SPU_NON_IA_TEXT,
+  OPTION_SPU_FIXED_SPACE,
+  OPTION_SPU_RESERVED_SPACE,
+  OPTION_SPU_EXTRA_STACK,
+  OPTION_SPU_NO_AUTO_OVERLAY,
+  OPTION_SPU_EMIT_FIXUPS,
+  /* Used by emultempl/tic6xdsbt.em.  */
+  OPTION_DSBT_INDEX,
+  OPTION_DSBT_SIZE,
+  /* Used by emultempl/ticoff.em.  */
+  OPTION_COFF_FORMAT,
+  /* Used by emultempl/vms.em.  */
+  OPTION_IDENTIFICATION,
+  /* Used by emultempl/vxworks.em.  */
+  OPTION_FORCE_DYNAMIC,
+  /* Used by emultempl/xtensaelf.em.  */
+  OPTION_OPT_SIZEOPT,
+  OPTION_LITERAL_MOVEMENT,
+  OPTION_NO_LITERAL_MOVEMENT,
+  OPTION_ABI_WINDOWED,
+  OPTION_ABI_CALL0,
 };
 
 /* The initial parser states.  */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ld: Put all emulation options in ldlex.h
  2024-01-17 15:46 [PATCH] ld: Put all emulation options in ldlex.h H.J. Lu
@ 2024-01-18 15:31 ` H.J. Lu
  2024-01-19 10:37   ` Nick Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: H.J. Lu @ 2024-01-18 15:31 UTC (permalink / raw)
  To: binutils, Nick Clifton, Alan Modra, Jan Beulich

On Wed, Jan 17, 2024 at 7:46 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> For each command line option, parse_args() calls ldemul_parse_args()
> to check if the command line option is an emulation option.  But when
> there is a conflict between the emulation option value and the default
> option value, the default command line option will be processed as if
> the emulation option is used.  Remove PARSE_AND_LIST_PROLOGUE and move
> all emulation options to ldlex.h to avoid conflicts.
>
>         PR ld/31247
>         * ldlex.h (option_values): Add all emulation options.
>         * emulparams/elf32mcore.sh (PARSE_AND_LIST_PROLOGUE): Removed.
>         * emulparams/plt_unwind.sh (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/aarch64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/alphaelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/armelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/avrelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/bfin.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/cskyelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/hppaelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/ia64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/m68hc1xelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/m68kelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/metagelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/mipself.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/nds32elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/nto.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/ppc32elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/ppc64elf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/riscvelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/rxelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/s390.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/scoreelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/spuelf.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/tic6xdsbt.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/vxworks.em (PARSE_AND_LIST_PROLOGUE): Likewise.
>         * emultempl/aix.em: Include "ldlex.h".
>         (OPTION_XXX): Removed.
>         (gld${EMULATION_NAME}_read_file): Replace lineno with linenumber.
>         * emultempl/beos.em (OPTION_XXX): Removed.
>         * emultempl/elf.em: Include "ldlex.h".
>         Don't check PARSE_AND_LIST_PROLOGUE.
>         (OPTION_XXX): Removed.
>         * emultempl/msp430.em: Include "ldlex.h".
>         (OPTION_XXX): Removed.
>         * emultempl/pe.em (OPTION_XXX): Removed.
>         * emultempl/pep.em (OPTION_XXX): Likewise.
>         * emultempl/ticoff.em: Include "ldlex.h".
>         (OPTION_XXX): Removed.
>         * emultempl/vms.em: Include "ldlex.h".
>         (OPTION_XXX): Removed.
>         * emultempl/xtensaelf.em (elf32xtensa_size_opt,
>         elf32xtensa_no_literal_movement, elf32xtensa_abi): Moved out of
>         PARSE_AND_LIST_PROLOGUE.
>         (PARSE_AND_LIST_PROLOGUE): Removed.
> ---
>  ld/emulparams/elf32mcore.sh |   4 -
>  ld/emulparams/plt_unwind.sh |   5 -
>  ld/emultempl/aarch64elf.em  |  10 --
>  ld/emultempl/aix.em         |  50 ++-----
>  ld/emultempl/alphaelf.em    |   6 -
>  ld/emultempl/armelf.em      |  25 ----
>  ld/emultempl/avrelf.em      |   9 --
>  ld/emultempl/beos.em        |  16 --
>  ld/emultempl/bfin.em        |   5 -
>  ld/emultempl/cskyelf.em     |   6 -
>  ld/emultempl/elf.em         |  22 +--
>  ld/emultempl/hppaelf.em     |   5 -
>  ld/emultempl/ia64elf.em     |   4 -
>  ld/emultempl/m68hc1xelf.em  |   5 -
>  ld/emultempl/m68kelf.em     |   4 -
>  ld/emultempl/metagelf.em    |   4 -
>  ld/emultempl/mipself.em     |  12 --
>  ld/emultempl/msp430.em      |   5 +-
>  ld/emultempl/nds32elf.em    |  12 --
>  ld/emultempl/nto.em         |   8 -
>  ld/emultempl/pe.em          |  78 ----------
>  ld/emultempl/pep.em         |  73 ---------
>  ld/emultempl/ppc32elf.em    |  20 ---
>  ld/emultempl/ppc64elf.em    |  35 -----
>  ld/emultempl/riscvelf.em    |  10 --
>  ld/emultempl/rxelf.em       |   7 -
>  ld/emultempl/s390.em        |   4 -
>  ld/emultempl/scoreelf.em    |   1 -
>  ld/emultempl/spuelf.em      |  24 ---
>  ld/emultempl/tic6xdsbt.em   |   6 -
>  ld/emultempl/ticoff.em      |   2 +-
>  ld/emultempl/vms.em         |   2 +-
>  ld/emultempl/vxworks.em     |   6 -
>  ld/emultempl/xtensaelf.em   |  14 +-
>  ld/ldlex.h                  | 286 ++++++++++++++++++++++++++++++++++++
>  35 files changed, 304 insertions(+), 481 deletions(-)
>
> diff --git a/ld/emulparams/elf32mcore.sh b/ld/emulparams/elf32mcore.sh
> index 88a8cb6e70b..7d433fc0f2d 100644
> --- a/ld/emulparams/elf32mcore.sh
> +++ b/ld/emulparams/elf32mcore.sh
> @@ -30,10 +30,6 @@ TEMPLATE_NAME=elf
>
>  # This code gets inserted into the generic elf32.sc linker script
>  # and allows us to define our own command line switches.
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_BASE_FILE               300
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    {"base-file", required_argument, NULL, OPTION_BASE_FILE},
>  '
> diff --git a/ld/emulparams/plt_unwind.sh b/ld/emulparams/plt_unwind.sh
> index ab16156415e..beb67260443 100644
> --- a/ld/emulparams/plt_unwind.sh
> +++ b/ld/emulparams/plt_unwind.sh
> @@ -1,10 +1,5 @@
>  PLT_UNWIND=yes
>
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_LD_GENERATED_UNWIND_INFO        301
> -#define OPTION_NO_LD_GENERATED_UNWIND_INFO 302
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    {"ld-generated-unwind-info", no_argument, NULL,
>     OPTION_LD_GENERATED_UNWIND_INFO},
> diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em
> index b647909ae63..aa2859d4f73 100644
> --- a/ld/emultempl/aarch64elf.em
> +++ b/ld/emultempl/aarch64elf.em
> @@ -355,16 +355,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_NO_ENUM_SIZE_WARNING    309
> -#define OPTION_PIC_VENEER              310
> -#define OPTION_STUBGROUP_SIZE          311
> -#define OPTION_NO_WCHAR_SIZE_WARNING   312
> -#define OPTION_FIX_ERRATUM_835769      313
> -#define OPTION_FIX_ERRATUM_843419      314
> -#define OPTION_NO_APPLY_DYNAMIC_RELOCS 315
> -'
> -
>  PARSE_AND_LIST_SHORTOPTS=p
>
>  PARSE_AND_LIST_LONGOPTS='
> diff --git a/ld/emultempl/aix.em b/ld/emultempl/aix.em
> index a445c32931d..33857b5d49c 100644
> --- a/ld/emultempl/aix.em
> +++ b/ld/emultempl/aix.em
> @@ -48,6 +48,7 @@ fragment <<EOF
>  #include "ldexp.h"
>  #include "ldlang.h"
>  #include "ldfile.h"
> +#include "ldlex.h"
>  #include "ldemul.h"
>  #include "ldctor.h"
>  #include <ldgram.h>
> @@ -171,35 +172,6 @@ gld${EMULATION_NAME}_before_parse (void)
>
>  /* Handle AIX specific options.  */
>
> -enum
> -  {
> -    OPTION_IGNORE = 300,
> -    OPTION_AUTOIMP,
> -    OPTION_ERNOTOK,
> -    OPTION_EROK,
> -    OPTION_EXPALL,
> -    OPTION_EXPFULL,
> -    OPTION_EXPORT,
> -    OPTION_IMPORT,
> -    OPTION_INITFINI,
> -    OPTION_LOADMAP,
> -    OPTION_MAXDATA,
> -    OPTION_MAXSTACK,
> -    OPTION_MODTYPE,
> -    OPTION_NOAUTOIMP,
> -    OPTION_NOEXPALL,
> -    OPTION_NOEXPFULL,
> -    OPTION_NOSTRCMPCT,
> -    OPTION_PD,
> -    OPTION_PT,
> -    OPTION_STRCMPCT,
> -    OPTION_UNIX,
> -    OPTION_32,
> -    OPTION_64,
> -    OPTION_LIBPATH,
> -    OPTION_NOLIBPATH,
> -  };
> -
>  static void
>  gld${EMULATION_NAME}_add_options
>    (int ns, char **shortopts, int nl, struct option **longopts,
> @@ -1299,7 +1271,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>  {
>    struct obstack *o;
>    FILE *f;
> -  int lineno;
> +  int linenumber;
>    int c;
>    bool keep;
>    const char *imppath;
> @@ -1323,7 +1295,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>    impfile = NULL;
>    impmember = NULL;
>
> -  lineno = 0;
> +  linenumber = 0;
>
>    /* Default to 32 and 64 bit mode
>       symbols at top of /lib/syscalls.exp do not have a mode modifier and they
> @@ -1347,7 +1319,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>         }
>
>        obstack_1grow (o, '\0');
> -      ++lineno;
> +      ++linenumber;
>
>        s = (char *) obstack_base (o);
>        while (ISSPACE (*s))
> @@ -1377,7 +1349,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>           else if (*s == '(')
>             einfo (_("%F%P:%s:%d: #! ([member]) is not supported "
>                      "in import files\n"),
> -                  filename, lineno);
> +                  filename, linenumber);
>           else
>             {
>               char cs;
> @@ -1403,7 +1375,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>                   impmember = "";
>                   if (cs != '\0')
>                     einfo (_("%P:%s:%d: warning: syntax error in import file\n"),
> -                          filename, lineno);
> +                          filename, linenumber);
>                 }
>               else
>                 {
> @@ -1415,7 +1387,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>                     *s = '\0';
>                   else
>                     einfo (_("%P:%s:%d: warning: syntax error in import file\n"),
> -                          filename, lineno);
> +                          filename, linenumber);
>                 }
>             }
>
> @@ -1451,7 +1423,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>                   if (*se != '\0')
>                     einfo (_("%P:%s%d: warning: syntax error in "
>                              "import/export file\n"),
> -                          filename, lineno);
> +                          filename, linenumber);
>                 }
>
>               if (s != se)
> @@ -1469,7 +1441,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>                         {
>                           einfo (_("%P:%s:%d: warning: syntax error in "
>                                    "import/export file\n"),
> -                                filename, lineno);
> +                                filename, linenumber);
>
>                         }
>                     }
> @@ -1503,7 +1475,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>                                                 address, imppath, impfile,
>                                                 impmember, syscall_flag))
>                     einfo (_("%X%P:%s:%d: failed to import symbol %s: %E\n"),
> -                          filename, lineno, symname);
> +                          filename, linenumber, symname);
>                 }
>             }
>         }
> @@ -1513,7 +1485,7 @@ gld${EMULATION_NAME}_read_file (const char *filename, bool import)
>    if (obstack_object_size (o) > 0)
>      {
>        einfo (_("%P:%s:%d: warning: ignoring unterminated last line\n"),
> -            filename, lineno);
> +            filename, linenumber);
>        obstack_free (o, obstack_base (o));
>      }
>
> diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em
> index cf32cd4ffa3..0445e798e3d 100644
> --- a/ld/emultempl/alphaelf.em
> +++ b/ld/emultempl/alphaelf.em
> @@ -111,12 +111,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_TASO            300
> -#define OPTION_SECUREPLT       (OPTION_TASO + 1)
> -#define OPTION_NO_SECUREPLT    (OPTION_SECUREPLT + 1)
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "taso", no_argument, NULL, OPTION_TASO },
>    { "secureplt", no_argument, NULL, OPTION_SECUREPLT },
> diff --git a/ld/emultempl/armelf.em b/ld/emultempl/armelf.em
> index 7fb1826ebed..8f501aed12a 100644
> --- a/ld/emultempl/armelf.em
> +++ b/ld/emultempl/armelf.em
> @@ -566,31 +566,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_THUMB_ENTRY             301
> -#define OPTION_BE8                     302
> -#define OPTION_TARGET1_REL             303
> -#define OPTION_TARGET1_ABS             304
> -#define OPTION_TARGET2                 305
> -#define OPTION_FIX_V4BX                        306
> -#define OPTION_USE_BLX                 307
> -#define OPTION_VFP11_DENORM_FIX                308
> -#define OPTION_NO_ENUM_SIZE_WARNING    309
> -#define OPTION_PIC_VENEER              310
> -#define OPTION_FIX_V4BX_INTERWORKING   311
> -#define OPTION_STUBGROUP_SIZE          312
> -#define OPTION_NO_WCHAR_SIZE_WARNING   313
> -#define OPTION_FIX_CORTEX_A8           314
> -#define OPTION_NO_FIX_CORTEX_A8                315
> -#define OPTION_NO_MERGE_EXIDX_ENTRIES  316
> -#define OPTION_FIX_ARM1176             317
> -#define OPTION_NO_FIX_ARM1176          318
> -#define OPTION_LONG_PLT                        319
> -#define OPTION_STM32L4XX_FIX           320
> -#define OPTION_CMSE_IMPLIB             321
> -#define OPTION_IN_IMPLIB               322
> -'
> -
>  PARSE_AND_LIST_SHORTOPTS=p
>
>  PARSE_AND_LIST_LONGOPTS='
> diff --git a/ld/emultempl/avrelf.em b/ld/emultempl/avrelf.em
> index 3fe81004745..792be729299 100644
> --- a/ld/emultempl/avrelf.em
> +++ b/ld/emultempl/avrelf.em
> @@ -232,15 +232,6 @@ avr_finish (void)
>  EOF
>
>
> -PARSE_AND_LIST_PROLOGUE='
> -
> -#define OPTION_NO_CALL_RET_REPLACEMENT 301
> -#define OPTION_PMEM_WRAP_AROUND               302
> -#define OPTION_NO_STUBS                       303
> -#define OPTION_DEBUG_STUBS            304
> -#define OPTION_DEBUG_RELAX            305
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "no-call-ret-replacement", no_argument,
>      NULL, OPTION_NO_CALL_RET_REPLACEMENT},
> diff --git a/ld/emultempl/beos.em b/ld/emultempl/beos.em
> index 844d4986c2d..29c386c61f8 100644
> --- a/ld/emultempl/beos.em
> +++ b/ld/emultempl/beos.em
> @@ -70,22 +70,6 @@ gld${EMULATION_NAME}_before_parse (void)
>
>  /* PE format extra command line options.  */
>
> -/* Used for setting flags in the PE header. */
> -#define OPTION_BASE_FILE               (300  + 1)
> -#define OPTION_DLL                     (OPTION_BASE_FILE + 1)
> -#define OPTION_FILE_ALIGNMENT          (OPTION_DLL + 1)
> -#define OPTION_IMAGE_BASE              (OPTION_FILE_ALIGNMENT + 1)
> -#define OPTION_MAJOR_IMAGE_VERSION     (OPTION_IMAGE_BASE + 1)
> -#define OPTION_MAJOR_OS_VERSION                (OPTION_MAJOR_IMAGE_VERSION + 1)
> -#define OPTION_MAJOR_SUBSYSTEM_VERSION (OPTION_MAJOR_OS_VERSION + 1)
> -#define OPTION_MINOR_IMAGE_VERSION     (OPTION_MAJOR_SUBSYSTEM_VERSION + 1)
> -#define OPTION_MINOR_OS_VERSION                (OPTION_MINOR_IMAGE_VERSION + 1)
> -#define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
> -#define OPTION_SECTION_ALIGNMENT       (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
> -#define OPTION_STACK                   (OPTION_SECTION_ALIGNMENT + 1)
> -#define OPTION_SUBSYSTEM               (OPTION_STACK + 1)
> -#define OPTION_HEAP                    (OPTION_SUBSYSTEM + 1)
> -
>  static void
>  gld${EMULATION_NAME}_add_options
>    (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
> diff --git a/ld/emultempl/bfin.em b/ld/emultempl/bfin.em
> index eb13055d9ea..4b9be670c62 100644
> --- a/ld/emultempl/bfin.em
> +++ b/ld/emultempl/bfin.em
> @@ -39,11 +39,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_CODE_IN_L1              300
> -#define OPTION_DATA_IN_L1              301
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "code-in-l1", no_argument, NULL, OPTION_CODE_IN_L1 },
>    { "data-in-l1", no_argument, NULL, OPTION_DATA_IN_L1 },
> diff --git a/ld/emultempl/cskyelf.em b/ld/emultempl/cskyelf.em
> index 82815e5e7a8..64a6ddf61f8 100644
> --- a/ld/emultempl/cskyelf.em
> +++ b/ld/emultempl/cskyelf.em
> @@ -288,12 +288,6 @@ EOF
>
>  # This code gets inserted into the generic elf32.sc linker script
>  # and allows us to define our own command line switches.
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_BRANCH_STUB             301
> -#define OPTION_NO_BRANCH_STUB          302
> -#define OPTION_STUBGROUP_SIZE          303
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    {"branch-stub",      no_argument,       NULL, OPTION_BRANCH_STUB},
>    {"no-branch-stub",   no_argument,       NULL, OPTION_NO_BRANCH_STUB},
> diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
> index 71cec19fdc6..f551225cdac 100644
> --- a/ld/emultempl/elf.em
> +++ b/ld/emultempl/elf.em
> @@ -45,6 +45,7 @@ fragment <<EOF
>  #include "ldexp.h"
>  #include "ldlang.h"
>  #include "ldfile.h"
> +#include "ldlex.h"
>  #include "ldemul.h"
>  #include <ldgram.h>
>  #include "elf-bfd.h"
> @@ -556,28 +557,7 @@ EOF
>  fi
>  fi
>
> -if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
>  fragment <<EOF
> - $PARSE_AND_LIST_PROLOGUE
> -EOF
> -fi
> -
> -fragment <<EOF
> -
> -enum elf_options
> -{
> -  OPTION_DISABLE_NEW_DTAGS = 400,
> -  OPTION_ENABLE_NEW_DTAGS,
> -  OPTION_GROUP,
> -  OPTION_EH_FRAME_HDR,
> -  OPTION_NO_EH_FRAME_HDR,
> -  OPTION_EXCLUDE_LIBS,
> -  OPTION_HASH_STYLE,
> -  OPTION_BUILD_ID,
> -  OPTION_PACKAGE_METADATA,
> -  OPTION_AUDIT,
> -  OPTION_COMPRESS_DEBUG
> -};
>
>  static void
>  gld${EMULATION_NAME}_add_options
> diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em
> index 09db0cb07de..45257980831 100644
> --- a/ld/emultempl/hppaelf.em
> +++ b/ld/emultempl/hppaelf.em
> @@ -314,11 +314,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_MULTI_SUBSPACE          301
> -#define OPTION_STUBGROUP_SIZE          (OPTION_MULTI_SUBSPACE + 1)
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "multi-subspace", no_argument, NULL, OPTION_MULTI_SUBSPACE },
>    { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
> diff --git a/ld/emultempl/ia64elf.em b/ld/emultempl/ia64elf.em
> index a4657bcf3ac..a74849d1dbb 100644
> --- a/ld/emultempl/ia64elf.em
> +++ b/ld/emultempl/ia64elf.em
> @@ -43,10 +43,6 @@ ia64elf_after_parse (void)
>
>  EOF
>
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_ITANIUM                 300
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>      { "itanium", no_argument, NULL, OPTION_ITANIUM},
>  '
> diff --git a/ld/emultempl/m68hc1xelf.em b/ld/emultempl/m68hc1xelf.em
> index 5355b0fc1c0..7aaa78a72d5 100644
> --- a/ld/emultempl/m68hc1xelf.em
> +++ b/ld/emultempl/m68hc1xelf.em
> @@ -322,11 +322,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_NO_TRAMPOLINE           300
> -#define OPTION_BANK_WINDOW             301
> -'
> -
>  # The options are repeated below so that no abbreviations are allowed.
>  # Otherwise -s matches stub-group-size
>  PARSE_AND_LIST_LONGOPTS='
> diff --git a/ld/emultempl/m68kelf.em b/ld/emultempl/m68kelf.em
> index 0477f1eb23a..30e7d171f6a 100644
> --- a/ld/emultempl/m68kelf.em
> +++ b/ld/emultempl/m68kelf.em
> @@ -200,10 +200,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_GOT     301
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "got", required_argument, NULL, OPTION_GOT},
>  '
> diff --git a/ld/emultempl/metagelf.em b/ld/emultempl/metagelf.em
> index 81ab64c1110..10d3ff10def 100644
> --- a/ld/emultempl/metagelf.em
> +++ b/ld/emultempl/metagelf.em
> @@ -282,10 +282,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_STUBGROUP_SIZE          301
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
>  '
> diff --git a/ld/emultempl/mipself.em b/ld/emultempl/mipself.em
> index f8fe4b9767e..3259f654b36 100644
> --- a/ld/emultempl/mipself.em
> +++ b/ld/emultempl/mipself.em
> @@ -232,18 +232,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -enum
> -  {
> -    OPTION_INSN32 = 301,
> -    OPTION_NO_INSN32,
> -    OPTION_IGNORE_BRANCH_ISA,
> -    OPTION_NO_IGNORE_BRANCH_ISA,
> -    OPTION_COMPACT_BRANCHES,
> -    OPTION_NO_COMPACT_BRANCHES
> -  };
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "insn32", no_argument, NULL, OPTION_INSN32 },
>    { "no-insn32", no_argument, NULL, OPTION_NO_INSN32 },
> diff --git a/ld/emultempl/msp430.em b/ld/emultempl/msp430.em
> index 92402b308a4..2d225317a25 100644
> --- a/ld/emultempl/msp430.em
> +++ b/ld/emultempl/msp430.em
> @@ -39,6 +39,7 @@ fragment <<EOF
>  #include "ldexp.h"
>  #include "ldlang.h"
>  #include "ldfile.h"
> +#include "ldlex.h"
>  #include "ldemul.h"
>  #include "libiberty.h"
>  #include <ldgram.h>
> @@ -443,10 +444,6 @@ msp430_elf_after_open (void)
>      bfd_map_over_sections (abfd, add_region_prefix, NULL);
>  }
>
> -#define OPTION_CODE_REGION             321
> -#define OPTION_DATA_REGION             (OPTION_CODE_REGION + 1)
> -#define OPTION_DISABLE_TRANS           (OPTION_CODE_REGION + 2)
> -
>  static void
>  gld${EMULATION_NAME}_add_options
>    (int ns, char **shortopts, int nl, struct option **longopts,
> diff --git a/ld/emultempl/nds32elf.em b/ld/emultempl/nds32elf.em
> index bde9e35de99..260e2a46e5d 100644
> --- a/ld/emultempl/nds32elf.em
> +++ b/ld/emultempl/nds32elf.em
> @@ -132,18 +132,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_BASELINE                        301
> -#define OPTION_ELIM_GC_RELOCS          (OPTION_BASELINE + 1)
> -#define OPTION_FP_AS_GP                        (OPTION_BASELINE + 2)
> -#define OPTION_NO_FP_AS_GP             (OPTION_BASELINE + 3)
> -#define OPTION_REDUCE_FP_UPDATE                (OPTION_BASELINE + 4)
> -#define OPTION_NO_REDUCE_FP_UPDATE     (OPTION_BASELINE + 5)
> -#define OPTION_EXPORT_SYMBOLS          (OPTION_BASELINE + 6)
> -#define OPTION_HYPER_RELAX             (OPTION_BASELINE + 7)
> -#define OPTION_TLSDESC_TRAMPOLINE      (OPTION_BASELINE + 8)
> -#define OPTION_NO_TLSDESC_TRAMPOLINE   (OPTION_BASELINE + 9)
> -'
>  PARSE_AND_LIST_LONGOPTS='
>    { "mfp-as-gp", no_argument, NULL, OPTION_FP_AS_GP},
>    { "mno-fp-as-gp", no_argument, NULL, OPTION_NO_FP_AS_GP},
> diff --git a/ld/emultempl/nto.em b/ld/emultempl/nto.em
> index de69e132348..7cda6650bc6 100644
> --- a/ld/emultempl/nto.em
> +++ b/ld/emultempl/nto.em
> @@ -190,14 +190,6 @@ EOF
>  # parse_args and list_options functions.
>  #
>
> -PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
> -enum nto_options
> -{
> -  OPTION_STACK = 500,
> -  OPTION_LAZY_STACK,
> -};
> -'
> -
>  PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
>    { "stack", required_argument, NULL, OPTION_STACK },
>    { "lazy-stack", no_argument, NULL, OPTION_LAZY_STACK },
> diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em
> index c6ed1110595..9ab5e6ef481 100644
> --- a/ld/emultempl/pe.em
> +++ b/ld/emultempl/pe.em
> @@ -235,84 +235,6 @@ fragment <<EOF
>
>  /* PE format extra command line options.  */
>
> -/* Used for setting flags in the PE header.  */
> -enum options
> -{
> -  OPTION_BASE_FILE = 300 + 1,
> -  OPTION_DLL,
> -  OPTION_FILE_ALIGNMENT,
> -  OPTION_IMAGE_BASE,
> -  OPTION_MAJOR_IMAGE_VERSION,
> -  OPTION_MAJOR_OS_VERSION,
> -  OPTION_MAJOR_SUBSYSTEM_VERSION,
> -  OPTION_MINOR_IMAGE_VERSION,
> -  OPTION_MINOR_OS_VERSION,
> -  OPTION_MINOR_SUBSYSTEM_VERSION,
> -  OPTION_SECTION_ALIGNMENT,
> -  OPTION_STACK,
> -  OPTION_SUBSYSTEM,
> -  OPTION_HEAP,
> -  OPTION_SUPPORT_OLD_CODE,
> -  OPTION_OUT_DEF,
> -  OPTION_EXPORT_ALL,
> -  OPTION_EXCLUDE_SYMBOLS,
> -  OPTION_EXCLUDE_ALL_SYMBOLS,
> -  OPTION_KILL_ATS,
> -  OPTION_STDCALL_ALIASES,
> -  OPTION_ENABLE_STDCALL_FIXUP,
> -  OPTION_DISABLE_STDCALL_FIXUP,
> -  OPTION_THUMB_ENTRY,
> -  OPTION_WARN_DUPLICATE_EXPORTS,
> -  OPTION_IMP_COMPAT,
> -  OPTION_ENABLE_AUTO_IMAGE_BASE,
> -  OPTION_DISABLE_AUTO_IMAGE_BASE,
> -  OPTION_DLL_SEARCH_PREFIX,
> -  OPTION_NO_DEFAULT_EXCLUDES,
> -  OPTION_DLL_ENABLE_AUTO_IMPORT,
> -  OPTION_DLL_DISABLE_AUTO_IMPORT,
> -  OPTION_ENABLE_EXTRA_PE_DEBUG,
> -  OPTION_EXCLUDE_LIBS,
> -  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
> -  OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
> -  OPTION_LARGE_ADDRESS_AWARE,
> -  OPTION_DISABLE_LARGE_ADDRESS_AWARE,
> -  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1,
> -  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
> -  OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
> -  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
> -  OPTION_NO_LEADING_UNDERSCORE,
> -  OPTION_LEADING_UNDERSCORE,
> -  OPTION_ENABLE_LONG_SECTION_NAMES,
> -  OPTION_DISABLE_LONG_SECTION_NAMES,
> -/* DLLCharacteristics flags.  */
> -  OPTION_DYNAMIC_BASE,
> -  OPTION_FORCE_INTEGRITY,
> -  OPTION_NX_COMPAT,
> -  OPTION_NO_ISOLATION,
> -  OPTION_NO_SEH,
> -  OPTION_NO_BIND,
> -  OPTION_WDM_DRIVER,
> -  OPTION_TERMINAL_SERVER_AWARE,
> -/* Determinism.  */
> -  OPTION_INSERT_TIMESTAMP,
> -  OPTION_NO_INSERT_TIMESTAMP,
> -  OPTION_BUILD_ID,
> -#ifdef PDB_H
> -  OPTION_PDB,
> -#endif
> -  OPTION_ENABLE_RELOC_SECTION,
> -  OPTION_DISABLE_RELOC_SECTION,
> -/* DLL Characteristics flags.  */
> -  OPTION_DISABLE_DYNAMIC_BASE,
> -  OPTION_DISABLE_FORCE_INTEGRITY,
> -  OPTION_DISABLE_NX_COMPAT,
> -  OPTION_DISABLE_NO_ISOLATION,
> -  OPTION_DISABLE_NO_SEH,
> -  OPTION_DISABLE_NO_BIND,
> -  OPTION_DISABLE_WDM_DRIVER,
> -  OPTION_DISABLE_TERMINAL_SERVER_AWARE
> -};
> -
>  static void
>  gld${EMULATION_NAME}_add_options
>    (int ns ATTRIBUTE_UNUSED,
> diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em
> index bd2ee2ede26..00c4ea9e15a 100644
> --- a/ld/emultempl/pep.em
> +++ b/ld/emultempl/pep.em
> @@ -245,79 +245,6 @@ gld${EMULATION_NAME}_before_parse (void)
>
>  /* PE format extra command line options.  */
>
> -/* Used for setting flags in the PE header.  */
> -enum options
> -{
> -  OPTION_BASE_FILE = 300 + 1,
> -  OPTION_DLL,
> -  OPTION_FILE_ALIGNMENT,
> -  OPTION_IMAGE_BASE,
> -  OPTION_MAJOR_IMAGE_VERSION,
> -  OPTION_MAJOR_OS_VERSION,
> -  OPTION_MAJOR_SUBSYSTEM_VERSION,
> -  OPTION_MINOR_IMAGE_VERSION,
> -  OPTION_MINOR_OS_VERSION,
> -  OPTION_MINOR_SUBSYSTEM_VERSION,
> -  OPTION_SECTION_ALIGNMENT,
> -  OPTION_STACK,
> -  OPTION_SUBSYSTEM,
> -  OPTION_HEAP,
> -  OPTION_SUPPORT_OLD_CODE,
> -  OPTION_OUT_DEF,
> -  OPTION_EXPORT_ALL,
> -  OPTION_EXCLUDE_SYMBOLS,
> -  OPTION_EXCLUDE_ALL_SYMBOLS,
> -  OPTION_KILL_ATS,
> -  OPTION_STDCALL_ALIASES,
> -  OPTION_ENABLE_STDCALL_FIXUP,
> -  OPTION_DISABLE_STDCALL_FIXUP,
> -  OPTION_WARN_DUPLICATE_EXPORTS,
> -  OPTION_IMP_COMPAT,
> -  OPTION_ENABLE_AUTO_IMAGE_BASE,
> -  OPTION_DISABLE_AUTO_IMAGE_BASE,
> -  OPTION_DLL_SEARCH_PREFIX,
> -  OPTION_NO_DEFAULT_EXCLUDES,
> -  OPTION_DLL_ENABLE_AUTO_IMPORT,
> -  OPTION_DLL_DISABLE_AUTO_IMPORT,
> -  OPTION_ENABLE_EXTRA_PE_DEBUG,
> -  OPTION_EXCLUDE_LIBS,
> -  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
> -  OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
> -  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
> -  OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
> -  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
> -  OPTION_NO_LEADING_UNDERSCORE,
> -  OPTION_LEADING_UNDERSCORE,
> -  OPTION_ENABLE_LONG_SECTION_NAMES,
> -  OPTION_DISABLE_LONG_SECTION_NAMES,
> -  OPTION_HIGH_ENTROPY_VA,
> -  OPTION_DYNAMIC_BASE,
> -  OPTION_FORCE_INTEGRITY,
> -  OPTION_NX_COMPAT,
> -  OPTION_NO_ISOLATION,
> -  OPTION_NO_SEH,
> -  OPTION_NO_BIND,
> -  OPTION_WDM_DRIVER,
> -  OPTION_INSERT_TIMESTAMP,
> -  OPTION_NO_INSERT_TIMESTAMP,
> -  OPTION_TERMINAL_SERVER_AWARE,
> -  OPTION_BUILD_ID,
> -#ifdef PDB_H
> -  OPTION_PDB,
> -#endif
> -  OPTION_ENABLE_RELOC_SECTION,
> -  OPTION_DISABLE_RELOC_SECTION,
> -  OPTION_DISABLE_HIGH_ENTROPY_VA,
> -  OPTION_DISABLE_DYNAMIC_BASE,
> -  OPTION_DISABLE_FORCE_INTEGRITY,
> -  OPTION_DISABLE_NX_COMPAT,
> -  OPTION_DISABLE_NO_ISOLATION,
> -  OPTION_DISABLE_NO_SEH,
> -  OPTION_DISABLE_NO_BIND,
> -  OPTION_DISABLE_WDM_DRIVER,
> -  OPTION_DISABLE_TERMINAL_SERVER_AWARE
> -};
> -
>  static void
>  gld${EMULATION_NAME}_add_options
>    (int ns ATTRIBUTE_UNUSED,
> diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
> index 0730a05e75b..12476f44fcf 100644
> --- a/ld/emultempl/ppc32elf.em
> +++ b/ld/emultempl/ppc32elf.em
> @@ -264,26 +264,6 @@ fi
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
> -enum ppc32_opt
> -{
> -  OPTION_NO_TLS_OPT = 321,
> -  OPTION_NO_TLS_GET_ADDR_OPT,
> -  OPTION_NEW_PLT,
> -  OPTION_OLD_PLT,
> -  OPTION_PLT_ALIGN,
> -  OPTION_NO_PLT_ALIGN,
> -  OPTION_NO_INLINE_OPT,
> -  OPTION_OLD_GOT,
> -  OPTION_STUBSYMS,
> -  OPTION_NO_STUBSYMS,
> -  OPTION_PPC476_WORKAROUND,
> -  OPTION_NO_PPC476_WORKAROUND,
> -  OPTION_NO_PICFIXUP,
> -  OPTION_VLE_RELOC_FIXUP
> -};
> -'
> -
>  PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
>    { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
>    { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
> diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
> index 533caed2fc2..23905e9bc88 100644
> --- a/ld/emultempl/ppc64elf.em
> +++ b/ld/emultempl/ppc64elf.em
> @@ -684,41 +684,6 @@ fi
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
> -enum ppc64_opt
> -{
> -  OPTION_STUBGROUP_SIZE = 321,
> -  OPTION_PLT_STATIC_CHAIN,
> -  OPTION_NO_PLT_STATIC_CHAIN,
> -  OPTION_PLT_THREAD_SAFE,
> -  OPTION_NO_PLT_THREAD_SAFE,
> -  OPTION_PLT_ALIGN,
> -  OPTION_NO_PLT_ALIGN,
> -  OPTION_PLT_LOCALENTRY,
> -  OPTION_NO_PLT_LOCALENTRY,
> -  OPTION_POWER10_STUBS,
> -  OPTION_NO_POWER10_STUBS,
> -  OPTION_NO_PCREL_OPT,
> -  OPTION_STUBSYMS,
> -  OPTION_NO_STUBSYMS,
> -  OPTION_SAVRES,
> -  OPTION_NO_SAVRES,
> -  OPTION_DOTSYMS,
> -  OPTION_NO_DOTSYMS,
> -  OPTION_NO_TLS_OPT,
> -  OPTION_TLS_GET_ADDR_OPT,
> -  OPTION_NO_TLS_GET_ADDR_OPT,
> -  OPTION_TLS_GET_ADDR_REGSAVE,
> -  OPTION_NO_TLS_GET_ADDR_REGSAVE,
> -  OPTION_NO_OPD_OPT,
> -  OPTION_NO_INLINE_OPT,
> -  OPTION_NO_TOC_OPT,
> -  OPTION_NO_MULTI_TOC,
> -  OPTION_NO_TOC_SORT,
> -  OPTION_NON_OVERLAPPING_OPD
> -};
> -'
> -
>  PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
>    { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
>    { "plt-static-chain", no_argument, NULL, OPTION_PLT_STATIC_CHAIN },
> diff --git a/ld/emultempl/riscvelf.em b/ld/emultempl/riscvelf.em
> index fe53b2a7a71..afc43ed55dc 100644
> --- a/ld/emultempl/riscvelf.em
> +++ b/ld/emultempl/riscvelf.em
> @@ -31,16 +31,6 @@ EOF
>
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.  */
> -PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
> -enum risccv_opt
> -{
> -  OPTION_RELAX_GP = 321,
> -  OPTION_NO_RELAX_GP,
> -  OPTION_CHECK_ULEB128,
> -  OPTION_NO_CHECK_ULEB128,
> -};
> -'
> -
>  PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
>      { "relax-gp", no_argument, NULL, OPTION_RELAX_GP },
>      { "no-relax-gp", no_argument, NULL, OPTION_NO_RELAX_GP },
> diff --git a/ld/emultempl/rxelf.em b/ld/emultempl/rxelf.em
> index 3b8df6ef665..cc76a274a26 100644
> --- a/ld/emultempl/rxelf.em
> +++ b/ld/emultempl/rxelf.em
> @@ -45,13 +45,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_NO_FLAG_MISMATCH_WARNINGS       301
> -#define OPTION_IGNORE_LMA                      302
> -#define OPTION_NO_IGNORE_LMA                   303
> -#define OPTION_FLAG_MISMATCH_WARNINGS          304
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "no-flag-mismatch-warnings", no_argument, NULL, OPTION_NO_FLAG_MISMATCH_WARNINGS},
>    { "flag-mismatch-warnings", no_argument, NULL, OPTION_FLAG_MISMATCH_WARNINGS},
> diff --git a/ld/emultempl/s390.em b/ld/emultempl/s390.em
> index 11e7f19bb52..179cbbd98d7 100644
> --- a/ld/emultempl/s390.em
> +++ b/ld/emultempl/s390.em
> @@ -42,10 +42,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_PGSTE   301
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "s390-pgste", no_argument, NULL, OPTION_PGSTE},
>  '
> diff --git a/ld/emultempl/scoreelf.em b/ld/emultempl/scoreelf.em
> index 6238b5e2a19..499a583decd 100644
> --- a/ld/emultempl/scoreelf.em
> +++ b/ld/emultempl/scoreelf.em
> @@ -76,7 +76,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE=''
>  PARSE_AND_LIST_SHORTOPTS=
>  PARSE_AND_LIST_LONGOPTS=''
>  PARSE_AND_LIST_OPTIONS=''
> diff --git a/ld/emultempl/spuelf.em b/ld/emultempl/spuelf.em
> index cc39435cc3b..2ff41b1e46e 100644
> --- a/ld/emultempl/spuelf.em
> +++ b/ld/emultempl/spuelf.em
> @@ -589,30 +589,6 @@ fi
>  # Define some shell vars to insert bits of code into the standard elf
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_SPU_PLUGIN              301
> -#define OPTION_SPU_NO_OVERLAYS         (OPTION_SPU_PLUGIN + 1)
> -#define OPTION_SPU_COMPACT_STUBS       (OPTION_SPU_NO_OVERLAYS + 1)
> -#define OPTION_SPU_STUB_SYMS           (OPTION_SPU_COMPACT_STUBS + 1)
> -#define OPTION_SPU_NON_OVERLAY_STUBS   (OPTION_SPU_STUB_SYMS + 1)
> -#define OPTION_SPU_LOCAL_STORE         (OPTION_SPU_NON_OVERLAY_STUBS + 1)
> -#define OPTION_SPU_STACK_ANALYSIS      (OPTION_SPU_LOCAL_STORE + 1)
> -#define OPTION_SPU_STACK_SYMS          (OPTION_SPU_STACK_ANALYSIS + 1)
> -#define OPTION_SPU_AUTO_OVERLAY                (OPTION_SPU_STACK_SYMS + 1)
> -#define OPTION_SPU_AUTO_RELINK         (OPTION_SPU_AUTO_OVERLAY + 1)
> -#define OPTION_SPU_OVERLAY_RODATA      (OPTION_SPU_AUTO_RELINK + 1)
> -#define OPTION_SPU_SOFT_ICACHE         (OPTION_SPU_OVERLAY_RODATA + 1)
> -#define OPTION_SPU_LINE_SIZE           (OPTION_SPU_SOFT_ICACHE + 1)
> -#define OPTION_SPU_NUM_LINES           (OPTION_SPU_LINE_SIZE + 1)
> -#define OPTION_SPU_LRLIVE              (OPTION_SPU_NUM_LINES + 1)
> -#define OPTION_SPU_NON_IA_TEXT         (OPTION_SPU_LRLIVE + 1)
> -#define OPTION_SPU_FIXED_SPACE         (OPTION_SPU_NON_IA_TEXT + 1)
> -#define OPTION_SPU_RESERVED_SPACE      (OPTION_SPU_FIXED_SPACE + 1)
> -#define OPTION_SPU_EXTRA_STACK         (OPTION_SPU_RESERVED_SPACE + 1)
> -#define OPTION_SPU_NO_AUTO_OVERLAY     (OPTION_SPU_EXTRA_STACK + 1)
> -#define OPTION_SPU_EMIT_FIXUPS         (OPTION_SPU_NO_AUTO_OVERLAY + 1)
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "plugin", no_argument, NULL, OPTION_SPU_PLUGIN },
>    { "soft-icache", no_argument, NULL, OPTION_SPU_SOFT_ICACHE },
> diff --git a/ld/emultempl/tic6xdsbt.em b/ld/emultempl/tic6xdsbt.em
> index 524e3f73eec..8140ef9c218 100644
> --- a/ld/emultempl/tic6xdsbt.em
> +++ b/ld/emultempl/tic6xdsbt.em
> @@ -165,12 +165,6 @@ EOF
>
>  # This code gets inserted into the generic elf32.sc linker script
>  # and allows us to define our own command line switches.
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_DSBT_INDEX              300
> -#define OPTION_DSBT_SIZE               301
> -#define OPTION_NO_MERGE_EXIDX_ENTRIES   302
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    {"dsbt-index", required_argument, NULL, OPTION_DSBT_INDEX},
>    {"dsbt-size", required_argument, NULL, OPTION_DSBT_SIZE},
> diff --git a/ld/emultempl/ticoff.em b/ld/emultempl/ticoff.em
> index 4b048bef8f9..fb6cf3a0c2e 100644
> --- a/ld/emultempl/ticoff.em
> +++ b/ld/emultempl/ticoff.em
> @@ -40,12 +40,12 @@ fragment <<EOF
>  #include "ldexp.h"
>  #include "ldlang.h"
>  #include "ldfile.h"
> +#include "ldlex.h"
>  #include "ldemul.h"
>
>  static int coff_version;
>
>  /* TI COFF extra command line options */
> -#define OPTION_COFF_FORMAT             (300 + 1)
>
>  static void
>  gld${EMULATION_NAME}_add_options
> diff --git a/ld/emultempl/vms.em b/ld/emultempl/vms.em
> index 67e9ea641eb..8baacb35a13 100644
> --- a/ld/emultempl/vms.em
> +++ b/ld/emultempl/vms.em
> @@ -24,6 +24,7 @@
>  fragment <<EOF
>  #include "libiberty.h"
>  #include "getopt.h"
> +#include "ldlex.h"
>
>  static void
>  gld${EMULATION_NAME}_before_parse (void)
> @@ -125,7 +126,6 @@ vms_place_orphan (asection *s,
>  }
>
>  /* VMS specific options.  */
> -#define OPTION_IDENTIFICATION          (300  + 1)
>
>  static void
>  gld${EMULATION_NAME}_add_options
> diff --git a/ld/emultempl/vxworks.em b/ld/emultempl/vxworks.em
> index 00cfeabad3a..307049cfd3a 100644
> --- a/ld/emultempl/vxworks.em
> +++ b/ld/emultempl/vxworks.em
> @@ -55,12 +55,6 @@ vxworks_after_open (void)
>
>  EOF
>
> -PARSE_AND_LIST_PROLOGUE=$PARSE_AND_LIST_PROLOGUE'
> -enum {
> -  OPTION_FORCE_DYNAMIC = 501
> -};
> -'
> -
>  PARSE_AND_LIST_LONGOPTS=$PARSE_AND_LIST_LONGOPTS'
>    {"force-dynamic", no_argument, NULL, OPTION_FORCE_DYNAMIC},
>  '
> diff --git a/ld/emultempl/xtensaelf.em b/ld/emultempl/xtensaelf.em
> index 512935392a9..3508eb7f503 100644
> --- a/ld/emultempl/xtensaelf.em
> +++ b/ld/emultempl/xtensaelf.em
> @@ -39,6 +39,9 @@ static void xtensa_colocate_output_literals (lang_statement_union_type *);
>  static void xtensa_strip_inconsistent_linkonce_sections
>    (lang_statement_list_type *);
>
> +extern int elf32xtensa_size_opt;
> +extern int elf32xtensa_no_literal_movement;
> +extern int elf32xtensa_abi;
>
>  /* This number is irrelevant until we turn on use_literal_pages */
>  static bfd_vma xtensa_page_power = 12; /* 4K pages.  */
> @@ -1922,17 +1925,6 @@ EOF
>  # Define some shell vars to insert bits of code into the standard ELF
>  # parse_args and list_options functions.
>  #
> -PARSE_AND_LIST_PROLOGUE='
> -#define OPTION_OPT_SIZEOPT              (300)
> -#define OPTION_LITERAL_MOVEMENT                (OPTION_OPT_SIZEOPT + 1)
> -#define OPTION_NO_LITERAL_MOVEMENT     (OPTION_LITERAL_MOVEMENT + 1)
> -#define OPTION_ABI_WINDOWED            (OPTION_NO_LITERAL_MOVEMENT + 1)
> -#define OPTION_ABI_CALL0               (OPTION_ABI_WINDOWED + 1)
> -extern int elf32xtensa_size_opt;
> -extern int elf32xtensa_no_literal_movement;
> -extern int elf32xtensa_abi;
> -'
> -
>  PARSE_AND_LIST_LONGOPTS='
>    { "size-opt", no_argument, NULL, OPTION_OPT_SIZEOPT},
>    { "literal-movement", no_argument, NULL, OPTION_LITERAL_MOVEMENT},
> diff --git a/ld/ldlex.h b/ld/ldlex.h
> index 161a9d4d8dc..e5ac2fa7fca 100644
> --- a/ld/ldlex.h
> +++ b/ld/ldlex.h
> @@ -181,6 +181,292 @@ enum option_values
>    OPTION_DISABLE_LINKER_VERSION,
>    OPTION_REMAP_INPUTS,
>    OPTION_REMAP_INPUTS_FILE,
> +  /* Used by emultempl/elf.em, emultempl/pe.em and emultempl/pep.em.  */
> +  OPTION_BUILD_ID,
> +  OPTION_EXCLUDE_LIBS,
> +  /* Used by emulparams/elf32mcore.sh, emultempl/beos.em, emultempl/pe.em
> +     and emultempl/pep.em.  */
> +  OPTION_BASE_FILE,
> +  /* Used by emultempl/ppc32elf.em and emultempl/ppc64elf.em.  */
> +  OPTION_NO_INLINE_OPT,
> +  OPTION_NO_PLT_ALIGN,
> +  OPTION_NO_STUBSYMS,
> +  OPTION_NO_TLS_GET_ADDR_OPT,
> +  OPTION_NO_TLS_OPT,
> +  OPTION_PLT_ALIGN,
> +  OPTION_STUBSYMS,
> +  /* Used by emultempl/armelf.em and emultempl/tic6xdsbt.em.  */
> +  OPTION_NO_MERGE_EXIDX_ENTRIES,
> +  /* Used by emultempl/aarch64elf.em and emultempl/armelf.em.  */
> +  OPTION_PIC_VENEER,
> +  OPTION_NO_ENUM_SIZE_WARNING,
> +  OPTION_NO_WCHAR_SIZE_WARNING,
> +  /* Used by emultempl/armelf.em and emultempl/pe.em.  */
> +  OPTION_THUMB_ENTRY,
> +  /* Used by emultempl/beos.em, emultempl/nto.em, emultempl/pe.em and
> +     emultempl/pep.em.  */
> +  OPTION_STACK,
> +  /* Used by emultempl/aarch64elf.em, emultempl/armelf.em,
> +     emultempl/cskyelf.em, emultempl/hppaelf.em, emultempl/metagelf.em
> +     and emultempl/ppc64elf.em.  */
> +  OPTION_STUBGROUP_SIZE,
> +  /* Used by emulparams/plt_unwind.sh.  */
> +  OPTION_LD_GENERATED_UNWIND_INFO,
> +  OPTION_NO_LD_GENERATED_UNWIND_INFO,
> +  /* Used by emultempl/aarch64elf.em.  */
> +  OPTION_FIX_ERRATUM_835769,
> +  OPTION_FIX_ERRATUM_843419,
> +  OPTION_NO_APPLY_DYNAMIC_RELOCS,
> +  /* Used by emultempl/aix.em.  */
> +  OPTION_AUTOIMP,
> +  OPTION_ERNOTOK,
> +  OPTION_EROK,
> +  OPTION_EXPALL,
> +  OPTION_EXPFULL,
> +  OPTION_EXPORT,
> +  OPTION_IMPORT,
> +  OPTION_INITFINI,
> +  OPTION_LOADMAP,
> +  OPTION_MAXDATA,
> +  OPTION_MAXSTACK,
> +  OPTION_MODTYPE,
> +  OPTION_NOAUTOIMP,
> +  OPTION_NOEXPALL,
> +  OPTION_NOEXPFULL,
> +  OPTION_NOSTRCMPCT,
> +  OPTION_PD,
> +  OPTION_PT,
> +  OPTION_STRCMPCT,
> +  OPTION_UNIX,
> +  OPTION_32,
> +  OPTION_64,
> +  OPTION_LIBPATH,
> +  OPTION_NOLIBPATH,
> +  /* Used by emultempl/alphaelf.em.  */
> +  OPTION_TASO,
> +  OPTION_SECUREPLT,
> +  OPTION_NO_SECUREPLT,
> +  /* Used by emultempl/armelf.em.  */
> +  OPTION_BE8,
> +  OPTION_TARGET1_REL,
> +  OPTION_TARGET1_ABS,
> +  OPTION_TARGET2,
> +  OPTION_FIX_V4BX,
> +  OPTION_USE_BLX,
> +  OPTION_VFP11_DENORM_FIX,
> +  OPTION_FIX_V4BX_INTERWORKING,
> +  OPTION_FIX_CORTEX_A8,
> +  OPTION_NO_FIX_CORTEX_A8,
> +  OPTION_FIX_ARM1176,
> +  OPTION_NO_FIX_ARM1176,
> +  OPTION_LONG_PLT,
> +  OPTION_STM32L4XX_FIX,
> +  OPTION_CMSE_IMPLIB,
> +  OPTION_IN_IMPLIB,
> +  /* Used by emultempl/avrelf.em.  */
> +  OPTION_NO_CALL_RET_REPLACEMENT,
> +  OPTION_PMEM_WRAP_AROUND,
> +  OPTION_NO_STUBS,
> +  OPTION_DEBUG_STUBS,
> +  OPTION_DEBUG_RELAX,
> +  /* Used by emultempl/bfin.em.  */
> +  OPTION_CODE_IN_L1,
> +  OPTION_DATA_IN_L1,
> +  /* Used by emultempl/cskyelf.em.  */
> +  OPTION_BRANCH_STUB,
> +  OPTION_NO_BRANCH_STUB,
> +  /* Used by emultempl/elf.em.  */
> +  OPTION_DISABLE_NEW_DTAGS,
> +  OPTION_ENABLE_NEW_DTAGS,
> +  OPTION_GROUP,
> +  OPTION_EH_FRAME_HDR,
> +  OPTION_NO_EH_FRAME_HDR,
> +  OPTION_HASH_STYLE,
> +  OPTION_PACKAGE_METADATA,
> +  OPTION_AUDIT,
> +  OPTION_COMPRESS_DEBUG,
> +  /* Used by emultempl/hppaelf.em.  */
> +  OPTION_MULTI_SUBSPACE,
> +  /* Used by emultempl/ia64elf.em.  */
> +  OPTION_ITANIUM,
> +  /* Used by emultempl/m68hc1xelf.em.  */
> +  OPTION_NO_TRAMPOLINE,
> +  OPTION_BANK_WINDOW,
> +  /* Used by emultempl/m68kelf.em.  */
> +  OPTION_GOT,
> +  /* Used by emultempl/mipself.em.  */
> +  OPTION_INSN32,
> +  OPTION_NO_INSN32,
> +  OPTION_IGNORE_BRANCH_ISA,
> +  OPTION_NO_IGNORE_BRANCH_ISA,
> +  OPTION_COMPACT_BRANCHES,
> +  OPTION_NO_COMPACT_BRANCHES,
> +  /* Used by emultempl/msp430.em.  */
> +  OPTION_CODE_REGION,
> +  OPTION_DATA_REGION,
> +  OPTION_DISABLE_TRANS,
> +  /* Used by emultempl/nds32elf.em.  */
> +  OPTION_BASELINE,
> +  OPTION_ELIM_GC_RELOCS,
> +  OPTION_FP_AS_GP,
> +  OPTION_NO_FP_AS_GP,
> +  OPTION_REDUCE_FP_UPDATE,
> +  OPTION_NO_REDUCE_FP_UPDATE,
> +  OPTION_EXPORT_SYMBOLS,
> +  OPTION_HYPER_RELAX,
> +  OPTION_TLSDESC_TRAMPOLINE,
> +  OPTION_NO_TLSDESC_TRAMPOLINE,
> +  /* Used by emultempl/nto.em.  */
> +  OPTION_LAZY_STACK,
> +  /* Used by emultempl/pe.em, emultempl/pep.em and emultempl/beos.em.  */
> +  OPTION_DLL,
> +  OPTION_FILE_ALIGNMENT,
> +  OPTION_IMAGE_BASE,
> +  OPTION_MAJOR_IMAGE_VERSION,
> +  OPTION_MAJOR_OS_VERSION,
> +  OPTION_MAJOR_SUBSYSTEM_VERSION,
> +  OPTION_MINOR_IMAGE_VERSION,
> +  OPTION_MINOR_OS_VERSION,
> +  OPTION_MINOR_SUBSYSTEM_VERSION,
> +  OPTION_SECTION_ALIGNMENT,
> +  OPTION_SUBSYSTEM,
> +  OPTION_HEAP,
> +  OPTION_SUPPORT_OLD_CODE,
> +  OPTION_OUT_DEF,
> +  OPTION_EXPORT_ALL,
> +  OPTION_EXCLUDE_SYMBOLS,
> +  OPTION_EXCLUDE_ALL_SYMBOLS,
> +  OPTION_KILL_ATS,
> +  OPTION_STDCALL_ALIASES,
> +  OPTION_ENABLE_STDCALL_FIXUP,
> +  OPTION_DISABLE_STDCALL_FIXUP,
> +  OPTION_WARN_DUPLICATE_EXPORTS,
> +  OPTION_IMP_COMPAT,
> +  OPTION_ENABLE_AUTO_IMAGE_BASE,
> +  OPTION_DISABLE_AUTO_IMAGE_BASE,
> +  OPTION_DLL_SEARCH_PREFIX,
> +  OPTION_NO_DEFAULT_EXCLUDES,
> +  OPTION_DLL_ENABLE_AUTO_IMPORT,
> +  OPTION_DLL_DISABLE_AUTO_IMPORT,
> +  OPTION_ENABLE_EXTRA_PE_DEBUG,
> +  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC,
> +  OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC,
> +  OPTION_LARGE_ADDRESS_AWARE,
> +  OPTION_DISABLE_LARGE_ADDRESS_AWARE,
> +  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V1,
> +  OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC_V2,
> +  OPTION_EXCLUDE_MODULES_FOR_IMPLIB,
> +  OPTION_USE_NUL_PREFIXED_IMPORT_TABLES,
> +  OPTION_NO_LEADING_UNDERSCORE,
> +  OPTION_LEADING_UNDERSCORE,
> +  OPTION_ENABLE_LONG_SECTION_NAMES,
> +  OPTION_DISABLE_LONG_SECTION_NAMES,
> +  /* DLLCharacteristics flags.  */
> +  OPTION_DYNAMIC_BASE,
> +  OPTION_FORCE_INTEGRITY,
> +  OPTION_NX_COMPAT,
> +  OPTION_NO_ISOLATION,
> +  OPTION_NO_SEH,
> +  OPTION_NO_BIND,
> +  OPTION_WDM_DRIVER,
> +  OPTION_TERMINAL_SERVER_AWARE,
> +  /* Determinism.  */
> +  OPTION_INSERT_TIMESTAMP,
> +  OPTION_NO_INSERT_TIMESTAMP,
> +  OPTION_PDB,
> +  OPTION_ENABLE_RELOC_SECTION,
> +  OPTION_DISABLE_RELOC_SECTION,
> +  /* DLL Characteristics flags.  */
> +  OPTION_DISABLE_DYNAMIC_BASE,
> +  OPTION_DISABLE_FORCE_INTEGRITY,
> +  OPTION_DISABLE_NX_COMPAT,
> +  OPTION_DISABLE_NO_ISOLATION,
> +  OPTION_DISABLE_NO_SEH,
> +  OPTION_DISABLE_NO_BIND,
> +  OPTION_DISABLE_WDM_DRIVER,
> +  OPTION_DISABLE_TERMINAL_SERVER_AWARE,
> +  /* Used by emultempl/pep.em.  */
> +  OPTION_DISABLE_HIGH_ENTROPY_VA,
> +  OPTION_HIGH_ENTROPY_VA,
> +  /* Used by emultempl/ppc32elf.em.  */
> +  OPTION_NEW_PLT,
> +  OPTION_OLD_PLT,
> +  OPTION_OLD_GOT,
> +  OPTION_PPC476_WORKAROUND,
> +  OPTION_NO_PPC476_WORKAROUND,
> +  OPTION_NO_PICFIXUP,
> +  OPTION_VLE_RELOC_FIXUP,
> +  /* Used by emultempl/ppc64elf.em.  */
> +  OPTION_PLT_STATIC_CHAIN,
> +  OPTION_NO_PLT_STATIC_CHAIN,
> +  OPTION_PLT_THREAD_SAFE,
> +  OPTION_NO_PLT_THREAD_SAFE,
> +  OPTION_PLT_LOCALENTRY,
> +  OPTION_NO_PLT_LOCALENTRY,
> +  OPTION_POWER10_STUBS,
> +  OPTION_NO_POWER10_STUBS,
> +  OPTION_NO_PCREL_OPT,
> +  OPTION_SAVRES,
> +  OPTION_NO_SAVRES,
> +  OPTION_DOTSYMS,
> +  OPTION_NO_DOTSYMS,
> +  OPTION_TLS_GET_ADDR_OPT,
> +  OPTION_TLS_GET_ADDR_REGSAVE,
> +  OPTION_NO_TLS_GET_ADDR_REGSAVE,
> +  OPTION_NO_OPD_OPT,
> +  OPTION_NO_TOC_OPT,
> +  OPTION_NO_MULTI_TOC,
> +  OPTION_NO_TOC_SORT,
> +  OPTION_NON_OVERLAPPING_OPD,
> +  /* Used by emultempl/riscvelf.em.  */
> +  OPTION_RELAX_GP,
> +  OPTION_NO_RELAX_GP,
> +  OPTION_CHECK_ULEB128,
> +  OPTION_NO_CHECK_ULEB128,
> +  /* Used by emultempl/rxelf.em.  */
> +  OPTION_NO_FLAG_MISMATCH_WARNINGS,
> +  OPTION_IGNORE_LMA,
> +  OPTION_NO_IGNORE_LMA,
> +  OPTION_FLAG_MISMATCH_WARNINGS,
> +  /* Used by emultempl/s390.em.  */
> +  OPTION_PGSTE,
> +  /* Used by emultempl/spuelf.em.  */
> +  OPTION_SPU_PLUGIN,
> +  OPTION_SPU_NO_OVERLAYS,
> +  OPTION_SPU_COMPACT_STUBS,
> +  OPTION_SPU_STUB_SYMS,
> +  OPTION_SPU_NON_OVERLAY_STUBS,
> +  OPTION_SPU_LOCAL_STORE,
> +  OPTION_SPU_STACK_ANALYSIS,
> +  OPTION_SPU_STACK_SYMS,
> +  OPTION_SPU_AUTO_OVERLAY,
> +  OPTION_SPU_AUTO_RELINK,
> +  OPTION_SPU_OVERLAY_RODATA,
> +  OPTION_SPU_SOFT_ICACHE,
> +  OPTION_SPU_LINE_SIZE,
> +  OPTION_SPU_NUM_LINES,
> +  OPTION_SPU_LRLIVE,
> +  OPTION_SPU_NON_IA_TEXT,
> +  OPTION_SPU_FIXED_SPACE,
> +  OPTION_SPU_RESERVED_SPACE,
> +  OPTION_SPU_EXTRA_STACK,
> +  OPTION_SPU_NO_AUTO_OVERLAY,
> +  OPTION_SPU_EMIT_FIXUPS,
> +  /* Used by emultempl/tic6xdsbt.em.  */
> +  OPTION_DSBT_INDEX,
> +  OPTION_DSBT_SIZE,
> +  /* Used by emultempl/ticoff.em.  */
> +  OPTION_COFF_FORMAT,
> +  /* Used by emultempl/vms.em.  */
> +  OPTION_IDENTIFICATION,
> +  /* Used by emultempl/vxworks.em.  */
> +  OPTION_FORCE_DYNAMIC,
> +  /* Used by emultempl/xtensaelf.em.  */
> +  OPTION_OPT_SIZEOPT,
> +  OPTION_LITERAL_MOVEMENT,
> +  OPTION_NO_LITERAL_MOVEMENT,
> +  OPTION_ABI_WINDOWED,
> +  OPTION_ABI_CALL0,
>  };
>
>  /* The initial parser states.  */
> --
> 2.43.0
>

I ran into this issue while working on the text section ordering file
command option.  I'd like to resolve this before I submit my next
patch.

Any comments, objections on this?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ld: Put all emulation options in ldlex.h
  2024-01-18 15:31 ` H.J. Lu
@ 2024-01-19 10:37   ` Nick Clifton
  0 siblings, 0 replies; 3+ messages in thread
From: Nick Clifton @ 2024-01-19 10:37 UTC (permalink / raw)
  To: H.J. Lu, binutils, Alan Modra, Jan Beulich

Hi H.J.

>> For each command line option, parse_args() calls ldemul_parse_args()
>> to check if the command line option is an emulation option.  But when
>> there is a conflict between the emulation option value and the default
>> option value, the default command line option will be processed as if
>> the emulation option is used. 

Hmm, yes I see how this can be a problem.  Given that the values are statically
allocated and there is know way of knowing how many emulations are going to be
involved in the creation of a single version of the linker, your approach makes
sense.

Patch approved - please apply.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-19 10:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 15:46 [PATCH] ld: Put all emulation options in ldlex.h H.J. Lu
2024-01-18 15:31 ` H.J. Lu
2024-01-19 10:37   ` Nick Clifton

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