All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	<dwarves@vger.kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>, <bpf@vger.kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>, <kernel-team@fb.com>,
	Nick Desaulniers <ndesaulniers@google.com>
Subject: [PATCH dwarves] btf_encoder: Fix a dwarf type DW_ATE_unsigned_1024 to btf encoding issue
Date: Tue, 25 Apr 2023 22:50:30 -0700	[thread overview]
Message-ID: <20230426055030.3743074-1-yhs@fb.com> (raw)

Nick Desaulniers reported an issue ([1]) where an 128-byte sized type
(DW_ATE_unsigned_1024) cannot be encoded into BTF with failure message
likes below:
  $ pahole -J reduced.o
  [2] INT DW_ATE_unsigned_1024 Error emitting BTF type
  Encountered error while encoding BTF.
See [1] for how to reproduce the issue.

The failure is due to currently BTF int type only supports upto 16
bytes (__int128) and in this case the dwarf int type is 128-byte.

The DW_ATE_unsigned_1024 is not a normal type for variable/func
declaration etc. It is used in DW_AT_location. There are two
ways to resolve this issue.
  (1). If btf encoding is expected, remove all dwarf int types
       where btf encoding will failure, e.g., non-power-of-2
       bytes, or greater than 16 bytes.
  (2). do a sanitization in btf_encoder ([2]).

This patch uses method (2) since it is a simple fix in btf_encoder.
I checked my local built vmlinux with latest
bpf-next. There is only one instance of DW_ATE_unsigned_24 (used in
DW_AT_location) so I expect irregular int types should be very rare.

  [1] https://github.com/libbpf/libbpf/pull/680
  [2] commit 7d8e829f636f ("btf_encoder: Sanitize non-regular int base type")

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 btf_encoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/btf_encoder.c b/btf_encoder.c
index 65f6e71..1aa0ad0 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -394,7 +394,7 @@ static int32_t btf_encoder__add_base_type(struct btf_encoder *encoder, const str
 	 * these non-regular int types to avoid libbpf/kernel complaints.
 	 */
 	byte_sz = BITS_ROUNDUP_BYTES(bt->bit_size);
-	if (!byte_sz || (byte_sz & (byte_sz - 1))) {
+	if (!byte_sz || (byte_sz & (byte_sz - 1)) || byte_sz > 16) {
 		name = "__SANITIZED_FAKE_INT__";
 		byte_sz = 4;
 	}
-- 
2.34.1


             reply	other threads:[~2023-04-26  5:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  5:50 Yonghong Song [this message]
2023-04-26 18:09 ` [PATCH dwarves] btf_encoder: Fix a dwarf type DW_ATE_unsigned_1024 to btf encoding issue Nick Desaulniers
2023-04-26 20:49   ` Yonghong Song

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=20230426055030.3743074-1-yhs@fb.com \
    --to=yhs@fb.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=eddyz87@gmail.com \
    --cc=kernel-team@fb.com \
    --cc=ndesaulniers@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.