View | Details | Raw Unified | Return to bug 8090
Collapse All | Expand All

(-)src/s/freebsd.h (-2 / +31 lines)
Lines 1-5 Link Here
1
/* Get the correct __FreeBSD_version, even if this is before that was
2
   defined. */
3
#ifndef __FreeBSD__
4
#define __FreeBSD_version 199401
5
#elif __FreeBSD__ == 1
6
#define __FreeBSD_version 199405
7
#else
8
#include <osreldate.h>
9
#endif
10
Lines 34-40 Link Here
34
#define LIB_GCC -lgcc
Lines 42-53 Link Here
42
#define UNEXEC unexsunos4.o
51
#ifdef __ELF__
52
53
#define LD_SWITCH_SYSTEM
54
#define START_FILES pre-crt0.o /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/crtbegin.o
55
#define UNEXEC unexelf.o
56
#define LIB_STANDARD -lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
57
#undef LIB_GCC
58
#define LIB_GCC
59
60
#else /* not __ELF__ */
61
62
#if __FreeBSD_version >= 300002
63
#define START_FILES pre-crt0.o /usr/lib/aout/crt0.o
64
#else /* __FreeBSD_version < 300002 */
65
#endif /* __FreeBSD_version < 300002 */
66
#define UNEXEC unexfreebsd.o
67
#define LIB_GCC -lgcc
Lines 63-68 Link Here
88
#endif /* not __ELF__ */
89
Lines 80-85 Link Here
107
#elif __FreeBSD__ == 3
108
#define BSD 199506
80
 $shar_touch -am 0930013598 'patch-ac' &&
109
 $shar_touch -am 0930013598 'patch-ac' &&
81
 chmod 0644 'patch-ac' ||
110
 chmod 0644 'patch-ac' ||
82
 $echo 'restore of' 'patch-ac' 'failed'
111
 $echo 'restore of' 'patch-ac' 'failed'
83
 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
112
 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
84
 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
113
 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
85
   md5sum -c << SHAR_EOF >/dev/null 2>&1 \
114
   md5sum -c << SHAR_EOF >/dev/null 2>&1 \
86
   || $echo 'patch-ac:' 'MD5 check failed'
115
   || $echo 'patch-ac:' 'MD5 check failed'
87
 else
116
 else
88
   shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'patch-ac'`"
117
   shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'patch-ac'`"
89
   test 1973 -eq "$shar_count" ||
118
   test 1973 -eq "$shar_count" ||
90
   $echo 'patch-ac:' 'original size' '1973,' 'current size' "$shar_count!"
119
   $echo 'patch-ac:' 'original size' '1973,' 'current size' "$shar_count!"
91
 fi
120
 fi
92
 $echo 'x -' SKIPPING 'patch-ae' '(file already exists)'
121
 $echo 'x -' SKIPPING 'patch-ae' '(file already exists)'
93
 $echo 'x -' extracting 'patch-ae' '(text)'
122
 $echo 'x -' extracting 'patch-ae' '(text)'
94
 sed 's/^X//' << 'SHAR_EOF' > 'patch-ae' &&
123
 sed 's/^X//' << 'SHAR_EOF' > 'patch-ae' &&
(-)src/unexelf.c (-47 / +279 lines)
Lines 33-46 Link Here
33
 *	unexec (new_name, a_name, data_start, bss_start, entry_address)
33
 *	unexec (new_name, old_name, data_start, bss_start, entry_address)
34
 *	char *new_name, *a_name;
34
 *	char *new_name, *old_name;
35
 * If a_name is non-NULL, the symbol table will be taken from the given file.
35
 * If old_name is non-NULL, the symbol table will be taken from the given file.
36
 * On some machines, an existing a_name file is required.
36
 * On some machines, an existing old_name file is required.
Lines 420-427 Link Here
420
#if !defined (__NetBSD__) && !defined (__OpenBSD__)
421
#endif
422
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
423
#include <sys/elf_mips.h>
424
#include <sym.h>
425
#endif /* __sony_news && _SYSTYPE_SYSV */
426
427
#if defined (__alpha__) && !defined (__NetBSD__) && !defined (__OpenBSD__)
428
/* Declare COFF debugging symbol table.  This used to be in
429
   /usr/include/sym.h, but this file is no longer included in Red Hat
430
   5.0 and presumably in any other glibc 2.x based distribution.  */
