public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v3 0/6] btf: refactor and add pruning option
@ 2024-05-30 21:32 David Faust
  2024-05-30 21:32 ` [PATCH v3 1/6] ctf, btf: restructure CTF/BTF emission David Faust
                   ` (5 more replies)
  0 siblings, 6 replies; 16+ messages in thread
From: David Faust @ 2024-05-30 21:32 UTC (permalink / raw)
  To: gcc-patches; +Cc: indu.bhagat, jose.marchesi, cupertino.miranda

[v2: https://gcc.gnu.org/pipermail/gcc-patches/2024-May/650482.html
 Changes from v2:
 - Handle -flto when generating BTF (in patch 1).  For LTO builds, BTF
   is emitted at early_finish as before.  For non-LTO builds, BTF will
   be emitted at (late) finish for all targets.
 - Move the option parsing change to allow -gbtf and -gctf together to
   the end of the series.  This patch is relatively separate from the
   other changes, and only depends upon patch 1.
 - Include Indu's various comments and suggestions throughout the
   series.
 - Fix a few GNU style issues with indentation and long lines.
 - Fix the special handling for .maps section variables in BTF in
   patch 4.  Previously the type marking was too aggressive, and undid
   nearly all the pruning in some kernel selftests.  In one test this
   fix reduced the emitted BTF from over 6000 types to about 200 types,
   very similar to clang's output for the same test.  ]

This patch series signficantly refactors the BTF generation in gcc,
making it simpler and easier to understand, extend and maintain.

It also introduces an optional algorithm to "prune" BTF information
before emission.  This pruning is meant to be used for BPF programs, to
alleviate the massive bloating of BTF information caused by including
Linux kernel internal headers.  The pruning is designed to be compatible
with the unconditional pruning performed  by the LLVM BPF backend when
generating BTF information.

While the changes are fairly significant, there is no actual change in
emitted BTF information (unless pruning is enabled), other than bug
fixes and small additions to the assembler debug comments.

Patch 1 restructures the emission of CTF and BTF information, with the
result that CTF is always completely generated and emitted before any
BTF-related procedures are run.  BTF emission is moved to late finish
for all targets, except when building with -flto.

Patch 2 changes the data structures shared by CTF and BTF to use
pointers rather than type IDs for all inter-type references.  This
change is completely transparent to both CTF and BTF.

Patch 3 heavily refactors btfout.cc to take advantage of the prior
changes and significantly simplify the BTF implementation.  The changes
are nearly transparent, however some small but important improvements
are also made possible by the refactor, such as fixing PR113566 for
non-LTO builds.

Patch 4 adds a new option to perform pruning of the BTF information
before emission.  This is intended to be used for BPF programs which
often include kernel headers, and in many cases reduces the size of
the resulting BTF information by a factor of 10.

Patch 5 makes BTF pruning work with BPF CO-RE, and enables the pruning
by default in the BPF backend.

Patch 6 takes advantage of the prior changes, and removes the
restriction on generating both CTF and BTF in the same compiler run,
allowing for any combinaion of -gdwarf, -gctf and -gbtf.

Tested on x86_64-linux-gnu, and on x86_64-linux-gnu host for
bpf-unknown-none target.

Also tested by compiling and runninng Linux kernel BPF selftests.
No known regressions.

David Faust (6):
  ctf, btf: restructure CTF/BTF emission
  ctf: use pointers instead of IDs internally
  btf: refactor and simplify implementation
  btf: add -fprune-btf option
  bpf,btf: enable BTF pruning by default for BPF
  opts: allow any combination of DWARF, CTF, BTF

 gcc/btfout.cc                                 | 1613 +++++++++--------
 gcc/common.opt                                |    4 +
 gcc/config/bpf/bpf.cc                         |    5 +
 gcc/config/bpf/btfext-out.cc                  |   14 +-
 gcc/config/bpf/core-builtins.cc               |   74 +-
 gcc/ctfc.cc                                   |  141 +-
 gcc/ctfc.h                                    |  113 +-
 gcc/ctfout.cc                                 |   22 +-
 gcc/doc/invoke.texi                           |   23 +
 gcc/dwarf2ctf.cc                              |  311 ++--
 gcc/dwarf2ctf.h                               |    2 +-
 gcc/dwarf2out.cc                              |    4 +-
 gcc/opts.cc                                   |   20 +-
 gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c  |   25 +
 gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c  |   33 +
 gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c  |   35 +
 .../gcc.dg/debug/btf/btf-prune-maps.c         |   20 +
 .../gcc.dg/debug/btf/btf-variables-5.c        |    6 +-
 include/btf.h                                 |    5 +
 19 files changed, 1420 insertions(+), 1050 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-1.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-2.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-3.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-prune-maps.c

-- 
2.43.0


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

end of thread, other threads:[~2024-06-05 22:16 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-30 21:32 [PATCH v3 0/6] btf: refactor and add pruning option David Faust
2024-05-30 21:32 ` [PATCH v3 1/6] ctf, btf: restructure CTF/BTF emission David Faust
2024-06-05  7:27   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 2/6] ctf: use pointers instead of IDs internally David Faust
2024-06-05  7:31   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 3/6] btf: refactor and simplify implementation David Faust
2024-06-05  7:41   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 4/6] btf: add -fprune-btf option David Faust
2024-05-31  7:07   ` Richard Biener
2024-05-31 15:57     ` David Faust
2024-05-31 16:24       ` Richard Biener
2024-06-05  7:56   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 5/6] bpf,btf: enable BTF pruning by default for BPF David Faust
2024-06-05 20:49   ` Indu Bhagat
2024-05-30 21:32 ` [PATCH v3 6/6] opts: allow any combination of DWARF, CTF, BTF David Faust
2024-06-05 22:16   ` Indu Bhagat

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 read-only IMAP folder(s) and NNTP newsgroup(s).