diff options
| author | Dan Nicolaescu | 2008-07-23 06:40:26 +0000 |
|---|---|---|
| committer | Dan Nicolaescu | 2008-07-23 06:40:26 +0000 |
| commit | f914a6bfad1a277cd80ca2ee8fb10c89f7dbef21 (patch) | |
| tree | b0d3da40f145b44b0a3cbeb16b54d8c98a110ec4 /src/unexec.c | |
| parent | 268b24eec66c68694ddd31f4373f17aefe01bfe0 (diff) | |
| download | emacs-f914a6bfad1a277cd80ca2ee8fb10c89f7dbef21.tar.gz emacs-f914a6bfad1a277cd80ca2ee8fb10c89f7dbef21.zip | |
Remove code depending on !COFF and USG, the file is
not used for such systems.
Diffstat (limited to 'src/unexec.c')
| -rw-r--r-- | src/unexec.c | 170 |
1 files changed, 4 insertions, 166 deletions
diff --git a/src/unexec.c b/src/unexec.c index 82d65f85877..a1f962bd606 100644 --- a/src/unexec.c +++ b/src/unexec.c | |||
| @@ -112,25 +112,6 @@ boundary is sufficient. That is the default. When a larger | |||
| 112 | boundary is needed, define SEGMENT_MASK to a mask of | 112 | boundary is needed, define SEGMENT_MASK to a mask of |
| 113 | the bits that must be zero on such a boundary. | 113 | the bits that must be zero on such a boundary. |
| 114 | 114 | ||
| 115 | * A_TEXT_OFFSET(HDR) | ||
| 116 | |||
| 117 | Some machines count the a.out header as part of the size of the text | ||
| 118 | segment (a_text); they may actually load the header into core as the | ||
| 119 | first data in the text segment. Some have additional padding between | ||
| 120 | the header and the real text of the program that is counted in a_text. | ||
| 121 | |||
| 122 | For these machines, define A_TEXT_OFFSET(HDR) to examine the header | ||
| 123 | structure HDR and return the number of bytes to add to `a_text' | ||
| 124 | before writing it (above and beyond the number of bytes of actual | ||
| 125 | program text). HDR's standard fields are already correct, except that | ||
| 126 | this adjustment to the `a_text' field has not yet been made; | ||
| 127 | thus, the amount of offset can depend on the data in the file. | ||
| 128 | |||
| 129 | * A_TEXT_SEEK(HDR) | ||
| 130 | |||
| 131 | If defined, this macro specifies the number of bytes to seek into the | ||
| 132 | a.out file before starting to write the text segment. | ||
| 133 | |||
| 134 | * ADJUST_EXEC_HEADER | 115 | * ADJUST_EXEC_HEADER |
| 135 | 116 | ||
| 136 | This macro can be used to generate statements to adjust or | 117 | This macro can be used to generate statements to adjust or |
| @@ -156,7 +137,7 @@ pointer looks like an int) but not on all machines. | |||
| 156 | 137 | ||
| 157 | #ifndef CANNOT_DUMP /* all rest of file! */ | 138 | #ifndef CANNOT_DUMP /* all rest of file! */ |
| 158 | 139 | ||
| 159 | #if defined(COFF) && defined(HAVE_COFF_H) | 140 | #ifdef HAVE_COFF_H |
| 160 | #include <coff.h> | 141 | #include <coff.h> |
| 161 | #ifdef MSDOS | 142 | #ifdef MSDOS |
| 162 | #if __DJGPP__ > 1 | 143 | #if __DJGPP__ > 1 |
| @@ -182,9 +163,9 @@ struct aouthdr | |||
| 182 | unsigned long data_start;/* base of data used for this file */ | 163 | unsigned long data_start;/* base of data used for this file */ |
| 183 | }; | 164 | }; |
| 184 | #endif /* not MSDOS */ | 165 | #endif /* not MSDOS */ |
| 185 | #else /* not COFF */ | 166 | #else /* not HAVE_COFF_H */ |
| 186 | #include <a.out.h> | 167 | #include <a.out.h> |
| 187 | #endif /* not COFF */ | 168 | #endif /* not HAVE_COFF_H */ |
| 188 | 169 | ||
| 189 | /* Define getpagesize if the system does not. | 170 | /* Define getpagesize if the system does not. |
| 190 | Note that this may depend on symbols defined in a.out.h. */ | 171 | Note that this may depend on symbols defined in a.out.h. */ |
| @@ -197,11 +178,7 @@ struct aouthdr | |||
| 197 | #include <sys/stat.h> | 178 | #include <sys/stat.h> |
| 198 | #include <errno.h> | 179 | #include <errno.h> |
| 199 | 180 | ||
| 200 | #include <sys/file.h> /* Must be after sys/types.h for USG*/ | 181 | #include <sys/file.h> |
| 201 | |||
| 202 | #ifdef USG5 | ||
| 203 | #include <fcntl.h> | ||
| 204 | #endif | ||
| 205 | 182 | ||
| 206 | #ifndef O_RDONLY | 183 | #ifndef O_RDONLY |
| 207 | #define O_RDONLY 0 | 184 | #define O_RDONLY 0 |
| @@ -214,7 +191,6 @@ struct aouthdr | |||
| 214 | extern char *start_of_text (); /* Start of text */ | 191 | extern char *start_of_text (); /* Start of text */ |
| 215 | extern char *start_of_data (); /* Start of initialized data */ | 192 | extern char *start_of_data (); /* Start of initialized data */ |
| 216 | 193 | ||
| 217 | #ifdef COFF | ||
| 218 | static long block_copy_start; /* Old executable start point */ | 194 | static long block_copy_start; /* Old executable start point */ |
| 219 | static struct filehdr f_hdr; /* File header */ | 195 | static struct filehdr f_hdr; /* File header */ |
| 220 | static struct aouthdr f_ohdr; /* Optional file header (a.out) */ | 196 | static struct aouthdr f_ohdr; /* Optional file header (a.out) */ |
| @@ -227,36 +203,6 @@ static long data_scnptr; | |||
| 227 | 203 | ||
| 228 | static long coff_offset; | 204 | static long coff_offset; |
| 229 | 205 | ||
| 230 | #else /* not COFF */ | ||
| 231 | |||
| 232 | extern char *sbrk (); | ||
| 233 | |||
| 234 | #define SYMS_START ((long) N_SYMOFF (ohdr)) | ||
| 235 | |||
| 236 | #if defined (USG) | ||
| 237 | static struct bhdr hdr, ohdr; | ||
| 238 | #define a_magic fmagic | ||
| 239 | #define a_text tsize | ||
| 240 | #define a_data dsize | ||
| 241 | #define a_bss bsize | ||
| 242 | #define a_syms ssize | ||
| 243 | #define a_trsize rtsize | ||
| 244 | #define a_drsize rdsize | ||
| 245 | #define a_entry entry | ||
| 246 | #define N_BADMAG(x) \ | ||
| 247 | (((x).fmagic)!=OMAGIC && ((x).fmagic)!=NMAGIC &&\ | ||
| 248 | ((x).fmagic)!=FMAGIC && ((x).fmagic)!=IMAGIC) | ||
| 249 | #define NEWMAGIC FMAGIC | ||
| 250 | #else /* not USG */ | ||
| 251 | static struct exec hdr, ohdr; | ||
| 252 | #define NEWMAGIC ZMAGIC | ||
| 253 | #endif /* not USG */ | ||
| 254 | |||
| 255 | static int unexec_text_start; | ||
| 256 | static int unexec_data_start; | ||
| 257 | |||
| 258 | #endif /* not COFF */ | ||
| 259 | |||
| 260 | static int pagemask; | 206 | static int pagemask; |
| 261 | 207 | ||
| 262 | /* Correct an int which is the bit pattern of a pointer to a byte | 208 | /* Correct an int which is the bit pattern of a pointer to a byte |
| @@ -320,13 +266,11 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) | |||
| 320 | char *new_name; | 266 | char *new_name; |
| 321 | { | 267 | { |
| 322 | int tem; | 268 | int tem; |
| 323 | #ifdef COFF | ||
| 324 | auto struct scnhdr f_thdr; /* Text section header */ | 269 | auto struct scnhdr f_thdr; /* Text section header */ |
| 325 | auto struct scnhdr f_dhdr; /* Data section header */ | 270 | auto struct scnhdr f_dhdr; /* Data section header */ |
| 326 | auto struct scnhdr f_bhdr; /* Bss section header */ | 271 | auto struct scnhdr f_bhdr; /* Bss section header */ |
| 327 | auto struct scnhdr scntemp; /* Temporary section header */ | 272 | auto struct scnhdr scntemp; /* Temporary section header */ |
| 328 | register int scns; | 273 | register int scns; |
| 329 | #endif /* COFF */ | ||
| 330 | unsigned int bss_end; | 274 | unsigned int bss_end; |
| 331 | 275 | ||
| 332 | pagemask = getpagesize () - 1; | 276 | pagemask = getpagesize () - 1; |
| @@ -370,7 +314,6 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) | |||
| 370 | data_start, bss_start); | 314 | data_start, bss_start); |
| 371 | } | 315 | } |
| 372 | 316 | ||
| 373 | #ifdef COFF | ||
| 374 | coff_offset = 0L; /* stays zero, except in DJGPP */ | 317 | coff_offset = 0L; /* stays zero, except in DJGPP */ |
| 375 | 318 | ||
| 376 | /* Salvage as much info from the existing file as possible */ | 319 | /* Salvage as much info from the existing file as possible */ |
| @@ -529,69 +472,6 @@ make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) | |||
| 529 | 472 | ||
| 530 | return (0); | 473 | return (0); |
| 531 | 474 | ||
| 532 | #else /* if not COFF */ | ||
| 533 | |||
| 534 | /* Get symbol table info from header of a.out file if given one. */ | ||
| 535 | if (a_out >= 0) | ||
| 536 | { | ||
| 537 | if (read (a_out, &ohdr, sizeof hdr) != sizeof hdr) | ||
| 538 | { | ||
| 539 | PERROR (a_name); | ||
| 540 | } | ||
| 541 | |||
| 542 | if (N_BADMAG (ohdr)) | ||
| 543 | { | ||
| 544 | ERROR1 ("invalid magic number in %s", a_name); | ||
| 545 | } | ||
| 546 | hdr = ohdr; | ||
| 547 | } | ||
| 548 | else | ||
| 549 | { | ||
| 550 | #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */ | ||
| 551 | bzero ((void *)&hdr, sizeof hdr); | ||
| 552 | #else | ||
| 553 | bzero (&hdr, sizeof hdr); | ||
| 554 | #endif | ||
| 555 | } | ||
| 556 | |||
| 557 | unexec_text_start = (long) start_of_text (); | ||
| 558 | unexec_data_start = data_start; | ||
| 559 | |||
| 560 | /* Machine-dependent fixup for header, or maybe for unexec_text_start */ | ||
| 561 | #ifdef ADJUST_EXEC_HEADER | ||
| 562 | ADJUST_EXEC_HEADER; | ||
| 563 | #endif /* ADJUST_EXEC_HEADER */ | ||
| 564 | |||
| 565 | hdr.a_trsize = 0; | ||
| 566 | hdr.a_drsize = 0; | ||
| 567 | if (entry_address != 0) | ||
| 568 | hdr.a_entry = entry_address; | ||
| 569 | |||
| 570 | hdr.a_bss = bss_end - bss_start; | ||
| 571 | hdr.a_data = bss_start - data_start; | ||
| 572 | #ifdef NO_REMAP | ||
| 573 | hdr.a_text = ohdr.a_text; | ||
| 574 | #else /* not NO_REMAP */ | ||
| 575 | hdr.a_text = data_start - unexec_text_start; | ||
| 576 | |||
| 577 | #ifdef A_TEXT_OFFSET | ||
| 578 | hdr.a_text += A_TEXT_OFFSET (ohdr); | ||
| 579 | #endif | ||
| 580 | |||
| 581 | #endif /* not NO_REMAP */ | ||
| 582 | |||
| 583 | if (write (new, &hdr, sizeof hdr) != sizeof hdr) | ||
| 584 | { | ||
| 585 | PERROR (new_name); | ||
| 586 | } | ||
| 587 | |||
| 588 | #ifdef A_TEXT_OFFSET | ||
| 589 | hdr.a_text -= A_TEXT_OFFSET (ohdr); | ||
| 590 | #endif | ||
| 591 | |||
| 592 | return 0; | ||
| 593 | |||
| 594 | #endif /* not COFF */ | ||
| 595 | } | 475 | } |
| 596 | 476 | ||
| 597 | write_segment (new, ptr, end) | 477 | write_segment (new, ptr, end) |
| @@ -661,8 +541,6 @@ copy_text_and_data (new, a_out) | |||
| 661 | register char *end; | 541 | register char *end; |
| 662 | register char *ptr; | 542 | register char *ptr; |
| 663 | 543 | ||
| 664 | #ifdef COFF | ||
| 665 | |||
| 666 | #ifdef MSDOS | 544 | #ifdef MSDOS |
| 667 | #if __DJGPP__ >= 2 | 545 | #if __DJGPP__ >= 2 |
| 668 | /* Dump the original table of exception handlers, not the one | 546 | /* Dump the original table of exception handlers, not the one |
| @@ -696,35 +574,6 @@ copy_text_and_data (new, a_out) | |||
| 696 | #endif | 574 | #endif |
| 697 | #endif | 575 | #endif |
| 698 | 576 | ||
| 699 | #else /* if not COFF */ | ||
| 700 | |||
| 701 | /* Some machines count the header as part of the text segment. | ||
| 702 | That is to say, the header appears in core | ||
| 703 | just before the address that start_of_text returns. | ||
| 704 | For them, N_TXTOFF is the place where the header goes. | ||
| 705 | We must adjust the seek to the place after the header. | ||
| 706 | Note that at this point hdr.a_text does *not* count | ||
| 707 | the extra A_TEXT_OFFSET bytes, only the actual bytes of code. */ | ||
| 708 | |||
| 709 | #ifdef A_TEXT_SEEK | ||
| 710 | lseek (new, (long) A_TEXT_SEEK (hdr), 0); | ||
| 711 | #else | ||
| 712 | lseek (new, (long) N_TXTOFF (hdr), 0); | ||
| 713 | #endif /* no A_TEXT_SEEK */ | ||
| 714 | |||
| 715 | ptr = (char *) unexec_text_start; | ||
| 716 | end = ptr + hdr.a_text; | ||
| 717 | write_segment (new, ptr, end); | ||
| 718 | |||
| 719 | ptr = (char *) unexec_data_start; | ||
| 720 | end = ptr + hdr.a_data; | ||
| 721 | /* This lseek is certainly incorrect when A_TEXT_OFFSET | ||
| 722 | and I believe it is a no-op otherwise. | ||
| 723 | Let's see if its absence ever fails. */ | ||
| 724 | /* lseek (new, (long) N_TXTOFF (hdr) + hdr.a_text, 0); */ | ||
| 725 | write_segment (new, ptr, end); | ||
| 726 | |||
| 727 | #endif /* not COFF */ | ||
| 728 | 577 | ||
| 729 | return 0; | 578 | return 0; |
| 730 | } | 579 | } |
| @@ -745,19 +594,13 @@ copy_sym (new, a_out, a_name, new_name) | |||
| 745 | if (a_out < 0) | 594 | if (a_out < 0) |
| 746 | return 0; | 595 | return 0; |
| 747 | 596 | ||
| 748 | #ifdef COFF | ||
| 749 | if (SYMS_START == 0L) | 597 | if (SYMS_START == 0L) |
| 750 | return 0; | 598 | return 0; |
| 751 | #endif /* COFF */ | ||
| 752 | 599 | ||
| 753 | #ifdef COFF | ||
| 754 | if (lnnoptr) /* if there is line number info */ | 600 | if (lnnoptr) /* if there is line number info */ |
| 755 | lseek (a_out, coff_offset + lnnoptr, 0); /* start copying from there */ | 601 | lseek (a_out, coff_offset + lnnoptr, 0); /* start copying from there */ |
| 756 | else | 602 | else |
| 757 | lseek (a_out, coff_offset + SYMS_START, 0); /* Position a.out to symtab. */ | 603 | lseek (a_out, coff_offset + SYMS_START, 0); /* Position a.out to symtab. */ |
| 758 | #else /* not COFF */ | ||
| 759 | lseek (a_out, SYMS_START, 0); /* Position a.out to symtab. */ | ||
| 760 | #endif /* not COFF */ | ||
| 761 | 604 | ||
| 762 | while ((n = read (a_out, page, sizeof page)) > 0) | 605 | while ((n = read (a_out, page, sizeof page)) > 0) |
| 763 | { | 606 | { |
| @@ -797,7 +640,6 @@ mark_x (name) | |||
| 797 | PERROR (name); | 640 | PERROR (name); |
| 798 | } | 641 | } |
| 799 | 642 | ||
| 800 | #ifdef COFF | ||
| 801 | #ifndef COFF_BSD_SYMBOLS | 643 | #ifndef COFF_BSD_SYMBOLS |
| 802 | 644 | ||
| 803 | /* | 645 | /* |
| @@ -869,8 +711,6 @@ adjust_lnnoptrs (writedesc, readdesc, new_name) | |||
| 869 | 711 | ||
| 870 | #endif /* COFF_BSD_SYMBOLS */ | 712 | #endif /* COFF_BSD_SYMBOLS */ |
| 871 | 713 | ||
| 872 | #endif /* COFF */ | ||
| 873 | |||
| 874 | /* **************************************************************** | 714 | /* **************************************************************** |
| 875 | * unexec | 715 | * unexec |
| 876 | * | 716 | * |
| @@ -894,11 +734,9 @@ unexec (new_name, a_name, data_start, bss_start, entry_address) | |||
| 894 | if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 | 734 | if (make_hdr (new, a_out, data_start, bss_start, entry_address, a_name, new_name) < 0 |
| 895 | || copy_text_and_data (new, a_out) < 0 | 735 | || copy_text_and_data (new, a_out) < 0 |
| 896 | || copy_sym (new, a_out, a_name, new_name) < 0 | 736 | || copy_sym (new, a_out, a_name, new_name) < 0 |
| 897 | #ifdef COFF | ||
| 898 | #ifndef COFF_BSD_SYMBOLS | 737 | #ifndef COFF_BSD_SYMBOLS |
| 899 | || adjust_lnnoptrs (new, a_out, new_name) < 0 | 738 | || adjust_lnnoptrs (new, a_out, new_name) < 0 |
| 900 | #endif | 739 | #endif |
| 901 | #endif | ||
| 902 | ) | 740 | ) |
| 903 | { | 741 | { |
| 904 | close (new); | 742 | close (new); |