Dwarves Archive mirror
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: dwarves@vger.kernel.org, arnaldo.melo@gmail.com
Cc: bpf@vger.kernel.org, kernel-team@fb.com, ast@kernel.org,
	daniel@iogearbox.net, andrii@kernel.org, yhs@fb.com,
	Eduard Zingerman <eddyz87@gmail.com>
Subject: [RFC dwarves 0/1] pahole: Save header guard names when --header_guards_db is passed
Date: Wed, 26 Oct 2022 01:07:28 +0300	[thread overview]
Message-ID: <20221025220729.2293891-1-eddyz87@gmail.com> (raw)

This is a supporting change for a kernel RFC that should allow using
uapi headers with vmlinux.h. For this it is necessary to add
`#ifndef GUARD ... #ifdef` brackets around some types if those types
originate from uapi kernel headers.

For example:

include/uapi/linux/tcp.h:

  #ifndef _UAPI_LINUX_TCP_H
  #define _UAPI_LINUX_TCP_H
  ...
  union tcp_word_hdr {
	struct tcphdr hdr;
	__be32        words[5];
  };
  ...
  #endif /* _UAPI_LINUX_TCP_H */

vmlinux.h:

  ...
  #ifndef _UAPI_LINUX_TCP_H

  union tcp_word_hdr {
	struct tcphdr hdr;
	__be32 words[5];
  };

  #endif
  ...

The information about the GUARD names has to be encoded in BTF to
allow `bpftool` to generate it for a specific kernel binary.

This is achieved by adding a parameter `--header_guards_db` to pahole.
This parameter should point to a file that associates header file
names with names of a C pre-processor variables used as a double
include guards (dubbed as "header guard"s).

For each emitted type the DWARF attribute DW_AT_decl_file is checked,
when the file name is present in the header guards DB a fake
BTF_KIND_DECL_TAG record of the following form is emitted:
- type: the id of the emitted type;
- name_off: a string "header_guard:<guard>".

I'd like to cover this thing with a few unit tests but I don't see any
tests in the dwarves repository ([1]), could you please suggest the
right location?

I'm going to use a lore link to this thread in the kernel RFC email.
I will post a link to the kernel RFC as a reply in this thread as soon
as I have one. The change is not useful on it's own, so if kernel RFC
will not be accepted this one should not be accepted either.

Thanks,
Eduard

[1] https://github.com/acmel/dwarves

Eduard Zingerman (1):
  pahole: Save header guard names when --header_guards_db is passed

 btf_encoder.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++----
 btf_encoder.h |   3 +-
 dutil.c       |  20 +++++++---
 dutil.h       |   1 +
 dwarves.h     |   1 +
 pahole.c      |  99 +++++++++++++++++++++++++++++++++++++++++++++++-
 6 files changed, 210 insertions(+), 17 deletions(-)

-- 
2.34.1


             reply	other threads:[~2022-10-25 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 22:07 Eduard Zingerman [this message]
2022-10-25 22:07 ` [RFC dwarves 1/1] pahole: Save header guard names when --header_guards_db is passed Eduard Zingerman

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=20221025220729.2293891-1-eddyz87@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=arnaldo.melo@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dwarves@vger.kernel.org \
    --cc=kernel-team@fb.com \
    --cc=yhs@fb.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).