Mercurial > hg > truffle
annotate src/os/solaris/fix_empty_sec_hdr_flags/fix_empty_sec_hdr_flags.c @ 16677:e342886ed437
ignore all zip files
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Sat, 02 Aug 2014 11:14:27 +0200 |
parents | 9c1709c4c80c |
children |
rev | line source |
---|---|
6095
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
1 /* |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
4 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
8 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
13 * accompanied this code). |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
14 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
18 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
21 * questions. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
22 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
23 */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
24 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
25 /* |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
26 * Name: fix_empty_sec_hdr_flags.c |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
27 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
28 * Description: Remove the SHF_ALLOC flag from "empty" section headers. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
29 * An "empty" section header has sh_addr == 0 and sh_size == 0. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
30 * |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
31 * This program is adapted from the example program shown on the |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
32 * elf(3elf) man page and from code from the Solaris compiler |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
33 * driver. |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
34 */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
35 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
36 #include <fcntl.h> |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
37 #include <stdio.h> |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
38 #include <libelf.h> |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
39 #include <stdlib.h> |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
40 #include <string.h> |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
41 #include <unistd.h> |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
42 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
43 static void failure(void); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
44 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
45 void |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
46 main(int argc, char ** argv) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
47 void * ehdr; /* ELF header */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
48 unsigned int i; /* section counter */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
49 int fd; /* descriptor for file */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
50 Elf * elf; /* ELF descriptor */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
51 char * elf_ident; /* ELF identity string */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
52 char * elf_obj; /* elf_obj file */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
53 int fix_count; /* number of flags fixed */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
54 int is_elfclass64; /* is an ELFCLASS64 file? */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
55 Elf_Scn * scn; /* ELF section descriptor */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
56 void * shdr; /* ELF section header */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
57 Elf_Data * shstrtab; /* ELF section header string table */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
58 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
59 if (argc != 2) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
60 (void) fprintf(stderr, "Usage: %s elf_obj\n", argv[0]); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
61 exit(2); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
62 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
63 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
64 /* open the elf_obj */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
65 elf_obj = argv[1]; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
66 if ((fd = open(elf_obj, O_RDWR)) == -1) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
67 (void) fprintf(stderr, "%s: cannot open file.\n", elf_obj); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
68 exit(3); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
69 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
70 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
71 (void) printf("Opening '%s' for update\n", elf_obj); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
72 (void) fflush(stdout); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
73 (void) elf_version(EV_CURRENT); /* coordinate ELF versions */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
74 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
75 /* obtain the ELF descriptors from the input file */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
76 if ((elf = elf_begin(fd, ELF_C_RDWR, NULL)) == NULL) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
77 failure(); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
78 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
79 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
80 /* determine if ELFCLASS64 or not? */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
81 elf_ident = elf_getident(elf, NULL); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
82 is_elfclass64 = (elf_ident[EI_CLASS] == ELFCLASS64); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
83 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
84 /* get the ELF header */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
85 if (is_elfclass64) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
86 ehdr = elf64_getehdr(elf); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
87 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
88 ehdr = elf32_getehdr(elf); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
89 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
90 if (ehdr == NULL) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
91 failure(); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
92 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
93 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
94 /* get the ELF section descriptor */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
95 if (is_elfclass64) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
96 scn = elf_getscn(elf, ((Elf64_Ehdr *) ehdr)->e_shstrndx); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
97 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
98 scn = elf_getscn(elf, ((Elf32_Ehdr *) ehdr)->e_shstrndx); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
99 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
100 if (scn == NULL) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
101 failure(); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
102 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
103 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
104 /* get the section header string table */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
105 shstrtab = elf_getdata(scn, NULL); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
106 if (shstrtab == NULL) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
107 failure(); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
108 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
109 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
110 fix_count = 0; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
111 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
112 /* traverse the sections of the input file */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
113 for (i = 1, scn = NULL; scn = elf_nextscn(elf, scn); i++) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
114 int has_flag_set; /* is SHF_ALLOC flag set? */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
115 int is_empty; /* is section empty? */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
116 char * name; /* short hand pointer */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
117 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
118 /* get the section header */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
119 if (is_elfclass64) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
120 shdr = elf64_getshdr(scn); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
121 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
122 shdr = elf32_getshdr(scn); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
123 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
124 if (shdr == NULL) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
125 failure(); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
126 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
127 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
128 if (is_elfclass64) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
129 name = (char *)shstrtab->d_buf + ((Elf64_Shdr *) shdr)->sh_name; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
130 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
131 name = (char *)shstrtab->d_buf + ((Elf32_Shdr *) shdr)->sh_name; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
132 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
133 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
134 if (is_elfclass64) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
135 has_flag_set = ((Elf64_Shdr *) shdr)->sh_flags & SHF_ALLOC; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
136 is_empty = ((Elf64_Shdr *) shdr)->sh_addr == 0 && |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
137 ((Elf64_Shdr *) shdr)->sh_size == 0; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
138 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
139 has_flag_set = ((Elf32_Shdr *) shdr)->sh_flags & SHF_ALLOC; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
140 is_empty = ((Elf32_Shdr *) shdr)->sh_addr == 0 && |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
141 ((Elf32_Shdr *) shdr)->sh_size == 0; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
142 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
143 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
144 if (is_empty && has_flag_set) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
145 (void) printf("section[%u] '%s' is empty, " |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
146 "but SHF_ALLOC flag is set.\n", i, name); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
147 (void) printf("Clearing the SHF_ALLOC flag.\n"); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
148 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
149 if (is_elfclass64) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
150 ((Elf64_Shdr *) shdr)->sh_flags &= ~SHF_ALLOC; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
151 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
152 ((Elf32_Shdr *) shdr)->sh_flags &= ~SHF_ALLOC; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
153 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
154 fix_count++; |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
155 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
156 } /* end for each ELF section */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
157 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
158 if (fix_count > 0) { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
159 (void) printf("Saving %d updates to '%s'\n", fix_count, elf_obj); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
160 (void) fflush(stdout); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
161 (void) elf_update(elf, ELF_C_NULL); /* recalc ELF memory structures */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
162 (void) elf_update(elf, ELF_C_WRITE); /* write out changes to ELF obj */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
163 } else { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
164 (void) printf("No SHF_ALLOC flags needed to be cleared.\n"); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
165 } |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
166 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
167 (void) elf_end(elf); /* done with ELF obj */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
168 (void) close(fd); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
169 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
170 (void) printf("Done %s '%s'\n", |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
171 (fix_count > 0) ? "updating" : "with", elf_obj); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
172 (void) fflush(stdout); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
173 exit(0); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
174 } /* end main */ |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
175 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
176 |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
177 static void |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
178 failure() { |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
179 (void) fprintf(stderr, "%s\n", elf_errmsg(elf_errno())); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
180 exit(6); |
9c1709c4c80c
7165598: enable FDS on Solaris X64 when 7165593 is fixed
dcubed
parents:
diff
changeset
|
181 } |