Currently objtool uses a naming heuristic to find the "base"
section to apply the relocation(s) to. The standard defines
the SHF_INFO_LINK flag (SHF => in the section header flags)
which indicates when the section header's sh_info field can
be used to find the necessary section.

Warns when the heuristic is used as a fallback and changes
the name heuristic calculation to handle rela (explicit
addend) and now rel (implicit addend) relocations.

Signed-off-by: Matt Helsley <[email protected]>
---
 tools/objtool/elf.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 6fb9f83f7f66..a162bc383945 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -502,7 +502,13 @@ static int read_relocs(struct elf *elf)
                if (sec->sh.sh_type != SHT_RELA)
                        continue;
 
-               sec->base = find_section_by_name(elf, sec->name + 5);
+               if (sec->sh.sh_flags & SHF_INFO_LINK) {
+                       sec->base = find_section_by_index(elf, sec->sh.sh_info);
+               } else if (strncmp(sec->name, ".rel", 4) == 0) {
+                       WARN("Using naming heuristic to find base of reloc 
section %s",
+                            sec->name);
+                       sec->base = find_section_by_name(elf, sec->name + 5);
+               }
                if (!sec->base) {
                        WARN("can't find base section for reloc section %s",
                             sec->name);
-- 
2.20.1

Reply via email to