args.c revision ba2be53024c0b999e74ba9adcd7d80fec5df8c57
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1988 AT&T 2N/A * All Rights Reserved 2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A#
pragma ident "%Z%%M% %I% %E% SMI" 2N/A * Publicly available flags are defined in ld(1). The following flags are 2N/A * private, and may be removed at any time. 2N/A * -z dtrace=symbol assigns symbol to PT_SUNWDTRACE segment, 2N/A * providing scratch area for dtrace processing. 2N/A * -z noreloc suppress relocation processing. This provides 2N/A * a mechanism for validating kernel module symbol 2N/A * resolution that would normally incur fatal 2N/A * relocation errors. 2N/A * -z rtldinfo=symbol assigns symbol to SUNW_RTLDINF dynamic tag, 2N/A * providing pre-initialization specific routines 2N/A * for TLS initialization. 2N/A * -z nointerp suppress the addition of an interpreter 2N/A * section. This is used to generate the kernel, 2N/A * but makes no sense to be used by anyone else. 2N/A * Define a set of local argument flags, the settings of these will be 2N/A * verified in check_flags() and lead to the appropriate output file flags 2N/A * being initialized. 2N/A * ztflag's state is set by pointing it to the matching string: 2N/A * text | textoff | textwarn 2N/A * Print usage message to stderr - 2 modes, summary message only, 2N/A * and full usage message. 2N/A * Checks the command line option flags for consistency. 2N/A * Combining relocations when building a relocatable 2N/A * object isn't allowed. Warn the user, but proceed. 2N/A * If the user hasn't explicitly requested that relocations 2N/A * not be combined, combine them by default. 2N/A * Set -Bdynamic on by default, setting is rechecked as input 2N/A * files are processed. 2N/A * If the use of default library searching has been suppressed 2N/A * but no runpaths have been provided we're going to have a hard 2N/A * job running this object. 2N/A * By default, text relocation warnings are given when building 2N/A * an executable unless the -b flag is specified. This option 2N/A * implies that unclean text can be created, so no warnings are 2N/A * generated unless specifically asked for. 2N/A * Create a dynamic object. -Bdirect indicates that all 2N/A * references should be bound directly. This also 2N/A * enables lazyloading. Individual symbols can be 2N/A * bound directly (or not) using mapfiles and the 2N/A * DIRECT (NODIRECT) qualifier. With this capability, 2N/A * each syminfo entry is tagged SYMINFO_FLG_DIRECTBIND. 2N/A * Prior to this per-symbol direct binding, runtime 2N/A * direct binding was controlled via the DF_1_DIRECT 2N/A * flag. This flag affected all references from the 2N/A * object. -Bdirect continues to set this flag, and 2N/A * thus provides a means of taking a newly built 2N/A * direct binding object back to older systems. 2N/A * NOTE, any use of per-symbol NODIRECT bindings, or 2N/A * -znodirect, will disable the creation of the 2N/A * DF_1_DIRECT flag. Older runtime linkers do not 2N/A * have the capability to do per-symbol direct bindings. 2N/A * -Bnodirect disables directly binding to any symbols 2N/A * exported from the object being created. Individual 2N/A * references to external objects can still be affected 2N/A * by -zdirect or mapfile DIRECT directives. 2N/A * Dynamically linked executable. 2N/A * By default, print text relocation errors for 2N/A * executables but *not* for shared objects. 2N/A * -Bsymbolic, and -Bnodirect make no sense. 2N/A * Dynamic relocatable object. * We can only strip the symbol table and string table * if no output relocations will refer to them. * If the user didn't supply an output file name supply a default. * We set the entrance criteria after all input argument processing as * it is only at this point we're sure what the output image will be * Does the host currently running the linker have the same * byte order as the target for which the object is being produced? * If not, set FLG_OF1_ENCDIFF so relocation code will know * Initialize string tables. Symbol definitions within mapfiles can * result in the creation of input sections. * Process any mapfiles after establishing the entrance criteria as * If a mapfile has been used to define a single symbolic scope of * interfaces, -Bsymbolic is established. This global setting goes * beyond individual symbol protection, and ensures all relocations * (even those that reference section symbols) are processed within * the object being built. * If -zloadfltr is set, verify that filtering is in effect. Filters * are either established from the command line, and affect the whole * object, or are set on a per-symbol basis from a mapfile. * Check that we have something to work with. This check is carried out * after mapfile processing as its possible a mapfile is being used to * define symbols, in which case it would be sufficient to build the * output file purely from the mapfile. * Decompose the string pointed by optarg into argv[][] so that argv[][] can be * used as an argument to getopt(). * If the second argument 'error' is not 0, then this is called from the first * pass. Else this is called from the second pass. * The argument being examined is either: * Count the number of arguments. * Pointing at non-separator character. while (*
p0 && (*
p0 !=
','))
* Pointing at a separator character. * Allocate argument vector. * Pointing at the beginning of non-separator character string. while (*
p0 && (*
p0 !=
','))
* Pointing at the beginining of separator character string. * Dispatch to pass1 or pass2 * Parsing options pass1 for process_flags(). * The -64 and -ztarget options are special, in that we validate * them, but otherwise ignore them. libld.so (this code) is called * from the ld front end program. ld has already examined the * arguments to determine the output class and machine type of the * output object, as reflected in the version (32/64) of ld_main() * that was called and the value of the 'mach' argument passed. * By time execution reaches this point, these options have already * been seen and acted on. * -64 is processed by ld to determine the output class. * Here we sanity check the option incase some other * -6* option is mistakenly passed to us. * This is a hack, and may be undone later. * The -b option is only used to build the Unix * kernel and its related kernel-mode modules. * We do not want those files to get a .SUNW_ldynsym * section. At least for now, the kernel makes no * use of .SUNW_ldynsym, and we do not want to use * the space to hold it. Therefore, we overload * the use of -b to also imply -znoldynsym. * For now, count any library as a shared object. This * is used to size the internal symbol cache. This * value is recalculated later on actual file processing * to get an accurate shared object count. * Multiple instances of this option may occur. Each * additional instance is effectively concatenated to * the previous separated by a colon. * Multiple instances of this option may occur. Each * additional instance is effectively concatenated to * the previous separated by a colon. * Multiple instances of this option may occur. Each * additional instance is effectively concatenated to * the previous separated by a colon. * For specific help, print our usage message and exit * immediately to ensure a 0 return code. * For some options set a flag - further consistancy * checks will be carried out in check_flags(). * For other options simply set the ofl flags directly. * The following options just need validation as they * are interpreted on the second pass through the * command line arguments. * If we have not yet read any input files go ahead * and process any debugging options (this allows any * argument processing, entrance criteria and library * initialization to be displayed). Otherwise, if an * input file has been seen, skip interpretation until * process_files (this allows debugging to be turned * on and off around individual groups of files). * Parsing options pass2 for * Record DT_NEEDED string * Pass 1 -- process_flags: collects all options and sets flags * If we detect some more options return to getopt(). * Checking argv[optind][1] against null prevents a forever * loop if an unadorned `-' argument is passed to us. int error = 0;
/* Collect all argument errors before exit */ * Having parsed everything, did we have any errors. * Pass 2 -- process_files: skips the flags collected in pass 1 and processes * If we detect some more options return to getopt(). * Checking argv[optind][1] against null prevents a forever * loop if an unadorned `-' argument is passed to us. * Check for mismatched input. optind =
1;
/* reinitialize optind */ * Process command line files (taking into account any applicable * preseeding flags). Return if any fatal errors have occurred. * Now that all command line files have been processed see if there are * any additional `needed' shared object dependencies. * If rescanning archives is enabled, do so now to determine whether * there might still be members extracted to satisfy references from any * explicit objects. Continue until no new objects are extracted. Note * that this pass is carried out *after* processing any implicit objects * (above) as they may already have resolved any undefined references * from any explicit dependencies. * If this archive was processed with -z allextract, * then all members have already been extracted. * Reestablish any archive specific command line flags. * If debugging, provide statistics on each archives extraction, or flag * any archive that has provided no members. Note that this could be a * nice place to free up much of the archive infrastructure, as we've * extracted any members we need. However, as we presently don't free * anything under ld(1) there's not much point in proceeding further. * If any version definitions have been established, either via input * from a mapfile or from the input relocatable objects, make sure any * version dependencies are satisfied, and version symbols created. * If segment ordering was specified (using mapfile) verify things