431
typedef struct {
432
	short magic;
433
	short vstamp;
434
	int ilineMax;
435
	int idnMax;
436
	int ipdMax;
437
	int isymMax;
438
	int ioptMax;
439
	int iauxMax;
440
	int issMax;
441
	int issExtMax;
442
	int ifdMax;
443
	int crfd;
444
	int iextMax;
445
	long cbLine;
446
	long cbLineOffset;
447
	long cbDnOffset;
448
	long cbPdOffset;
449
	long cbSymOffset;
450
	long cbOptOffset;
451
	long cbAuxOffset;
452
	long cbSsOffset;
453
	long cbSsExtOffset;
454
	long cbFdOffset;
455
	long cbRfdOffset;
456
	long cbExtOffset;
457
} HDRR, *pHDRR; 
458
#define cbHDRR sizeof(HDRR)
459
#define hdrNil ((pHDRR)0)
460
#endif
461
462
#ifdef __NetBSD__
463
/*
464
 * NetBSD does not have normal-looking user-land ELF support.
465
 */
466
# ifdef __alpha__
467
#  define ELFSIZE	64
468
# else
469
#  define ELFSIZE	32
470
# endif
471
# include <sys/exec_elf.h>
472
473
# define PT_LOAD	Elf_pt_load
474
# define SHT_SYMTAB	Elf_sht_symtab
475
# define SHT_DYNSYM	Elf_sht_dynsym
476
# define SHT_NULL	Elf_sht_null
477
# define SHT_NOBITS	Elf_sht_nobits
478
# define SHT_REL	Elf_sht_rel
479
# define SHT_RELA	Elf_sht_rela
480
481
# define SHN_UNDEF	Elf_eshn_undefined
482
# define SHN_ABS	Elf_eshn_absolute
483
# define SHN_COMMON	Elf_eshn_common
484
485
/*
486
 * The magic of picking the right size types is handled by the ELFSIZE
487
 * definition above.
488
 */
