90 |
* is made the last in the table to avoid changing any existing index. |
* is made the last in the table to avoid changing any existing index. |
91 |
*/ |
*/ |
92 |
|
|
93 |
/* Modified by wtien@urbana.mcd.mot.com of Motorola Inc. |
/* Modified by wtien@urbana.mcd.mot.com of Motorola Inc. |
94 |
* |
* |
95 |
* The above mechanism does not work if the unexeced ELF file is being |
* The above mechanism does not work if the unexeced ELF file is being |
96 |
* re-layout by other applications (such as `strip'). All the applications |
* re-layout by other applications (such as `strip'). All the applications |
97 |
* that re-layout the internal of ELF will layout all sections in ascending |
* that re-layout the internal of ELF will layout all sections in ascending |
98 |
* order of their file offsets. After the re-layout, the data2 section will |
* order of their file offsets. After the re-layout, the data2 section will |
99 |
* still be the LAST section in the section header vector, but its file offset |
* still be the LAST section in the section header vector, but its file offset |
100 |
* is now being pushed far away down, and causes part of it not to be mapped |
* is now being pushed far away down, and causes part of it not to be mapped |
101 |
* in (ie. not covered by the load segment entry in PHDR vector), therefore |
* in (ie. not covered by the load segment entry in PHDR vector), therefore |
102 |
* causes the new binary to fail. |
* causes the new binary to fail. |
103 |
* |
* |
104 |
* The solution is to modify the unexec algorithm to insert the new data2 |
* The solution is to modify the unexec algorithm to insert the new data2 |
105 |
* section header right before the new bss section header, so their file |
* section header right before the new bss section header, so their file |
106 |
* offsets will be in the ascending order. Since some of the section's (all |
* offsets will be in the ascending order. Since some of the section's (all |
107 |
* sections AFTER the bss section) indexes are now changed, we also need to |
* sections AFTER the bss section) indexes are now changed, we also need to |
108 |
* modify some fields to make them point to the right sections. This is done |
* modify some fields to make them point to the right sections. This is done |
109 |
* by macro PATCH_INDEX. All the fields that need to be patched are: |
* by macro PATCH_INDEX. All the fields that need to be patched are: |
110 |
* |
* |
111 |
* 1. ELF header e_shstrndx field. |
* 1. ELF header e_shstrndx field. |
112 |
* 2. section header sh_link and sh_info field. |
* 2. section header sh_link and sh_info field. |
113 |
* 3. symbol table entry st_shndx field. |
* 3. symbol table entry st_shndx field. |
124 |
* |
* |
125 |
* /home1/marco/emacs/emacs-19.22/src |
* /home1/marco/emacs/emacs-19.22/src |
126 |
* dump -hv temacs |
* dump -hv temacs |
127 |
* |
* |
128 |
* temacs: |
* temacs: |
129 |
* |
* |
130 |
* **** SECTION HEADER TABLE **** |
* **** SECTION HEADER TABLE **** |
132 |
* Link Info Adralgn Entsize |
* Link Info Adralgn Entsize |
133 |
* |
* |
134 |
* [1] PBIT -A-- 0x4000f4 0xf4 0x13 .interp |
* [1] PBIT -A-- 0x4000f4 0xf4 0x13 .interp |
135 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
136 |
* |
* |
137 |
* [2] REGI -A-- 0x400108 0x108 0x18 .reginfo |
* [2] REGI -A-- 0x400108 0x108 0x18 .reginfo |
138 |
* 0 0 0x4 0x18 |
* 0 0 0x4 0x18 |
139 |
* |
* |
140 |
* [3] DYNM -A-- 0x400120 0x120 0xb8 .dynamic |
* [3] DYNM -A-- 0x400120 0x120 0xb8 .dynamic |
141 |
* 6 0 0x4 0x8 |
* 6 0 0x4 0x8 |
142 |
* |
* |
143 |
* [4] HASH -A-- 0x4001d8 0x1d8 0x8a0 .hash |
* [4] HASH -A-- 0x4001d8 0x1d8 0x8a0 .hash |
144 |
* 5 0 0x4 0x4 |
* 5 0 0x4 0x4 |
145 |
* |
* |
146 |
* [5] DYNS -A-- 0x400a78 0xa78 0x11f0 .dynsym |
* [5] DYNS -A-- 0x400a78 0xa78 0x11f0 .dynsym |
147 |
* 6 2 0x4 0x10 |
* 6 2 0x4 0x10 |
148 |
* |
* |
149 |
* [6] STRT -A-- 0x401c68 0x1c68 0xbf9 .dynstr |
* [6] STRT -A-- 0x401c68 0x1c68 0xbf9 .dynstr |
150 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
151 |
* |
* |
152 |
* [7] REL -A-- 0x402864 0x2864 0x18 .rel.dyn |
* [7] REL -A-- 0x402864 0x2864 0x18 .rel.dyn |
153 |
* 5 14 0x4 0x8 |
* 5 14 0x4 0x8 |
154 |
* |
* |
155 |
* [8] PBIT -AI- 0x402880 0x2880 0x60 .init |
* [8] PBIT -AI- 0x402880 0x2880 0x60 .init |
156 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
157 |
* |
* |
158 |
* [9] PBIT -AI- 0x4028e0 0x28e0 0x1234 .plt |
* [9] PBIT -AI- 0x4028e0 0x28e0 0x1234 .plt |
159 |
* 0 0 0x4 0x4 |
* 0 0 0x4 0x4 |
160 |
* |
* |
161 |
* [10] PBIT -AI- 0x403b20 0x3b20 0xee400 .text |
* [10] PBIT -AI- 0x403b20 0x3b20 0xee400 .text |
162 |
* 0 0 0x20 0x1 |
* 0 0 0x20 0x1 |
163 |
* |
* |
164 |
* [11] PBIT -AI- 0x4f1f20 0xf1f20 0x60 .fini |
* [11] PBIT -AI- 0x4f1f20 0xf1f20 0x60 .fini |
165 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
166 |
* |
* |
167 |
* [12] PBIT -A-- 0x4f1f80 0xf1f80 0xd90 .rdata |
* [12] PBIT -A-- 0x4f1f80 0xf1f80 0xd90 .rdata |
168 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
169 |
* |
* |
170 |
* [13] PBIT -A-- 0x4f2d10 0xf2d10 0x17e0 .rodata |
* [13] PBIT -A-- 0x4f2d10 0xf2d10 0x17e0 .rodata |
171 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
172 |
* |
* |
173 |
* [14] PBIT WA-- 0x5344f0 0xf44f0 0x4b3e4 .data <<<<< |
* [14] PBIT WA-- 0x5344f0 0xf44f0 0x4b3e4 .data <<<<< |
174 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
175 |
* |
* |
176 |
* [15] PBIT WA-G 0x57f8d4 0x13f8d4 0x2a84 .got |
* [15] PBIT WA-G 0x57f8d4 0x13f8d4 0x2a84 .got |
177 |
* 0 0 0x4 0x4 |
* 0 0 0x4 0x4 |
178 |
* |
* |
179 |
* [16] PBIT WA-G 0x582360 0x142360 0x10 .sdata <<<<< |
* [16] PBIT WA-G 0x582360 0x142360 0x10 .sdata <<<<< |
180 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
181 |
* |
* |
182 |
* [17] NOBI WA-G 0x582370 0x142370 0xb84 .sbss <<<<< |
* [17] NOBI WA-G 0x582370 0x142370 0xb84 .sbss <<<<< |
183 |
* 0 0 0x4 0 |
* 0 0 0x4 0 |
184 |
* |
* |
185 |
* [18] NOBI WA-- 0x582f00 0x142370 0x27ec0 .bss <<<<< |
* [18] NOBI WA-- 0x582f00 0x142370 0x27ec0 .bss <<<<< |
186 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
187 |
* |
* |
188 |
* [19] SYMT ---- 0 0x142370 0x10e40 .symtab |
* [19] SYMT ---- 0 0x142370 0x10e40 .symtab |
189 |
* 20 1108 0x4 0x10 |
* 20 1108 0x4 0x10 |
190 |
* |
* |
191 |
* [20] STRT ---- 0 0x1531b0 0xed9e .strtab |
* [20] STRT ---- 0 0x1531b0 0xed9e .strtab |
192 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
193 |
* |
* |
194 |
* [21] STRT ---- 0 0x161f4e 0xb5 .shstrtab |
* [21] STRT ---- 0 0x161f4e 0xb5 .shstrtab |
195 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
196 |
* |
* |
197 |
* [22] PBIT ---- 0 0x162003 0x28e2a .comment |
* [22] PBIT ---- 0 0x162003 0x28e2a .comment |
198 |
* 0 0 0x1 0x1 |
* 0 0 0x1 0x1 |
199 |
* |
* |
200 |
* [23] PBIT ---- 0 0x18ae2d 0x592 .debug |
* [23] PBIT ---- 0 0x18ae2d 0x592 .debug |
201 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
202 |
* |
* |
203 |
* [24] PBIT ---- 0 0x18b3bf 0x80 .line |
* [24] PBIT ---- 0 0x18b3bf 0x80 .line |
204 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
205 |
* |
* |
206 |
* [25] MDBG ---- 0 0x18b440 0x60 .mdebug |
* [25] MDBG ---- 0 0x18b440 0x60 .mdebug |
207 |
* 0 0 0x4 0 |
* 0 0 0x4 0 |
208 |
* |
* |
209 |
* |
* |
210 |
* dump -hv emacs |
* dump -hv emacs |
211 |
* |
* |
212 |
* emacs: |
* emacs: |
213 |
* |
* |
214 |
* **** SECTION HEADER TABLE **** |
* **** SECTION HEADER TABLE **** |
216 |
* Link Info Adralgn Entsize |
* Link Info Adralgn Entsize |
217 |
* |
* |
218 |
* [1] PBIT -A-- 0x4000f4 0xf4 0x13 .interp |
* [1] PBIT -A-- 0x4000f4 0xf4 0x13 .interp |
219 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
220 |
* |
* |
221 |
* [2] REGI -A-- 0x400108 0x108 0x18 .reginfo |
* [2] REGI -A-- 0x400108 0x108 0x18 .reginfo |
222 |
* 0 0 0x4 0x18 |
* 0 0 0x4 0x18 |
223 |
* |
* |
224 |
* [3] DYNM -A-- 0x400120 0x120 0xb8 .dynamic |
* [3] DYNM -A-- 0x400120 0x120 0xb8 .dynamic |
225 |
* 6 0 0x4 0x8 |
* 6 0 0x4 0x8 |
226 |
* |
* |
227 |
* [4] HASH -A-- 0x4001d8 0x1d8 0x8a0 .hash |
* [4] HASH -A-- 0x4001d8 0x1d8 0x8a0 .hash |
228 |
* 5 0 0x4 0x4 |
* 5 0 0x4 0x4 |
229 |
* |
* |
230 |
* [5] DYNS -A-- 0x400a78 0xa78 0x11f0 .dynsym |
* [5] DYNS -A-- 0x400a78 0xa78 0x11f0 .dynsym |
231 |
* 6 2 0x4 0x10 |
* 6 2 0x4 0x10 |
232 |
* |
* |
233 |
* [6] STRT -A-- 0x401c68 0x1c68 0xbf9 .dynstr |
* [6] STRT -A-- 0x401c68 0x1c68 0xbf9 .dynstr |
234 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
235 |
* |
* |
236 |
* [7] REL -A-- 0x402864 0x2864 0x18 .rel.dyn |
* [7] REL -A-- 0x402864 0x2864 0x18 .rel.dyn |
237 |
* 5 14 0x4 0x8 |
* 5 14 0x4 0x8 |
238 |
* |
* |
239 |
* [8] PBIT -AI- 0x402880 0x2880 0x60 .init |
* [8] PBIT -AI- 0x402880 0x2880 0x60 .init |
240 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
241 |
* |
* |
242 |
* [9] PBIT -AI- 0x4028e0 0x28e0 0x1234 .plt |
* [9] PBIT -AI- 0x4028e0 0x28e0 0x1234 .plt |
243 |
* 0 0 0x4 0x4 |
* 0 0 0x4 0x4 |
244 |
* |
* |
245 |
* [10] PBIT -AI- 0x403b20 0x3b20 0xee400 .text |
* [10] PBIT -AI- 0x403b20 0x3b20 0xee400 .text |
246 |
* 0 0 0x20 0x1 |
* 0 0 0x20 0x1 |
247 |
* |
* |
248 |
* [11] PBIT -AI- 0x4f1f20 0xf1f20 0x60 .fini |
* [11] PBIT -AI- 0x4f1f20 0xf1f20 0x60 .fini |
249 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
250 |
* |
* |
251 |
* [12] PBIT -A-- 0x4f1f80 0xf1f80 0xd90 .rdata |
* [12] PBIT -A-- 0x4f1f80 0xf1f80 0xd90 .rdata |
252 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
253 |
* |
* |
254 |
* [13] PBIT -A-- 0x4f2d10 0xf2d10 0x17e0 .rodata |
* [13] PBIT -A-- 0x4f2d10 0xf2d10 0x17e0 .rodata |
255 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
256 |
* |
* |
257 |
* [14] PBIT WA-- 0x5344f0 0xf44f0 0x4b3e4 .data <<<<< |
* [14] PBIT WA-- 0x5344f0 0xf44f0 0x4b3e4 .data <<<<< |
258 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
259 |
* |
* |
260 |
* [15] PBIT WA-G 0x57f8d4 0x13f8d4 0x2a84 .got |
* [15] PBIT WA-G 0x57f8d4 0x13f8d4 0x2a84 .got |
261 |
* 0 0 0x4 0x4 |
* 0 0 0x4 0x4 |
262 |
* |
* |
263 |
* [16] PBIT WA-G 0x582360 0x142360 0xb94 .sdata <<<<< |
* [16] PBIT WA-G 0x582360 0x142360 0xb94 .sdata <<<<< |
264 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
265 |
* |
* |
266 |
* [17] PBIT WA-- 0x582f00 0x142f00 0x94100 .data <<<<< |
* [17] PBIT WA-- 0x582f00 0x142f00 0x94100 .data <<<<< |
267 |
* 0 0 0x10 0x1 |
* 0 0 0x10 0x1 |
268 |
* |
* |
269 |
* [18] NOBI WA-G 0x617000 0x1d7000 0 .sbss <<<<< |
* [18] NOBI WA-G 0x617000 0x1d7000 0 .sbss <<<<< |
270 |
* 0 0 0x4 0 |
* 0 0 0x4 0 |
271 |
* |
* |
272 |
* [19] NOBI WA-- 0x617000 0x1d7000 0 .bss <<<<< |
* [19] NOBI WA-- 0x617000 0x1d7000 0 .bss <<<<< |
273 |
* 0 0 0x4 0x1 |
* 0 0 0x4 0x1 |
274 |
* |
* |
275 |
* [20] SYMT ---- 0 0x1d7000 0x10e40 .symtab |
* [20] SYMT ---- 0 0x1d7000 0x10e40 .symtab |
276 |
* 21 1109 0x4 0x10 |
* 21 1109 0x4 0x10 |
277 |
* |
* |
278 |
* [21] STRT ---- 0 0x1e7e40 0xed9e .strtab |
* [21] STRT ---- 0 0x1e7e40 0xed9e .strtab |
279 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
280 |
* |
* |
281 |
* [22] STRT ---- 0 0x1f6bde 0xb5 .shstrtab |
* [22] STRT ---- 0 0x1f6bde 0xb5 .shstrtab |
282 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
283 |
* |
* |
284 |
* [23] PBIT ---- 0 0x1f6c93 0x28e2a .comment |
* [23] PBIT ---- 0 0x1f6c93 0x28e2a .comment |
285 |
* 0 0 0x1 0x1 |
* 0 0 0x1 0x1 |
286 |
* |
* |
287 |
* [24] PBIT ---- 0 0x21fabd 0x592 .debug |
* [24] PBIT ---- 0 0x21fabd 0x592 .debug |
288 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
289 |
* |
* |
290 |
* [25] PBIT ---- 0 0x22004f 0x80 .line |
* [25] PBIT ---- 0 0x22004f 0x80 .line |
291 |
* 0 0 0x1 0 |
* 0 0 0x1 0 |
292 |
* |
* |
293 |
* [26] MDBG ---- 0 0x2200d0 0x60 .mdebug |
* [26] MDBG ---- 0 0x2200d0 0x60 .mdebug |
294 |
* 0 0 0x4 0 |
* 0 0 0x4 0 |
295 |
* |
* |
296 |
*/ |
*/ |
297 |
|
|
450 |
{ |
{ |
451 |
old_sdata_index = old_sbss_index - 1; |
old_sdata_index = old_sbss_index - 1; |
452 |
} |
} |
453 |
|
|
454 |
|
|
455 |
/* Find the old .bss section. |
/* Find the old .bss section. |
456 |
*/ |
*/ |
683 |
if (old_data_index == old_file_h->e_shnum) |
if (old_data_index == old_file_h->e_shnum) |
684 |
fatal ("Can't find .data in %s.\n", old_name, 0); |
fatal ("Can't find .data in %s.\n", old_name, 0); |
685 |
|
|
686 |
/* Walk through all section headers, insert the new data2 section right |
/* Walk through all section headers, insert the new data2 section right |
687 |
before the new bss section. */ |
before the new bss section. */ |
688 |
for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++) |
for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++) |
689 |
{ |
{ |
698 |
{ |
{ |
699 |
memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(old_data_index), |
memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(old_data_index), |
700 |
new_file_h->e_shentsize); |
new_file_h->e_shentsize); |
701 |
|
|
702 |
NEW_SECTION_H(nn).sh_addr = new_data3_addr; |
NEW_SECTION_H(nn).sh_addr = new_data3_addr; |
703 |
NEW_SECTION_H(nn).sh_offset = new_data3_offset; |
NEW_SECTION_H(nn).sh_offset = new_data3_offset; |
704 |
NEW_SECTION_H(nn).sh_size = new_data3_size; |
NEW_SECTION_H(nn).sh_size = new_data3_size; |
709 |
NEW_SECTION_H(nn).sh_addralign = OLD_SECTION_H(n).sh_addralign; |
NEW_SECTION_H(nn).sh_addralign = OLD_SECTION_H(n).sh_addralign; |
710 |
|
|
711 |
/* Now copy over what we have in the memory now. */ |
/* Now copy over what we have in the memory now. */ |
712 |
memcpy (NEW_SECTION_H(nn).sh_offset + new_base, |
memcpy (NEW_SECTION_H(nn).sh_offset + new_base, |
713 |
(caddr_t) OLD_SECTION_H(n).sh_addr, |
(caddr_t) OLD_SECTION_H(n).sh_addr, |
714 |
new_data3_size); |
new_data3_size); |
715 |
/* the new .data2 section should also come before the |
/* the new .data2 section should also come before the |
716 |
* new .sbss section */ |
* new .sbss section */ |
721 |
/* We always have a .sdata section: append the contents of the |
/* We always have a .sdata section: append the contents of the |
722 |
* old .sbss section. |
* old .sbss section. |
723 |
*/ |
*/ |
724 |
memcpy (new_data3_offset + new_base, |
memcpy (new_data3_offset + new_base, |
725 |
(caddr_t) OLD_SECTION_H(n).sh_addr, |
(caddr_t) OLD_SECTION_H(n).sh_addr, |
726 |
new_data3_size); |
new_data3_size); |
727 |
nn ++; |
nn ++; |
728 |
} |
} |
729 |
} |
} |
730 |
else if (n == old_bss_index) |
else if (n == old_bss_index) |
731 |
|
|
732 |
/* If it is bss section, insert the new data2 section before it. */ |
/* If it is bss section, insert the new data2 section before it. */ |
733 |
{ |
{ |
734 |
Elf32_Word tmp_align; |
Elf32_Word tmp_align; |
741 |
/* Steal the data section header for this data2 section. */ |
/* Steal the data section header for this data2 section. */ |
742 |
memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(old_data_index), |
memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(old_data_index), |
743 |
new_file_h->e_shentsize); |
new_file_h->e_shentsize); |
744 |
|
|
745 |
NEW_SECTION_H(nn).sh_addr = new_data2_addr; |
NEW_SECTION_H(nn).sh_addr = new_data2_addr; |
746 |
NEW_SECTION_H(nn).sh_offset = new_data2_offset; |
NEW_SECTION_H(nn).sh_offset = new_data2_offset; |
747 |
NEW_SECTION_H(nn).sh_size = new_data2_size; |
NEW_SECTION_H(nn).sh_size = new_data2_size; |
751 |
NEW_SECTION_H(nn).sh_addralign = tmp_align; |
NEW_SECTION_H(nn).sh_addralign = tmp_align; |
752 |
|
|
753 |
/* Now copy over what we have in the memory now. */ |
/* Now copy over what we have in the memory now. */ |
754 |
memcpy (NEW_SECTION_H(nn).sh_offset + new_base, |
memcpy (NEW_SECTION_H(nn).sh_offset + new_base, |
755 |
(caddr_t) tmp_addr, new_data2_size); |
(caddr_t) tmp_addr, new_data2_size); |
756 |
nn += 2; |
nn += 2; |
757 |
} |
} |
758 |
|
|
759 |
memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(n), |
memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(n), |
760 |
old_file_h->e_shentsize); |
old_file_h->e_shentsize); |
761 |
|
|
762 |
if (old_sdata_index && n == old_sdata_index) |
if (old_sdata_index && n == old_sdata_index) |
763 |
/* The old .sdata section has now a new size */ |
/* The old .sdata section has now a new size */ |
764 |
NEW_SECTION_H(nn).sh_size = new_sdata_size; |
NEW_SECTION_H(nn).sh_size = new_sdata_size; |
773 |
NEW_SECTION_H(nn).sh_addr += new_data2_size + new_data2_align + |
NEW_SECTION_H(nn).sh_addr += new_data2_size + new_data2_align + |
774 |
new_data3_size; |
new_data3_size; |
775 |
/* Let the new bss section address alignment be the same as the |
/* Let the new bss section address alignment be the same as the |
776 |
section address alignment followed the old bss section, so |
section address alignment followed the old bss section, so |
777 |
this section will be placed in exactly the same place. */ |
this section will be placed in exactly the same place. */ |
778 |
NEW_SECTION_H(nn).sh_addralign = |
NEW_SECTION_H(nn).sh_addralign = |
779 |
OLD_SECTION_H(nn + (old_sdata_index ? 1 : 0)).sh_addralign; |
OLD_SECTION_H(nn + (old_sdata_index ? 1 : 0)).sh_addralign; |
786 |
new_data3_size - old_bss_padding; |
new_data3_size - old_bss_padding; |
787 |
NEW_SECTION_H(nn).sh_addr += new_data2_size; |
NEW_SECTION_H(nn).sh_addr += new_data2_size; |
788 |
/* Let the new bss section address alignment be the same as the |
/* Let the new bss section address alignment be the same as the |
789 |
section address alignment followed the old bss section, so |
section address alignment followed the old bss section, so |
790 |
this section will be placed in exactly the same place. */ |
this section will be placed in exactly the same place. */ |
791 |
NEW_SECTION_H(nn).sh_addralign = |
NEW_SECTION_H(nn).sh_addralign = |
792 |
OLD_SECTION_H((nn - (old_sdata_index ? 0 : 1))).sh_addralign; |
OLD_SECTION_H((nn - (old_sdata_index ? 0 : 1))).sh_addralign; |
799 |
new_data2_align + |
new_data2_align + |
800 |
new_data3_size - |
new_data3_size - |
801 |
old_bss_padding; |
old_bss_padding; |
802 |
|
|
803 |
/* If any section hdr refers to the section after the new .data |
/* If any section hdr refers to the section after the new .data |
804 |
section, make it refer to next one because we have inserted |
section, make it refer to next one because we have inserted |
805 |
a new section in between. */ |
a new section in between. */ |
806 |
|
|
807 |
PATCH_INDEX(NEW_SECTION_H(nn).sh_link); |
PATCH_INDEX(NEW_SECTION_H(nn).sh_link); |
808 |
PATCH_INDEX(NEW_SECTION_H(nn).sh_info); |
PATCH_INDEX(NEW_SECTION_H(nn).sh_info); |
809 |
|
|
810 |
/* Now, start to copy the content of sections. */ |
/* Now, start to copy the content of sections. */ |
811 |
if (NEW_SECTION_H(nn).sh_type == SHT_NULL |
if (NEW_SECTION_H(nn).sh_type == SHT_NULL |
812 |
|| NEW_SECTION_H(nn).sh_type == SHT_NOBITS) |
|| NEW_SECTION_H(nn).sh_type == SHT_NOBITS) |
813 |
continue; |
continue; |
814 |
|
|
815 |
/* Write out the sections. .data, .data1 and .sdata get copied from |
/* Write out the sections. .data, .data1 and .sdata get copied from |
816 |
* the current process instead of the old file. |
* the current process instead of the old file. |
817 |
*/ |
*/ |
821 |
src = (caddr_t) OLD_SECTION_H(n).sh_addr; |
src = (caddr_t) OLD_SECTION_H(n).sh_addr; |
822 |
else |
else |
823 |
src = old_base + OLD_SECTION_H(n).sh_offset; |
src = old_base + OLD_SECTION_H(n).sh_offset; |
824 |
|
|
825 |
memcpy (NEW_SECTION_H(nn).sh_offset + new_base, src, |
memcpy (NEW_SECTION_H(nn).sh_offset + new_base, src, |
826 |
((n == old_sdata_index) ? |
((n == old_sdata_index) ? |
827 |
old_sdata_size : |
old_sdata_size : |
833 |
{ |
{ |
834 |
Elf32_Shdr *spt = &NEW_SECTION_H(nn); |
Elf32_Shdr *spt = &NEW_SECTION_H(nn); |
835 |
unsigned int num = spt->sh_size / spt->sh_entsize; |
unsigned int num = spt->sh_size / spt->sh_entsize; |
836 |
Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H(nn).sh_offset + |
Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H(nn).sh_offset + |
837 |
new_base); |
new_base); |
838 |
for (; num--; sym++) |
for (; num--; sym++) |
839 |
{ |
{ |
841 |
|| (sym->st_shndx == SHN_ABS) |
|| (sym->st_shndx == SHN_ABS) |
842 |
|| (sym->st_shndx == SHN_COMMON)) |
|| (sym->st_shndx == SHN_COMMON)) |
843 |
continue; |
continue; |
844 |
|
|
845 |
PATCH_INDEX(sym->st_shndx); |
PATCH_INDEX(sym->st_shndx); |
846 |
} |
} |
847 |
} |
} |