[RFC][PATCH v5 49/51] objtool: mcount: Remove relocation size check

From: Matt Helsley
Date: Thu Jun 18 2020 - 16:41:35 EST


Rather than use the size of the relocations check the section
header type directly to see if the mcount relocations should
be rel or rela relocations.

Signed-off-by: Matt Helsley <mhelsley@xxxxxxxxxx>
---
tools/objtool/elf.c | 4 ++--
tools/objtool/elf.h | 2 +-
tools/objtool/mcount.c | 15 +++++----------
3 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 733e10d4a574..4948df31bba0 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -642,8 +642,8 @@ static int read_relocs(struct elf *elf)

sec->base->reloc = sec;
sec->mcountable = relocs_mcountable(sec);
- if (sec->mcountable && !elf->mcount_rel_entsize)
- elf->mcount_rel_entsize = sec->sh.sh_entsize;
+ if (sec->mcountable)
+ elf->mcount_r_addends = (sec->sh.sh_type == SHT_RELA);

nr_reloc = 0;
for (i = 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) {
diff --git a/tools/objtool/elf.h b/tools/objtool/elf.h
index 8ece1ca79cca..f298e327af01 100644
--- a/tools/objtool/elf.h
+++ b/tools/objtool/elf.h
@@ -87,8 +87,8 @@ struct elf {
Elf *elf;
GElf_Ehdr ehdr;
int fd;
- size_t mcount_rel_entsize;
bool changed;
+ bool mcount_r_addends;
char *name;
struct list_head sections;
DECLARE_HASHTABLE(symbol_hash, ELF_HASH_BITS);
diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c
index 9527924af56b..084bbc02de0c 100644
--- a/tools/objtool/mcount.c
+++ b/tools/objtool/mcount.c
@@ -368,22 +368,17 @@ static void fill_mcount_locs(GElf_Sxword r_offset, GElf_Addr **rbuf,
}

/* Overall supervision for Elf32 ET_REL file. */
-static int do_mcount(unsigned const reltype, size_t rela_size)
+static int do_mcount(unsigned const reltype)
{
- GElf_Sxword r_offset = 0;
-
struct section *sec, *mlocs, *mrels;
const char * const mc_name = "__mcount_loc";
-
- const unsigned int rel_entsize = lf->mcount_rel_entsize;
+ GElf_Sxword r_offset = 0;
int result = -1;
- bool is_rela;
+ const bool is_rela = lf->mcount_r_addends;

if (find_section_by_name(lf, "__mcount_loc") != NULL)
return 0;

- is_rela = (rela_size == rel_entsize);
-
/* add section: __mcount_loc */
mlocs = elf_create_section(lf, mc_name, sizeof(GElf_Addr), 0);
if (!mlocs)
@@ -562,7 +557,7 @@ static int do_file(char const *const fname)
is_fake_mcount = MIPS_is_fake_mcount;
}
loc_size = 4;
- rc = do_mcount(reltype, sizeof(Elf32_Rela));
+ rc = do_mcount(reltype);
break;
case ELFCLASS64: {
if (lf->ehdr.e_ehsize != sizeof(Elf64_Ehdr)
@@ -580,7 +575,7 @@ static int do_file(char const *const fname)
is_fake_mcount = MIPS_is_fake_mcount;
}
loc_size = 8;
- rc = do_mcount(reltype, sizeof(Elf64_Rela));
+ rc = do_mcount(reltype);
break;
}
} /* end switch */
--
2.20.1