Skip to content

Commit 41b402a

Browse files
Steven Rostedtrostedt
authored andcommitted
ftrace/recordmcount: Add helper function get_sym_str_and_relp()
The code to get the symbol, string, and relp pointers in the two functions sift_rel_mcount() and nop_mcount() are identical and also non-trivial. Moving this duplicate code into a single helper function makes the code easier to read and more maintainable. Cc: John Reiser <jreiser@bitwagon.com> Link: http://lkml.kernel.org/r/20110421023739.723658553@goodmis.org Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 37762cb commit 41b402a

1 file changed

Lines changed: 37 additions & 30 deletions

File tree

‎scripts/recordmcount.h‎

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#undef has_rel_mcount
3030
#undef tot_relsize
3131
#undef get_mcountsym
32+
#undef get_sym_str_and_relp
3233
#undef do_func
3334
#undef Elf_Addr
3435
#undef Elf_Ehdr
@@ -56,6 +57,7 @@
5657
# define __has_rel_mcount __has64_rel_mcount
5758
# define has_rel_mcount has64_rel_mcount
5859
# define tot_relsize tot64_relsize
60+
# define get_sym_str_and_relp get_sym_str_and_relp_64
5961
# define do_func do64
6062
# define get_mcountsym get_mcountsym_64
6163
# define is_fake_mcount is_fake_mcount64
@@ -86,6 +88,7 @@
8688
# define __has_rel_mcount __has32_rel_mcount
8789
# define has_rel_mcount has32_rel_mcount
8890
# define tot_relsize tot32_relsize
91+
# define get_sym_str_and_relp get_sym_str_and_relp_32
8992
# define do_func do32
9093
# define get_mcountsym get_mcountsym_32
9194
# define is_fake_mcount is_fake_mcount32
@@ -260,6 +263,29 @@ static unsigned get_mcountsym(Elf_Sym const *const sym0,
260263
return mcountsym;
261264
}
262265

266+
static void get_sym_str_and_relp(Elf_Shdr const *const relhdr,
267+
Elf_Ehdr const *const ehdr,
268+
Elf_Sym const **sym0,
269+
char const **str0,
270+
Elf_Rel const **relp)
271+
{
272+
Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
273+
+ (void *)ehdr);
274+
unsigned const symsec_sh_link = w(relhdr->sh_link);
275+
Elf_Shdr const *const symsec = &shdr0[symsec_sh_link];
276+
Elf_Shdr const *const strsec = &shdr0[w(symsec->sh_link)];
277+
Elf_Rel const *const rel0 = (Elf_Rel const *)(_w(relhdr->sh_offset)
278+
+ (void *)ehdr);
279+
280+
*sym0 = (Elf_Sym const *)(_w(symsec->sh_offset)
281+
+ (void *)ehdr);
282+
283+
*str0 = (char const *)(_w(strsec->sh_offset)
284+
+ (void *)ehdr);
285+
286+
*relp = rel0;
287+
}
288+
263289
/*
264290
* Look at the relocations in order to find the calls to mcount.
265291
* Accumulate the section offsets that are found, and their relocation info,
@@ -276,26 +302,16 @@ static uint_t *sift_rel_mcount(uint_t *mlocp,
276302
{
277303
uint_t *const mloc0 = mlocp;
278304
Elf_Rel *mrelp = *mrelpp;
279-
Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
280-
+ (void *)ehdr);
281-
unsigned const symsec_sh_link = w(relhdr->sh_link);
282-
Elf_Shdr const *const symsec = &shdr0[symsec_sh_link];
283-
Elf_Sym const *const sym0 = (Elf_Sym const *)(_w(symsec->sh_offset)
284-
+ (void *)ehdr);
285-
286-
Elf_Shdr const *const strsec = &shdr0[w(symsec->sh_link)];
287-
char const *const str0 = (char const *)(_w(strsec->sh_offset)
288-
+ (void *)ehdr);
289-
290-
Elf_Rel const *const rel0 = (Elf_Rel const *)(_w(relhdr->sh_offset)
291-
+ (void *)ehdr);
305+
Elf_Sym const *sym0;
306+
char const *str0;
307+
Elf_Rel const *relp;
292308
unsigned rel_entsize = _w(relhdr->sh_entsize);
293309
unsigned const nrel = _w(relhdr->sh_size) / rel_entsize;
294-
Elf_Rel const *relp = rel0;
295-
296310
unsigned mcountsym = 0;
297311
unsigned t;
298312

313+
get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);
314+
299315
for (t = nrel; t; --t) {
300316
if (!mcountsym)
301317
mcountsym = get_mcountsym(sym0, relp, str0);
@@ -331,27 +347,18 @@ static void nop_mcount(Elf_Shdr const *const relhdr,
331347
{
332348
Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
333349
+ (void *)ehdr);
334-
unsigned const symsec_sh_link = w(relhdr->sh_link);
335-
Elf_Shdr const *const symsec = &shdr0[symsec_sh_link];
336-
Elf_Sym const *const sym0 = (Elf_Sym const *)(_w(symsec->sh_offset)
337-
+ (void *)ehdr);
338-
339-
Elf_Shdr const *const strsec = &shdr0[w(symsec->sh_link)];
340-
char const *const str0 = (char const *)(_w(strsec->sh_offset)
341-
+ (void *)ehdr);
342-
343-
Elf_Rel const *const rel0 = (Elf_Rel const *)(_w(relhdr->sh_offset)
344-
+ (void *)ehdr);
350+
Elf_Sym const *sym0;
351+
char const *str0;
352+
Elf_Rel const *relp;
353+
Elf_Shdr const *const shdr = &shdr0[w(relhdr->sh_info)];
345354
unsigned rel_entsize = _w(relhdr->sh_entsize);
346355
unsigned const nrel = _w(relhdr->sh_size) / rel_entsize;
347-
Elf_Rel const *relp = rel0;
348-
349-
Elf_Shdr const *const shdr = &shdr0[w(relhdr->sh_info)];
350-
351356
unsigned mcountsym = 0;
352357
unsigned t;
353358
int once = 0;
354359

360+
get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);
361+
355362
for (t = nrel; t; --t) {
356363
int ret = -1;
357364

0 commit comments

Comments
 (0)