* ld-mips-elf/elf-rel-got-n64-linux.d: New file.
[deliverable/binutils-gdb.git] / ld / lexsup.c
index 87a729a4fe28ba5ba967c591cde6c0af92245f34..185a86d63f5ac57d8e66e4365e257fc3887b0b8d 100644 (file)
@@ -1,6 +1,6 @@
 /* Parse options for the GNU linker.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002
+   2001, 2002, 2003
    Free Software Foundation, Inc.
 
    This file is part of GLD, the Gnu Linker.
 #define        S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
 #endif
 
-static int is_num PARAMS ((const char *, int, int, int));
-static void set_default_dirlist PARAMS ((char *));
-static void set_section_start PARAMS ((char *, char *));
-static void help PARAMS ((void));
+static void set_default_dirlist (char *);
+static void set_section_start (char *, char *);
+static void help (void);
 
 /* Non-zero if we are processing a --defsym from the command line.  */
 int parsing_defsym = 0;
@@ -110,7 +109,7 @@ int parsing_defsym = 0;
 #define OPTION_WARN_ONCE               (OPTION_WARN_MULTIPLE_GP + 1)
 #define OPTION_WARN_SECTION_ALIGN      (OPTION_WARN_ONCE + 1)
 #define OPTION_SPLIT_BY_RELOC          (OPTION_WARN_SECTION_ALIGN + 1)
-#define OPTION_SPLIT_BY_FILE           (OPTION_SPLIT_BY_RELOC + 1)
+#define OPTION_SPLIT_BY_FILE           (OPTION_SPLIT_BY_RELOC + 1)
 #define OPTION_WHOLE_ARCHIVE           (OPTION_SPLIT_BY_FILE + 1)
 #define OPTION_WRAP                    (OPTION_WHOLE_ARCHIVE + 1)
 #define OPTION_FORCE_EXE_SUFFIX                (OPTION_WRAP + 1)
@@ -118,15 +117,16 @@ int parsing_defsym = 0;
 #define OPTION_NO_GC_SECTIONS          (OPTION_GC_SECTIONS + 1)
 #define OPTION_CHECK_SECTIONS          (OPTION_NO_GC_SECTIONS + 1)
 #define OPTION_NO_CHECK_SECTIONS       (OPTION_CHECK_SECTIONS + 1)
-#define OPTION_MPC860C0                 (OPTION_NO_CHECK_SECTIONS + 1)
+#define OPTION_MPC860C0                        (OPTION_NO_CHECK_SECTIONS + 1)
 #define OPTION_NO_UNDEFINED            (OPTION_MPC860C0 + 1)
-#define OPTION_INIT                     (OPTION_NO_UNDEFINED + 1)
-#define OPTION_FINI                     (OPTION_INIT + 1)
+#define OPTION_INIT                    (OPTION_NO_UNDEFINED + 1)
+#define OPTION_FINI                    (OPTION_INIT + 1)
 #define OPTION_SECTION_START           (OPTION_FINI + 1)
 #define OPTION_UNIQUE                  (OPTION_SECTION_START + 1)
-#define OPTION_TARGET_HELP              (OPTION_UNIQUE + 1)
+#define OPTION_TARGET_HELP             (OPTION_UNIQUE + 1)
 #define OPTION_ALLOW_SHLIB_UNDEFINED   (OPTION_TARGET_HELP + 1)
-#define OPTION_ALLOW_MULTIPLE_DEFINITION (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
+#define OPTION_NO_ALLOW_SHLIB_UNDEFINED        (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
+#define OPTION_ALLOW_MULTIPLE_DEFINITION (OPTION_NO_ALLOW_SHLIB_UNDEFINED + 1)
 #define OPTION_NO_UNDEFINED_VERSION    (OPTION_ALLOW_MULTIPLE_DEFINITION + 1)
 #define OPTION_DISCARD_NONE            (OPTION_NO_UNDEFINED_VERSION + 1)
 #define OPTION_SPARE_DYNAMIC_TAGS      (OPTION_DISCARD_NONE + 1)
@@ -137,6 +137,7 @@ int parsing_defsym = 0;
 #define OPTION_NO_STRIP_DISCARDED      (OPTION_STRIP_DISCARDED + 1)
 #define OPTION_ACCEPT_UNKNOWN_INPUT_ARCH    (OPTION_NO_STRIP_DISCARDED + 1)
 #define OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_ACCEPT_UNKNOWN_INPUT_ARCH + 1)
+#define OPTION_PIE                     (OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH + 1)
 
 /* The long options.  This structure is used for both the option
    parsing and the help text.  */
@@ -232,8 +233,8 @@ static const struct ld_option ld_options[] =
       '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
   { {"emit-relocs", no_argument, NULL, 'q'},
       'q', NULL, "Generate relocations in final output", TWO_DASHES },
