recordmcount.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /*
  2. * recordmcount.h
  3. *
  4. * This code was taken out of recordmcount.c written by
  5. * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved.
  6. *
  7. * The original code had the same algorithms for both 32bit
  8. * and 64bit ELF files, but the code was duplicated to support
  9. * the difference in structures that were used. This
  10. * file creates a macro of everything that is different between
  11. * the 64 and 32 bit code, such that by including this header
  12. * twice we can create both sets of functions by including this
  13. * header once with RECORD_MCOUNT_64 undefined, and again with
  14. * it defined.
  15. *
  16. * This conversion to macros was done by:
  17. * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
  18. *
  19. * Licensed under the GNU General Public License, version 2 (GPLv2).
  20. */
  21. #undef append_func
  22. #undef is_fake_mcount
  23. #undef fn_is_fake_mcount
  24. #undef MIPS_is_fake_mcount
  25. #undef mcount_adjust
  26. #undef sift_rel_mcount
  27. #undef nop_mcount
  28. #undef find_secsym_ndx
  29. #undef __has_rel_mcount
  30. #undef has_rel_mcount
  31. #undef tot_relsize
  32. #undef get_mcountsym
  33. #undef get_sym_str_and_relp
  34. #undef do_func
  35. #undef Elf_Addr
  36. #undef Elf_Ehdr
  37. #undef Elf_Shdr
  38. #undef Elf_Rel
  39. #undef Elf_Rela
  40. #undef Elf_Sym
  41. #undef ELF_R_SYM
  42. #undef Elf_r_sym
  43. #undef ELF_R_INFO
  44. #undef Elf_r_info
  45. #undef ELF_ST_BIND
  46. #undef ELF_ST_TYPE
  47. #undef fn_ELF_R_SYM
  48. #undef fn_ELF_R_INFO
  49. #undef uint_t
  50. #undef _w
  51. #undef _align
  52. #undef _size
  53. #ifdef RECORD_MCOUNT_64
  54. # define append_func append64
  55. # define sift_rel_mcount sift64_rel_mcount
  56. # define nop_mcount nop_mcount_64
  57. # define find_secsym_ndx find64_secsym_ndx
  58. # define __has_rel_mcount __has64_rel_mcount
  59. # define has_rel_mcount has64_rel_mcount
  60. # define tot_relsize tot64_relsize
  61. # define get_sym_str_and_relp get_sym_str_and_relp_64
  62. # define do_func do64
  63. # define get_mcountsym get_mcountsym_64
  64. # define is_fake_mcount is_fake_mcount64
  65. # define fn_is_fake_mcount fn_is_fake_mcount64
  66. # define MIPS_is_fake_mcount MIPS64_is_fake_mcount
  67. # define mcount_adjust mcount_adjust_64
  68. # define Elf_Addr Elf64_Addr
  69. # define Elf_Ehdr Elf64_Ehdr
  70. # define Elf_Shdr Elf64_Shdr
  71. # define Elf_Rel Elf64_Rel
  72. # define Elf_Rela Elf64_Rela
  73. # define Elf_Sym Elf64_Sym
  74. # define ELF_R_SYM ELF64_R_SYM
  75. # define Elf_r_sym Elf64_r_sym
  76. # define ELF_R_INFO ELF64_R_INFO
  77. # define Elf_r_info Elf64_r_info
  78. # define ELF_ST_BIND ELF64_ST_BIND
  79. # define ELF_ST_TYPE ELF64_ST_TYPE
  80. # define fn_ELF_R_SYM fn_ELF64_R_SYM
  81. # define fn_ELF_R_INFO fn_ELF64_R_INFO
  82. # define uint_t uint64_t
  83. # define _w w8
  84. # define _align 7u
  85. # define _size 8
  86. #else
  87. # define append_func append32
  88. # define sift_rel_mcount sift32_rel_mcount
  89. # define nop_mcount nop_mcount_32
  90. # define find_secsym_ndx find32_secsym_ndx
  91. # define __has_rel_mcount __has32_rel_mcount
  92. # define has_rel_mcount has32_rel_mcount
  93. # define tot_relsize tot32_relsize
  94. # define get_sym_str_and_relp get_sym_str_and_relp_32
  95. # define do_func do32
  96. # define get_mcountsym get_mcountsym_32
  97. # define is_fake_mcount is_fake_mcount32
  98. # define fn_is_fake_mcount fn_is_fake_mcount32
  99. # define MIPS_is_fake_mcount MIPS32_is_fake_mcount
  100. # define mcount_adjust mcount_adjust_32
  101. # define Elf_Addr Elf32_Addr
  102. # define Elf_Ehdr Elf32_Ehdr
  103. # define Elf_Shdr Elf32_Shdr
  104. # define Elf_Rel Elf32_Rel
  105. # define Elf_Rela Elf32_Rela
  106. # define Elf_Sym Elf32_Sym
  107. # define ELF_R_SYM ELF32_R_SYM
  108. # define Elf_r_sym Elf32_r_sym
  109. # define ELF_R_INFO ELF32_R_INFO
  110. # define Elf_r_info Elf32_r_info
  111. # define ELF_ST_BIND ELF32_ST_BIND
  112. # define ELF_ST_TYPE ELF32_ST_TYPE
  113. # define fn_ELF_R_SYM fn_ELF32_R_SYM
  114. # define fn_ELF_R_INFO fn_ELF32_R_INFO
  115. # define uint_t uint32_t
  116. # define _w w
  117. # define _align 3u
  118. # define _size 4
  119. #endif
  120. /* Functions and pointers that do_file() may override for specific e_machine. */
  121. static int fn_is_fake_mcount(Elf_Rel const *rp)
  122. {
  123. return 0;
  124. }
  125. static int (*is_fake_mcount)(Elf_Rel const *rp) = fn_is_fake_mcount;
  126. static uint_t fn_ELF_R_SYM(Elf_Rel const *rp)
  127. {
  128. return ELF_R_SYM(_w(rp->r_info));
  129. }
  130. static uint_t (*Elf_r_sym)(Elf_Rel const *rp) = fn_ELF_R_SYM;
  131. static void fn_ELF_R_INFO(Elf_Rel *const rp, unsigned sym, unsigned type)
  132. {
  133. rp->r_info = _w(ELF_R_INFO(sym, type));
  134. }
  135. static void (*Elf_r_info)(Elf_Rel *const rp, unsigned sym, unsigned type) = fn_ELF_R_INFO;
  136. static int mcount_adjust = 0;
  137. /*
  138. * MIPS mcount long call has 2 _mcount symbols, only the position of the 1st
  139. * _mcount symbol is needed for dynamic function tracer, with it, to disable
  140. * tracing(ftrace_make_nop), the instruction in the position is replaced with
  141. * the "b label" instruction, to enable tracing(ftrace_make_call), replace the
  142. * instruction back. So, here, we set the 2nd one as fake and filter it.
  143. *
  144. * c: 3c030000 lui v1,0x0 <--> b label
  145. * c: R_MIPS_HI16 _mcount
  146. * c: R_MIPS_NONE *ABS*
  147. * c: R_MIPS_NONE *ABS*
  148. * 10: 64630000 daddiu v1,v1,0
  149. * 10: R_MIPS_LO16 _mcount
  150. * 10: R_MIPS_NONE *ABS*
  151. * 10: R_MIPS_NONE *ABS*
  152. * 14: 03e0082d move at,ra
  153. * 18: 0060f809 jalr v1
  154. * label:
  155. */
  156. #define MIPS_FAKEMCOUNT_OFFSET 4
  157. static int MIPS_is_fake_mcount(Elf_Rel const *rp)
  158. {
  159. static Elf_Addr old_r_offset;
  160. Elf_Addr current_r_offset = _w(rp->r_offset);
  161. int is_fake;
  162. is_fake = old_r_offset &&
  163. (current_r_offset - old_r_offset == MIPS_FAKEMCOUNT_OFFSET);
  164. old_r_offset = current_r_offset;
  165. return is_fake;
  166. }
  167. /* Append the new shstrtab, Elf_Shdr[], __mcount_loc and its relocations. */
  168. static void append_func(Elf_Ehdr *const ehdr,
  169. Elf_Shdr *const shstr,
  170. uint_t const *const mloc0,
  171. uint_t const *const mlocp,
  172. Elf_Rel const *const mrel0,
  173. Elf_Rel const *const mrelp,
  174. unsigned int const rel_entsize,
  175. unsigned int const symsec_sh_link)
  176. {
  177. /* Begin constructing output file */
  178. Elf_Shdr mcsec;
  179. char const *mc_name = (sizeof(Elf_Rela) == rel_entsize)
  180. ? ".rela__mcount_loc"
  181. : ".rel__mcount_loc";
  182. unsigned const old_shnum = w2(ehdr->e_shnum);
  183. uint_t const old_shoff = _w(ehdr->e_shoff);
  184. uint_t const old_shstr_sh_size = _w(shstr->sh_size);
  185. uint_t const old_shstr_sh_offset = _w(shstr->sh_offset);
  186. uint_t t = 1 + strlen(mc_name) + _w(shstr->sh_size);
  187. uint_t new_e_shoff;
  188. shstr->sh_size = _w(t);
  189. shstr->sh_offset = _w(sb.st_size);
  190. t += sb.st_size;
  191. t += (_align & -t); /* word-byte align */
  192. new_e_shoff = t;
  193. /* body for new shstrtab */
  194. ulseek(fd_map, sb.st_size, SEEK_SET);
  195. uwrite(fd_map, old_shstr_sh_offset + (void *)ehdr, old_shstr_sh_size);
  196. uwrite(fd_map, mc_name, 1 + strlen(mc_name));
  197. /* old(modified) Elf_Shdr table, word-byte aligned */
  198. ulseek(fd_map, t, SEEK_SET);
  199. t += sizeof(Elf_Shdr) * old_shnum;
  200. uwrite(fd_map, old_shoff + (void *)ehdr,
  201. sizeof(Elf_Shdr) * old_shnum);
  202. /* new sections __mcount_loc and .rel__mcount_loc */
  203. t += 2*sizeof(mcsec);
  204. mcsec.sh_name = w((sizeof(Elf_Rela) == rel_entsize) + strlen(".rel")
  205. + old_shstr_sh_size);
  206. mcsec.sh_type = w(SHT_PROGBITS);
  207. mcsec.sh_flags = _w(SHF_ALLOC);
  208. mcsec.sh_addr = 0;
  209. mcsec.sh_offset = _w(t);
  210. mcsec.sh_size = _w((void *)mlocp - (void *)mloc0);
  211. mcsec.sh_link = 0;
  212. mcsec.sh_info = 0;
  213. mcsec.sh_addralign = _w(_size);
  214. mcsec.sh_entsize = _w(_size);
  215. uwrite(fd_map, &mcsec, sizeof(mcsec));
  216. mcsec.sh_name = w(old_shstr_sh_size);
  217. mcsec.sh_type = (sizeof(Elf_Rela) == rel_entsize)
  218. ? w(SHT_RELA)
  219. : w(SHT_REL);
  220. mcsec.sh_flags = 0;
  221. mcsec.sh_addr = 0;
  222. mcsec.sh_offset = _w((void *)mlocp - (void *)mloc0 + t);
  223. mcsec.sh_size = _w((void *)mrelp - (void *)mrel0);
  224. mcsec.sh_link = w(symsec_sh_link);
  225. mcsec.sh_info = w(old_shnum);
  226. mcsec.sh_addralign = _w(_size);
  227. mcsec.sh_entsize = _w(rel_entsize);
  228. uwrite(fd_map, &mcsec, sizeof(mcsec));
  229. uwrite(fd_map, mloc0, (void *)mlocp - (void *)mloc0);
  230. uwrite(fd_map, mrel0, (void *)mrelp - (void *)mrel0);
  231. ehdr->e_shoff = _w(new_e_shoff);
  232. ehdr->e_shnum = w2(2 + w2(ehdr->e_shnum)); /* {.rel,}__mcount_loc */
  233. ulseek(fd_map, 0, SEEK_SET);
  234. uwrite(fd_map, ehdr, sizeof(*ehdr));
  235. }
  236. static unsigned get_mcountsym(Elf_Sym const *const sym0,
  237. Elf_Rel const *relp,
  238. char const *const str0)
  239. {
  240. unsigned mcountsym = 0;
  241. Elf_Sym const *const symp =
  242. &sym0[Elf_r_sym(relp)];
  243. char const *symname = &str0[w(symp->st_name)];
  244. char const *mcount = gpfx == '_' ? "_mcount" : "mcount";
  245. if (symname[0] == '.')
  246. ++symname; /* ppc64 hack */
  247. if (strcmp(mcount, symname) == 0 ||
  248. (altmcount && strcmp(altmcount, symname) == 0))
  249. mcountsym = Elf_r_sym(relp);
  250. return mcountsym;
  251. }
  252. static void get_sym_str_and_relp(Elf_Shdr const *const relhdr,
  253. Elf_Ehdr const *const ehdr,
  254. Elf_Sym const **sym0,
  255. char const **str0,
  256. Elf_Rel const **relp)
  257. {
  258. Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
  259. + (void *)ehdr);
  260. unsigned const symsec_sh_link = w(relhdr->sh_link);
  261. Elf_Shdr const *const symsec = &shdr0[symsec_sh_link];
  262. Elf_Shdr const *const strsec = &shdr0[w(symsec->sh_link)];
  263. Elf_Rel const *const rel0 = (Elf_Rel const *)(_w(relhdr->sh_offset)
  264. + (void *)ehdr);
  265. *sym0 = (Elf_Sym const *)(_w(symsec->sh_offset)
  266. + (void *)ehdr);
  267. *str0 = (char const *)(_w(strsec->sh_offset)
  268. + (void *)ehdr);
  269. *relp = rel0;
  270. }
  271. /*
  272. * Look at the relocations in order to find the calls to mcount.
  273. * Accumulate the section offsets that are found, and their relocation info,
  274. * onto the end of the existing arrays.
  275. */
  276. static uint_t *sift_rel_mcount(uint_t *mlocp,
  277. unsigned const offbase,
  278. Elf_Rel **const mrelpp,
  279. Elf_Shdr const *const relhdr,
  280. Elf_Ehdr const *const ehdr,
  281. unsigned const recsym,
  282. uint_t const recval,
  283. unsigned const reltype)
  284. {
  285. uint_t *const mloc0 = mlocp;
  286. Elf_Rel *mrelp = *mrelpp;
  287. Elf_Sym const *sym0;
  288. char const *str0;
  289. Elf_Rel const *relp;
  290. unsigned rel_entsize = _w(relhdr->sh_entsize);
  291. unsigned const nrel = _w(relhdr->sh_size) / rel_entsize;
  292. unsigned mcountsym = 0;
  293. unsigned t;
  294. get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);
  295. for (t = nrel; t; --t) {
  296. if (!mcountsym)
  297. mcountsym = get_mcountsym(sym0, relp, str0);
  298. if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) {
  299. uint_t const addend =
  300. _w(_w(relp->r_offset) - recval + mcount_adjust);
  301. mrelp->r_offset = _w(offbase
  302. + ((void *)mlocp - (void *)mloc0));
  303. Elf_r_info(mrelp, recsym, reltype);
  304. if (rel_entsize == sizeof(Elf_Rela)) {
  305. ((Elf_Rela *)mrelp)->r_addend = addend;
  306. *mlocp++ = 0;
  307. } else
  308. *mlocp++ = addend;
  309. mrelp = (Elf_Rel *)(rel_entsize + (void *)mrelp);
  310. }
  311. relp = (Elf_Rel const *)(rel_entsize + (void *)relp);
  312. }
  313. *mrelpp = mrelp;
  314. return mlocp;
  315. }
  316. /*
  317. * Read the relocation table again, but this time its called on sections
  318. * that are not going to be traced. The mcount calls here will be converted
  319. * into nops.
  320. */
  321. static void nop_mcount(Elf_Shdr const *const relhdr,
  322. Elf_Ehdr const *const ehdr,
  323. const char *const txtname)
  324. {
  325. Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
  326. + (void *)ehdr);
  327. Elf_Sym const *sym0;
  328. char const *str0;
  329. Elf_Rel const *relp;
  330. Elf_Shdr const *const shdr = &shdr0[w(relhdr->sh_info)];
  331. unsigned rel_entsize = _w(relhdr->sh_entsize);
  332. unsigned const nrel = _w(relhdr->sh_size) / rel_entsize;
  333. unsigned mcountsym = 0;
  334. unsigned t;
  335. int once = 0;
  336. get_sym_str_and_relp(relhdr, ehdr, &sym0, &str0, &relp);
  337. for (t = nrel; t; --t) {
  338. int ret = -1;
  339. if (!mcountsym)
  340. mcountsym = get_mcountsym(sym0, relp, str0);
  341. if (mcountsym == Elf_r_sym(relp) && !is_fake_mcount(relp)) {
  342. if (make_nop)
  343. ret = make_nop((void *)ehdr, shdr->sh_offset + relp->r_offset);
  344. if (warn_on_notrace_sect && !once) {
  345. printf("Section %s has mcount callers being ignored\n",
  346. txtname);
  347. once = 1;
  348. /* just warn? */
  349. if (!make_nop)
  350. return;
  351. }
  352. }
  353. /*
  354. * If we successfully removed the mcount, mark the relocation
  355. * as a nop (don't do anything with it).
  356. */
  357. if (!ret) {
  358. Elf_Rel rel;
  359. rel = *(Elf_Rel *)relp;
  360. Elf_r_info(&rel, Elf_r_sym(relp), rel_type_nop);
  361. ulseek(fd_map, (void *)relp - (void *)ehdr, SEEK_SET);
  362. uwrite(fd_map, &rel, sizeof(rel));
  363. }
  364. relp = (Elf_Rel const *)(rel_entsize + (void *)relp);
  365. }
  366. }
  367. /*
  368. * Find a symbol in the given section, to be used as the base for relocating
  369. * the table of offsets of calls to mcount. A local or global symbol suffices,
  370. * but avoid a Weak symbol because it may be overridden; the change in value
  371. * would invalidate the relocations of the offsets of the calls to mcount.
  372. * Often the found symbol will be the unnamed local symbol generated by
  373. * GNU 'as' for the start of each section. For example:
  374. * Num: Value Size Type Bind Vis Ndx Name
  375. * 2: 00000000 0 SECTION LOCAL DEFAULT 1
  376. */
  377. static unsigned find_secsym_ndx(unsigned const txtndx,
  378. char const *const txtname,
  379. uint_t *const recvalp,
  380. Elf_Shdr const *const symhdr,
  381. Elf_Ehdr const *const ehdr)
  382. {
  383. Elf_Sym const *const sym0 = (Elf_Sym const *)(_w(symhdr->sh_offset)
  384. + (void *)ehdr);
  385. unsigned const nsym = _w(symhdr->sh_size) / _w(symhdr->sh_entsize);
  386. Elf_Sym const *symp;
  387. unsigned t;
  388. for (symp = sym0, t = nsym; t; --t, ++symp) {
  389. unsigned int const st_bind = ELF_ST_BIND(symp->st_info);
  390. if (txtndx == w2(symp->st_shndx)
  391. /* avoid STB_WEAK */
  392. && (STB_LOCAL == st_bind || STB_GLOBAL == st_bind)) {
  393. /* function symbols on ARM have quirks, avoid them */
  394. if (w2(ehdr->e_machine) == EM_ARM
  395. && ELF_ST_TYPE(symp->st_info) == STT_FUNC)
  396. continue;
  397. *recvalp = _w(symp->st_value);
  398. return symp - sym0;
  399. }
  400. }
  401. fprintf(stderr, "Cannot find symbol for section %d: %s.\n",
  402. txtndx, txtname);
  403. fail_file();
  404. }
  405. /* Evade ISO C restriction: no declaration after statement in has_rel_mcount. */
  406. static char const *
  407. __has_rel_mcount(Elf_Shdr const *const relhdr, /* is SHT_REL or SHT_RELA */
  408. Elf_Shdr const *const shdr0,
  409. char const *const shstrtab,
  410. char const *const fname)
  411. {
  412. /* .sh_info depends on .sh_type == SHT_REL[,A] */
  413. Elf_Shdr const *const txthdr = &shdr0[w(relhdr->sh_info)];
  414. char const *const txtname = &shstrtab[w(txthdr->sh_name)];
  415. if (strcmp("__mcount_loc", txtname) == 0) {
  416. fprintf(stderr, "warning: __mcount_loc already exists: %s\n",
  417. fname);
  418. succeed_file();
  419. }
  420. if (w(txthdr->sh_type) != SHT_PROGBITS ||
  421. !(_w(txthdr->sh_flags) & SHF_EXECINSTR))
  422. return NULL;
  423. return txtname;
  424. }
  425. static char const *has_rel_mcount(Elf_Shdr const *const relhdr,
  426. Elf_Shdr const *const shdr0,
  427. char const *const shstrtab,
  428. char const *const fname)
  429. {
  430. if (w(relhdr->sh_type) != SHT_REL && w(relhdr->sh_type) != SHT_RELA)
  431. return NULL;
  432. return __has_rel_mcount(relhdr, shdr0, shstrtab, fname);
  433. }
  434. static unsigned tot_relsize(Elf_Shdr const *const shdr0,
  435. unsigned nhdr,
  436. const char *const shstrtab,
  437. const char *const fname)
  438. {
  439. unsigned totrelsz = 0;
  440. Elf_Shdr const *shdrp = shdr0;
  441. char const *txtname;
  442. for (; nhdr; --nhdr, ++shdrp) {
  443. txtname = has_rel_mcount(shdrp, shdr0, shstrtab, fname);
  444. if (txtname && is_mcounted_section_name(txtname))
  445. totrelsz += _w(shdrp->sh_size);
  446. }
  447. return totrelsz;
  448. }
  449. /* Overall supervision for Elf32 ET_REL file. */
  450. static void
  451. do_func(Elf_Ehdr *const ehdr, char const *const fname, unsigned const reltype)
  452. {
  453. Elf_Shdr *const shdr0 = (Elf_Shdr *)(_w(ehdr->e_shoff)
  454. + (void *)ehdr);
  455. unsigned const nhdr = w2(ehdr->e_shnum);
  456. Elf_Shdr *const shstr = &shdr0[w2(ehdr->e_shstrndx)];
  457. char const *const shstrtab = (char const *)(_w(shstr->sh_offset)
  458. + (void *)ehdr);
  459. Elf_Shdr const *relhdr;
  460. unsigned k;
  461. /* Upper bound on space: assume all relevant relocs are for mcount. */
  462. unsigned const totrelsz = tot_relsize(shdr0, nhdr, shstrtab, fname);
  463. Elf_Rel *const mrel0 = umalloc(totrelsz);
  464. Elf_Rel * mrelp = mrel0;
  465. /* 2*sizeof(address) <= sizeof(Elf_Rel) */
  466. uint_t *const mloc0 = umalloc(totrelsz>>1);
  467. uint_t * mlocp = mloc0;
  468. unsigned rel_entsize = 0;
  469. unsigned symsec_sh_link = 0;
  470. for (relhdr = shdr0, k = nhdr; k; --k, ++relhdr) {
  471. char const *const txtname = has_rel_mcount(relhdr, shdr0,
  472. shstrtab, fname);
  473. if (txtname && is_mcounted_section_name(txtname)) {
  474. uint_t recval = 0;
  475. unsigned const recsym = find_secsym_ndx(
  476. w(relhdr->sh_info), txtname, &recval,
  477. &shdr0[symsec_sh_link = w(relhdr->sh_link)],
  478. ehdr);
  479. rel_entsize = _w(relhdr->sh_entsize);
  480. mlocp = sift_rel_mcount(mlocp,
  481. (void *)mlocp - (void *)mloc0, &mrelp,
  482. relhdr, ehdr, recsym, recval, reltype);
  483. } else if (txtname && (warn_on_notrace_sect || make_nop)) {
  484. /*
  485. * This section is ignored by ftrace, but still
  486. * has mcount calls. Convert them to nops now.
  487. */
  488. nop_mcount(relhdr, ehdr, txtname);
  489. }
  490. }
  491. if (mloc0 != mlocp) {
  492. append_func(ehdr, shstr, mloc0, mlocp, mrel0, mrelp,
  493. rel_entsize, symsec_sh_link);
  494. }
  495. free(mrel0);
  496. free(mloc0);
  497. }