Mercurial > emacs
comparison src/unexelf.c @ 28121:da0b1ef29e28
Restore changes of 1999-10-19.
(unexec): Don't adjust bss for sbss type SHT_PROGBITS; otherwise
fix its type and alignment; copy it from current process.
author | Dave Love <fx@gnu.org> |
---|---|
date | Sun, 12 Mar 2000 17:04:43 +0000 |
parents | 026eb782382e |
children | c0ff788ed359 |
comparison
equal
deleted
inserted
replaced
28120:ff3e24c96b80 | 28121:da0b1ef29e28 |
---|---|
1 /* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992 | 1 /* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1999, 2000 |
2 Free Software Foundation, Inc. | 2 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GNU Emacs. | 4 This file is part of GNU Emacs. |
5 | 5 |
6 GNU Emacs is free software; you can redistribute it and/or modify | 6 GNU Emacs is free software; you can redistribute it and/or modify |
50 * program code and literal data, while the data segment is always unshared | 50 * program code and literal data, while the data segment is always unshared |
51 * and unprotected. Data_start gives the lowest unprotected address. | 51 * and unprotected. Data_start gives the lowest unprotected address. |
52 * The value you specify may be rounded down to a suitable boundary | 52 * The value you specify may be rounded down to a suitable boundary |
53 * as required by the machine you are using. | 53 * as required by the machine you are using. |
54 * | 54 * |
55 * Specifying zero for data_start means the boundary between text and data | |
56 * should not be the same as when the program was loaded. | |
57 * If NO_REMAP is defined, the argument data_start is ignored and the | |
58 * segment boundaries are never changed. | |
59 * | |
60 * Bss_start indicates how much of the data segment is to be saved in the | 55 * Bss_start indicates how much of the data segment is to be saved in the |
61 * a.out file and restored when the program is executed. It gives the lowest | 56 * a.out file and restored when the program is executed. It gives the lowest |
62 * unsaved address, and is rounded up to a page boundary. The default when 0 | 57 * unsaved address, and is rounded up to a page boundary. The default when 0 |
63 * is given assumes that the entire data segment is to be stored, including | 58 * is given assumes that the entire data segment is to be stored, including |
64 * the previous data and bss as well as any additional storage allocated with | 59 * the previous data and bss as well as any additional storage allocated with |
65 * break (2). | 60 * break (2). |
66 * | 61 * |
67 * The new file is set up to start at entry_address. | 62 * The new file is set up to start at entry_address. |
68 * | |
69 * If you make improvements I'd like to get them too. | |
70 * harpo!utah-cs!thomas, thomas@Utah-20 | |
71 * | 63 * |
72 */ | 64 */ |
73 | 65 |
74 /* Even more heavily modified by james@bigtex.cactus.org of Dell Computer Co. | 66 /* Even more heavily modified by james@bigtex.cactus.org of Dell Computer Co. |
75 * ELF support added. | 67 * ELF support added. |
410 [21] 1 0 0 0x8f949 0x68b7 .comment | 402 [21] 1 0 0 0x8f949 0x68b7 .comment |
411 0 0 0x1 0 | 403 0 0 0x1 0 |
412 | 404 |
413 */ | 405 */ |
414 | 406 |
407 #ifndef emacs | |
408 #define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1) | |
409 #else | |
410 #include <config.h> | |
411 extern void fatal (char *, ...); | |
412 #endif | |
413 | |
415 #include <sys/types.h> | 414 #include <sys/types.h> |
416 #include <stdio.h> | 415 #include <stdio.h> |
417 #include <sys/stat.h> | 416 #include <sys/stat.h> |
418 #include <memory.h> | 417 #include <memory.h> |
419 #include <string.h> | 418 #include <string.h> |
507 # include <link.h> /* get ElfW etc */ | 506 # include <link.h> /* get ElfW etc */ |
508 #endif | 507 #endif |
509 | 508 |
510 #ifndef ElfW | 509 #ifndef ElfW |
511 # ifdef __STDC__ | 510 # ifdef __STDC__ |
512 # define ElfW(type) Elf32_##type | 511 # define ElfBitsW(bits, type) Elf##bits##_##type |
513 # else | 512 # else |
514 # define ElfW(type) Elf32_/**/type | 513 # define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type |
515 # endif | 514 # endif |
516 #endif | 515 # ifdef _LP64 |
517 | 516 # define ELFSIZE 64 |
518 #ifndef emacs | 517 # else |
519 #define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1) | 518 # define ELFSIZE 32 |
520 #else | 519 # endif |
521 #include <config.h> | 520 /* This macro expands `bits' before invoking ElfBitsW. */ |
522 extern void fatal (char *, ...); | 521 # define ElfExpandBitsW(bits, type) ElfBitsW (bits, type) |
522 # define ElfW(type) ElfExpandBitsW (ELFSIZE, type) | |
523 #endif | 523 #endif |
524 | 524 |
525 #ifndef ELF_BSS_SECTION_NAME | 525 #ifndef ELF_BSS_SECTION_NAME |
526 #define ELF_BSS_SECTION_NAME ".bss" | 526 #define ELF_BSS_SECTION_NAME ".bss" |
527 #endif | 527 #endif |
700 old_bss_index = find_section (".bss", old_section_names, | 700 old_bss_index = find_section (".bss", old_section_names, |
701 old_name, old_file_h, old_section_h, 0); | 701 old_name, old_file_h, old_section_h, 0); |
702 | 702 |
703 old_sbss_index = find_section (".sbss", old_section_names, | 703 old_sbss_index = find_section (".sbss", old_section_names, |
704 old_name, old_file_h, old_section_h, 1); | 704 old_name, old_file_h, old_section_h, 1); |
705 if (old_sbss_index != -1) | |
706 if (OLD_SECTION_H (old_sbss_index).sh_type == SHT_PROGBITS) | |
707 old_sbss_index = -1; | |
705 | 708 |
706 if (old_sbss_index == -1) | 709 if (old_sbss_index == -1) |
707 { | 710 { |
708 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; | 711 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; |
709 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; | 712 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; |
956 /* For symbol tables, info is a symbol table index, | 959 /* For symbol tables, info is a symbol table index, |
957 so don't change it. */ | 960 so don't change it. */ |
958 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB | 961 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB |
959 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) | 962 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) |
960 PATCH_INDEX (NEW_SECTION_H (nn).sh_info); | 963 PATCH_INDEX (NEW_SECTION_H (nn).sh_info); |
964 | |
965 if (old_sbss_index != -1) | |
966 if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".sbss")) | |
967 { | |
968 NEW_SECTION_H (nn).sh_offset = | |
969 round_up (NEW_SECTION_H (nn).sh_offset, | |
970 NEW_SECTION_H (nn).sh_addralign); | |
971 NEW_SECTION_H (nn).sh_type = SHT_PROGBITS; | |
972 } | |
961 | 973 |
962 /* Now, start to copy the content of sections. */ | 974 /* Now, start to copy the content of sections. */ |
963 if (NEW_SECTION_H (nn).sh_type == SHT_NULL | 975 if (NEW_SECTION_H (nn).sh_type == SHT_NULL |
964 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) | 976 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) |
965 continue; | 977 continue; |
975 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 987 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
976 ".lit8") | 988 ".lit8") |
977 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 989 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
978 ".sdata1") | 990 ".sdata1") |
979 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 991 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
980 ".data1")) | 992 ".data1") |
993 || !strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, | |
994 ".sbss")) | |
981 src = (caddr_t) OLD_SECTION_H (n).sh_addr; | 995 src = (caddr_t) OLD_SECTION_H (n).sh_addr; |
982 else | 996 else |
983 src = old_base + OLD_SECTION_H (n).sh_offset; | 997 src = old_base + OLD_SECTION_H (n).sh_offset; |
984 | 998 |
985 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, | 999 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, |