Print this page
4270 ld(1) argument error reporting is still pretty bad
4227 ld --library-path is translated to -l-path, not -L

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/sgs/libld/common/util.c
          +++ new/usr/src/cmd/sgs/libld/common/util.c
↓ open down ↓ 293 lines elided ↑ open up ↑
 294  294  
 295  295          if ((str = libld_malloc(len)) == NULL)
 296  296                  return ('?');
 297  297          (void) snprintf(str, len, MSG_ORIG(MSG_FMT_STRCAT),
 298  298              MSG_ORIG(MSG_ARG_WRAP), optarg);
 299  299          optarg = str;
 300  300          return (c);
 301  301  }
 302  302  
 303  303  /*
 304      - * Determine whether this string, possibly with an associated option, should be
 305      - * translated to an option character.  If so, update the optind and optarg
 306      - * as described for short options in getopt(3c).
      304 + * Determine whether this string, possibly with an associated option, should
      305 + * be translated to an option character.  If so, update the optind and optarg
      306 + * and optopt as described for short options in getopt(3c).
 307  307   *
 308  308   * entry:
 309  309   *      lml - Link map list for debug messages
 310  310   *      ndx - Starting optind for current item
 311  311   *      argc, argv - Command line arguments
 312  312   *      arg - Option to be examined
 313  313   *      c, opt - Option character (c) and corresponding long name (opt)
 314  314   *      optsz - 0 if option does not accept a value. If option does
 315  315   *              accept a value, strlen(opt), giving the offset to the
 316  316   *              value if the option and value are combined in one string.
↓ open down ↓ 5 lines elided ↑ open up ↑
 322  322      const char *opt, size_t optsz, int cbfunc(int))
 323  323  {
 324  324          if (optsz == 0) {
 325  325                  /*
 326  326                   * Compare a single option (ie. there's no associated option
 327  327                   * argument).
 328  328                   */
 329  329                  if (strcmp(arg, opt) == 0) {
 330  330                          DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 331  331                          optind += 1;
      332 +                        optopt = c;
 332  333                          return (c);
 333  334                  }
 334      -
 335      -        } else if (strncmp(arg, opt, optsz) == 0) {
      335 +        } else if ((strcmp(arg, opt) == 0) ||
      336 +            ((arg[optsz] == '=') && strncmp(arg, opt, optsz) == 0)) {
 336  337                  /*
 337  338                   * Otherwise, compare the option name, which may be
 338  339                   * concatenated with the option argument.
 339  340                   */
 340  341                  DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 341  342  
 342  343                  if (arg[optsz] == '\0') {
 343  344                          /*
 344  345                           * Optarg is the next argument (white space separated).
 345  346                           * Make sure an optarg is available, and if not return
 346  347                           * a failure to prevent any fall-through to the generic
 347  348                           * getopt() processing.
      349 +                         *
      350 +                         * Since we'll be completely failing this option we
      351 +                         * don't want to update optopt with the translation,
      352 +                         * but also need to set it to _something_.  Setting it
      353 +                         * to the '-' of the argument causes us to behave
      354 +                         * correctly.
 348  355                           */
 349  356                          if ((++optind + 1) > argc) {
      357 +                                optopt = arg[0];
 350  358                                  return ('?');
 351  359                          }
 352  360                          optarg = argv[optind];
 353  361                          optind++;
 354  362                  } else {
 355  363                          /*
 356      -                         * Optarg concatenated to option (no white space).
 357  364                           * GNU option/option argument pairs can be represented
 358  365                           * with a "=" separator.  If this is the case, remove
 359  366                           * the separator.
 360  367                           */
 361  368                          optarg = &arg[optsz];
 362  369                          optind++;
 363  370                          if (*optarg == '=') {
 364  371                                  if (*(++optarg) == '\0')
      372 +                                        optopt = arg[0];
 365  373                                          return ('?');
 366  374                          }
 367  375                  }
 368  376  
 369  377                  if (cbfunc != NULL)
 370  378                          c = (*cbfunc)(c);
 371      -
      379 +                optopt = c;
 372  380                  return (c);
 373  381          }
 374  382          return (0);
 375  383  }
 376  384  
 377  385  /*
 378  386   * Parse an individual option.  The intent of this function is to determine if
 379  387   * any known, non-Solaris options have been passed to ld(1).  This condition
 380  388   * can occur as a result of build configuration tools, because of users
 381  389   * familiarity with other systems, or simply the users preferences.  If a known
↓ open down ↓ 380 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX