linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC][PATCH v5 00/51] objtool: Make recordmcount a subcommand
@ 2020-06-18 20:37 Matt Helsley
  2020-06-18 20:37 ` [RFC][PATCH v5 01/51] objtool: Factor out reasons to build objtool Matt Helsley
                   ` (51 more replies)
  0 siblings, 52 replies; 55+ messages in thread
From: Matt Helsley @ 2020-06-18 20:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Josh Poimboeuf, Peter Zijlstra, Steven Rostedt, Julien Thierry,
	Kamalesh Babulal, Matt Helsley

recordmcount has its own ELF wrapper code and could utilize
objtool's ELF code to more-portably handle architecture variations.
This series makes recordmcount a subcommand of objtool. It very
gradually converts recordmcount to become a subcommand of objtool and
then reuses parts of objtool's ELF code.

recordmcount maps the file in and collects simple information it needs to
append a section to the object file. The only part of the original file it
modifies is the address of new section tables -- interestingly enough this
resembles RCU in that we don't really trim the old tables so
much as unlink them via a critical offset and then rely on
future tooling, in this case, to drop the unused bits.

Much of the recordmcount ELF code is only reading and walking the data
structures to collect the mcount locations it records in a separate
area of memory. This means it's safe to mix access to the mapped
file with access to the objtool-style linked data
structures as we gradually convert it to using only the linked data
structures. Once the old ELF code is no longer in use we can drop it
and use objtool to take over the task of writing the results without
using the RCU-like trick any more.

After that we greatly simplify the mcount subcommand by adding a
few flags to the ELF reading code in objtool. Overall the series
removes about 600 lines of recordmcount while adding little to
objtool's ELF code.

Testing so far:

I've been using scripts to test cross compilation and execution of
objtool, and mcount on objects built for x86, ppc64le, arm64, s390, and
sparc.


Applies on top of:
	objtool/core

	Peter Zijlstra's "x86/entry: noinstr fixes" [2]

	Sami Tolvanen's patch enabling support for more than 64k
	sections in recordmcount, already going upstream. [3]

Changes since v4[1]:
v5:
	Updated the HAVE_C_RECORDMCOUNT Kconfig description.

	Removed unused extern is_cmd_mcount_available() spotted by Julien Thierry.

	Issue with symbol info handling reported and fixed by Kamalesh Babulal.

	Removed the giant per-supported-arch series of ifdef blocks in
	the objtool Makefile and replaced with new CONFIG_ variables
	as suggested by Julien Thierry.

	Moved the first pass through the sections into objtool's ELF
	code as suggested by Peter Zijlstra.

	Removed a redundant section lookup.

	Removed old comments that no longer apply since conversion to objtool.

v4:
	Split out recordmcount cleanups and upstreamed. [5]

	Split out, iterated on objtool multi-arch support, and upstreamed. [6]

	Split out expanded relocation support, renamed types, and functions
	to reflect expanded relocation support, and upstreamed. [4]

	This set is based on the patches sent upstream and posted above.

	Adapted to renames by Ingo and Peter: s/elf_open/elf_open_read/

	Added weak symbols for mcount subcommand
		This nicely eliminated the need for the mcount.h header.

	Added tools/objtool/Makefile per-arch SUBCMD_ blocks for each
		arch recordmcount / mcount supports.

	Moved ftrace/mcount/record.h from objtool_dep to recordmcount_dep
		This keeps the dependencies better organized.

	Fixed Makefile issue reported for PowerPC and a couple other archs
		by kbuild test robot. The always-$(BUILD_C_RECORDMCOUNT)
		line wasn't sufficiently replaced. Added to prepare-objtool
		target in top level Makefile.

	Split up dependencies to be independent of CONFIG_STACK_VALIDATION
		and CONFIG_UNWINDER_ORC since these are x86-specific.
		Now any arch which uses the C version of recordmcount
		will build objtool if dynamic tracing is enabled.

	Added a second rename at the end to be consistent with other
		objtool subcommands.

v3:
        Rebased on mainline. s/elf_open/elf_read/ in recordmcount.c

v2:
        Fix whitespace before line continuation

        Add ftrace/mcount/record.h to objtool_dep

        Rename the Makefile variable BUILD_C_RECORDMCOUNT to
            better reflect its purpose

        Similar: rename recordmcount_source => recordmcount_dep
            When using objtool we can just depend on the
            binary rather than the source the binary is
            built from. This should address Josh's feedback and
            make the Makefile code a bit clearer

        Add a comment to make reading the Makefile a little
            easier

        Rebased to latest mainline -rc

[1] https://lore.kernel.org/lkml/cover.1591125127.git.mhelsley@vmware.com/
[2] https://lore.kernel.org/lkml/20200618144407.520952071@infradead.org
[3] https://lore.kernel.org/lkml/20200424193046.160744-1-samitolvanen@google.com
[4] https://lore.kernel.org/lkml/cover.1590785960.git.mhelsley@vmware.com/
[5] https://lore.kernel.org/lkml/20190802134712.2d8cc63f@gandalf.local.home/
[6] https://lore.kernel.org/lkml/cover.1586468801.git.mhelsley@vmware.com/


