Skip to content

Commit 77f9f57

Browse files
committed
modpost: factor out the common boilerplate of section_rel(a)
The first few lines of section_rel() and section_rela() are the same. They both retrieve the index of the section to which the relocaton applies, and skip known-good sections. This common code should be moved to check_sec_ref(). Avoid ugly casts when computing 'start' and 'stop', and also make the Elf_Rel and Elf_Rela pointers const. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
1 parent 29ae5c0 commit 77f9f57

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

scripts/mod/modpost.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,17 +1420,10 @@ static void get_rel_type_and_sym(struct elf_info *elf, uint64_t r_info,
14201420
}
14211421

14221422
static void section_rela(struct module *mod, struct elf_info *elf,
1423-
Elf_Shdr *sechdr)
1423+
unsigned int fsecndx, const char *fromsec,
1424+
const Elf_Rela *start, const Elf_Rela *stop)
14241425
{
1425-
Elf_Rela *rela;
1426-
unsigned int fsecndx = sechdr->sh_info;
1427-
const char *fromsec = sec_name(elf, fsecndx);
1428-
Elf_Rela *start = (void *)elf->hdr + sechdr->sh_offset;
1429-
Elf_Rela *stop = (void *)start + sechdr->sh_size;
1430-
1431-
/* if from section (name) is know good then skip it */
1432-
if (match(fromsec, section_white_list))
1433-
return;
1426+
const Elf_Rela *rela;
14341427

14351428
for (rela = start; rela < stop; rela++) {
14361429
Elf_Addr taddr, r_offset;
@@ -1460,17 +1453,10 @@ static void section_rela(struct module *mod, struct elf_info *elf,
14601453
}
14611454

14621455
static void section_rel(struct module *mod, struct elf_info *elf,
1463-
Elf_Shdr *sechdr)
1456+
unsigned int fsecndx, const char *fromsec,
1457+
const Elf_Rel *start, const Elf_Rel *stop)
14641458
{
1465-
Elf_Rel *rel;
1466-
unsigned int fsecndx = sechdr->sh_info;
1467-
const char *fromsec = sec_name(elf, fsecndx);
1468-
Elf_Rel *start = (void *)elf->hdr + sechdr->sh_offset;
1469-
Elf_Rel *stop = (void *)start + sechdr->sh_size;
1470-
1471-
/* if from section (name) is know good then skip it */
1472-
if (match(fromsec, section_white_list))
1473-
return;
1459+
const Elf_Rel *rel;
14741460

14751461
for (rel = start; rel < stop; rel++) {
14761462
Elf_Sym *tsym;
@@ -1525,10 +1511,26 @@ static void check_sec_ref(struct module *mod, struct elf_info *elf)
15251511

15261512
check_section(mod->name, elf, sechdr);
15271513
/* We want to process only relocation sections and not .init */
1528-
if (sechdr->sh_type == SHT_RELA)
1529-
section_rela(mod, elf, sechdr);
1530-
else if (sechdr->sh_type == SHT_REL)
1531-
section_rel(mod, elf, sechdr);
1514+
if (sechdr->sh_type == SHT_REL || sechdr->sh_type == SHT_RELA) {
1515+
/* section to which the relocation applies */
1516+
unsigned int secndx = sechdr->sh_info;
1517+
const char *secname = sec_name(elf, secndx);
1518+
const void *start, *stop;
1519+
1520+
/* If the section is known good, skip it */
1521+
if (match(secname, section_white_list))
1522+
continue;
1523+
1524+
start = sym_get_data_by_offset(elf, i, 0);
1525+
stop = start + sechdr->sh_size;
1526+
1527+
if (sechdr->sh_type == SHT_RELA)
1528+
section_rela(mod, elf, secndx, secname,
1529+
start, stop);
1530+
else
1531+
section_rel(mod, elf, secndx, secname,
1532+
start, stop);
1533+
}
15321534
}
15331535
}
15341536

0 commit comments

Comments
 (0)