4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 1988 AT&T
23 * Copyright (c) 1989 AT&T
27 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI"
49 /* EXTERNAL VARIABLES DEFINED */
50 int fflag
= 0, /* print full output if -f option is supplied */
51 Fflag
= 0, /* print full output if -F option is supplied */
52 nflag
= 0; /* include NOLOAD sections in size if -n */
53 /* option is supplied */
54 int numbase
= DECIMAL
;
55 static int errflag
= 0; /* Global error flag */
57 int exitcode
= 0; /* Global exit code */
62 static char *tool_name
;
64 static void usagerr();
66 #define OPTSTR "VoxnfF" /* option string for usage error message */
67 #define GETOPTSTR "VoxnfF?" /* option string for getopt */
70 static Elf_Arhdr
*arhdr
;
75 * parses the command line
76 * opens, processes and closes each object file command line argument
79 * - int numbase = HEX if the -x flag is in the command line
80 * = OCTAL if the -o flag is in the command line
81 * = DECIMAL if the -d flag is in the command line
84 * - process(filename) to print the size information in the object file
88 * - an error message if any unknown options appear on the command line
89 * - a usage message if no object file args appear on the command line
90 * - an error message if it can't open an object file
91 * or if the object file has the wrong magic number
93 * exits 1 - errors found, 0 - no errors
96 main(int argc
, char ** argv
, char ** envp
)
98 /* UNIX FUNCTIONS CALLED */
101 /* SIZE FUNCTIONS CALLED */
102 extern void process();
104 /* EXTERNAL VARIABLES USED */
113 extern char *archive
;
119 * Check for a binary that better fits this architecture.
121 (void) conv_check_native(argv
, envp
);
125 while ((c
= getopt(argc
, argv
, GETOPTSTR
)) != EOF
) {
131 (void) fprintf(stderr
,
132 "size: -x set, -o ignored\n");
140 if (numbase
!= OCTAL
)
143 (void) fprintf(stderr
,
144 "size: -o set, -x ignored\n");
159 (void) fprintf(stderr
, "size: %s %s\n",
160 (const char *)SGU_PKG
,
161 (const char *)SGU_REL
);
171 if (errflag
|| (optind
>= argc
)) {
172 if (!(Vflag
&& (argc
== 2) && !errflag
)) {
176 if ((argc
- optind
) == 1) {
177 oneflag
++; /* only one file to process */
180 if (elf_version(EV_CURRENT
) == EV_NONE
) {
181 (void) fprintf(stderr
, "size: Libelf is out of date");
182 exit(FATAL
); /* library out of date */
185 for (; optind
< argc
; optind
++) {
186 fname
= argv
[optind
];
187 if ((fd
= open(argv
[optind
], O_RDONLY
)) == -1) {
188 error(fname
, "cannot open");
193 if ((arf
= elf_begin(fd
, cmd
, arf
)) == 0) {
194 /* error(fname, "cannot open"); */
195 (void) fprintf(stderr
,
196 "size: %s: %s\n", fname
, elf_errmsg(-1));
200 if (elf_kind(arf
) == ELF_K_AR
) {
201 archive
= argv
[optind
];
206 while ((elf
= elf_begin(fd
, cmd
, arf
)) != 0) {
207 if ((arhdr
= elf_getarhdr(elf
)) == 0) {
208 if (elf_kind(arf
) == ELF_K_NONE
) {
210 (void) fprintf(stderr
,
211 "%s: %s: invalid file type\n",
219 } else if (arhdr
->ar_name
[0] != '/') {
220 fname
= arhdr
->ar_name
;
221 if (elf_kind(arf
) == ELF_K_NONE
) {
223 (void) fprintf(stderr
,
224 "%s: %s[%s]: invalid file type\n",
225 tool_name
, archive
, fname
);
251 (void) fprintf(stderr
,
252 "usage: %s [-%s] file(s)...\n", tool_name
, OPTSTR
);