ext4: add Support for large (2TB+) block devices and files
[openwrt.git] / target / linux / cobalt / patches-2.6.32 / 001-no_module_reloc.patch
1 diff -urN linux-2.6.32.7/arch/mips/Makefile linux-2.6.32.7.new/arch/mips/Makefile
2 --- linux-2.6.32.7/arch/mips/Makefile 2010-02-01 18:06:35.000000000 +0100
3 +++ linux-2.6.32.7.new/arch/mips/Makefile 2010-01-29 00:06:20.000000000 +0100
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.32.7/arch/mips/include/asm/module.h linux-2.6.32.7.new/arch/mips/include/asm/module.h
14 --- linux-2.6.32.7/arch/mips/include/asm/module.h 2010-02-01 18:06:35.000000000 +0100
15 +++ linux-2.6.32.7.new/arch/mips/include/asm/module.h 2010-01-29 00:06:20.000000000 +0100
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 *phys_plt_tbl;
22 - void *virt_plt_tbl;
23 - unsigned int phys_plt_offset;
24 - unsigned int virt_plt_offset;
25 };
26
27 typedef uint8_t Elf64_Byte; /* Type for a 8-bit quantity. */
28 diff -urN linux-2.6.32.7/arch/mips/kernel/module.c linux-2.6.32.7.new/arch/mips/kernel/module.c
29 --- linux-2.6.32.7/arch/mips/kernel/module.c 2010-02-01 18:06:35.000000000 +0100
30 +++ linux-2.6.32.7.new/arch/mips/kernel/module.c 2010-01-29 00:06:20.000000000 +0100
31 @@ -43,117 +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 -
146 void *module_alloc(unsigned long size)
147 {
148 #ifdef MODULE_START
149 @@ -169,99 +58,21 @@
150
151 return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL);
152 #else
153 - void *ptr;
154 -
155 if (size == 0)
156 return NULL;
157 -
158 - ptr = alloc_phys(size);
159 -
160 - /* If we failed to allocate physically contiguous memory,
161 - * fall back to regular vmalloc. The module loader code will
162 - * create jump tables to handle long jumps */
163 - if (!ptr)
164 - return vmalloc(size);
165 -
166 - return ptr;
167 -#endif
168 -}
169 -
170 -static inline bool is_phys_addr(void *ptr)
171 -{
172 -#ifdef CONFIG_64BIT
173 - return (KSEGX((unsigned long)ptr) == CKSEG0);
174 -#else
175 - return (KSEGX(ptr) == KSEG0);
176 + return vmalloc(size);
177 #endif
178 }
179
180 /* Free memory returned from module_alloc */
181 void module_free(struct module *mod, void *module_region)
182 {
183 - if (is_phys_addr(module_region)) {
184 - if (mod->module_init == module_region)
185 - free_phys(module_region, mod->init_size);
186 - else if (mod->module_core == module_region)
187 - free_phys(module_region, mod->core_size);
188 - else
189 - BUG();
190 - } else {
191 - vfree(module_region);
192 - }
193 -}
194 -
195 -static void *__module_alloc(int size, bool phys)
196 -{
197 - void *ptr;
198 -
199 - if (phys)
200 - ptr = kmalloc(size, GFP_KERNEL);
201 - else
202 - ptr = vmalloc(size);
203 - return ptr;
204 -}
205 -
206 -static void __module_free(void *ptr)
207 -{
208 - if (is_phys_addr(ptr))
209 - kfree(ptr);
210 - else
211 - vfree(ptr);
212 + vfree(module_region);
213 }
214
215 int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
216 char *secstrings, struct module *mod)
217 {
218 - unsigned int symindex = 0;
219 - unsigned int core_size, init_size;
220 - int i;
221 -
222 - for (i = 1; i < hdr->e_shnum; i++)
223 - if (sechdrs[i].sh_type == SHT_SYMTAB)
224 - symindex = i;
225 -
226 - core_size = get_plt_size(hdr, sechdrs, secstrings, symindex, false);
227 - init_size = get_plt_size(hdr, sechdrs, secstrings, symindex, true);
228 -
229 - mod->arch.phys_plt_offset = 0;
230 - mod->arch.virt_plt_offset = 0;
231 - mod->arch.phys_plt_tbl = NULL;
232 - mod->arch.virt_plt_tbl = NULL;
233 -
234 - if ((core_size + init_size) == 0)
235 - return 0;
236 -
237 - mod->arch.phys_plt_tbl = __module_alloc(core_size + init_size, 1);
238 - if (!mod->arch.phys_plt_tbl)
239 - return -ENOMEM;
240 -
241 - mod->arch.virt_plt_tbl = __module_alloc(core_size + init_size, 0);
242 - if (!mod->arch.virt_plt_tbl) {
243 - __module_free(mod->arch.phys_plt_tbl);
244 - mod->arch.phys_plt_tbl = NULL;
245 - return -ENOMEM;
246 - }
247 -
248 return 0;
249 }
250
251 @@ -284,36 +95,28 @@
252 return 0;
253 }
254
255 -static Elf_Addr add_plt_entry_to(unsigned *plt_offset,
256 - void *start, Elf_Addr v)
257 +static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
258 {
259 - unsigned *tramp = start + *plt_offset;
260 - *plt_offset += 4 * sizeof(int);
261 -
262 - /* adjust carry for addiu */
263 - if (v & 0x00008000)
264 - v += 0x10000;
265 -
266 - tramp[0] = 0x3c190000 | (v >> 16); /* lui t9, hi16 */
267 - tramp[1] = 0x27390000 | (v & 0xffff); /* addiu t9, t9, lo16 */
268 - tramp[2] = 0x03200008; /* jr t9 */
269 - tramp[3] = 0x00000000; /* nop */
270 + if (v % 4) {
271 + pr_err("module %s: dangerous R_MIPS_26 REL relocation\n",
272 + me->name);
273 + return -ENOEXEC;
274 + }
275
276 - return (Elf_Addr) tramp;
277 -}
278 + if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
279 + printk(KERN_ERR
280 + "module %s: relocation overflow\n",
281 + me->name);
282 + return -ENOEXEC;
283 + }
284
285 -static Elf_Addr add_plt_entry(struct module *me, void *location, Elf_Addr v)
286 -{
287 - if (is_phys_addr(location))
288 - return add_plt_entry_to(&me->arch.phys_plt_offset,
289 - me->arch.phys_plt_tbl, v);
290 - else
291 - return add_plt_entry_to(&me->arch.virt_plt_offset,
292 - me->arch.virt_plt_tbl, v);
293 + *location = (*location & ~0x03ffffff) |
294 + ((*location + (v >> 2)) & 0x03ffffff);
295
296 + return 0;
297 }
298
299 -static int set_r_mips_26(struct module *me, u32 *location, u32 ofs, Elf_Addr v)
300 +static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
301 {
302 if (v % 4) {
303 pr_err("module %s: dangerous R_MIPS_26 RELArelocation\n",
304 @@ -322,31 +125,17 @@
305 }
306
307 if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
308 - v = add_plt_entry(me, location, v + (ofs << 2));
309 - if (!v) {
310 - printk(KERN_ERR
311 + printk(KERN_ERR
312 "module %s: relocation overflow\n",
313 me->name);
314 - return -ENOEXEC;
315 - }
316 - ofs = 0;
317 + return -ENOEXEC;
318 }
319
320 - *location = (*location & ~0x03ffffff) | ((ofs + (v >> 2)) & 0x03ffffff);
321 + *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff);
322
323 return 0;
324 }
325
326 -static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
327 -{
328 - return set_r_mips_26(me, location, *location & 0x03ffffff, v);
329 -}
330 -
331 -static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
332 -{
333 - return set_r_mips_26(me, location, 0, v);
334 -}
335 -
336 static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v)
337 {
338 struct mips_hi16 *n;
339 @@ -611,32 +400,11 @@
340 list_add(&me->arch.dbe_list, &dbe_list);
341 spin_unlock_irq(&dbe_lock);
342 }
343 -
344 - /* Get rid of the fixup trampoline if we're running the module
345 - * from physically mapped address space */
346 - if (me->arch.phys_plt_offset == 0) {
347 - __module_free(me->arch.phys_plt_tbl);
348 - me->arch.phys_plt_tbl = NULL;
349 - }
350 - if (me->arch.virt_plt_offset == 0) {
351 - __module_free(me->arch.virt_plt_tbl);
352 - me->arch.virt_plt_tbl = NULL;
353 - }
354 -
355 return 0;
356 }
357
358 void module_arch_cleanup(struct module *mod)
359 {
360 - if (mod->arch.phys_plt_tbl) {
361 - __module_free(mod->arch.phys_plt_tbl);
362 - mod->arch.phys_plt_tbl = NULL;
363 - }
364 - if (mod->arch.virt_plt_tbl) {
365 - __module_free(mod->arch.virt_plt_tbl);
366 - mod->arch.virt_plt_tbl = NULL;
367 - }
368 -
369 spin_lock_irq(&dbe_lock);
370 list_del(&mod->arch.dbe_list);
371 spin_unlock_irq(&dbe_lock);
This page took 0.05749 seconds and 5 git commands to generate.