Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp1601859lqs; Sat, 15 Jun 2024 17:30:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiCWvgMfXNVJKIq+gU7FKRtB+SCMCSUdOyaoITcJurQNLwmYk1HAsFRgGaq/XoFl8cIxiMw7sSByVF/etMv07bqG1PUL6KOe8fINxUMA== X-Google-Smtp-Source: AGHT+IEY0SdggqsN1UVEE+GQPFxXvQ/dIvNL9GXlJqR8HVXIvib6VKOjHu0WkQ/SQjGLNp7g+Szi X-Received: by 2002:a05:6808:1407:b0:3d2:2d8c:2119 with SMTP id 5614622812f47-3d24e8f2a11mr7002311b6e.28.1718497817613; Sat, 15 Jun 2024 17:30:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718497817; cv=pass; d=google.com; s=arc-20160816; b=YUYW0bdNHSweyKB7D16EAJS8xQmRvd6Uddq5G31D0Pq09dEtOUEPZsnicVUAvrJtRd UqBMFDkrn4bj5zjV8bcweUgwNRjyS1PYo+gmdpT8xDbEDu04feGycuGX1yYDlg61pr6H pucjWAD8R3sbg+pWJS77Rqfy/At0IAD180sciHwsUI88Bb/nGRkxP6fSrq65rIi1jNqu tK1QnJQonSnQi0gGe309wt9YtXsvaTeDYgm8pxy6LP82WZcWAugLHzZwdya2CeDiQB6F G/P+fb5EhI5x1WR9qzCbDG4g999T20lL1zAJOpRQpEfwrh9tpfiq6SPjYtaMLSmMzeza uLeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=BTBbcROF1kvXaM6dZlPyFTcs4OHmLeqwYC/d1IExwvY=; fh=SxtnWxvKUwOVwVTQvyU8UCUUaoISwlxuFFYSVL9vOUc=; b=SI6QtRRwDAzBmGwUeuu5IVRwH5XLRF+9PUA6Gr3NF0lfFkPapv0FFQ5SRNY5V7zxYs CZOouU9VAQ27M/0CxpBbakvLTJyNpR+Mcm0G/NX40XzQT0Ms9TlscjRCg3akVpzC79Te MWteJE6bzp2K7GbrmryhenYE0X9o5ef2FIY1iwimMQzvMb5oh19G5cPTC/etDVUFa340 ctHgPt+i+Waz1JXaSCnMsYZ+hecymoLDVGJDoVvEKj0fX3U8dkP4nACKN8XILRZxnFbD DI1W6gay6i/+eqqeG8CMWuYGYw26HUMlvIXYGEf7SXsyFJ/jcV+Ls83B3tD45a4LIAO5 EcJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mm6K2Mwd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-216066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-70788b52dc2si1240418a12.827.2024.06.15.17.30.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 17:30:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-216066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=mm6K2Mwd; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-216066-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-216066-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2C116283145 for ; Sun, 16 Jun 2024 00:30:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24B464C92; Sun, 16 Jun 2024 00:30:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mm6K2Mwd" Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAC0223BF; Sun, 16 Jun 2024 00:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718497809; cv=none; b=c1oiSYZREK4gcd28txug6nz2CcTTV4/8M4LQtfL2JfedQhAdexdbSZSoTEmG86CbbwNCfQM7b6xlbon6ObfNyXrwUhmoujD/yElJNowWZWGZ35/2QMM6bKE6LdUzDRAIOA6+MfKUfE6LhjXN3s+LwVEoR5elss26Pn/p2d+xJbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718497809; c=relaxed/simple; bh=WY60PRAGN65hKOjuRFFy2T6DnCrZjrVj79ITXNKWAAo=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DQKyLuqy1QJ5MONexwRBTeoZh/+7nPfI5QyBksw0pB4N3cuVvg1jVXm3R/2r+IPMl9KTZEgdxPO6USp1rAZwDqxtdTNSm6/TiN/vRx/7VXjHK31FzYqPPK2OtklqlDaWRYx8VFZFgv6F5zCuDmjxFQHqD+C4gDCIe5Zs6g9Q854= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mm6K2Mwd; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-6e9f52e99c2so2551397a12.1; Sat, 15 Jun 2024 17:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718497807; x=1719102607; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BTBbcROF1kvXaM6dZlPyFTcs4OHmLeqwYC/d1IExwvY=; b=mm6K2MwdvYNRnRvjTUqHJ8WJtIu7yYwmSp4a2vAHYLlTnmclyL9VVodFGtlXfu1aVa 481yWHZEtw7KN6UnY2YQn+tH8MCYOp0/rSmZRcnoJ9fnofU3Vkf+ISD7diHd7abkUVwk 1ZudS38Ww8WyIUuWCNMaII/q+EF++8rGQ8RILJot44A7ghuyWEWR4L0ccUS3elwEJRG2 vxVnpRgx9qVTTavLQZgQ8NRoMLYzleiZAcBu2YceTT+1hxcl1PLonBuBdjtJ0NpHmWFp nCJC8x6mNdhoyogP4+JkQuZrQomSSFibbKTka62e0gP0uXzNaH4cVa1cJg0a9r40ah02 wS8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718497807; x=1719102607; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BTBbcROF1kvXaM6dZlPyFTcs4OHmLeqwYC/d1IExwvY=; b=ipByYQ+KL1YYUrCkYUzdVqVb2KggBqsVWDFp+8mJP/uEbxrUwdwr7LLZqAxw+FNWNe GugtQ1xno/JkOXZrYt0uKdXovLtQ4adPSzyp2ApSF4qrzMJ6QgVcMQPouJJVMxFYSc9H OeESXET52p9/Z5+ojPA6IPRpfpUN9/X/10SjJ8lZnANAMwbXVKghsEV7637654h9q7fs y/lMB475zgw9qH5weMBHyBkzazkq1tZy+WnI8yCOfzCE0tWfNLVCd8nNYptBnw6QrufH r4KGtchu9T92yXeALdnwO0l1pW0dtL74BOxu+aEg525o+nUdNMWDWhBkrr6AfG8gbHiS i0OA== X-Forwarded-Encrypted: i=1; AJvYcCWUprphPjXJybtezr3yvEaM8usm8yDGP+l8j8wzKeIs36mR/XEGWZ2B/QDledduQiAUE9t8yjeK1jBDPsH4PlWF3QgUgUnoxOu22Vf7jdGZNIqSIFj5tPbUXd/wL4bhnuYG X-Gm-Message-State: AOJu0YykNSKDJ0Fx1GxLTgi6+sOUgozxD6wmwTuBomB352AKf5POGYNY GYa9HLs/jcEx+TVJm8kKe55kABBko3LKPcQKF4QcJeTAJ7nyddv+ X-Received: by 2002:a05:6a20:8427:b0:1b5:d00e:98e3 with SMTP id adf61e73a8af0-1bae7d97c20mr6501499637.11.1718497806983; Sat, 15 Jun 2024 17:30:06 -0700 (PDT) Received: from ubuntu.localdomain ([240e:304:7697:ee96:7cea:342b:603a:c6]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c4a769be25sm8612448a91.35.2024.06.15.17.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jun 2024 17:30:06 -0700 (PDT) From: Donglin Peng To: ast@kernel.org Cc: daniel@iogearbox.net, song@kernel.org, andrii@kernel.org, eddyz87@gmail.com, haoluo@google.com, yonghong.song@linux.dev, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Donglin Peng Subject: [PATCH] libbpf: checking the btf_type kind when fixing variable offsets Date: Sat, 15 Jun 2024 17:29:58 -0700 Message-Id: <20240616002958.2095829-1-dolinux.peng@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit I encountered an issue when building the test_progs using the repository[1]: $ clang --version Ubuntu clang version 17.0.6 (++20231208085846+6009708b4367-1~exp1~20231208085949.74) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin $ pwd /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/ $ make test_progs V=1 ... /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/tools/sbin/bpftool gen object /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/ip_check_defrag.bpf.linked2.o /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/ip_check_defrag.bpf.linked1.o libbpf: failed to find symbol for variable 'bpf_dynptr_slice' in section '.ksyms' Error: failed to link '/work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/ip_check_defrag.bpf.linked1.o': No such file or directory (2) make: *** [Makefile:656: /work/Qemu/x86_64/linux-6.10-rc2/tools/testing/selftests/bpf/ip_check_defrag.skel.h] Error 254 After investigation, I found that the btf_types in the '.ksyms' section have a kind of BTF_KIND_FUNC instead of BTF_KIND_VAR: $ bpftool btf dump file ./ip_check_defrag.bpf.linked1.o ... [2] DATASEC '.ksyms' size=0 vlen=2 type_id=16 offset=0 size=0 (FUNC 'bpf_dynptr_from_skb') type_id=17 offset=0 size=0 (FUNC 'bpf_dynptr_slice') ... [16] FUNC 'bpf_dynptr_from_skb' type_id=82 linkage=extern [17] FUNC 'bpf_dynptr_slice' type_id=85 linkage=extern ... To fix this, we can a add check for the kind. [1] https://github.com/eddyz87/bpf/tree/binsort-btf-dedup Link: https://lore.kernel.org/all/4f551dc5fc792936ca364ce8324c0adea38162f1.camel@gmail.com/ Fixes: 8fd27bf69b86 ("libbpf: Add BPF static linker BTF and BTF.ext support") Signed-off-by: Donglin Peng --- tools/lib/bpf/linker.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c index 0d4be829551b..7f5fc9ac4ad6 100644 --- a/tools/lib/bpf/linker.c +++ b/tools/lib/bpf/linker.c @@ -2213,10 +2213,17 @@ static int linker_fixup_btf(struct src_obj *obj) vi = btf_var_secinfos(t); for (j = 0, m = btf_vlen(t); j < m; j++, vi++) { const struct btf_type *vt = btf__type_by_id(obj->btf, vi->type); - const char *var_name = btf__str_by_offset(obj->btf, vt->name_off); - int var_linkage = btf_var(vt)->linkage; + const char *var_name; + int var_linkage; Elf64_Sym *sym; + /* should be a variable */ + if (btf_kind(vt) != BTF_KIND_VAR) + continue; + + var_name = btf__str_by_offset(obj->btf, vt->name_off); + var_linkage = btf_var(vt)->linkage; + /* no need to patch up static or extern vars */ if (var_linkage != BTF_VAR_GLOBAL_ALLOCATED) continue; -- 2.25.1