aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/recordmcount.h
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2011-04-20 21:13:06 -0400
committerSteven Rostedt <rostedt@goodmis.org>2011-05-16 14:48:55 -0400
commit41b402a201a12efdff4acc990e023a89a409cd41 (patch)
treeedc7904cc777dc55d045759da04c2442b06f06f4 /scripts/recordmcount.h
parent37762cb9977626343b3cd1aab9146313c94748c2 (diff)
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>
Diffstat (limited to 'scripts/recordmcount.h')
-rw-r--r--scripts/recordmcount.h67
1 files changed, 37 insertions, 30 deletions
diff --git a/scripts/recordmcount.h b/scripts/recordmcount.h
index deb6a517638c..3c00faba745f 100644
--- a/scripts/recordmcount.h
+++ b/scripts/recordmcount.h
@@ -29,6 +29,7 @@
29#undef has_rel_mcount 29#undef has_rel_mcount
30#undef tot_relsize 30#undef tot_relsize
31#undef get_mcountsym 31#undef get_mcountsym
32#undef get_sym_str_and_relp
32#undef do_func 33#undef do_func
33#undef Elf_Addr 34#undef Elf_Addr
34#undef Elf_Ehdr 35#undef Elf_Ehdr
@@ -56,6 +57,7 @@
56# define __has_rel_mcount __has64_rel_mcount 57# define __has_rel_mcount __has64_rel_mcount
57# define has_rel_mcount has64_rel_mcount 58# define has_rel_mcount has64_rel_mcount
58# define tot_relsize tot64_relsize 59# define tot_relsize tot64_relsize
60# define get_sym_str_and_relp get_sym_str_and_relp_64
59# define do_func do64 61# define do_func do64
60# define get_mcountsym get_mcountsym_64 62# define get_mcountsym get_mcountsym_64
61# define is_fake_mcount is_fake_mcount64 63# define is_fake_mcount is_fake_mcount64
@@ -86,6 +88,7 @@
86# define __has_rel_mcount __has32_rel_mcount 88# define __has_rel_mcount __has32_rel_mcount
87# define has_rel_mcount has32_rel_mcount 89# define has_rel_mcount has32_rel_mcount
88# define tot_relsize tot32_relsize 90# define tot_relsize tot32_relsize
91# define get_sym_str_and_relp get_sym_str_and_relp_32
89# define do_func do32 92# define do_func do32
90# define get_mcountsym get_mcountsym_32 93# define get_mcountsym get_mcountsym_32
91# define is_fake_mcount is_fake_mcount32 94# define is_fake_mcount is_fake_mcount32
@@ -260,6 +263,29 @@ static unsigned get_mcountsym(Elf_Sym const *const sym0,
260 return mcountsym; 263 return mcountsym;
261} 264}
262 265
266static 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
263/* 289/*
264 * Look at the relocations in order to find the calls to mcount. 290 * Look at the relocations in order to find the calls to mcount.
265 * Accumulate the section offsets that are found, and their relocation info, 291 * Accumulate the section offsets that are found, and their relocation info,
@@ -276,26 +302,16 @@ static uint_t *sift_rel_mcount(uint_t *mlocp,
276{ 302{
277 uint_t *const mloc0 = mlocp; 303 uint_t *const mloc0 = mlocp;
278 Elf_Rel *mrelp = *mrelpp; 304 Elf_Rel *mrelp = *mrelpp;
279 Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff) 305 Elf_Sym const *sym0;
280 + (void *)ehdr); 306 char const *str0;
281 unsigned const symsec_sh_link = w(relhdr->sh_link); 307 Elf_Rel const *relp;
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);
292 unsigned rel_entsize = _w(relhdr->sh_entsize); 308 unsigned rel_entsize = _w(relhdr->sh_entsize);
293 unsigned const nrel = _w(relhdr->sh_size) / rel_entsize; 309 unsigned const nrel = _w(relhdr->sh_size) / rel_entsize;
294 Elf_Rel const *relp = rel0;
295
296 unsigned mcountsym = 0; 310 unsigned mcountsym = 0;
297 unsigned t; 311 unsigned t;
298 312
313 get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);
314
299 for (t = nrel; t; --t) { 315 for (t = nrel; t; --t) {
300 if (!mcountsym) 316 if (!mcountsym)
301 mcountsym = get_mcountsym(sym0, relp, str0); 317 mcountsym = get_mcountsym(sym0, relp, str0);
@@ -331,27 +347,18 @@ static void nop_mcount(Elf_Shdr const *const relhdr,
331{ 347{
332 Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff) 348 Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
333 + (void *)ehdr); 349 + (void *)ehdr);
334 unsigned const symsec_sh_link = w(relhdr->sh_link); 350 Elf_Sym const *sym0;
335 Elf_Shdr const *const symsec = &shdr0[symsec_sh_link]; 351 char const *str0;
336 Elf_Sym const *const sym0 = (Elf_Sym const *)(_w(symsec->sh_offset) 352 Elf_Rel const *relp;
337 + (void *)ehdr); 353 Elf_Shdr const *const shdr = &shdr0[w(relhdr->sh_info)];
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);
345 unsigned rel_entsize = _w(relhdr->sh_entsize); 354 unsigned rel_entsize = _w(relhdr->sh_entsize);
346 unsigned const nrel = _w(relhdr->sh_size) / rel_entsize; 355 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
351 unsigned mcountsym = 0; 356 unsigned mcountsym = 0;
352 unsigned t; 357 unsigned t;
353 int once = 0; 358 int once = 0;
354 359
360 get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);
361
355 for (t = nrel; t; --t) { 362 for (t = nrel; t; --t) {
356 int ret = -1; 363 int ret = -1;
357 364