ld -z options

Alan Modra amodra@gmail.com
Thu Jul 14 03:29:00 GMT 2011


On Wed, Jul 13, 2011 at 04:07:35PM -0700, Ian Lance Taylor wrote:
> Alan Modra <amodra@gmail.com> writes:
> 
> > I found today that none of the ld -z options are available on ELF
> > targets that lack shared lib support (unless the target happens to
> > provide some target specific options, which is weird).  This patch
> > rearranges the option support code in elf32.em to make a few useful
> > options generally available, and moves a couple of x86/x86_64 options
> > out of the general set.  I'll commit this after running tests
> > overnight.
> 
> While you're looking at this, how would you feel about making the linker
> give a warning or error when an unrecognized -z option is used?

Done.  A warning seems reasonable.  I've also taken out the
"-z KEYWORD Ignored for Solaris compatibility" help message, and moved
emultempl/plt_unwind.em to emulparams/plt_unwind.sh so that it doesn't
conflict with other uses of EXTRA_EM_FILE.

	* emultempl/elf32.em (gld${EMULATION_NAME}_add_options,
	gld${EMULATION_NAME}_handle_option, gld${EMULATION_NAME}_list_options):
	Provide --build-id, -z defs, -z muldefs, -z max-page-size,
	-z common-page-size, -z execstack, -z noexecstack for all targets.
	Add help for --exclude-libs.
	(OPTION_LD_GENERATED_UNWIND_INFO,
	OPTION_NO_LD_GENERATED_UNWIND_INFO): Move this..
	(gld${EMULATION_NAME}_handle_option): ..and code handling
	--ld-generated-unwind-info and --no-ld-generated-unwind-info..
	* emulparams/plt_unwind.sh: ..to here.  New file.  Add help.
	* emulparams/elf32_x86_64.sh: Include plt_unwind.sh.
	* emulparams/elf_i386.sh: Likewise.
	* emulparams/elf_i386_chaos.sh: Likewise.
	* emulparams/elf_i386_ldso.sh: Likewise.
	* emulparams/elf_l1om.sh: Likewise.
	* emulparams/elf_x86_64.sh: Likewise.

Index: ld/emulparams/elf32_x86_64.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32_x86_64.sh,v
retrieving revision 1.2
diff -u -p -r1.2 elf32_x86_64.sh
--- ld/emulparams/elf32_x86_64.sh	16 Feb 2011 19:14:41 -0000	1.2
+++ ld/emulparams/elf32_x86_64.sh	14 Jul 2011 02:12:01 -0000
@@ -1,3 +1,4 @@
+. ${srcdir}/emulparams/plt_unwind.sh
 SCRIPT_NAME=elf
 ELFSIZE=32
 OUTPUT_FORMAT="elf32-x86-64"
Index: ld/emulparams/elf_i386.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_i386.sh,v
retrieving revision 1.10
diff -u -p -r1.10 elf_i386.sh
--- ld/emulparams/elf_i386.sh	29 Jul 2009 14:59:23 -0000	1.10
+++ ld/emulparams/elf_i386.sh	14 Jul 2011 02:12:01 -0000
@@ -1,3 +1,4 @@
+. ${srcdir}/emulparams/plt_unwind.sh
 SCRIPT_NAME=elf
 OUTPUT_FORMAT="elf32-i386"
 NO_RELA_RELOCS=yes
Index: ld/emulparams/elf_i386_chaos.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_i386_chaos.sh,v
retrieving revision 1.6
diff -u -p -r1.6 elf_i386_chaos.sh
--- ld/emulparams/elf_i386_chaos.sh	9 Aug 2007 11:02:24 -0000	1.6
+++ ld/emulparams/elf_i386_chaos.sh	14 Jul 2011 02:12:01 -0000
@@ -1,3 +1,4 @@
+. ${srcdir}/emulparams/plt_unwind.sh
 SCRIPT_NAME=elf_chaos
 OUTPUT_FORMAT="elf32-i386"
 TEXT_START_ADDR=0x40000000
Index: ld/emulparams/elf_i386_ldso.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_i386_ldso.sh,v
retrieving revision 1.6
diff -u -p -r1.6 elf_i386_ldso.sh
--- ld/emulparams/elf_i386_ldso.sh	22 Oct 2008 05:20:44 -0000	1.6
+++ ld/emulparams/elf_i386_ldso.sh	14 Jul 2011 02:12:01 -0000
@@ -1,3 +1,4 @@
+. ${srcdir}/emulparams/plt_unwind.sh
 SCRIPT_NAME=elf
 OUTPUT_FORMAT="elf32-i386"
 NO_RELA_RELOCS=yes
