comparison src/unexelf.c @ 24290:8f4f410490af

(HAS_SBSS_SECTION): Define this in some cases. (unexec): Test this instead of specific systems.
author Richard M. Stallman <rms@gnu.org>
date Wed, 10 Feb 1999 03:02:01 +0000
parents 0f032f45a525
children f0d69d0f8222
comparison
equal deleted inserted replaced
24289:7917ac967ee5 24290:8f4f410490af
425 #endif 425 #endif
426 #include <sys/mman.h> 426 #include <sys/mman.h>
427 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) 427 #if defined (__sony_news) && defined (_SYSTYPE_SYSV)
428 #include <sys/elf_mips.h> 428 #include <sys/elf_mips.h>
429 #include <sym.h> 429 #include <sym.h>
430 #define HAS_SBSS_SECTION
430 #endif /* __sony_news && _SYSTYPE_SYSV */ 431 #endif /* __sony_news && _SYSTYPE_SYSV */
432
433 #if defined (__NetBSD__) && defined (__powerpc__)
434 #define HAS_SBSS_SECTION
435 #endif
431 436
432 #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__) 437 #if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
433 /* Declare COFF debugging symbol table. This used to be in 438 /* Declare COFF debugging symbol table. This used to be in
434 /usr/include/sym.h, but this file is no longer included in Red Hat 439 /usr/include/sym.h, but this file is no longer included in Red Hat
435 5.0 and presumably in any other glibc 2.x based distribution. */ 440 5.0 and presumably in any other glibc 2.x based distribution. */
618 ElfW(Word) old_bss_size, new_data2_size; 623 ElfW(Word) old_bss_size, new_data2_size;
619 ElfW(Off) new_data2_offset; 624 ElfW(Off) new_data2_offset;
620 ElfW(Addr) new_data2_addr; 625 ElfW(Addr) new_data2_addr;
621 626
622 int n, nn, old_bss_index, old_data_index, new_data2_index; 627 int n, nn, old_bss_index, old_data_index, new_data2_index;
623 #if defined ( __sony_news) && defined (_SYSTYPE_SYSV) 628 #if defined (HAS_SBSS_SECTION)
624 int old_sbss_index, old_mdebug_index; 629 int old_sbss_index, old_mdebug_index;
625 #endif /* __sony_news && _SYSTYPE_SYSV */ 630 #endif /* HAS_SBSS_SECTION */
626 struct stat stat_buf; 631 struct stat stat_buf;
627 632
628 /* Open the old file & map it into the address space. */ 633 /* Open the old file & map it into the address space. */
629 634
630 old_file = open (old_name, O_RDONLY); 635 old_file = open (old_name, O_RDONLY);
670 break; 675 break;
671 } 676 }
672 if (old_bss_index == old_file_h->e_shnum) 677 if (old_bss_index == old_file_h->e_shnum)
673 fatal ("Can't find .bss in %s.\n", old_name, 0); 678 fatal ("Can't find .bss in %s.\n", old_name, 0);
674 679
675 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) 680 #if defined (HAS_SBSS_SECTION)
676 for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum; 681 for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum;
677 old_sbss_index++) 682 old_sbss_index++)
678 { 683 {
679 #ifdef DEBUG 684 #ifdef DEBUG
680 fprintf (stderr, "Looking for .sbss - found %s\n", 685 fprintf (stderr, "Looking for .sbss - found %s\n",
711 ".mdebug")) 716 ".mdebug"))
712 break; 717 break;
713 } 718 }
714 if (old_mdebug_index == old_file_h->e_shnum) 719 if (old_mdebug_index == old_file_h->e_shnum)
715 old_mdebug_index = 0; 720 old_mdebug_index = 0;
716 #else /* not (__sony_news && _SYSTYPE_SYSV) */ 721 #else /* not HAS_SBSS_SECTION */
717 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr; 722 old_bss_addr = OLD_SECTION_H (old_bss_index).sh_addr;
718 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size; 723 old_bss_size = OLD_SECTION_H (old_bss_index).sh_size;
719 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ 724 #endif /* not HAS_SBSS_SECTION */
720 #if defined (emacs) || !defined (DEBUG) 725 #if defined (emacs) || !defined (DEBUG)
721 new_bss_addr = (ElfW(Addr)) sbrk (0); 726 new_bss_addr = (ElfW(Addr)) sbrk (0);
722 #else 727 #else
723 new_bss_addr = old_bss_addr + old_bss_size + 0x1234; 728 new_bss_addr = old_bss_addr + old_bss_size + 0x1234;
724 #endif 729 #endif
725 new_data2_addr = old_bss_addr; 730 new_data2_addr = old_bss_addr;
726 new_data2_size = new_bss_addr - old_bss_addr; 731 new_data2_size = new_bss_addr - old_bss_addr;
727 #if !defined (__sony_news) || !defined (_SYSTYPE_SYSV) 732 #if !defined (HAS_SBSS_SECTION)
728 new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset; 733 new_data2_offset = OLD_SECTION_H (old_bss_index).sh_offset;
729 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ 734 #endif /* not HAS_SBSS_SECTION */
730 735
731 #ifdef DEBUG 736 #ifdef DEBUG
732 fprintf (stderr, "old_bss_index %d\n", old_bss_index); 737 fprintf (stderr, "old_bss_index %d\n", old_bss_index);
733 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr); 738 fprintf (stderr, "old_bss_addr %x\n", old_bss_addr);
734 fprintf (stderr, "old_bss_size %x\n", old_bss_size); 739 fprintf (stderr, "old_bss_size %x\n", old_bss_size);
809 /* Compute maximum of all requirements for alignment of section. */ 814 /* Compute maximum of all requirements for alignment of section. */
810 int alignment = (NEW_PROGRAM_H (n)).p_align; 815 int alignment = (NEW_PROGRAM_H (n)).p_align;
811 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment) 816 if ((OLD_SECTION_H (old_bss_index)).sh_addralign > alignment)
812 alignment = OLD_SECTION_H (old_bss_index).sh_addralign; 817 alignment = OLD_SECTION_H (old_bss_index).sh_addralign;
813 818
814 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) 819 #if defined (HAS_SBSS_SECTION)
815 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz 820 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz
816 > round_up (old_bss_addr, alignment)) 821 > round_up (old_bss_addr, alignment))
817 fatal ("Program segment above .bss in %s\n", old_name, 0); 822 fatal ("Program segment above .bss in %s\n", old_name, 0);
818 #else /* not (__sony_news && _SYSTYPE_SYSV) */ 823 #else /* not HAS_SBSS_SECTION */
819 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr) 824 if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz > old_bss_addr)
820 fatal ("Program segment above .bss in %s\n", old_name, 0); 825 fatal ("Program segment above .bss in %s\n", old_name, 0);
821 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ 826 #endif /* not HAS_SBSS_SECTION */
822 827
823 if (NEW_PROGRAM_H (n).p_type == PT_LOAD 828 if (NEW_PROGRAM_H (n).p_type == PT_LOAD
824 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr 829 && (round_up ((NEW_PROGRAM_H (n)).p_vaddr
825 + (NEW_PROGRAM_H (n)).p_filesz, 830 + (NEW_PROGRAM_H (n)).p_filesz,
826 alignment) 831 alignment)
865 before the new bss section. */ 870 before the new bss section. */
866 for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++) 871 for (n = 1, nn = 1; n < (int) old_file_h->e_shnum; n++, nn++)
867 { 872 {
868 caddr_t src; 873 caddr_t src;
869 int temp_index; 874 int temp_index;
870 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) 875 #if defined (HAS_SBSS_SECTION)
871 /* If it is (s)bss section, insert the new data2 section before it. */ 876 /* If it is (s)bss section, insert the new data2 section before it. */
872 /* new_data2_index is the index of either old_sbss or old_bss, that was 877 /* new_data2_index is the index of either old_sbss or old_bss, that was
873 chosen as a section for new_data2. */ 878 chosen as a section for new_data2. */
874 temp_index = new_data2_index; 879 temp_index = new_data2_index;
875 #else /* not (__sony_news && _SYSTYPE_SYSV) */ 880 #else /* not HAS_SBSS_SECTION */
876 /* If it is bss section, insert the new data2 section before it. */ 881 /* If it is bss section, insert the new data2 section before it. */
877 temp_index = old_bss_index; 882 temp_index = old_bss_index;
878 #endif /* not (__sony_news && _SYSTYPE_SYSV) */ 883 #endif /* not HAS_SBSS_SECTION */
879 if (n == temp_index) 884 if (n == temp_index)
880 { 885 {
881 /* Steal the data section header for this data2 section. */ 886 /* Steal the data section header for this data2 section. */
882 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index), 887 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (old_data_index),
883 new_file_h->e_shentsize); 888 new_file_h->e_shentsize);
899 904
900 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n), 905 memcpy (&NEW_SECTION_H (nn), &OLD_SECTION_H (n),
901 old_file_h->e_shentsize); 906 old_file_h->e_shentsize);
902 907
903 if (n == old_bss_index 908 if (n == old_bss_index
904 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) 909 #if defined (HAS_SBSS_SECTION)
905 /* The new bss and sbss section's size is zero, and its file offset 910 /* The new bss and sbss section's size is zero, and its file offset
906 and virtual address should be off by NEW_DATA2_SIZE. */ 911 and virtual address should be off by NEW_DATA2_SIZE. */
907 || n == old_sbss_index 912 || n == old_sbss_index
908 #endif /* __sony_news and _SYSTYPE_SYSV */ 913 #endif /* HAS_SBSS_SECTION */
909 ) 914 )
910 { 915 {
911 /* NN should be `old_bss_index + 1' at this point. */ 916 /* NN should be `old_bss_index + 1' at this point. */
912 NEW_SECTION_H (nn).sh_offset += new_data2_size; 917 NEW_SECTION_H (nn).sh_offset += new_data2_size;
913 NEW_SECTION_H (nn).sh_addr += new_data2_size; 918 NEW_SECTION_H (nn).sh_addr += new_data2_size;
968 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data") 973 if (!strcmp (old_section_names + NEW_SECTION_H (n).sh_name, ".data")
969 #ifdef _nec_ews_svr4 /* hir, 1994.6.13 */ 974 #ifdef _nec_ews_svr4 /* hir, 1994.6.13 */
970 || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name), 975 || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name),
971 ".sdata") 976 ".sdata")
972 #endif 977 #endif
973 #if defined (__sony_news) && defined (_SYSTYPE_SYSV) 978 #if defined (HAS_SBSS_SECTION)
974 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), 979 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
975 ".sdata") 980 ".sdata")
976 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), 981 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
977 ".lit4") 982 ".lit4")
978 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), 983 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
979 ".lit8") 984 ".lit8")
980 #endif /* __sony_news && _SYSTYPE_SYSV */ 985 #endif /* HAS_SBSS_SECTION */
981 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name), 986 || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
982 ".data1")) 987 ".data1"))
983 src = (caddr_t) OLD_SECTION_H (n).sh_addr; 988 src = (caddr_t) OLD_SECTION_H (n).sh_addr;
984 else 989 else
985 src = old_base + OLD_SECTION_H (n).sh_offset; 990 src = old_base + OLD_SECTION_H (n).sh_offset;