Matt Helsley (51):
  objtool: Factor out reasons to build objtool
  objtool: Prepare to merge recordmcount
  objtool: Make recordmcount into mcount subcmd
  objtool: recordmcount: Start using objtool's elf wrapper
  objtool: recordmcount: Search for __mcount_loc before walking the
    sections
  objtool: recordmcount: Convert do_func() relhdrs
  objtool: mcount: Move nhdr into find_symtab()
  objtool: mcount: Remove unused fname parameter
  objtool: mcount: Use libelf for section header names
  objtool: mcount: Walk objtool Elf structs in find_secsym_ndx
  objtool: mcount: Use symbol structs to find mcount relocations
  objtool: mcount: Walk relocation lists
  objtool: mcount: Return symbol from mcountsym
  objtool: mcount: Move get_mcountsym
  objtool: mcount: Replace MIPS offset types
  objtool: mcount: Move is_fake_mcount()
  objtool: mcount: Stop using ehdr in find_section_sym_index
  objtool: mcount: Move find_section_sym_index()
  objtool: mcount: Restrict using ehdr in append_func()
  objtool: mcount: Use objtool ELF to write
  objtool: mcount: Move nop_mcount()
  objtool: mcount: Move has_rel_mcount() and tot_relsize()
  objtool: mcount: Move relocation entry size detection
  objtool: mcount: Only keep ELF file size
  objtool: mcount: Use ELF header from objtool
  objtool: mcount: Remove unused file mapping
  objtool: mcount: Reduce usage of _size wrapper
  objtool: mcount: Move mcount_adjust out of wrapper
  objtool: mcount: Pre-allocate new ELF sections
  objtool: mcount: Generic location and relocation table types
  objtool: mcount: Use objtool relocation section
  objtool: mcount: Move sift_rel_mcount out of wrapper file
  objtool: mcount: Remove wrapper for ELF relocation type
  objtool: mcount: Remove wrapper double-include trick
  objtool: mcount: Remove endian wrappers
  objtool: mcount: Rename to mcount.c
  objtool: mcount: Simplify mcount name matching
  objtool: mcount: mcount symbol name simplification
  objtool: mcount: Verify x86 instruction with memcmp()
  objtool: mcount: const-ify ARM instruction patterns
  objtool: mcount: Convert nop writes to elf_write_insn()
  objtool: mcount: Move mcount symbol name testing
  objtool: check: Use class to recognize kcov calls
  objtool: mcount: Keep lists locations and relocations
  objtool: mcount: Move mcount section test to objtool ELF
  objtool: mcount: Flag mcount relocation sections
  objtool: mcount: Merge section mcount flags
  objtool: mcount: Eliminate first pass
  objtool: mcount: Remove relocation size check
  objtool: mcount: Remove useless lookup
  objtool: mcount: Remove stale description

 Documentation/dontdiff                     |   2 +-
 Documentation/trace/ftrace-design.rst      |   4 +-
 Documentation/trace/ftrace.rst             |   6 +-
 Makefile                                   |  39 +-
 arch/Kconfig                               |  23 +
 arch/arm64/include/asm/ftrace.h            |   2 +-
 arch/x86/Kconfig.debug                     |   1 +
 arch/x86/include/asm/ftrace.h              |   2 +-
 kernel/trace/Kconfig                       |   9 +-
 lib/Kconfig.debug                          |   1 +
 scripts/.gitignore                         |   1 -
 scripts/Makefile                           |   1 -
 scripts/Makefile.build                     |  22 +-
 scripts/recordmcount.c                     | 663 --------------------
 scripts/recordmcount.h                     | 692 ---------------------
 scripts/sorttable.h                        |   2 +-
 tools/objtool/.gitignore                   |   1 +
 tools/objtool/Build                        |   2 +
 tools/objtool/Makefile                     |  14 +-
 tools/objtool/builtin-mcount.c             |  50 ++
 tools/objtool/builtin.h                    |   1 +
 tools/objtool/check.c                      |   3 +-
 tools/objtool/elf.c                        |  60 +-
 tools/objtool/elf.h                        |  12 +-
 tools/objtool/mcount.c                     | 596 ++++++++++++++++++
 tools/objtool/objtool.c                    |   1 +
 tools/objtool/objtool.h                    |   1 +
 {scripts => tools/objtool}/recordmcount.pl |   0
 tools/objtool/weak.c                       |   5 +
 29 files changed, 806 insertions(+), 1410 deletions(-)
 delete mode 100644 scripts/recordmcount.c
 delete mode 100644 scripts/recordmcount.h
 create mode 100644 tools/objtool/builtin-mcount.c
 create mode 100644 tools/objtool/mcount.c
 rename {scripts => tools/objtool}/recordmcount.pl (100%)


