projects
/
chise
/
xemacs-chise.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update.
[chise/xemacs-chise.git]
/
src
/
unexcw.c
diff --git
a/src/unexcw.c
b/src/unexcw.c
index
a39fbc2
..
63190c5
100644
(file)
--- a/
src/unexcw.c
+++ b/
src/unexcw.c
@@
-23,11
+23,13
@@
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
/* This is a complete rewrite, some code snarfed from unexnt.c and
unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */
/* This is a complete rewrite, some code snarfed from unexnt.c and
unexec.c, Andy Piper (andy@xemacs.org) 13-1-98 */
+#include <config.h>
+#include "lisp.h"
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
-#include <config.h>
#include <string.h>
#define DONT_ENCAPSULATE /* filenames are external in unex*.c */
#include <string.h>
#define DONT_ENCAPSULATE /* filenames are external in unex*.c */
@@
-53,7
+55,11
@@
unexec (char *, char *, void *, void *, void *)
((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
/* Note that all sections must be aligned on a 0x1000 boundary so
this is the minimum size that our dummy bss can be. */
((((unsigned long)addr) + ALLOC_UNIT) & ALLOC_MASK)
/* Note that all sections must be aligned on a 0x1000 boundary so
this is the minimum size that our dummy bss can be. */
+#ifndef NO_DEBUG
#define BSS_PAD_SIZE 0x1000
#define BSS_PAD_SIZE 0x1000
+#else
+#define BSS_PAD_SIZE 0
+#endif
/* To prevent zero-initialized variables from being placed into the bss
section, use non-zero values to represent an uninitialized state. */
/* To prevent zero-initialized variables from being placed into the bss
section, use non-zero values to represent an uninitialized state. */
@@
-88,12
+94,10
@@
if (lseek(a_out, 0, SEEK_CUR) != a) \
exit(-1); \
}
exit(-1); \
}
-void
-unexec (char *out_name, char *in_name, void *start_data,
- void * d1, void * d2);
/* Dump out .data and .bss sections into a new executable. */
/* Dump out .data and .bss sections into a new executable. */
-void unexec (char *out_name, char *in_name, void *start_data,
- void * d1, void * d2)
+int
+unexec (char *out_name, char *in_name, uintptr_t start_data,
+ uintptr_t d1, uintptr_t d2)
{
/* ugly nt hack - should be in lisp */
int a_new, a_out = -1;
{
/* ugly nt hack - should be in lisp */
int a_new, a_out = -1;
@@
-121,7
+125,7
@@
void unexec (char *out_name, char *in_name, void *start_data,
}
if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
}
if ((a_new = open (new_name, O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
- CREAT_MODE)) < 0)
+ 0755)) < 0)
{
PERROR (new_name);
}
{
PERROR (new_name);
}
@@
-133,12
+137,13
@@
void unexec (char *out_name, char *in_name, void *start_data,
close(a_out);
close(a_new);
close(a_out);
close(a_new);
+ return 0;
}
/* Flip through the executable and cache the info necessary for dumping. */
static void get_section_info (int a_out, char* a_name)
{
}
/* Flip through the executable and cache the info necessary for dumping. */
static void get_section_info (int a_out, char* a_name)
{
- extern int my_ebss;
+ extern char my_ebss[];
/* From lastfile.c */
extern char my_edata[];
/* From lastfile.c */
extern char my_edata[];
@@
-287,6
+292,11
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size;
}
data_padding = (f_bss.s_vaddr - f_data.s_vaddr) - f_data.s_size;
}
+ if ((new_bss_size - bss_size) < BSS_PAD_SIZE)
+ {
+ PERROR (".bss free space too small");
+ }
+
file_sz_change=(new_bss_size + data_padding) - BSS_PAD_SIZE;
new_data_size=f_ohdr.dsize + file_sz_change;
file_sz_change=(new_bss_size + data_padding) - BSS_PAD_SIZE;
new_data_size=f_ohdr.dsize + file_sz_change;
@@
-306,6
+316,9
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
lseek (a_new, 0, SEEK_SET);
/* write file header */
f_hdr.f_symptr += file_sz_change;
lseek (a_new, 0, SEEK_SET);
/* write file header */
f_hdr.f_symptr += file_sz_change;
+#ifdef NO_DEBUG
+ f_hdr.f_nscns--;
+#endif
printf("writing file header\n");
if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr))
printf("writing file header\n");
if (write(a_new, &f_hdr, sizeof(f_hdr)) != sizeof(f_hdr))
@@
-333,7
+346,7
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
{
PERROR("failed to write text header");
}
{
PERROR("failed to write text header");
}
-
+#ifndef NO_DEBUG
/* Write small bss section. */
if (!sections_reversed)
{
/* Write small bss section. */
if (!sections_reversed)
{
@@
-345,7
+358,7
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
PERROR("failed to write bss header");
}
}
PERROR("failed to write bss header");
}
}
-
+#endif
/* write new data header */
printf("writing .data header\n");
/* write new data header */
printf("writing .data header\n");
@@
-353,7
+366,7
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
{
PERROR("failed to write data header");
}
{
PERROR("failed to write data header");
}
-
+#ifndef NO_DEBUG
/* Write small bss section. */
if (sections_reversed)
{
/* Write small bss section. */
if (sections_reversed)
{
@@
-365,7
+378,7
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
PERROR("failed to write bss header");
}
}
PERROR("failed to write bss header");
}
}
-
+#endif
printf("writing following data header\n");
f_nextdata.s_scnptr += file_sz_change;
if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
printf("writing following data header\n");
f_nextdata.s_scnptr += file_sz_change;
if (f_nextdata.s_lnnoptr != 0) f_nextdata.s_lnnoptr += file_sz_change;
@@
-392,7
+405,14
@@
copy_executable_and_dump_data_section (int a_out, int a_new)
PERROR("failed to write data header");
}
}
PERROR("failed to write data header");
}
}
-
+#ifdef NO_DEBUG
+ /* dump bss to maintain offsets */
+ memset(&f_bss, 0, sizeof(f_bss));
+ if (write(a_new, &f_bss, sizeof(f_bss)) != sizeof(f_bss))
+ {
+ PERROR("failed to write bss header");
+ }
+#endif
size=lseek(a_new, 0, SEEK_CUR);
CHECK_AOUT_POS(size);
size=lseek(a_new, 0, SEEK_CUR);
CHECK_AOUT_POS(size);