comparison src/unexelfsgi.c @ 278:90d73dddcdc4 r21-0b37

Import from CVS: tag r21-0b37
author cvs
date Mon, 13 Aug 2007 10:31:29 +0200
parents ca9a9ec9c1c1
children e11d67e05968
comparison
equal deleted inserted replaced
277:cfdf3ff11843 278:90d73dddcdc4
582 if (idx == old_file_h->e_shnum) 582 if (idx == old_file_h->e_shnum)
583 { 583 {
584 if (noerror) 584 if (noerror)
585 return -1; 585 return -1;
586 else 586 else
587 fatal ("Can't find .bss in %s.\n", file_name, 0); 587 fatal ("Can't find .bss in %s.\n", file_name);
588 } 588 }
589 589
590 return idx; 590 return idx;
591 } 591 }
592 592
624 l_Elf_Word old_bss_size, new_data2_size; 624 l_Elf_Word old_bss_size, new_data2_size;
625 l_Elf_Off new_data2_offset, new_base_offset; 625 l_Elf_Off new_data2_offset, new_base_offset;
626 l_Elf_Addr new_data2_addr; 626 l_Elf_Addr new_data2_addr;
627 l_Elf_Addr new_offsets_shift; 627 l_Elf_Addr new_offsets_shift;
628 628
629 int n, nn, old_bss_index, old_data_index, new_data2_index; 629 int n, nn, old_bss_index, old_data_index;
630 int old_mdebug_index, old_sbss_index; 630 int old_mdebug_index, old_sbss_index;
631 struct stat stat_buf; 631 struct stat stat_buf;
632 632
633 /* Open the old file & map it into the address space. */ 633 /* Open the old file & map it into the address space. */
634 634
711 fprintf (stderr, "new_data2_offset %x\n", new_data2_offset); 711 fprintf (stderr, "new_data2_offset %x\n", new_data2_offset);
712 fprintf (stderr, "new_offsets_shift %x\n", new_offsets_shift); 712 fprintf (stderr, "new_offsets_shift %x\n", new_offsets_shift);
713 #endif 713 #endif
714 714
715 if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size) 715 if ((unsigned) new_bss_addr < (unsigned) old_bss_addr + old_bss_size)
716 fatal (".bss shrank when undumping???\n", 0, 0); 716 fatal (".bss shrank when undumping???\n");
717 717
718 /* Set the output file to the right size and mmap it. Set 718 /* Set the output file to the right size and mmap it. Set
719 pointers to various interesting objects. stat_buf still has 719 pointers to various interesting objects. stat_buf still has
720 old_file data. */ 720 old_file data. */
721 721
755 /* Fix up file header. We'll add one section. Section header is 755 /* Fix up file header. We'll add one section. Section header is
756 further away now. */ 756 further away now. */
757 757
758 new_file_h->e_shoff += new_offsets_shift; 758 new_file_h->e_shoff += new_offsets_shift;
759 new_file_h->e_shnum += 1; 759 new_file_h->e_shnum += 1;
760
760 761
761 #ifdef DEBUG 762 #ifdef DEBUG
762 fprintf (stderr, "Old section offset %x\n", old_file_h->e_shoff); 763 fprintf (stderr, "Old section offset %x\n", old_file_h->e_shoff);
763 fprintf (stderr, "Old section count %d\n", old_file_h->e_shnum); 764 fprintf (stderr, "Old section count %d\n", old_file_h->e_shnum);
764 fprintf (stderr, "New section offset %x\n", new_file_h->e_shoff); 765 fprintf (stderr, "New section offset %x\n", new_file_h->e_shoff);
780 alignment = OLD_SECTION_H (old_bss_index).sh_addralign; 781 alignment = OLD_SECTION_H (old_bss_index).sh_addralign;
781 782
782 /* Supposedly this condition is okay for the SGI. */ 783 /* Supposedly this condition is okay for the SGI. */
783 #if 0 784 #if 0
784 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_base_addr) 785 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_base_addr)
785 fatal ("Program segment above .bss in %s\n", old_name, 0); 786 fatal ("Program segment above .bss in %s\n", old_name);
786 #endif 787 #endif
787 788
788 if (NEW_PROGRAM_H (n).p_type == PT_LOAD 789 if (NEW_PROGRAM_H (n).p_type == PT_LOAD
789 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr 790 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr
790 + (NEW_PROGRAM_H (n)).p_filesz, 791 + (NEW_PROGRAM_H (n)).p_filesz,
792 == round_up (old_base_addr, alignment))) 793 == round_up (old_base_addr, alignment)))
793 break; 794 break;
794 } 795 }
795 if (n < 0) 796 if (n < 0)
796 fatal ("Couldn't find segment next to %s in %s\n", 797 fatal ("Couldn't find segment next to %s in %s\n",
797 old_sbss_index == -1 ? ".sbss" : ".bss", old_name, 0); 798 old_sbss_index == -1 ? ".sbss" : ".bss", old_name);
798 799
799 NEW_PROGRAM_H (n).p_filesz += new_offsets_shift; 800 NEW_PROGRAM_H (n).p_filesz += new_offsets_shift;
800 NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz; 801 NEW_PROGRAM_H (n).p_memsz = NEW_PROGRAM_H (n).p_filesz;
801 802
802 #if 1 /* Maybe allow section after data2 - does this ever happen? */ 803 #if 1 /* Maybe allow section after data2 - does this ever happen? */
820 old_data_index++) 821 old_data_index++)
821 if (!strcmp (old_section_names + OLD_SECTION_H (old_data_index).sh_name, 822 if (!strcmp (old_section_names + OLD_SECTION_H (old_data_index).sh_name,
822 ".data")) 823 ".data"))
823 break; 824 break;
824 if (old_data_index == old_file_h->e_shnum) 825 if (old_data_index == old_file_h->e_shnum)
825 fatal ("Can't find .data in %s.\n", old_name, 0); 826 fatal ("Can't find .data in %s.\n", old_name);
826 827
827 /* Walk through all section headers, insert the new data2 section right 828 /* Walk through all section headers, insert the new data2 section right
828 before the new bss section. */ 829 before the new bss section. */
829 for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++) 830 for (n = 1, nn = 1; n < old_file_h->e_shnum; n++, nn++)
830 { 831 {
891 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB 892 if (NEW_SECTION_H (nn).sh_type != SHT_SYMTAB
892 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM) 893 && NEW_SECTION_H (nn).sh_type != SHT_DYNSYM)
893 PATCH_INDEX (NEW_SECTION_H (nn).sh_info); 894 PATCH_INDEX (NEW_SECTION_H (nn).sh_info);
894 895
895 /* Fix the type and alignment for the .sbss section */ 896 /* Fix the type and alignment for the .sbss section */
896 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".sbss")) 897 if ((old_sbss_index != -1) && !strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".sbss"))
897 { 898 {
898 NEW_SECTION_H (nn).sh_type = SHT_PROGBITS; 899 NEW_SECTION_H (nn).sh_type = SHT_PROGBITS;
899 NEW_SECTION_H (nn).sh_offset = round_up (NEW_SECTION_H (nn).sh_offset, 900 NEW_SECTION_H (nn).sh_offset = round_up (NEW_SECTION_H (nn).sh_offset,
900 NEW_SECTION_H (nn).sh_addralign); 901 NEW_SECTION_H (nn).sh_addralign);
901 } 902 }
990 PATCH_INDEX (sym->st_shndx); 991 PATCH_INDEX (sym->st_shndx);
991 } 992 }
992 } 993 }
993 } 994 }
994 995
996 /* Kludge around the stupid 5.3 run time loader which always
997 zero-fills the .sbss section no matter what. */
998
999 if (old_sbss_index != -1)
1000 strcpy (new_base
1001 + NEW_SECTION_H (new_file_h->e_shstrndx).sh_offset
1002 + NEW_SECTION_H (old_sbss_index).sh_name,
1003 ".zbzz");
1004
995 /* Close the files and make the new file executable. */ 1005 /* Close the files and make the new file executable. */
996 1006
997 if (close (old_file)) 1007 if (close (old_file))
998 fatal ("Can't close (%s): errno %d\n", old_name, errno); 1008 fatal ("Can't close (%s): errno %d\n", old_name, errno);
999 1009