17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21fb1354edSrie 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T 247c478bd9Sstevel@tonic-gate * All Rights Reserved 257c478bd9Sstevel@tonic-gate * 26dc0f59e5SAli Bahrami * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 277c478bd9Sstevel@tonic-gate */ 28b533f56bSRobert Mustacchi /* 29b533f56bSRobert Mustacchi * Copyright (c) 2012, Joyent, Inc. All rights reserved. 30b533f56bSRobert Mustacchi */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* 3370d3e49eSrie * Publicly available flags are defined in ld(1). The following flags are 347c478bd9Sstevel@tonic-gate * private, and may be removed at any time. 357c478bd9Sstevel@tonic-gate * 367c478bd9Sstevel@tonic-gate * OPTION MEANING 377c478bd9Sstevel@tonic-gate * 387c478bd9Sstevel@tonic-gate * -z dtrace=symbol assigns symbol to PT_SUNWDTRACE segment, 392926dd2eSrie * providing scratch area for dtrace processing. 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * -z noreloc suppress relocation processing. This provides 427c478bd9Sstevel@tonic-gate * a mechanism for validating kernel module symbol 437c478bd9Sstevel@tonic-gate * resolution that would normally incur fatal 447c478bd9Sstevel@tonic-gate * relocation errors. 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * -z rtldinfo=symbol assigns symbol to SUNW_RTLDINF dynamic tag, 477c478bd9Sstevel@tonic-gate * providing pre-initialization specific routines 487c478bd9Sstevel@tonic-gate * for TLS initialization. 4970d3e49eSrie * 5070d3e49eSrie * -z nointerp suppress the addition of an interpreter 5170d3e49eSrie * section. This is used to generate the kernel, 5270d3e49eSrie * but makes no sense to be used by anyone else. 530e233487SRod Evans * 540e233487SRod Evans * -z norelaxreloc suppress the automatic addition of relaxed 550e233487SRod Evans * relocations to GNU linkonce/COMDAT sections. 5656e2cc86SAli Bahrami * 5756e2cc86SAli Bahrami * -z nosighandler suppress the registration of the signal handler 5856e2cc86SAli Bahrami * used to manage SIGBUS. 597c478bd9Sstevel@tonic-gate */ 60cdcc71c0SAli Bahrami 61cdcc71c0SAli Bahrami /* 62cdcc71c0SAli Bahrami * The following flags are committed, and will not be removed, but are 63cdcc71c0SAli Bahrami * not publically documented, either because they are obsolete, or because 64cdcc71c0SAli Bahrami * they exist to work around defects in other software and are not of 65cdcc71c0SAli Bahrami * sufficient interest otherwise. 66cdcc71c0SAli Bahrami * 67cdcc71c0SAli Bahrami * OPTION MEANING 68cdcc71c0SAli Bahrami * 69cdcc71c0SAli Bahrami * -Wl,... compiler drivers and configuration tools 70cdcc71c0SAli Bahrami * have been known to pass this compiler option 71cdcc71c0SAli Bahrami * to ld(1). Strip off the "-Wl," prefix and 72cdcc71c0SAli Bahrami * process the remainder (...) as a normal option. 73cdcc71c0SAli Bahrami */ 74cdcc71c0SAli Bahrami 757c478bd9Sstevel@tonic-gate #include <sys/link.h> 767c478bd9Sstevel@tonic-gate #include <stdio.h> 777c478bd9Sstevel@tonic-gate #include <fcntl.h> 787c478bd9Sstevel@tonic-gate #include <string.h> 797c478bd9Sstevel@tonic-gate #include <errno.h> 807c478bd9Sstevel@tonic-gate #include <elf.h> 817c478bd9Sstevel@tonic-gate #include <unistd.h> 825aefb655Srie #include <debug.h> 837c478bd9Sstevel@tonic-gate #include "msg.h" 847c478bd9Sstevel@tonic-gate #include "_libld.h" 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * Define a set of local argument flags, the settings of these will be 887c478bd9Sstevel@tonic-gate * verified in check_flags() and lead to the appropriate output file flags 897c478bd9Sstevel@tonic-gate * being initialized. 907c478bd9Sstevel@tonic-gate */ 917c478bd9Sstevel@tonic-gate typedef enum { 927c478bd9Sstevel@tonic-gate SET_UNKNOWN = -1, 937c478bd9Sstevel@tonic-gate SET_FALSE = 0, 947c478bd9Sstevel@tonic-gate SET_TRUE = 1 957c478bd9Sstevel@tonic-gate } Setstate; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate static Setstate dflag = SET_UNKNOWN; 987c478bd9Sstevel@tonic-gate static Setstate zdflag = SET_UNKNOWN; 997c478bd9Sstevel@tonic-gate static Setstate Qflag = SET_UNKNOWN; 1007c478bd9Sstevel@tonic-gate static Setstate Bdflag = SET_UNKNOWN; 1011007fd6fSAli Bahrami static Setstate zfwflag = SET_UNKNOWN; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate static Boolean aflag = FALSE; 1047c478bd9Sstevel@tonic-gate static Boolean bflag = FALSE; 1057c478bd9Sstevel@tonic-gate static Boolean rflag = FALSE; 1067c478bd9Sstevel@tonic-gate static Boolean sflag = FALSE; 1077c478bd9Sstevel@tonic-gate static Boolean zinflag = FALSE; 1087c478bd9Sstevel@tonic-gate static Boolean zlflag = FALSE; 1097c478bd9Sstevel@tonic-gate static Boolean Bgflag = FALSE; 1107c478bd9Sstevel@tonic-gate static Boolean Blflag = FALSE; 1117c478bd9Sstevel@tonic-gate static Boolean Beflag = FALSE; 1127c478bd9Sstevel@tonic-gate static Boolean Bsflag = FALSE; 113e23c41c9SAli Bahrami static Boolean Dflag = FALSE; 1147c478bd9Sstevel@tonic-gate static Boolean Gflag = FALSE; 1157c478bd9Sstevel@tonic-gate static Boolean Vflag = FALSE; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * ztflag's state is set by pointing it to the matching string: 1197c478bd9Sstevel@tonic-gate * text | textoff | textwarn 1207c478bd9Sstevel@tonic-gate */ 1211007fd6fSAli Bahrami static const char *ztflag = NULL; 1221007fd6fSAli Bahrami 1231007fd6fSAli Bahrami /* 1241007fd6fSAli Bahrami * Remember the guidance flags that result from the initial -z guidance 1251007fd6fSAli Bahrami * option, so that they can be compared to any that follow. We only want 1261007fd6fSAli Bahrami * to issue a warning when they differ. 1271007fd6fSAli Bahrami */ 1281007fd6fSAli Bahrami static ofl_guideflag_t initial_guidance_flags = 0; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate static uintptr_t process_files_com(Ofl_desc *, int, char **); 1317c478bd9Sstevel@tonic-gate static uintptr_t process_flags_com(Ofl_desc *, int, char **, int *); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Print usage message to stderr - 2 modes, summary message only, 1357c478bd9Sstevel@tonic-gate * and full usage message. 1367c478bd9Sstevel@tonic-gate */ 1377c478bd9Sstevel@tonic-gate static void 1387c478bd9Sstevel@tonic-gate usage_mesg(Boolean detail) 1397c478bd9Sstevel@tonic-gate { 1407c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_USAGE), 1417c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_OPTIONS)); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate if (detail == FALSE) 1447c478bd9Sstevel@tonic-gate return; 1457c478bd9Sstevel@tonic-gate 14656e2cc86SAli Bahrami (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_3)); 1477c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_6)); 1487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_A)); 1497c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_B)); 1507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBDR)); 1517c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBDY)); 1527c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBE)); 1537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBG)); 1547c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBL)); 1557c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBR)); 1567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CBS)); 1577c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_C)); 1587c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CC)); 1597c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_D)); 1607c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CD)); 1617c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_E)); 1627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_F)); 1637c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CF)); 1647c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CG)); 1657c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_H)); 1667c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_I)); 1677c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CI)); 1687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_L)); 1697c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CL)); 1707c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_M)); 1717c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CM)); 1727c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CN)); 1737c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_O)); 1747c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_P)); 1757c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CP)); 1767c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CQ)); 1777c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_R)); 1787c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CR)); 1797c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_S)); 1807c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CS)); 1817c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_T)); 1827c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_U)); 1837c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CV)); 1847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_CY)); 1857c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZA)); 1867c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZAE)); 1877010c12aSrie (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZAL)); 188b533f56bSRobert Mustacchi (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZADLIB)); 1897c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZC)); 190f441771bSRod Evans (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDEF)); 1917c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDFS)); 1927c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZDRS)); 1937c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZE)); 1941007fd6fSAli Bahrami (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZFATW)); 1957c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZFA)); 1967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZGP)); 1971007fd6fSAli Bahrami (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZGUIDE)); 1987c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZH)); 1997c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZIG)); 2007c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINA)); 2017c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINI)); 2027c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZINT)); 2037c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLAZY)); 2047c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLD32)); 2057c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLD64)); 2067c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZLO)); 2077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZM)); 20870d3e49eSrie (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNC)); 2097c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDFS)); 2107c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDEF)); 2117c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDEL)); 2127c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDLO)); 2137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNDU)); 2142926dd2eSrie (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNLD)); 21570d3e49eSrie (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNOW)); 2167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNPA)); 2177c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZNV)); 2187c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZO)); 2197c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZPIA)); 2207c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRL)); 221d2ef9fe9Sab196087 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRREL)); 2227c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRS)); 223551cffe3SAli Bahrami (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRSN)); 224551cffe3SAli Bahrami (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZRSGRP)); 22508278a5eSRod Evans (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZSCAP)); 226ba2be530Sab196087 (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTARG)); 2277c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZT)); 2287c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTO)); 2297c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTW)); 230cdcc71c0SAli Bahrami (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZWRAP)); 231f441771bSRod Evans (void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZVER)); 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate /* 235551cffe3SAli Bahrami * Rescan the archives seen on the command line in order 236551cffe3SAli Bahrami * to handle circularly dependent archives, stopping when 237551cffe3SAli Bahrami * no further member extraction occurs. 238551cffe3SAli Bahrami * 239551cffe3SAli Bahrami * entry: 240551cffe3SAli Bahrami * ofl - Output file descriptor 241551cffe3SAli Bahrami * isgrp - True if this is a an archive group search, False 242551cffe3SAli Bahrami * to search starting with argv[1] through end_arg_ndx 243551cffe3SAli Bahrami * end_arg_ndx - Index of final argv element to consider. 244551cffe3SAli Bahrami */ 245551cffe3SAli Bahrami static uintptr_t 246551cffe3SAli Bahrami ld_rescan_archives(Ofl_desc *ofl, int isgrp, int end_arg_ndx) 247551cffe3SAli Bahrami { 248551cffe3SAli Bahrami ofl->ofl_flags1 |= FLG_OF1_EXTRACT; 249551cffe3SAli Bahrami 250551cffe3SAli Bahrami while (ofl->ofl_flags1 & FLG_OF1_EXTRACT) { 25157ef7aa9SRod Evans Aliste idx; 252551cffe3SAli Bahrami Ar_desc *adp; 253551cffe3SAli Bahrami Word start_ndx = isgrp ? ofl->ofl_ars_gsndx : 0; 254551cffe3SAli Bahrami Word ndx = 0; 255551cffe3SAli Bahrami 256551cffe3SAli Bahrami ofl->ofl_flags1 &= ~FLG_OF1_EXTRACT; 257551cffe3SAli Bahrami 258551cffe3SAli Bahrami DBG_CALL(Dbg_file_ar_rescan(ofl->ofl_lml, 259551cffe3SAli Bahrami isgrp ? ofl->ofl_ars_gsandx : 1, end_arg_ndx)); 260551cffe3SAli Bahrami 26157ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_ars, idx, adp)) { 262551cffe3SAli Bahrami /* If not to starting index yet, skip it */ 263551cffe3SAli Bahrami if (ndx++ < start_ndx) 264551cffe3SAli Bahrami continue; 265551cffe3SAli Bahrami 266551cffe3SAli Bahrami /* 267551cffe3SAli Bahrami * If this archive was processed with -z allextract, 268551cffe3SAli Bahrami * then all members have already been extracted. 269551cffe3SAli Bahrami */ 270551cffe3SAli Bahrami if (adp->ad_elf == NULL) 271551cffe3SAli Bahrami continue; 272551cffe3SAli Bahrami 273551cffe3SAli Bahrami /* 274551cffe3SAli Bahrami * Reestablish any archive specific command line flags. 275551cffe3SAli Bahrami */ 276551cffe3SAli Bahrami ofl->ofl_flags1 &= ~MSK_OF1_ARCHIVE; 277551cffe3SAli Bahrami ofl->ofl_flags1 |= (adp->ad_flags & MSK_OF1_ARCHIVE); 278551cffe3SAli Bahrami 279551cffe3SAli Bahrami /* 280551cffe3SAli Bahrami * Re-process the archive. Note that a file descriptor 281551cffe3SAli Bahrami * is unnecessary, as the file is already available in 282551cffe3SAli Bahrami * memory. 283551cffe3SAli Bahrami */ 284dc0f59e5SAli Bahrami if (!ld_process_archive(adp->ad_name, -1, adp, ofl)) 285551cffe3SAli Bahrami return (S_ERROR); 286551cffe3SAli Bahrami if (ofl->ofl_flags & FLG_OF_FATAL) 287551cffe3SAli Bahrami return (1); 288551cffe3SAli Bahrami } 289551cffe3SAli Bahrami } 290551cffe3SAli Bahrami 291551cffe3SAli Bahrami return (1); 292551cffe3SAli Bahrami } 293551cffe3SAli Bahrami 294551cffe3SAli Bahrami /* 2957c478bd9Sstevel@tonic-gate * Checks the command line option flags for consistency. 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate static uintptr_t 2987c478bd9Sstevel@tonic-gate check_flags(Ofl_desc * ofl, int argc) 2997c478bd9Sstevel@tonic-gate { 3001007fd6fSAli Bahrami /* 3011007fd6fSAli Bahrami * If the user specified -zguidance=noall, then we can safely disable 3021007fd6fSAli Bahrami * the entire feature. The purpose of -zguidance=noall is to allow 3031007fd6fSAli Bahrami * the user to override guidance specified from a makefile via 3041007fd6fSAli Bahrami * the LD_OPTIONS environment variable, and so, we want to behave 3051007fd6fSAli Bahrami * in exactly the same manner we would have if no option were present. 3061007fd6fSAli Bahrami */ 3071007fd6fSAli Bahrami if ((ofl->ofl_guideflags & (FLG_OFG_ENABLE | FLG_OFG_NO_ALL)) == 3081007fd6fSAli Bahrami (FLG_OFG_ENABLE | FLG_OFG_NO_ALL)) 3091007fd6fSAli Bahrami ofl->ofl_guideflags &= ~FLG_OFG_ENABLE; 3101007fd6fSAli Bahrami 3111007fd6fSAli Bahrami if (Plibpath && (Llibdir || Ulibdir)) 3121007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_YP), 3137c478bd9Sstevel@tonic-gate Llibdir ? 'L' : 'U'); 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate if (rflag) { 3167c478bd9Sstevel@tonic-gate if (dflag == SET_UNKNOWN) 3177c478bd9Sstevel@tonic-gate dflag = SET_FALSE; 318e38a713aSrie /* 319e38a713aSrie * Combining relocations when building a relocatable 320e38a713aSrie * object isn't allowed. Warn the user, but proceed. 321e38a713aSrie */ 3221007fd6fSAli Bahrami if (ofl->ofl_flags & FLG_OF_COMREL) 3231007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_MARG_INCOMP), 3241007fd6fSAli Bahrami MSG_INTL(MSG_MARG_REL), 3257c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZCOMBRELOC)); 3267c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_RELOBJ; 327e38a713aSrie } else { 328e38a713aSrie /* 32908278a5eSRod Evans * Translating object capabilities to symbol capabilities is 33008278a5eSRod Evans * only meaningful when creating a relocatable object. 33108278a5eSRod Evans */ 3321007fd6fSAli Bahrami if (ofl->ofl_flags & FLG_OF_OTOSCAP) 3331007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ONLY), 33408278a5eSRod Evans MSG_ORIG(MSG_ARG_ZSYMBOLCAP), 33508278a5eSRod Evans MSG_INTL(MSG_MARG_REL)); 33608278a5eSRod Evans 33708278a5eSRod Evans /* 338e38a713aSrie * If the user hasn't explicitly requested that relocations 339e38a713aSrie * not be combined, combine them by default. 340e38a713aSrie */ 341e38a713aSrie if ((ofl->ofl_flags & FLG_OF_NOCOMREL) == 0) 342e38a713aSrie ofl->ofl_flags |= FLG_OF_COMREL; 3437c478bd9Sstevel@tonic-gate } 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate if (zdflag == SET_TRUE) 3467c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_NOUNDEF; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if (zinflag) 3497c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_INTERPOSE; 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate if (sflag) 3527c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_STRIP; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate if (Qflag == SET_TRUE) 3557c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_ADDVERS; 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate if (Blflag) 3587c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_AUTOLCL; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate if (Beflag) 36144bac77bSrie ofl->ofl_flags |= FLG_OF_AUTOELM; 3627c478bd9Sstevel@tonic-gate 3631007fd6fSAli Bahrami if (Blflag && Beflag) 3641007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP), 3657c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BELIMINATE), MSG_ORIG(MSG_ARG_BLOCAL)); 3667c478bd9Sstevel@tonic-gate 3671007fd6fSAli Bahrami if (ofl->ofl_interp && (ofl->ofl_flags1 & FLG_OF1_NOINTRP)) 3681007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP), 36970d3e49eSrie MSG_ORIG(MSG_ARG_CI), MSG_ORIG(MSG_ARG_ZNOINTERP)); 37070d3e49eSrie 3710e233487SRod Evans if ((ofl->ofl_flags1 & (FLG_OF1_NRLXREL | FLG_OF1_RLXREL)) == 3721007fd6fSAli Bahrami (FLG_OF1_NRLXREL | FLG_OF1_RLXREL)) 3731007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP), 3740e233487SRod Evans MSG_ORIG(MSG_ARG_ZRELAXRELOC), 3750e233487SRod Evans MSG_ORIG(MSG_ARG_ZNORELAXRELOC)); 3760e233487SRod Evans 3771007fd6fSAli Bahrami if (ofl->ofl_filtees && !Gflag) 3781007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_ONLYAVL), 3791007fd6fSAli Bahrami ((ofl->ofl_flags & FLG_OF_AUX) ? 3801007fd6fSAli Bahrami MSG_INTL(MSG_MARG_FILTER_AUX) : MSG_INTL(MSG_MARG_FILTER))); 381604635faSRod Evans 3827c478bd9Sstevel@tonic-gate if (dflag != SET_FALSE) { 3837c478bd9Sstevel@tonic-gate /* 3847c478bd9Sstevel@tonic-gate * Set -Bdynamic on by default, setting is rechecked as input 3857c478bd9Sstevel@tonic-gate * files are processed. 3867c478bd9Sstevel@tonic-gate */ 3877c478bd9Sstevel@tonic-gate ofl->ofl_flags |= 3887c478bd9Sstevel@tonic-gate (FLG_OF_DYNAMIC | FLG_OF_DYNLIBS | FLG_OF_PROCRED); 3897c478bd9Sstevel@tonic-gate 3901007fd6fSAli Bahrami if (aflag) 3911007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_INCOMP), 3921007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_DY), MSG_ORIG(MSG_ARG_A)); 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate if (bflag) 3957c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_BFLAG; 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate if (Bgflag == TRUE) { 3981007fd6fSAli Bahrami if (zdflag == SET_FALSE) 3991007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 4005aefb655Srie MSG_INTL(MSG_ARG_INCOMP), 4017c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BGROUP), 4027c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZNODEF)); 4037c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_GROUP; 4047c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_NOUNDEF; 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate /* 4087c478bd9Sstevel@tonic-gate * If the use of default library searching has been suppressed 4097c478bd9Sstevel@tonic-gate * but no runpaths have been provided we're going to have a hard 4107c478bd9Sstevel@tonic-gate * job running this object. 4117c478bd9Sstevel@tonic-gate */ 4127c478bd9Sstevel@tonic-gate if ((ofl->ofl_dtflags_1 & DF_1_NODEFLIB) && !ofl->ofl_rpath) 4131007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_ARG_NODEFLIB), 414551cffe3SAli Bahrami MSG_INTL(MSG_MARG_RPATH)); 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate /* 4177c478bd9Sstevel@tonic-gate * By default, text relocation warnings are given when building 4187c478bd9Sstevel@tonic-gate * an executable unless the -b flag is specified. This option 4197c478bd9Sstevel@tonic-gate * implies that unclean text can be created, so no warnings are 4207c478bd9Sstevel@tonic-gate * generated unless specifically asked for. 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate if ((ztflag == MSG_ORIG(MSG_ARG_ZTEXTOFF)) || 4231007fd6fSAli Bahrami ((ztflag == NULL) && bflag)) { 4247c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_TEXTOFF; 4251007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_TEXT; 4261007fd6fSAli Bahrami } else if (ztflag == MSG_ORIG(MSG_ARG_ZTEXT)) { 4277c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_PURETXT; 4281007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_TEXT; 4291007fd6fSAli Bahrami } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate if (Gflag || !rflag) { 4327c478bd9Sstevel@tonic-gate /* 4337c478bd9Sstevel@tonic-gate * Create a dynamic object. -Bdirect indicates that all 4347c478bd9Sstevel@tonic-gate * references should be bound directly. This also 4357c478bd9Sstevel@tonic-gate * enables lazyloading. Individual symbols can be 4367c478bd9Sstevel@tonic-gate * bound directly (or not) using mapfiles and the 4377c478bd9Sstevel@tonic-gate * DIRECT (NODIRECT) qualifier. With this capability, 4387c478bd9Sstevel@tonic-gate * each syminfo entry is tagged SYMINFO_FLG_DIRECTBIND. 4397c478bd9Sstevel@tonic-gate * Prior to this per-symbol direct binding, runtime 4407c478bd9Sstevel@tonic-gate * direct binding was controlled via the DF_1_DIRECT 4417c478bd9Sstevel@tonic-gate * flag. This flag affected all references from the 4427c478bd9Sstevel@tonic-gate * object. -Bdirect continues to set this flag, and 4437c478bd9Sstevel@tonic-gate * thus provides a means of taking a newly built 4447c478bd9Sstevel@tonic-gate * direct binding object back to older systems. 4457c478bd9Sstevel@tonic-gate * 4467c478bd9Sstevel@tonic-gate * NOTE, any use of per-symbol NODIRECT bindings, or 4477c478bd9Sstevel@tonic-gate * -znodirect, will disable the creation of the 4487c478bd9Sstevel@tonic-gate * DF_1_DIRECT flag. Older runtime linkers do not 4497c478bd9Sstevel@tonic-gate * have the capability to do per-symbol direct bindings. 4507c478bd9Sstevel@tonic-gate */ 4517c478bd9Sstevel@tonic-gate if (Bdflag == SET_TRUE) { 4527c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_DIRECT; 4537c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_LAZYLD; 4541007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_LAZY; 4557c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMINFO; 4567c478bd9Sstevel@tonic-gate } 4577c478bd9Sstevel@tonic-gate 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * -Bnodirect disables directly binding to any symbols 4607c478bd9Sstevel@tonic-gate * exported from the object being created. Individual 4617c478bd9Sstevel@tonic-gate * references to external objects can still be affected 4627c478bd9Sstevel@tonic-gate * by -zdirect or mapfile DIRECT directives. 4637c478bd9Sstevel@tonic-gate */ 4647c478bd9Sstevel@tonic-gate if (Bdflag == SET_FALSE) { 46528bda19cSRod Evans ofl->ofl_flags1 |= (FLG_OF1_NDIRECT | 46628bda19cSRod Evans FLG_OF1_NGLBDIR | FLG_OF1_ALNODIR); 4677c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMINFO; 4687c478bd9Sstevel@tonic-gate } 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate if (!Gflag && !rflag) { 4727c478bd9Sstevel@tonic-gate /* 4737c478bd9Sstevel@tonic-gate * Dynamically linked executable. 4747c478bd9Sstevel@tonic-gate */ 4757c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_EXEC; 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate if (zdflag != SET_FALSE) 4787c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_NOUNDEF; 4797c478bd9Sstevel@tonic-gate 4801007fd6fSAli Bahrami /* 4811007fd6fSAli Bahrami * -z textwarn is the default for executables, and 4821007fd6fSAli Bahrami * only an explicit -z text* option can change that, 4831007fd6fSAli Bahrami * so there's no need to provide additional guidance. 4841007fd6fSAli Bahrami */ 4851007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_TEXT; 4861007fd6fSAli Bahrami 4871007fd6fSAli Bahrami if (Bsflag) 4881007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 48992a02081SRod Evans MSG_INTL(MSG_ARG_DY_INCOMP), 4907c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BSYMBOLIC)); 4911007fd6fSAli Bahrami if (ofl->ofl_soname) 4921007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 493551cffe3SAli Bahrami MSG_INTL(MSG_MARG_DY_INCOMP), 494551cffe3SAli Bahrami MSG_INTL(MSG_MARG_SONAME)); 4957c478bd9Sstevel@tonic-gate } else if (!rflag) { 4967c478bd9Sstevel@tonic-gate /* 4977c478bd9Sstevel@tonic-gate * Shared library. 4987c478bd9Sstevel@tonic-gate */ 4997c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SHAROBJ; 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate /* 5021007fd6fSAli Bahrami * By default, print text relocation warnings for 5031007fd6fSAli Bahrami * executables but *not* for shared objects. However, 5041007fd6fSAli Bahrami * if -z guidance is on, issue warnings for shared 5051007fd6fSAli Bahrami * objects as well. 5061007fd6fSAli Bahrami * 5071007fd6fSAli Bahrami * If -z textwarn is explicitly specified, also issue 5081007fd6fSAli Bahrami * guidance messages if -z guidance is on, but not 5091007fd6fSAli Bahrami * for -z text or -z textoff. 5107c478bd9Sstevel@tonic-gate */ 5111007fd6fSAli Bahrami if (ztflag == NULL) { 5121007fd6fSAli Bahrami if (!OFL_GUIDANCE(ofl, FLG_OFG_NO_TEXT)) 5137c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_TEXTOFF; 5141007fd6fSAli Bahrami } else if ((ofl->ofl_flags & FLG_OF_PURETXT) || 5151007fd6fSAli Bahrami (ofl->ofl_flags1 & FLG_OF1_TEXTOFF)) { 5161007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_TEXT; 5171007fd6fSAli Bahrami } 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate if (Bsflag) { 5209a411307Srie /* 5219a411307Srie * -Bsymbolic, and -Bnodirect make no sense. 5229a411307Srie */ 5231007fd6fSAli Bahrami if (Bdflag == SET_FALSE) 5241007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 5259a411307Srie MSG_INTL(MSG_ARG_INCOMP), 5269a411307Srie MSG_ORIG(MSG_ARG_BSYMBOLIC), 5279a411307Srie MSG_ORIG(MSG_ARG_BNODIRECT)); 5287c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_SYMBOLIC; 5297c478bd9Sstevel@tonic-gate ofl->ofl_dtflags |= DF_SYMBOLIC; 5307c478bd9Sstevel@tonic-gate } 5317c478bd9Sstevel@tonic-gate } else { 5327c478bd9Sstevel@tonic-gate /* 5333c4993fbSrie * Dynamic relocatable object. 5347c478bd9Sstevel@tonic-gate */ 5351007fd6fSAli Bahrami if (ztflag == NULL) 5367c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_TEXTOFF; 5371007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_TEXT; 5383c4993fbSrie 5391007fd6fSAli Bahrami if (ofl->ofl_interp) 5401007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 541551cffe3SAli Bahrami MSG_INTL(MSG_MARG_INCOMP), 542551cffe3SAli Bahrami MSG_INTL(MSG_MARG_REL), 543551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_CI)); 5447c478bd9Sstevel@tonic-gate } 5457c478bd9Sstevel@tonic-gate } else { 5467c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_STATIC; 5477c478bd9Sstevel@tonic-gate 5481007fd6fSAli Bahrami if (bflag) 5491007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP), 5501007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_B)); 5511007fd6fSAli Bahrami if (ofl->ofl_soname) 5521007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_INCOMP), 553551cffe3SAli Bahrami MSG_INTL(MSG_MARG_SONAME)); 5541007fd6fSAli Bahrami if (ofl->ofl_depaudit) 5551007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP), 5561007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_CP)); 5571007fd6fSAli Bahrami if (ofl->ofl_audit) 5581007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP), 5591007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_P)); 5601007fd6fSAli Bahrami if (ofl->ofl_config) 5611007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP), 5621007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_C)); 5631007fd6fSAli Bahrami if (ztflag) 5641007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP), 5655aefb655Srie MSG_ORIG(MSG_ARG_ZTEXTALL)); 5661007fd6fSAli Bahrami if (Gflag) 5671007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_INCOMP), 568551cffe3SAli Bahrami MSG_INTL(MSG_MARG_SO)); 5691007fd6fSAli Bahrami if (aflag && rflag) 5701007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_INCOMP), 5711007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_A), MSG_INTL(MSG_MARG_REL)); 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate if (rflag) { 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * We can only strip the symbol table and string table 5763c4993fbSrie * if no output relocations will refer to them. 5777c478bd9Sstevel@tonic-gate */ 5781007fd6fSAli Bahrami if (sflag) 5791007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, 580551cffe3SAli Bahrami MSG_INTL(MSG_ARG_STRIP), 581551cffe3SAli Bahrami MSG_INTL(MSG_MARG_REL), 582551cffe3SAli Bahrami MSG_INTL(MSG_MARG_STRIP)); 5837c478bd9Sstevel@tonic-gate 5841007fd6fSAli Bahrami if (ztflag == NULL) 5857c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_TEXTOFF; 5861007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_TEXT; 5877c478bd9Sstevel@tonic-gate 5881007fd6fSAli Bahrami if (ofl->ofl_interp) 5891007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 590551cffe3SAli Bahrami MSG_INTL(MSG_MARG_INCOMP), 591551cffe3SAli Bahrami MSG_INTL(MSG_MARG_REL), 592551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_CI)); 5937c478bd9Sstevel@tonic-gate } else { 5947c478bd9Sstevel@tonic-gate /* 5957c478bd9Sstevel@tonic-gate * Static executable. 5967c478bd9Sstevel@tonic-gate */ 5977c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_EXEC | FLG_OF_PROCRED; 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate if (zdflag != SET_FALSE) 6007c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_NOUNDEF; 6017c478bd9Sstevel@tonic-gate } 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * If the user didn't supply an output file name supply a default. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate if (ofl->ofl_name == NULL) 6087c478bd9Sstevel@tonic-gate ofl->ofl_name = MSG_ORIG(MSG_STR_AOUT); 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * We set the entrance criteria after all input argument processing as 6127c478bd9Sstevel@tonic-gate * it is only at this point we're sure what the output image will be 6137c478bd9Sstevel@tonic-gate * (static or dynamic). 6147c478bd9Sstevel@tonic-gate */ 615ba2be530Sab196087 if (ld_ent_setup(ofl, ld_targ.t_m.m_segm_align) == S_ERROR) 6167c478bd9Sstevel@tonic-gate return (S_ERROR); 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate /* 619f3324781Sab196087 * Does the host currently running the linker have the same 620f3324781Sab196087 * byte order as the target for which the object is being produced? 621f3324781Sab196087 * If not, set FLG_OF1_ENCDIFF so relocation code will know 622f3324781Sab196087 * to check. 623f3324781Sab196087 */ 624ba2be530Sab196087 if (_elf_sys_encoding() != ld_targ.t_m.m_data) 625f3324781Sab196087 ofl->ofl_flags1 |= FLG_OF1_ENCDIFF; 626f3324781Sab196087 627f3324781Sab196087 /* 6283c573fccSAli Bahrami * If the target has special executable section filling requirements, 6293c573fccSAli Bahrami * register the fill function with libelf 6303c573fccSAli Bahrami */ 6313c573fccSAli Bahrami if (ld_targ.t_ff.ff_execfill != NULL) 6323c573fccSAli Bahrami _elf_execfill(ld_targ.t_ff.ff_execfill); 6333c573fccSAli Bahrami 6343c573fccSAli Bahrami /* 635c1c6f601Srie * Initialize string tables. Symbol definitions within mapfiles can 636c1c6f601Srie * result in the creation of input sections. 637c1c6f601Srie */ 638c1c6f601Srie if (ld_init_strings(ofl) == S_ERROR) 639c1c6f601Srie return (S_ERROR); 640c1c6f601Srie 641c1c6f601Srie /* 64269112eddSAli Bahrami * Process mapfiles. Mapfile can redefine or add sections/segments, 64369112eddSAli Bahrami * so this must come after the default entrance criteria are established 64469112eddSAli Bahrami * (above). 6457c478bd9Sstevel@tonic-gate */ 64657ef7aa9SRod Evans if (ofl->ofl_maps) { 6477c478bd9Sstevel@tonic-gate const char *name; 64857ef7aa9SRod Evans Aliste idx; 6497c478bd9Sstevel@tonic-gate 65057ef7aa9SRod Evans for (APLIST_TRAVERSE(ofl->ofl_maps, idx, name)) 65169112eddSAli Bahrami if (!ld_map_parse(name, ofl)) 6527c478bd9Sstevel@tonic-gate return (S_ERROR); 6537c478bd9Sstevel@tonic-gate 65469112eddSAli Bahrami if (!ld_map_post_process(ofl)) 6557c478bd9Sstevel@tonic-gate return (S_ERROR); 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate /* 6599a411307Srie * If a mapfile has been used to define a single symbolic scope of 6609a411307Srie * interfaces, -Bsymbolic is established. This global setting goes 6619a411307Srie * beyond individual symbol protection, and ensures all relocations 6629a411307Srie * (even those that reference section symbols) are processed within 6639a411307Srie * the object being built. 6649a411307Srie */ 66544bac77bSrie if (((ofl->ofl_flags & 66644bac77bSrie (FLG_OF_MAPSYMB | FLG_OF_MAPGLOB)) == FLG_OF_MAPSYMB) && 66744bac77bSrie (ofl->ofl_flags & (FLG_OF_AUTOLCL | FLG_OF_AUTOELM))) { 6689a411307Srie ofl->ofl_flags |= FLG_OF_SYMBOLIC; 6699a411307Srie ofl->ofl_dtflags |= DF_SYMBOLIC; 6709a411307Srie } 6719a411307Srie 6729a411307Srie /* 6737c478bd9Sstevel@tonic-gate * If -zloadfltr is set, verify that filtering is in effect. Filters 6747c478bd9Sstevel@tonic-gate * are either established from the command line, and affect the whole 6757c478bd9Sstevel@tonic-gate * object, or are set on a per-symbol basis from a mapfile. 6767c478bd9Sstevel@tonic-gate */ 6777c478bd9Sstevel@tonic-gate if (zlflag) { 6781007fd6fSAli Bahrami if ((ofl->ofl_filtees == NULL) && (ofl->ofl_dtsfltrs == NULL)) 6791007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_NOFLTR), 6807c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZLOADFLTR)); 6817c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_LOADFLTR; 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate /* 6857c478bd9Sstevel@tonic-gate * Check that we have something to work with. This check is carried out 6867c478bd9Sstevel@tonic-gate * after mapfile processing as its possible a mapfile is being used to 6877c478bd9Sstevel@tonic-gate * define symbols, in which case it would be sufficient to build the 6887c478bd9Sstevel@tonic-gate * output file purely from the mapfile. 6897c478bd9Sstevel@tonic-gate */ 6907c478bd9Sstevel@tonic-gate if ((ofl->ofl_objscnt == 0) && (ofl->ofl_soscnt == 0)) { 691e23c41c9SAli Bahrami if ((Vflag || 692e23c41c9SAli Bahrami (Dflag && (dbg_desc->d_extra & DBG_E_HELP_EXIT))) && 693e23c41c9SAli Bahrami (argc == 2)) { 6947c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_DONE; 695e23c41c9SAli Bahrami } else { 6961007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_NOFILES)); 6977c478bd9Sstevel@tonic-gate return (S_ERROR); 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate return (1); 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate /* 7047c478bd9Sstevel@tonic-gate * Decompose the string pointed by optarg into argv[][] so that argv[][] can be 7057c478bd9Sstevel@tonic-gate * used as an argument to getopt(). 7067c478bd9Sstevel@tonic-gate * 7071007fd6fSAli Bahrami * If the second argument 'usage' is not NULL, then this is called from the 7081007fd6fSAli Bahrami * first pass. Else this is called from the second pass. 7097c478bd9Sstevel@tonic-gate */ 7107c478bd9Sstevel@tonic-gate static uintptr_t 7111007fd6fSAli Bahrami createargv(Ofl_desc *ofl, int *usage) 7127c478bd9Sstevel@tonic-gate { 7137c478bd9Sstevel@tonic-gate int argc = 0, idx = 0, ooptind; 7147c478bd9Sstevel@tonic-gate uintptr_t ret; 7157c478bd9Sstevel@tonic-gate char **argv, *p0; 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate /* 7187c478bd9Sstevel@tonic-gate * The argument being examined is either: 7197c478bd9Sstevel@tonic-gate * ld32= or 7207c478bd9Sstevel@tonic-gate * ld64= 7217c478bd9Sstevel@tonic-gate */ 7227c478bd9Sstevel@tonic-gate #if defined(_LP64) 7237c478bd9Sstevel@tonic-gate if (optarg[2] == '3') 7247c478bd9Sstevel@tonic-gate return (0); 7257c478bd9Sstevel@tonic-gate #else 7267c478bd9Sstevel@tonic-gate if (optarg[2] == '6') 7277c478bd9Sstevel@tonic-gate return (0); 7287c478bd9Sstevel@tonic-gate #endif 7297c478bd9Sstevel@tonic-gate 7307c478bd9Sstevel@tonic-gate p0 = &optarg[5]; 7317c478bd9Sstevel@tonic-gate 7327c478bd9Sstevel@tonic-gate /* 7337c478bd9Sstevel@tonic-gate * Count the number of arguments. 7347c478bd9Sstevel@tonic-gate */ 7357c478bd9Sstevel@tonic-gate while (*p0) { 7367c478bd9Sstevel@tonic-gate /* 7377c478bd9Sstevel@tonic-gate * Pointing at non-separator character. 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate if (*p0 != ',') { 7407c478bd9Sstevel@tonic-gate argc++; 7417c478bd9Sstevel@tonic-gate while (*p0 && (*p0 != ',')) 7427c478bd9Sstevel@tonic-gate p0++; 7437c478bd9Sstevel@tonic-gate continue; 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate /* 7477c478bd9Sstevel@tonic-gate * Pointing at a separator character. 7487c478bd9Sstevel@tonic-gate */ 7497c478bd9Sstevel@tonic-gate if (*p0 == ',') { 7507c478bd9Sstevel@tonic-gate while (*p0 == ',') 7517c478bd9Sstevel@tonic-gate p0++; 7527c478bd9Sstevel@tonic-gate continue; 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate } 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate if (argc == 0) 7577c478bd9Sstevel@tonic-gate return (0); 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate /* 7607c478bd9Sstevel@tonic-gate * Allocate argument vector. 7617c478bd9Sstevel@tonic-gate */ 76257ef7aa9SRod Evans if ((p0 = (char *)strdup(&optarg[5])) == NULL) 7637c478bd9Sstevel@tonic-gate return (S_ERROR); 76457ef7aa9SRod Evans if ((argv = libld_malloc((sizeof (char *)) * (argc + 1))) == NULL) 7657c478bd9Sstevel@tonic-gate return (S_ERROR); 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate while (*p0) { 7687c478bd9Sstevel@tonic-gate char *p; 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate /* 7717c478bd9Sstevel@tonic-gate * Pointing at the beginning of non-separator character string. 7727c478bd9Sstevel@tonic-gate */ 7737c478bd9Sstevel@tonic-gate if (*p0 != ',') { 7747c478bd9Sstevel@tonic-gate p = p0; 7757c478bd9Sstevel@tonic-gate while (*p0 && (*p0 != ',')) 7767c478bd9Sstevel@tonic-gate p0++; 7777c478bd9Sstevel@tonic-gate argv[idx++] = p; 7787c478bd9Sstevel@tonic-gate if (*p0) { 7797c478bd9Sstevel@tonic-gate *p0 = '\0'; 7807c478bd9Sstevel@tonic-gate p0++; 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate continue; 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate /* 7867c478bd9Sstevel@tonic-gate * Pointing at the beginining of separator character string. 7877c478bd9Sstevel@tonic-gate */ 7887c478bd9Sstevel@tonic-gate if (*p0 == ',') { 7897c478bd9Sstevel@tonic-gate while (*p0 == ',') 7907c478bd9Sstevel@tonic-gate p0++; 7917c478bd9Sstevel@tonic-gate continue; 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate } 7947c478bd9Sstevel@tonic-gate argv[idx] = 0; 7957c478bd9Sstevel@tonic-gate ooptind = optind; 7967c478bd9Sstevel@tonic-gate optind = 0; 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate /* 7997c478bd9Sstevel@tonic-gate * Dispatch to pass1 or pass2 8007c478bd9Sstevel@tonic-gate */ 8011007fd6fSAli Bahrami if (usage) 8021007fd6fSAli Bahrami ret = process_flags_com(ofl, argc, argv, usage); 8037c478bd9Sstevel@tonic-gate else 8047c478bd9Sstevel@tonic-gate ret = process_files_com(ofl, argc, argv); 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate optind = ooptind; 80792a02081SRod Evans return (ret); 8087c478bd9Sstevel@tonic-gate } 8097c478bd9Sstevel@tonic-gate 8101007fd6fSAli Bahrami /* 8111007fd6fSAli Bahrami * Parse the items in a '-z guidance' value, and set the ofl_guideflags. 8121007fd6fSAli Bahrami * A guidance option looks like this: 8131007fd6fSAli Bahrami * 8141007fd6fSAli Bahrami * -z guidance[=item1,item2,...] 8151007fd6fSAli Bahrami * 8161007fd6fSAli Bahrami * Where each item specifies categories of guidance messages to suppress, 8171007fd6fSAli Bahrami * each starting with the prefix 'no'. We allow arbitrary whitespace between 8181007fd6fSAli Bahrami * the items, allow multiple ',' delimiters without an intervening item, and 8191007fd6fSAli Bahrami * quietly ignore any items we don't recognize. 8201007fd6fSAli Bahrami * 8211007fd6fSAli Bahrami * - Such items are likely to be known to newer versions of the linker, 8221007fd6fSAli Bahrami * and we do not want an older version of the linker to 8231007fd6fSAli Bahrami * complain about them. 8241007fd6fSAli Bahrami * 8251007fd6fSAli Bahrami * - Times and standards can change, and so we wish to reserve the 8261007fd6fSAli Bahrami * right to make an old item that no longer makes sense go away. 8271007fd6fSAli Bahrami * Quietly ignoring unrecognized items facilitates this. 8281007fd6fSAli Bahrami * 8291007fd6fSAli Bahrami * However, we always display unrecognized items in debug output. 8301007fd6fSAli Bahrami * 8311007fd6fSAli Bahrami * entry: 8321007fd6fSAli Bahrami * ofl - Output descriptor 8331007fd6fSAli Bahrami * optarg - option string to be processed. This will either be a NULL 8341007fd6fSAli Bahrami * terminated 'guidance', or it will be 'guidance=' followed 8351007fd6fSAli Bahrami * by the item tokens as described above. 8361007fd6fSAli Bahrami * 8371007fd6fSAli Bahrami * exit: 8381007fd6fSAli Bahrami * Returns TRUE (1) on success, FALSE (0) on failure. 8391007fd6fSAli Bahrami * 8401007fd6fSAli Bahrami */ 8411007fd6fSAli Bahrami static Boolean 8421007fd6fSAli Bahrami guidance_parse(Ofl_desc *ofl, char *optarg) 8431007fd6fSAli Bahrami { 8441007fd6fSAli Bahrami typedef struct { 8451007fd6fSAli Bahrami const char *name; 8461007fd6fSAli Bahrami ofl_guideflag_t flag; 8471007fd6fSAli Bahrami } item_desc; 8481007fd6fSAli Bahrami 8491007fd6fSAli Bahrami static item_desc items[] = { 8501007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_ALL), FLG_OFG_NO_ALL }, 8511007fd6fSAli Bahrami 8521007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_DEFS), FLG_OFG_NO_DEFS }, 8531007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_DIRECT), FLG_OFG_NO_DB }, 8541007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_LAZYLOAD), FLG_OFG_NO_LAZY }, 8551007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_MAPFILE), FLG_OFG_NO_MF }, 8561007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_TEXT), FLG_OFG_NO_TEXT }, 8571007fd6fSAli Bahrami { MSG_ORIG(MSG_ARG_GUIDE_NO_UNUSED), FLG_OFG_NO_UNUSED }, 8581007fd6fSAli Bahrami { NULL, 0 } 8591007fd6fSAli Bahrami }; 8601007fd6fSAli Bahrami 8611007fd6fSAli Bahrami char *lasts, *name; 8621007fd6fSAli Bahrami item_desc *item; 8631007fd6fSAli Bahrami ofl_guideflag_t ofl_guideflags = FLG_OFG_ENABLE; 8641007fd6fSAli Bahrami 8651007fd6fSAli Bahrami /* 8661007fd6fSAli Bahrami * Skip the 'guidance' prefix. If NULL terminated, there are no 8671007fd6fSAli Bahrami * item values to parse. Otherwise, skip the '=' and parse the items. 8681007fd6fSAli Bahrami */ 8691007fd6fSAli Bahrami optarg += MSG_ARG_GUIDE_SIZE; 8701007fd6fSAli Bahrami if (*optarg == '=') { 8711007fd6fSAli Bahrami optarg++; 8721007fd6fSAli Bahrami 8731007fd6fSAli Bahrami if ((name = libld_malloc(strlen(optarg) + 1)) == NULL) 8741007fd6fSAli Bahrami return (FALSE); 8751007fd6fSAli Bahrami (void) strcpy(name, optarg); 8761007fd6fSAli Bahrami 8771007fd6fSAli Bahrami if ((name = strtok_r(name, MSG_ORIG(MSG_ARG_GUIDE_DELIM), 8781007fd6fSAli Bahrami &lasts)) != NULL) { 8791007fd6fSAli Bahrami do { 8801007fd6fSAli Bahrami for (item = items; item->name != NULL; item++) 8811007fd6fSAli Bahrami if (strcasecmp(name, item->name) == 0) 8821007fd6fSAli Bahrami break; 8831007fd6fSAli Bahrami if (item->name == NULL) { 8841007fd6fSAli Bahrami DBG_CALL(Dbg_args_guidance_unknown( 8851007fd6fSAli Bahrami ofl->ofl_lml, name)); 8861007fd6fSAli Bahrami continue; 8871007fd6fSAli Bahrami } 8881007fd6fSAli Bahrami ofl_guideflags |= item->flag; 8891007fd6fSAli Bahrami } while ((name = strtok_r(NULL, 8901007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_GUIDE_DELIM), &lasts)) != NULL); 8911007fd6fSAli Bahrami } 8921007fd6fSAli Bahrami } 8931007fd6fSAli Bahrami 8941007fd6fSAli Bahrami /* 8951007fd6fSAli Bahrami * If -zguidance is used more than once, we take the first one. We 8961007fd6fSAli Bahrami * do this quietly if they have identical options, and with a warning 8971007fd6fSAli Bahrami * otherwise. 8981007fd6fSAli Bahrami */ 8991007fd6fSAli Bahrami if ((initial_guidance_flags & FLG_OFG_ENABLE) && 9001007fd6fSAli Bahrami (ofl_guideflags != initial_guidance_flags)) { 9011007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, MSG_INTL(MSG_ARG_MTONCE), 9021007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_ZGUIDE)); 9031007fd6fSAli Bahrami return (TRUE); 9041007fd6fSAli Bahrami } 9051007fd6fSAli Bahrami 9061007fd6fSAli Bahrami /* 9071007fd6fSAli Bahrami * First time: Save the flags for comparison to any subsequent 9081007fd6fSAli Bahrami * -z guidance that comes along, and OR the resulting flags into 9091007fd6fSAli Bahrami * the flags kept in the output descriptor. 9101007fd6fSAli Bahrami */ 9111007fd6fSAli Bahrami initial_guidance_flags = ofl_guideflags; 9121007fd6fSAli Bahrami ofl->ofl_guideflags |= ofl_guideflags; 9131007fd6fSAli Bahrami return (TRUE); 9141007fd6fSAli Bahrami } 9151007fd6fSAli Bahrami 916b533f56bSRobert Mustacchi /* 917b533f56bSRobert Mustacchi * Parse the -z assert-deflib option. This option can appear in two different 918b533f56bSRobert Mustacchi * forms: 919b533f56bSRobert Mustacchi * -z assert-deflib 920b533f56bSRobert Mustacchi * -z assert-deflib=libfred.so 921b533f56bSRobert Mustacchi * 922b533f56bSRobert Mustacchi * Either form enables this option, the latter form marks libfred.so as an 923b533f56bSRobert Mustacchi * exempt library from the check. It is valid to have multiple invocations of 924b533f56bSRobert Mustacchi * the second form. We silently ignore mulitple occurrences of the first form 925b533f56bSRobert Mustacchi * and multiple invocations of the first form when the second form also occurs. 926b533f56bSRobert Mustacchi * 927b533f56bSRobert Mustacchi * We only return false when we have an internal error, such as the failure of 928b533f56bSRobert Mustacchi * aplist_append. Every other time we return true, but we have the appropriate 929b533f56bSRobert Mustacchi * fatal flags set beacuse of the ld_eprintf. 930b533f56bSRobert Mustacchi */ 931b533f56bSRobert Mustacchi static int 932b533f56bSRobert Mustacchi assdeflib_parse(Ofl_desc *ofl, char *optarg) 933b533f56bSRobert Mustacchi { 934b533f56bSRobert Mustacchi size_t olen, mlen; 935b533f56bSRobert Mustacchi ofl->ofl_flags |= FLG_OF_ADEFLIB; 936b533f56bSRobert Mustacchi 937b533f56bSRobert Mustacchi olen = strlen(optarg); 938b533f56bSRobert Mustacchi /* Minimum size of assert-deflib=lib%s.so */ 939b533f56bSRobert Mustacchi mlen = MSG_ARG_ASSDEFLIB_SIZE + 1 + MSG_STR_LIB_SIZE + 940b533f56bSRobert Mustacchi MSG_STR_SOEXT_SIZE; 941b533f56bSRobert Mustacchi if (olen > MSG_ARG_ASSDEFLIB_SIZE) { 942b533f56bSRobert Mustacchi if (optarg[MSG_ARG_ASSDEFLIB_SIZE] != '=') { 943b533f56bSRobert Mustacchi ld_eprintf(ofl, ERR_FATAL, "Missing =\n"); 944b533f56bSRobert Mustacchi ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ILLEGAL), 945b533f56bSRobert Mustacchi MSG_ORIG(MSG_ARG_ASSDEFLIB), optarg); 946b533f56bSRobert Mustacchi return (TRUE); 947b533f56bSRobert Mustacchi } 948b533f56bSRobert Mustacchi 949b533f56bSRobert Mustacchi if (strncmp(optarg + MSG_ARG_ASSDEFLIB_SIZE + 1, 950b533f56bSRobert Mustacchi MSG_ORIG(MSG_STR_LIB), MSG_STR_LIB_SIZE) != 0 || 951b533f56bSRobert Mustacchi strcmp(optarg + olen - MSG_STR_SOEXT_SIZE, 952b533f56bSRobert Mustacchi MSG_ORIG(MSG_STR_SOEXT)) != 0 || olen <= mlen) { 953b533f56bSRobert Mustacchi ld_eprintf(ofl, ERR_FATAL, 954b533f56bSRobert Mustacchi MSG_INTL(MSG_ARG_ASSDEFLIB_MALFORMED), optarg); 955b533f56bSRobert Mustacchi return (TRUE); 956b533f56bSRobert Mustacchi } 957b533f56bSRobert Mustacchi 958b533f56bSRobert Mustacchi if (aplist_append(&ofl->ofl_assdeflib, optarg + 959b533f56bSRobert Mustacchi MSG_ARG_ASSDEFLIB_SIZE + 1, AL_CNT_ASSDEFLIB) == NULL) 960b533f56bSRobert Mustacchi return (FALSE); 961b533f56bSRobert Mustacchi } 962b533f56bSRobert Mustacchi 963b533f56bSRobert Mustacchi return (TRUE); 964b533f56bSRobert Mustacchi } 965b533f56bSRobert Mustacchi 9662017c965SRod Evans static int optitle = 0; 9677c478bd9Sstevel@tonic-gate /* 9687c478bd9Sstevel@tonic-gate * Parsing options pass1 for process_flags(). 9697c478bd9Sstevel@tonic-gate */ 9707c478bd9Sstevel@tonic-gate static uintptr_t 9711007fd6fSAli Bahrami parseopt_pass1(Ofl_desc *ofl, int argc, char **argv, int *usage) 9727c478bd9Sstevel@tonic-gate { 97392a02081SRod Evans int c, ndx = optind; 9747c478bd9Sstevel@tonic-gate 975ba2be530Sab196087 /* 97656e2cc86SAli Bahrami * The -32, -64 and -ztarget options are special, in that we validate 977ba2be530Sab196087 * them, but otherwise ignore them. libld.so (this code) is called 978ba2be530Sab196087 * from the ld front end program. ld has already examined the 979ba2be530Sab196087 * arguments to determine the output class and machine type of the 980ba2be530Sab196087 * output object, as reflected in the version (32/64) of ld_main() 981ba2be530Sab196087 * that was called and the value of the 'mach' argument passed. 982ba2be530Sab196087 * By time execution reaches this point, these options have already 983ba2be530Sab196087 * been seen and acted on. 984ba2be530Sab196087 */ 98592a02081SRod Evans while ((c = ld_getopt(ofl->ofl_lml, ndx, argc, argv)) != -1) { 9867c478bd9Sstevel@tonic-gate 9877c478bd9Sstevel@tonic-gate switch (c) { 98856e2cc86SAli Bahrami case '3': 98956e2cc86SAli Bahrami DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 99056e2cc86SAli Bahrami 99156e2cc86SAli Bahrami /* 99256e2cc86SAli Bahrami * -32 is processed by ld to determine the output class. 99356e2cc86SAli Bahrami * Here we sanity check the option incase some other 99456e2cc86SAli Bahrami * -3* option is mistakenly passed to us. 99556e2cc86SAli Bahrami */ 9961007fd6fSAli Bahrami if (optarg[0] != '2') 9971007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 99856e2cc86SAli Bahrami MSG_INTL(MSG_ARG_ILLEGAL), 99956e2cc86SAli Bahrami MSG_ORIG(MSG_ARG_3), optarg); 100056e2cc86SAli Bahrami continue; 100156e2cc86SAli Bahrami 1002ba2be530Sab196087 case '6': 10032017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 100492a02081SRod Evans 10057c478bd9Sstevel@tonic-gate /* 10067c478bd9Sstevel@tonic-gate * -64 is processed by ld to determine the output class. 10077c478bd9Sstevel@tonic-gate * Here we sanity check the option incase some other 10087c478bd9Sstevel@tonic-gate * -6* option is mistakenly passed to us. 10097c478bd9Sstevel@tonic-gate */ 10101007fd6fSAli Bahrami if (optarg[0] != '4') 10111007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 10125aefb655Srie MSG_INTL(MSG_ARG_ILLEGAL), 10137c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_6), optarg); 10147c478bd9Sstevel@tonic-gate continue; 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate case 'a': 10172017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 10187c478bd9Sstevel@tonic-gate aflag = TRUE; 10197c478bd9Sstevel@tonic-gate break; 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate case 'b': 10222017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 10237c478bd9Sstevel@tonic-gate bflag = TRUE; 10249039eeafSab196087 10259039eeafSab196087 /* 10269039eeafSab196087 * This is a hack, and may be undone later. 10279039eeafSab196087 * The -b option is only used to build the Unix 10289039eeafSab196087 * kernel and its related kernel-mode modules. 10299039eeafSab196087 * We do not want those files to get a .SUNW_ldynsym 10309039eeafSab196087 * section. At least for now, the kernel makes no 10319039eeafSab196087 * use of .SUNW_ldynsym, and we do not want to use 10329039eeafSab196087 * the space to hold it. Therefore, we overload 10339039eeafSab196087 * the use of -b to also imply -znoldynsym. 10349039eeafSab196087 */ 10359039eeafSab196087 ofl->ofl_flags |= FLG_OF_NOLDYNSYM; 10367c478bd9Sstevel@tonic-gate break; 10377c478bd9Sstevel@tonic-gate 10387c478bd9Sstevel@tonic-gate case 'c': 10392017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 10407c478bd9Sstevel@tonic-gate if (ofl->ofl_config) 10411007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 10425aefb655Srie MSG_INTL(MSG_ARG_MTONCE), 10437c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_C)); 10447c478bd9Sstevel@tonic-gate else 10457c478bd9Sstevel@tonic-gate ofl->ofl_config = optarg; 10467c478bd9Sstevel@tonic-gate break; 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate case 'C': 10492017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 10505aefb655Srie demangle_flag = 1; 10517c478bd9Sstevel@tonic-gate break; 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate case 'd': 10542017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 10557c478bd9Sstevel@tonic-gate if ((optarg[0] == 'n') && (optarg[1] == '\0')) { 10567c478bd9Sstevel@tonic-gate if (dflag != SET_UNKNOWN) 10571007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 10587c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 10597c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_D)); 10607c478bd9Sstevel@tonic-gate else 10617c478bd9Sstevel@tonic-gate dflag = SET_FALSE; 10627c478bd9Sstevel@tonic-gate } else if ((optarg[0] == 'y') && (optarg[1] == '\0')) { 10637c478bd9Sstevel@tonic-gate if (dflag != SET_UNKNOWN) 10641007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 10657c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 10667c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_D)); 10677c478bd9Sstevel@tonic-gate else 10687c478bd9Sstevel@tonic-gate dflag = SET_TRUE; 10697c478bd9Sstevel@tonic-gate } else { 10701007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 10715aefb655Srie MSG_INTL(MSG_ARG_ILLEGAL), 10727c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_D), optarg); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate break; 10757c478bd9Sstevel@tonic-gate 10767c478bd9Sstevel@tonic-gate case 'e': 10772017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 10787c478bd9Sstevel@tonic-gate if (ofl->ofl_entry) 10791007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 1080551cffe3SAli Bahrami MSG_INTL(MSG_MARG_MTONCE), 1081551cffe3SAli Bahrami MSG_INTL(MSG_MARG_ENTRY)); 10827c478bd9Sstevel@tonic-gate else 10837c478bd9Sstevel@tonic-gate ofl->ofl_entry = (void *)optarg; 10847c478bd9Sstevel@tonic-gate break; 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate case 'f': 10872017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 10887c478bd9Sstevel@tonic-gate if (ofl->ofl_filtees && 10897c478bd9Sstevel@tonic-gate (!(ofl->ofl_flags & FLG_OF_AUX))) { 10901007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 1091551cffe3SAli Bahrami MSG_INTL(MSG_MARG_INCOMP), 1092551cffe3SAli Bahrami MSG_INTL(MSG_MARG_FILTER_AUX), 1093551cffe3SAli Bahrami MSG_INTL(MSG_MARG_FILTER)); 10947c478bd9Sstevel@tonic-gate } else { 10957c478bd9Sstevel@tonic-gate if ((ofl->ofl_filtees = 10967c478bd9Sstevel@tonic-gate add_string(ofl->ofl_filtees, optarg)) == 10977c478bd9Sstevel@tonic-gate (const char *)S_ERROR) 10987c478bd9Sstevel@tonic-gate return (S_ERROR); 10997c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_AUX; 11007c478bd9Sstevel@tonic-gate } 11017c478bd9Sstevel@tonic-gate break; 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate case 'F': 11042017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 11057c478bd9Sstevel@tonic-gate if (ofl->ofl_filtees && 11067c478bd9Sstevel@tonic-gate (ofl->ofl_flags & FLG_OF_AUX)) { 11071007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 1108551cffe3SAli Bahrami MSG_INTL(MSG_MARG_INCOMP), 1109551cffe3SAli Bahrami MSG_INTL(MSG_MARG_FILTER), 1110551cffe3SAli Bahrami MSG_INTL(MSG_MARG_FILTER_AUX)); 11117c478bd9Sstevel@tonic-gate } else { 11127c478bd9Sstevel@tonic-gate if ((ofl->ofl_filtees = 11137c478bd9Sstevel@tonic-gate add_string(ofl->ofl_filtees, optarg)) == 11147c478bd9Sstevel@tonic-gate (const char *)S_ERROR) 11157c478bd9Sstevel@tonic-gate return (S_ERROR); 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate break; 11187c478bd9Sstevel@tonic-gate 11197c478bd9Sstevel@tonic-gate case 'h': 11202017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 11217c478bd9Sstevel@tonic-gate if (ofl->ofl_soname) 11221007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 1123551cffe3SAli Bahrami MSG_INTL(MSG_MARG_MTONCE), 1124551cffe3SAli Bahrami MSG_INTL(MSG_MARG_SONAME)); 11257c478bd9Sstevel@tonic-gate else 11267c478bd9Sstevel@tonic-gate ofl->ofl_soname = (const char *)optarg; 11277c478bd9Sstevel@tonic-gate break; 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate case 'i': 11302017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 11317c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_IGNENV; 11327c478bd9Sstevel@tonic-gate break; 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate case 'I': 11352017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 11367c478bd9Sstevel@tonic-gate if (ofl->ofl_interp) 11371007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 11385aefb655Srie MSG_INTL(MSG_ARG_MTONCE), 11397c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CI)); 11407c478bd9Sstevel@tonic-gate else 11417c478bd9Sstevel@tonic-gate ofl->ofl_interp = (const char *)optarg; 11427c478bd9Sstevel@tonic-gate break; 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate case 'l': 11452017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 11467c478bd9Sstevel@tonic-gate /* 11477c478bd9Sstevel@tonic-gate * For now, count any library as a shared object. This 11487c478bd9Sstevel@tonic-gate * is used to size the internal symbol cache. This 11497c478bd9Sstevel@tonic-gate * value is recalculated later on actual file processing 11507c478bd9Sstevel@tonic-gate * to get an accurate shared object count. 11517c478bd9Sstevel@tonic-gate */ 11527c478bd9Sstevel@tonic-gate ofl->ofl_soscnt++; 11537c478bd9Sstevel@tonic-gate break; 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate case 'm': 11562017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 11577c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_GENMAP; 11587c478bd9Sstevel@tonic-gate break; 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate case 'o': 11612017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 11627c478bd9Sstevel@tonic-gate if (ofl->ofl_name) 11631007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 1164551cffe3SAli Bahrami MSG_INTL(MSG_MARG_MTONCE), 1165551cffe3SAli Bahrami MSG_INTL(MSG_MARG_OUTFILE)); 11667c478bd9Sstevel@tonic-gate else 11677c478bd9Sstevel@tonic-gate ofl->ofl_name = (const char *)optarg; 11687c478bd9Sstevel@tonic-gate break; 11697c478bd9Sstevel@tonic-gate 11707c478bd9Sstevel@tonic-gate case 'p': 11712017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 117292a02081SRod Evans 11737c478bd9Sstevel@tonic-gate /* 11747c478bd9Sstevel@tonic-gate * Multiple instances of this option may occur. Each 11757c478bd9Sstevel@tonic-gate * additional instance is effectively concatenated to 11767c478bd9Sstevel@tonic-gate * the previous separated by a colon. 11777c478bd9Sstevel@tonic-gate */ 11787c478bd9Sstevel@tonic-gate if (*optarg != '\0') { 11797c478bd9Sstevel@tonic-gate if ((ofl->ofl_audit = 11807c478bd9Sstevel@tonic-gate add_string(ofl->ofl_audit, 11817c478bd9Sstevel@tonic-gate optarg)) == (const char *)S_ERROR) 11827c478bd9Sstevel@tonic-gate return (S_ERROR); 11837c478bd9Sstevel@tonic-gate } 11847c478bd9Sstevel@tonic-gate break; 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate case 'P': 11872017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 118892a02081SRod Evans 11897c478bd9Sstevel@tonic-gate /* 11907c478bd9Sstevel@tonic-gate * Multiple instances of this option may occur. Each 11917c478bd9Sstevel@tonic-gate * additional instance is effectively concatenated to 11927c478bd9Sstevel@tonic-gate * the previous separated by a colon. 11937c478bd9Sstevel@tonic-gate */ 11947c478bd9Sstevel@tonic-gate if (*optarg != '\0') { 11957c478bd9Sstevel@tonic-gate if ((ofl->ofl_depaudit = 11967c478bd9Sstevel@tonic-gate add_string(ofl->ofl_depaudit, 11977c478bd9Sstevel@tonic-gate optarg)) == (const char *)S_ERROR) 11987c478bd9Sstevel@tonic-gate return (S_ERROR); 11997c478bd9Sstevel@tonic-gate } 12007c478bd9Sstevel@tonic-gate break; 12017c478bd9Sstevel@tonic-gate 12027c478bd9Sstevel@tonic-gate case 'r': 12032017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 12047c478bd9Sstevel@tonic-gate rflag = TRUE; 12057c478bd9Sstevel@tonic-gate break; 12067c478bd9Sstevel@tonic-gate 12077c478bd9Sstevel@tonic-gate case 'R': 12082017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 120992a02081SRod Evans 12107c478bd9Sstevel@tonic-gate /* 12117c478bd9Sstevel@tonic-gate * Multiple instances of this option may occur. Each 12127c478bd9Sstevel@tonic-gate * additional instance is effectively concatenated to 12137c478bd9Sstevel@tonic-gate * the previous separated by a colon. 12147c478bd9Sstevel@tonic-gate */ 12157c478bd9Sstevel@tonic-gate if (*optarg != '\0') { 12167c478bd9Sstevel@tonic-gate if ((ofl->ofl_rpath = 12177c478bd9Sstevel@tonic-gate add_string(ofl->ofl_rpath, 12187c478bd9Sstevel@tonic-gate optarg)) == (const char *)S_ERROR) 12197c478bd9Sstevel@tonic-gate return (S_ERROR); 12207c478bd9Sstevel@tonic-gate } 12217c478bd9Sstevel@tonic-gate break; 12227c478bd9Sstevel@tonic-gate 12237c478bd9Sstevel@tonic-gate case 's': 12242017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 12257c478bd9Sstevel@tonic-gate sflag = TRUE; 12267c478bd9Sstevel@tonic-gate break; 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate case 't': 12292017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 12307c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_NOWARN; 12317c478bd9Sstevel@tonic-gate break; 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate case 'u': 12342017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 12357c478bd9Sstevel@tonic-gate break; 12367c478bd9Sstevel@tonic-gate 12377c478bd9Sstevel@tonic-gate case 'z': 12382017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 123992a02081SRod Evans 12407c478bd9Sstevel@tonic-gate /* 12417c478bd9Sstevel@tonic-gate * For specific help, print our usage message and exit 12427010c12aSrie * immediately to ensure a 0 return code. 12437c478bd9Sstevel@tonic-gate */ 12447c478bd9Sstevel@tonic-gate if (strncmp(optarg, MSG_ORIG(MSG_ARG_HELP), 12457c478bd9Sstevel@tonic-gate MSG_ARG_HELP_SIZE) == 0) { 12461007fd6fSAli Bahrami usage_mesg(TRUE); 12477c478bd9Sstevel@tonic-gate exit(0); 12487c478bd9Sstevel@tonic-gate } 12497c478bd9Sstevel@tonic-gate 12507c478bd9Sstevel@tonic-gate /* 12517c478bd9Sstevel@tonic-gate * For some options set a flag - further consistancy 12527c478bd9Sstevel@tonic-gate * checks will be carried out in check_flags(). 12537c478bd9Sstevel@tonic-gate */ 12547c478bd9Sstevel@tonic-gate if ((strncmp(optarg, MSG_ORIG(MSG_ARG_LD32), 12557c478bd9Sstevel@tonic-gate MSG_ARG_LD32_SIZE) == 0) || 12567c478bd9Sstevel@tonic-gate (strncmp(optarg, MSG_ORIG(MSG_ARG_LD64), 12577c478bd9Sstevel@tonic-gate MSG_ARG_LD64_SIZE) == 0)) { 12581007fd6fSAli Bahrami if (createargv(ofl, usage) == S_ERROR) 12597c478bd9Sstevel@tonic-gate return (S_ERROR); 12607c478bd9Sstevel@tonic-gate 12617c478bd9Sstevel@tonic-gate } else if ( 12627c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_DEFS)) == 0) { 12637c478bd9Sstevel@tonic-gate if (zdflag != SET_UNKNOWN) 12641007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 12657c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 12667c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZDEFNODEF)); 12677c478bd9Sstevel@tonic-gate else 12687c478bd9Sstevel@tonic-gate zdflag = SET_TRUE; 12691007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DEFS; 12707c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 12717c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NODEFS)) == 0) { 12727c478bd9Sstevel@tonic-gate if (zdflag != SET_UNKNOWN) 12731007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 12747c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 12757c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZDEFNODEF)); 12767c478bd9Sstevel@tonic-gate else 12777c478bd9Sstevel@tonic-gate zdflag = SET_FALSE; 12781007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DEFS; 12797c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 12807c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_TEXT)) == 0) { 12817c478bd9Sstevel@tonic-gate if (ztflag && 12821007fd6fSAli Bahrami (ztflag != MSG_ORIG(MSG_ARG_ZTEXT))) 12831007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 12847c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_INCOMP), 12857c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZTEXT), 12867c478bd9Sstevel@tonic-gate ztflag); 12877c478bd9Sstevel@tonic-gate ztflag = MSG_ORIG(MSG_ARG_ZTEXT); 12887c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 12897c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_TEXTOFF)) == 0) { 12907c478bd9Sstevel@tonic-gate if (ztflag && 12911007fd6fSAli Bahrami (ztflag != MSG_ORIG(MSG_ARG_ZTEXTOFF))) 12921007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 12937c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_INCOMP), 12947c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZTEXTOFF), 12957c478bd9Sstevel@tonic-gate ztflag); 12967c478bd9Sstevel@tonic-gate ztflag = MSG_ORIG(MSG_ARG_ZTEXTOFF); 12977c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 12987c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_TEXTWARN)) == 0) { 12997c478bd9Sstevel@tonic-gate if (ztflag && 13001007fd6fSAli Bahrami (ztflag != MSG_ORIG(MSG_ARG_ZTEXTWARN))) 13011007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 13027c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_INCOMP), 13037c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ZTEXTWARN), 13047c478bd9Sstevel@tonic-gate ztflag); 13057c478bd9Sstevel@tonic-gate ztflag = MSG_ORIG(MSG_ARG_ZTEXTWARN); 13067c478bd9Sstevel@tonic-gate 13077c478bd9Sstevel@tonic-gate /* 13087c478bd9Sstevel@tonic-gate * For other options simply set the ofl flags directly. 13097c478bd9Sstevel@tonic-gate */ 13107c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13117c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_RESCAN)) == 0) { 13127c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_RESCAN; 13137c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13147c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ABSEXEC)) == 0) { 13157c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_ABSEXEC; 13167c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13177c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_LOADFLTR)) == 0) { 13187c478bd9Sstevel@tonic-gate zlflag = TRUE; 13197c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13207c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NORELOC)) == 0) { 13217c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_NORELOC; 13227c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13237c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOVERSION)) == 0) { 13247c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_NOVERSEC; 13257c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13267c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_MULDEFS)) == 0) { 13277c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_MULDEFS; 13287c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13297c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_REDLOCSYM)) == 0) { 133044bac77bSrie ofl->ofl_flags |= FLG_OF_REDLSYM; 13317c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13327c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_INITFIRST)) == 0) { 13337c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_INITFIRST; 13347c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13357c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NODELETE)) == 0) { 13367c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_NODELETE; 13377c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13387c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOPARTIAL)) == 0) { 13397c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_NOPARTI; 13407c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13417c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOOPEN)) == 0) { 13427c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_NOOPEN; 13437c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13447c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOW)) == 0) { 13457c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_NOW; 13467c478bd9Sstevel@tonic-gate ofl->ofl_dtflags |= DF_BIND_NOW; 13477c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13487c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ORIGIN)) == 0) { 13497c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_ORIGIN; 13507c478bd9Sstevel@tonic-gate ofl->ofl_dtflags |= DF_ORIGIN; 13517c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13527c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NODEFAULTLIB)) == 0) { 13537c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_NODEFLIB; 13547c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13557c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NODUMP)) == 0) { 13567c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_NODUMP; 13577c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13587c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ENDFILTEE)) == 0) { 13597c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_ENDFILTEE; 13607c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13617c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_VERBOSE)) == 0) { 13627c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_VERBOSE; 13637c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13647c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_COMBRELOC)) == 0) { 1365e38a713aSrie ofl->ofl_flags |= FLG_OF_COMREL; 1366e38a713aSrie } else if (strcmp(optarg, 1367e38a713aSrie MSG_ORIG(MSG_ARG_NOCOMBRELOC)) == 0) { 1368e38a713aSrie ofl->ofl_flags |= FLG_OF_NOCOMREL; 13697c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 13707c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOCOMPSTRTAB)) == 0) { 13717c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_NCSTTAB; 13727c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 137370d3e49eSrie MSG_ORIG(MSG_ARG_NOINTERP)) == 0) { 137470d3e49eSrie ofl->ofl_flags1 |= FLG_OF1_NOINTRP; 137570d3e49eSrie } else if (strcmp(optarg, 13767c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_INTERPOSE)) == 0) { 13777c478bd9Sstevel@tonic-gate zinflag = TRUE; 13780bc07c75Srie } else if (strcmp(optarg, 13790bc07c75Srie MSG_ORIG(MSG_ARG_IGNORE)) == 0) { 13800bc07c75Srie ofl->ofl_flags1 |= FLG_OF1_IGNPRC; 13819039eeafSab196087 } else if (strcmp(optarg, 1382d2ef9fe9Sab196087 MSG_ORIG(MSG_ARG_RELAXRELOC)) == 0) { 1383d2ef9fe9Sab196087 ofl->ofl_flags1 |= FLG_OF1_RLXREL; 1384d2ef9fe9Sab196087 } else if (strcmp(optarg, 13850e233487SRod Evans MSG_ORIG(MSG_ARG_NORELAXRELOC)) == 0) { 13860e233487SRod Evans ofl->ofl_flags1 |= FLG_OF1_NRLXREL; 13870e233487SRod Evans } else if (strcmp(optarg, 13889039eeafSab196087 MSG_ORIG(MSG_ARG_NOLDYNSYM)) == 0) { 13899039eeafSab196087 ofl->ofl_flags |= FLG_OF_NOLDYNSYM; 13907247f888Srie } else if (strcmp(optarg, 13917247f888Srie MSG_ORIG(MSG_ARG_GLOBAUDIT)) == 0) { 13927247f888Srie ofl->ofl_dtflags_1 |= DF_1_GLOBAUDIT; 139356e2cc86SAli Bahrami } else if (strcmp(optarg, 139456e2cc86SAli Bahrami MSG_ORIG(MSG_ARG_NOSIGHANDLER)) == 0) { 139556e2cc86SAli Bahrami ofl->ofl_flags1 |= FLG_OF1_NOSGHND; 139608278a5eSRod Evans } else if (strcmp(optarg, 139708278a5eSRod Evans MSG_ORIG(MSG_ARG_SYMBOLCAP)) == 0) { 139808278a5eSRod Evans ofl->ofl_flags |= FLG_OF_OTOSCAP; 1399551cffe3SAli Bahrami 1400551cffe3SAli Bahrami /* 1401551cffe3SAli Bahrami * Check archive group usage 1402551cffe3SAli Bahrami * -z rescan-start ... -z rescan-end 1403551cffe3SAli Bahrami * to ensure they don't overlap and are well formed. 1404551cffe3SAli Bahrami */ 1405551cffe3SAli Bahrami } else if (strcmp(optarg, 1406551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_RESCAN_START)) == 0) { 1407551cffe3SAli Bahrami if (ofl->ofl_ars_gsandx == 0) { 1408551cffe3SAli Bahrami ofl->ofl_ars_gsandx = ndx; 1409551cffe3SAli Bahrami } else if (ofl->ofl_ars_gsandx > 0) { 1410551cffe3SAli Bahrami /* Another group is still open */ 14111007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 1412551cffe3SAli Bahrami MSG_INTL(MSG_ARG_AR_GRP_OLAP), 1413551cffe3SAli Bahrami MSG_INTL(MSG_MARG_AR_GRPS)); 1414551cffe3SAli Bahrami /* Don't report cascading errors */ 1415551cffe3SAli Bahrami ofl->ofl_ars_gsandx = -1; 1416551cffe3SAli Bahrami } 1417551cffe3SAli Bahrami } else if (strcmp(optarg, 1418551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_RESCAN_END)) == 0) { 1419551cffe3SAli Bahrami if (ofl->ofl_ars_gsandx > 0) { 1420551cffe3SAli Bahrami ofl->ofl_ars_gsandx = 0; 1421551cffe3SAli Bahrami } else if (ofl->ofl_ars_gsandx == 0) { 1422551cffe3SAli Bahrami /* There was no matching begin */ 14231007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 1424551cffe3SAli Bahrami MSG_INTL(MSG_ARG_AR_GRP_BAD), 1425551cffe3SAli Bahrami MSG_INTL(MSG_MARG_AR_GRP_END), 1426551cffe3SAli Bahrami MSG_INTL(MSG_MARG_AR_GRP_START)); 1427551cffe3SAli Bahrami /* Don't report cascading errors */ 1428551cffe3SAli Bahrami ofl->ofl_ars_gsandx = -1; 1429551cffe3SAli Bahrami } 1430cdcc71c0SAli Bahrami 1431cdcc71c0SAli Bahrami /* 1432cdcc71c0SAli Bahrami * If -z wrap is seen, enter the symbol to be wrapped 1433cdcc71c0SAli Bahrami * into the wrap AVL tree. 1434cdcc71c0SAli Bahrami */ 1435cdcc71c0SAli Bahrami } else if (strncmp(optarg, MSG_ORIG(MSG_ARG_WRAP), 1436cdcc71c0SAli Bahrami MSG_ARG_WRAP_SIZE) == 0) { 1437cdcc71c0SAli Bahrami if (ld_wrap_enter(ofl, 1438cdcc71c0SAli Bahrami optarg + MSG_ARG_WRAP_SIZE) == NULL) 1439cdcc71c0SAli Bahrami return (S_ERROR); 14401007fd6fSAli Bahrami } else if ((strncmp(optarg, MSG_ORIG(MSG_ARG_GUIDE), 14411007fd6fSAli Bahrami MSG_ARG_GUIDE_SIZE) == 0) && 14421007fd6fSAli Bahrami ((optarg[MSG_ARG_GUIDE_SIZE] == '=') || 14431007fd6fSAli Bahrami (optarg[MSG_ARG_GUIDE_SIZE] == '\0'))) { 14441007fd6fSAli Bahrami if (!guidance_parse(ofl, optarg)) 14451007fd6fSAli Bahrami return (S_ERROR); 14461007fd6fSAli Bahrami } else if (strcmp(optarg, 14471007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_FATWARN)) == 0) { 14481007fd6fSAli Bahrami if (zfwflag == SET_FALSE) { 14491007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 14501007fd6fSAli Bahrami MSG_INTL(MSG_ARG_MTONCE), 14511007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_ZFATWNOFATW)); 14521007fd6fSAli Bahrami } else { 14531007fd6fSAli Bahrami zfwflag = SET_TRUE; 14541007fd6fSAli Bahrami ofl->ofl_flags |= FLG_OF_FATWARN; 14551007fd6fSAli Bahrami } 14561007fd6fSAli Bahrami } else if (strcmp(optarg, 14571007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_NOFATWARN)) == 0) { 14581007fd6fSAli Bahrami if (zfwflag == SET_TRUE) 14591007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 14601007fd6fSAli Bahrami MSG_INTL(MSG_ARG_MTONCE), 14611007fd6fSAli Bahrami MSG_ORIG(MSG_ARG_ZFATWNOFATW)); 14621007fd6fSAli Bahrami else 14631007fd6fSAli Bahrami zfwflag = SET_FALSE; 1464cdcc71c0SAli Bahrami 14657c478bd9Sstevel@tonic-gate /* 1466b533f56bSRobert Mustacchi * Process everything related to -z assert-deflib. This 1467b533f56bSRobert Mustacchi * must be done in pass 1 because it gets used in pass 1468b533f56bSRobert Mustacchi * 2. 1469b533f56bSRobert Mustacchi */ 1470b533f56bSRobert Mustacchi } else if (strncmp(optarg, MSG_ORIG(MSG_ARG_ASSDEFLIB), 1471b533f56bSRobert Mustacchi MSG_ARG_ASSDEFLIB_SIZE) == 0) { 1472b533f56bSRobert Mustacchi if (assdeflib_parse(ofl, optarg) != TRUE) 1473b533f56bSRobert Mustacchi return (S_ERROR); 1474b533f56bSRobert Mustacchi /* 14750bc07c75Srie * The following options just need validation as they 14767c478bd9Sstevel@tonic-gate * are interpreted on the second pass through the 14777c478bd9Sstevel@tonic-gate * command line arguments. 14787c478bd9Sstevel@tonic-gate */ 14797c478bd9Sstevel@tonic-gate } else if ( 14807c478bd9Sstevel@tonic-gate strncmp(optarg, MSG_ORIG(MSG_ARG_INITARRAY), 14817c478bd9Sstevel@tonic-gate MSG_ARG_INITARRAY_SIZE) && 14827c478bd9Sstevel@tonic-gate strncmp(optarg, MSG_ORIG(MSG_ARG_FINIARRAY), 14837c478bd9Sstevel@tonic-gate MSG_ARG_FINIARRAY_SIZE) && 14847c478bd9Sstevel@tonic-gate strncmp(optarg, MSG_ORIG(MSG_ARG_PREINITARRAY), 14857c478bd9Sstevel@tonic-gate MSG_ARG_PREINITARRAY_SIZE) && 14867c478bd9Sstevel@tonic-gate strncmp(optarg, MSG_ORIG(MSG_ARG_RTLDINFO), 14877c478bd9Sstevel@tonic-gate MSG_ARG_RTLDINFO_SIZE) && 14887c478bd9Sstevel@tonic-gate strncmp(optarg, MSG_ORIG(MSG_ARG_DTRACE), 14897c478bd9Sstevel@tonic-gate MSG_ARG_DTRACE_SIZE) && 14907c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_ALLEXTRT)) && 14917c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_DFLEXTRT)) && 14927c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_DIRECT)) && 14937c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_NODIRECT)) && 14947c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_GROUPPERM)) && 14957c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_LAZYLOAD)) && 14967c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_NOGROUPPERM)) && 14977c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_NOLAZYLOAD)) && 1498f441771bSRod Evans strcmp(optarg, MSG_ORIG(MSG_ARG_NODEFERRED)) && 14997c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_RECORD)) && 15007010c12aSrie strcmp(optarg, MSG_ORIG(MSG_ARG_ALTEXEC64)) && 1501ba2be530Sab196087 strcmp(optarg, MSG_ORIG(MSG_ARG_WEAKEXT)) && 1502ba2be530Sab196087 strncmp(optarg, MSG_ORIG(MSG_ARG_TARGET), 1503551cffe3SAli Bahrami MSG_ARG_TARGET_SIZE) && 1504f441771bSRod Evans strcmp(optarg, MSG_ORIG(MSG_ARG_RESCAN_NOW)) && 1505f441771bSRod Evans strcmp(optarg, MSG_ORIG(MSG_ARG_DEFERRED))) { 15061007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 15075aefb655Srie MSG_INTL(MSG_ARG_ILLEGAL), 15087c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_Z), optarg); 15097c478bd9Sstevel@tonic-gate } 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate break; 15127c478bd9Sstevel@tonic-gate 15137c478bd9Sstevel@tonic-gate case 'D': 15147c478bd9Sstevel@tonic-gate /* 15157c478bd9Sstevel@tonic-gate * If we have not yet read any input files go ahead 15167c478bd9Sstevel@tonic-gate * and process any debugging options (this allows any 15177c478bd9Sstevel@tonic-gate * argument processing, entrance criteria and library 15187c478bd9Sstevel@tonic-gate * initialization to be displayed). Otherwise, if an 15197c478bd9Sstevel@tonic-gate * input file has been seen, skip interpretation until 15207c478bd9Sstevel@tonic-gate * process_files (this allows debugging to be turned 15217c478bd9Sstevel@tonic-gate * on and off around individual groups of files). 15227c478bd9Sstevel@tonic-gate */ 1523e23c41c9SAli Bahrami Dflag = 1; 15245aefb655Srie if (ofl->ofl_objscnt == 0) { 1525e23c41c9SAli Bahrami if (dbg_setup(ofl, optarg, 2) == 0) 15267c478bd9Sstevel@tonic-gate return (S_ERROR); 15275aefb655Srie } 152892a02081SRod Evans 152992a02081SRod Evans /* 153092a02081SRod Evans * A diagnostic can only be provided after dbg_setup(). 15312017c965SRod Evans * As this is the first diagnostic that can be produced 15322017c965SRod Evans * by ld(1), issue a title for timing and basic output. 153392a02081SRod Evans */ 15342017c965SRod Evans if ((optitle == 0) && DBG_ENABLED) { 15352017c965SRod Evans optitle++; 15362017c965SRod Evans DBG_CALL(Dbg_basic_options(ofl->ofl_lml)); 15372017c965SRod Evans } 15382017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 15397c478bd9Sstevel@tonic-gate break; 15407c478bd9Sstevel@tonic-gate 15417c478bd9Sstevel@tonic-gate case 'B': 15422017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 15437c478bd9Sstevel@tonic-gate if (strcmp(optarg, MSG_ORIG(MSG_ARG_DIRECT)) == 0) { 15447c478bd9Sstevel@tonic-gate if (Bdflag == SET_FALSE) { 15451007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 15467c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_INCOMP), 15477c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BNODIRECT), 15487c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BDIRECT)); 15491007fd6fSAli Bahrami } else { 15507c478bd9Sstevel@tonic-gate Bdflag = SET_TRUE; 15511007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB; 15521007fd6fSAli Bahrami } 15537c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 15547c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NODIRECT)) == 0) { 15557c478bd9Sstevel@tonic-gate if (Bdflag == SET_TRUE) { 15561007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 15577c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_INCOMP), 15587c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BDIRECT), 15597c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BNODIRECT)); 15601007fd6fSAli Bahrami } else { 15617c478bd9Sstevel@tonic-gate Bdflag = SET_FALSE; 15621007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB; 15631007fd6fSAli Bahrami } 15647c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 15657c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_SYMBOLIC)) == 0) 15667c478bd9Sstevel@tonic-gate Bsflag = TRUE; 15677c478bd9Sstevel@tonic-gate else if (strcmp(optarg, MSG_ORIG(MSG_ARG_REDUCE)) == 0) 15687c478bd9Sstevel@tonic-gate ofl->ofl_flags |= FLG_OF_PROCRED; 15697c478bd9Sstevel@tonic-gate else if (strcmp(optarg, MSG_ORIG(MSG_STR_LOCAL)) == 0) 15707c478bd9Sstevel@tonic-gate Blflag = TRUE; 15717c478bd9Sstevel@tonic-gate else if (strcmp(optarg, MSG_ORIG(MSG_ARG_GROUP)) == 0) 15727c478bd9Sstevel@tonic-gate Bgflag = TRUE; 15737c478bd9Sstevel@tonic-gate else if (strcmp(optarg, 15747c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_ELIMINATE)) == 0) 15757c478bd9Sstevel@tonic-gate Beflag = TRUE; 1576635216b6SRod Evans else if (strcmp(optarg, 1577635216b6SRod Evans MSG_ORIG(MSG_ARG_TRANSLATOR)) == 0) { 15781007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, 1579635216b6SRod Evans MSG_INTL(MSG_ARG_UNSUPPORTED), 1580635216b6SRod Evans MSG_ORIG(MSG_ARG_BTRANSLATOR)); 1581635216b6SRod Evans } else if (strcmp(optarg, 1582635216b6SRod Evans MSG_ORIG(MSG_STR_LD_DYNAMIC)) && 15837c478bd9Sstevel@tonic-gate strcmp(optarg, MSG_ORIG(MSG_ARG_STATIC))) { 15841007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 15855aefb655Srie MSG_INTL(MSG_ARG_ILLEGAL), 15867c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CB), optarg); 15877c478bd9Sstevel@tonic-gate } 15887c478bd9Sstevel@tonic-gate break; 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate case 'G': 15912017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 15927c478bd9Sstevel@tonic-gate Gflag = TRUE; 15937c478bd9Sstevel@tonic-gate break; 15947c478bd9Sstevel@tonic-gate 15957c478bd9Sstevel@tonic-gate case 'L': 15962017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 15977c478bd9Sstevel@tonic-gate break; 15987c478bd9Sstevel@tonic-gate 15997c478bd9Sstevel@tonic-gate case 'M': 16002017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 160157ef7aa9SRod Evans if (aplist_append(&(ofl->ofl_maps), optarg, 160257ef7aa9SRod Evans AL_CNT_OFL_MAPFILES) == NULL) 16037c478bd9Sstevel@tonic-gate return (S_ERROR); 16047c478bd9Sstevel@tonic-gate break; 16057c478bd9Sstevel@tonic-gate 16067c478bd9Sstevel@tonic-gate case 'N': 16072017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 16087c478bd9Sstevel@tonic-gate break; 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate case 'Q': 16112017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 16127c478bd9Sstevel@tonic-gate if ((optarg[0] == 'n') && (optarg[1] == '\0')) { 16137c478bd9Sstevel@tonic-gate if (Qflag != SET_UNKNOWN) 16141007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 16157c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 16167c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CQ)); 16177c478bd9Sstevel@tonic-gate else 16187c478bd9Sstevel@tonic-gate Qflag = SET_FALSE; 16197c478bd9Sstevel@tonic-gate } else if ((optarg[0] == 'y') && (optarg[1] == '\0')) { 16207c478bd9Sstevel@tonic-gate if (Qflag != SET_UNKNOWN) 16211007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 16227c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 16237c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CQ)); 16247c478bd9Sstevel@tonic-gate else 16257c478bd9Sstevel@tonic-gate Qflag = SET_TRUE; 16267c478bd9Sstevel@tonic-gate } else { 16271007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 16285aefb655Srie MSG_INTL(MSG_ARG_ILLEGAL), 16297c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CQ), optarg); 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate break; 16327c478bd9Sstevel@tonic-gate 16337c478bd9Sstevel@tonic-gate case 'S': 16342017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 163557ef7aa9SRod Evans if (aplist_append(&lib_support, optarg, 163657ef7aa9SRod Evans AL_CNT_SUPPORT) == NULL) 16377c478bd9Sstevel@tonic-gate return (S_ERROR); 16387c478bd9Sstevel@tonic-gate break; 16397c478bd9Sstevel@tonic-gate 16407c478bd9Sstevel@tonic-gate case 'V': 16412017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 16427c478bd9Sstevel@tonic-gate if (!Vflag) 16437c478bd9Sstevel@tonic-gate (void) fprintf(stderr, MSG_ORIG(MSG_STR_STRNL), 16447c478bd9Sstevel@tonic-gate ofl->ofl_sgsid); 16457c478bd9Sstevel@tonic-gate Vflag = TRUE; 16467c478bd9Sstevel@tonic-gate break; 16477c478bd9Sstevel@tonic-gate 16487c478bd9Sstevel@tonic-gate case 'Y': 16492017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, optarg)); 16507c478bd9Sstevel@tonic-gate if (strncmp(optarg, MSG_ORIG(MSG_ARG_LCOM), 2) == 0) { 16517c478bd9Sstevel@tonic-gate if (Llibdir) 16521007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 16537c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 16547c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CYL)); 16557c478bd9Sstevel@tonic-gate else 16567c478bd9Sstevel@tonic-gate Llibdir = optarg + 2; 16577c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 16587c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_UCOM), 2) == 0) { 16597c478bd9Sstevel@tonic-gate if (Ulibdir) 16601007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 16617c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 16627c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CYU)); 16637c478bd9Sstevel@tonic-gate else 16647c478bd9Sstevel@tonic-gate Ulibdir = optarg + 2; 16657c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 16667c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_PCOM), 2) == 0) { 16677c478bd9Sstevel@tonic-gate if (Plibpath) 16681007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING_NF, 16697c478bd9Sstevel@tonic-gate MSG_INTL(MSG_ARG_MTONCE), 16707c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CYP)); 16717c478bd9Sstevel@tonic-gate else 16727c478bd9Sstevel@tonic-gate Plibpath = optarg + 2; 16737c478bd9Sstevel@tonic-gate } else { 16741007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 16755aefb655Srie MSG_INTL(MSG_ARG_ILLEGAL), 16767c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CY), optarg); 16777c478bd9Sstevel@tonic-gate } 16787c478bd9Sstevel@tonic-gate break; 16797c478bd9Sstevel@tonic-gate 16807c478bd9Sstevel@tonic-gate case '?': 16812017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL)); 1682*c5accfb2SRichard Lowe /* 1683*c5accfb2SRichard Lowe * If the option character is '-', we're looking at a 1684*c5accfb2SRichard Lowe * long option which couldn't be translated, display a 1685*c5accfb2SRichard Lowe * more useful error. 1686*c5accfb2SRichard Lowe */ 1687*c5accfb2SRichard Lowe if (optopt == '-') { 1688*c5accfb2SRichard Lowe eprintf(ofl->ofl_lml, ERR_FATAL, 1689*c5accfb2SRichard Lowe MSG_INTL(MSG_ARG_LONG_UNKNOWN), 1690*c5accfb2SRichard Lowe argv[optind-1]); 1691*c5accfb2SRichard Lowe } else { 16921007fd6fSAli Bahrami eprintf(ofl->ofl_lml, ERR_FATAL, 16931007fd6fSAli Bahrami MSG_INTL(MSG_ARG_UNKNOWN), optopt); 1694*c5accfb2SRichard Lowe } 16951007fd6fSAli Bahrami (*usage)++; 16967c478bd9Sstevel@tonic-gate break; 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate default: 16997c478bd9Sstevel@tonic-gate break; 17007c478bd9Sstevel@tonic-gate } 170192a02081SRod Evans 170292a02081SRod Evans /* 170392a02081SRod Evans * Update the argument index for the next getopt() iteration. 170492a02081SRod Evans */ 170592a02081SRod Evans ndx = optind; 17067c478bd9Sstevel@tonic-gate } 17077c478bd9Sstevel@tonic-gate return (1); 17087c478bd9Sstevel@tonic-gate } 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate /* 17117c478bd9Sstevel@tonic-gate * Parsing options pass2 for 17127c478bd9Sstevel@tonic-gate */ 17137c478bd9Sstevel@tonic-gate static uintptr_t 17147c478bd9Sstevel@tonic-gate parseopt_pass2(Ofl_desc *ofl, int argc, char **argv) 17157c478bd9Sstevel@tonic-gate { 171692a02081SRod Evans int c, ndx = optind; 17177c478bd9Sstevel@tonic-gate 171892a02081SRod Evans while ((c = ld_getopt(ofl->ofl_lml, ndx, argc, argv)) != -1) { 17197c478bd9Sstevel@tonic-gate Ifl_desc *ifl; 17207c478bd9Sstevel@tonic-gate Sym_desc *sdp; 17217c478bd9Sstevel@tonic-gate 17227c478bd9Sstevel@tonic-gate switch (c) { 17237c478bd9Sstevel@tonic-gate case 'l': 17242017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 172592a02081SRod Evans optarg)); 17265aefb655Srie if (ld_find_library(optarg, ofl) == S_ERROR) 17277c478bd9Sstevel@tonic-gate return (S_ERROR); 17287c478bd9Sstevel@tonic-gate break; 17297c478bd9Sstevel@tonic-gate case 'B': 17302017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 173192a02081SRod Evans optarg)); 17327c478bd9Sstevel@tonic-gate if (strcmp(optarg, 17337c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_STR_LD_DYNAMIC)) == 0) { 17347c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_DYNAMIC) 17357c478bd9Sstevel@tonic-gate ofl->ofl_flags |= 17367c478bd9Sstevel@tonic-gate FLG_OF_DYNLIBS; 17377c478bd9Sstevel@tonic-gate else { 17381007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 173992a02081SRod Evans MSG_INTL(MSG_ARG_ST_INCOMP), 17407c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_BDYNAMIC)); 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 17437c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_STATIC)) == 0) 17447c478bd9Sstevel@tonic-gate ofl->ofl_flags &= ~FLG_OF_DYNLIBS; 17457c478bd9Sstevel@tonic-gate break; 17467c478bd9Sstevel@tonic-gate case 'L': 17472017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 174892a02081SRod Evans optarg)); 17495aefb655Srie if (ld_add_libdir(ofl, optarg) == S_ERROR) 17507c478bd9Sstevel@tonic-gate return (S_ERROR); 17517c478bd9Sstevel@tonic-gate break; 17527c478bd9Sstevel@tonic-gate case 'N': 17532017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 175492a02081SRod Evans optarg)); 17557c478bd9Sstevel@tonic-gate /* 17567c478bd9Sstevel@tonic-gate * Record DT_NEEDED string 17577c478bd9Sstevel@tonic-gate */ 17581007fd6fSAli Bahrami if (!(ofl->ofl_flags & FLG_OF_DYNAMIC)) 17591007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 176092a02081SRod Evans MSG_INTL(MSG_ARG_ST_INCOMP), 17617c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_CN)); 176257ef7aa9SRod Evans if (((ifl = libld_calloc(1, 176357ef7aa9SRod Evans sizeof (Ifl_desc))) == NULL) || 176457ef7aa9SRod Evans (aplist_append(&ofl->ofl_sos, ifl, 176557ef7aa9SRod Evans AL_CNT_OFL_LIBS) == NULL)) 17667c478bd9Sstevel@tonic-gate return (S_ERROR); 1767fb1354edSrie 1768fb1354edSrie ifl->ifl_name = MSG_INTL(MSG_STR_COMMAND); 17697c478bd9Sstevel@tonic-gate ifl->ifl_soname = optarg; 1770fb1354edSrie ifl->ifl_flags = (FLG_IF_NEEDSTR | 1771fb1354edSrie FLG_IF_FILEREF | FLG_IF_DEPREQD); 1772fb1354edSrie 17737c478bd9Sstevel@tonic-gate break; 17747c478bd9Sstevel@tonic-gate case 'D': 17752017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 177692a02081SRod Evans optarg)); 1777e23c41c9SAli Bahrami (void) dbg_setup(ofl, optarg, 3); 17787c478bd9Sstevel@tonic-gate break; 17797c478bd9Sstevel@tonic-gate case 'u': 17802017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 178192a02081SRod Evans optarg)); 1782f5a18a30Srie if (ld_sym_add_u(optarg, ofl, 1783f5a18a30Srie MSG_STR_COMMAND) == (Sym_desc *)S_ERROR) 17847c478bd9Sstevel@tonic-gate return (S_ERROR); 17857c478bd9Sstevel@tonic-gate break; 17867c478bd9Sstevel@tonic-gate case 'z': 17872017c965SRod Evans DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, 178892a02081SRod Evans optarg)); 17897c478bd9Sstevel@tonic-gate if ((strncmp(optarg, MSG_ORIG(MSG_ARG_LD32), 17907c478bd9Sstevel@tonic-gate MSG_ARG_LD32_SIZE) == 0) || 17917c478bd9Sstevel@tonic-gate (strncmp(optarg, MSG_ORIG(MSG_ARG_LD64), 17927c478bd9Sstevel@tonic-gate MSG_ARG_LD64_SIZE) == 0)) { 17937c478bd9Sstevel@tonic-gate if (createargv(ofl, 0) == S_ERROR) 17947c478bd9Sstevel@tonic-gate return (S_ERROR); 17957c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 17967c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_ALLEXTRT)) == 0) { 17977c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_ALLEXRT; 17987c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= ~FLG_OF1_WEAKEXT; 17997c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18007c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_WEAKEXT)) == 0) { 18017c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_WEAKEXT; 18027c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= ~FLG_OF1_ALLEXRT; 18037c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18047c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_DFLEXTRT)) == 0) { 18057c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= 18067247f888Srie ~(FLG_OF1_ALLEXRT | 18077247f888Srie FLG_OF1_WEAKEXT); 18087c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18097c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_DIRECT)) == 0) { 18107c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_ZDIRECT; 18111007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB; 18127c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18137c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NODIRECT)) == 0) { 18147c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= ~FLG_OF1_ZDIRECT; 18151007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB; 18167c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18177c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_IGNORE)) == 0) { 18180bc07c75Srie ofl->ofl_flags1 |= FLG_OF1_IGNORE; 18197c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18207c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_RECORD)) == 0) { 18217c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= ~FLG_OF1_IGNORE; 18227c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18237c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_LAZYLOAD)) == 0) { 18247c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_LAZYLD; 18251007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_LAZY; 18267c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18277c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOLAZYLOAD)) == 0) { 18287c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= ~ FLG_OF1_LAZYLD; 18291007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_LAZY; 18307c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18317c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_GROUPPERM)) == 0) { 18327c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_GRPPRM; 18337c478bd9Sstevel@tonic-gate } else if (strcmp(optarg, 18347c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_NOGROUPPERM)) == 0) { 18357c478bd9Sstevel@tonic-gate ofl->ofl_flags1 &= ~FLG_OF1_GRPPRM; 18367c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 18377c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_INITARRAY), 18387c478bd9Sstevel@tonic-gate MSG_ARG_INITARRAY_SIZE) == 0) { 18395aefb655Srie if (((sdp = ld_sym_add_u(optarg + 1840f5a18a30Srie MSG_ARG_INITARRAY_SIZE, ofl, 1841f5a18a30Srie MSG_STR_COMMAND)) == 18427c478bd9Sstevel@tonic-gate (Sym_desc *)S_ERROR) || 184357ef7aa9SRod Evans (aplist_append(&ofl->ofl_initarray, 184457ef7aa9SRod Evans sdp, AL_CNT_OFL_ARRAYS) == NULL)) 18457c478bd9Sstevel@tonic-gate return (S_ERROR); 18467c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 18477c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_FINIARRAY), 18487c478bd9Sstevel@tonic-gate MSG_ARG_FINIARRAY_SIZE) == 0) { 18495aefb655Srie if (((sdp = ld_sym_add_u(optarg + 1850f5a18a30Srie MSG_ARG_FINIARRAY_SIZE, ofl, 1851f5a18a30Srie MSG_STR_COMMAND)) == 18527c478bd9Sstevel@tonic-gate (Sym_desc *)S_ERROR) || 185357ef7aa9SRod Evans (aplist_append(&ofl->ofl_finiarray, 185457ef7aa9SRod Evans sdp, AL_CNT_OFL_ARRAYS) == NULL)) 18557c478bd9Sstevel@tonic-gate return (S_ERROR); 18567c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 18577c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_PREINITARRAY), 18587c478bd9Sstevel@tonic-gate MSG_ARG_PREINITARRAY_SIZE) == 0) { 18595aefb655Srie if (((sdp = ld_sym_add_u(optarg + 1860f5a18a30Srie MSG_ARG_PREINITARRAY_SIZE, ofl, 1861f5a18a30Srie MSG_STR_COMMAND)) == 18627c478bd9Sstevel@tonic-gate (Sym_desc *)S_ERROR) || 186357ef7aa9SRod Evans (aplist_append(&ofl->ofl_preiarray, 186457ef7aa9SRod Evans sdp, AL_CNT_OFL_ARRAYS) == NULL)) 18657c478bd9Sstevel@tonic-gate return (S_ERROR); 18667c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 18677c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_RTLDINFO), 18687c478bd9Sstevel@tonic-gate MSG_ARG_RTLDINFO_SIZE) == 0) { 18695aefb655Srie if (((sdp = ld_sym_add_u(optarg + 1870f5a18a30Srie MSG_ARG_RTLDINFO_SIZE, ofl, 1871f5a18a30Srie MSG_STR_COMMAND)) == 18727c478bd9Sstevel@tonic-gate (Sym_desc *)S_ERROR) || 187357ef7aa9SRod Evans (aplist_append(&ofl->ofl_rtldinfo, 187457ef7aa9SRod Evans sdp, AL_CNT_OFL_ARRAYS) == NULL)) 18757c478bd9Sstevel@tonic-gate return (S_ERROR); 18767c478bd9Sstevel@tonic-gate } else if (strncmp(optarg, 18777c478bd9Sstevel@tonic-gate MSG_ORIG(MSG_ARG_DTRACE), 18787c478bd9Sstevel@tonic-gate MSG_ARG_DTRACE_SIZE) == 0) { 18795aefb655Srie if ((sdp = ld_sym_add_u(optarg + 1880f5a18a30Srie MSG_ARG_DTRACE_SIZE, ofl, 1881f5a18a30Srie MSG_STR_COMMAND)) == 18827c478bd9Sstevel@tonic-gate (Sym_desc *)S_ERROR) 18837c478bd9Sstevel@tonic-gate return (S_ERROR); 18847c478bd9Sstevel@tonic-gate ofl->ofl_dtracesym = sdp; 1885551cffe3SAli Bahrami } else if (strcmp(optarg, 1886551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_RESCAN_NOW)) == 0) { 1887551cffe3SAli Bahrami if (ld_rescan_archives(ofl, 0, ndx) == 1888551cffe3SAli Bahrami S_ERROR) 1889551cffe3SAli Bahrami return (S_ERROR); 1890551cffe3SAli Bahrami } else if (strcmp(optarg, 1891551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_RESCAN_START)) == 0) { 1892551cffe3SAli Bahrami ofl->ofl_ars_gsndx = ofl->ofl_arscnt; 1893551cffe3SAli Bahrami ofl->ofl_ars_gsandx = ndx; 1894551cffe3SAli Bahrami } else if (strcmp(optarg, 1895551cffe3SAli Bahrami MSG_ORIG(MSG_ARG_RESCAN_END)) == 0) { 1896551cffe3SAli Bahrami if (ld_rescan_archives(ofl, 1, ndx) == 1897551cffe3SAli Bahrami S_ERROR) 1898551cffe3SAli Bahrami return (S_ERROR); 1899f441771bSRod Evans } else if (strcmp(optarg, 1900f441771bSRod Evans MSG_ORIG(MSG_ARG_DEFERRED)) == 0) { 1901f441771bSRod Evans ofl->ofl_flags1 |= FLG_OF1_DEFERRED; 1902f441771bSRod Evans } else if (strcmp(optarg, 1903f441771bSRod Evans MSG_ORIG(MSG_ARG_NODEFERRED)) == 0) { 1904f441771bSRod Evans ofl->ofl_flags1 &= ~FLG_OF1_DEFERRED; 19057c478bd9Sstevel@tonic-gate } 19067c478bd9Sstevel@tonic-gate default: 19077c478bd9Sstevel@tonic-gate break; 19087c478bd9Sstevel@tonic-gate } 190992a02081SRod Evans 191092a02081SRod Evans /* 191192a02081SRod Evans * Update the argument index for the next getopt() iteration. 191292a02081SRod Evans */ 191392a02081SRod Evans ndx = optind; 19147c478bd9Sstevel@tonic-gate } 19157c478bd9Sstevel@tonic-gate return (1); 19167c478bd9Sstevel@tonic-gate } 19177c478bd9Sstevel@tonic-gate 19187c478bd9Sstevel@tonic-gate /* 19197c478bd9Sstevel@tonic-gate * 19207c478bd9Sstevel@tonic-gate * Pass 1 -- process_flags: collects all options and sets flags 19217c478bd9Sstevel@tonic-gate */ 19227c478bd9Sstevel@tonic-gate static uintptr_t 19231007fd6fSAli Bahrami process_flags_com(Ofl_desc *ofl, int argc, char **argv, int *usage) 19247c478bd9Sstevel@tonic-gate { 19257c478bd9Sstevel@tonic-gate for (; optind < argc; optind++) { 19267c478bd9Sstevel@tonic-gate /* 19277c478bd9Sstevel@tonic-gate * If we detect some more options return to getopt(). 19287c478bd9Sstevel@tonic-gate * Checking argv[optind][1] against null prevents a forever 19297c478bd9Sstevel@tonic-gate * loop if an unadorned `-' argument is passed to us. 19307c478bd9Sstevel@tonic-gate */ 19317c478bd9Sstevel@tonic-gate while ((optind < argc) && (argv[optind][0] == '-')) { 19327c478bd9Sstevel@tonic-gate if (argv[optind][1] != '\0') { 19331007fd6fSAli Bahrami if (parseopt_pass1(ofl, argc, argv, 19341007fd6fSAli Bahrami usage) == S_ERROR) 19357c478bd9Sstevel@tonic-gate return (S_ERROR); 19367c478bd9Sstevel@tonic-gate } else if (++optind < argc) 19377c478bd9Sstevel@tonic-gate continue; 19387c478bd9Sstevel@tonic-gate } 19397c478bd9Sstevel@tonic-gate if (optind >= argc) 19407c478bd9Sstevel@tonic-gate break; 19417c478bd9Sstevel@tonic-gate ofl->ofl_objscnt++; 19427c478bd9Sstevel@tonic-gate } 1943551cffe3SAli Bahrami 1944551cffe3SAli Bahrami /* Did an unterminated archive group run off the end? */ 1945551cffe3SAli Bahrami if (ofl->ofl_ars_gsandx > 0) { 19461007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_AR_GRP_BAD), 1947551cffe3SAli Bahrami MSG_INTL(MSG_MARG_AR_GRP_START), 1948551cffe3SAli Bahrami MSG_INTL(MSG_MARG_AR_GRP_END)); 1949551cffe3SAli Bahrami return (S_ERROR); 1950551cffe3SAli Bahrami } 1951551cffe3SAli Bahrami 19527c478bd9Sstevel@tonic-gate return (1); 19537c478bd9Sstevel@tonic-gate } 19547c478bd9Sstevel@tonic-gate 19557c478bd9Sstevel@tonic-gate uintptr_t 19565aefb655Srie ld_process_flags(Ofl_desc *ofl, int argc, char **argv) 19577c478bd9Sstevel@tonic-gate { 19581007fd6fSAli Bahrami int usage = 0; /* Collect all argument errors before exit */ 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate if (argc < 2) { 19617c478bd9Sstevel@tonic-gate usage_mesg(FALSE); 19627c478bd9Sstevel@tonic-gate return (S_ERROR); 19637c478bd9Sstevel@tonic-gate } 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate /* 19667c478bd9Sstevel@tonic-gate * Option handling 19677c478bd9Sstevel@tonic-gate */ 196892a02081SRod Evans opterr = 0; 196992a02081SRod Evans optind = 1; 19701007fd6fSAli Bahrami if (process_flags_com(ofl, argc, argv, &usage) == S_ERROR) 19717c478bd9Sstevel@tonic-gate return (S_ERROR); 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate /* 19741007fd6fSAli Bahrami * Having parsed everything, did we have any usage errors. 19757c478bd9Sstevel@tonic-gate */ 19761007fd6fSAli Bahrami if (usage) { 19771007fd6fSAli Bahrami eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_ARG_USEHELP)); 19787c478bd9Sstevel@tonic-gate return (S_ERROR); 19797c478bd9Sstevel@tonic-gate } 19807c478bd9Sstevel@tonic-gate 19817c478bd9Sstevel@tonic-gate return (check_flags(ofl, argc)); 19827c478bd9Sstevel@tonic-gate } 19837c478bd9Sstevel@tonic-gate 19847c478bd9Sstevel@tonic-gate /* 19857c478bd9Sstevel@tonic-gate * Pass 2 -- process_files: skips the flags collected in pass 1 and processes 19867c478bd9Sstevel@tonic-gate * files. 19877c478bd9Sstevel@tonic-gate */ 19887c478bd9Sstevel@tonic-gate static uintptr_t 19897c478bd9Sstevel@tonic-gate process_files_com(Ofl_desc *ofl, int argc, char **argv) 19907c478bd9Sstevel@tonic-gate { 19917c478bd9Sstevel@tonic-gate for (; optind < argc; optind++) { 19927c478bd9Sstevel@tonic-gate int fd; 1993dc0f59e5SAli Bahrami uintptr_t open_ret; 19942926dd2eSrie char *path; 19957c478bd9Sstevel@tonic-gate Rej_desc rej = { 0 }; 19967c478bd9Sstevel@tonic-gate 19977c478bd9Sstevel@tonic-gate /* 19987c478bd9Sstevel@tonic-gate * If we detect some more options return to getopt(). 19997c478bd9Sstevel@tonic-gate * Checking argv[optind][1] against null prevents a forever 20007c478bd9Sstevel@tonic-gate * loop if an unadorned `-' argument is passed to us. 20017c478bd9Sstevel@tonic-gate */ 20027c478bd9Sstevel@tonic-gate while ((optind < argc) && (argv[optind][0] == '-')) { 20037c478bd9Sstevel@tonic-gate if (argv[optind][1] != '\0') { 20047c478bd9Sstevel@tonic-gate if (parseopt_pass2(ofl, argc, argv) == S_ERROR) 20057c478bd9Sstevel@tonic-gate return (S_ERROR); 20067c478bd9Sstevel@tonic-gate } else if (++optind < argc) 20077c478bd9Sstevel@tonic-gate continue; 20087c478bd9Sstevel@tonic-gate } 20097c478bd9Sstevel@tonic-gate if (optind >= argc) 20107c478bd9Sstevel@tonic-gate break; 20117c478bd9Sstevel@tonic-gate 20122926dd2eSrie path = argv[optind]; 20132926dd2eSrie if ((fd = open(path, O_RDONLY)) == -1) { 20147c478bd9Sstevel@tonic-gate int err = errno; 20157c478bd9Sstevel@tonic-gate 20161007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 20172926dd2eSrie MSG_INTL(MSG_SYS_OPEN), path, strerror(err)); 20187c478bd9Sstevel@tonic-gate continue; 20197c478bd9Sstevel@tonic-gate } 20207c478bd9Sstevel@tonic-gate 20212017c965SRod Evans DBG_CALL(Dbg_args_file(ofl->ofl_lml, optind, path)); 20227c478bd9Sstevel@tonic-gate 2023dc0f59e5SAli Bahrami open_ret = ld_process_open(path, path, &fd, ofl, 2024dc0f59e5SAli Bahrami (FLG_IF_CMDLINE | FLG_IF_NEEDED), &rej, NULL); 20253906e0c2Srie if (fd != -1) 20267c478bd9Sstevel@tonic-gate (void) close(fd); 2027dc0f59e5SAli Bahrami if (open_ret == S_ERROR) 20287c478bd9Sstevel@tonic-gate return (S_ERROR); 20297c478bd9Sstevel@tonic-gate 20307c478bd9Sstevel@tonic-gate /* 20317c478bd9Sstevel@tonic-gate * Check for mismatched input. 20327c478bd9Sstevel@tonic-gate */ 20337c478bd9Sstevel@tonic-gate if (rej.rej_type) { 2034de777a60Sab196087 Conv_reject_desc_buf_t rej_buf; 2035de777a60Sab196087 20361007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, 20375aefb655Srie MSG_INTL(reject[rej.rej_type]), 20387c478bd9Sstevel@tonic-gate rej.rej_name ? rej.rej_name : 2039de777a60Sab196087 MSG_INTL(MSG_STR_UNKNOWN), 2040ba2be530Sab196087 conv_reject_desc(&rej, &rej_buf, 2041ba2be530Sab196087 ld_targ.t_m.m_mach)); 20427c478bd9Sstevel@tonic-gate return (1); 20437c478bd9Sstevel@tonic-gate } 20447c478bd9Sstevel@tonic-gate } 20457c478bd9Sstevel@tonic-gate return (1); 20467c478bd9Sstevel@tonic-gate } 20477c478bd9Sstevel@tonic-gate 20487c478bd9Sstevel@tonic-gate uintptr_t 20495aefb655Srie ld_process_files(Ofl_desc *ofl, int argc, char **argv) 20507c478bd9Sstevel@tonic-gate { 20512017c965SRod Evans DBG_CALL(Dbg_basic_files(ofl->ofl_lml)); 20522017c965SRod Evans 20537c478bd9Sstevel@tonic-gate /* 20547c478bd9Sstevel@tonic-gate * Process command line files (taking into account any applicable 20552017c965SRod Evans * preceding flags). Return if any fatal errors have occurred. 20567c478bd9Sstevel@tonic-gate */ 205792a02081SRod Evans opterr = 0; 205892a02081SRod Evans optind = 1; 20597c478bd9Sstevel@tonic-gate if (process_files_com(ofl, argc, argv) == S_ERROR) 20607c478bd9Sstevel@tonic-gate return (S_ERROR); 20617c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_FATAL) 20627c478bd9Sstevel@tonic-gate return (1); 20637c478bd9Sstevel@tonic-gate 20647c478bd9Sstevel@tonic-gate /* 20651007fd6fSAli Bahrami * Guidance: Use -B direct/nodirect or -z direct/nodirect. 20661007fd6fSAli Bahrami * 20671007fd6fSAli Bahrami * This is a backstop for the case where the link had no dependencies. 20681007fd6fSAli Bahrami * Otherwise, it will get caught by ld_process_ifl(). We need both, 20691007fd6fSAli Bahrami * because -z direct is positional, and its value at the time where 20701007fd6fSAli Bahrami * the first dependency is seen might be different than it is now. 20711007fd6fSAli Bahrami */ 20721007fd6fSAli Bahrami if ((ofl->ofl_flags & FLG_OF_DYNAMIC) && 20731007fd6fSAli Bahrami OFL_GUIDANCE(ofl, FLG_OFG_NO_DB)) { 20741007fd6fSAli Bahrami ld_eprintf(ofl, ERR_GUIDANCE, MSG_INTL(MSG_GUIDE_DIRECT)); 20751007fd6fSAli Bahrami ofl->ofl_guideflags |= FLG_OFG_NO_DB; 20761007fd6fSAli Bahrami } 20771007fd6fSAli Bahrami 20781007fd6fSAli Bahrami /* 20797c478bd9Sstevel@tonic-gate * Now that all command line files have been processed see if there are 20807c478bd9Sstevel@tonic-gate * any additional `needed' shared object dependencies. 20817c478bd9Sstevel@tonic-gate */ 208257ef7aa9SRod Evans if (ofl->ofl_soneed) 20835aefb655Srie if (ld_finish_libs(ofl) == S_ERROR) 20847c478bd9Sstevel@tonic-gate return (S_ERROR); 20857c478bd9Sstevel@tonic-gate 20867c478bd9Sstevel@tonic-gate /* 20877c478bd9Sstevel@tonic-gate * If rescanning archives is enabled, do so now to determine whether 20887c478bd9Sstevel@tonic-gate * there might still be members extracted to satisfy references from any 20897c478bd9Sstevel@tonic-gate * explicit objects. Continue until no new objects are extracted. Note 20907c478bd9Sstevel@tonic-gate * that this pass is carried out *after* processing any implicit objects 20917c478bd9Sstevel@tonic-gate * (above) as they may already have resolved any undefined references 20927c478bd9Sstevel@tonic-gate * from any explicit dependencies. 20937c478bd9Sstevel@tonic-gate */ 2094551cffe3SAli Bahrami if (ofl->ofl_flags1 & FLG_OF1_RESCAN) { 2095551cffe3SAli Bahrami if (ld_rescan_archives(ofl, 0, argc) == S_ERROR) 20967c478bd9Sstevel@tonic-gate return (S_ERROR); 20977c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_FATAL) 20987c478bd9Sstevel@tonic-gate return (1); 20997c478bd9Sstevel@tonic-gate } 21007c478bd9Sstevel@tonic-gate 21017c478bd9Sstevel@tonic-gate /* 21027c478bd9Sstevel@tonic-gate * If debugging, provide statistics on each archives extraction, or flag 21037c478bd9Sstevel@tonic-gate * any archive that has provided no members. Note that this could be a 21047c478bd9Sstevel@tonic-gate * nice place to free up much of the archive infrastructure, as we've 21057c478bd9Sstevel@tonic-gate * extracted any members we need. However, as we presently don't free 21067c478bd9Sstevel@tonic-gate * anything under ld(1) there's not much point in proceeding further. 21077c478bd9Sstevel@tonic-gate */ 21087c478bd9Sstevel@tonic-gate DBG_CALL(Dbg_statistics_ar(ofl)); 21097c478bd9Sstevel@tonic-gate 21107c478bd9Sstevel@tonic-gate /* 21117c478bd9Sstevel@tonic-gate * If any version definitions have been established, either via input 21127c478bd9Sstevel@tonic-gate * from a mapfile or from the input relocatable objects, make sure any 21137c478bd9Sstevel@tonic-gate * version dependencies are satisfied, and version symbols created. 21147c478bd9Sstevel@tonic-gate */ 211557ef7aa9SRod Evans if (ofl->ofl_verdesc) 21165aefb655Srie if (ld_vers_check_defs(ofl) == S_ERROR) 21177c478bd9Sstevel@tonic-gate return (S_ERROR); 21187c478bd9Sstevel@tonic-gate 21197c478bd9Sstevel@tonic-gate /* 212069112eddSAli Bahrami * If input section ordering was specified within some segment 212169112eddSAli Bahrami * using a mapfile, verify that the expected sections were seen. 21227c478bd9Sstevel@tonic-gate */ 212369112eddSAli Bahrami if (ofl->ofl_flags & FLG_OF_IS_ORDER) 21245aefb655Srie ld_ent_check(ofl); 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate return (1); 21277c478bd9Sstevel@tonic-gate } 2128c1c6f601Srie 2129c1c6f601Srie uintptr_t 2130c1c6f601Srie ld_init_strings(Ofl_desc *ofl) 2131c1c6f601Srie { 2132c1c6f601Srie uint_t stflags; 2133c1c6f601Srie 2134c1c6f601Srie if (ofl->ofl_flags1 & FLG_OF1_NCSTTAB) 2135c1c6f601Srie stflags = 0; 2136c1c6f601Srie else 2137c1c6f601Srie stflags = FLG_STNEW_COMPRESS; 2138c1c6f601Srie 213957ef7aa9SRod Evans if (((ofl->ofl_shdrsttab = st_new(stflags)) == NULL) || 214057ef7aa9SRod Evans ((ofl->ofl_strtab = st_new(stflags)) == NULL) || 214157ef7aa9SRod Evans ((ofl->ofl_dynstrtab = st_new(stflags)) == NULL)) 2142c1c6f601Srie return (S_ERROR); 2143c1c6f601Srie 2144c1c6f601Srie return (0); 2145c1c6f601Srie } 2146