1 diff -urN linux-2.6.30.10/arch/mips/Makefile linux-2.6.30.10.new//arch/mips/Makefile
2 --- linux-2.6.30.10/arch/mips/Makefile 2010-01-29 16:12:01.000000000 +0100
3 +++ linux-2.6.30.10.new//arch/mips/Makefile 2009-12-04 07:00:07.000000000 +0100
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
11 cflags-y += -ffreestanding
13 diff -urN linux-2.6.30.10/arch/mips/include/asm/module.h linux-2.6.30.10.new//arch/mips/include/asm/module.h
14 --- linux-2.6.30.10/arch/mips/include/asm/module.h 2010-01-29 16:12:01.000000000 +0100
15 +++ linux-2.6.30.10.new//arch/mips/include/asm/module.h 2009-12-04 07:00:07.000000000 +0100
17 struct list_head dbe_list;
18 const struct exception_table_entry *dbe_start;
19 const struct exception_table_entry *dbe_end;
23 - unsigned int phys_plt_offset;
24 - unsigned int virt_plt_offset;
27 typedef uint8_t Elf64_Byte; /* Type for a 8-bit quantity. */
28 diff -urN linux-2.6.30.10/arch/mips/kernel/module.c linux-2.6.30.10.new//arch/mips/kernel/module.c
29 --- linux-2.6.30.10/arch/mips/kernel/module.c 2010-01-29 16:12:01.000000000 +0100
30 +++ linux-2.6.30.10.new//arch/mips/kernel/module.c 2009-12-04 07:00:07.000000000 +0100
32 static LIST_HEAD(dbe_list);
33 static DEFINE_SPINLOCK(dbe_lock);
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.
41 -get_plt_size(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
42 - const char *secstrings, unsigned int symindex, bool is_init)
44 - unsigned long ret = 0;
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;
52 - if (sechdrs[i].sh_type != SHT_REL
53 - && sechdrs[i].sh_type != SHT_RELA)
56 - /* Not a valid relocation section? */
57 - if (info >= hdr->e_shnum)
60 - /* Don't bother with non-allocated sections */
61 - if (!(sechdrs[info].sh_flags & SHF_ALLOC))
64 - /* If it's called *.init*, and we're not init, we're
66 - if ((strstr(secstrings + sechdrs[i].sh_name, ".init") != 0)
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);
75 - for (j = 0; j < size; ++j) {
78 - if (ELF_MIPS_R_TYPE(rel[j]) != R_MIPS_26)
81 - sym = syms + ELF_MIPS_R_SYM(rel[j]);
82 - if (!is_init && sym->st_shndx != SHN_UNDEF)
85 - ret += 4 * sizeof(int);
88 - Elf_Mips_Rela *rela = (void *) sechdrs[i].sh_addr;
89 - unsigned int size = sechdrs[i].sh_size / sizeof(*rela);
91 - for (j = 0; j < size; ++j) {
94 - if (ELF_MIPS_R_TYPE(rela[j]) != R_MIPS_26)
97 - sym = syms + ELF_MIPS_R_SYM(rela[j]);
98 - if (!is_init && sym->st_shndx != SHN_UNDEF)
101 - ret += 4 * sizeof(int);
109 -#ifndef MODULE_START
110 -static void *alloc_phys(unsigned long size)
116 - size = PAGE_ALIGN(size);
117 - order = get_order(size);
119 - page = alloc_pages(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN |
120 - __GFP_THISNODE, order);
124 - split_page(page, order);
126 - for (p = page + (size >> PAGE_SHIFT); p < page + (1 << order); ++p)
129 - return page_address(page);
133 -static void free_phys(void *ptr, unsigned long size)
138 - page = virt_to_page(ptr);
139 - end = page + (PAGE_ALIGN(size) >> PAGE_SHIFT);
141 - for (; page < end; ++page)
145 void *module_alloc(unsigned long size)
148 @@ -168,101 +58,23 @@
150 return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL);
157 - ptr = alloc_phys(size);
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 */
163 - return vmalloc(size);
169 -static inline bool is_phys_addr(void *ptr)
172 - return (KSEGX((unsigned long)ptr) == CKSEG0);
174 - return (KSEGX(ptr) == KSEG0);
175 + return vmalloc(size);
179 /* Free memory returned from module_alloc */
180 void module_free(struct module *mod, void *module_region)
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);
190 - vfree(module_region);
192 + vfree(module_region);
193 /* FIXME: If module_region == mod->init_region, trim exception
197 -static void *__module_alloc(int size, bool phys)
202 - ptr = kmalloc(size, GFP_KERNEL);
204 - ptr = vmalloc(size);
208 -static void __module_free(void *ptr)
210 - if (is_phys_addr(ptr))
216 int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
217 char *secstrings, struct module *mod)
219 - unsigned int symindex = 0;
220 - unsigned int core_size, init_size;
223 - for (i = 1; i < hdr->e_shnum; i++)
224 - if (sechdrs[i].sh_type == SHT_SYMTAB)
227 - core_size = get_plt_size(hdr, sechdrs, secstrings, symindex, false);
228 - init_size = get_plt_size(hdr, sechdrs, secstrings, symindex, true);
230 - mod->arch.phys_plt_offset = 0;
231 - mod->arch.virt_plt_offset = 0;
232 - mod->arch.phys_plt_tbl = NULL;
233 - mod->arch.virt_plt_tbl = NULL;
235 - if ((core_size + init_size) == 0)
238 - mod->arch.phys_plt_tbl = __module_alloc(core_size + init_size, 1);
239 - if (!mod->arch.phys_plt_tbl)
242 - mod->arch.virt_plt_tbl = __module_alloc(core_size + init_size, 0);
243 - if (!mod->arch.virt_plt_tbl) {
244 - __module_free(mod->arch.phys_plt_tbl);
245 - mod->arch.phys_plt_tbl = NULL;
256 -static Elf_Addr add_plt_entry_to(unsigned *plt_offset,
257 - void *start, Elf_Addr v)
258 +static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
260 - unsigned *tramp = start + *plt_offset;
262 - *plt_offset += 4 * sizeof(int);
264 - /* adjust carry for addiu */
265 - if (v & 0x00008000)
268 - tramp[0] = 0x3c190000 | (v >> 16); /* lui t9, hi16 */
269 - tramp[1] = 0x27390000 | (v & 0xffff); /* addiu t9, t9, lo16 */
270 - tramp[2] = 0x03200008; /* jr t9 */
271 - tramp[3] = 0x00000000; /* nop */
273 + printk(KERN_ERR "module %s: dangerous relocation\n", me->name);
277 - return (Elf_Addr) tramp;
279 + if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
281 + "module %s: relocation overflow\n",
286 -static Elf_Addr add_plt_entry(struct module *me, void *location, Elf_Addr v)
288 - if (is_phys_addr(location))
289 - return add_plt_entry_to(&me->arch.phys_plt_offset,
290 - me->arch.phys_plt_tbl, v);
292 - return add_plt_entry_to(&me->arch.virt_plt_offset,
293 - me->arch.virt_plt_tbl, v);
294 + *location = (*location & ~0x03ffffff) |
295 + ((*location + (v >> 2)) & 0x03ffffff);
300 -static int set_r_mips_26(struct module *me, u32 *location, u32 ofs, Elf_Addr v)
301 +static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
304 printk(KERN_ERR "module %s: dangerous relocation\n", me->name);
305 @@ -323,31 +125,17 @@
308 if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
309 - v = add_plt_entry(me, location, v + (ofs << 2));
313 "module %s: relocation overflow\n",
321 - *location = (*location & ~0x03ffffff) | ((ofs + (v >> 2)) & 0x03ffffff);
322 + *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff);
327 -static int apply_r_mips_26_rel(struct module *me, u32 *location, Elf_Addr v)
329 - return set_r_mips_26(me, location, *location & 0x03ffffff, v);
332 -static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v)
334 - return set_r_mips_26(me, location, 0, v);
337 static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v)
340 @@ -612,32 +400,11 @@
341 list_add(&me->arch.dbe_list, &dbe_list);
342 spin_unlock_irq(&dbe_lock);
345 - /* Get rid of the fixup trampoline if we're running the module
346 - * from physically mapped address space */
347 - if (me->arch.phys_plt_offset == 0) {
348 - __module_free(me->arch.phys_plt_tbl);
349 - me->arch.phys_plt_tbl = NULL;
351 - if (me->arch.virt_plt_offset == 0) {
352 - __module_free(me->arch.virt_plt_tbl);
353 - me->arch.virt_plt_tbl = NULL;
359 void module_arch_cleanup(struct module *mod)
361 - if (mod->arch.phys_plt_tbl) {
362 - __module_free(mod->arch.phys_plt_tbl);
363 - mod->arch.phys_plt_tbl = NULL;
365 - if (mod->arch.virt_plt_tbl) {
366 - __module_free(mod->arch.virt_plt_tbl);
367 - mod->arch.virt_plt_tbl = NULL;
370 spin_lock_irq(&dbe_lock);
371 list_del(&mod->arch.dbe_list);
372 spin_unlock_irq(&dbe_lock);