Commit a68914a5 authored by Masahiro Yamada's avatar Masahiro Yamada

modpost: change return type of addend_*_rel()

Now that none of addend_*_rel() returns a meaningful value (the return
value is always 0), change all of them to return the value of r_addend.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
parent 783c55ae
...@@ -1257,21 +1257,18 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf, ...@@ -1257,21 +1257,18 @@ static void check_section_mismatch(struct module *mod, struct elf_info *elf,
tosec, taddr); tosec, taddr);
} }
static int addend_386_rel(uint32_t *location, Elf_Rela *r) static Elf_Addr addend_386_rel(uint32_t *location, Elf_Rela *r)
{ {
unsigned int r_typ = ELF_R_TYPE(r->r_info); unsigned int r_typ = ELF_R_TYPE(r->r_info);
switch (r_typ) { switch (r_typ) {
case R_386_32: case R_386_32:
r->r_addend = TO_NATIVE(*location); return TO_NATIVE(*location);
break;
case R_386_PC32: case R_386_PC32:
r->r_addend = TO_NATIVE(*location) + 4; return TO_NATIVE(*location) + 4;
break;
default:
r->r_addend = (Elf_Addr)(-1);
} }
return 0;
return (Elf_Addr)(-1);
} }
#ifndef R_ARM_CALL #ifndef R_ARM_CALL
...@@ -1315,7 +1312,7 @@ static int32_t sign_extend32(int32_t value, int index) ...@@ -1315,7 +1312,7 @@ static int32_t sign_extend32(int32_t value, int index)
return (int32_t)(value << shift) >> shift; return (int32_t)(value << shift) >> shift;
} }
static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) static Elf_Addr addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r)
{ {
unsigned int r_typ = ELF_R_TYPE(r->r_info); unsigned int r_typ = ELF_R_TYPE(r->r_info);
uint32_t inst, upper, lower, sign, j1, j2; uint32_t inst, upper, lower, sign, j1, j2;
...@@ -1325,22 +1322,19 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ...@@ -1325,22 +1322,19 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r)
case R_ARM_ABS32: case R_ARM_ABS32:
case R_ARM_REL32: case R_ARM_REL32:
inst = TO_NATIVE(*(uint32_t *)loc); inst = TO_NATIVE(*(uint32_t *)loc);
r->r_addend = inst + sym->st_value; return inst + sym->st_value;
break;
case R_ARM_MOVW_ABS_NC: case R_ARM_MOVW_ABS_NC:
case R_ARM_MOVT_ABS: case R_ARM_MOVT_ABS:
inst = TO_NATIVE(*(uint32_t *)loc); inst = TO_NATIVE(*(uint32_t *)loc);
offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff), offset = sign_extend32(((inst & 0xf0000) >> 4) | (inst & 0xfff),
15); 15);
r->r_addend = offset + sym->st_value; return offset + sym->st_value;
break;
case R_ARM_PC24: case R_ARM_PC24:
case R_ARM_CALL: case R_ARM_CALL:
case R_ARM_JUMP24: case R_ARM_JUMP24:
inst = TO_NATIVE(*(uint32_t *)loc); inst = TO_NATIVE(*(uint32_t *)loc);
offset = sign_extend32((inst & 0x00ffffff) << 2, 25); offset = sign_extend32((inst & 0x00ffffff) << 2, 25);
r->r_addend = offset + sym->st_value + 8; return offset + sym->st_value + 8;
break;
case R_ARM_THM_MOVW_ABS_NC: case R_ARM_THM_MOVW_ABS_NC:
case R_ARM_THM_MOVT_ABS: case R_ARM_THM_MOVT_ABS:
upper = TO_NATIVE(*(uint16_t *)loc); upper = TO_NATIVE(*(uint16_t *)loc);
...@@ -1350,8 +1344,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ...@@ -1350,8 +1344,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r)
((lower & 0x7000) >> 4) | ((lower & 0x7000) >> 4) |
(lower & 0x00ff), (lower & 0x00ff),
15); 15);
r->r_addend = offset + sym->st_value; return offset + sym->st_value;
break;
case R_ARM_THM_JUMP19: case R_ARM_THM_JUMP19:
/* /*
* Encoding T3: * Encoding T3:
...@@ -1372,8 +1365,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ...@@ -1372,8 +1365,7 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r)
((upper & 0x03f) << 12) | ((upper & 0x03f) << 12) |
((lower & 0x07ff) << 1), ((lower & 0x07ff) << 1),
20); 20);
r->r_addend = offset + sym->st_value + 4; return offset + sym->st_value + 4;
break;
case R_ARM_THM_CALL: case R_ARM_THM_CALL:
case R_ARM_THM_JUMP24: case R_ARM_THM_JUMP24:
/* /*
...@@ -1399,15 +1391,13 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r) ...@@ -1399,15 +1391,13 @@ static int addend_arm_rel(void *loc, Elf_Sym *sym, Elf_Rela *r)
((upper & 0x03ff) << 12) | ((upper & 0x03ff) << 12) |
((lower & 0x07ff) << 1), ((lower & 0x07ff) << 1),
24); 24);
r->r_addend = offset + sym->st_value + 4; return offset + sym->st_value + 4;
break;
default:
r->r_addend = (Elf_Addr)(-1);
} }
return 0;
return (Elf_Addr)(-1);
} }
static int addend_mips_rel(uint32_t *location, Elf_Rela *r) static Elf_Addr addend_mips_rel(uint32_t *location, Elf_Rela *r)
{ {
unsigned int r_typ = ELF_R_TYPE(r->r_info); unsigned int r_typ = ELF_R_TYPE(r->r_info);
uint32_t inst; uint32_t inst;
...@@ -1415,18 +1405,13 @@ static int addend_mips_rel(uint32_t *location, Elf_Rela *r) ...@@ -1415,18 +1405,13 @@ static int addend_mips_rel(uint32_t *location, Elf_Rela *r)
inst = TO_NATIVE(*location); inst = TO_NATIVE(*location);
switch (r_typ) { switch (r_typ) {
case R_MIPS_LO16: case R_MIPS_LO16:
r->r_addend = inst & 0xffff; return inst & 0xffff;
break;
case R_MIPS_26: case R_MIPS_26:
r->r_addend = (inst & 0x03ffffff) << 2; return (inst & 0x03ffffff) << 2;
break;
case R_MIPS_32: case R_MIPS_32:
r->r_addend = inst; return inst;
break;
default:
r->r_addend = (Elf_Addr)(-1);
} }
return 0; return (Elf_Addr)(-1);
} }
#ifndef EM_RISCV #ifndef EM_RISCV
...@@ -1513,6 +1498,7 @@ static void section_rel(struct module *mod, struct elf_info *elf, ...@@ -1513,6 +1498,7 @@ static void section_rel(struct module *mod, struct elf_info *elf,
for (rel = start; rel < stop; rel++) { for (rel = start; rel < stop; rel++) {
Elf_Sym *tsym; Elf_Sym *tsym;
Elf_Addr taddr = 0;
void *loc; void *loc;
r.r_offset = TO_NATIVE(rel->r_offset); r.r_offset = TO_NATIVE(rel->r_offset);
...@@ -1531,27 +1517,26 @@ static void section_rel(struct module *mod, struct elf_info *elf, ...@@ -1531,27 +1517,26 @@ static void section_rel(struct module *mod, struct elf_info *elf,
r.r_info = TO_NATIVE(rel->r_info); r.r_info = TO_NATIVE(rel->r_info);
r_sym = ELF_R_SYM(r.r_info); r_sym = ELF_R_SYM(r.r_info);
#endif #endif
r.r_addend = 0;
loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset); loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset);
tsym = elf->symtab_start + r_sym; tsym = elf->symtab_start + r_sym;
switch (elf->hdr->e_machine) { switch (elf->hdr->e_machine) {
case EM_386: case EM_386:
addend_386_rel(loc, &r); taddr = addend_386_rel(loc, &r);
break; break;
case EM_ARM: case EM_ARM:
addend_arm_rel(loc, tsym, &r); taddr = addend_arm_rel(loc, tsym, &r);
break; break;
case EM_MIPS: case EM_MIPS:
addend_mips_rel(loc, &r); taddr = addend_mips_rel(loc, &r);
break; break;
default: default:
fatal("Please add code to calculate addend for this architecture\n"); fatal("Please add code to calculate addend for this architecture\n");
} }
check_section_mismatch(mod, elf, tsym, check_section_mismatch(mod, elf, tsym,
fsecndx, fromsec, r.r_offset, r.r_addend); fsecndx, fromsec, r.r_offset, taddr);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment