[RFC][PATCH v4 16/32] objtool: mcount: Restrict using ehdr in append_func()

From: Matt Helsley
Date: Tue Jun 02 2020 - 15:51:20 EST


Use the ehdr parameter to append_func() to write the
ELF file's header but use the objtool ELF header data
as the basis for making changes. The makes it clearer
when we can switch from using the old recordmcount
wrapper to write the ELF file because ehdr will only
be passed on to uwrite() calls and those will get
replaced later.

Signed-off-by: Matt Helsley <mhelsley@xxxxxxxxxx>
---
tools/objtool/recordmcount.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/objtool/recordmcount.h b/tools/objtool/recordmcount.h
index 98cf9eea6074..7ebc617fb3a6 100644
--- a/tools/objtool/recordmcount.h
+++ b/tools/objtool/recordmcount.h
@@ -99,8 +99,8 @@ static int append_func(Elf_Ehdr *const ehdr,
char const *mc_name = (sizeof(Elf_Rela) == rel_entsize)
? ".rela__mcount_loc"
: ".rel__mcount_loc";
- unsigned const old_shnum = w2(ehdr->e_shnum);
- uint_t const old_shoff = _w(ehdr->e_shoff);
+ unsigned const old_shnum = lf->ehdr.e_shnum;
+ uint_t const old_shoff = lf->ehdr.e_shoff;
uint_t const old_shstr_sh_size = _w(shstr->sh_size);
uint_t const old_shstr_sh_offset = _w(shstr->sh_offset);
uint_t t = 1 + strlen(mc_name) + _w(shstr->sh_size);
@@ -167,7 +167,7 @@ static int append_func(Elf_Ehdr *const ehdr,
return -1;

ehdr->e_shoff = _w(new_e_shoff);
- ehdr->e_shnum = w2(2 + w2(ehdr->e_shnum)); /* {.rel,}__mcount_loc */
+ ehdr->e_shnum = w2(2 + lf->ehdr.e_shnum); /* {.rel,}__mcount_loc */
if (ulseek(0, SEEK_SET) < 0)
return -1;
if (uwrite(ehdr, sizeof(*ehdr)) < 0)
--
2.20.1