modpost: use more reliable way to get fromsec in section_rel(a)()
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 30 Jul 2022 17:36:35 +0000 (02:36 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 3 Aug 2022 13:58:10 +0000 (22:58 +0900)
commit5419aa2a8deea06b796222d3215dac6adc270c78
treed97177c46418af4e852f04c2925ad5245970943c
parent125ed24a4ab0d704bab5dee5ccb2c3b05f627c78
modpost: use more reliable way to get fromsec in section_rel(a)()

The section name of Rel and Rela starts with ".rel" and ".rela"
respectively (but, I do not know whether this is specification or
convention).

For example, ".rela.text" holds relocation entries applied to the
".text" section.

So, the code chops the ".rel" or ".rela" prefix to get the name of
the section to which the relocation applies.

However, I do not like to skip 4 or 5 bytes blindly because it is
potential memory overrun.

The ELF specification provides a more reliable way to do this.

 - The sh_info field holds extra information, whose interpretation
   depends on the section type

 - If the section type is SHT_REL or SHT_RELA, the sh_info field holds
   the section header index of the section to which the relocation
   applies.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/mod/modpost.c