History

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.

Steven Rostedt committed 15 years ago

Commit 41b402a1 parent 37762cb1 file · +37 −30Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/recordmcount.h+37−30
@@ -29,6 +29,7 @@ · 28 unmodified lines
29#undef has_rel_mcount29#undef has_rel_mcount
30#undef tot_relsize30#undef tot_relsize
31#undef get_mcountsym31#undef get_mcountsym
32#undef get_sym_str_and_relp
32#undef do_func33#undef do_func
33#undef Elf_Addr34#undef Elf_Addr
34#undef Elf_Ehdr35#undef Elf_Ehdr
@@ -56,6 +57,7 @@ · 21 unmodified lines
56# define __has_rel_mcount __has64_rel_mcount57# define __has_rel_mcount __has64_rel_mcount
57# define has_rel_mcount has64_rel_mcount58# define has_rel_mcount has64_rel_mcount
58# define tot_relsize tot64_relsize59# define tot_relsize tot64_relsize
60# define get_sym_str_and_relp get_sym_str_and_relp_64
59# define do_func do6461# define do_func do64
60# define get_mcountsym get_mcountsym_6462# define get_mcountsym get_mcountsym_64
61# define is_fake_mcount is_fake_mcount6463# define is_fake_mcount is_fake_mcount64
@@ -86,6 +88,7 @@ · 24 unmodified lines
86# define __has_rel_mcount __has32_rel_mcount88# define __has_rel_mcount __has32_rel_mcount
87# define has_rel_mcount has32_rel_mcount89# define has_rel_mcount has32_rel_mcount
88# define tot_relsize tot32_relsize90# define tot_relsize tot32_relsize
91# define get_sym_str_and_relp get_sym_str_and_relp_32
89# define do_func do3292# define do_func do32
90# define get_mcountsym get_mcountsym_3293# define get_mcountsym get_mcountsym_32
91# define is_fake_mcount is_fake_mcount3294# define is_fake_mcount is_fake_mcount32
@@ -260,6 +263,29 @@ static unsigned get_mcountsym(Elf_Sym const *const sym0, · 168 unmodified lines
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, · 10 unmodified lines
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, · 29 unmodified lines
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