// SPDX-License-Identifier: GPL-2.0-only /* * recordmcount.c: construct a table of the locations of calls to 'mcount' * so that ftrace can find them quickly. * Copyright 2009 John F. Reiser <jreiser@BitWagon.com>. All rights reserved. * * Restructured to fit Linux format, as well as other updates: * Copyright 2010 Steven Rostedt <srostedt@redhat.com>, Red Hat Inc.
*/
/* * Strategy: alter the .o file in-place. * * Append a new STRTAB that has the new section names, followed by a new array * ElfXX_Shdr[] that has the new section headers, followed by the section * contents for __mcount_loc and its relocations. The old shstrtab strings, * and the old ElfXX_Shdr[] array, remain as "garbage" (commonly, a couple * kilobytes.) Subsequent processing by /bin/ld (or the kernel module loader) * will ignore the garbage regions, because they are not designated by the * new .e_shoff nor the new ElfXX_Shdr[]. [In order to remove the garbage, * then use "ld -r" to create a new file that omits the garbage.]
*/
staticint fd_map; /* File descriptor for file being modified. */ staticint mmap_failed; /* Boolean flag. */ staticchar gpfx; /* prefix for global symbol name (sometimes '_') */ staticstruct stat sb; /* Remember .st_size, etc. */ staticconstchar *altmcount; /* alternate mcount symbol name */ staticint warn_on_notrace_sect; /* warn when section has mcount not being recorded */ staticvoid *file_map; /* pointer of the mapped file */ staticvoid *file_end; /* pointer to the end of the mapped file */ staticint file_updated; /* flag to state file was changed */ staticvoid *file_ptr; /* current file pointer location */
staticvoid *file_append; /* added to the end of the file */ static size_t file_append_size; /* how much is added to end of file */
/* * Get the whole file as a programming convenience in order to avoid * malloc+lseek+read+free of many pieces. If successful, then mmap * avoids copying unused pieces; else just read the whole file. * Open for both read and write; new info will be appended to the file. * Use MAP_PRIVATE so that a few changes to the in-memory ElfXX_Ehdr * do not propagate to the file until an explicit overwrite at the last. * This preserves most aspects of consistency (all except .st_size) * for simultaneous readers of the file while we are appending to it. * However, multiple writers still are bad. We choose not to use * locking because it is expensive and the use case of kernel build * makes multiple writers unlikely.
*/ staticvoid *mmap_file(charconst *fname)
{ /* Avoid problems if early cleanup() */
fd_map = -1;
mmap_failed = 1;
file_map = NULL;
file_ptr = NULL;
file_updated = 0;
sb.st_size = 0;
staticint LARCH32_is_fake_mcount(Elf32_Rel const *rp)
{ switch (ELF64_R_TYPE(w(rp->r_info))) { case R_LARCH_MARK_LA: case R_LARCH_SOP_PUSH_PLT_PCREL: return 0;
}
return 1;
}
staticint LARCH64_is_fake_mcount(Elf64_Rel const *rp)
{ switch (ELF64_R_TYPE(w(rp->r_info))) { case R_LARCH_MARK_LA: case R_LARCH_SOP_PUSH_PLT_PCREL: return 0;
}
return 1;
}
/* 64-bit EM_MIPS has weird ELF64_Rela.r_info. * http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf * We interpret Table 29 Relocation Operation (Elf64_Rel, Elf64_Rela) [p.40] * to imply the order of the members; the spec does not say so. * typedef unsigned char Elf64_Byte; * fails on MIPS64 because their <elf.h> already has it!
*/
typedef uint8_t myElf64_Byte; /* Type for a 8-bit quantity. */
union mips_r_info {
Elf64_Xword r_info; struct {
Elf64_Word r_sym; /* Symbol index. */
myElf64_Byte r_ssym; /* Special symbol. */
myElf64_Byte r_type3; /* Third relocation. */
myElf64_Byte r_type2; /* Second relocation. */
myElf64_Byte r_type; /* First relocation. */
} r_mips;
};
/* Process each file in turn, allowing deep failure. */ for (i = optind; i < argc; i++) { char *file = argv[i]; int len;
/* * The file kernel/trace/ftrace.o references the mcount * function but does not call it. Since ftrace.o should * not be traced anyway, we just skip it.
*/
len = strlen(file); if (len >= ftrace_size &&
strcmp(file + (len - ftrace_size), ftrace) == 0) continue;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.