489
# ifdef __STDC__
490
#  define ElfW(type)    Elf_##type
491
# else
492
#  define ElfW(type)    Elf_/**/type
493
# endif
494
495
# ifdef __alpha__
496
#  include <sys/exec_ecoff.h>
497
#  define HDRR		struct ecoff_symhdr
498
#  define pHDRR		HDRR *
499
# endif
500
#endif /* __NetBSD__ */
501
502
#ifdef __OpenBSD__
503
# include <sys/exec_elf.h>
504
#endif
505
506
#if __GNU_LIBRARY__ - 0 >= 6
507
# include <link.h>	/* get ElfW etc */
508
#endif
509
510
#ifndef ElfW
511
# ifdef __STDC__
512
#  define ElfW(type)	Elf32_##type
513
# else
514
#  define ElfW(type)	Elf32_/**/type
515
# endif
516
#endif
Lines 462-474 Link Here
462
     (*(Elf32_Shdr *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
559
     (*(ElfW(Shdr) *) ((byte *) old_section_h + old_file_h->e_shentsize * (n)))
463
     (*(Elf32_Shdr *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
560
     (*(ElfW(Shdr) *) ((byte *) new_section_h + new_file_h->e_shentsize * (n)))
464
     (*(Elf32_Phdr *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
561
     (*(ElfW(Phdr) *) ((byte *) old_program_h + old_file_h->e_phentsize * (n)))
465
     (*(Elf32_Phdr *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
562
     (*(ElfW(Phdr) *) ((byte *) new_program_h + new_file_h->e_phentsize * (n)))
Lines 478-486 Link Here
478
int
575
ElfW(Addr)
479
     int x, y;
576
     ElfW(Addr) x, y;
Lines 510-528 Link Here
510
  Elf32_Ehdr *old_file_h, *new_file_h;
607
  ElfW(Ehdr) *old_file_h, *new_file_h;
511
  Elf32_Phdr *old_program_h, *new_program_h;
608
  ElfW(Phdr) *old_program_h, *new_program_h;
512
  Elf32_Shdr *old_section_h, *new_section_h;
609
  ElfW(Shdr) *old_section_h, *new_section_h;
513
  Elf32_Addr old_bss_addr, new_bss_addr;
610
  ElfW(Addr) old_bss_addr, new_bss_addr;
514
  Elf32_Word old_bss_size, new_data2_size;
611
  ElfW(Word) old_bss_size, new_data2_size;
515
  Elf32_Off  new_data2_offset;
612
  ElfW(Off)  new_data2_offset;
516
  Elf32_Addr new_data2_addr;
613
  ElfW(Addr) new_data2_addr;
614
#if defined ( __sony_news) && defined (_SYSTYPE_SYSV)
615
  int old_sbss_index, old_mdebug_index;
616
#endif /* __sony_news && _SYSTYPE_SYSV */
Lines 535-541 Link Here
535
  old_base = mmap (0, stat_buf.st_size, PROT_READ, MAP_SHARED, old_file, 0);
635
  old_base = mmap ((caddr_t) 0, stat_buf.st_size, PROT_READ, MAP_SHARED,
636
		   old_file, 0);
Lines 547-555 Link Here
547
  old_file_h = (Elf32_Ehdr *) old_base;
648
  old_file_h = (ElfW(Ehdr) *) old_base;
548
  old_program_h = (Elf32_Phdr *) ((byte *) old_base + old_file_h->e_phoff);
649
  old_program_h = (ElfW(Phdr) *) ((byte *) old_base + old_file_h->e_phoff);
549
  old_section_h = (Elf32_Shdr *) ((byte *) old_base + old_file_h->e_shoff);
650
  old_section_h = (ElfW(Shdr) *) ((byte *) old_base + old_file_h->e_shoff);
Lines 571-586 Link Here
571
#if defined(emacs) || !defined(DEBUG)
672
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
572
  new_bss_addr = (Elf32_Addr) sbrk (0);
673
  for (old_sbss_index = 1; old_sbss_index < (int) old_file_h->e_shnum;
674
       old_sbss_index++)
675
    {
676
#ifdef DEBUG
677
      fprintf (stderr, "Looking for .sbss - found %s\n",
678
	       old_section_names + OLD_SECTION_H (old_sbss_index).sh_name);
679
#endif
680
      if (!strcmp (old_section_names + OLD_SECTION_H (old_sbss_index).sh_name,
681
		   ".sbss"))
682
	break;
683
    }
684
  if (old_sbss_index == old_file_h->e_shnum)
685
    {
686
      old_bss_addr = OLD_SECTION_H(old_bss_index).sh_addr;
687
      old_bss_size = OLD_SECTION_H(old_bss_index).sh_size;
688
      new_data2_offset = OLD_SECTION_H(old_bss_index).sh_offset;
689
      new_data2_index = old_bss_index;
690
    }
691
  else
692
    {
693
      old_bss_addr = OLD_SECTION_H(old_sbss_index).sh_addr;
694
      old_bss_size = OLD_SECTION_H(old_bss_index).sh_size
695
	+ OLD_SECTION_H(old_sbss_index).sh_size;
696
      new_data2_offset = OLD_SECTION_H(old_sbss_index).sh_offset;
697
      new_data2_index = old_sbss_index;
698
    }
699
700
  for (old_mdebug_index = 1; old_mdebug_index < (int) old_file_h->e_shnum;
701
       old_mdebug_index++)
702
    {
703
#ifdef DEBUG
704
      fprintf (stderr, "Looking for .mdebug - found %s\n",
705
	       old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name);
706
#endif
707
      if (!strcmp (old_section_names + OLD_SECTION_H (old_mdebug_index).sh_name,
708
		   ".mdebug"))
709
	break;
710
    }
711
    if (old_mdebug_index == old_file_h->e_shnum)
712
	old_mdebug_index = 0;
713
#else /* not (__sony_news && _SYSTYPE_SYSV) */	    
714
#endif /* not (__sony_news && _SYSTYPE_SYSV) */	    
715
#if defined (emacs) || !defined (DEBUG)
716
  new_bss_addr = (ElfW(Addr)) sbrk (0);
717
#if !defined (__sony_news) || !defined (_SYSTYPE_SYSV)
718
#endif /*  not (__sony_news && _SYSTYPE_SYSV) */
Lines 610-628 Link Here
610
  new_base = mmap (0, new_file_size, PROT_READ | PROT_WRITE, MAP_PRIVATE,
756
  new_base = mmap ((caddr_t) 0, new_file_size, PROT_READ | PROT_WRITE,
611
		   new_file, 0);
757
		   MAP_PRIVATE, new_file, 0);
612
  new_base = mmap (0, new_file_size, PROT_READ | PROT_WRITE, MAP_SHARED,
758
  new_base = mmap ((caddr_t) 0, new_file_size, PROT_READ | PROT_WRITE,
613
		   new_file, 0);
759
		   MAP_SHARED, new_file, 0);
614
  new_file_h = (Elf32_Ehdr *) new_base;
760
  new_file_h = (ElfW(Ehdr) *) new_base;
615
  new_program_h = (Elf32_Phdr *) ((byte *) new_base + old_file_h->e_phoff);
761
  new_program_h = (ElfW(Phdr) *) ((byte *) new_base + old_file_h->e_phoff);
616
  new_section_h = (Elf32_Shdr *)
762
  new_section_h = (ElfW(Shdr) *)
Lines 665-672 Link Here
811
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
812
      if (NEW_PROGRAM_H (n).p_vaddr + NEW_PROGRAM_H (n).p_filesz
813
	  > round_up (old_bss_addr, alignment))
814
	fatal ("Program segment above .bss in %s\n", old_name, 0);
815
#else /* not (__sony_news && _SYSTYPE_SYSV) */
816
#endif /* not (__sony_news && _SYSTYPE_SYSV) */
Lines 678-684 Link Here
678
  NEW_PROGRAM_H (n).p_filesz += new_data2_size;
830
  /* Make sure that the size includes any padding before the old .bss
831
     section.  */
832
  NEW_PROGRAM_H (n).p_filesz = new_bss_addr - NEW_PROGRAM_H (n).p_vaddr;
Lines 712-719 Link Here
712
      /* If it is bss section, insert the new data2 section before it. */
866
      int temp_index;
713
      if (n == old_bss_index)
867
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
868
      /* If it is (s)bss section, insert the new data2 section before it.  */
869
      /* new_data2_index is the index of either old_sbss or old_bss, that was
870
	 chosen as a section for new_data2.   */
871
      temp_index = new_data2_index;
872
#else /* not (__sony_news && _SYSTYPE_SYSV) */
873
      /* If it is bss section, insert the new data2 section before it.  */
874
      temp_index = old_bss_index;
875
#endif /* not (__sony_news && _SYSTYPE_SYSV) */
876
      if (n == temp_index)
Lines 736-745 Link Here
736
899
      
737
      /* The new bss section's size is zero, and its file offset and virtual
900
      if (n == old_bss_index
738
	 address should be off by NEW_DATA2_SIZE. */
901
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
739
      if (n == old_bss_index)
902
	  /* The new bss and sbss section's size is zero, and its file offset
903
	     and virtual address should be off by NEW_DATA2_SIZE.  */
904
	  || n == old_sbss_index
905
#endif /* __sony_news and _SYSTYPE_SYSV */
906
	  )
Lines 799-804 Link Here
966
#ifdef _nec_ews_svr4				/* hir, 1994.6.13 */
967
	  || !strcmp ((old_section_names + NEW_SECTION_H(n).sh_name),
968
		      ".sdata")
969
#endif
970
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
971
	  || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
972
		      ".sdata")
973
	  || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
974
		      ".lit4")
975
	  || !strcmp ((old_section_names + NEW_SECTION_H (n).sh_name),
976
		      ".lit8")
977
#endif /* __sony_news && _SYSTYPE_SYSV */
Lines 808-820 Link Here
808
	  Elf32_Shdr *spt = &NEW_SECTION_H (nn);
987
#ifdef __alpha__
988
      /* Update Alpha COFF symbol table: */
989
      if (strcmp (old_section_names + OLD_SECTION_H (n).sh_name, ".mdebug")
990
	  == 0)
991
	{
992
	  pHDRR symhdr = (pHDRR) (NEW_SECTION_H (nn).sh_offset + new_base);
993
994
	  symhdr->cbLineOffset += new_data2_size;
995
	  symhdr->cbDnOffset += new_data2_size;
996
	  symhdr->cbPdOffset += new_data2_size;
997
	  symhdr->cbSymOffset += new_data2_size;
998
	  symhdr->cbOptOffset += new_data2_size;
999
	  symhdr->cbAuxOffset += new_data2_size;
1000
	  symhdr->cbSsOffset += new_data2_size;
1001
	  symhdr->cbSsExtOffset += new_data2_size;
1002
	  symhdr->cbFdOffset += new_data2_size;
1003
	  symhdr->cbRfdOffset += new_data2_size;
1004
	  symhdr->cbExtOffset += new_data2_size;
1005
	}
1006
#endif /* __alpha__ */
1007
1008
#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
1009
      if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG && old_mdebug_index) 
1010
        {
1011
	  int diff = NEW_SECTION_H(nn).sh_offset 
1012
	 	- OLD_SECTION_H(old_mdebug_index).sh_offset;
1013
	  HDRR *phdr = (HDRR *)(NEW_SECTION_H (nn).sh_offset + new_base);
1014
1015
	  if (diff)
1016
	    {
1017
	      phdr->cbLineOffset += diff;
1018
	      phdr->cbDnOffset   += diff;
1019
	      phdr->cbPdOffset   += diff;
1020
	      phdr->cbSymOffset  += diff;
1021
	      phdr->cbOptOffset  += diff;
1022
	      phdr->cbAuxOffset  += diff;
1023
	      phdr->cbSsOffset   += diff;
1024
	      phdr->cbSsExtOffset += diff;
1025
	      phdr->cbFdOffset   += diff;
1026
	      phdr->cbRfdOffset  += diff;
1027
	      phdr->cbExtOffset  += diff;
1028
	    }
1029
	}
1030
#endif /* __sony_news && _SYSTYPE_SYSV */
809
	  Elf32_Sym * sym = (Elf32_Sym *) (NEW_SECTION_H (nn).sh_offset +
1031
	  ElfW(Shdr) *spt = &NEW_SECTION_H (nn);
1032
	  ElfW(Sym) * sym = (ElfW(Sym) *) (NEW_SECTION_H (nn).sh_offset +
Lines 832-838 Link Here
832
      Elf32_Sym *symp, *symendp;
1055
      ElfW(Sym) *symp, *symendp;
Lines 840-851 Link Here
840
      symp = (Elf32_Sym *) (NEW_SECTION_H (n).sh_offset + new_base);
1063
      symp = (ElfW(Sym) *) (NEW_SECTION_H (n).sh_offset + new_base);
841
      symendp = (Elf32_Sym *) ((byte *)symp + NEW_SECTION_H (n).sh_size);
1064
      symendp = (ElfW(Sym) *) ((byte *)symp + NEW_SECTION_H (n).sh_size);
842
	    || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0)
1065
	    || strcmp ((char *) (symnames + symp->st_name), "end") == 0
1066
	    || strcmp ((char *) (symnames + symp->st_name), "_edata") == 0
1067
	    || strcmp ((char *) (symnames + symp->st_name), "edata") == 0)
Lines 853-859 Link Here
853
      Elf32_Shdr section = NEW_SECTION_H (n);
1078
      ElfW(Shdr) section = NEW_SECTION_H (n);
Lines 867-880 Link Here
867
	    Elf32_Addr offset = NEW_SECTION_H (nn).sh_addr -
1092
	    ElfW(Addr) offset = NEW_SECTION_H (nn).sh_addr -
868
		Elf32_Addr addr = ((Elf32_Rel *) reloc)->r_offset - offset;
1093
		ElfW(Addr) addr = ((ElfW(Rel) *) reloc)->r_offset - offset;
869
		memcpy (new_base + addr, old_base + addr, 4);
1094
#ifdef __alpha__
1095
		/* The Alpha ELF binutils currently have a bug that
1096
		   sometimes results in relocs that contain all
1097
		   zeroes.  Work around this for now...  */
1098
		if (((ElfW(Rel) *) reloc)->r_offset == 0)
1099
		    continue;
1100
#endif
1101
		memcpy (new_base + addr, old_base + addr, sizeof(ElfW(Addr)));
870
 $shar_touch -am 0930013598 'patch-ae' &&
1102
 $shar_touch -am 0930013598 'patch-ae' &&
871
 chmod 0644 'patch-ae' ||
1103
 chmod 0644 'patch-ae' ||
872
 $echo 'restore of' 'patch-ae' 'failed'
1104
 $echo 'restore of' 'patch-ae' 'failed'
873
 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
1105
 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
874
 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
1106
 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
875
   md5sum -c << SHAR_EOF >/dev/null 2>&1 \
1107
   md5sum -c << SHAR_EOF >/dev/null 2>&1 \
876
   || $echo 'patch-ae:' 'MD5 check failed'
1108
   || $echo 'patch-ae:' 'MD5 check failed'
877
 else
1109
 else
878
   shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'patch-ae'`"
1110
   shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'patch-ae'`"
879
   test 17911 -eq "$shar_count" ||
1111
   test 17911 -eq "$shar_count" ||
880
   $echo 'patch-ae:' 'original size' '17911,' 'current size' "$shar_count!"
1112
   $echo 'patch-ae:' 'original size' '17911,' 'current size' "$shar_count!"
881
 fi
1113
 fi

Return to bug 8090