summaryrefslogtreecommitdiff
path: root/editors/emacs/patches/patch-az
blob: 7c4ca88fa92880d0e7182eb43fca6e031240b8bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
$NetBSD: patch-az,v 1.6 1999/12/28 14:09:14 tron Exp $

--- src/unexelf.c.orig	Fri Dec 17 15:48:53 1999
+++ src/unexelf.c	Fri Dec 17 15:55:21 1999
@@ -478,6 +478,13 @@
 # endif
 # include <sys/exec_elf.h>
 
+#include <sys/param.h>
+
+/* NetBSD 1.4M has sane <elf.h> */
+
+#if !defined(__NetBSD_Version__) || __NetBSD_Version__ < 104130000
+# include <sys/exec_elf.h>
+
 # define PT_LOAD	Elf_pt_load
 # define SHT_SYMTAB	Elf_sht_symtab
 # define SHT_DYNSYM	Elf_sht_dynsym
@@ -490,6 +497,10 @@
 # define SHN_ABS	Elf_eshn_absolute
 # define SHN_COMMON	Elf_eshn_common
 
+#else
+# include <elf.h>
+#endif
+
 /*
  * The magic of picking the right size types is handled by the ELFSIZE
  * definition above.
@@ -504,9 +515,14 @@
 #  include <sys/exec_ecoff.h>
 #  define HDRR		struct ecoff_symhdr
 #  define pHDRR		HDRR *
-# endif
+# endif /* __alpha__ */
 #endif /* __NetBSD__ */
 
+# ifdef __mips__
+#  define SHT_MIPS_DEBUG	DT_MIPS_FLAGS
+#  define HDRR		struct Elf_Shdr
+# endif /* __mips__ */
+
 #ifdef __OpenBSD__
 # include <sys/exec_elf.h>
 #endif
@@ -530,6 +546,14 @@
 extern void fatal (char *, ...);
 #endif
 
+#if defined ( __sony_news) && defined (_SYSTYPE_SYSV)
+# define HAVE_MIPS_SBSS
+#endif
+
+#if defined (__mips__) && (defined(__NetBSD__) || defined(__OpenBSD__))
+# define HAVE_MIPS_SBSS
+#endif
+
 #ifndef ELF_BSS_SECTION_NAME
 #define ELF_BSS_SECTION_NAME ".bss"
 #endif
@@ -588,6 +612,47 @@
   return x - rem + y;
 }
 
+#if defined(__alpha__) || (defined ( __sony_news) && defined (_SYSTYPE_SYSV))
+/* We are using  ECOFF symbols embedded in ELF. */
+
+void
+relocate_ecoff_symhdr(symhdr, diff)
+    HDRR *symhdr;
+    ElfW(Word) diff;
+{
+  symhdr->cbLineOffset += diff;
+  symhdr->cbDnOffset   += diff;
+  symhdr->cbPdOffset   += diff;
+  symhdr->cbSymOffset  += diff;
+  symhdr->cbOptOffset  += diff;
+  symhdr->cbAuxOffset  += diff;
+  symhdr->cbSsOffset   += diff;
+  symhdr->cbSsExtOffset += diff;
+  symhdr->cbFdOffset   += diff;
+  symhdr->cbRfdOffset  += diff;
+  symhdr->cbExtOffset  += diff;
+}
+#endif /* __alpha__ or __sony_news and systype_sysv */
+
+#ifdef notyet
+void
+relocate_elf_proghdr(p, diff)
+    HDRR *symhdr;
+    Elfw(Word) diff;
+{
+	phdr->sh_name  += diff;
+	phdr->sh_type  += diff;
+	phdr->sh_flags += diff;
+	phdr->sh_addr  += diff;
+	phdr->sh_offset += diff;
+	phdr->sh_size  += diff;
+	phdr->sh_link  += diff;
+	phdr->sh_info  += diff;
+	phdr->sh_addralign += diff;
+	phdr->sh_entsize += diff;
+};
+#endif /* notyet */
+
 /* ****************************************************************
  * unexec
  *
@@ -829,6 +894,10 @@
   if (n < 0)
     fatal ("Couldn't find segment next to .bss in %s\n", old_name, 0);
 
+#ifdef HAVE_MIPS_SBSS
+  bss_phdr_index = n;
+#endif
+
   /* Make sure that the size includes any padding before the old .bss
      section.  */
   NEW_PROGRAM_H (n).p_filesz = new_bss_addr - NEW_PROGRAM_H (n).p_vaddr;
