[kernel] revert the 027-mips_module_reloc.patch patch for mips64 targets until we...
[openwrt.git] / target / linux / sibyte / patches / 106-no_module_reloc.patch
1 diff -urN linux-2.6.30.7/arch/mips/Makefile linux-2.6.30.7.new/arch/mips/Makefile
2 --- linux-2.6.30.7/arch/mips/Makefile 2009-09-27 13:17:16.000000000 +0200
3 +++ linux-2.6.30.7.new/arch/mips/Makefile 2009-09-15 19:46:05.000000000 +0200
4 @@ -83,7 +83,7 @@
5 cflags-y += -G 0 -mno-abicalls -fno-pic -pipe
6 cflags-y += -msoft-float
7 LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
8 -MODFLAGS += -mno-long-calls
9 +MODFLAGS += -mlong-calls
10
11 cflags-y += -ffreestanding
12
13 diff -urN linux-2.6.30.7/arch/mips/include/asm/module.h linux-2.6.30.7.new/arch/mips/include/asm/module.h
14 --- linux-2.6.30.7/arch/mips/include/asm/module.h 2009-09-27 13:17:16.000000000 +0200
15 +++ linux-2.6.30.7.new/arch/mips/include/asm/module.h 2009-09-15 19:46:05.000000000 +0200
16 @@ -9,11 +9,6 @@
17 struct list_head dbe_list;
18 const struct exception_table_entry *dbe_start;
19 const struct exception_table_entry *dbe_end;
20 -
21 - void *plt_tbl;
22 - unsigned int core_plt_offset;
23 - unsigned int core_plt_size;
24 - unsigned int init_plt_offset;
25 };
26
27 typedef uint8_t Elf64_Byte; /* Type for a 8-bit quantity. */
28 diff -urN linux-2.6.30.7/arch/mips/kernel/module.c linux-2.6.30.7.new/arch/mips/kernel/module.c
29 --- linux-2.6.30.7/arch/mips/kernel/module.c 2009-09-27 13:17:16.000000000 +0200
30 +++ linux-2.6.30.7.new/arch/mips/kernel/module.c 2009-09-15 19:46:05.000000000 +0200
31 @@ -43,116 +43,6 @@
32 static LIST_HEAD(dbe_list);
33 static DEFINE_SPINLOCK(dbe_lock);
34
35 -/*
36 - * Get the potential max trampolines size required of the init and
37 - * non-init sections. Only used if we cannot find enough contiguous
38 - * physically mapped memory to put the module into.
39 - */
40 -static unsigned int
41 -get_plt_size(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
42 - const char *secstrings, unsigned int symindex, bool is_init)
43 -{
44 - unsigned long ret = 0;
45 - unsigned int i, j;
46 - Elf_Sym *syms;
47 -
48 - /* Everything marked ALLOC (this includes the exported symbols) */
49 - for (i = 1; i < hdr->e_shnum; ++i) {
50 - unsigned int info = sechdrs[i].sh_info;
51 -
52 - if (sechdrs[i].sh_type != SHT_REL
53 - && sechdrs[i].sh_type != SHT_RELA)
54 - continue;
55 -
56 - /* Not a valid relocation section? */
57 - if (info >= hdr->e_shnum)
58 - continue;
59 -
60 - /* Don't bother with non-allocated sections */
61 - if (!(sechdrs[info].sh_flags & SHF_ALLOC))
62 - continue;
63 -
64 - /* If it's called *.init*, and we're not init, we're
65 - not interested */
66 - if ((strstr(secstrings + sechdrs[i].sh_name, ".init") != 0)
67 - != is_init)
68 - continue;
69 -
70 - syms = (Elf_Sym *) sechdrs[symindex].sh_addr;
71 - if (sechdrs[i].sh_type == SHT_REL) {
72 - Elf_Mips_Rel *rel = (void *) sechdrs[i].sh_addr;
73 - unsigned int size = sechdrs[i].sh_size / sizeof(*rel);
74 -
75 - for (j = 0; j < size; ++j) {
76 - Elf_Sym *sym;
77 -
78 - if (ELF_MIPS_R_TYPE(rel[j]) != R_MIPS_26)
79 - continue;
80 -
81 - sym = syms + ELF_MIPS_R_SYM(rel[j]);
82 - if (!is_init && sym->st_shndx != SHN_UNDEF)
83 - continue;
84 -
85 - ret += 4 * sizeof(int);
86 - }
87 - } else {
88 - Elf_Mips_Rela *rela = (void *) sechdrs[i].sh_addr;
89 - unsigned int size = sechdrs[i].sh_size / sizeof(*rela);
90 -
91 - for (j = 0; j < size; ++j) {
92 - Elf_Sym *sym;
93 -
94 - if (ELF_MIPS_R_TYPE(rela[j]) != R_MIPS_26)
95 - continue;
96 -
97 - sym = syms + ELF_MIPS_R_SYM(rela[j]);
98 - if (!is_init && sym->st_shndx != SHN_UNDEF)
99 - continue;
100 -
101 - ret += 4 * sizeof(int);
102 - }
103 - }
104 - }
105 -
106 - return ret;
107 -}
108 -
109 -#ifndef MODULE_START
110 -static void *alloc_phys(unsigned long size)
111 -{
112 - unsigned order;
113 - struct page *page;
114 - struct page *p;
115 -
116 - size = PAGE_ALIGN(size);
117 - order = get_order(size);
118 -
119 - page = alloc_pages(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN |
120 - __GFP_THISNODE, order);
121 - if (!page)
122 - return NULL;
123 -
124 - split_page(page, order);
125 -
126 - for (p = page + (size >> PAGE_SHIFT); p < page + (1 << order); ++p)
127 - __free_page(p);
128 -
129 - return page_address(page);
130 -}
131 -#endif
132 -
133 -static void free_phys(void *ptr, unsigned long size)
134 -{
135 - struct page *page;
136 - struct page *end;
137 -
138 - page = virt_to_page(ptr);
139 - end = page + (PAGE_ALIGN(size) >> PAGE_SHIFT);
140 -
141 - for (; page < end; ++page)
142 - __free_page(page);
143 -}
144 -
145 void *module_alloc(unsigned long size)
146 {
147 #ifdef MODULE_START
148 @@ -168,45 +58,16 @@
149
150 return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL);
151 #else
152 - void *ptr;
153 -
154 if (size == 0)
155 return NULL;
156 -
157 - ptr = alloc_phys(size);
158 -
159 - /* If we failed to allocate physically contiguous memory,
160 - * fall back to regular vmalloc. The module loader code will
161 - * create jump tables to handle long jumps */
162 - if (!ptr)
163 - return vmalloc(size);
164 -
165 - return ptr;
166 -#endif
167 -}
168 -
169 -static inline bool is_phys_addr(void *ptr)
170 -{
171 -#ifdef CONFIG_64BIT
172 - return (KSEGX((unsigned long)ptr) == CKSEG0);
173 -#else
174 - return (KSEGX(ptr) == KSEG0);
175 + return vmalloc(size);
176 #endif
177 }
178
179 /* Free memory returned from module_alloc */
180 void module_free(struct module *mod, void *module_region)
181 {
182 - if (is_phys_addr(module_region)) {
183 - if (mod->module_init == module_region)
184 - free_phys(module_region, mod->init_size);
185 - else if (mod->module_core == module_region)
186 - free_phys(module_region, mod->core_size);
187 - else
188 - BUG();
189 - } else {
190 - vfree(module_region);
191 - }
192 + vfree(module_region);
193 /* FIXME: If module_region == mod->init_region, trim exception
194 table entries. */
195 }
196 @@ -214,24 +75,6 @@
197 int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
198 char *secstrings, struct module *mod)
199 {
200 - unsigned int symindex = 0;
201 - unsigned int core_size, init_size;
202 - int i;
203 -
204 - for (i = 1; i < hdr->e_shnum; i++)
205 - if (sechdrs[i].sh_type == SHT_SYMTAB)
206 - symindex = i;
207 -
208 - core_size = get_plt_size(hdr, sechdrs, secstrings, symindex, false);
209 - init_size = get_plt_size(hdr, sechdrs, secstrings, symindex, true);
210 -
211 - mod->arch.core_plt_offset = 0;
212 - mod->arch.core_plt_size = core_size;
213 - mod->arch.init_plt_offset = core_size;
214 - mod->arch.plt_tbl = kmalloc(core_size + init_size, GFP_KERNEL);
215 - if (!mod->arch.plt_tbl)
216 - return -ENOMEM;
217 -
218 return 0;
219 }
220
221 @@ -254,41 +97,27 @@
222 return 0;
223 }
224
225 -static Elf_Addr add_plt_entry_to(unsigned *plt_offset,
226 - void *start, Elf_Addr v)
227 +static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
228 {
229 - unsigned *tramp = start + *plt_offset;
230 -
231 - *plt_offset += 4 * sizeof(int);
232 -
233 - /* adjust carry for addiu */
234 - if (v & 0x00008000)
235 - v += 0x10000;
236 -
237 - tramp[0] = 0x3c190000 | (v >> 16); /* lui t9, hi16 */
238 - tramp[1] = 0x27390000 | (v & 0xffff); /* addiu t9, t9, lo16 */
239 - tramp[2] = 0x03200008; /* jr t9 */
240 - tramp[3] = 0x00000000; /* nop */
241 -
242 - return (Elf_Addr) tramp;
243 -}
244 + if (v % 4) {
245 + printk(KERN_ERR "module %s: dangerous relocation\n", me->name);
246 + return -ENOEXEC;
247 + }
248
249 -static Elf_Addr add_plt_entry(struct module *me, void *location, Elf_Addr v)
250 -{
251 - if (location >= me->module_core &&
252 - location < me->module_core + me->core_size)
253 - return add_plt_entry_to(&me->arch.core_plt_offset,
254 - me->arch.plt_tbl, v);
255 + if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
256 + printk(KERN_ERR
257 + "module %s: relocation overflow\n",
258 + me->name);
259 + return -ENOEXEC;
260 + }
261
262 - if (location >= me->module_init &&
263 - location < me->module_init + me->init_size)
264 - return add_plt_entry_to(&me->arch.init_plt_offset,
265 - me->arch.plt_tbl, v);
266 + *location = (*location & ~0x03ffffff) |
267 + ((*location + (v >> 2)) & 0x03ffffff);
268
269 return 0;
270 }
271
272 -static int set_r_mips_26(struct module *me, u32 *location, u32 ofs, Elf_Addr v)
273 +static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
274 {
275 if (v % 4) {
276 printk(KERN_ERR "module %s: dangerous relocation\n", me->name);
277 @@ -296,31 +125,17 @@
278 }
279
280 if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
281 - v = add_plt_entry(me, location, v + (ofs << 2));
282 - if (!v) {
283 - printk(KERN_ERR
284 + printk(KERN_ERR
285 "module %s: relocation overflow\n",
286 me->name);
287 - return -ENOEXEC;
288 - }
289 - ofs = 0;
290 + return -ENOEXEC;
291 }
292
293 - *location = (*location & ~0x03ffffff) | ((ofs + (v >> 2)) & 0x03ffffff);
294 + *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff);
295
296 return 0;
297 }
298
299 -static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
300 -{
301 - return set_r_mips_26(me, location, *location & 0x03ffffff, v);
302 -}
303 -
304 -static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
305 -{
306 - return set_r_mips_26(me, location, 0, v);
307 -}
308 -
309 static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v)
310 {
311 struct mips_hi16 *n;
312 @@ -585,23 +400,11 @@
313 list_add(&me->arch.dbe_list, &dbe_list);
314 spin_unlock_irq(&dbe_lock);
315 }
316 -
317 - /* Get rid of the fixup trampoline if we're running the module
318 - * from physically mapped address space */
319 - if (me->arch.core_plt_offset == 0 &&
320 - me->arch.init_plt_offset == me->arch.core_plt_size &&
321 - is_phys_addr(me->module_core)) {
322 - kfree(me->arch.plt_tbl);
323 - me->arch.plt_tbl = NULL;
324 - }
325 -
326 return 0;
327 }
328
329 void module_arch_cleanup(struct module *mod)
330 {
331 - if (mod->arch.plt_tbl)
332 - kfree(mod->arch.plt_tbl);
333 spin_lock_irq(&dbe_lock);
334 list_del(&mod->arch.dbe_list);
335 spin_unlock_irq(&dbe_lock);
This page took 0.084285 seconds and 5 git commands to generate.