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


 284  * changes optarg to include the missing wrap= prefix.
 285  *
 286  * exit:
 287  *      Returns c on success, or '?' on error.
 288  */
 289 static int
 290 str2chr_wrap_cb(int c)
 291 {
 292         char    *str;
 293         size_t  len = MSG_ARG_WRAP_SIZE + strlen(optarg) + 1;
 294 
 295         if ((str = libld_malloc(len)) == NULL)
 296                 return ('?');
 297         (void) snprintf(str, len, MSG_ORIG(MSG_FMT_STRCAT),
 298             MSG_ORIG(MSG_ARG_WRAP), optarg);
 299         optarg = str;
 300         return (c);
 301 }
 302 
 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).
 307  *
 308  * entry:
 309  *      lml - Link map list for debug messages
 310  *      ndx - Starting optind for current item
 311  *      argc, argv - Command line arguments
 312  *      arg - Option to be examined
 313  *      c, opt - Option character (c) and corresponding long name (opt)
 314  *      optsz - 0 if option does not accept a value. If option does
 315  *              accept a value, strlen(opt), giving the offset to the
 316  *              value if the option and value are combined in one string.
 317  *      cbfunc - NULL, or pointer to function to call if a translation is
 318  *              successful.
 319  */
 320 static int
 321 str2chr(Lm_list *lml, int ndx, int argc, char **argv, char *arg, int c,
 322     const char *opt, size_t optsz, int cbfunc(int))
 323 {
 324         if (optsz == 0) {
 325                 /*
 326                  * Compare a single option (ie. there's no associated option
 327                  * argument).
 328                  */
 329                 if (strcmp(arg, opt) == 0) {
 330                         DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 331                         optind += 1;

 332                         return (c);
 333                 }
 334 
 335         } else if (strncmp(arg, opt, optsz) == 0) {
 336                 /*
 337                  * Otherwise, compare the option name, which may be
 338                  * concatenated with the option argument.
 339                  */
 340                 DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 341 
 342                 if (arg[optsz] == '\0') {
 343                         /*
 344                          * Optarg is the next argument (white space separated).
 345                          * Make sure an optarg is available, and if not return
 346                          * a failure to prevent any fall-through to the generic
 347                          * getopt() processing.






 348                          */
 349                         if ((++optind + 1) > argc) {

 350                                 return ('?');
 351                         }
 352                         optarg = argv[optind];
 353                         optind++;
 354                 } else {
 355                         /*
 356                          * Optarg concatenated to option (no white space).
 357                          * GNU option/option argument pairs can be represented
 358                          * with a "=" separator.  If this is the case, remove
 359                          * the separator.
 360                          */
 361                         optarg = &arg[optsz];
 362                         optind++;
 363                         if (*optarg == '=') {
 364                                 if (*(++optarg) == '\0')

 365                                         return ('?');
 366                         }
 367                 }
 368 
 369                 if (cbfunc != NULL)
 370                         c = (*cbfunc)(c);
 371 
 372                 return (c);
 373         }
 374         return (0);
 375 }
 376 
 377 /*
 378  * Parse an individual option.  The intent of this function is to determine if
 379  * any known, non-Solaris options have been passed to ld(1).  This condition
 380  * can occur as a result of build configuration tools, because of users
 381  * familiarity with other systems, or simply the users preferences.  If a known
 382  * non-Solaris option can be determined, translate that option into the Solaris
 383  * counterpart.
 384  *
 385  * This function will probably never be a complete solution, as new, non-Solaris
 386  * options are discovered, their translation will have to be added.  Other
 387  * non-Solaris options are incompatible with the Solaris link-editor, and will
 388  * never be recognized.  We support what we can.
 389  */
 390 int
 391 ld_getopt(Lm_list *lml, int ndx, int argc, char **argv)




 284  * changes optarg to include the missing wrap= prefix.
 285  *
 286  * exit:
 287  *      Returns c on success, or '?' on error.
 288  */
 289 static int
 290 str2chr_wrap_cb(int c)
 291 {
 292         char    *str;
 293         size_t  len = MSG_ARG_WRAP_SIZE + strlen(optarg) + 1;
 294 
 295         if ((str = libld_malloc(len)) == NULL)
 296                 return ('?');
 297         (void) snprintf(str, len, MSG_ORIG(MSG_FMT_STRCAT),
 298             MSG_ORIG(MSG_ARG_WRAP), optarg);
 299         optarg = str;
 300         return (c);
 301 }
 302 
 303 /*
 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  *
 308  * entry:
 309  *      lml - Link map list for debug messages
 310  *      ndx - Starting optind for current item
 311  *      argc, argv - Command line arguments
 312  *      arg - Option to be examined
 313  *      c, opt - Option character (c) and corresponding long name (opt)
 314  *      optsz - 0 if option does not accept a value. If option does
 315  *              accept a value, strlen(opt), giving the offset to the
 316  *              value if the option and value are combined in one string.
 317  *      cbfunc - NULL, or pointer to function to call if a translation is
 318  *              successful.
 319  */
 320 static int
 321 str2chr(Lm_list *lml, int ndx, int argc, char **argv, char *arg, int c,
 322     const char *opt, size_t optsz, int cbfunc(int))
 323 {
 324         if (optsz == 0) {
 325                 /*
 326                  * Compare a single option (ie. there's no associated option
 327                  * argument).
 328                  */
 329                 if (strcmp(arg, opt) == 0) {
 330                         DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 331                         optind += 1;
 332                         optopt = c;
 333                         return (c);
 334                 }
 335         } else if ((strcmp(arg, opt) == 0) ||
 336             ((arg[optsz] == '=') && strncmp(arg, opt, optsz) == 0)) {
 337                 /*
 338                  * Otherwise, compare the option name, which may be
 339                  * concatenated with the option argument.
 340                  */
 341                 DBG_CALL(Dbg_args_str2chr(lml, ndx, opt, c));
 342 
 343                 if (arg[optsz] == '\0') {
 344                         /*
 345                          * Optarg is the next argument (white space separated).
 346                          * Make sure an optarg is available, and if not return
 347                          * a failure to prevent any fall-through to the generic
 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.
 355                          */
 356                         if ((++optind + 1) > argc) {
 357                                 optopt = arg[0];
 358                                 return ('?');
 359                         }
 360                         optarg = argv[optind];
 361                         optind++;
 362                 } else {
 363                         /*

 364                          * GNU option/option argument pairs can be represented
 365                          * with a "=" separator.  If this is the case, remove
 366                          * the separator.
 367                          */
 368                         optarg = &arg[optsz];
 369                         optind++;
 370                         if (*optarg == '=') {
 371                                 if (*(++optarg) == '\0')
 372                                         optopt = arg[0];
 373                                         return ('?');
 374                         }
 375                 }
 376 
 377                 if (cbfunc != NULL)
 378                         c = (*cbfunc)(c);
 379                 optopt = c;
 380                 return (c);
 381         }
 382         return (0);
 383 }
 384 
 385 /*
 386  * Parse an individual option.  The intent of this function is to determine if
 387  * any known, non-Solaris options have been passed to ld(1).  This condition
 388  * can occur as a result of build configuration tools, because of users
 389  * familiarity with other systems, or simply the users preferences.  If a known
 390  * non-Solaris option can be determined, translate that option into the Solaris
 391  * counterpart.
 392  *
 393  * This function will probably never be a complete solution, as new, non-Solaris
 394  * options are discovered, their translation will have to be added.  Other
 395  * non-Solaris options are incompatible with the Solaris link-editor, and will
 396  * never be recognized.  We support what we can.
 397  */
 398 int
 399 ld_getopt(Lm_list *lml, int ndx, int argc, char **argv)