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
26 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
53 #define FORMAT "%-16s%-12ld%-6u%-6u%-8o%-10ld%-2s"
54 #define ROUNDUP(x) (((x) + 1) & ~1)
57 #define DELETED -1 /* The section will be removed */
58 #define NULLED -2 /* The section will be nulled */
59 #define EXPANDED -3 /* The size of the section expanded */
60 #define SHRUNK -4 /* The section shrinked */
62 #define ACT_NOP 0x00000000
63 #define ACT_DELETE 0x00000001
64 #define ACT_PRINT 0x00000002
65 #define ACT_COMPRESS 0x00000003
66 #define ACT_APPEND 0x00000004
67 #define ACT_ZAP 0x00000005
68 #define SET_ACTION(x, y) x = (x & 0xfffffff0) | y
69 #define GET_ACTION(x) (x & 0x0000000f)
71 #define NOSEG 0x00000010
72 #define IN 0x00000020 /* section is IN a segment */
73 #define PRIOR 0x00000030 /* section is PRIOR to a segment */
74 #define AFTER 0x00000040 /* section is AFTER a segment */
75 #define SET_LOC(x, y) x = (x & 0xffffff0f) | y
76 #define GET_LOC(x) (x & 0x000000f0)
78 #define CANDIDATE 0x00000100
79 #define MOVING 0x00000200
80 #define MODIFIED 0x00000400
82 #define UNSET_CANDIDATE(x) x = x & ~CANDIDATE
83 #define SET_CANDIDATE(x) x = x | CANDIDATE
84 #define ISCANDIDATE(x) (x & CANDIDATE)
85 #define SET_MOVING(x) x = (x | MOVING)
86 #define GET_MOVING(x) (x & MOVING)
87 #define SET_MODIFIED(x) x = (x | MODIFIED)
88 #define GET_MODIFIED(x) (x & MODIFIED)
93 #define DONT_BUILD 3 /* this code is used to prevent building a new file */
94 /* because mcs was given only -p */
99 #define STR_STRIP "strip"
102 * Structure to hold section information.
104 typedef struct section_info_table
{
106 * Section information.
108 Elf_Scn
*scn
; /* Section */
109 Elf_Data
*data
; /* Original data */
110 Elf_Data
*mdata
; /* Modified data */
111 char *name
; /* Section name, or NULL if unknown */
114 GElf_Word secno
; /* The new index */
115 GElf_Word osecno
; /* The original index */
116 GElf_Word rel_scn_index
;
119 } section_info_table
;
122 * Structure to hold action information
124 typedef struct action
{
125 int a_action
; /* Which action to take ? */
126 int a_cnt
; /* Am I applied ? */
127 char *a_string
; /* The string to be added. */
131 * Structure to hold the section names specified.
133 typedef struct s_name
{
138 #define SECT_NAME sect_head->name
139 #define SNAME_FLG_STRNCMP 0x01 /* Use strncmp() instead of strcmp() */
140 /* for section name comparison. */
143 * Structure to hold command information
145 typedef struct cmd_info
{
146 APlist
*sh_groups
; /* list of SHT_GROUP sections */
150 int no_of_compressed
;
152 size_t str_size
; /* size of string to be appended */
153 int flags
; /* Various flags */
156 #define MIGHT_CHG 0x0001
165 #define I_AM_STRIP 0x0200
166 #define SHF_GROUP_MOVE 0x0400 /* SHF_GROUP section moves */
167 #define SHF_GROUP_DEL 0x0800 /* SHF_GROUP section deleted */
169 #define CHK_OPT(_x, _y) (_x->flags & _y)
174 typedef struct seg_table
{
184 const char *tmp_name
; /* NULL, or name of temp file */
185 int tmp_unlink
; /* True if should unlink prior to exit */
189 * Function prototypes.
191 int apply_action(section_info_table
*, char *, Cmd_Info
*);
192 int each_file(char *, Cmd_Info
*);
193 void error_message(int, ...);
196 void free_tempfile(Tmp_File
*);
201 #define MALLOC_ERROR 0
202 #define USAGE_ERROR 1
203 #define ELFVER_ERROR 2
205 #define LIBELF_ERROR 4
206 #define OPEN_TEMP_ERROR 5
207 #define WRITE_ERROR 6
208 #define GETARHDR_ERROR 7
209 #define FILE_TYPE_ERROR 8
210 #define NOT_MANIPULATED_ERROR 9
211 #define WRN_MANIPULATED_ERROR 10
212 #define NO_SECT_TABLE_ERROR 11
213 #define READ_ERROR 12
214 #define READ_MANI_ERROR 13
215 #define WRITE_MANI_ERROR 14
216 #define LSEEK_MANI_ERROR 15
217 #define SYM_TAB_AR_ERROR 16
218 #define EXEC_AR_ERROR 17
219 #define READ_SYS_ERROR 18
220 #define OPEN_WRITE_ERROR 19
221 #define ACT_PRINT_ERROR 20
222 #define ACT_DELETE1_ERROR 21
223 #define ACT_DELETE2_ERROR 22
224 #define ACT_APPEND1_ERROR 23
225 #define ACT_APPEND2_ERROR 24
226 #define ACT_COMPRESS1_ERROR 25
227 #define ACT_COMPRESS2_ERROR 26
228 #define ACCESS_ERROR 27
229 #define WRITE_MANI_ERROR2 28
231 #define PLAIN_ERROR 0
232 #define LIBelf_ERROR 1
233 #define SYSTEM_ERROR 2