@@ -908,6 +977,28 @@
 	     this section will be placed in exactly the same place. */
 	  NEW_SECTION_H (nn).sh_addralign = OLD_SECTION_H (nn).sh_addralign;
 	  NEW_SECTION_H (nn).sh_size = 0;
+
+#ifdef HAVE_MIPS_SBSS
+	  /* On ELF mips,  the new data section replaces both .sbss and .bss
+	     (we have, after all, written to them.).  Adding new_data2_size
+	     to the sh_addr and sh_offset of sbss puts sbss at the end of
+	     the new data section. setting the size to zero makes it empty.
+	     But then, adding the new_data2_size to the bss address puts
+	     its start  beyond the end of the original bss. If the sbss size
+	     was bigger than a page,  the bss ends up not covered by the
+	     program header.  This breaks strip. Since both sbss and bss
+	     are zero-sized,  just use the same address and file offset for
+	     both, guaranteeing other tools will assign them to the same
+	     program section (asssuming no sections are loaded at higher
+	     offsets.)  */
+	  if (n == old_bss_index) {
+	    	 int new_sbss_bss_padding = NEW_SECTION_H(nn).sh_addr -
+		    NEW_SECTION_H(nn - 1).sh_addr;
+		printf("sbss to bss offset =0x%x\n", new_sbss_bss_padding);
+		NEW_SECTION_H(nn).sh_addr =NEW_SECTION_H(nn - 1).sh_addr;
+		NEW_SECTION_H(nn).sh_offset =NEW_SECTION_H(nn - 1).sh_offset;
+	  }
+#endif  /* HAVE_MIPS_SBSS */
 	}
       else
 	{
@@ -983,22 +1074,11 @@
 	  == 0)
 	{
 	  pHDRR symhdr = (pHDRR) (NEW_SECTION_H (nn).sh_offset + new_base);
-
-	  symhdr->cbLineOffset += new_data2_size;
-	  symhdr->cbDnOffset += new_data2_size;
-	  symhdr->cbPdOffset += new_data2_size;
-	  symhdr->cbSymOffset += new_data2_size;
-	  symhdr->cbOptOffset += new_data2_size;
-	  symhdr->cbAuxOffset += new_data2_size;
-	  symhdr->cbSsOffset += new_data2_size;
-	  symhdr->cbSsExtOffset += new_data2_size;
-	  symhdr->cbFdOffset += new_data2_size;
-	  symhdr->cbRfdOffset += new_data2_size;
-	  symhdr->cbExtOffset += new_data2_size;
+	  relocate_ecoff_symhdr(symhdr, new_data2_size);
 	}
 #endif /* __alpha__ */
 
-#if defined (__sony_news) && defined (_SYSTYPE_SYSV)
+#ifdef HAVE_MIPS_SBSS
       if (NEW_SECTION_H (nn).sh_type == SHT_MIPS_DEBUG && old_mdebug_index) 
         {
 	  int diff = NEW_SECTION_H(nn).sh_offset 
@@ -1007,20 +1087,17 @@
 
 	  if (diff)
 	    {
-	      phdr->cbLineOffset += diff;
-	      phdr->cbDnOffset   += diff;
-	      phdr->cbPdOffset   += diff;
-	      phdr->cbSymOffset  += diff;
-	      phdr->cbOptOffset  += diff;
-	      phdr->cbAuxOffset  += diff;
-	      phdr->cbSsOffset   += diff;
-	      phdr->cbSsExtOffset += diff;
-	      phdr->cbFdOffset   += diff;
-	      phdr->cbRfdOffset  += diff;
-	      phdr->cbExtOffset  += diff;
+#if defined ( __sony_news) && defined (_SYSTYPE_SYSV)
+	      relocate_ecoff_symhdr(phdr, diff);
+#else
+	      /* xxxBSD with  GNU binutils has .mdebug, but not ecoff(???)  */
+#ifdef DEBUG
+	      printf("Dont know how to relocate mdebug syms by %0x\n", diff);
+#endif
+#endif
 	    }
 	}
-#endif /* __sony_news && _SYSTYPE_SYSV */
+#endif /* HAVE_MIPS_SBSS */
 
 #if __sgi
       /* Adjust  the HDRR offsets in .mdebug and copy the