Mercurial > emacs
comparison src/unexelf.c @ 18474:c21ad324c249
[__sony_news && _SYSTYPE_SYSV]: Include sym.h and sys/elf_mips.h.
(unexec): Add __sony_news && _SYSTYPE_SYSV conditionals.
Add a _nec_ews_svr4 conditional.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 27 Jun 1997 22:08:03 +0000 |
parents | 2c15b1cd3b84 |
children | ee209ce34d8a |
comparison
equal
deleted
inserted
replaced
18473:9e73857f8855 | 18474:c21ad324c249 |
---|---|
420 #include <errno.h> | 420 #include <errno.h> |
421 #include <unistd.h> | 421 #include <unistd.h> |
422 #include <fcntl.h> | 422 #include <fcntl.h> |
423 #include <elf.h> | 423 #include <elf.h> |
424 #include <sys/mman.h> | 424 #include <sys/mman.h> |
425 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
426 #include <sys/elf_mips.h> | |
427 #include <sym.h> | |
428 #endif /* __sony_news && _SYSTYPE_SYSV */ | |
425 | 429 |
426 #ifdef __alpha__ | 430 #ifdef __alpha__ |
427 # include <sym.h> /* get COFF debugging symbol table declaration */ | 431 # include <sym.h> /* get COFF debugging symbol table declaration */ |
428 #endif | 432 #endif |
429 | 433 |
537 ElfW(Word) old_bss_size, new_data2_size; | 541 ElfW(Word) old_bss_size, new_data2_size; |
538 ElfW(Off) new_data2_offset; | 542 ElfW(Off) new_data2_offset; |
539 ElfW(Addr) new_data2_addr; | 543 ElfW(Addr) new_data2_addr; |
540 | 544 |
541 int n, nn, old_bss_index, old_data_index, new_data2_index; | 545 int n, nn, old_bss_index, old_data_index, new_data2_index; |
546 #if defined ( __sony_news) && defined (_SYSTYPE_SYSV) | |
547 int old_sbss_index, old_mdebug_index; | |
548 #endif /* __sony_news && _SYSTYPE_SYSV */ | |
542 struct stat stat_buf; | 549 struct stat stat_buf; |
543 | 550 |
544 /* Open the old file & map it into the address space. */ | 551 /* Open the old file & map it into the address space. */ |
545 | 552 |
546 old_file = open (old_name, O_RDONLY); | 553 old_file = open (old_name, O_RDONLY); |
585 break; | 592 break; |
586 } | 593 } |
587 if (old_bss_index == old_file_h->e_shnum) | 594 if (old_bss_index == old_file_h->e_shnum) |
588 fatal ("Can't find .bss in %s.\n", old_name, 0); | 595 fatal ("Can't find .bss in %s.\n", old_name, 0); |
589 | 596 |
597 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
598 for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum; | |
599 old_sbss_index++) | |
600 { | |
601 #ifdef DEBUG | |
602 fprintf (stderr, "Looking for .sbss - found %s\n", | |
603 old_section_names + OLD_SECTION_H (old_sbss_index).sh_name); | |
604 #endif | |
605 if (!strcmp (old_section_names + OLD_SECTION_H (old_sbss_index).sh_name, | |
606 ".sbss")) | |
607 break; | |
608 } | |
609 if (old_sbss_index == old_file_h->e_shnum) | |
610 { | |
611 old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr; | |
612 old_bss_size = OLD_SECTION_H(old_bss_index).sh_size; | |
613 new_data2_offset = OLD_SECTION_H(old_bss_index).sh_offset; | |
614 new_data2_index = old_bss_index; | |
615 } | |
616 else | |
617 { | |
618 old_bss_addr = OLD_SECTION_H(old_sbss_index).sh_addr; | |
619 old_bss_size = OLD_SECTION_H(old_bss_index).sh_size | |
620 + OLD_SECTION_H(old_sbss_index).sh_size; | |
621 new_data2_offset = OLD_SECTION_H(old_sbss_index).sh_offset; | |
622 new_data2_index = old_sbss_index; | |
623 } | |
624 | |
625 for (old_mdebug_index = 1; old_mdebug_index < (int) old_file_h->e_shnum; | |
626 old_mdebug_index++) | |
627 { | |
628 #ifdef DEBUG | |
629 fprintf (stderr, "Looking for .mdebug - found %s\n", | |
630 old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name); | |
631 #endif | |
632 if (!strcmp (old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name, | |
633 ".mdebug")) | |
634 break; | |
635 } | |
636 if (old_mdebug_index == old_file_h->e_shnum) | |
637 old_mdebug_index = 0; | |
638 #else /* not (__sony_news && _SYSTYPE_SYSV) */ | |
590 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; | 639 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; |
591 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; | 640 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; |
641 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
592 #if defined(emacs) || !defined(DEBUG) | 642 #if defined(emacs) || !defined(DEBUG) |
593 new_bss_addr = (ElfW(Addr)) sbrk (0); | 643 new_bss_addr = (ElfW(Addr)) sbrk (0); |
594 #else | 644 #else |
595 new_bss_addr = old_bss_addr + old_bss_size + 0x1234; | 645 new_bss_addr = old_bss_addr + old_bss_size + 0x1234; |
596 #endif | 646 #endif |
597 new_data2_addr = old_bss_addr; | 647 new_data2_addr = old_bss_addr; |
598 new_data2_size = new_bss_addr - old_bss_addr; | 648 new_data2_size = new_bss_addr - old_bss_addr; |
649 #if !defined (__sony_news) || !defined (_SYSTYPE_SYSV) | |
599 new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset; | 650 new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset; |
651 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
600 | 652 |
601 #ifdef DEBUG | 653 #ifdef DEBUG |
602 fprintf (stderr, "old_bss_index %d\n", old_bss_index); | 654 fprintf (stderr, "old_bss_index %d\n", old_bss_index); |
603 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr); | 655 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr); |
604 fprintf (stderr, "old_bss_size %x\n", old_bss_size); | 656 fprintf (stderr, "old_bss_size %x\n", old_bss_size); |
679 /* Compute maximum of all requirements for alignment of section. */ | 731 /* Compute maximum of all requirements for alignment of section. */ |
680 int alignment = (NEW_PROGRAM_H (n)).p_align; | 732 int alignment = (NEW_PROGRAM_H (n)).p_align; |
681 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) | 733 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) |
682 alignment = OLD_SECTION_H (old_bss_index).sh_addralign; | 734 alignment = OLD_SECTION_H (old_bss_index).sh_addralign; |
683 | 735 |
736 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
737 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz | |
738 > round_up (old_bss_addr, alignment)) | |
739 fatal ("Program segment above .bss in %s\n", old_name, 0); | |
740 #else /* not (__sony_news && _SYSTYPE_SYSV) */ | |
684 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr) | 741 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr) |
685 fatal ("Program segment above .bss in %s\n", old_name, 0); | 742 fatal ("Program segment above .bss in %s\n", old_name, 0); |
743 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
686 | 744 |
687 if (NEW_PROGRAM_H (n).p_type == PT_LOAD | 745 if (NEW_PROGRAM_H (n).p_type == PT_LOAD |
688 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr | 746 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr |
689 + (NEW_PROGRAM_H (n)).p_filesz, | 747 + (NEW_PROGRAM_H (n)).p_filesz, |
690 alignment) | 748 alignment) |
726 /* Walk through all section headers, insert the new data2 section right | 784 /* Walk through all section headers, insert the new data2 section right |
727 before the new bss section. */ | 785 before the new bss section. */ |
728 for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++) | 786 for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++) |
729 { | 787 { |
730 caddr_t src; | 788 caddr_t src; |
731 /* If it is bss section, insert the new data2 section before it. */ | 789 int temp_index; |
732 if (n == old_bss_index) | 790 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) |
791 /* If it is (s)bss section, insert the new data2 section before it. */ | |
792 /* new_data2_index is the index of either old_sbss or old_bss, that was | |
793 chosen as a section for new_data2. */ | |
794 temp_index = new_data2_index; | |
795 #else /* not (__sony_news && _SYSTYPE_SYSV) */ | |
796 /* If it is bss section, insert the new data2 section before it. */ | |
797 temp_index = old_bss_index; | |
798 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ | |
799 if (n == temp_index) | |
733 { | 800 { |
734 /* Steal the data section header for this data2 section. */ | 801 /* Steal the data section header for this data2 section. */ |
735 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), | 802 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), |
736 new_file_h->e_shentsize); | 803 new_file_h->e_shentsize); |
737 | 804 |
750 nn++; | 817 nn++; |
751 } | 818 } |
752 | 819 |
753 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), | 820 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), |
754 old_file_h->e_shentsize); | 821 old_file_h->e_shentsize); |
755 | 822 |
756 /* The new bss section's size is zero, and its file offset and virtual | 823 if (n == old_bss_index |
757 address should be off by NEW_DATA2_SIZE. */ | 824 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) |
758 if (n == old_bss_index) | 825 /* The new bss and sbss section's size is zero, and its file offset |
826 and virtual address should be off by NEW_DATA2_SIZE. */ | |
827 || n == old_sbss_index | |
828 #endif /* __sony_news and _SYSTYPE_SYSV */ | |
829 ) | |
759 { | 830 { |
760 /* NN should be `old_bss_index + 1' at this point. */ | 831 /* NN should be `old_bss_index + 1' at this point. */ |
761 NEW_SECTION_H (nn).sh_offset += new_data2_size; | 832 NEW_SECTION_H (nn).sh_offset += new_data2_size; |
762 NEW_SECTION_H (nn).sh_addr += new_data2_size; | 833 NEW_SECTION_H (nn).sh_addr += new_data2_size; |
763 /* Let the new bss section address alignment be the same as the | 834 /* Let the new bss section address alignment be the same as the |
813 | 884 |
814 /* Write out the sections. .data and .data1 (and data2, called | 885 /* Write out the sections. .data and .data1 (and data2, called |
815 ".data" in the strings table) get copied from the current process | 886 ".data" in the strings table) get copied from the current process |
816 instead of the old file. */ | 887 instead of the old file. */ |
817 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") | 888 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") |
889 #ifdef _nec_ews_svr4 /* hir, 1994.6.13 */ | |
890 || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name), | |
891 ".sdata") | |
892 #endif | |
893 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
894 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
895 ".sdata") | |
896 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
897 ".lit4") | |
898 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | |
899 ".lit8") | |
900 #endif /* __sony_news && _SYSTYPE_SYSV */ | |
818 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 901 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
819 ".data1")) | 902 ".data1")) |
820 src = (caddr_t) OLD_SECTION_H (n).sh_addr; | 903 src = (caddr_t) OLD_SECTION_H (n).sh_addr; |
821 else | 904 else |
822 src = old_base + OLD_SECTION_H (n).sh_offset; | 905 src = old_base + OLD_SECTION_H (n).sh_offset; |
843 symhdr->cbRfdOffset += new_data2_size; | 926 symhdr->cbRfdOffset += new_data2_size; |
844 symhdr->cbExtOffset += new_data2_size; | 927 symhdr->cbExtOffset += new_data2_size; |
845 } | 928 } |
846 #endif /* __alpha__ */ | 929 #endif /* __alpha__ */ |
847 | 930 |
931 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) | |
932 if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG && old_mdebug_index) | |
933 { | |
934 int diff = NEW_SECTION_H(nn).sh_offset | |
935 - OLD_SECTION_H(old_mdebug_index).sh_offset; | |
936 HDRR *phdr = (HDRR *)(NEW_SECTION_H (nn).sh_offset + new_base); | |
937 | |
938 if (diff) | |
939 { | |
940 phdr->cbLineOffset += diff; | |
941 phdr->cbDnOffset += diff; | |
942 phdr->cbPdOffset += diff; | |
943 phdr->cbSymOffset += diff; | |
944 phdr->cbOptOffset += diff; | |
945 phdr->cbAuxOffset += diff; | |
946 phdr->cbSsOffset += diff; | |
947 phdr->cbSsExtOffset += diff; | |
948 phdr->cbFdOffset += diff; | |
949 phdr->cbRfdOffset += diff; | |
950 phdr->cbExtOffset += diff; | |
951 } | |
952 } | |
953 #endif /* __sony_news && _SYSTYPE_SYSV */ | |
848 /* If it is the symbol table, its st_shndx field needs to be patched. */ | 954 /* If it is the symbol table, its st_shndx field needs to be patched. */ |
849 if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB | 955 if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB |
850 || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) | 956 || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) |
851 { | 957 { |
852 ElfW(Shdr) *spt = &NEW_SECTION_H (nn); | 958 ElfW(Shdr) *spt = &NEW_SECTION_H (nn); |