Index: ld/emulparams/elf_l1om.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_l1om.sh,v
retrieving revision 1.2
diff -u -p -r1.2 elf_l1om.sh
--- ld/emulparams/elf_l1om.sh	31 Mar 2011 22:23:09 -0000	1.2
+++ ld/emulparams/elf_l1om.sh	14 Jul 2011 02:12:01 -0000
@@ -1,3 +1,4 @@
+. ${srcdir}/emulparams/plt_unwind.sh
 SCRIPT_NAME=elf
 ELFSIZE=64
 OUTPUT_FORMAT="elf64-l1om"
Index: ld/emulparams/elf_x86_64.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf_x86_64.sh,v
retrieving revision 1.22
diff -u -p -r1.22 elf_x86_64.sh
--- ld/emulparams/elf_x86_64.sh	29 Jul 2009 14:59:23 -0000	1.22
+++ ld/emulparams/elf_x86_64.sh	14 Jul 2011 02:12:01 -0000
@@ -1,3 +1,4 @@
+. ${srcdir}/emulparams/plt_unwind.sh
 SCRIPT_NAME=elf
 ELFSIZE=64
 OUTPUT_FORMAT="elf64-x86-64"
Index: ld/emulparams/plt_unwind.sh
===================================================================
RCS file: ld/emulparams/plt_unwind.sh
diff -N ld/emulparams/plt_unwind.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/emulparams/plt_unwind.sh	14 Jul 2011 02:34:57 -0000
@@ -0,0 +1,28 @@
+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},
+  {"no-ld-generated-unwind-info", no_argument, NULL,
+   OPTION_NO_LD_GENERATED_UNWIND_INFO},
+'
+
+PARSE_AND_LIST_OPTIONS='
+  fprintf (file, _("\
+  --ld-generated-unwind-info  Generate exception handling info for PLT.\n\
+  --no-ld-generated-unwind-info Don'\''t do so.\n"
+		   ));
+'
+
+PARSE_AND_LIST_ARGS_CASES='
+    case OPTION_LD_GENERATED_UNWIND_INFO:
+      link_info.no_ld_generated_unwind_info = FALSE;
+      break;
+
+    case OPTION_NO_LD_GENERATED_UNWIND_INFO:
+      link_info.no_ld_generated_unwind_info = TRUE;
+      break;
+'
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.220
diff -u -p -r1.220 elf32.em
--- ld/emultempl/elf32.em	20 Jun 2011 13:18:48 -0000	1.220
+++ ld/emultempl/elf32.em	14 Jul 2011 02:12:02 -0000
@@ -2106,8 +2106,6 @@ EOF
 fi
 fi
 
-if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
-
 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
 fragment <<EOF
  $PARSE_AND_LIST_PROLOGUE
@@ -2124,42 +2122,49 @@ fragment <<EOF
 #define OPTION_HASH_STYLE		(OPTION_EXCLUDE_LIBS + 1)
 #define OPTION_BUILD_ID			(OPTION_HASH_STYLE + 1)
 #define OPTION_AUDIT			(OPTION_BUILD_ID + 1)
