annotate src/unexsni.c @ 83382:7a3090aca393

Fix hardcoded stdout usage in term.c. (Reported by Dan Nicolaescu.) * src/term.c (tty_set_terminal_modes): Output newlines on the correct terminal device. git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-422
author Karoly Lorentey <lorentey@elte.hu>
date Mon, 19 Sep 2005 21:25:51 +0000
parents a0d1312ede66
children 3bd95f4f2941 2d92f5c9d6ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Unexec for Siemens machines running Sinix (modified SVR4).
64770
a0d1312ede66 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1993, 1994, 1995, 2002,
a0d1312ede66 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64084
diff changeset
3 2003, 2004, 2005 Free Software Foundation, Inc.
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
5 This file is part of GNU Emacs.
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
6
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
7 GNU Emacs is free software; you can redistribute it and/or modify
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
8 it under the terms of the GNU General Public License as published by
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
9 the Free Software Foundation; either version 2, or (at your option)
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
10 any later version.
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
15 GNU General Public License for more details.
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
14186
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
17 You should have received a copy of the GNU General Public License
ee40177f6c68 Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents: 13944
diff changeset
18 along with GNU Emacs; see the file COPYING. If not, write to
64084
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
a8fa7c632ee4 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
20 Boston, MA 02110-1301, USA.
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 In other words, you are welcome to use, share and improve this program.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 You are forbidden to forbid anyone else to use, share and improve
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 what you give them. Help stamp out software-hoarding! */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 /*
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 * unexec.c - Convert a running program into an a.out file.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 * Author: Spencer W. Thomas
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 * Computer Science Dept.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 * University of Utah
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 * Date: Tue Mar 2 1982
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 * Modified heavily since then.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 * Synopsis:
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 * unexec (new_name, a_name, data_start, bss_start, entry_address)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 * char *new_name, *a_name;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 * unsigned data_start, bss_start, entry_address;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 * Takes a snapshot of the program and makes an a.out format file in the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 * file named by the string argument new_name.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 * If a_name is non-NULL, the symbol table will be taken from the given file.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 * On some machines, an existing a_name file is required.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 * The boundaries within the a.out file may be adjusted with the data_start
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 * and bss_start arguments. Either or both may be given as 0 for defaults.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 * Data_start gives the boundary between the text segment and the data
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 * segment of the program. The text segment can contain shared, read-only
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 * program code and literal data, while the data segment is always unshared
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 * and unprotected. Data_start gives the lowest unprotected address.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 * The value you specify may be rounded down to a suitable boundary
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 * as required by the machine you are using.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 * Specifying zero for data_start means the boundary between text and data
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 * should not be the same as when the program was loaded.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 * If NO_REMAP is defined, the argument data_start is ignored and the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 * segment boundaries are never changed.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 * Bss_start indicates how much of the data segment is to be saved in the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 * a.out file and restored when the program is executed. It gives the lowest
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 * unsaved address, and is rounded up to a page boundary. The default when 0
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 * is given assumes that the entire data segment is to be stored, including
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 * the previous data and bss as well as any additional storage allocated with
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 * break (2).
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 * The new file is set up to start at entry_address.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 * If you make improvements I'd like to get them too.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 * harpo!utah-cs!thomas, thomas@Utah-20
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 /* Even more heavily modified by james@bigtex.cactus.org of Dell Computer Co.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 * ELF support added.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 * Basic theory: the data space of the running process needs to be
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 * dumped to the output file. Normally we would just enlarge the size
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 * of .data, scooting everything down. But we can't do that in ELF,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 * because there is often something between the .data space and the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 * .bss space.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 * In the temacs dump below, notice that the Global Offset Table
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 * (.got) and the Dynamic link data (.dynamic) come between .data1 and
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 * .bss. It does not work to overlap .data with these fields.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 * The solution is to create a new .data segment. This segment is
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 * filled with data from the current process. Since the contents of
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 * various sections refer to sections by index, the new .data segment
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 * is made the last in the table to avoid changing any existing index.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
93 /* Modified by wtien@urbana.mcd.mot.com of Motorola Inc.
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
94 *
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 * The above mechanism does not work if the unexeced ELF file is being
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
96 * re-layout by other applications (such as `strip'). All the applications
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 * that re-layout the internal of ELF will layout all sections in ascending
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
98 * order of their file offsets. After the re-layout, the data2 section will
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
99 * still be the LAST section in the section header vector, but its file offset
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 * is now being pushed far away down, and causes part of it not to be mapped
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
101 * in (ie. not covered by the load segment entry in PHDR vector), therefore
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 * causes the new binary to fail.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 * The solution is to modify the unexec algorithm to insert the new data2
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 * section header right before the new bss section header, so their file
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
106 * offsets will be in the ascending order. Since some of the section's (all
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
107 * sections AFTER the bss section) indexes are now changed, we also need to
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
108 * modify some fields to make them point to the right sections. This is done
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 * by macro PATCH_INDEX. All the fields that need to be patched are:
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
110 *
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 * 1. ELF header e_shstrndx field.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 * 2. section header sh_link and sh_info field.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 * 3. symbol table entry st_shndx field.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 /*
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 * New modifications for Siemens Nixdorf's MIPS-based machines.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 * Marco.Walther@mch.sni.de
26473
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
119 * marco@inreach.com
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 * The problem: Before the bss segment we have a so called sbss segment
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 * (small bss) and maybe an sdata segment. These segments
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 * must also be handled correct.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 * /home1/marco/emacs/emacs-19.22/src
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 * dump -hv temacs
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
127 *
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 * temacs:
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 * **** SECTION HEADER TABLE ****
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 * [No] Type Flags Addr Offset Size Name
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 * Link Info Adralgn Entsize
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 * [1] PBIT -A-- 0x4000f4 0xf4 0x13 .interp
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
135 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 * [2] REGI -A-- 0x400108 0x108 0x18 .reginfo
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
138 * 0 0 0x4 0x18
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 * [3] DYNM -A-- 0x400120 0x120 0xb8 .dynamic
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
141 * 6 0 0x4 0x8
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 * [4] HASH -A-- 0x4001d8 0x1d8 0x8a0 .hash
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
144 * 5 0 0x4 0x4
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 * [5] DYNS -A-- 0x400a78 0xa78 0x11f0 .dynsym
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
147 * 6 2 0x4 0x10
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 * [6] STRT -A-- 0x401c68 0x1c68 0xbf9 .dynstr
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
150 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 * [7] REL -A-- 0x402864 0x2864 0x18 .rel.dyn
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
153 * 5 14 0x4 0x8
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 * [8] PBIT -AI- 0x402880 0x2880 0x60 .init
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
156 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 * [9] PBIT -AI- 0x4028e0 0x28e0 0x1234 .plt
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
159 * 0 0 0x4 0x4
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 * [10] PBIT -AI- 0x403b20 0x3b20 0xee400 .text
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
162 * 0 0 0x20 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 * [11] PBIT -AI- 0x4f1f20 0xf1f20 0x60 .fini
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
165 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 * [12] PBIT -A-- 0x4f1f80 0xf1f80 0xd90 .rdata
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
168 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 * [13] PBIT -A-- 0x4f2d10 0xf2d10 0x17e0 .rodata
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
171 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 * [14] PBIT WA-- 0x5344f0 0xf44f0 0x4b3e4 .data <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
174 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 * [15] PBIT WA-G 0x57f8d4 0x13f8d4 0x2a84 .got
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
177 * 0 0 0x4 0x4
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 * [16] PBIT WA-G 0x582360 0x142360 0x10 .sdata <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
180 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 * [17] NOBI WA-G 0x582370 0x142370 0xb84 .sbss <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
183 * 0 0 0x4 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 * [18] NOBI WA-- 0x582f00 0x142370 0x27ec0 .bss <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
186 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 * [19] SYMT ---- 0 0x142370 0x10e40 .symtab
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
189 * 20 1108 0x4 0x10
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 * [20] STRT ---- 0 0x1531b0 0xed9e .strtab
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
192 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 * [21] STRT ---- 0 0x161f4e 0xb5 .shstrtab
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
195 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 * [22] PBIT ---- 0 0x162003 0x28e2a .comment
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
198 * 0 0 0x1 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 * [23] PBIT ---- 0 0x18ae2d 0x592 .debug
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
201 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 * [24] PBIT ---- 0 0x18b3bf 0x80 .line
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
204 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 * [25] MDBG ---- 0 0x18b440 0x60 .mdebug
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
207 * 0 0 0x4 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 * dump -hv emacs
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
211 *
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 * emacs:
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 * **** SECTION HEADER TABLE ****
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 * [No] Type Flags Addr Offset Size Name
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 * Link Info Adralgn Entsize
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 * [1] PBIT -A-- 0x4000f4 0xf4 0x13 .interp
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
219 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 * [2] REGI -A-- 0x400108 0x108 0x18 .reginfo
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
222 * 0 0 0x4 0x18
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 * [3] DYNM -A-- 0x400120 0x120 0xb8 .dynamic
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
225 * 6 0 0x4 0x8
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 * [4] HASH -A-- 0x4001d8 0x1d8 0x8a0 .hash
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
228 * 5 0 0x4 0x4
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 * [5] DYNS -A-- 0x400a78 0xa78 0x11f0 .dynsym
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
231 * 6 2 0x4 0x10
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 * [6] STRT -A-- 0x401c68 0x1c68 0xbf9 .dynstr
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
234 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 * [7] REL -A-- 0x402864 0x2864 0x18 .rel.dyn
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
237 * 5 14 0x4 0x8
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 * [8] PBIT -AI- 0x402880 0x2880 0x60 .init
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
240 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 * [9] PBIT -AI- 0x4028e0 0x28e0 0x1234 .plt
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
243 * 0 0 0x4 0x4
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 * [10] PBIT -AI- 0x403b20 0x3b20 0xee400 .text
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
246 * 0 0 0x20 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 * [11] PBIT -AI- 0x4f1f20 0xf1f20 0x60 .fini
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
249 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 * [12] PBIT -A-- 0x4f1f80 0xf1f80 0xd90 .rdata
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
252 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 * [13] PBIT -A-- 0x4f2d10 0xf2d10 0x17e0 .rodata
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
255 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 * [14] PBIT WA-- 0x5344f0 0xf44f0 0x4b3e4 .data <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
258 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 * [15] PBIT WA-G 0x57f8d4 0x13f8d4 0x2a84 .got
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
261 * 0 0 0x4 0x4
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 * [16] PBIT WA-G 0x582360 0x142360 0xb94 .sdata <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
264 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 * [17] PBIT WA-- 0x582f00 0x142f00 0x94100 .data <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
267 * 0 0 0x10 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 * [18] NOBI WA-G 0x617000 0x1d7000 0 .sbss <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
270 * 0 0 0x4 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 * [19] NOBI WA-- 0x617000 0x1d7000 0 .bss <<<<<
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
273 * 0 0 0x4 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 * [20] SYMT ---- 0 0x1d7000 0x10e40 .symtab
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
276 * 21 1109 0x4 0x10
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 * [21] STRT ---- 0 0x1e7e40 0xed9e .strtab
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
279 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 * [22] STRT ---- 0 0x1f6bde 0xb5 .shstrtab
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
282 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 * [23] PBIT ---- 0 0x1f6c93 0x28e2a .comment
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
285 * 0 0 0x1 0x1
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 * [24] PBIT ---- 0 0x21fabd 0x592 .debug
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
288 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 * [25] PBIT ---- 0 0x22004f 0x80 .line
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
291 * 0 0 0x1 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 * [26] MDBG ---- 0 0x2200d0 0x60 .mdebug
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
294 * 0 0 0x4 0
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 #include <sys/types.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 #include <stdio.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 #include <sys/stat.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 #include <memory.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 #include <string.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 #include <errno.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 #include <unistd.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 #include <fcntl.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 #include <elf.h>
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 #include <sys/mman.h>
26473
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
308 #include <assert.h>
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
309
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
310 /* #define DEBUG */
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 #ifndef emacs
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 #define fatal(a, b, c) fprintf(stderr, a, b, c), exit(1)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 #else
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 extern void fatal(char *, ...);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 /* Get the address of a particular section or program header entry,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 * accounting for the size of the entries.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 #define OLD_SECTION_H(n) \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (*(Elf32_Shdr *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 #define NEW_SECTION_H(n) \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (*(Elf32_Shdr *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 #define OLD_PROGRAM_H(n) \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (*(Elf32_Phdr *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 #define NEW_PROGRAM_H(n) \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (*(Elf32_Phdr *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 #define PATCH_INDEX(n) \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 do { \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 if ((n) >= old_sbss_index) \
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (n) += 1 + (old_sdata_index ? 0 : 1); } while (0)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 typedef unsigned char byte;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 /* Round X up to a multiple of Y. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 int
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 round_up (x, y)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 int x, y;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 int rem = x % y;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 if (rem == 0)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 return x;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 return x - rem + y;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 /* ****************************************************************
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 * unexec
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 * driving logic.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 * In ELF, this works by replacing the old .bss section with a new
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 * .data section, and inserting an empty .bss immediately afterwards.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 *
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 void
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 unexec (new_name, old_name, data_start, bss_start, entry_address)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 char *new_name, *old_name;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 unsigned data_start, bss_start, entry_address;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 extern unsigned int bss_end;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 int new_file, old_file, new_file_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 /* Pointers to the base of the image of the two files. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 caddr_t old_base, new_base;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 /* Pointers to the file, program and section headers for the old and new
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 * files.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 Elf32_Ehdr *old_file_h, *new_file_h;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 Elf32_Phdr *old_program_h, *new_program_h;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 Elf32_Shdr *old_section_h, *new_section_h;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 /* Point to the section name table in the old file */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 char *old_section_names;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 Elf32_Addr old_bss_addr, new_bss_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 Elf32_Addr old_sbss_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 Elf32_Word old_bss_size, new_data2_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 Elf32_Word old_sbss_size, new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 Elf32_Off new_data2_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 Elf32_Off new_data3_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 Elf32_Addr new_data2_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 Elf32_Addr new_data3_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388
26473
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
389
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
390 Elf32_Addr old_rel_dyn_addr;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
391 Elf32_Word old_rel_dyn_size;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
392 int old_rel_dyn_index;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
393
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 Elf32_Word old_sdata_size, new_sdata_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 int old_sdata_index = 0;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 int n, nn, old_data_index, new_data2_align;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 int old_bss_index;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 int old_sbss_index;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 int old_bss_padding;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 struct stat stat_buf;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 /* Open the old file & map it into the address space. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 old_file = open (old_name, O_RDONLY);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 if (old_file < 0)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 fatal ("Can't open %s for reading: errno %d\n", old_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 if (fstat (old_file, &stat_buf) == -1)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 fatal ("Can't fstat(%s): errno %d\n", old_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 old_base = mmap (0, stat_buf.st_size, PROT_READ, MAP_SHARED, old_file, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 if (old_base == (caddr_t) -1)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 fatal ("Can't mmap(%s): errno %d\n", old_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 #ifdef DEBUG
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 fprintf (stderr, "mmap(%s, %x) -> %x\n", old_name, stat_buf.st_size,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 old_base);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 /* Get pointers to headers & section names */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 old_file_h = (Elf32_Ehdr *) old_base;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 old_program_h = (Elf32_Phdr *) ((byte *) old_base + old_file_h->e_phoff);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 old_section_h = (Elf32_Shdr *) ((byte *) old_base + old_file_h->e_shoff);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 old_section_names = (char *) old_base
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 + OLD_SECTION_H(old_file_h->e_shstrndx).sh_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 /* Find the old .sbss section.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 for (old_sbss_index = 1; old_sbss_index < old_file_h->e_shnum;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 old_sbss_index++)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 #ifdef DEBUG
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 fprintf (stderr, "Looking for .sbss - found %s\n",
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 old_section_names + OLD_SECTION_H(old_sbss_index).sh_name);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 if (!strcmp (old_section_names + OLD_SECTION_H(old_sbss_index).sh_name,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 ".sbss"))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 break;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 if (old_sbss_index == old_file_h->e_shnum)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 fatal ("Can't find .sbss in %s.\n", old_name, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 if (!strcmp(old_section_names + OLD_SECTION_H(old_sbss_index - 1).sh_name,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ".sdata"))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 old_sdata_index = old_sbss_index - 1;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
453
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 /* Find the old .bss section.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 for (old_bss_index = 1; old_bss_index < old_file_h->e_shnum; old_bss_index++)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 #ifdef DEBUG
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 fprintf (stderr, "Looking for .bss - found %s\n",
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 old_section_names + OLD_SECTION_H(old_bss_index).sh_name);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 if (!strcmp (old_section_names + OLD_SECTION_H(old_bss_index).sh_name,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 ".bss"))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 break;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 if (old_bss_index == old_file_h->e_shnum)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 fatal ("Can't find .bss in %s.\n", old_name, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 if (old_sbss_index != (old_bss_index - 1))
13944
cb66e1ad369d (unexec): Message fix.
Karl Heuer <kwzh@gnu.org>
parents: 11235
diff changeset
472 fatal (".sbss should come immediately before .bss in %s.\n", old_name, 0);
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473
26473
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
474 /* Find the old .rel.dyn section.
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
475 */
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
476
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
477 for (old_rel_dyn_index = 1; old_rel_dyn_index < old_file_h->e_shnum;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
478 old_rel_dyn_index++)
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
479 {
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
480 #ifdef DEBUG
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
481 fprintf (stderr, "Looking for .rel.dyn - found %s\n",
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
482 old_section_names + OLD_SECTION_H(old_rel_dyn_index).sh_name);
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
483 #endif
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
484 if (!strcmp (old_section_names + OLD_SECTION_H(old_rel_dyn_index).sh_name,
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
485 ".rel.dyn"))
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
486 break;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
487 }
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
488 if (old_rel_dyn_index == old_file_h->e_shnum)
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
489 fatal ("Can't find .rel_dyn in %s.\n", old_name, 0);
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
490
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
491 old_rel_dyn_addr = OLD_SECTION_H(old_rel_dyn_index).sh_addr;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
492 old_rel_dyn_size = OLD_SECTION_H(old_rel_dyn_index).sh_size;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
493
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 /* Figure out parameters of the new data3 and data2 sections.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 * Change the sbss and bss sections.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 old_bss_size = OLD_SECTION_H(old_bss_index).sh_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 old_sbss_addr = OLD_SECTION_H(old_sbss_index).sh_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 old_sbss_size = OLD_SECTION_H(old_sbss_index).sh_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 if (old_sdata_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 old_sdata_size = OLD_SECTION_H(old_sdata_index).sh_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 #if defined(emacs) || !defined(DEBUG)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 bss_end = (unsigned int) sbrk (0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 new_bss_addr = (Elf32_Addr) bss_end;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 #else
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 new_bss_addr = old_bss_addr + old_bss_size + 0x1234;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 if (old_sdata_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 new_sdata_size = OLD_SECTION_H(old_sbss_index).sh_offset -
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 OLD_SECTION_H(old_sdata_index).sh_offset + old_sbss_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 new_data3_addr = old_sbss_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 new_data3_size = old_sbss_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 new_data3_offset = OLD_SECTION_H(old_sbss_index).sh_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 new_data2_addr = old_bss_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 new_data2_size = new_bss_addr - old_bss_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 new_data2_align = (new_data3_offset + old_sbss_size) %
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 OLD_SECTION_H(old_bss_index).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 new_data2_align = new_data2_align ?
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 OLD_SECTION_H(old_bss_index).sh_addralign - new_data2_align :
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 0;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 new_data2_offset = new_data3_offset + old_sbss_size + new_data2_align;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 old_bss_padding = OLD_SECTION_H(old_bss_index).sh_offset -
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 OLD_SECTION_H(old_sbss_index).sh_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 #ifdef DEBUG
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 fprintf (stderr, "old_bss_index %d\n", old_bss_index);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 fprintf (stderr, "old_bss_size %x\n", old_bss_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 fprintf (stderr, "new_bss_addr %x\n", new_bss_addr);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 fprintf (stderr, "new_data2_addr %x\n", new_data2_addr);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 fprintf (stderr, "new_data2_size %x\n", new_data2_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 fprintf (stderr, "new_data2_offset %x\n", new_data2_offset);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 fprintf (stderr, "old_sbss_index %d\n", old_sbss_index);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 fprintf (stderr, "old_sbss_addr %x\n", old_sbss_addr);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 fprintf (stderr, "old_sbss_size %x\n", old_sbss_size);
26473
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
547 fprintf (stderr, "old_rel_dyn_addr %x\n", old_rel_dyn_addr);
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
548 fprintf (stderr, "old_rel_dyn_size %x\n", old_rel_dyn_size);
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 if (old_sdata_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 fprintf (stderr, "old_sdata_size %x\n", old_sdata_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 fprintf (stderr, "new_sdata_size %x\n", new_sdata_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 else
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 fprintf (stderr, "new_data3_addr %x\n", new_data3_addr);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 fprintf (stderr, "new_data3_size %x\n", new_data3_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 fprintf (stderr, "new_data3_offset %x\n", new_data3_offset);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 fatal (".bss shrank when undumping???\n", 0, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 /* Set the output file to the right size and mmap(2) it. Set
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 * pointers to various interesting objects. stat_buf still has
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 * old_file data.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 new_file = open (new_name, O_RDWR | O_CREAT, 0666);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 if (new_file < 0)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 fatal ("Can't creat(%s): errno %d\n", new_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 new_file_size = stat_buf.st_size +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 ((1 + (old_sdata_index ? 0 : 1)) * old_file_h->e_shentsize) +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 new_data2_size + new_data3_size + new_data2_align;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 if (ftruncate (new_file, new_file_size))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 fatal ("Can't ftruncate(%s): errno %d\n", new_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 new_base = mmap (0, new_file_size, PROT_READ | PROT_WRITE, MAP_SHARED,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 new_file, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 if (new_base == (caddr_t) -1)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 fatal ("Can't mmap(%s): errno %d\n", new_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 new_file_h = (Elf32_Ehdr *) new_base;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 new_program_h = (Elf32_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 new_section_h = (Elf32_Shdr *) ((byte *) new_base +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 old_file_h->e_shoff +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 new_data2_size +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 new_data3_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 /* Make our new file, program and section headers as copies of the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 * originals.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 memcpy (new_file_h, old_file_h, old_file_h->e_ehsize);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 memcpy (new_program_h, old_program_h,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 old_file_h->e_phnum * old_file_h->e_phentsize);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 /* Modify the e_shstrndx if necessary. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 PATCH_INDEX (new_file_h->e_shstrndx);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 /* Fix up file header. We'll add one section. Section header is
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 * further away now.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 new_file_h->e_shoff += new_data2_size + new_data2_align + new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611 new_file_h->e_shnum += 1 + (old_sdata_index ? 0 : 1);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 #ifdef DEBUG
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
614 fprintf (stderr, "Old section offset %x\n", old_file_h->e_shoff);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
615 fprintf (stderr, "Old section count %d\n", old_file_h->e_shnum);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
616 fprintf (stderr, "New section offset %x\n", new_file_h->e_shoff);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 fprintf (stderr, "New section count %d\n", new_file_h->e_shnum);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620 /* Fix up a new program header. Extend the writable data segment so
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 * that the bss area is covered too. Find that segment by looking
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 * for a segment that ends just before the .bss area. Make sure
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 * that no segments are above the new .data2. Put a loop at the end
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 * to adjust the offset and address of any segment that is above
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 * data2, just in case we decide to allow this later.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 for (n = new_file_h->e_phnum - 1; n >= 0; n--)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 /* Compute maximum of all requirements for alignment of section. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 int alignment = (NEW_PROGRAM_H (n)).p_align;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 alignment = OLD_SECTION_H (old_bss_index).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635 if ((OLD_SECTION_H (old_sbss_index)).sh_addralign > alignment)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 alignment = OLD_SECTION_H (old_sbss_index).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 /* Supposedly this condition is okay for the SGI. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 #if 0
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 if (NEW_PROGRAM_H(n).p_vaddr + NEW_PROGRAM_H(n).p_filesz > old_bss_addr)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 fatal ("Program segment above .bss in %s\n", old_name, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 if (NEW_PROGRAM_H(n).p_type == PT_LOAD
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 + (NEW_PROGRAM_H (n)).p_filesz,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 alignment)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 == round_up (old_bss_addr, alignment)))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 break;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 if (n < 0)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 NEW_PROGRAM_H(n).p_filesz += new_data2_size + new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 NEW_PROGRAM_H(n).p_memsz = NEW_PROGRAM_H(n).p_filesz;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 #if 1 /* Maybe allow section after data2 - does this ever happen? */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 for (n = new_file_h->e_phnum - 1; n >= 0; n--)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 if (NEW_PROGRAM_H(n).p_vaddr
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 && NEW_PROGRAM_H(n).p_vaddr >= new_data3_addr)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 NEW_PROGRAM_H(n).p_vaddr += new_data2_size - old_bss_size +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 new_data3_size - old_sbss_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 if (NEW_PROGRAM_H(n).p_offset >= new_data3_offset)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 NEW_PROGRAM_H(n).p_offset += new_data2_size + new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 #endif
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 /* Fix up section headers based on new .data2 section. Any section
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 * whose offset or virtual address is after the new .data2 section
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 * gets its value adjusted. .bss size becomes zero and new address
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 * is set. data2 section header gets added by copying the existing
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 * .data header and modifying the offset, address and size.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 for (old_data_index = 1; old_data_index < old_file_h->e_shnum;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 old_data_index++)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 if (!strcmp (old_section_names + OLD_SECTION_H(old_data_index).sh_name,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 ".data"))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 break;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 if (old_data_index == old_file_h->e_shnum)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 fatal ("Can't find .data in %s.\n", old_name, 0);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
686 /* Walk through all section headers, insert the new data2 section right
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 before the new bss section. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 caddr_t src;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 if (n == old_sbss_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 /* If it is sbss section, insert the new data3 section before it. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 /* Steal the data section header for this data3 section. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 if (!old_sdata_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(old_data_index),
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 new_file_h->e_shentsize);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
701
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 NEW_SECTION_H(nn).sh_addr = new_data3_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 NEW_SECTION_H(nn).sh_offset = new_data3_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 NEW_SECTION_H(nn).sh_size = new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 NEW_SECTION_H(nn).sh_flags = OLD_SECTION_H(n).sh_flags;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 /* Use the sbss section's alignment. This will assure that the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 new data3 section always be placed in the same spot as the old
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 sbss section by any other application. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 NEW_SECTION_H(nn).sh_addralign = OLD_SECTION_H(n).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 /* Now copy over what we have in the memory now. */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
712 memcpy (NEW_SECTION_H(nn).sh_offset + new_base,
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
713 (caddr_t) OLD_SECTION_H(n).sh_addr,
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 new_data3_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 /* the new .data2 section should also come before the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 * new .sbss section */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 nn += 2;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 else
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 /* We always have a .sdata section: append the contents of the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 * old .sbss section.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
724 memcpy (new_data3_offset + new_base,
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
725 (caddr_t) OLD_SECTION_H(n).sh_addr,
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 new_data3_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 nn ++;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 else if (n == old_bss_index)
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
731
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 /* If it is bss section, insert the new data2 section before it. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 Elf32_Word tmp_align;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 Elf32_Addr tmp_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 tmp_align = OLD_SECTION_H(n).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 tmp_addr = OLD_SECTION_H(n).sh_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740 nn -= 2;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 /* Steal the data section header for this data2 section. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(old_data_index),
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 new_file_h->e_shentsize);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
744
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 NEW_SECTION_H(nn).sh_addr = new_data2_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 NEW_SECTION_H(nn).sh_offset = new_data2_offset;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 NEW_SECTION_H(nn).sh_size = new_data2_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 /* Use the bss section's alignment. This will assure that the
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 new data2 section always be placed in the same spot as the old
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 bss section by any other application. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 NEW_SECTION_H(nn).sh_addralign = tmp_align;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 /* Now copy over what we have in the memory now. */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
754 memcpy (NEW_SECTION_H(nn).sh_offset + new_base,
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (caddr_t) tmp_addr, new_data2_size);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 nn += 2;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
758
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
759 memcpy (&NEW_SECTION_H(nn), &OLD_SECTION_H(n),
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 old_file_h->e_shentsize);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
761
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 if (old_sdata_index && n == old_sdata_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 /* The old .sdata section has now a new size */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 NEW_SECTION_H(nn).sh_size = new_sdata_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
765
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 /* The new bss section's size is zero, and its file offset and virtual
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 address should be off by NEW_DATA2_SIZE. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 if (n == old_sbss_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
770 /* NN should be `old_sbss_index + 2' at this point. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 NEW_SECTION_H(nn).sh_offset += new_data2_size + new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 NEW_SECTION_H(nn).sh_addr += new_data2_size + new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 new_data3_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 /* Let the new bss section address alignment be the same as the
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
776 section address alignment followed the old bss section, so
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 this section will be placed in exactly the same place. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
778 NEW_SECTION_H(nn).sh_addralign =
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 OLD_SECTION_H(nn + (old_sdata_index ? 1 : 0)).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780 NEW_SECTION_H(nn).sh_size = 0;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
781 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
782 else if (n == old_bss_index)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 /* NN should be `old_bss_index + 2' at this point. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 NEW_SECTION_H(nn).sh_offset += new_data2_size + new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 new_data3_size - old_bss_padding;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 NEW_SECTION_H(nn).sh_addr += new_data2_size;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 /* Let the new bss section address alignment be the same as the
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
789 section address alignment followed the old bss section, so
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 this section will be placed in exactly the same place. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 NEW_SECTION_H(nn).sh_addralign =
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 OLD_SECTION_H((nn - (old_sdata_index ? 0 : 1))).sh_addralign;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
793 NEW_SECTION_H(nn).sh_size = 0;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 /* Any section that was original placed AFTER the bss section should now
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 be off by NEW_DATA2_SIZE. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 else if (NEW_SECTION_H(nn).sh_offset >= new_data3_offset)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798 NEW_SECTION_H(nn).sh_offset += new_data2_size +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 new_data2_align +
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 new_data3_size -
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 old_bss_padding;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
802
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 /* If any section hdr refers to the section after the new .data
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
804 section, make it refer to next one because we have inserted
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 a new section in between. */
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
806
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
807 PATCH_INDEX(NEW_SECTION_H(nn).sh_link);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 PATCH_INDEX(NEW_SECTION_H(nn).sh_info);
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
809
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
810 /* Now, start to copy the content of sections. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 if (NEW_SECTION_H(nn).sh_type == SHT_NULL
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 || NEW_SECTION_H(nn).sh_type == SHT_NOBITS)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 continue;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
814
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 /* Write out the sections. .data, .data1 and .sdata get copied from
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 * the current process instead of the old file.
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
817 */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
818 if (!strcmp (old_section_names + OLD_SECTION_H(n).sh_name, ".data") ||
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
819 !strcmp (old_section_names + OLD_SECTION_H(n).sh_name, ".data1") ||
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
820 (old_sdata_index && (n == old_sdata_index)))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
821 src = (caddr_t) OLD_SECTION_H(n).sh_addr;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
822 else
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 src = old_base + OLD_SECTION_H(n).sh_offset;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
824
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
825 memcpy (NEW_SECTION_H(nn).sh_offset + new_base, src,
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
826 ((n == old_sdata_index) ?
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
827 old_sdata_size :
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
828 NEW_SECTION_H(nn).sh_size));
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
829
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
830 /* If it is the symbol table, its st_shndx field needs to be patched. */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 if (NEW_SECTION_H(nn).sh_type == SHT_SYMTAB
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 || NEW_SECTION_H(nn).sh_type == SHT_DYNSYM)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 Elf32_Shdr *spt = &NEW_SECTION_H(nn);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
835 unsigned int num = spt->sh_size / spt->sh_entsize;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
836 Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H(nn).sh_offset +
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 new_base);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 for (; num--; sym++)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 {
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 if ((sym->st_shndx == SHN_UNDEF)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
841 || (sym->st_shndx == SHN_ABS)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 || (sym->st_shndx == SHN_COMMON))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 continue;
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 26473
diff changeset
844
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
845 PATCH_INDEX(sym->st_shndx);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
846 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
847 }
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848 }
26473
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
849 {
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
850 Elf32_Rel *rel_p;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
851 unsigned int old_data_addr_start;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
852 unsigned int old_data_addr_end;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
853 unsigned int old_data_offset;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
854 unsigned int new_data_offset;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
855 int i;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
856
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
857 rel_p = (Elf32_Rel *)OLD_SECTION_H(old_rel_dyn_index).sh_addr;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
858 old_data_addr_start = OLD_SECTION_H(old_data_index).sh_addr;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
859 old_data_addr_end = old_data_addr_start +
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
860 OLD_SECTION_H(old_data_index).sh_size;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
861 old_data_offset = (int)OLD_SECTION_H(old_data_index).sh_offset +
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
862 (unsigned int)old_base;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
863 new_data_offset = (int)NEW_SECTION_H(old_data_index).sh_offset +
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
864 (unsigned int)new_base;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
865
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
866 #ifdef DEBUG
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
867 fprintf(stderr, "old_data.sh_addr= 0x%08x ... 0x%08x\n", old_data_addr_start,
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
868 old_data_addr_end);
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
869 #endif /* DEBUG */
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
870
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
871 for (i = 0; i < old_rel_dyn_size/sizeof(Elf32_Rel); i++)
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
872 {
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
873 #ifdef DEBUG
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
874 fprintf(stderr, ".rel.dyn offset= 0x%08x type= %d sym= %d\n",
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
875 rel_p->r_offset, ELF32_R_TYPE(rel_p->r_info), ELF32_R_SYM(rel_p->r_info));
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
876 #endif /* DEBUG */
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
877
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
878 if (rel_p->r_offset)
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
879 {
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
880 unsigned int offset;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
881
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
882 assert(old_data_addr_start <= rel_p->r_offset &&
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
883 rel_p->r_offset <= old_data_addr_end);
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
884
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
885 offset = rel_p->r_offset - old_data_addr_start;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
886
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
887 #ifdef DEBUG
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
888 fprintf(stderr, "r_offset= 0x%08x *r_offset= 0x%08x\n",
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
889 rel_p->r_offset, *((int *)(rel_p->r_offset)));
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
890 fprintf(stderr, "old = 0x%08x *old =0x%08x\n",
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
891 (old_data_offset + offset - (unsigned int)old_base),
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
892 *((int *)(old_data_offset + offset)));
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
893 fprintf(stderr, "new = 0x%08x *new =0x%08x\n",
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
894 (new_data_offset + offset - (unsigned int)new_base),
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
895 *((int *)(new_data_offset + offset)));
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
896 #endif /* DEBUG */
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
897
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
898 *((int *)(new_data_offset + offset)) = *((int *)(old_data_offset + offset));
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
899 }
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
900
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
901 rel_p++;
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
902 }
762c51f4a100 (unexec): Handle .rel.dyn section.
Gerd Moellmann <gerd@gnu.org>
parents: 14186
diff changeset
903 }
11074
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 /* Close the files and make the new file executable */
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 if (close (old_file))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 fatal ("Can't close(%s): errno %d\n", old_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 if (close (new_file))
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 fatal ("Can't close(%s): errno %d\n", new_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 if (stat (new_name, &stat_buf) == -1)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 fatal ("Can't stat(%s): errno %d\n", new_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 n = umask (777);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 umask (n);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 stat_buf.st_mode |= 0111 & ~n;
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 if (chmod (new_name, stat_buf.st_mode) == -1)
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 fatal ("Can't chmod(%s): errno %d\n", new_name, errno);
259db0e1a815 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
922
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
923 /* arch-tag: c784ead3-7a27-442b-83fe-7af8d08654d3
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
924 (do not change this comment) */