annotate src/unexcw.c @ 531:0493e9f3c27f

[xemacs-hg @ 2001-05-12 11:16:12 by ben] event-msw.c: eliminate cygwin warnings. dired.c, syswindows.h, win32.c: find the Net* functions the hard way to avoid errors on win 9x. find-paths.el: fix error with null EXCLUDE-REGEXP. font-lock.el: fix problem reported by hrvoje with buffers starting with a space. lib-complete.el: add a variable to control where `find-library' looks, analogous to `find-function-source-path'. etags.c: new version from Francesco. Makefile.in.in: i'm getting real tired of incomplete commits. is this getting worse or something?
author ben
date Sat, 12 May 2001 11:16:25 +0000
parents 0784d089fdc9
children 666d73d6ac56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* unexec for GNU Emacs on Cygwin32.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1994, 1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* This is a complete rewrite, some code snarfed from unexnt.c and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
26 #include <config.h>
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
27 #include "lisp.h"
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
28
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include <stdio.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include <stdlib.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include <fcntl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 #include <string.h>
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
34
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
35 #define DONT_ENCAPSULATE /* filenames are external in unex*.c */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "sysfile.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
37
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #define PERROR(arg) perror(arg);exit(-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #ifndef HAVE_A_OUT_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 unexec (char *, char *, void *, void *, void *)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 PERROR("cannot unexec() a.out.h not installed");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
47 #ifndef MAX_PATH
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
48 #define MAX_PATH 260
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
49 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include <a.out.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #define ALLOC_UNIT 0xFFFF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #define ALLOC_MASK ~((unsigned long)(ALLOC_UNIT))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #define ALIGN_ALLOC(addr) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
56 /* Note that all sections must be aligned on a 0x1000 boundary so
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
57 this is the minimum size that our dummy bss can be. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
58 #ifndef NO_DEBUG
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
59 #define BSS_PAD_SIZE 0x1000
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
60 #else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
61 #define BSS_PAD_SIZE 0
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
62 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 /* To prevent zero-initialized variables from being placed into the bss
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 section, use non-zero values to represent an uninitialized state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #define UNINIT_PTR ((void *) 0xF0A0F0A0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 #define UNINIT_LONG (0xF0A0F0A0L)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 static void get_section_info (int a_out, char* a_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 static void copy_executable_and_dump_data_section (int a_out, int a_new);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 static void dup_file_area(int a_out, int a_new, long size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 static void write_int_to_bss(int a_out, int a_new, void* va, void* newval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 /* Cached info about the .data section in the executable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 void* data_start_va = UNINIT_PTR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 unsigned long data_size = UNINIT_LONG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 /* Cached info about the .bss section in the executable. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 void* bss_start = UNINIT_PTR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 unsigned long bss_size = UNINIT_LONG;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 int sections_reversed = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 FILHDR f_hdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 PEAOUTHDR f_ohdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 SCNHDR f_data, f_bss, f_text, f_nextdata;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #define PERROR(arg) perror(arg);exit(-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #define CHECK_AOUT_POS(a) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 if (lseek(a_out, 0, SEEK_CUR) != a) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 printf("we are at %lx, should be at %lx\n", \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 lseek(a_out, 0, SEEK_CUR), a); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 exit(-1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 /* Dump out .data and .bss sections into a new executable. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
98 int
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
99 unexec (char *out_name, char *in_name, uintptr_t start_data,
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
100 uintptr_t d1, uintptr_t d2)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* ugly nt hack - should be in lisp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 int a_new, a_out = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 char new_name[MAX_PATH], a_name[MAX_PATH];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 char *ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 /* Make sure that the input and output filenames have the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 ".exe" extension...patch them up if they don't. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 strcpy (a_name, in_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 ptr = a_name + strlen (a_name) - 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 if (strcmp (ptr, ".exe"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 strcat (a_name, ".exe");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 strcpy (new_name, out_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 ptr = new_name + strlen (new_name) - 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 if (strcmp (ptr, ".exe"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 strcat (new_name, ".exe");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 /* We need to round off our heap to NT's allocation unit (64KB). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 /* round_heap (get_allocation_unit ()); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 if (a_name && (a_out = open (a_name, O_RDONLY | OPEN_BINARY)) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 PERROR (a_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
128 0755)) < 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 PERROR (new_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 /* Get the interesting section info, like start and size of .bss... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 get_section_info (a_out, a_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 copy_executable_and_dump_data_section (a_out, a_new);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 close(a_out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 close(a_new);
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
140 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 /* Flip through the executable and cache the info necessary for dumping. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 static void get_section_info (int a_out, char* a_name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
146 extern char my_ebss[];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 /* From lastfile.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 extern char my_edata[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 PERROR (a_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 if (f_hdr.e_magic != DOSMAGIC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 PERROR("unknown exe header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 /* Check the NT header signature ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 if (f_hdr.nt_signature != NT_SIGNATURE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 PERROR("invalid nt header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 /* Flip through the sections for .data and .bss ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 if (f_hdr.f_opthdr > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 if (read (a_out, &f_ohdr, AOUTSZ) != AOUTSZ)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 PERROR (a_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 /* Loop through .data & .bss section headers, copying them in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 With newer lds these are reversed so we have to cope with both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 lseek (a_out, sizeof (f_hdr) + f_hdr.f_opthdr, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 if (read (a_out, &f_text, sizeof (f_text)) != sizeof (f_text)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 strcmp (f_text.s_name, ".text"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 PERROR ("no .text section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 /* The .bss section. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 if (read (a_out, &f_bss, sizeof (f_bss)) != sizeof (f_bss)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (strcmp (f_bss.s_name, ".bss") && strcmp (f_bss.s_name, ".data")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 PERROR ("no .bss / .data section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* check for reversed .bss and .data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 if (!strcmp(f_bss.s_name, ".data"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 printf(".data and .bss reversed\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 sections_reversed = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 memcpy(&f_data, &f_bss, sizeof(f_bss));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 /* The .data section. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 if (!sections_reversed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 if (read (a_out, &f_data, sizeof (f_data)) != sizeof (f_data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 strcmp (f_data.s_name, ".data"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 PERROR ("no .data section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 if (read (a_out, &f_bss, sizeof (f_bss)) != sizeof (f_bss)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 strcmp (f_bss.s_name, ".bss"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 PERROR ("no .bss section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 bss_start = (void *) ((char*)f_ohdr.ImageBase + f_bss.s_vaddr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 bss_size = (unsigned long)((char*)&my_ebss-(char*)bss_start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 /* must keep bss data that we want to be blank as blank */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 printf("found bss - keeping %lx of %lx bytes\n", bss_size, f_ohdr.bsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* The .data section. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 data_start_va = (void *) ((char*)f_ohdr.ImageBase + f_data.s_vaddr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 /* We want to only write Emacs data back to the executable,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 not any of the library data (if library data is included,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 then a dumped Emacs won't run on system versions other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 than the one Emacs was dumped on). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 data_size = (unsigned long)my_edata - (unsigned long)data_start_va;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 printf("found data - keeping %lx of %lx bytes\n", data_size, f_ohdr.dsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 /* The following data section - often .idata */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 if (read (a_out, &f_nextdata, sizeof (f_nextdata)) != sizeof (f_nextdata)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 strcmp (&f_nextdata.s_name[2], "data"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 PERROR ("no other data section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 /* The dump routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 copy_executable_and_dump_data_section (int a_out, int a_new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 long size=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 unsigned long new_data_size, new_bss_size,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 bss_padding, file_sz_change, data_padding=0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 f_data_s_vaddr = f_data.s_vaddr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 f_data_s_scnptr = f_data.s_scnptr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 f_bss_s_vaddr = f_bss.s_vaddr,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 f_nextdata_s_scnptr = f_nextdata.s_scnptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 void* empty_space;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 extern int static_heap_dumped;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 SCNHDR section;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
263 /* calculate new sizes:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
264
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
265 f_ohdr.dsize is the total initialized data size on disk which is
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
266 f_data.s_size + f_idata.s_size.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
267
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
268 f_ohdr.data_start is the base addres of all data and so should
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
269 not be changed.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
270
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
271 *.s_vaddr is the virtual address of the start of the section
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
272 *normalized from f_ohdr.ImageBase.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
273
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
274 *.s_paddr appears to be the number of bytes in the section
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
275 *actually used (whereas *.s_size is aligned).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 bsize is now 0 since subsumed into .data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 dsize is dsize + (f_data.s_vaddr - f_bss.s_vaddr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 f_data.s_vaddr is f_bss.s_vaddr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 f_data.s_size is new dsize maybe.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 what about s_paddr & s_scnptr? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 /* this is the amount the file increases in size */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 if (!sections_reversed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 new_bss_size = f_data.s_vaddr - f_bss.s_vaddr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 data_padding = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 new_bss_size = f_nextdata.s_vaddr - f_bss.s_vaddr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
295 if ((new_bss_size - bss_size) < BSS_PAD_SIZE)
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
296 {
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
297 PERROR (".bss free space too small");
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
298 }
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
299
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
300 file_sz_change=(new_bss_size + data_padding) - BSS_PAD_SIZE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 new_data_size=f_ohdr.dsize + file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 if (!sections_reversed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 f_data.s_vaddr = f_bss.s_vaddr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 f_data.s_paddr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 if (f_data.s_size + f_nextdata.s_size != f_ohdr.dsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 printf("section size doesn't tally with dsize %lx != %lx\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 f_data.s_size + f_nextdata.s_size, f_ohdr.dsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 f_data.s_size += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 lseek (a_new, 0, SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 /* write file header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 f_hdr.f_symptr += file_sz_change;
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
319 #ifdef NO_DEBUG
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
320 f_hdr.f_nscns--;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
321 #endif
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
322
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 printf("writing file header\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 PERROR("failed to write file header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 /* write optional header fixing dsize & bsize*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 printf("writing optional header\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 printf("new data size is %lx, >= %lx\n", new_data_size,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 f_ohdr.dsize + f_ohdr.bsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 if (new_data_size < f_ohdr.dsize + f_ohdr.bsize )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
334 printf("warning: new data size is < approx\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 f_ohdr.dsize=new_data_size;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
337 f_ohdr.bsize=BSS_PAD_SIZE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 if (write(a_new, &f_ohdr, sizeof(f_ohdr)) != sizeof(f_ohdr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 PERROR("failed to write optional header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 /* write text as is */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 printf("writing text header (unchanged)\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 if (write(a_new, &f_text, sizeof(f_text)) != sizeof(f_text))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 PERROR("failed to write text header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 }
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
349 #ifndef NO_DEBUG
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
350 /* Write small bss section. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
351 if (!sections_reversed)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
352 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
353 f_bss.s_size = BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
354 f_bss.s_paddr = BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
355 f_bss.s_vaddr = f_data.s_vaddr - BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
356 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
357 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
358 PERROR("failed to write bss header");
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
359 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
360 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
361 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 /* write new data header */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 printf("writing .data header\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 if (write(a_new, &f_data, sizeof(f_data)) != sizeof(f_data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 PERROR("failed to write data header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 }
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
369 #ifndef NO_DEBUG
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
370 /* Write small bss section. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
371 if (sections_reversed)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
372 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
373 f_bss.s_size = BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
374 f_bss.s_paddr = BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
375 f_bss.s_vaddr = f_nextdata.s_vaddr - BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
376 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
377 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
378 PERROR("failed to write bss header");
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
379 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
380 }
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
381 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 printf("writing following data header\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 f_nextdata.s_scnptr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 if (f_nextdata.s_relptr != 0) f_nextdata.s_relptr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 if (write(a_new, &f_nextdata, sizeof(f_nextdata)) != sizeof(f_nextdata))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 PERROR("failed to write nextdata header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 /* copy other section headers adjusting the file offset */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 for (i=0; i<(f_hdr.f_nscns-3); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 if (read (a_out, &section, sizeof (section)) != sizeof (section))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 PERROR ("no .data section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 section.s_scnptr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 if (section.s_lnnoptr != 0) section.s_lnnoptr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 if (section.s_relptr != 0) section.s_relptr += file_sz_change;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 if (write(a_new, &section, sizeof(section)) != sizeof(section))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 PERROR("failed to write data header");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
408 #ifdef NO_DEBUG
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
409 /* dump bss to maintain offsets */
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
410 memset(&f_bss, 0, sizeof(f_bss));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
411 if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
412 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
413 PERROR("failed to write bss header");
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
414 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
415 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 size=lseek(a_new, 0, SEEK_CUR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 CHECK_AOUT_POS(size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 /* copy eveything else until start of data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 size = f_data_s_scnptr - lseek (a_out, 0, SEEK_CUR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 printf ("copying executable up to data section ... %lx bytes\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 dup_file_area(a_out, a_new, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 CHECK_AOUT_POS(f_data_s_scnptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 if (!sections_reversed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
430 /* dump bss + padding between sections, sans small bss pad */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 printf ("dumping .bss into executable... %lx bytes\n", bss_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 if (write(a_new, bss_start, bss_size) != (int)bss_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 PERROR("failed to write bss section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 /* pad, needs to be zero */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
438 bss_padding = (new_bss_size - bss_size) - BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
439 if (bss_padding < 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
440 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
441 PERROR("padded .bss too small");
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
442 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 printf ("padding .bss ... %lx bytes\n", bss_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 empty_space = malloc(bss_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 memset(empty_space, 0, bss_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 if (write(a_new, empty_space, bss_padding) != (int)bss_padding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 PERROR("failed to write bss section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 free(empty_space);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 /* tell dumped version not to free pure heap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 static_heap_dumped = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 /* Get a pointer to the raw data in our address space. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 printf ("dumping .data section... %lx bytes\n", data_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 if (write(a_new, data_start_va, data_size) != (int)data_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 PERROR("failed to write data section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 /* were going to use free again ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 static_heap_dumped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 size = lseek(a_out, f_data_s_scnptr + data_size, SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 if (!sections_reversed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 size = f_nextdata_s_scnptr - size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 dup_file_area(a_out, a_new, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
473 /* need to pad to bss with data in file */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 printf ("padding .data ... %lx bytes\n", data_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 size = (f_bss_s_vaddr - f_data_s_vaddr) - data_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 dup_file_area(a_out, a_new, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 /* dump bss + padding between sections */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 printf ("dumping .bss into executable... %lx bytes\n", bss_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 if (write(a_new, bss_start, bss_size) != (int)bss_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 PERROR("failed to write bss section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 /* pad, needs to be zero */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
486 bss_padding = (new_bss_size - bss_size) - BSS_PAD_SIZE;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
487 if (bss_padding < 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
488 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
489 PERROR("padded .bss too small");
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
490 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 printf ("padding .bss ... %lx bytes\n", bss_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 empty_space = malloc(bss_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 memset(empty_space, 0, bss_padding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 if (write(a_new, empty_space, bss_padding) != (int)bss_padding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 PERROR("failed to write bss section");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 free(empty_space);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 if (lseek(a_new, 0, SEEK_CUR) != f_nextdata.s_scnptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 printf("at %lx should be at %lx\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 lseek(a_new, 0, SEEK_CUR),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 f_nextdata.s_scnptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 PERROR("file positioning error\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 lseek(a_out, f_nextdata_s_scnptr, SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 CHECK_AOUT_POS(f_nextdata_s_scnptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 /* now dump - nextdata don't need to do this cygwin ds is in .data! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 printf ("dumping following data section... %lx bytes\n", f_nextdata.s_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 dup_file_area(a_out,a_new,f_nextdata.s_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 /* write rest of file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 printf ("writing rest of file\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 size = lseek(a_out, 0, SEEK_END);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 size = size - (f_nextdata_s_scnptr + f_nextdata.s_size); /* length remaining in a_out */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 lseek(a_out, f_nextdata_s_scnptr + f_nextdata.s_size, SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 dup_file_area(a_out, a_new, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 * copy from aout to anew
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 static void dup_file_area(int a_out, int a_new, long size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 char page[BUFSIZ];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 long n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 for (; size > 0; size -= sizeof (page))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 n = size > sizeof (page) ? sizeof (page) : size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 if (read (a_out, page, n) != n || write (a_new, page, n) != n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 PERROR ("dump_out()");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 static void write_int_to_bss(int a_out, int a_new, void* va, void* newval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 int cpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 cpos = lseek(a_new, 0, SEEK_CUR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 if (va < bss_start || va > bss_start + f_data.s_size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 PERROR("address not in data space\n");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 lseek(a_new, f_data.s_scnptr + ((unsigned long)va -
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (unsigned long)bss_start), SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 if (write(a_new, newval, sizeof(int)) != (int)sizeof(int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 PERROR("failed to write int value");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 lseek(a_new, cpos, SEEK_SET);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 #endif /* HAVE_A_OUT_H */