4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Set bits in the DT_FLAGS_1 member of the .dynamic section of an object.
43 #include <sys/types.h>
50 * These are here because we can't be sure (yet) that the build machine has a
51 * sys/link.h that includes the following #defines. This tool will be executed
52 * on the build machine, so we have to use its headers (rather than the ones
53 * in $ROOT which will, by definition, be up to date). These #defines can be
54 * removed when we're sure that all build machines have recent copies of
57 #ifndef DF_1_IGNMULDEF
58 #define DF_1_IGNMULDEF 0x00040000
61 #define DF_1_NOKSYMS 0x00080000
69 static struct dtflagval dtflagvals
[] = {
70 { "DF_1_IGNMULDEF", DF_1_IGNMULDEF
},
71 { "DF_1_NOKSYMS", DF_1_NOKSYMS
},
80 (void) fprintf(stderr
, "Usage: %s -f flag_val file\n", progname
);
85 set_flag(char *ifile
, ulong_t flval
)
92 int fd
, secidx
, nent
, i
;
94 (void) elf_version(EV_CURRENT
);
96 if ((fd
= open(ifile
, O_RDWR
)) < 0)
97 die("Can't open %s", ifile
);
99 if ((elf
= elf_begin(fd
, ELF_C_RDWR
, NULL
)) == NULL
)
100 elfdie("Can't start ELF for %s", ifile
);
102 if ((secidx
= findelfsecidx(elf
, ".dynamic")) == -1)
103 die("Can't find .dynamic section in %s\n", ifile
);
105 if ((scn
= elf_getscn(elf
, secidx
)) == NULL
)
106 elfdie("elf_getscn (%d)", secidx
);
108 if (gelf_getshdr(scn
, &shdr
) == NULL
)
111 if ((data
= elf_getdata(scn
, NULL
)) == NULL
)
112 elfdie("elf_getdata");
114 nent
= shdr
.sh_size
/ shdr
.sh_entsize
;
115 for (i
= 0; i
< nent
; i
++) {
116 if (gelf_getdyn(data
, i
, &dyn
) == NULL
)
117 elfdie("gelf_getdyn");
119 if (dyn
.d_tag
== DT_FLAGS_1
) {
120 dyn
.d_un
.d_val
|= (Elf64_Xword
)flval
;
122 if (gelf_update_dyn(data
, i
, &dyn
) == 0)
123 elfdie("gelf_update_dyn");
130 die("%s's .dynamic section doesn't have a DT_FLAGS_1 "
134 if (elf_update(elf
, ELF_C_WRITE
) == -1)
135 elfdie("Couldn't update %s with changes", ifile
);
142 parse_flag(char *optarg
)
148 for (arg
= strtok(optarg
, ","); arg
!= NULL
; arg
= strtok(NULL
, ",")) {
149 for (i
= 0; dtflagvals
[i
].fv_name
!= NULL
; i
++) {
150 if (strcmp(dtflagvals
[i
].fv_name
, arg
) == 0)
151 flval
|= dtflagvals
[i
].fv_val
;
159 main(int argc
, char **argv
)
164 progname
= basename(argv
[0]);
166 while ((c
= getopt(argc
, argv
, "f:")) != EOF
) {
169 if ((flval
= strtoul(optarg
, NULL
, 0)) == 0 &&
170 (flval
= parse_flag(optarg
)) == 0)
178 if (flval
== 0 || argc
- optind
!= 1)
181 set_flag(argv
[optind
], flval
);