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.
46 /* EXTERNAL VARIABLES DEFINED */
47 int fflag
= 0, /* print full output if -f option is supplied */
48 Fflag
= 0, /* print full output if -F option is supplied */
49 nflag
= 0; /* include NOLOAD sections in size if -n */
50 /* option is supplied */
51 int numbase
= DECIMAL
;
52 static int errflag
= 0; /* Global error flag */
54 int exitcode
= 0; /* Global exit code */
59 static char *tool_name
;
61 static void usagerr();
63 #define OPTSTR "VoxnfF" /* option string for usage error message */
64 #define GETOPTSTR "VoxnfF?" /* option string for getopt */
67 static Elf_Arhdr
*arhdr
;
72 * parses the command line
73 * opens, processes and closes each object file command line argument
76 * - int numbase = HEX if the -x flag is in the command line
77 * = OCTAL if the -o flag is in the command line
78 * = DECIMAL if the -d flag is in the command line
81 * - process(filename) to print the size information in the object file
85 * - an error message if any unknown options appear on the command line
86 * - a usage message if no object file args appear on the command line
87 * - an error message if it can't open an object file
88 * or if the object file has the wrong magic number
90 * exits 1 - errors found, 0 - no errors
93 main(int argc
, char ** argv
, char ** envp
)
95 /* UNIX FUNCTIONS CALLED */
98 /* SIZE FUNCTIONS CALLED */
99 extern void process();
101 /* EXTERNAL VARIABLES USED */
110 extern char *archive
;
117 while ((c
= getopt(argc
, argv
, GETOPTSTR
)) != EOF
) {
123 (void) fprintf(stderr
,
124 "size: -x set, -o ignored\n");
132 if (numbase
!= OCTAL
)
135 (void) fprintf(stderr
,
136 "size: -o set, -x ignored\n");
151 (void) fprintf(stderr
, "size: %s %s\n",
152 (const char *)SGU_PKG
,
153 (const char *)SGU_REL
);
163 if (errflag
|| (optind
>= argc
)) {
164 if (!(Vflag
&& (argc
== 2) && !errflag
)) {
168 if ((argc
- optind
) == 1) {
169 oneflag
++; /* only one file to process */
172 if (elf_version(EV_CURRENT
) == EV_NONE
) {
173 (void) fprintf(stderr
, "size: Libelf is out of date");
174 exit(FATAL
); /* library out of date */
177 for (; optind
< argc
; optind
++) {
178 fname
= argv
[optind
];
179 if ((fd
= open(argv
[optind
], O_RDONLY
)) == -1) {
180 error(fname
, "cannot open");
185 if ((arf
= elf_begin(fd
, cmd
, arf
)) == 0) {
186 /* error(fname, "cannot open"); */
187 (void) fprintf(stderr
,
188 "size: %s: %s\n", fname
, elf_errmsg(-1));
192 if (elf_kind(arf
) == ELF_K_AR
) {
193 archive
= argv
[optind
];
198 while ((elf
= elf_begin(fd
, cmd
, arf
)) != 0) {
199 if ((arhdr
= elf_getarhdr(elf
)) == 0) {
200 if (elf_kind(arf
) == ELF_K_NONE
) {
202 (void) fprintf(stderr
,
203 "%s: %s: invalid file type\n",
211 } else if (arhdr
->ar_name
[0] != '/') {
212 fname
= arhdr
->ar_name
;
213 if (elf_kind(arf
) == ELF_K_NONE
) {
215 (void) fprintf(stderr
,
216 "%s: %s[%s]: invalid file type\n",
217 tool_name
, archive
, fname
);
243 (void) fprintf(stderr
,
244 "usage: %s [-%s] file(s)...\n", tool_name
, OPTSTR
);