-  { {"relocateable", no_argument, NULL, 'r'},
-      'r', NULL, N_("Generate relocateable output"), TWO_DASHES },
+  { {"relocatable", no_argument, NULL, 'r'},
+      'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
   { {NULL, no_argument, NULL, '\0'},
       'i', NULL, NULL, ONE_DASH },
   { {"just-symbols", required_argument, NULL, 'R'},
@@ -335,7 +336,9 @@ static const struct ld_option ld_options[] =
   { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
      '\0', NULL, N_("Allow no undefined symbols"), TWO_DASHES },
   { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
-     '\0', NULL, N_("Allow undefined symbols in shared objects"), TWO_DASHES },
+     '\0', NULL, N_("Allow undefined symbols in shared objects (the default)"), TWO_DASHES },
+  { {"no-allow-shlib-undefined", no_argument, NULL, OPTION_NO_ALLOW_SHLIB_UNDEFINED},
+     '\0', NULL, N_("Do not allow undefined symbols in shared objects"), TWO_DASHES },
   { {"allow-multiple-definition", no_argument, NULL, OPTION_ALLOW_MULTIPLE_DEFINITION},
      '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
   { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
@@ -367,6 +370,10 @@ static const struct ld_option ld_options[] =
       '\0', NULL, N_("Create a shared library"), ONE_DASH },
   { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD.  */
       '\0', NULL, NULL, ONE_DASH },
+  { {"pie", no_argument, NULL, OPTION_PIE},
+      '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
+  { {"pic-executable", no_argument, NULL, OPTION_PIE},
+      '\0', NULL, NULL, TWO_DASHES },
   { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
       '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
   { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
@@ -432,11 +439,7 @@ static const struct ld_option ld_options[] =
    between MIN and MAX.  The return value is the number or ERR.  */
 
 static int
-is_num (string, min, max, err)
-     const char *string;
-     int min;
-     int max;
-     int err;
+is_num (const char *string, int min, int max, int err)
 {
   int result = 0;
 
@@ -456,19 +459,21 @@ is_num (string, min, max, err)
 }
 
 void
-parse_args (argc, argv)
-     unsigned argc;
-     char **argv;
+parse_args (unsigned argc, char **argv)
 {
   unsigned i;
   int is, il, irl;
   int ingroup = 0;
   char *default_dirlist = NULL;
-  char shortopts[OPTION_COUNT * 3 + 2];
-  struct option longopts[OPTION_COUNT + 1];
-  struct option really_longopts[OPTION_COUNT + 1];
+  char *shortopts;
+  struct option *longopts;
+  struct option *really_longopts;
   int last_optind;
 
+  shortopts = xmalloc (OPTION_COUNT * 3 + 2);
+  longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
+  really_longopts = xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
+
   /* Starting the short option string with '-' is for programs that
      expect options and other ARGV-elements in any order and that care about
      the ordering of the two.  We describe each non-option ARGV-element
@@ -513,6 +518,8 @@ parse_args (argc, argv)
   longopts[il].name = NULL;
   really_longopts[irl].name = NULL;
 
+  ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
+
   /* The -G option is ambiguous on different platforms.  Sometimes it
      specifies the largest data size to put into the small data
      section.  Sometimes it is equivalent to --shared.  Unfortunately,
@@ -550,7 +557,7 @@ parse_args (argc, argv)
        {
          char *n;
 
-         n = (char *) xmalloc (strlen (argv[i]) + 20);
+         n = xmalloc (strlen (argv[i]) + 20);
          sprintf (n, "--library=%s", argv[i] + 2);
          argv[i] = n;
        }
@@ -583,6 +590,9 @@ parse_args (argc, argv)
          optc = getopt_long (argc, argv, "-", really_longopts, &longind);
        }
 
+      if (ldemul_handle_option (optc))
+       continue;
+
       if (optc == -1)
        break;
 
@@ -594,16 +604,15 @@ parse_args (argc, argv)
          einfo (_("%P%F: use the --help option for usage information\n"));
 
        case 1:                 /* File name.  */
-         lang_add_input_file (optarg, lang_input_file_is_file_enum,
-                              (char *) NULL);
+         lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
          break;
 
        case OPTION_IGNORE:
          break;
        case 'a':
          /* For HP/UX compatibility.  Actually -a shared should mean
-             ``use only shared libraries'' but, then, we don't
-             currently support shared libraries on HP/UX anyhow.  */
+            ``use only shared libraries'' but, then, we don't
+            currently support shared libraries on HP/UX anyhow.  */
          if (strcmp (optarg, "archive") == 0)
            config.dynamic_link = FALSE;
          else if (strcmp (optarg, "shared") == 0
@@ -695,8 +704,7 @@ parse_args (argc, argv)
        case 'f':
          if (command_line.auxiliary_filters == NULL)
            {
-             command_line.auxiliary_filters =
-               (char **) xmalloc (2 * sizeof (char *));
+             command_line.auxiliary_filters = xmalloc (2 * sizeof (char *));
              command_line.auxiliary_filters[0] = optarg;
              command_line.auxiliary_filters[1] = NULL;
            }
@@ -708,9 +716,9 @@ parse_args (argc, argv)
              c = 0;
              for (p = command_line.auxiliary_filters; *p != NULL; p++)
                ++c;
-             command_line.auxiliary_filters =
-               (char **) xrealloc (command_line.auxiliary_filters,
-                                   (c + 2) * sizeof (char *));
+             command_line.auxiliary_filters
+               = xrealloc (command_line.auxiliary_filters,
+                           (c + 2) * sizeof (char *));
              command_line.auxiliary_filters[c] = optarg;
              command_line.auxiliary_filters[c + 1] = NULL;
            }
@@ -743,8 +751,7 @@ parse_args (argc, argv)
          ldfile_add_library_path (optarg, TRUE);
          break;
        case 'l':
-         lang_add_input_file (optarg, lang_input_file_is_l_enum,
-                              (char *) NULL);
+         lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
          break;
        case 'M':
          config.map_filename = "-";
@@ -788,6 +795,9 @@ parse_args (argc, argv)
        case OPTION_ALLOW_SHLIB_UNDEFINED:
          link_info.allow_shlib_undefined = TRUE;
          break;
+       case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
+         link_info.allow_shlib_undefined = FALSE;
+         break;
        case OPTION_ALLOW_MULTIPLE_DEFINITION:
          link_info.allow_multiple_definition = TRUE;
          break;
@@ -820,7 +830,7 @@ parse_args (argc, argv)
          lang_add_output (optarg, 0);
          break;
        case OPTION_OFORMAT:
-         lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0);
+         lang_add_output_format (optarg, NULL, NULL, 0);
          break;
        case 'q':
          link_info.emitrelocations = TRUE;
@@ -838,7 +848,7 @@ parse_args (argc, argv)
               and will seg-fault the next time around.  */
            einfo(_("%P%F: bad -rpath option\n"));
 
-         link_info.relocateable = TRUE;
+         link_info.relocatable = TRUE;
          config.build_constructors = FALSE;
          config.magic_demand_paged = FALSE;
          config.text_read_only = FALSE;
@@ -860,7 +870,7 @@ parse_args (argc, argv)
              {
                lang_add_input_file (optarg,
                                     lang_input_file_is_symbols_only_enum,
-                                    (char *) NULL);
+                                    NULL);
                break;
              }
          }
@@ -942,6 +952,15 @@ parse_args (argc, argv)
          else
            einfo (_("%P%F: -shared not supported\n"));
          break;
+       case OPTION_PIE:
+         if (config.has_shared)
+           {
+             link_info.shared = TRUE;
+             link_info.pie = TRUE;
+           }
+         else
+           einfo (_("%P%F: -pie not supported\n"));
+         break;
        case 'h':               /* Used on Solaris.  */
        case OPTION_SONAME:
          command_line.soname = optarg;
@@ -1011,7 +1030,7 @@ parse_args (argc, argv)
          link_info.task_link = TRUE;
          /* Fall through - do an implied -r option.  */
        case OPTION_UR:
-         link_info.relocateable = TRUE;
+         link_info.relocatable = TRUE;
          config.build_constructors = TRUE;
          config.magic_demand_paged = FALSE;
          config.text_read_only = FALSE;
@@ -1030,6 +1049,7 @@ parse_args (argc, argv)
          ldversion (1);
          version_printed = TRUE;
          trace_file_tries = TRUE;
+         overflow_cutoff_limit = -2;
          break;
        case 'v':
          ldversion (0);
@@ -1045,8 +1065,8 @@ parse_args (argc, argv)
          break;
        case OPTION_VERSION_SCRIPT:
          /* This option indicates a small script that only specifies
-             version information.  Read it, but don't assume that
-             we've seen a linker script.  */
+            version information.  Read it, but don't assume that
+            we've seen a linker script.  */
          {
            FILE *hold_script_handle;
 
@@ -1099,6 +1119,8 @@ parse_args (argc, argv)
        case 'Y':
          if (strncmp (optarg, "P,", 2) == 0)
            optarg += 2;
+         if (default_dirlist != NULL)
+           free (default_dirlist);
          default_dirlist = xstrdup (optarg);
          break;
        case 'y':
@@ -1176,16 +1198,17 @@ parse_args (argc, argv)
     lang_leave_group ();
 
   if (default_dirlist != NULL)
-    set_default_dirlist (default_dirlist);
-
+    {
+      set_default_dirlist (default_dirlist);
+      free (default_dirlist);
+    }
 }
 
 /* Add the (colon-separated) elements of DIRLIST_PTR to the
    library search path.  */
 
 static void
-set_default_dirlist (dirlist_ptr)
-     char *dirlist_ptr;
+set_default_dirlist (char *dirlist_ptr)
 {
   char *p;
 
@@ -1203,8 +1226,7 @@ set_default_dirlist (dirlist_ptr)
 }
 
 static void
-set_section_start (sect, valstr)
-     char *sect, *valstr;
+set_section_start (char *sect, char *valstr)
 {
   const char *end;
   bfd_vma val = bfd_scan_vma (valstr, &end, 16);
@@ -1216,7 +1238,7 @@ set_section_start (sect, valstr)
 /* Print help messages for the options.  */
 
 static void
-help ()
+help (void)
 {
   unsigned i;
   const char **targets, **pp;
This page took 0.027288 seconds and 4 git commands to generate.