public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Faust <david.faust@oracle.com>
To: gcc-patches@gcc.gnu.org
Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com,
	cupertino.miranda@oracle.com
Subject: [PATCH v4 0/6] btf: refactor and add pruning option
Date: Tue, 11 Jun 2024 12:01:39 -0700	[thread overview]
Message-ID: <20240611190145.115887-1-david.faust@oracle.com> (raw)

[v3: https://gcc.gnu.org/pipermail/gcc-patches/2024-May/653165.html
 Changes from v3:
 - Address typos, comment fixes and other minor nits pointed out by
   Indu in patches 1-3 and 5.
 - Rename option added in patch 4 from -fprune-btf to -gprune-btf.
 - Reword commit message in patch 4 to better describe behavior of
   -gprune-btf between LTO and non-LTO builds.
 - Improve the option parsing in patch 6 using Indu's suggested
   approach.  Add a few tests for -gdwarf, -gbtf, -gctf interaction. ]

 Review status:
 - Patches 1-3 have been approved, not yet pushed.
 - The CTF/BTF portion of patch 5 has been approved; the remaining
   portion needs BPF backend reviewer approval.
 - Patches 4 and 6 need review.  Both have portions which I think
   need global maintainer approval. ]

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 -gprune-btf option
  bpf,btf: enable BTF pruning by default for BPF
  opts: allow any combination of DWARF, CTF, BTF

 gcc/btfout.cc                                 | 1615 +++++++++--------
 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                                   |  153 +-
 gcc/ctfc.h                                    |  113 +-
 gcc/ctfout.cc                                 |   22 +-
 gcc/doc/invoke.texi                           |   23 +
 gcc/dwarf2ctf.cc                              |  324 ++--
 gcc/dwarf2ctf.h                               |    2 +-
 gcc/dwarf2out.cc                              |    4 +-
 gcc/opts.cc                                   |   20 +-
 gcc/testsuite/gcc.dg/debug/btf/btf-3.c        |    8 +
 gcc/testsuite/gcc.dg/debug/btf/btf-4.c        |    8 +
 gcc/testsuite/gcc.dg/debug/btf/btf-5.c        |    9 +
 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 +
 22 files changed, 1457 insertions(+), 1065 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-3.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-4.c
 create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-5.c
 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


             reply	other threads:[~2024-06-11 19:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11 19:01 David Faust [this message]
2024-06-11 19:01 ` [PATCH v4 1/6] ctf, btf: restructure CTF/BTF emission David Faust
2024-06-11 19:01 ` [PATCH v4 2/6] ctf: use pointers instead of IDs internally David Faust
2024-06-11 19:01 ` [PATCH v4 3/6] btf: refactor and simplify implementation David Faust
2024-06-11 19:01 ` [PATCH v4 4/6] btf: add -gprune-btf option David Faust
2024-06-24 16:11   ` David Faust
2024-06-24 18:32     ` Indu Bhagat
2024-06-11 19:01 ` [PATCH v4 5/6] bpf,btf: enable BTF pruning by default for BPF David Faust
2024-06-12 16:55   ` Jose E. Marchesi
2024-06-12 17:40     ` David Faust
2024-06-12 18:46       ` Jose E. Marchesi
2024-06-11 19:01 ` [PATCH v4 6/6] opts: allow any combination of DWARF, CTF, BTF David Faust
2024-06-24 16:13   ` David Faust

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240611190145.115887-1-david.faust@oracle.com \
    --to=david.faust@oracle.com \
    --cc=cupertino.miranda@oracle.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=indu.bhagat@oracle.com \
    --cc=jose.marchesi@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).