-#define OPTION_LD_GENERATED_UNWIND_INFO	(OPTION_AUDIT + 1)
-#define OPTION_NO_LD_GENERATED_UNWIND_INFO (OPTION_LD_GENERATED_UNWIND_INFO + 1)
 
 static void
 gld${EMULATION_NAME}_add_options
   (int ns, char **shortopts, int nl, struct option **longopts,
    int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
 {
+EOF
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
   static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
+EOF
+else
+fragment <<EOF
+  static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
+EOF
+fi
+fragment <<EOF
   static const struct option xtra_long[] = {
-    {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
+EOF
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
     {"audit", required_argument, NULL, OPTION_AUDIT},
-    {"depaudit", required_argument, NULL, 'P'},
+    {"Bgroup", no_argument, NULL, OPTION_GROUP},
+EOF
+fi
+fragment <<EOF
+    {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
 EOF
-
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 fragment <<EOF
+    {"depaudit", required_argument, NULL, 'P'},
     {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
     {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
     {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
     {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
     {"hash-style", required_argument, NULL, OPTION_HASH_STYLE},
-    {"ld-generated-unwind-info", no_argument, NULL,
-      OPTION_LD_GENERATED_UNWIND_INFO},
-    {"no-ld-generated-unwind-info", no_argument, NULL,
-      OPTION_NO_LD_GENERATED_UNWIND_INFO},
-    {"Bgroup", no_argument, NULL, OPTION_GROUP},
 EOF
 fi
-
 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
 fragment <<EOF
     $PARSE_AND_LIST_LONGOPTS
 EOF
 fi
-
 fragment <<EOF
     {NULL, no_argument, NULL, 0}
   };
@@ -2192,17 +2197,19 @@ gld${EMULATION_NAME}_handle_option (int 
       if (strcmp (optarg, "none"))
 	link_info.emit_note_gnu_build_id = xstrdup (optarg);
       break;
+
+EOF
+
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
     case OPTION_AUDIT:
   	gld${EMULATION_NAME}_append_to_separated_string (&audit, optarg); 
 	break;
+
     case 'P':
 	gld${EMULATION_NAME}_append_to_separated_string (&depaudit, optarg);
 	break;
 
-EOF
-
-if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
-fragment <<EOF
     case OPTION_DISABLE_NEW_DTAGS:
       link_info.new_dtags = FALSE;
       break;
@@ -2215,14 +2222,6 @@ fragment <<EOF
       link_info.eh_frame_hdr = TRUE;
       break;
 
-    case OPTION_LD_GENERATED_UNWIND_INFO:
-      link_info.no_ld_generated_unwind_info = FALSE;
-      break;
-
-    case OPTION_NO_LD_GENERATED_UNWIND_INFO:
-      link_info.no_ld_generated_unwind_info = TRUE;
-      break;
-
     case OPTION_GROUP:
       link_info.flags_1 |= (bfd_vma) DF_1_GROUP;
       /* Groups must be self-contained.  */
@@ -2250,8 +2249,46 @@ fragment <<EOF
 	einfo (_("%P%F: invalid hash style \`%s'\n"), optarg);
       break;
 
+EOF
+fi
+fragment <<EOF
     case 'z':
-      if (strcmp (optarg, "initfirst") == 0)
+      if (strcmp (optarg, "defs") == 0)
+	link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
+      else if (strcmp (optarg, "muldefs") == 0)
+	link_info.allow_multiple_definition = TRUE;
+      else if (CONST_STRNEQ (optarg, "max-page-size="))
+	{
+	  char *end;
+
+	  config.maxpagesize = strtoul (optarg + 14, &end, 0);
+	  if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
+	    einfo (_("%P%F: invalid maxium page size \`%s'\n"),
+		   optarg + 14);
+	}
+      else if (CONST_STRNEQ (optarg, "common-page-size="))
+	{
+	  char *end;
+	  config.commonpagesize = strtoul (optarg + 17, &end, 0);
+	  if (*end
+	      || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
+	    einfo (_("%P%F: invalid common page size \`%s'\n"),
+		   optarg + 17);
+	}
+      else if (strcmp (optarg, "execstack") == 0)
+	{
+	  link_info.execstack = TRUE;
+	  link_info.noexecstack = FALSE;
+	}
+      else if (strcmp (optarg, "noexecstack") == 0)
+	{
+	  link_info.noexecstack = TRUE;
+	  link_info.execstack = FALSE;
+	}
+EOF
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
+      else if (strcmp (optarg, "initfirst") == 0)
 	link_info.flags_1 |= (bfd_vma) DF_1_INITFIRST;
       else if (strcmp (optarg, "interpose") == 0)
 	link_info.flags_1 |= (bfd_vma) DF_1_INTERPOSE;
@@ -2280,26 +2317,12 @@ fragment <<EOF
 	  link_info.flags |= (bfd_vma) DF_ORIGIN;
 	  link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN;
 	}
-      else if (strcmp (optarg, "defs") == 0)
-	link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
-      else if (strcmp (optarg, "muldefs") == 0)
-	link_info.allow_multiple_definition = TRUE;
       else if (strcmp (optarg, "combreloc") == 0)
 	link_info.combreloc = TRUE;
       else if (strcmp (optarg, "nocombreloc") == 0)
 	link_info.combreloc = FALSE;
       else if (strcmp (optarg, "nocopyreloc") == 0)
 	link_info.nocopyreloc = TRUE;
-      else if (strcmp (optarg, "execstack") == 0)
-	{
-	  link_info.execstack = TRUE;
-	  link_info.noexecstack = FALSE;
-	}
-      else if (strcmp (optarg, "noexecstack") == 0)
-	{
-	  link_info.noexecstack = TRUE;
-	  link_info.execstack = FALSE;
-	}
 EOF
 
   if test -n "$COMMONPAGESIZE"; then
@@ -2310,30 +2333,13 @@ fragment <<EOF
 	link_info.relro = FALSE;
 EOF
   fi
+fi
 
 fragment <<EOF
-      else if (CONST_STRNEQ (optarg, "max-page-size="))
-	{
-	  char *end;
-
-	  config.maxpagesize = strtoul (optarg + 14, &end, 0);
-	  if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
-	    einfo (_("%P%F: invalid maxium page size \`%s'\n"),
-		   optarg + 14);
-	}
-      else if (CONST_STRNEQ (optarg, "common-page-size="))
-	{
-	  char *end;
-	  config.commonpagesize = strtoul (optarg + 17, &end, 0);
-	  if (*end
-	      || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
-	    einfo (_("%P%F: invalid common page size \`%s'\n"),
-		   optarg + 17);
-	}
-      /* What about the other Solaris -z options? FIXME.  */
+      else
+	einfo (_("%P: warning: -z %s ignored.\n"), optarg);
       break;
 EOF
-fi
 
 if test -n "$PARSE_AND_LIST_ARGS_CASES" ; then
 fragment <<EOF
@@ -2355,19 +2361,24 @@ fragment <<EOF
 static void
 gld${EMULATION_NAME}_list_options (FILE * file)
 {
-  fprintf (file, _("\
-  --build-id[=STYLE]          Generate build ID note\n"));
+EOF
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
   fprintf (file, _("\
   --audit=AUDITLIB            Specify a library to use for auditing\n"));
   fprintf (file, _("\
-  -P AUDITLIB, --depaudit=AUDITLIB\n" "\
-                              Specify a library to use for auditing dependencies\n"));
+  -Bgroup                     Selects group name lookup rules for DSO\n"));
+EOF
+fi
+fragment <<EOF
+  fprintf (file, _("\
+  --build-id[=STYLE]          Generate build ID note\n"));
 EOF
-
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 fragment <<EOF
   fprintf (file, _("\
-  -Bgroup                     Selects group name lookup rules for DSO\n"));
+  -P AUDITLIB, --depaudit=AUDITLIB\n" "\
+                              Specify a library to use for auditing dependencies\n"));
   fprintf (file, _("\
   --disable-new-dtags         Disable new dynamic tags\n"));
   fprintf (file, _("\
@@ -2375,13 +2386,25 @@ fragment <<EOF
   fprintf (file, _("\
   --eh-frame-hdr              Create .eh_frame_hdr section\n"));
   fprintf (file, _("\
+  --exclude-libs=LIBS         Make all symbols in LIBS hidden\n"));
+  fprintf (file, _("\
   --hash-style=STYLE          Set hash style to sysv, gnu or both\n"));
   fprintf (file, _("\
   -z combreloc                Merge dynamic relocs into one section and sort\n"));
+EOF
+fi
+
+fragment <<EOF
+  fprintf (file, _("\
+  -z common-page-size=SIZE    Set common page size to SIZE\n"));
   fprintf (file, _("\
   -z defs                     Report unresolved symbols in object files.\n"));
   fprintf (file, _("\
   -z execstack                Mark executable as requiring executable stack\n"));
+EOF
+
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
   fprintf (file, _("\
   -z initfirst                Mark DSO to be initialized first at runtime\n"));
   fprintf (file, _("\
@@ -2390,8 +2413,18 @@ fragment <<EOF
   -z lazy                     Mark object lazy runtime binding (default)\n"));
   fprintf (file, _("\
   -z loadfltr                 Mark object requiring immediate process\n"));
+EOF
+fi
+
+fragment <<EOF
+  fprintf (file, _("\
+  -z max-page-size=SIZE       Set maximum page size to SIZE\n"));
   fprintf (file, _("\
   -z muldefs                  Allow multiple definitions\n"));
+EOF
+
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
+fragment <<EOF
   fprintf (file, _("\
   -z nocombreloc              Don't merge dynamic relocs into one section\n"));
   fprintf (file, _("\
@@ -2404,10 +2437,13 @@ fragment <<EOF
   -z nodlopen                 Mark DSO not available to dlopen\n"));
   fprintf (file, _("\
   -z nodump                   Mark DSO not available to dldump\n"));
+EOF
+fi
+fragment <<EOF
   fprintf (file, _("\
   -z noexecstack              Mark executable as not requiring executable stack\n"));
 EOF
-
+if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
   if test -n "$COMMONPAGESIZE"; then
 fragment <<EOF
   fprintf (file, _("\
@@ -2429,15 +2465,6 @@ fragment <<EOF
   -z relro                    Create RELRO program header\n"));
 EOF
   fi
-
-fragment <<EOF
-  fprintf (file, _("\
-  -z max-page-size=SIZE       Set maximum page size to SIZE\n"));
-  fprintf (file, _("\
-  -z common-page-size=SIZE    Set common page size to SIZE\n"));
-  fprintf (file, _("\
-  -z KEYWORD                  Ignored for Solaris compatibility\n"));
-EOF
 fi
 
 if test -n "$PARSE_AND_LIST_OPTIONS" ; then
@@ -2456,17 +2483,6 @@ fragment <<EOF
 EOF
 fi
 fi
-else
-fragment <<EOF
-#define gld${EMULATION_NAME}_add_options NULL
-#define gld${EMULATION_NAME}_handle_option NULL
-EOF
-if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
-fragment <<EOF
-#define gld${EMULATION_NAME}_list_options NULL
-EOF
-fi
-fi
 
 fragment <<EOF
 


-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list