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]
21 /* Copyright (c) 1988 AT&T */
22 /* All Rights Reserved */
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
39 extern char *prog_name
;
43 * Print the symbols in the archive symbol table.
46 ar_sym_read(Elf
*elf
, char *filename
)
49 size_t cnt
, ptr
, is64
;
52 if ((arsym
= elf_getarsym(elf
, &ptr
)) == NULL
) {
53 (void) fprintf(stderr
, "%s: %s: no archive symbol table\n",
58 is64
= (_elf_getarsymwordsize(elf
) == 8);
59 (void) printf("%s:\n", filename
);
62 (void) printf(" **** ARCHIVE SYMBOL TABLE ****\n");
64 (void) printf("%-8s %s\n\n", "Offset", "Name");
65 fmt
= "%-16.16llx %s\n";
67 (void) printf("%-8s %s\n\n", "Offset", "Name");
68 fmt
= "%-8.8llx %s\n";
71 for (cnt
= 0; cnt
< ptr
; cnt
++, arsym
++) {
73 (void) printf(fmt
, EC_XWORD(arsym
->as_off
),
74 (arsym
->as_name
? arsym
->as_name
: ""));
79 * Print the program execution header. Input is an opened ELF object file, the
80 * number of structure instances in the header as recorded in the ELF header,
84 dump_exec_header(Elf
*elf_file
, unsigned nseg
, char *filename
)
90 extern int v_flag
, p_flag
;
91 extern char *prog_name
;
93 if (gelf_getclass(elf_file
) == ELFCLASS64
)
99 (void) printf(" ***** PROGRAM EXECUTION HEADER *****\n");
100 (void) printf("%-*s%-*s%-*s%s\n",
101 field
, "Type", field
, "Offset",
102 field
, "Vaddr", "Paddr");
103 (void) printf("%-*s%-*s%-*s%s\n\n",
104 field
, "Filesz", field
, "Memsz",
105 field
, "Flags", "Align");
108 if ((gelf_getehdr(elf_file
, &ehdr
) == 0) || (ehdr
.e_phnum
== 0)) {
112 for (counter
= 0; counter
< nseg
; counter
++) {
114 if (gelf_getphdr(elf_file
, counter
, &p_phdr
) == 0) {
115 (void) fprintf(stderr
,
116 "%s: %s: premature EOF on program exec header\n",
117 prog_name
, filename
);
123 "%-*d%-#*llx%-#*llx%-#*llx\n%-#*llx%-#*llx%-*u%-#*llx\n\n",
124 field
, EC_WORD(p_phdr
.p_type
),
125 field
, EC_OFF(p_phdr
.p_offset
),
126 field
, EC_ADDR(p_phdr
.p_vaddr
),
127 field
, EC_ADDR(p_phdr
.p_paddr
),
128 field
, EC_XWORD(p_phdr
.p_filesz
),
129 field
, EC_XWORD(p_phdr
.p_memsz
),
130 field
, EC_WORD(p_phdr
.p_flags
),
131 field
, EC_XWORD(p_phdr
.p_align
));
133 Conv_inv_buf_t inv_buf
;
135 (void) printf("%-*s", field
,
136 conv_phdr_type(ehdr
.e_ident
[EI_OSABI
],
137 ehdr
.e_machine
, p_phdr
.p_type
, DUMP_CONVFMT
,
140 "%-#*llx%-#*llx%-#*llx\n%-#*llx%-#*llx",
141 field
, EC_OFF(p_phdr
.p_offset
),
142 field
, EC_ADDR(p_phdr
.p_vaddr
),
143 field
, EC_ADDR(p_phdr
.p_paddr
),
144 field
, EC_XWORD(p_phdr
.p_filesz
),
145 field
, EC_XWORD(p_phdr
.p_memsz
));
147 switch (p_phdr
.p_flags
) {
148 case 0: (void) printf("%-*s", field
, "---"); break;
150 (void) printf("%-*s", field
, "--x");
153 (void) printf("%-*s", field
, "-w-");
156 (void) printf("%-*s", field
, "-wx");
159 (void) printf("%-*s", field
, "r--");
162 (void) printf("%-*s", field
, "r-x");
165 (void) printf("%-*s", field
, "rw-");
168 (void) printf("%-*s", field
, "rwx");
171 (void) printf("%-*d", field
, p_phdr
.p_flags
);
175 "%-#*llx\n\n", field
, EC_XWORD(p_phdr
.p_align
));