+ if (read (a_out, &f_hdr, sizeof (f_hdr)) != sizeof (f_hdr))
+ {
+ PERROR (a_name);
+ }
+ if (f_hdr.f_opthdr > 0)
+ {
+ if (read (a_out, &f_ohdr, sizeof (f_ohdr)) != sizeof (f_ohdr))
+ {
+ PERROR (a_name);
+ }
+ }
+ if (f_hdr.f_nscns > MAX_SECTIONS)
+ {
+ ERROR0 ("unexec: too many section headers -- increase MAX_SECTIONS");
+ }
+ /* Loop through section headers */
+ for (scns = 0; scns < f_hdr.f_nscns; scns++) {
+ struct scnhdr *s = §ion[scns];
+ if (read (a_out, s, sizeof (*s)) != sizeof (*s))
+ {
+ PERROR (a_name);
+ }
+
+#define CHECK_SCNHDR(ptr, name, flags) \
+ if (strcmp(s->s_name, name) == 0) { \
+ if (s->s_flags != flags) { \
+ fprintf(stderr, "unexec: %lx flags where %x expected in %s section.\n", \
+ (unsigned long)s->s_flags, flags, name); \
+ } \
+ if (ptr) { \
+ fprintf(stderr, "unexec: duplicate section header for section %s.\n", \
+ name); \
+ } \
+ ptr = s; \
+ }
+ CHECK_SCNHDR(f_thdr, _TEXT, STYP_TEXT);
+ CHECK_SCNHDR(f_dhdr, _DATA, STYP_DATA);
+ CHECK_SCNHDR(f_bhdr, _BSS, STYP_BSS);
+ CHECK_SCNHDR(f_lhdr, _LOADER, STYP_LOADER);
+ CHECK_SCNHDR(f_dbhdr, _DEBUG, STYP_DEBUG);
+ CHECK_SCNHDR(f_tchdr, _TYPCHK, STYP_TYPCHK);
+ CHECK_SCNHDR(f_xhdr, _EXCEPT, STYP_EXCEPT);
+ }
+
+ if (f_thdr == 0)
+ {
+ ERROR1 ("unexec: couldn't find \"%s\" section", (int) _TEXT);
+ }
+ if (f_dhdr == 0)
+ {
+ ERROR1 ("unexec: couldn't find \"%s\" section", (int) _DATA);
+ }
+ if (f_bhdr == 0)
+ {
+ ERROR1 ("unexec: couldn't find \"%s\" section", (int) _BSS);
+ }