Mercurial > emacs
comparison src/unexelf.c @ 8595:099f80df77bf
(unexec): Don't alter the info field of SHT_SYMTAB and SHT_DYNSYM sections.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 23 Aug 1994 21:35:23 +0000 |
parents | dd787a5353d1 |
children | 401b9dbedc4e |
comparison
equal
deleted
inserted
replaced
8594:4d8d02befd11 | 8595:099f80df77bf |
---|---|
723 else if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset) | 723 else if (NEW_SECTION_H (nn).sh_offset >= new_data2_offset) |
724 NEW_SECTION_H (nn).sh_offset += new_data2_size; | 724 NEW_SECTION_H (nn).sh_offset += new_data2_size; |
725 | 725 |
726 /* If any section hdr refers to the section after the new .data | 726 /* If any section hdr refers to the section after the new .data |
727 section, make it refer to next one because we have inserted | 727 section, make it refer to next one because we have inserted |
728 a new section in between. */ | 728 a new section in between. */ |
729 | 729 |
730 PATCH_INDEX (NEW_SECTION_H (nn).sh_link); | 730 PATCH_INDEX (NEW_SECTION_H (nn).sh_link); |
731 PATCH_INDEX (NEW_SECTION_H (nn).sh_info); | 731 /* For symbol tables, info is a symbol table index, |
732 | 732 so don't change it. */ |
733 /* Now, start to copy the content of sections. */ | 733 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB |
734 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) | |
735 PATCH_INDEX (NEW_SECTION_H (nn).sh_info); | |
736 | |
737 /* Now, start to copy the content of sections. */ | |
734 if (NEW_SECTION_H (nn).sh_type == SHT_NULL | 738 if (NEW_SECTION_H (nn).sh_type == SHT_NULL |
735 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) | 739 || NEW_SECTION_H (nn).sh_type == SHT_NOBITS) |
736 continue; | 740 continue; |
737 | 741 |
738 /* Write out the sections. .data and .data1 (and data2, called | 742 /* Write out the sections. .data and .data1 (and data2, called |
739 * ".data" in the strings table) get copied from the current process | 743 ".data" in the strings table) get copied from the current process |
740 * instead of the old file. | 744 instead of the old file. */ |
741 */ | |
742 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") | 745 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") |
743 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), | 746 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), |
744 ".data1")) | 747 ".data1")) |
745 src = (caddr_t) OLD_SECTION_H (n).sh_addr; | 748 src = (caddr_t) OLD_SECTION_H (n).sh_addr; |
746 else | 749 else |
747 src = old_base + OLD_SECTION_H (n).sh_offset; | 750 src = old_base + OLD_SECTION_H (n).sh_offset; |
748 | 751 |
749 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, | 752 memcpy (NEW_SECTION_H (nn).sh_offset + new_base, src, |
750 NEW_SECTION_H (nn).sh_size); | 753 NEW_SECTION_H (nn).sh_size); |
751 | 754 |
752 /* If it is the symbol table, its st_shndx field needs to be patched. */ | 755 /* If it is the symbol table, its st_shndx field needs to be patched. */ |
753 if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB | 756 if (NEW_SECTION_H (nn).sh_type == SHT_SYMTAB |
754 || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) | 757 || NEW_SECTION_H (nn).sh_type == SHT_DYNSYM) |
755 { | 758 { |
756 Elf32_Shdr *spt = &NEW_SECTION_H (nn); | 759 Elf32_Shdr *spt = &NEW_SECTION_H (nn); |
757 unsigned int num = spt->sh_size / spt->sh_entsize; | 760 unsigned int num = spt->sh_size / spt->sh_entsize; |
767 PATCH_INDEX (sym->st_shndx); | 770 PATCH_INDEX (sym->st_shndx); |
768 } | 771 } |
769 } | 772 } |
770 } | 773 } |
771 | 774 |
772 /* Update the symbol values of _edata and _end. */ | 775 /* Update the symbol values of _edata and _end. */ |
773 for (n = new_file_h->e_shnum - 1; n; n--) | 776 for (n = new_file_h->e_shnum - 1; n; n--) |
774 { | 777 { |
775 byte *symnames; | 778 byte *symnames; |
776 Elf32_Sym *symp, *symendp; | 779 Elf32_Sym *symp, *symendp; |
777 | 780 |
787 if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0 | 790 if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0 |
788 || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0) | 791 || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0) |
789 memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); | 792 memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); |
790 } | 793 } |
791 | 794 |
792 /* Close the files and make the new file executable */ | 795 /* Close the files and make the new file executable. */ |
793 | 796 |
794 if (close (old_file)) | 797 if (close (old_file)) |
795 fatal ("Can't close (%s): errno %d\n", old_name, errno); | 798 fatal ("Can't close (%s): errno %d\n", old_name, errno); |
796 | 799 |
797 if (close (new_file)) | 800 if (close (new_file)) |