Mercurial > hg > xemacs-beta
comparison src/unexelfsgi.c @ 167:85ec50267440 r20-3b10
Import from CVS: tag r20-3b10
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:45:46 +0200 |
parents | 5a88923fcbfe |
children | 157b30c96d03 |
comparison
equal
deleted
inserted
replaced
166:7a77eb660975 | 167:85ec50267440 |
---|---|
624 | 624 |
625 /* Point to the section name table in the old file. */ | 625 /* Point to the section name table in the old file. */ |
626 char *old_section_names; | 626 char *old_section_names; |
627 | 627 |
628 l_Elf_Addr old_bss_addr, new_bss_addr; | 628 l_Elf_Addr old_bss_addr, new_bss_addr; |
629 l_Elf_Addr old_base_addr; | |
629 l_Elf_Word old_bss_size, new_data2_size; | 630 l_Elf_Word old_bss_size, new_data2_size; |
630 l_Elf_Off new_data2_offset; | 631 l_Elf_Off new_data2_offset, new_base_offset; |
631 l_Elf_Addr new_data2_addr; | 632 l_Elf_Addr new_data2_addr; |
632 l_Elf_Addr new_offsets_shift; | 633 l_Elf_Addr new_offsets_shift; |
633 | 634 |
634 int n, nn, old_bss_index, old_data_index, new_data2_index; | 635 int n, nn, old_bss_index, old_data_index, new_data2_index; |
635 int old_mdebug_index; | 636 int old_mdebug_index, old_sbss_index; |
636 struct stat stat_buf; | 637 struct stat stat_buf; |
637 | 638 |
638 /* Open the old file & map it into the address space. */ | 639 /* Open the old file & map it into the address space. */ |
639 | 640 |
640 old_file = open (old_name, O_RDONLY); | 641 old_file = open (old_name, O_RDONLY); |
666 /* Find the mdebug section, if any. */ | 667 /* Find the mdebug section, if any. */ |
667 | 668 |
668 old_mdebug_index = find_section (".mdebug", old_section_names, | 669 old_mdebug_index = find_section (".mdebug", old_section_names, |
669 old_name, old_file_h, old_section_h, 1); | 670 old_name, old_file_h, old_section_h, 1); |
670 | 671 |
672 /* Find the .sbss section, if any. */ | |
673 | |
674 old_sbss_index = find_section (".sbss", old_section_names, | |
675 old_name, old_file_h, old_section_h, 1); | |
676 | |
671 /* Find the old .bss section. */ | 677 /* Find the old .bss section. */ |
672 | 678 |
673 old_bss_index = find_section (".bss", old_section_names, | 679 old_bss_index = find_section (".bss", old_section_names, |
674 old_name, old_file_h, old_section_h, 0); | 680 old_name, old_file_h, old_section_h, 0); |
675 | 681 |
679 old_data_index = find_section (".data", old_section_names, | 685 old_data_index = find_section (".data", old_section_names, |
680 old_name, old_file_h, old_section_h, 0); | 686 old_name, old_file_h, old_section_h, 0); |
681 | 687 |
682 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; | 688 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; |
683 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; | 689 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; |
690 old_base_addr = old_sbss_index == -1 ? old_bss_addr : OLD_SECTION_H (old_sbss_index).sh_addr; | |
684 #if defined(emacs) || !defined(DEBUG) | 691 #if defined(emacs) || !defined(DEBUG) |
685 bss_end = (uintptr_t) sbrk (0); | 692 bss_end = (uintptr_t) sbrk (0); |
686 new_bss_addr = (l_Elf_Addr) bss_end; | 693 new_bss_addr = (l_Elf_Addr) bss_end; |
687 #else | 694 #else |
688 new_bss_addr = old_bss_addr + old_bss_size + 0x1234; | 695 new_bss_addr = old_bss_addr + old_bss_size + 0x1234; |
689 #endif | 696 #endif |
690 new_data2_addr = old_bss_addr; | 697 new_data2_addr = old_bss_addr; |
691 new_data2_size = new_bss_addr - old_bss_addr; | 698 new_data2_size = new_bss_addr - old_bss_addr; |
692 new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset + | 699 new_data2_offset = OLD_SECTION_H (old_data_index).sh_offset + |
693 (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr); | 700 (new_data2_addr - OLD_SECTION_H (old_data_index).sh_addr); |
701 new_base_offset = OLD_SECTION_H (old_data_index).sh_offset + | |
702 (old_base_addr - OLD_SECTION_H (old_data_index).sh_addr); | |
694 new_offsets_shift = new_bss_addr - | 703 new_offsets_shift = new_bss_addr - |
695 ((old_bss_addr & ~0xfff) + ((old_bss_addr & 0xfff) ? 0x1000 : 0)); | 704 ((old_base_addr & ~0xfff) + ((old_base_addr & 0xfff) ? 0x1000 : 0)); |
696 | 705 |
697 #ifdef DEBUG | 706 #ifdef DEBUG |
698 fprintf (stderr, "old_bss_index %d\n", old_bss_index); | 707 fprintf (stderr, "old_bss_index %d\n", old_bss_index); |
699 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr); | 708 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr); |
700 fprintf (stderr, "old_bss_size %x\n", old_bss_size); | 709 fprintf (stderr, "old_bss_size %x\n", old_bss_size); |
710 fprintf (stderr, "old_base_addr %x\n", old_base_addr); | |
701 fprintf (stderr, "new_bss_addr %x\n", new_bss_addr); | 711 fprintf (stderr, "new_bss_addr %x\n", new_bss_addr); |
702 fprintf (stderr, "new_data2_addr %x\n", new_data2_addr); | 712 fprintf (stderr, "new_data2_addr %x\n", new_data2_addr); |
703 fprintf (stderr, "new_data2_size %x\n", new_data2_size); | 713 fprintf (stderr, "new_data2_size %x\n", new_data2_size); |
704 fprintf (stderr, "new_data2_offset %x\n", new_data2_offset); | 714 fprintf (stderr, "new_data2_offset %x\n", new_data2_offset); |
705 fprintf (stderr, "new_offsets_shift %x\n", new_offsets_shift); | 715 fprintf (stderr, "new_offsets_shift %x\n", new_offsets_shift); |
772 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) | 782 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) |
773 alignment = OLD_SECTION_H (old_bss_index).sh_addralign; | 783 alignment = OLD_SECTION_H (old_bss_index).sh_addralign; |
774 | 784 |
775 /* Supposedly this condition is okay for the SGI. */ | 785 /* Supposedly this condition is okay for the SGI. */ |
776 #if 0 | 786 #if 0 |
777 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr) | 787 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_base_addr) |
778 fatal ("Program segment above .bss in %s\n", old_name, 0); | 788 fatal ("Program segment above .bss in %s\n", old_name, 0); |
779 #endif | 789 #endif |
780 | 790 |
781 if (NEW_PROGRAM_H (n).p_type == PT_LOAD | 791 if (NEW_PROGRAM_H (n).p_type == PT_LOAD |
782 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr | 792 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr |
783 + (NEW_PROGRAM_H (n)).p_filesz, | 793 + (NEW_PROGRAM_H (n)).p_filesz, |
784 alignment) | 794 alignment) |
785 == round_up (old_bss_addr, alignment))) | 795 == round_up (old_base_addr, alignment))) |
786 break; | 796 break; |
787 } | 797 } |
788 if (n < 0) | 798 if (n < 0) |
789 fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0); | 799 fatal ("Couldn't find segment next to %s in %s\n", |
800 old_sbss_index == -1 ? ".sbss" : ".bss", old_name, 0); | |
790 | 801 |
791 NEW_PROGRAM_H (n).p_filesz += new_offsets_shift; | 802 NEW_PROGRAM_H (n).p_filesz += new_offsets_shift; |
792 NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz; | 803 NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz; |
793 | 804 |
794 #if 1 /* Maybe allow section after data2 - does this ever happen? */ | 805 #if 1 /* Maybe allow section after data2 - does this ever happen? */ |
868 old_file_h->e_shentsize); | 879 old_file_h->e_shentsize); |
869 | 880 |
870 /* Any section that was original placed AFTER the bss | 881 /* Any section that was original placed AFTER the bss |
871 section must now be adjusted by NEW_OFFSETS_SHIFT. */ | 882 section must now be adjusted by NEW_OFFSETS_SHIFT. */ |
872 | 883 |
873 if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset) | 884 if (NEW_SECTION_H (nn).sh_offset >= new_base_offset) |
874 NEW_SECTION_H (nn).sh_offset += new_offsets_shift; | 885 NEW_SECTION_H (nn).sh_offset += new_offsets_shift; |
875 | 886 |
876 /* If any section hdr refers to the section after the new .data | 887 /* If any section hdr refers to the section after the new .data |
877 section, make it refer to next one because we have inserted | 888 section, make it refer to next one because we have inserted |
878 a new section in between. */ | 889 a new section in between. */ |
895 /* Now, start to copy the content of sections. */ | 906 /* Now, start to copy the content of sections. */ |
896 if (NEW_SECTION_H (nn).sh_type == SHT_NULL | 907 if (NEW_SECTION_H (nn).sh_type == SHT_NULL |
897 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) | 908 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) |
898 continue; | 909 continue; |
899 | 910 |
900 /* Write out the sections. .data, .data1 nad .sbss (and data2, called | 911 /* Write out the sections. .data, .data1 and .sbss (and data2, called |
901 ".data" in the strings table) get copied from the current process | 912 ".data" in the strings table) get copied from the current process |
902 instead of the old file. */ | 913 instead of the old file. */ |
903 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") | 914 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") |
904 || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data1") | 915 || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data1") |
905 || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".got") | 916 || !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".got") |