#include <scnhdr.h>
#include <sym.h>
-#ifdef IRIS_4D
+#if defined (IRIS_4D) || defined (sony)
#include "getpagesize.h"
+#include <fcntl.h>
#endif
static void fatal_unexec ();
+static void mark_x ();
#define READ(_fd, _buffer, _size, _error_message, _error_arg) \
errno = EEOF; \
&& hdr.fhdr.f_magic != (MIPSELMAGIC | 1)
&& hdr.fhdr.f_magic != (MIPSEBMAGIC | 1))
{
- fprintf(stderr,
- "unexec: input file magic number is %x, not %x, %x, %x or %x.\n",
- hdr.fhdr.f_magic,
- MIPSELMAGIC, MIPSEBMAGIC,
- MIPSELMAGIC | 1, MIPSEBMAGIC | 1);
+ fprintf (stderr,
+ "unexec: input file magic number is %x, not %x, %x, %x or %x.\n",
+ hdr.fhdr.f_magic,
+ MIPSELMAGIC, MIPSEBMAGIC,
+ MIPSELMAGIC | 1, MIPSEBMAGIC | 1);
exit(1);
}
#else /* not MIPS2 */
}
#define CHECK_SCNHDR(ptr, name, flags) \
- if (strcmp (hdr.section[i].s_name, name) == 0) \
- { \
- if (hdr.section[i].s_flags != flags) \
- fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \
- hdr.section[i].s_flags, flags, name); \
- ptr = hdr.section + i; \
- i += 1; \
- } \
- else \
- ptr = NULL;
-
- i = 0;
+ ptr = NULL; \
+ for (i = 0; i < hdr.fhdr.f_nscns && !ptr; i++) \
+ if (strcmp (hdr.section[i].s_name, name) == 0) \
+ { \
+ if (hdr.section[i].s_flags != flags) \
+ fprintf (stderr, "unexec: %x flags (%x expected) in %s section.\n", \
+ hdr.section[i].s_flags, flags, name); \
+ ptr = hdr.section + i; \
+ } \
+
CHECK_SCNHDR (text_section, _TEXT, STYP_TEXT);
CHECK_SCNHDR (init_section, _INIT, STYP_INIT);
CHECK_SCNHDR (rdata_section, _RDATA, STYP_RDATA);
CHECK_SCNHDR (sdata_section, _SDATA, STYP_SDATA);
CHECK_SCNHDR (sbss_section, _SBSS, STYP_SBSS);
CHECK_SCNHDR (bss_section, _BSS, STYP_BSS);
+#if 0 /* Apparently this error check goes off on irix 3.3,
+ but it doesn't indicate a real problem. */
if (i != hdr.fhdr.f_nscns)
fprintf (stderr, "unexec: %d sections found instead of %d.\n",
i, hdr.fhdr.f_nscns);
+#endif
+
+ text_section->s_scnptr = 0;
pagesize = getpagesize ();
brk = (sbrk (0) + pagesize - 1) & (-pagesize);
hdr.aout.bss_start = hdr.aout.data_start + hdr.aout.dsize;
rdata_section->s_size = data_start - DATA_START;
+
+ /* Adjust start and virtual addresses of rdata_section, too. */
+ rdata_section->s_vaddr = DATA_START;
+ rdata_section->s_paddr = DATA_START;
+ rdata_section->s_scnptr = text_section->s_scnptr + hdr.aout.tsize;
+
data_section->s_vaddr = data_start;
data_section->s_paddr = data_start;
- data_section->s_size = brk - DATA_START;
+ data_section->s_size = brk - data_start;
data_section->s_scnptr = rdata_section->s_scnptr + rdata_section->s_size;
vaddr = data_section->s_vaddr + data_section->s_size;
scnptr = data_section->s_scnptr + data_section->s_size;
/*
* mark_x
*
- * After succesfully building the new a.out, mark it executable
+ * After successfully building the new a.out, mark it executable
*/
-static
+static void
mark_x (name)
char *name;
{