comparison src/unexelf.c @ 14054:103a1b22fcd8

(unexec) [SOLARIS2]: Undo relocations performed by the runtime linker.
author Karl Heuer <kwzh@gnu.org>
date Mon, 08 Jan 1996 22:29:48 +0000
parents 16a95d5d252e
children ee40177f6c68
comparison
equal deleted inserted replaced
14053:c8c5b83d9691 14054:103a1b22fcd8
805 if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0 805 if (strcmp ((char *) (symnames + symp->st_name), "_end") == 0
806 || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0) 806 || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0)
807 memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr)); 807 memcpy (&symp->st_value, &new_bss_addr, sizeof (new_bss_addr));
808 } 808 }
809 809
810 #ifdef SOLARIS2
811 /* This loop seeks out relocation sections for the data section, so
812 that it can undo relocations performed by the runtime linker. */
813 for (n = new_file_h->e_shnum - 1; n; n--)
814 {
815 Elf32_Shdr section = NEW_SECTION_H (n);
816 switch (section.sh_type) {
817 default:
818 break;
819 case SHT_REL:
820 case SHT_RELA:
821 /* This code handles two different size structs, but there
822 should be no harm in that provided that r_offset is always
823 the first member. */
824 nn = section.sh_info;
825 if (!strcmp (old_section_names + NEW_SECTION_H (nn).sh_name, ".data")
826 || !strcmp ((old_section_names + NEW_SECTION_H (nn).sh_name),
827 ".data1"))
828 {
829 Elf32_Addr offset = NEW_SECTION_H (nn).sh_addr -
830 NEW_SECTION_H (nn).sh_offset;
831 caddr_t reloc = old_base + section.sh_offset, end;
832 for (end = reloc + section.sh_size; reloc < end;
833 reloc += section.sh_entsize)
834 {
835 Elf32_Addr addr = ((Elf32_Rel *) reloc)->r_offset - offset;
836 memcpy (new_base + addr, old_base + addr, 4);
837 }
838 }
839 break;
840 }
841 }
842 #endif
843
810 #ifdef UNEXEC_USE_MAP_PRIVATE 844 #ifdef UNEXEC_USE_MAP_PRIVATE
811 if (lseek (new_file, 0, SEEK_SET) == -1) 845 if (lseek (new_file, 0, SEEK_SET) == -1)
812 fatal ("Can't rewind (%s): errno %d\n", new_name, errno); 846 fatal ("Can't rewind (%s): errno %d\n", new_name, errno);
813 847
814 if (write (new_file, new_base, new_file_size) != new_file_size) 848 if (write (new_file, new_base, new_file_size) != new_file_size)