base-commit: 14bda4e5293ed9722f1dc39b543024e37707d6c6
prerequisite-patch-id: b9f6483185e4e80fccbb6ec7276bf61ce0329472
prerequisite-patch-id: 6d3fec64974cdce64fec35141ff71f0532cb8c82
prerequisite-patch-id: b71e084f3d2adeb4d05e4327183b75b388a20e6d
prerequisite-patch-id: 261f5d8102f4ecee86df2eb93be6a29495702717
prerequisite-patch-id: 64fa3e2f92e5dfd1b64289b4118288b6d2a25a67
prerequisite-patch-id: e5671d612490912b263505907657f3197c4a0833
prerequisite-patch-id: cba407d3dc82ad54095a9b5149b0c851c4e30b19
prerequisite-patch-id: bcf669a844506eec601cba1797f954e59cc7a2ad
-- 
2.20.1


^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2020-06-25 10:39 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 20:37 [RFC][PATCH v5 00/51] objtool: Make recordmcount a subcommand Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 01/51] objtool: Factor out reasons to build objtool Matt Helsley
2020-06-24 15:37   ` Miroslav Benes
2020-06-18 20:37 ` [RFC][PATCH v5 02/51] objtool: Prepare to merge recordmcount Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 03/51] objtool: Make recordmcount into mcount subcmd Matt Helsley
2020-06-25 10:39   ` Miroslav Benes
2020-06-18 20:37 ` [RFC][PATCH v5 04/51] objtool: recordmcount: Start using objtool's elf wrapper Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 05/51] objtool: recordmcount: Search for __mcount_loc before walking the sections Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 06/51] objtool: recordmcount: Convert do_func() relhdrs Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 07/51] objtool: mcount: Move nhdr into find_symtab() Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 08/51] objtool: mcount: Remove unused fname parameter Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 09/51] objtool: mcount: Use libelf for section header names Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 10/51] objtool: mcount: Walk objtool Elf structs in find_secsym_ndx Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 11/51] objtool: mcount: Use symbol structs to find mcount relocations Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 12/51] objtool: mcount: Walk relocation lists Matt Helsley
2020-06-18 20:37 ` [RFC][PATCH v5 13/51] objtool: mcount: Return symbol from mcountsym Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 14/51] objtool: mcount: Move get_mcountsym Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 15/51] objtool: mcount: Replace MIPS offset types Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 16/51] objtool: mcount: Move is_fake_mcount() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 17/51] objtool: mcount: Stop using ehdr in find_section_sym_index Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 18/51] objtool: mcount: Move find_section_sym_index() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 19/51] objtool: mcount: Restrict using ehdr in append_func() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 20/51] objtool: mcount: Use objtool ELF to write Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 21/51] objtool: mcount: Move nop_mcount() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 22/51] objtool: mcount: Move has_rel_mcount() and tot_relsize() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 23/51] objtool: mcount: Move relocation entry size detection Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 24/51] objtool: mcount: Only keep ELF file size Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 25/51] objtool: mcount: Use ELF header from objtool Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 26/51] objtool: mcount: Remove unused file mapping Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 27/51] objtool: mcount: Reduce usage of _size wrapper Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 28/51] objtool: mcount: Move mcount_adjust out of wrapper Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 29/51] objtool: mcount: Pre-allocate new ELF sections Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 30/51] objtool: mcount: Generic location and relocation table types Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 31/51] objtool: mcount: Use objtool relocation section Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 32/51] objtool: mcount: Move sift_rel_mcount out of wrapper file Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 33/51] objtool: mcount: Remove wrapper for ELF relocation type Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 34/51] objtool: mcount: Remove wrapper double-include trick Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 35/51] objtool: mcount: Remove endian wrappers Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 36/51] objtool: mcount: Rename to mcount.c Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 37/51] objtool: mcount: Simplify mcount name matching Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 38/51] objtool: mcount: mcount symbol name simplification Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 39/51] objtool: mcount: Verify x86 instruction with memcmp() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 40/51] objtool: mcount: const-ify ARM instruction patterns Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 41/51] objtool: mcount: Convert nop writes to elf_write_insn() Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 42/51] objtool: mcount: Move mcount symbol name testing Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 43/51] objtool: check: Use class to recognize kcov calls Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 44/51] objtool: mcount: Keep lists locations and relocations Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 45/51] objtool: mcount: Move mcount section test to objtool ELF Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 46/51] objtool: mcount: Flag mcount relocation sections Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 47/51] objtool: mcount: Merge section mcount flags Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 48/51] objtool: mcount: Eliminate first pass Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 49/51] objtool: mcount: Remove relocation size check Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 50/51] objtool: mcount: Remove useless lookup Matt Helsley
2020-06-18 20:38 ` [RFC][PATCH v5 51/51] objtool: mcount: Remove stale description Matt Helsley
2020-06-23 14:12 ` [RFC][PATCH v5 00/51] objtool: Make recordmcount a subcommand Matt Helsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).