Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Fix module.c build for 32 bit

Fixes build failure introduced by "Make most arch asm/module.h files use
asm-generic/module.h" by moving all the RELA processing code to a
separate file to be used only for RELA processing on 64-bit kernels.

CC arch/mips/kernel/module.o
arch/mips/kernel/module.c:250:14: error: 'reloc_handlers_rela' defined but not
used [-Werror=unused-variable]
cc1: all warnings being treated as errors

make[6]: *** [arch/mips/kernel/module.o] Error 1

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

authored by

Ralf Baechle and committed by
Rusty Russell
6ede8123 c99af375

+147 -120
+1
arch/mips/kernel/Makefile
··· 31 31 32 32 obj-$(CONFIG_STACKTRACE) += stacktrace.o 33 33 obj-$(CONFIG_MODULES) += mips_ksyms.o module.o 34 + obj-$(CONFIG_MODULES) += module-rela.o 34 35 35 36 obj-$(CONFIG_FUNCTION_TRACER) += mcount.o ftrace.o 36 37
+145
arch/mips/kernel/module-rela.c
··· 1 + /* 2 + * This program is free software; you can redistribute it and/or modify 3 + * it under the terms of the GNU General Public License as published by 4 + * the Free Software Foundation; either version 2 of the License, or 5 + * (at your option) any later version. 6 + * 7 + * This program is distributed in the hope that it will be useful, 8 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 + * GNU General Public License for more details. 11 + * 12 + * You should have received a copy of the GNU General Public License 13 + * along with this program; if not, write to the Free Software 14 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 + * 16 + * Copyright (C) 2001 Rusty Russell. 17 + * Copyright (C) 2003, 2004 Ralf Baechle (ralf@linux-mips.org) 18 + * Copyright (C) 2005 Thiemo Seufer 19 + */ 20 + 21 + #include <linux/elf.h> 22 + #include <linux/err.h> 23 + #include <linux/errno.h> 24 + #include <linux/moduleloader.h> 25 + 26 + extern int apply_r_mips_none(struct module *me, u32 *location, Elf_Addr v); 27 + 28 + static int apply_r_mips_32_rela(struct module *me, u32 *location, Elf_Addr v) 29 + { 30 + *location = v; 31 + 32 + return 0; 33 + } 34 + 35 + static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v) 36 + { 37 + if (v % 4) { 38 + pr_err("module %s: dangerous R_MIPS_26 RELArelocation\n", 39 + me->name); 40 + return -ENOEXEC; 41 + } 42 + 43 + if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) { 44 + printk(KERN_ERR 45 + "module %s: relocation overflow\n", 46 + me->name); 47 + return -ENOEXEC; 48 + } 49 + 50 + *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff); 51 + 52 + return 0; 53 + } 54 + 55 + static int apply_r_mips_hi16_rela(struct module *me, u32 *location, Elf_Addr v) 56 + { 57 + *location = (*location & 0xffff0000) | 58 + ((((long long) v + 0x8000LL) >> 16) & 0xffff); 59 + 60 + return 0; 61 + } 62 + 63 + static int apply_r_mips_lo16_rela(struct module *me, u32 *location, Elf_Addr v) 64 + { 65 + *location = (*location & 0xffff0000) | (v & 0xffff); 66 + 67 + return 0; 68 + } 69 + 70 + static int apply_r_mips_64_rela(struct module *me, u32 *location, Elf_Addr v) 71 + { 72 + *(Elf_Addr *)location = v; 73 + 74 + return 0; 75 + } 76 + 77 + static int apply_r_mips_higher_rela(struct module *me, u32 *location, 78 + Elf_Addr v) 79 + { 80 + *location = (*location & 0xffff0000) | 81 + ((((long long) v + 0x80008000LL) >> 32) & 0xffff); 82 + 83 + return 0; 84 + } 85 + 86 + static int apply_r_mips_highest_rela(struct module *me, u32 *location, 87 + Elf_Addr v) 88 + { 89 + *location = (*location & 0xffff0000) | 90 + ((((long long) v + 0x800080008000LL) >> 48) & 0xffff); 91 + 92 + return 0; 93 + } 94 + 95 + static int (*reloc_handlers_rela[]) (struct module *me, u32 *location, 96 + Elf_Addr v) = { 97 + [R_MIPS_NONE] = apply_r_mips_none, 98 + [R_MIPS_32] = apply_r_mips_32_rela, 99 + [R_MIPS_26] = apply_r_mips_26_rela, 100 + [R_MIPS_HI16] = apply_r_mips_hi16_rela, 101 + [R_MIPS_LO16] = apply_r_mips_lo16_rela, 102 + [R_MIPS_64] = apply_r_mips_64_rela, 103 + [R_MIPS_HIGHER] = apply_r_mips_higher_rela, 104 + [R_MIPS_HIGHEST] = apply_r_mips_highest_rela 105 + }; 106 + 107 + int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, 108 + unsigned int symindex, unsigned int relsec, 109 + struct module *me) 110 + { 111 + Elf_Mips_Rela *rel = (void *) sechdrs[relsec].sh_addr; 112 + Elf_Sym *sym; 113 + u32 *location; 114 + unsigned int i; 115 + Elf_Addr v; 116 + int res; 117 + 118 + pr_debug("Applying relocate section %u to %u\n", relsec, 119 + sechdrs[relsec].sh_info); 120 + 121 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { 122 + /* This is where to make the change */ 123 + location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr 124 + + rel[i].r_offset; 125 + /* This is the symbol it is referring to */ 126 + sym = (Elf_Sym *)sechdrs[symindex].sh_addr 127 + + ELF_MIPS_R_SYM(rel[i]); 128 + if (IS_ERR_VALUE(sym->st_value)) { 129 + /* Ignore unresolved weak symbol */ 130 + if (ELF_ST_BIND(sym->st_info) == STB_WEAK) 131 + continue; 132 + printk(KERN_WARNING "%s: Unknown symbol %s\n", 133 + me->name, strtab + sym->st_name); 134 + return -ENOENT; 135 + } 136 + 137 + v = sym->st_value + rel[i].r_addend; 138 + 139 + res = reloc_handlers_rela[ELF_MIPS_R_TYPE(rel[i])](me, location, v); 140 + if (res) 141 + return res; 142 + } 143 + 144 + return 0; 145 + }
+1 -120
arch/mips/kernel/module.c
··· 51 51 } 52 52 #endif 53 53 54 - static int apply_r_mips_none(struct module *me, u32 *location, Elf_Addr v) 54 + int apply_r_mips_none(struct module *me, u32 *location, Elf_Addr v) 55 55 { 56 56 return 0; 57 57 } ··· 59 59 static int apply_r_mips_32_rel(struct module *me, u32 *location, Elf_Addr v) 60 60 { 61 61 *location += v; 62 - 63 - return 0; 64 - } 65 - 66 - static int apply_r_mips_32_rela(struct module *me, u32 *location, Elf_Addr v) 67 - { 68 - *location = v; 69 62 70 63 return 0; 71 64 } ··· 84 91 return 0; 85 92 } 86 93 87 - static int apply_r_mips_26_rela(struct module *me, u32 *location, Elf_Addr v) 88 - { 89 - if (v % 4) { 90 - pr_err("module %s: dangerous R_MIPS_26 RELArelocation\n", 91 - me->name); 92 - return -ENOEXEC; 93 - } 94 - 95 - if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) { 96 - printk(KERN_ERR 97 - "module %s: relocation overflow\n", 98 - me->name); 99 - return -ENOEXEC; 100 - } 101 - 102 - *location = (*location & ~0x03ffffff) | ((v >> 2) & 0x03ffffff); 103 - 104 - return 0; 105 - } 106 - 107 94 static int apply_r_mips_hi16_rel(struct module *me, u32 *location, Elf_Addr v) 108 95 { 109 96 struct mips_hi16 *n; ··· 101 128 n->value = v; 102 129 n->next = me->arch.r_mips_hi16_list; 103 130 me->arch.r_mips_hi16_list = n; 104 - 105 - return 0; 106 - } 107 - 108 - static int apply_r_mips_hi16_rela(struct module *me, u32 *location, Elf_Addr v) 109 - { 110 - *location = (*location & 0xffff0000) | 111 - ((((long long) v + 0x8000LL) >> 16) & 0xffff); 112 131 113 132 return 0; 114 133 } ··· 182 217 return -ENOEXEC; 183 218 } 184 219 185 - static int apply_r_mips_lo16_rela(struct module *me, u32 *location, Elf_Addr v) 186 - { 187 - *location = (*location & 0xffff0000) | (v & 0xffff); 188 - 189 - return 0; 190 - } 191 - 192 - static int apply_r_mips_64_rela(struct module *me, u32 *location, Elf_Addr v) 193 - { 194 - *(Elf_Addr *)location = v; 195 - 196 - return 0; 197 - } 198 - 199 - static int apply_r_mips_higher_rela(struct module *me, u32 *location, 200 - Elf_Addr v) 201 - { 202 - *location = (*location & 0xffff0000) | 203 - ((((long long) v + 0x80008000LL) >> 32) & 0xffff); 204 - 205 - return 0; 206 - } 207 - 208 - static int apply_r_mips_highest_rela(struct module *me, u32 *location, 209 - Elf_Addr v) 210 - { 211 - *location = (*location & 0xffff0000) | 212 - ((((long long) v + 0x800080008000LL) >> 48) & 0xffff); 213 - 214 - return 0; 215 - } 216 - 217 220 static int (*reloc_handlers_rel[]) (struct module *me, u32 *location, 218 221 Elf_Addr v) = { 219 222 [R_MIPS_NONE] = apply_r_mips_none, ··· 189 256 [R_MIPS_26] = apply_r_mips_26_rel, 190 257 [R_MIPS_HI16] = apply_r_mips_hi16_rel, 191 258 [R_MIPS_LO16] = apply_r_mips_lo16_rel 192 - }; 193 - 194 - static int (*reloc_handlers_rela[]) (struct module *me, u32 *location, 195 - Elf_Addr v) = { 196 - [R_MIPS_NONE] = apply_r_mips_none, 197 - [R_MIPS_32] = apply_r_mips_32_rela, 198 - [R_MIPS_26] = apply_r_mips_26_rela, 199 - [R_MIPS_HI16] = apply_r_mips_hi16_rela, 200 - [R_MIPS_LO16] = apply_r_mips_lo16_rela, 201 - [R_MIPS_64] = apply_r_mips_64_rela, 202 - [R_MIPS_HIGHER] = apply_r_mips_higher_rela, 203 - [R_MIPS_HIGHEST] = apply_r_mips_highest_rela 204 259 }; 205 260 206 261 int apply_relocate(Elf_Shdr *sechdrs, const char *strtab, ··· 240 319 me->arch.r_mips_hi16_list = NULL; 241 320 242 321 return -ENOEXEC; 243 - } 244 - 245 - return 0; 246 - } 247 - 248 - int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, 249 - unsigned int symindex, unsigned int relsec, 250 - struct module *me) 251 - { 252 - Elf_Mips_Rela *rel = (void *) sechdrs[relsec].sh_addr; 253 - Elf_Sym *sym; 254 - u32 *location; 255 - unsigned int i; 256 - Elf_Addr v; 257 - int res; 258 - 259 - pr_debug("Applying relocate section %u to %u\n", relsec, 260 - sechdrs[relsec].sh_info); 261 - 262 - for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { 263 - /* This is where to make the change */ 264 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr 265 - + rel[i].r_offset; 266 - /* This is the symbol it is referring to */ 267 - sym = (Elf_Sym *)sechdrs[symindex].sh_addr 268 - + ELF_MIPS_R_SYM(rel[i]); 269 - if (IS_ERR_VALUE(sym->st_value)) { 270 - /* Ignore unresolved weak symbol */ 271 - if (ELF_ST_BIND(sym->st_info) == STB_WEAK) 272 - continue; 273 - printk(KERN_WARNING "%s: Unknown symbol %s\n", 274 - me->name, strtab + sym->st_name); 275 - return -ENOENT; 276 - } 277 - 278 - v = sym->st_value + rel[i].r_addend; 279 - 280 - res = reloc_handlers_rela[ELF_MIPS_R_TYPE(rel[i])](me, location, v); 281 - if (res) 282 - return res; 283 322 } 284 323 285 324 return 0;