diff options
| author | Gerd Moellmann | 1999-12-07 09:50:01 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 1999-12-07 09:50:01 +0000 |
| commit | 52da6a59f17afe50bdae531cfcc2742e518a1fd0 (patch) | |
| tree | 07c97d10d51a8077b0d88111e43d0205593aeb95 /src | |
| parent | 0b82e382e320f9e0d3be725b3a5e9b6cd2bf03d2 (diff) | |
| download | emacs-52da6a59f17afe50bdae531cfcc2742e518a1fd0.tar.gz emacs-52da6a59f17afe50bdae531cfcc2742e518a1fd0.zip | |
Include <syms.h>, not <sym.h> on IRIX. Removed
duplicate definition of ElfW.
(find_section): Copied from unexsgi.c.
(unexec): Use find_section. Adjust whitespace. Initialize
new_data2_offset based on old_data, not sbss (this fixes a bug on
IRIX6). Change #ifdef __mips to __sgi, since it's IRIX-specific.
Adjust test for presence of .mdebug section to the new return
value of find_section.
Merge changes from 20.5.
(unexec): Handle .lit4 and .lit8 unconditionally.
Diffstat (limited to 'src')
| -rw-r--r-- | src/unexelf.c | 175 |
1 files changed, 83 insertions, 92 deletions
diff --git a/src/unexelf.c b/src/unexelf.c index 804e86b45e0..ad0f346be3c 100644 --- a/src/unexelf.c +++ b/src/unexelf.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992, 1999 | 1 | /* Copyright (C) 1985, 1986, 1987, 1988, 1990, 1992 |
| 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. |
| @@ -412,13 +412,6 @@ Filesz Memsz Flags Align | |||
| 412 | 412 | ||
| 413 | */ | 413 | */ |
| 414 | 414 | ||
| 415 | #ifndef emacs | ||
| 416 | #define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1) | ||
| 417 | #else | ||
| 418 | #include <config.h> | ||
| 419 | extern void fatal (char *, ...); | ||
| 420 | #endif | ||
| 421 | |||
| 422 | #include <sys/types.h> | 415 | #include <sys/types.h> |
| 423 | #include <stdio.h> | 416 | #include <stdio.h> |
| 424 | #include <sys/stat.h> | 417 | #include <sys/stat.h> |
| @@ -436,7 +429,7 @@ extern void fatal (char *, ...); | |||
| 436 | #include <sym.h> | 429 | #include <sym.h> |
| 437 | #endif /* __sony_news && _SYSTYPE_SYSV */ | 430 | #endif /* __sony_news && _SYSTYPE_SYSV */ |
| 438 | #if __sgi | 431 | #if __sgi |
| 439 | #include <sym.h> /* for HDRR declaration */ | 432 | #include <syms.h> /* for HDRR declaration */ |
| 440 | #endif /* __sgi */ | 433 | #endif /* __sgi */ |
| 441 | 434 | ||
| 442 | #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__) | 435 | #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__) |
| @@ -497,16 +490,6 @@ typedef struct { | |||
| 497 | # define SHN_ABS Elf_eshn_absolute | 490 | # define SHN_ABS Elf_eshn_absolute |
| 498 | # define SHN_COMMON Elf_eshn_common | 491 | # define SHN_COMMON Elf_eshn_common |
| 499 | 492 | ||
| 500 | /* | ||
| 501 | * The magic of picking the right size types is handled by the ELFSIZE | ||
| 502 | * definition above. | ||
| 503 | */ | ||
| 504 | # ifdef __STDC__ | ||
| 505 | # define ElfW(type) Elf_##type | ||
| 506 | # else | ||
| 507 | # define ElfW(type) Elf_/**/type | ||
| 508 | # endif | ||
| 509 | |||
| 510 | # ifdef __alpha__ | 493 | # ifdef __alpha__ |
| 511 | # include <sys/exec_ecoff.h> | 494 | # include <sys/exec_ecoff.h> |
| 512 | # define HDRR struct ecoff_symhdr | 495 | # define HDRR struct ecoff_symhdr |
| @@ -524,18 +507,17 @@ typedef struct { | |||
| 524 | 507 | ||
| 525 | #ifndef ElfW | 508 | #ifndef ElfW |
| 526 | # ifdef __STDC__ | 509 | # ifdef __STDC__ |
| 527 | # define ElfBitsW(bits, type) Elf##bits##_##type | 510 | # define ElfW(type) Elf32_##type |
| 528 | # else | ||
| 529 | # define ElfBitsW(bits, type) Elf/**/bits/**/_/**/type | ||
| 530 | # endif | ||
| 531 | # ifdef _LP64 | ||
| 532 | # define ELFSIZE 64 | ||
| 533 | # else | 511 | # else |
| 534 | # define ELFSIZE 32 | 512 | # define ElfW(type) Elf32_/**/type |
| 535 | # endif | 513 | # endif |
| 536 | /* This macro expands `bits' before invoking ElfBitsW. */ | 514 | #endif |
| 537 | # define ElfExpandBitsW(bits, type) ElfBitsW (bits, type) | 515 | |
| 538 | # define ElfW(type) ElfExpandBitsW (ELFSIZE, type) | 516 | #ifndef emacs |
| 517 | #define fatal(a, b, c) fprintf (stderr, a, b, c), exit (1) | ||
| 518 | #else | ||
| 519 | #include <config.h> | ||
| 520 | extern void fatal (char *, ...); | ||
| 539 | #endif | 521 | #endif |
| 540 | 522 | ||
| 541 | #ifndef ELF_BSS_SECTION_NAME | 523 | #ifndef ELF_BSS_SECTION_NAME |
| @@ -596,6 +578,45 @@ round_up (x, y) | |||
| 596 | return x - rem + y; | 578 | return x - rem + y; |
| 597 | } | 579 | } |
| 598 | 580 | ||
| 581 | /* Return the index of the section named NAME. | ||
| 582 | SECTION_NAMES, FILE_NAME and FILE_H give information | ||
| 583 | about the file we are looking in. | ||
| 584 | |||
| 585 | If we don't find the section NAME, that is a fatal error | ||
| 586 | if NOERROR is 0; we return -1 if NOERROR is nonzero. */ | ||
| 587 | |||
| 588 | static int | ||
| 589 | find_section (name, section_names, file_name, old_file_h, old_section_h, noerror) | ||
| 590 | char *name; | ||
| 591 | char *section_names; | ||
| 592 | char *file_name; | ||
| 593 | ElfW(Ehdr) *old_file_h; | ||
| 594 | ElfW(Shdr) *old_section_h; | ||
| 595 | int noerror; | ||
| 596 | { | ||
| 597 | int idx; | ||
| 598 | |||
| 599 | for (idx = 1; idx < old_file_h->e_shnum; idx++) | ||
| 600 | { | ||
| 601 | #ifdef DEBUG | ||
| 602 | fprintf (stderr, "Looking for %s - found %s\n", name, | ||
| 603 | section_names + OLD_SECTION_H (idx).sh_name); | ||
| 604 | #endif | ||
| 605 | if (!strcmp (section_names + OLD_SECTION_H (idx).sh_name, | ||
| 606 | name)) | ||
| 607 | break; | ||
| 608 | } | ||
| 609 | if (idx == old_file_h->e_shnum) | ||
| 610 | { | ||
| 611 | if (noerror) | ||
| 612 | return -1; | ||
| 613 | else | ||
| 614 | fatal ("Can't find %s in %s.\n", name, file_name, 0); | ||
| 615 | } | ||
| 616 | |||
| 617 | return idx; | ||
| 618 | } | ||
| 619 | |||
| 599 | /* **************************************************************** | 620 | /* **************************************************************** |
| 600 | * unexec | 621 | * unexec |
| 601 | * | 622 | * |
| @@ -630,8 +651,10 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 630 | ElfW(Off) new_data2_offset; | 651 | ElfW(Off) new_data2_offset; |
| 631 | ElfW(Addr) new_data2_addr; | 652 | ElfW(Addr) new_data2_addr; |
| 632 | 653 | ||
| 633 | int n, nn, old_bss_index, old_data_index, new_data2_index; | 654 | int n, nn; |
| 634 | int old_sbss_index, old_mdebug_index; | 655 | int old_bss_index, old_sbss_index; |
| 656 | int old_data_index, new_data2_index; | ||
| 657 | int old_mdebug_index; | ||
| 635 | struct stat stat_buf; | 658 | struct stat stat_buf; |
| 636 | 659 | ||
| 637 | /* Open the old file & map it into the address space. */ | 660 | /* Open the old file & map it into the address space. */ |
| @@ -663,65 +686,40 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 663 | old_section_names = (char *) old_base | 686 | old_section_names = (char *) old_base |
| 664 | + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; | 687 | + OLD_SECTION_H (old_file_h->e_shstrndx).sh_offset; |
| 665 | 688 | ||
| 689 | /* Find the mdebug section, if any. */ | ||
| 690 | |||
| 691 | old_mdebug_index = find_section (".mdebug", old_section_names, | ||
| 692 | old_name, old_file_h, old_section_h, 1); | ||
| 693 | |||
| 666 | /* Find the old .bss section. Figure out parameters of the new | 694 | /* Find the old .bss section. Figure out parameters of the new |
| 667 | * data2 and bss sections. | 695 | * data2 and bss sections. |
| 668 | */ | 696 | */ |
| 669 | 697 | ||
| 670 | for (old_bss_index = 1; old_bss_index < (int) old_file_h->e_shnum; | 698 | old_bss_index = find_section (".bss", old_section_names, |
| 671 | old_bss_index++) | 699 | old_name, old_file_h, old_section_h, 0); |
| 672 | { | ||
| 673 | #ifdef DEBUG | ||
| 674 | fprintf (stderr, "Looking for .bss - found %s\n", | ||
| 675 | old_section_names + OLD_SECTION_H (old_bss_index).sh_name); | ||
| 676 | #endif | ||
| 677 | if (!strcmp (old_section_names + OLD_SECTION_H (old_bss_index).sh_name, | ||
| 678 | ELF_BSS_SECTION_NAME)) | ||
| 679 | break; | ||
| 680 | } | ||
| 681 | if (old_bss_index == old_file_h->e_shnum) | ||
| 682 | fatal ("Can't find .bss in %s.\n", old_name, 0); | ||
| 683 | 700 | ||
| 684 | for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum; | 701 | old_sbss_index = find_section (".sbss", old_section_names, |
| 685 | old_sbss_index++) | 702 | old_name, old_file_h, old_section_h, 1); |
| 686 | { | 703 | |
| 687 | #ifdef DEBUG | 704 | if (old_sbss_index == -1) |
| 688 | fprintf (stderr, "Looking for .sbss - found %s\n", | ||
| 689 | old_section_names + OLD_SECTION_H (old_sbss_index).sh_name); | ||
| 690 | #endif | ||
| 691 | if (!strcmp (old_section_names + OLD_SECTION_H (old_sbss_index).sh_name, | ||
| 692 | ".sbss")) | ||
| 693 | break; | ||
| 694 | } | ||
| 695 | if (old_sbss_index == old_file_h->e_shnum) | ||
| 696 | { | 705 | { |
| 697 | old_sbss_index = -1; | 706 | old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; |
| 698 | old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr; | 707 | old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; |
| 699 | old_bss_size = OLD_SECTION_H(old_bss_index).sh_size; | ||
| 700 | new_data2_offset = OLD_SECTION_H(old_bss_index).sh_offset; | ||
| 701 | new_data2_index = old_bss_index; | 708 | new_data2_index = old_bss_index; |
| 702 | } | 709 | } |
| 703 | else | 710 | else |
| 704 | { | 711 | { |
| 705 | old_bss_addr = OLD_SECTION_H(old_sbss_index).sh_addr; | 712 | old_bss_addr = OLD_SECTION_H (old_sbss_index).sh_addr; |
| 706 | old_bss_size = OLD_SECTION_H(old_bss_index).sh_size | 713 | old_bss_size = OLD_SECTION_H (old_bss_index).sh_size |
| 707 | + OLD_SECTION_H(old_sbss_index).sh_size; | 714 | + OLD_SECTION_H (old_sbss_index).sh_size; |
| 708 | new_data2_offset = OLD_SECTION_H(old_sbss_index).sh_offset; | ||
| 709 | new_data2_index = old_sbss_index; | 715 | new_data2_index = old_sbss_index; |
| 710 | } | 716 | } |
| 711 | 717 | ||
| 712 | for (old_mdebug_index = 1; old_mdebug_index < (int) old_file_h->e_shnum; | 718 | /* Find the old .data section. Figure out parameters of |
| 713 | old_mdebug_index++) | 719 | the new data2 and bss sections. */ |
| 714 | { | 720 | |
| 715 | #ifdef DEBUG | 721 | old_data_index = find_section (".data", old_section_names, |
| 716 | fprintf (stderr, "Looking for .mdebug - found %s\n", | 722 | old_name, old_file_h, old_section_h, 0); |
| 717 | old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name); | ||
| 718 | #endif | ||
| 719 | if (!strcmp (old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name, | ||
| 720 | ".mdebug")) | ||
| 721 | break; | ||
| 722 | } | ||
| 723 | if (old_mdebug_index == old_file_h->e_shnum) | ||
| 724 | old_mdebug_index = 0; | ||
| 725 | 723 | ||
| 726 | #if defined (emacs) || !defined (DEBUG) | 724 | #if defined (emacs) || !defined (DEBUG) |
| 727 | new_bss_addr = (ElfW(Addr)) sbrk (0); | 725 | new_bss_addr = (ElfW(Addr)) sbrk (0); |
| @@ -730,6 +728,8 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 730 | #endif | 728 | #endif |
| 731 | new_data2_addr = old_bss_addr; | 729 | new_data2_addr = old_bss_addr; |
| 732 | new_data2_size = new_bss_addr - old_bss_addr; | 730 | new_data2_size = new_bss_addr - old_bss_addr; |
| 731 | new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset + | ||
| 732 | (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr); | ||
| 733 | 733 | ||
| 734 | #ifdef DEBUG | 734 | #ifdef DEBUG |
| 735 | fprintf (stderr, "old_bss_index %d\n", old_bss_index); | 735 | fprintf (stderr, "old_bss_index %d\n", old_bss_index); |
| @@ -814,13 +814,13 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 814 | if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) | 814 | if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) |
| 815 | alignment = OLD_SECTION_H (old_bss_index).sh_addralign; | 815 | alignment = OLD_SECTION_H (old_bss_index).sh_addralign; |
| 816 | 816 | ||
| 817 | #ifdef __mips | 817 | #ifdef __sgi |
| 818 | /* According to r02kar@x4u2.desy.de (Karsten Kuenne) | 818 | /* According to r02kar@x4u2.desy.de (Karsten Kuenne) |
| 819 | and oliva@gnu.org (Alexandre Oliva), on IRIX 5.2, we | 819 | and oliva@gnu.org (Alexandre Oliva), on IRIX 5.2, we |
| 820 | always get "Program segment above .bss" when dumping | 820 | always get "Program segment above .bss" when dumping |
| 821 | when the executable doesn't have an sbss section. */ | 821 | when the executable doesn't have an sbss section. */ |
| 822 | if (old_sbss_index != -1) | 822 | if (old_sbss_index != -1) |
| 823 | #endif /* __mips */ | 823 | #endif /* __sgi */ |
| 824 | if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz | 824 | if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz |
| 825 | > (old_sbss_index == -1 | 825 | > (old_sbss_index == -1 |
| 826 | ? old_bss_addr | 826 | ? old_bss_addr |
| @@ -934,15 +934,9 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 934 | >= OLD_SECTION_H (old_bss_index-1).sh_offset) | 934 | >= OLD_SECTION_H (old_bss_index-1).sh_offset) |
| 935 | NEW_SECTION_H (nn).sh_offset += new_data2_size; | 935 | NEW_SECTION_H (nn).sh_offset += new_data2_size; |
| 936 | #else | 936 | #else |
| 937 | /* The idea of this is that the bss section's sh_offset | 937 | if (round_up (NEW_SECTION_H (nn).sh_offset, |
| 938 | may need rounding up to compare with new_data2_offset. | ||
| 939 | So we cannot simply compare the sh_offset. | ||
| 940 | However, another small section could exist just before | ||
| 941 | the bss section, and we need to know that is before. */ | ||
| 942 | if (round_up (NEW_SECTION_H (nn).sh_offset | ||
| 943 | + NEW_SECTION_H (nn).sh_size, | ||
| 944 | OLD_SECTION_H (old_bss_index).sh_addralign) | 938 | OLD_SECTION_H (old_bss_index).sh_addralign) |
| 945 | > new_data2_offset) | 939 | >= new_data2_offset) |
| 946 | NEW_SECTION_H (nn).sh_offset += new_data2_size; | 940 | NEW_SECTION_H (nn).sh_offset += new_data2_size; |
| 947 | #endif | 941 | #endif |
| 948 | /* Any section that was originally placed after the section | 942 | /* Any section that was originally placed after the section |
| @@ -979,8 +973,6 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 979 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 973 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
| 980 | ".lit8") | 974 | ".lit8") |
| 981 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 975 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
| 982 | ".got") | ||
| 983 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | ||
| 984 | ".sdata1") | 976 | ".sdata1") |
| 985 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 977 | || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
| 986 | ".data1")) | 978 | ".data1")) |
| @@ -1013,7 +1005,8 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 1013 | #endif /* __alpha__ */ | 1005 | #endif /* __alpha__ */ |
| 1014 | 1006 | ||
| 1015 | #if defined (__sony_news) && defined (_SYSTYPE_SYSV) | 1007 | #if defined (__sony_news) && defined (_SYSTYPE_SYSV) |
| 1016 | if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG && old_mdebug_index) | 1008 | if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG |
| 1009 | && old_mdebug_index != -1) | ||
| 1017 | { | 1010 | { |
| 1018 | int diff = NEW_SECTION_H(nn).sh_offset | 1011 | int diff = NEW_SECTION_H(nn).sh_offset |
| 1019 | - OLD_SECTION_H(old_mdebug_index).sh_offset; | 1012 | - OLD_SECTION_H(old_mdebug_index).sh_offset; |
| @@ -1156,8 +1149,6 @@ unexec (new_name, old_name, data_start, bss_start, entry_address) | |||
| 1156 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), | 1149 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), |
| 1157 | ".lit8") | 1150 | ".lit8") |
| 1158 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), | 1151 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), |
| 1159 | ".got") | ||
| 1160 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), | ||
| 1161 | ".sdata1") | 1152 | ".sdata1") |
| 1162 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), | 1153 | || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name), |
| 1163 | ".data1")) | 1154 | ".data1")) |