Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
modpost: add a helper to get data pointed by a symbol
Browse files Browse the repository at this point in the history
When CONFIG_MODULE_REL_CRCS is enabled, the value of __crc_* is not
an absolute value, but the address to the CRC data embedded in the
.rodata section.

Getting the data pointed by the symbol value is somewhat complex.
Split it out into a new helper, sym_get_data().

I will reuse it to refactor namespace_from_kstrtabns() in the next
commit.

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y authored and mvaisakh committed Mar 21, 2023
1 parent d42f40b commit 028cbbe
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ static const char *sec_name(struct elf_info *elf, int secindex)
return sech_name(elf, &elf->sechdrs[secindex]);
}

static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
{
Elf_Shdr *sechdr = &info->sechdrs[sym->st_shndx];
unsigned long offset;

offset = sym->st_value;
if (info->hdr->e_type != ET_REL)
offset -= sechdr->sh_addr;

return (void *)info->hdr + sechdr->sh_offset + offset;
}

#define strstarts(str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)

static enum export export_from_secname(struct elf_info *elf, unsigned int sec)
Expand Down Expand Up @@ -700,10 +712,7 @@ static void handle_modversions(struct module *mod, struct elf_info *info,
unsigned int *crcp;

/* symbol points to the CRC in the ELF object */
crcp = (void *)info->hdr + sym->st_value +
info->sechdrs[sym->st_shndx].sh_offset -
(info->hdr->e_type != ET_REL ?
info->sechdrs[sym->st_shndx].sh_addr : 0);
crcp = sym_get_data(info, sym);
crc = TO_NATIVE(*crcp);
}
sym_update_crc(symname + strlen("__crc_"), mod, crc,
Expand Down

0 comments on commit 028cbbe

Please sign in to comment.