From patchwork Fri Oct 4 17:26:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13822846 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AE86157492; Fri, 4 Oct 2024 17:26:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062804; cv=fail; b=IJ3ceMx6R2MrU9lM6BzbUgdYJNahXk+uUlfFU8EXlp03oISDKdUv7ASWETXcj+TcHuztyWacPikRvOnUbkVyQJoA8gZgxPzt9BjzeAs0O5pTnYJTXCxDxYDuhoxkwCdGsmIRcS+SuOa4f9xojo7KEvpqJIe+/5ko204CT0k18fc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062804; c=relaxed/simple; bh=J/tCs23VsC3IAq9AyVx1T2jOdLDQN1dct4b3x9QbPvE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=D2caFZGFl/Wu9+dqqlLCUduTuamnDdTRT2HsXxDxGI3/oRDRCFNSLAE7W7TELBh3o6+lkA5MVHF0v4bvSKFMQu8kKjdr9kqow1ls+XcRVzYH2YiNR7tWefxS1Bc1j2gkoncrWH9caMqTGwDlg64iV2lSHppS7FfBotJuKKoi8po= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=VcpqIm7r; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=fpDy34DX; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="VcpqIm7r"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="fpDy34DX" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 494GfvQ2031803; Fri, 4 Oct 2024 17:26:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=G2J1lWDlK/K8GQcwdp+Owxc9LxgqcAifnGnDVcIYq3g=; b= VcpqIm7rallycXxbCFmZ2fPNpPxtq78nMva/xKoI3Eh1MS2WzO3/kxvc8l1oC+4B ABuTBtGs5ATnY9XFytRGY1/owpGgPcDn88GYFnbkotH+1FyxI4cHG+EucEAxWudU 5OzWCtpGLacwe+jiU0j6iulS0gmMXWP2S+LK2V+jRyx4eIed/fSR79YU+Hglp19k NxS2BZmu5qmMYQ9Q0mBCQcQ3SvlByi3SndFxktXOofdqPModnnEasv5UG2CoOUru OwyfNWvqmSKfJ8q6YTXyAwgWGfzIOSMIy50Om2tFlcARoYsE6P5q9m4AYnfEaFZN 3ehxbl4BzQqx+IN4OknhqA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4220492429-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 494H4rGL005877; Fri, 4 Oct 2024 17:26:37 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422056u661-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x/sn74o/QJfnCBd+K+6oiiah9DlohES4M/LYszueUo7kIdxqIoCuOubj7dfj5kamCKdVj55I9pmxND05nSvq40svi7C2pbBPXp5X8BY8egI85fyMphKqsw/z3tGNhTz/6TEixgogdwO3NZVSrh8YV4nEA9Avjbf4j6dYWQ/5v9mXHCc/gJQjS2yQIL1sBpqOkoe0yXnDB4P4C3QpHBgmMMZ9V/Q7AeIGW/Yohjnx1B0IMBhrWMCXmHQVo+mobL8QOv17lheah0Gp6175CbfvhI3EE5+vSqk4ytBgv+Dg4TguXnytvCM35sw6uA6bI3qXtZbuGyIzR9x7vHqQYafnFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=G2J1lWDlK/K8GQcwdp+Owxc9LxgqcAifnGnDVcIYq3g=; b=P4FFqmFLECcSg/a+a7WfNsahLqjgzzPbpX4BZEm06OT5RgV5Ae0i4PX33yeVVTlCly8UIFk6xxpea+3TovM1dxmPYUscflOd4dYm7HxcDue7y8He0hXmnb5fZXi+8t7iziuiijj3aaTtvOGxROINK/qx3eha2PHNIVp/ymjFdjsK6/VEJmumjM4zNKih97ZxZ250es9r6dgwL0o1nyBpCfT8L6U73OWV550Okso+F+56LBm7WDQc/GLKJ8v/U4hpCRCneM6LeaZmBQqLO0Nj5c/xPUwNxBhXhS3X7Ce7jxN5Von9yf39uY1FDB9KIvYkUTBeAtCOqzodbFYYsVvfzw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=G2J1lWDlK/K8GQcwdp+Owxc9LxgqcAifnGnDVcIYq3g=; b=fpDy34DX1Xr2V+mCQ9MkTD+BwQYv7ydvFCL8LTjUGwwDIPNjyP3RTrg92WAJFEhTzUcwkNq6nJE+irRXbIqW3yOFuqrIOhnmjLJdS8hyph8ii9lHLFmPEcP67tSW9f8vixpk1tV7F4V9iwCyK62CxRkhQyf7VtnedqnA+Yao46c= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by IA1PR10MB7485.namprd10.prod.outlook.com (2603:10b6:208:451::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.19; Fri, 4 Oct 2024 17:26:34 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.017; Fri, 4 Oct 2024 17:26:34 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v4 1/4] btf_encoder: stop indexing symbols for VARs Date: Fri, 4 Oct 2024 10:26:25 -0700 Message-ID: <20241004172631.629870-2-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241004172631.629870-1-stephen.s.brennan@oracle.com> References: <20241004172631.629870-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR03CA0142.namprd03.prod.outlook.com (2603:10b6:a03:33c::27) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|IA1PR10MB7485:EE_ X-MS-Office365-Filtering-Correlation-Id: 95d0a8ee-162c-4683-e019-08dce499b185 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: obPxx6ujCUqh7VkWylGFeOLQONzjFNfoqB0vPlRQZYfiVVlT+ctTbLTM9Nt/4ZCZ4dLMPP6z3utn2jeEp2niTOPz8EdzCUy/5jCYhoHAgvcUFQUKCyha7c5Q8aZJD1lDZpu5/led+lePyPiBlgps3ewmLhQInpHf6PksIh2zswvV3SABx2uL+vvBc/UoyeAgEqh4qRtbJtICkt274/MmHsYbYUGx7ONAF6YY4QZdwWW8n5EKoBWWy/OH1AiRboyOXnOzBPuScx3nbLFiejgmM9FM3DWwPLrm4Ce578KlSC5gLidG4D8PBnlqIwMvl0sYPoDnVGYOdOe+ZI4+gsj3w2ZRSlQoPqZFYEpGsXmbL/Kef8oPwjfLVnvDd1IGHgMV361eNu6HnyXdmk1q7M4xdIqs2QlyWDmFI2jn7JV6QrhEQN0Ut03cnG/aqGHRYun/zlxbFnWbEQ8k6/Ry7qjWuzsLF4SV9RG1hysyRB6NKl9/UuUjKWIy5CGPaLKGthrG5GRTwdAz9EtB3FASGwjsJO8AZ7Z6GEvHrMPHNRnX6w82szS5y/bXKQVe8l38NgEeN9M648vrsWUrpNk4/T88H1z6RsQ7uejQiLjfaU3m/zLL8tHVttQ3jWvtuVz3B3iHOgKJLOpm4xRi1nMUMqTblexG2arqUr/ED805us5wvMt5HQXbnGRqxHKud/diqyMjWdKIhvEqJb+sdFDAls6q4vEdJ2egigTX8D060NgwmSzSAXnuhv4pd8Y2KVvbMil9x8/bfAs2N8fZVdhXbmUMGEasqTe3I1PbwQb3C+u7rI0/2Q2bouLLuqAIL3qyFxwr819DkZ0uEnoqeG3tYQQTL5DJDa8s0vEtL8/E9fJP6/0XqOxkPVa96HLbH3v9eICHC546mfJkGtohJz1YMof+kH0WoBOS5WpFn83ABKCXof1SVxXsXlVj2pyLclHxSf5u/C2WQjlu2JTKUhAWHjEYaso8Ng9FMyUuvPZ/62LaK4u9W6TuGCcgg2/2qpo+vcYkkig77l4V9Aimf25e7uWlrZ4XqpM9BYeYlYfFZTQsizrYP1yVsO30TX4zBEpdyT47/RNjDcPrENOhw7p6Jh5nWewM4xwFl0mKnOvsJiNFf2wDz8Au4fpu11DhGUItHplcb4Zfh6a94TeRYFaAUmsfDt0pCtRBjnrv7ad0F2Cf+pt175Kh9NDW1hhLkgYF+3Ceq/8IcHlnCcc08HmxnvAUkzmKJ7PtEzV1wXD/b+KJiuRzLlroy+4Kg6QIGbgRNjuC4xSUeDqHpR6uc/FHn+T82Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-Anti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wxXbcV/lNe6cAOhTvRlmJhNZcUBMa7+hbAGGMuBcqIopigdWAqsyrVgNiW8uEk3e7WRkSralf9WsJRdfxj8ea4XxjBRovmPeMANI6cuIKUvqGiXTGWQVMPUbi2I7CRFQrQ9EMT89oEVp634jbuiy4Q3pe4tSWtCqg39Q35pKh97J2Kb1wbYlZVfqke1TbZFj9jG2Orgip4jh/AwQ63c= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95d0a8ee-162c-4683-e019-08dce499b185 X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2024 17:26:34.1234 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fpl7kEYbSHOTeFLB8UNM033OH+kBDURspcX5ikqu+4hzUb2sZRWnLIavj5L/cfC2X8tkX6qqIj/Ku8Z6ZSefYQ25VA3CFq9L7Qf1zFP3SLc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB7485 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-04_14,2024-10-04_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410040119 X-Proofpoint-GUID: s1g5N-sW6RXk_bstJCAflitAlTVTlrT3 X-Proofpoint-ORIG-GUID: s1g5N-sW6RXk_bstJCAflitAlTVTlrT3 Currently we index symbols from the percpu ELF section, and when processing DWARF variables for inclusion, we check whether the variable matches an existing symbol. The matched symbol is used for three purposes: 1. When no symbol of the same address is found, the variable is skipped. This can occur because the symbol name was an invalid BTF identifier, and so it did not get indexed. Or more commonly, it can be because the variable is not stored in the per-cpu section, and thus was not indexed. 2. If the symbol offset is 0, then we compare the DWARF variable's name against the symbol name to filter out "special" DWARF variables. 3. We use the symbol size in the DATASEC entry for the variable. For 1, we don't need the symbol table: we can simply check the DWARF variable name directly, and we can use the variable address to determine the ELF section it is contained in. For 3, we also don't need the symbol table: we can use the variable's size information from DWARF. Issue 2 is more complicated, but thanks to the addition of the "artificial" and "top_level" flags, many of the "special" DWARF variables can be directly filtered out, and the few remaining problematic variables can be filtered by name from a kernel-specific list of patterns. This allows the symbol table index to be removed. The benefit of removing this index is twofold. First, handling variable addresses is simplified, since we don't need to know whether the file is ET_REL. Second, this will make it easier to output variables that aren't just percpu, since we won't need to index variables from all ELF sections. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire Acked-by: Jiri Olsa --- btf_encoder.c | 253 ++++++++++++++++++++------------------------------ 1 file changed, 99 insertions(+), 154 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 652a945..61e9ece 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -93,16 +93,11 @@ struct elf_function { struct btf_encoder_func_state state; }; -struct var_info { - uint64_t addr; - const char *name; - uint32_t sz; -}; - struct elf_secinfo { uint64_t addr; const char *name; uint64_t sz; + uint32_t type; }; /* @@ -125,17 +120,11 @@ struct btf_encoder { gen_floats, skip_encoding_decl_tag, tag_kfuncs, - is_rel, gen_distilled_base; uint32_t array_index_id; struct elf_secinfo *secinfo; size_t seccnt; - struct { - struct var_info *vars; - int var_cnt; - int allocated; - uint32_t shndx; - } percpu; + size_t percpu_shndx; int encode_vars; struct { struct elf_function *entries; @@ -2098,111 +2087,18 @@ int btf_encoder__encode(struct btf_encoder *encoder) return err; } -static int percpu_var_cmp(const void *_a, const void *_b) -{ - const struct var_info *a = _a; - const struct var_info *b = _b; - - if (a->addr == b->addr) - return 0; - return a->addr < b->addr ? -1 : 1; -} - -static bool btf_encoder__percpu_var_exists(struct btf_encoder *encoder, uint64_t addr, uint32_t *sz, const char **name) -{ - struct var_info key = { .addr = addr }; - const struct var_info *p = bsearch(&key, encoder->percpu.vars, encoder->percpu.var_cnt, - sizeof(encoder->percpu.vars[0]), percpu_var_cmp); - if (!p) - return false; - - *sz = p->sz; - *name = p->name; - return true; -} - -static int btf_encoder__collect_percpu_var(struct btf_encoder *encoder, GElf_Sym *sym, size_t sym_sec_idx) -{ - const char *sym_name; - uint64_t addr; - uint32_t size; - - /* compare a symbol's shndx to determine if it's a percpu variable */ - if (sym_sec_idx != encoder->percpu.shndx) - return 0; - if (elf_sym__type(sym) != STT_OBJECT) - return 0; - - addr = elf_sym__value(sym); - size = elf_sym__size(sym); - if (!size) - return 0; /* ignore zero-sized symbols */ - - sym_name = elf_sym__name(sym, encoder->symtab); - if (!btf_name_valid(sym_name)) { - dump_invalid_symbol("Found symbol of invalid name when encoding btf", - sym_name, encoder->verbose, encoder->force); - if (encoder->force) - return 0; - return -1; - } - - if (encoder->verbose) - printf("Found per-CPU symbol '%s' at address 0x%" PRIx64 "\n", sym_name, addr); - - /* Make sure addr is section-relative. For kernel modules (which are - * ET_REL files) this is already the case. For vmlinux (which is an - * ET_EXEC file) we need to subtract the section address. - */ - if (!encoder->is_rel) - addr -= encoder->secinfo[encoder->percpu.shndx].addr; - - if (encoder->percpu.var_cnt == encoder->percpu.allocated) { - struct var_info *new; - - new = reallocarray_grow(encoder->percpu.vars, - &encoder->percpu.allocated, - sizeof(*encoder->percpu.vars)); - if (!new) { - fprintf(stderr, "Failed to allocate memory for variables\n"); - return -1; - } - encoder->percpu.vars = new; - } - encoder->percpu.vars[encoder->percpu.var_cnt].addr = addr; - encoder->percpu.vars[encoder->percpu.var_cnt].sz = size; - encoder->percpu.vars[encoder->percpu.var_cnt].name = sym_name; - encoder->percpu.var_cnt++; - - return 0; -} - -static int btf_encoder__collect_symbols(struct btf_encoder *encoder, bool collect_percpu_vars) +static int btf_encoder__collect_symbols(struct btf_encoder *encoder) { - Elf32_Word sym_sec_idx; + uint32_t sym_sec_idx; uint32_t core_id; GElf_Sym sym; - /* cache variables' addresses, preparing for searching in symtab. */ - encoder->percpu.var_cnt = 0; - - /* search within symtab for percpu variables */ elf_symtab__for_each_symbol_index(encoder->symtab, core_id, sym, sym_sec_idx) { - if (collect_percpu_vars && btf_encoder__collect_percpu_var(encoder, &sym, sym_sec_idx)) - return -1; if (btf_encoder__collect_function(encoder, &sym)) return -1; } - if (collect_percpu_vars) { - if (encoder->percpu.var_cnt) - qsort(encoder->percpu.vars, encoder->percpu.var_cnt, sizeof(encoder->percpu.vars[0]), percpu_var_cmp); - - if (encoder->verbose) - printf("Found %d per-CPU variables!\n", encoder->percpu.var_cnt); - } - if (encoder->functions.cnt) { qsort(encoder->functions.entries, encoder->functions.cnt, sizeof(encoder->functions.entries[0]), functions_cmp); @@ -2224,15 +2120,57 @@ static bool ftype__has_arg_names(const struct ftype *ftype) return true; } +static size_t get_elf_section(struct btf_encoder *encoder, uint64_t addr) +{ + /* Start at index 1 to ignore initial SHT_NULL section */ + for (size_t i = 1; i < encoder->seccnt; i++) { + /* Variables are only present in PROGBITS or NOBITS (.bss) */ + if (encoder->secinfo[i].type == SHT_PROGBITS || + encoder->secinfo[i].type == SHT_NOBITS) + continue; + + if (encoder->secinfo[i].addr <= addr && + (addr - encoder->secinfo[i].addr) < encoder->secinfo[i].sz) + return i; + } + return 0; +} + +/* + * Filter out variables / symbol names with common prefixes and no useful + * values. Prefixes should be added sparingly, and it should be objectively + * obvious that they are not useful. + */ +static bool filter_variable_name(const char *name) +{ + static const struct { char *s; size_t len; } skip[] = { + #define X(str) {str, sizeof(str) - 1} + X("__UNIQUE_ID"), + X("__tpstrtab_"), + X("__exitcall_"), + X("__func_stack_frame_non_standard_") + #undef X + }; + int i; + + if (*name != '_') + return false; + + for (i = 0; i < ARRAY_SIZE(skip); i++) { + if (strncmp(name, skip[i].s, skip[i].len) == 0) + return true; + } + return false; +} + static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) { struct cu *cu = encoder->cu; uint32_t core_id; struct tag *pos; int err = -1; - struct elf_secinfo *pcpu_scn = &encoder->secinfo[encoder->percpu.shndx]; - if (encoder->percpu.shndx == 0 || !encoder->symtab) + if (encoder->percpu_shndx == 0 || !encoder->symtab) return 0; if (encoder->verbose) @@ -2240,59 +2178,69 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) cu__for_each_variable(cu, core_id, pos) { struct variable *var = tag__variable(pos); - uint32_t size, type, linkage; - const char *name, *dwarf_name; + uint32_t type, linkage; + const char *name; struct llvm_annotation *annot; const struct tag *tag; + size_t shndx, size; uint64_t addr; int id; + /* Skip incomplete (non-defining) declarations */ if (var->declaration && !var->spec) continue; - /* percpu variables are allocated in global space */ - if (variable__scope(var) != VSCOPE_GLOBAL && !var->spec) + /* + * top_level: indicates that the variable is declared at the top + * level of the CU, and thus it is globally scoped. + * artificial: indicates that the variable is a compiler-generated + * "fake" variable that doesn't appear in the source. + * scope: set by pahole to indicate the type of storage the + * variable has. GLOBAL indicates it is stored in static + * memory (as opposed to a stack variable or register) + * + * Some variables are "top_level" but not GLOBAL: + * e.g. current_stack_pointer, which is a register variable, + * despite having global CU-declarations. We don't want that, + * since no code could actually find this variable. + * Some variables are GLOBAL but not top_level: + * e.g. function static variables + */ + if (!var->top_level || var->artificial || var->scope != VSCOPE_GLOBAL) continue; /* addr has to be recorded before we follow spec */ addr = var->ip.addr; - dwarf_name = variable__name(var); - /* Make sure addr is section-relative. DWARF, unlike ELF, - * always contains virtual symbol addresses, so subtract - * the section address unconditionally. - */ - if (addr < pcpu_scn->addr || addr >= pcpu_scn->addr + pcpu_scn->sz) + /* Get the ELF section info for the variable */ + shndx = get_elf_section(encoder, addr); + if (shndx != encoder->percpu_shndx) continue; - addr -= pcpu_scn->addr; - if (!btf_encoder__percpu_var_exists(encoder, addr, &size, &name)) - continue; /* not a per-CPU variable */ + /* Convert addr to section relative */ + addr -= encoder->secinfo[shndx].addr; - /* A lot of "special" DWARF variables (e.g, __UNIQUE_ID___xxx) - * have addr == 0, which is the same as, say, valid - * fixed_percpu_data per-CPU variable. To distinguish between - * them, additionally compare DWARF and ELF symbol names. If - * DWARF doesn't provide proper name, pessimistically assume - * bad variable. - * - * Examples of such special variables are: - * - * 1. __ADDRESSABLE(sym), which are forcely emitted as symbols. - * 2. __UNIQUE_ID(prefix), which are introduced to generate unique ids. - * 3. __exitcall(fn), functions which are labeled as exit calls. - * - * This is relevant only for vmlinux image, as for kernel - * modules per-CPU data section has non-zero offset so all - * per-CPU symbols have non-zero values. - */ - if (var->ip.addr == 0) { - if (!dwarf_name || strcmp(dwarf_name, name)) + /* DWARF specification reference should be followed, because + * information like the name & type may not be present on var */ + if (var->spec) + var = var->spec; + + name = variable__name(var); + if (!name) + continue; + + /* Check for invalid BTF names */ + if (!btf_name_valid(name)) { + dump_invalid_symbol("Found invalid variable name when encoding btf", + name, encoder->verbose, encoder->force); + if (encoder->force) continue; + else + return -1; } - if (var->spec) - var = var->spec; + if (filter_variable_name(name)) + continue; if (var->ip.tag.type == 0) { fprintf(stderr, "error: found variable '%s' in CU '%s' that has void type\n", @@ -2304,9 +2252,10 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) } tag = cu__type(cu, var->ip.tag.type); - if (tag__size(tag, cu) == 0) { + size = tag__size(tag, cu); + if (size == 0) { if (encoder->verbose) - fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", dwarf_name ?: ""); + fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", name); continue; } @@ -2388,8 +2337,6 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam goto out_delete; } - encoder->is_rel = ehdr.e_type == ET_REL; - switch (ehdr.e_ident[EI_DATA]) { case ELFDATA2LSB: btf__set_endianness(encoder->btf, BTF_LITTLE_ENDIAN); @@ -2430,15 +2377,16 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].addr = shdr.sh_addr; encoder->secinfo[shndx].sz = shdr.sh_size; encoder->secinfo[shndx].name = secname; + encoder->secinfo[shndx].type = shdr.sh_type; if (strcmp(secname, PERCPU_SECTION) == 0) - encoder->percpu.shndx = shndx; + encoder->percpu_shndx = shndx; } - if (!encoder->percpu.shndx && encoder->verbose) + if (!encoder->percpu_shndx && encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); - if (btf_encoder__collect_symbols(encoder, encoder->encode_vars & BTF_VAR_PERCPU)) + if (btf_encoder__collect_symbols(encoder)) goto out_delete; if (encoder->verbose) @@ -2480,9 +2428,6 @@ void btf_encoder__delete(struct btf_encoder *encoder) encoder->functions.allocated = encoder->functions.cnt = 0; free(encoder->functions.entries); encoder->functions.entries = NULL; - encoder->percpu.allocated = encoder->percpu.var_cnt = 0; - free(encoder->percpu.vars); - encoder->percpu.vars = NULL; free(encoder); } From patchwork Fri Oct 4 17:26:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13822844 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AAFF1E378D; Fri, 4 Oct 2024 17:26:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062802; cv=fail; b=eoVG8CEO065ovVtpY/dXS4c72Pw+MQFwHw/OfvoRFqJjXroVX+RRee6EnjMJIZYOet05bMDPbtQnyDWuo8hz/+vbWEyzz9Ivg0Gz5wIP99iop/0sPN3QfPARFhFOynVS9NSoI2YYQv+T5QgH3PEOkfXeGKLzX0cTVz5KxJ2d4t4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062802; c=relaxed/simple; bh=t4qmbLO0VYKpg3RusnN/yqt0ARosjrA/KZBiIv6Lb0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=B3SFU5kH4M7sBz5giNBnToXSgmvweQI86BvFt7mLlgeqYQ4PP4ME8tLjgUWV7IljUIQStaFJhzrzRIa7EXG4uC0RZyoHmYDvBe2/gchSjceGJNlg8YIJRPETG05UR9go+I4sJeu0fXVbvKUL+r+RqZqnX+IPhOMQMmiIz88vjD0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=SQ2Pb7ZF; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=I6enpX1C; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="SQ2Pb7ZF"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="I6enpX1C" Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 494Gfu1M015209; Fri, 4 Oct 2024 17:26:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=2BoYj8vJoCc5YOGcljrF0j59xv9vGYkaEkCcW4RMm0g=; b= SQ2Pb7ZF5BzQT5aOyIhKHHTZIKWy3o0dSxQAmt45HhRCLiMhoHLNEzP3VJEs95g6 e/cjtzYl62g9aC0/npxuJjac9Y4TMfZRVVlSQ9ZOIna7oIkLfzQO7v5g/nR2W5RS KXlqCRFHOk+YgiuOFDu9DrcuBVu6t4MSmz/FOCF+tDpzHspzEAJnHg5HxumdRDjh 24M8GyPBbdNqhEzbR2EIhvYl3zKaedHQbdO7mbgQyXYl4/rSI4MB3Qqbdk5jyfju KvWfI1JXfIZg3MweRA43jUv3XvNSjEQKcomZ+5p9JfUms/eabZnfLFsRmfdugVbR intGiRVIQg+MPxFEwlOSmg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42204gt2qj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 494H4rGM005877; Fri, 4 Oct 2024 17:26:37 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422056u661-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pDZlIN5COL/in4RSmUgTwP4iqnG6vLTvm5o9XAvD2JRJQ4ukpyZpOFG4cMqGPi/TGKV4hIVlzqMSXfcRbOAySd6T+14TkCj1nI1ikTYMRZrAaXz85ium/WhSwSX1VKYPSYDKDX0QVhH18m08x2+XZ7U4lRW3ypSdE6rZk0rg6holmGPMWmzohcbqelpdm6KWgV3e799GQbFpiV7Zsa0PDkqgcf5BQziqs6f7QcrAe2Ko/UvgiCBnfWwxajuVevUPEvYYf77ZaaYS+Rd6DHDsYth33rMB7JrRGwVs6ZtdRNspNuohSRIyqjsCd30/SP+K4FfvnBkXzNCbopG7w5E01Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2BoYj8vJoCc5YOGcljrF0j59xv9vGYkaEkCcW4RMm0g=; b=wYS30qKwEU+iJh4Q3vNr5LAZI157DSB8N3xWZode5JaJPmaZcBUN9hcuQmm9LElVrv6XD01N4cDLxMfX5StgxMEREIadtybjnejIdMOWsTrnQwSLsUPOISBdUKOJYVCXXwDp1K5oTZGw4YP5okAdSUn8lPnsTJtO3i5vHxr86bnnUDlFTqC40wxtYpQ3y9+sujfHIA0SilhQ353mJB5pYTq1knhmmMkx8xAAUzXe4mR4CY1p2tM1g+6+51R+C4ZGBUteQ3vgcL8Fk5QZWT582BrqFjqIYtE3fii3HPT4ZS5URnDGfJn3hPPi3GcFKa9+rxieEKwW/YHQvGs45N2Cnw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2BoYj8vJoCc5YOGcljrF0j59xv9vGYkaEkCcW4RMm0g=; b=I6enpX1C3Cj664izuhhEdedMJ5lJtdDf14TYOtetY0GT5MkjvdDvPPacFMO25KVZSPFji4QZeKACEhAlBbSdskVnJ4Bfg5nlHGwcOjmv+2Ucp47S3A3ZBKJYfE1VfzvMusxhlYoGEl9vddb7MOVOarR8ErdPA1a+1rytIpfyKf0= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by IA1PR10MB7485.namprd10.prod.outlook.com (2603:10b6:208:451::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.19; Fri, 4 Oct 2024 17:26:35 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.017; Fri, 4 Oct 2024 17:26:35 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v4 2/4] btf_encoder: explicitly check addr/size for u32 overflow Date: Fri, 4 Oct 2024 10:26:26 -0700 Message-ID: <20241004172631.629870-3-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241004172631.629870-1-stephen.s.brennan@oracle.com> References: <20241004172631.629870-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR03CA0390.namprd03.prod.outlook.com (2603:10b6:a03:3a1::35) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|IA1PR10MB7485:EE_ X-MS-Office365-Filtering-Correlation-Id: 55d637c7-9c70-4d43-6f40-08dce499b24d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: Lek5cEipHLFmu31z4y3VDNqOBo52MlqjVo1VAGYlSHmBWZ8Si1j3WN3sHjAIaatgR8V1ktbF7tfq27ec+nk2ZrCyy8k7Wwd4oqzhpyjPK+gfIfbLP9akQS8GIA7T2NDEix+vAfl+noBH9SfAtlgE5r9Hm12crNlGBK87VhQx86dpJZMzFpD2i/KvAAMklBZOHE2lnoYUmDENoXtL/aHG+y0OTlQJuZ/KpQxq0L/h9uGhcuRf6M5EF/aQb59QWwkgIB9JizIXXVd60sD0FuQMZc0ACV4O3soBu3ghLQSZvrfFW9t8IZBnLE0/htWimJ9Ok0aUJF5cFqUVGN480FaTzRbz9QO9hDrorj1Tl+hKA61VT4c58TZ7xNsbGlbgH2KbCOdgSCFKpnwU9IzQX/JQlzAH3f69okjHO1bOIq9AzLTIf2npqOFkj5vs4m/9ZdoJYQmlzcisqNOiLk9zRLL5i25v/L+gEF7ZtuZyzB3sB0Dr0Y/VZfHRIDMif0VZRGgFkNS9YQFNBslmwaz+M5Cl+xY7rG8e9oROeIOGCSrJ6zdF+BByiDxdCWGv+Py0fKQ0E/9ijNlAWfVR6xueFDMdgDF/uYbEoqtvgCImxCcd5mVSoKvTklDa9hAIGwizcwcaLnEseaGIpKfcn8PTtHCqh//WUwW8esnAdjCS2umXYuCNdiaUMuKAyTzp5Oe5UXG2gA7+vKkH57O4mbCCXK96JqDRGURWvVTySqT2dDFUIPKo6SauQptNxqrZmeWJsiNkj0WnT7YKOljdqvfKIzLusfUlAS/+HqrXsXsIw67oIi7fkyqrVHad/GOkf2qvigfHwSVVbMMQ8D+AMWfJj3hUiihGwRi9l/h3hAwbLWmLLKJPOoD3JOlO6Fu08djQMgPG8vOlIfgONOYQJAjS+xxRe/5HNvv0R3Gw1kMtXH8SO3W0Hf0olXHNXokME8OxDd3BJFwdJpg9pvdqthJbkbMLioPDOum36VrikVUGwAgtGrKBA2OsSsc2lEifOLvmbOaR3nitfkZyLkiYjaZT5bDVjvFbRKFZO1+BQk4QcFLm3qM+Vbx0WQZDD6rMhQwByqrYVQpLCbiAHnBvg8CcfdifwmUKc2gl553JacH4x3YegJiP5kdHzXQFFKc4sehSEOJFNMxxid4UoSLwUTpvtQTnsC3TQc5rRqU00iPXnOw4A6etqwOxH1xD2WeIeM8IvBnOau/9ejcbQ9y8PigiX8bT2i6q9eUqxdATX/UmwBWt8sBVIc0gN/4xDQ3edqrEwwccTcWsojDHVlF0IIKOQSlhVw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nr+Mfv2vYFdK8ZeucmEQAlOcDpk7DLp3qlJzT99frPD552zGNtyT9bazsJAYJ35lqL0WBvvaY61uznWqA372p1OwY+e7DAkjExXVdJl+gd7a/1RDcp597BtGXsP0kxZSx0OIizGgIQJqBhJbw09Fl0D57sQKYZ8DUrAEGu76VnuvAZlI25HO2r/82sD7aodv+Rb1j4I+wfN/BNLFtSLFtdIj4M93KPefSWNaieSn3koytVZqH/iLsvjRh0LSiU5c3L3SBxgN75HVhvwiSc7jcAfA429McOn0bXU4B2ETmU5+vLrTm/4LAcJbL1b9rspfKUlQxKF5MxrZCSTGamMtIq6laMmskAJ3jXhkx+1q3RjaWDga/acZkLd3nSpzHWol5FgJzQMgSmqim6W3D8vWdCFujReFxdjuoKypKUH0CsT22TyJhSZpOtoSjbWWyYaqVaWDBmUBDUx+b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UzXRHHgIGBS3tXjCcRTEiqCYT3cD9xrk7ZaB7cqh6cbJAvFgO2Qn5GnoSGQnHi2ySsQg98RuGZmitbFjRBsiuQWaOmyA320iP34= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: R2X3xu1wymaRxQFlRCGS8Sp6fh+Te+BS/+/Xo8RY5AfRANrFQ1m7iSX79rKZriJ7Gj0tGO66NQByTSvlm08dH4jLMNuFmaCRncIeyMuMC+Ot+P7IoijAUj0WS6SY4LOwImzQioR8jc26wU+H4c8FU1UY/53c5Qo2o+WQ9el5QXs17oDw2Ytc+V5J9FZKFpUiA/pLrJV32YOWKKl6Awv+zV/VMzKBdOtAby9UMndkSjKuQQkCyMEip+hUKrwPVVuBiadcyL/D25nZ/BBbm6sWB4hv8ZxGMvxeAkKTyeJwHyrUGzs5uoJE/sL1CkfvSeU6Q2r6BCJFNay7mvq6yyUbVVuGe1Dqe8uZIpfgi78KEKqgZPVhpkRz1XwSVrwe8TsdUSmaJ4zKQgVT2/TqLVlRFbCRuzpFvLZayDA5HEaAhlCegWjK2yGskjFm4J8fIdy7vvAJeOQ3zawRaViM/oWBdG33ugGC++mDRWV3tNXqv6OTdAPtPoQPg03UQOZ6UMq/rjfTVGLabMOoIsQ4Alh9zjfmpATnOHlN9RI6i+xZGHSJtgXDlTwNC+YzXI2BU9TCWPl/EM1ylrDYjmTXM4YoSOUHhIvlsCfRI48RtjcgMkc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55d637c7-9c70-4d43-6f40-08dce499b24d X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2024 17:26:35.4306 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l3MPrDn+vCcQyIRsnKVZ4+K8hwj9LXchZl/KWXZQAhBroAbPTEmfhIDb1TDo1f85VVaqEU3PwgXODihOFpUy6oHuWTh9DOp2lccfcHcCWF4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB7485 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-04_14,2024-10-04_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410040119 X-Proofpoint-GUID: XitPjNXmN4fx15f8_jezt1GHu7n5b7Ba X-Proofpoint-ORIG-GUID: XitPjNXmN4fx15f8_jezt1GHu7n5b7Ba The addr is a uint64_t, and depending on the size of a data section, there's no guarantee that it fits into a uint32_t, even after subtracting out the section start address. Similarly, the variable size is a size_t which could exceed a uint32_t. Check both for overflow, and if found, skip the variable with an error message. Use explicit casts when we cast to uint32_t so it's plain to see that this is happening. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire Acked-by: Jiri Olsa --- btf_encoder.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 61e9ece..5586cd8 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2253,9 +2253,16 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) tag = cu__type(cu, var->ip.tag.type); size = tag__size(tag, cu); - if (size == 0) { + if (size == 0 || size > UINT32_MAX) { if (encoder->verbose) - fprintf(stderr, "Ignoring zero-sized per-CPU variable '%s'...\n", name); + fprintf(stderr, "Ignoring %s-sized per-CPU variable '%s'...\n", + size == 0 ? "zero" : "over", name); + continue; + } + if (addr > UINT32_MAX) { + if (encoder->verbose) + fprintf(stderr, "Ignoring variable '%s' - its offset %zu doesn't fit in a u32\n", + name, addr); continue; } @@ -2288,7 +2295,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into * encoder->types later when we add BTF_VAR_DATASEC. */ - id = btf_encoder__add_var_secinfo(encoder, id, addr, size); + id = btf_encoder__add_var_secinfo(encoder, id, (uint32_t)addr, (uint32_t)size); if (id < 0) { fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", name, addr); From patchwork Fri Oct 4 17:26:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13822847 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 802801D9A62; Fri, 4 Oct 2024 17:26:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062806; cv=fail; b=b/zm19jq9ohLjXoNGgyhB38I11gR0VNifMUf3dLJuXpLqCjF19JUHDGl+UTN99BG0bR+/NcT6fLpFxf33LKxGmkdV5OaeTKl1h5aWQX0o51HBbdE2kFKL0niQBCntNEVzLMaZjpB8TeiK6NAnt5/wCckk6nSHwVdsTko5ASPJ8M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062806; c=relaxed/simple; bh=c/MDGrKQqSrqE11GT/m3g/CnlzoEheGl8zN6pW+MTf8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=nJ1NxbS7BgOsCbhPMsfbblVCOVvIApBt/OvncrzPK7xDyL1szBmo6sY+eb/2+pCm6SuQHeqeilcj7PYKW/RV2G1MjQKGjYYxs1bv18XUp4NTVeXp3FPdv0ZXuz6DULT3qFObO5uZ1X40PZuRlmn6Wld/WuvxElq6x2bHV033OeE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=BHYcAi20; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=hW2muueT; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="BHYcAi20"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hW2muueT" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 494Gfs0H001853; Fri, 4 Oct 2024 17:26:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=xzGdJz58yU+OYmxzfakqJV+SzcpjJdEmE4cs54NFXuk=; b= BHYcAi20XUr9OJRRBnq4znJmFbPUE5NR2L2yvnt7JrBzCMqqBqc/dUXv1v8+urGU COJ+PgQ5XO7dYDF52tUHs39bBj4NR7HELJxyRxUTGJSZWwcnVwxLj+92SEOMwPyT VCO/SIYSd+rq7YtSiBrtvHV6B9Ah/xylj2PTLKjY975AFZ3N3FahRg6OKV319pfJ 3TvKmF/mNnx7Lsxk2c0ff4tkNd0XbrDszxcucNwD9Xx0Ob9w1ifQKnmHUlNTbR4q x504LSafmvDffc/QXvQD9THI/RWoTVt4glWeMZKtDMbxVEcZOZ67MYeTviabz9HS rCFpOb0zIBamZ9GVa6z9jw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42204b24na-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:40 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 494H0BH7005936; Fri, 4 Oct 2024 17:26:39 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2172.outbound.protection.outlook.com [104.47.55.172]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422056u670-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q16yu/84SX525wTr2fALhWHpAwmnPcoup1N8Ssctgitt7eIPPfSykb+coQ4wS48526k2UkWnqvdOr5vsqR7tEaqA2ZmQRLDmxerA4Fxjqc75ZS+YWniVyl5cVNIAlwxPvnjFj2vLMoNnqC32mzcHoWGO6vVEjGRZRDuy8FLraKEdp8nS6Yay+u0T3wUlVqFQlA/JEAddbeTrWZ7pAqB1X+DiQga25qcsDxUglpVvfqV6d55WBCt2qUkHTLz+ue7L6d18wNiBU6hyp+5cfmiKa+56CizV7C+PcBZ8lH2TO6s6MatNgzrKlf7IDB1Qw2C1wp9VKJTdMcZFa5yU9Om1MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xzGdJz58yU+OYmxzfakqJV+SzcpjJdEmE4cs54NFXuk=; b=ZP7FN1s3FYcN+MvhlBt069NszihIkGLgnbWhO+9FDRlhorn7qpF9dq1mTEEEEijt6Irok3vy8Dk0n3KP47PZfG5FjxRdySOTv849IhMSTD2B2rbFJS45s2aMv/I/5WW51MCBBZ2gHsLyOPPHUOmXyMqhL/xb9hVVnb+Vx0OAQ+2H1/IjWa/AxHM6BTFssx880Vr22f4/I6WEvB+PE9Tdbp1z+OhCEg+EZi1yKBb05PJzlHO3XNMq17aRlwP5rnzt8oxAb2FMKO2nQNHSNjuEXK60DOiUQHBMDakSgusltx+n9t2pmlfgXzpozfFslUAYRgE+YEr5/3l5dPUWT9azcA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xzGdJz58yU+OYmxzfakqJV+SzcpjJdEmE4cs54NFXuk=; b=hW2muueTM5JUYp8r/Pe7Zp2URdkB7f7Njpe4udbRysEmZDQ+ZwGqVZrw+3UcDtxy2Uq8E7NZhHVe0rNZF02oQqJp/VGgx9iBxF2mI746dJQK7eKiir2VDn/ONNTdJ+C/RuuCATufolbvCPTTRpo+FrZRVHdNWXCYsD6p0Q/yP/g= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by IA1PR10MB7485.namprd10.prod.outlook.com (2603:10b6:208:451::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.19; Fri, 4 Oct 2024 17:26:36 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.017; Fri, 4 Oct 2024 17:26:36 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v4 3/4] btf_encoder: allow encoding VARs from many sections Date: Fri, 4 Oct 2024 10:26:27 -0700 Message-ID: <20241004172631.629870-4-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241004172631.629870-1-stephen.s.brennan@oracle.com> References: <20241004172631.629870-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR05CA0090.namprd05.prod.outlook.com (2603:10b6:a03:332::35) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|IA1PR10MB7485:EE_ X-MS-Office365-Filtering-Correlation-Id: 5132fd1f-edb9-498c-aa46-08dce499b30f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: 8Ypp9aqGYIgMIhvdvnIhG3vJo3aQnWktxW41AgLuPFg8WF6seutwS6tE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NJD3jNQ5FMx2++aLPoB+LsLbIMZzBj/CpUaEL8A5dLS6iSROz1x5AuWnzHkjbJsbDEOFDwEsHw5ejGfi6Xlfe7QeYjCWaGDW4ij2341Ri7VnHTeSkSUr2NR/4H6LzgoEgCCWPCmms6R3KDbBD3smHYMSr9OAs0YyFtcA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OFtWLTf0Wh5+vv61Iws397AE1dXIdw+uaaHDoGHqrGx4CxWY5iXj4hFsEy4BWcUHK6BBLdUxUrghymArp1PbteMQ0DlEkTLhEiK0MXc3p+zElOYYVDwewbmOzih4471e4VEBoIEcLWqtLuw7SUL5Co1/AJb9r51cpRiTbYDH6Vt1/q1AABX72XMlQi7I3hOa5fgWKCaxHPxGmiMy4+K8JrYhGJOGDYJld+a+oaDwcoFu/F+njaVnhzvp+2RyjE1oablEM/NRaV505pAj6mAWymedxggBxkNcBcGDpS4pLnddqNrikgT7k81YW2Edcuq6j/MjyaLVgWfkdkYt9wNNTjp/QmQ9v64fJ/EAPlmTu7ZyUP1k+TGQKlnZzbBBvcRIZp66ZnSQi3r37kjoRrznapKsTv6i7UJd8LZJrUp+T4aKTacOcxvNuOF+QKv2HzsanqJ325GQK33kYCKCl3VTqPAOoVP0S4knJYhcw4mciFZU+mJwaVvLd8rGJWB/+UhOsgWs7fBJib3LoDAkLxzWpwuet3z4nSr/8Rro/sPhZZUUSfDQvTFYD4r1LQ18+sGD/KdhJw+hf9QuL6YPXO+TjIsFCexeHgbZthBpJZT6pRLeMx3KYAeyMvhgHf1huXctpIzOm4faQFln3jZxCPE+dRxZ8OpJpqVM7OwVDCkbsPeD6SF8OCp9re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lR+JiBCsWWwu/TxcJ3jXGCPbo1B2kyEESzmvc4TNhkEBHD9sULXsw7OCIR2bJTjRKsxr85VXtdYXqls8+pDaCQ7SjPoNS2dst7xu2DgHPTMWTO9mx2Q0NG07GEPH9NG5ghjW0UWRfSfUNHNtpblHFGJ9IRlYRt4hkjib+70puLeuYP3rX2IFr1ILTu+WkUIbMCytXrwxFF80vvEjguKNFKJUafgJg8aWwgCslADOTFaXZfHSAmaTXiw+OsIOsO3Np8+t0vXY5JEjVCzV7TaQnuoG86lRmH5Lj849gISx8Y3hGLFn0RtyU9SxwTxth+60oVT3IiOA8N/ZOv9qujetpOz31lIpy5YbcFWgMocewy0EZOzoDmSSjt209fPXQf5JueN26//9RLO4jX1eR0BtHZv0LNU1GhabXwV+vSxzONM60CqcyhCIKvt231FCTE+fdgNKVe37fnk8bFMxKjOExjsRVz+kVKgQqctNeaP0EotDP++GKf2YBSegrWglHWVEKT9i3EEf+g8p10NqFdGMQcqutqlYmE17qtbdY+7Jqzlt7t7Pw0M6DXUSvmDLWJb9c= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5132fd1f-edb9-498c-aa46-08dce499b30f X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2024 17:26:36.7049 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BYUxsw/V4FXZtPeXaw/E3fNLaK2AtCEY3bN8LtkFG/jATij+N8qEYMgeaLpcFSADM0j4naRsNVxk9jggz9ZV8vY3wtR5lkytj36Vnoexlxw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR10MB7485 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-04_14,2024-10-04_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410040119 X-Proofpoint-ORIG-GUID: vOlSMtw0kNXSb99JL8rTYblJtzv2vSgj X-Proofpoint-GUID: vOlSMtw0kNXSb99JL8rTYblJtzv2vSgj Currently we maintain one buffer of DATASEC entries that describe the offsets for variables in the percpu ELF section. In order to make it possible to output all global variables, we'll need to output a DATASEC for each ELF section containing variables, and we'll need to control whether or not to encode variables on a per-section basis. With this change, the ability to emit VARs from multiple sections is technically present, but not enabled, so pahole still only emits percpu variables. A subsequent change will enable emitting all global variables. Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire Acked-by: Jiri Olsa --- btf_encoder.c | 87 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 5586cd8..838a0b1 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -98,6 +98,8 @@ struct elf_secinfo { const char *name; uint64_t sz; uint32_t type; + bool include; + struct gobuffer secinfo; }; /* @@ -107,7 +109,6 @@ struct btf_encoder { struct list_head node; struct btf *btf; struct cu *cu; - struct gobuffer percpu_secinfo; const char *source_filename; const char *filename; struct elf_symtab *symtab; @@ -124,7 +125,6 @@ struct btf_encoder { uint32_t array_index_id; struct elf_secinfo *secinfo; size_t seccnt; - size_t percpu_shndx; int encode_vars; struct { struct elf_function *entries; @@ -784,46 +784,56 @@ static int32_t btf_encoder__add_var(struct btf_encoder *encoder, uint32_t type, return id; } -static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, uint32_t type, - uint32_t offset, uint32_t size) +static int32_t btf_encoder__add_var_secinfo(struct btf_encoder *encoder, size_t shndx, + uint32_t type, uint32_t offset, uint32_t size) { struct btf_var_secinfo si = { .type = type, .offset = offset, .size = size, }; - return gobuffer__add(&encoder->percpu_secinfo, &si, sizeof(si)); + return gobuffer__add(&encoder->secinfo[shndx].secinfo, &si, sizeof(si)); } int32_t btf_encoder__add_encoder(struct btf_encoder *encoder, struct btf_encoder *other) { - struct gobuffer *var_secinfo_buf = &other->percpu_secinfo; - size_t sz = gobuffer__size(var_secinfo_buf); - uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); - uint32_t type_id; - uint32_t next_type_id = btf__type_cnt(encoder->btf); - int32_t i, id; - struct btf_var_secinfo *vsi; - + size_t shndx; if (encoder == other) return 0; btf_encoder__add_saved_funcs(other); - for (i = 0; i < nr_var_secinfo; i++) { - vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; - type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */ - id = btf_encoder__add_var_secinfo(encoder, type_id, vsi->offset, vsi->size); - if (id < 0) - return id; + for (shndx = 1; shndx < other->seccnt; shndx++) { + struct gobuffer *var_secinfo_buf = &other->secinfo[shndx].secinfo; + size_t sz = gobuffer__size(var_secinfo_buf); + uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); + uint32_t type_id; + uint32_t next_type_id = btf__type_cnt(encoder->btf); + int32_t i, id; + struct btf_var_secinfo *vsi; + + if (strcmp(encoder->secinfo[shndx].name, other->secinfo[shndx].name)) { + fprintf(stderr, "mismatched ELF sections at index %zu: \"%s\", \"%s\"\n", + shndx, encoder->secinfo[shndx].name, other->secinfo[shndx].name); + return -1; + } + + for (i = 0; i < nr_var_secinfo; i++) { + vsi = (struct btf_var_secinfo *)var_secinfo_buf->entries + i; + type_id = next_type_id + vsi->type - 1; /* Type ID starts from 1 */ + id = btf_encoder__add_var_secinfo(encoder, shndx, type_id, vsi->offset, vsi->size); + if (id < 0) + return id; + } } return btf__add_btf(encoder->btf, other->btf); } -static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char *section_name) +static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, size_t shndx) { - struct gobuffer *var_secinfo_buf = &encoder->percpu_secinfo; + struct gobuffer *var_secinfo_buf = &encoder->secinfo[shndx].secinfo; + const char *section_name = encoder->secinfo[shndx].name; struct btf *btf = encoder->btf; size_t sz = gobuffer__size(var_secinfo_buf); uint16_t nr_var_secinfo = sz / sizeof(struct btf_var_secinfo); @@ -2032,12 +2042,14 @@ int btf_encoder__encode(struct btf_encoder *encoder) { bool should_tag_kfuncs; int err; + size_t shndx; /* for single-threaded case, saved funcs are added here */ btf_encoder__add_saved_funcs(encoder); - if (gobuffer__size(&encoder->percpu_secinfo) != 0) - btf_encoder__add_datasec(encoder, PERCPU_SECTION); + for (shndx = 1; shndx < encoder->seccnt; shndx++) + if (gobuffer__size(&encoder->secinfo[shndx].secinfo)) + btf_encoder__add_datasec(encoder, shndx); /* Empty file, nothing to do, so... done! */ if (btf__type_cnt(encoder->btf) == 1) @@ -2170,7 +2182,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) struct tag *pos; int err = -1; - if (encoder->percpu_shndx == 0 || !encoder->symtab) + if (!encoder->symtab) return 0; if (encoder->verbose) @@ -2214,7 +2226,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) /* Get the ELF section info for the variable */ shndx = get_elf_section(encoder, addr); - if (shndx != encoder->percpu_shndx) + if (!shndx || shndx >= encoder->seccnt || !encoder->secinfo[shndx].include) continue; /* Convert addr to section relative */ @@ -2255,7 +2267,7 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) size = tag__size(tag, cu); if (size == 0 || size > UINT32_MAX) { if (encoder->verbose) - fprintf(stderr, "Ignoring %s-sized per-CPU variable '%s'...\n", + fprintf(stderr, "Ignoring %s-sized variable '%s'...\n", size == 0 ? "zero" : "over", name); continue; } @@ -2292,13 +2304,14 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder) } /* - * add a BTF_VAR_SECINFO in encoder->percpu_secinfo, which will be added into - * encoder->types later when we add BTF_VAR_DATASEC. + * Add the variable to the secinfo for the section it appears in. + * Later we will generate a BTF_VAR_DATASEC for all any section with + * an encoded variable. */ - id = btf_encoder__add_var_secinfo(encoder, id, (uint32_t)addr, (uint32_t)size); + id = btf_encoder__add_var_secinfo(encoder, shndx, id, (uint32_t)addr, (uint32_t)size); if (id < 0) { fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n", - name, addr); + name, addr); goto out; } } @@ -2376,6 +2389,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam goto out_delete; } + bool found_percpu = false; for (shndx = 0; shndx < encoder->seccnt; shndx++) { const char *secname = NULL; Elf_Scn *sec = elf_section_by_idx(cu->elf, &shdr, shndx, &secname); @@ -2386,11 +2400,14 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].name = secname; encoder->secinfo[shndx].type = shdr.sh_type; - if (strcmp(secname, PERCPU_SECTION) == 0) - encoder->percpu_shndx = shndx; + if (strcmp(secname, PERCPU_SECTION) == 0) { + found_percpu = true; + if (encoder->encode_vars & BTF_VAR_PERCPU) + encoder->secinfo[shndx].include = true; + } } - if (!encoder->percpu_shndx && encoder->verbose) + if (!found_percpu && encoder->verbose) printf("%s: '%s' doesn't have '%s' section\n", __func__, cu->filename, PERCPU_SECTION); if (btf_encoder__collect_symbols(encoder)) @@ -2418,12 +2435,14 @@ void btf_encoder__delete_func(struct elf_function *func) void btf_encoder__delete(struct btf_encoder *encoder) { int i; + size_t shndx; if (encoder == NULL) return; btf_encoders__delete(encoder); - __gobuffer__delete(&encoder->percpu_secinfo); + for (shndx = 0; shndx < encoder->seccnt; shndx++) + __gobuffer__delete(&encoder->secinfo[shndx].secinfo); zfree(&encoder->filename); zfree(&encoder->source_filename); btf__free(encoder->btf); From patchwork Fri Oct 4 17:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Brennan X-Patchwork-Id: 13822848 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A111D1CACC0; Fri, 4 Oct 2024 17:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062809; cv=fail; b=nuH8CN//i7tDKJnlrj/5tLh3C/kckJ8x7g1sec0mNGIKD7wmrqH+AIScNbF9bw3ZtsK/uPPKRhRRP0RHEOzm5ZwCw3uYY66qoQglRzknmyOAxuwn0QjQUgApKNofl2LKl+e3pkxWwA331K5h6Qc48tudC6zMWOSoXNkanE+E9t4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728062809; c=relaxed/simple; bh=gPXy7eHE+jqm5IAgFmJ15vl09p6ElsiYMpj4/JeOjoU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ASzlFe52/9FT6ZscWK7HPJ92IHSxGNAwq2hgwn/HsaKLq22LJrlpykZcb+hTc+iWCvCa8giw8T2MlGXcxAET6f8O6NrySrmRdkV28wMn9GiDnLFH3t4n5P8tB8VvE0joAXdYCbd/btW7CZvBMGrLPTSMCQo37K4V2KMp2gbN0KQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=dFfKFeZv; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=nf68GGcF; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dFfKFeZv"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="nf68GGcF" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 494GfwCj007029; Fri, 4 Oct 2024 17:26:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=2noXyZdHFGQxNvBGIxT+qKvE/2d9IrmHjpZUcDpl2gs=; b= dFfKFeZv05JEak7zuwk+zFtdtJqxRgr+0RL18TVklkO6lwBXax4zT1hTV/fqO101 1F90gDqf6uaTI+TVHNhae2ePWf/cdIBfuUyKzqjHJ5QVZgdgVeYWYQcnV4ihzuU7 4boH8i8iil/txxnVke5/lbgqgGsuFYp0XRSiJBpG2LSTxrpVVfIj72twK+HQvHei DPn9Ml54/D4VKkg6mVMaRKnyshHnYnblTN5EkrG0ijExa9ZnM5shxL74cbimUjMi j6HN2fm5CVoBtD1AlF03KGQHg31efQ5N9l72UxeBBz9xYvs/mjA+SBXq3F8cis6V xcZABD/UUyu4o6qBZ4eyTw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 422049a3h8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:44 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 494GsSqc013389; Fri, 4 Oct 2024 17:26:43 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2169.outbound.protection.outlook.com [104.47.55.169]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 422057v1gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 04 Oct 2024 17:26:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PjWXilhKjL0ab7ohR/BUFk+k/CPpkscuFSdtcZZSNzegFUfPUTP9bBp/7x8gByqY6ICQkGsRpnSQDgevcS1ZFr81PnBtkFy5qJ27xhZ0ouZ/NzGnk2YX2Fay4wAlYjzA5NWgsKTCd65qiBPgfVpjm0vKC55fnSM0Ndgf7AZS1P9c2l8P/jg3a077EwzaSS8uv8fH+JKjpjYWpnD7wgwSYSGLU1LnzuPYkGVYFl9/MaGYRrDmy7w2lt5Fp7ma9Ph75Vq8znBhuGJbeUBJOmrsKf/HXSh1GKGGRe1xWQd+6UaO60yajBJODqs3HllkRdqepmqkxqShWZBKrs5BgOeZng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2noXyZdHFGQxNvBGIxT+qKvE/2d9IrmHjpZUcDpl2gs=; b=eqJyymypa8fu3kEqX9aEqW20ezgUQ+Gy6g8v5rrzftgbIl9u0hDiAU/+xxiX2YpJcahm/Tojo/2JpO8f78U8YCv8+FTfY1CTqU5ELjsB7y8Vava7O8tn8TSwcN96eqWtrHMsZAfXuSHjGMUmampkGnH4g9hZr1CISch5mp9TnMErC4Lm3vJabMaMuQJb4u10ejqe3Cz/sS8BnWE7SVeNfY4/9AgwQ1A5YAfTUtKLutnSIVZ0cAiaMxMCLHeYYdS/9tuBxr5rxbndV9DH81TsDvehNHdjpBM46I/qYFKXPiECaVY7NnM5kikNG2bO8XwmMQkxt9un7fDkFcudiQJ9dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2noXyZdHFGQxNvBGIxT+qKvE/2d9IrmHjpZUcDpl2gs=; b=nf68GGcFYDEZCWKpawb0TEkaSmkiigNZNzh7sAQKjJTBDerjLIwSXbgeXyyF6P3Ir9EQ3tlg3Y2jKkTxMlhOMS4r6lNMEyu2s5SoesF4jcuJId1NDHcr5iLHoV4EDAR5qk7+2CGiHPhZKQa1H7yRHogCBRkHhs2YK2UseMfWKP8= Received: from PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) by LV3PR10MB7745.namprd10.prod.outlook.com (2603:10b6:408:1b7::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.18; Fri, 4 Oct 2024 17:26:38 +0000 Received: from PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca]) by PH8PR10MB6597.namprd10.prod.outlook.com ([fe80::6874:4af6:bf0a:6ca%3]) with mapi id 15.20.8026.017; Fri, 4 Oct 2024 17:26:37 +0000 From: Stephen Brennan To: Arnaldo Carvalho de Melo Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org, Stephen Brennan , Alan Maguire Subject: [PATCH dwarves v4 4/4] pahole: add global_var BTF feature Date: Fri, 4 Oct 2024 10:26:28 -0700 Message-ID: <20241004172631.629870-5-stephen.s.brennan@oracle.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241004172631.629870-1-stephen.s.brennan@oracle.com> References: <20241004172631.629870-1-stephen.s.brennan@oracle.com> X-ClientProxiedBy: SJ0PR13CA0103.namprd13.prod.outlook.com (2603:10b6:a03:2c5::18) To PH8PR10MB6597.namprd10.prod.outlook.com (2603:10b6:510:226::20) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH8PR10MB6597:EE_|LV3PR10MB7745:EE_ X-MS-Office365-Filtering-Correlation-Id: aab1d693-8788-4265-d9ff-08dce499b3c6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 0a63eNXyRJpStlBjYkp9gfE08ZCpN+sbwHbUWaQ7q2vKks+C/mSP4W5HwfTq5kS6MrCLLVjleP/jDegKrSHEUIqdcpi1iD8YeaxjCFI/fzM8BcAgW/3JnsKXmwn6nTGKz8GW+L7OBUNgws1+R9p3z6z7R7iI+5R1p74uo/PRtL3jFLzjYUxDnaWV7UN2/bXlWbHOwxIcSllUHHNr5J86gcZ33xJf12kFgkxMBcGW3KvAPVMcuVrc08WSMQRC8UXShjgXkbL60qDz9cI1ZT2gpeMd/oXBAwdgfRkpmZfgUHDSxj8HLrPdZNXcIFvnTotT/Zf7OoWdaZZYKgZM2uzp5oZH0ik7BDUa4THoB1dmK0eSUKJj4mGGEVuJNTswJLHqL+yeiKbxfZ+NuvjIzHnUCq4FUFWCcMoUZNjZCwywCe7l1AjuJzZ4nxMmEqmt66N5b6VrgLFgZKNlmDMRxDQa8KLBwaHTJqxXBAShhTSBtE4/CPxzwc084Mi+zSouERfT2/FKIkYieHcclQtxhdOeMQ0sky3mNVeaU/gMUzh2972PDpZIBR+8VD6uOKe2DMKY0Y0DSO8boUEcpBHnG5XlMzyHuifThQsvwnNyBeLjsJw0Wm6Pq4aISADgSue4MiyeMl1QAh59kDxXjF+Y/oDsK4fPEtfNhHeGY9RSC3pfUkBIWMoEFPpTfQve2ZqpwTr2Ni4wv3o8trup1+3VmkPcQVt7QQ1yzKFZcSGk7N8CRCor8lMckR4xm2gI4SXnfU2ZSdfDp6KTGoXJrx8lLcKQ2QnzKjbbay6DYjcZL6i4+3vgffE/dXRer/rp1yiHOSArVGWUGK18jiuh+vdmgVi9iiZi1MVdAk9F4TnlEx5Nl9JiikvsSWqlRHtIaYJTCowsCVGXHJx11znAjrX8ZnCPWHL+vWqys99hCxoZ4pIM5Sh+6IXjlhxU4ulBGSLocyT5sZWjXBCjqNWcSvQkO/QGtbknv+/tBZ1zz10So+wg9i7B+YVrsz+KyQEv1rD/oMinFjo5pM6dODn3r0zM+xsck877edmSJb5irsOJFh4eGTeL0EDSRHspNkMpfbD9TvyR0usyPLlwou9FTqmpvUoe/vMCIKZVAbLKZjpzUS/WnQkbwT5ZFvg7gO7Ju1YC8suo6qTRYaO82495uUYBy+Sep4cY4fApDi3k3dQk+4JhzPRUnRpJGuhQ9AOcHmlw+PecrZpq5e5rnUNQUKzE4NoBdKqHg4EP8fZn6rlhMneQsnHeKpy8M85w4BMzdtGYBehNmS3RWlYqqJGDav4MM0u8zg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR10MB6597.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-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RuSESH7Dlz243OKRpbgw8m7pgyoZUFePiEgMzR0jsCxuijCdD19x8v6xUGAT7IpFfBXUp60ffKpip6mNOk2UO3+rXfNPXJFydFZobNUh06VMQX20o6wWtJgAmekSj0KRVDuzAjNOt2w/E7sMqPit/CoMdFZFu6+5BagENIjlnHE9GVishQLL55VRkZHWu3haVfh0NUdC8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: aab1d693-8788-4265-d9ff-08dce499b3c6 X-MS-Exchange-CrossTenant-AuthSource: PH8PR10MB6597.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2024 17:26:37.8743 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QE6rqgkq+0sUPurblpB8pLqx6D/Nd6qnbTk1EIefTluE+aRf/vtR9pFrQlwYTLOw/V31KArvzQsyoJX3IHhYsN6TUUyeicTFfqH2hZNSQ3s= X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR10MB7745 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-04_14,2024-10-04_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 suspectscore=0 spamscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410040119 X-Proofpoint-ORIG-GUID: Z-I5AbmfxGEbCTlREknKXSekUljyU18U X-Proofpoint-GUID: Z-I5AbmfxGEbCTlREknKXSekUljyU18U So far, pahole has only encoded type information for percpu variables. However, there are several reasons why type information for all global variables would be useful in the kernel: 1. Runtime kernel debuggers like drgn could use the BTF to introspect kernel data structures without needing to install heavyweight DWARF. 2. BPF programs using the "__ksym" annotation could declare the variables using the correct type, rather than "void". It makes sense to introduce a feature for this in pahole so that these capabilities can be explored in the kernel. The feature is non-default: when using "--btf-features=default", it is disabled. It must be explicitly requested, e.g. with "--btf-features=+global_var". Signed-off-by: Stephen Brennan Reviewed-by: Alan Maguire Tested-by: Alan Maguire Acked-by: Jiri Olsa --- btf_encoder.c | 5 +++++ btf_encoder.h | 1 + dwarves.h | 1 + man-pages/pahole.1 | 7 +++++-- pahole.c | 3 ++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/btf_encoder.c b/btf_encoder.c index 838a0b1..201a48c 100644 --- a/btf_encoder.c +++ b/btf_encoder.c @@ -2348,6 +2348,8 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->encode_vars = 0; if (!conf_load->skip_encoding_btf_vars) encoder->encode_vars |= BTF_VAR_PERCPU; + if (conf_load->encode_btf_global_vars) + encoder->encode_vars |= BTF_VAR_GLOBAL; GElf_Ehdr ehdr; @@ -2400,6 +2402,9 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam encoder->secinfo[shndx].name = secname; encoder->secinfo[shndx].type = shdr.sh_type; + if (encoder->encode_vars & BTF_VAR_GLOBAL) + encoder->secinfo[shndx].include = true; + if (strcmp(secname, PERCPU_SECTION) == 0) { found_percpu = true; if (encoder->encode_vars & BTF_VAR_PERCPU) diff --git a/btf_encoder.h b/btf_encoder.h index 91e7947..824963b 100644 --- a/btf_encoder.h +++ b/btf_encoder.h @@ -20,6 +20,7 @@ struct list_head; enum btf_var_option { BTF_VAR_NONE = 0, BTF_VAR_PERCPU = 1, + BTF_VAR_GLOBAL = 2, }; struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filename, struct btf *base_btf, bool verbose, struct conf_load *conf_load); diff --git a/dwarves.h b/dwarves.h index 0fede91..fef881f 100644 --- a/dwarves.h +++ b/dwarves.h @@ -92,6 +92,7 @@ struct conf_load { bool btf_gen_optimized; bool skip_encoding_btf_inconsistent_proto; bool skip_encoding_btf_vars; + bool encode_btf_global_vars; bool btf_gen_floats; bool btf_encode_force; bool reproducible_build; diff --git a/man-pages/pahole.1 b/man-pages/pahole.1 index b3e6632..7c1a69a 100644 --- a/man-pages/pahole.1 +++ b/man-pages/pahole.1 @@ -238,7 +238,9 @@ the debugging information. .TP .B \-\-skip_encoding_btf_vars -Do not encode VARs in BTF. +By default, VARs are encoded only for percpu variables. When specified, this +option prevents encoding any VARs. Note that this option can be overridden +by the feature "global_var". .TP .B \-\-skip_encoding_btf_decl_tag @@ -304,7 +306,7 @@ Encode BTF using the specified feature list, or specify 'default' for all standa encode_force Ignore invalid symbols when encoding BTF; for example if a symbol has an invalid name, it will be ignored and BTF encoding will continue. - var Encode variables using BTF_KIND_VAR in BTF. + var Encode percpu variables using BTF_KIND_VAR in BTF. float Encode floating-point types in BTF. decl_tag Encode declaration tags using BTF_KIND_DECL_TAG. type_tag Encode type tags using BTF_KIND_TYPE_TAG. @@ -329,6 +331,7 @@ Supported non-standard features (not enabled for 'default') the associated base BTF to support later relocation of split BTF with a possibly changed base, storing it in a .BTF.base ELF section. + global_var Encode all global variables using BTF_KIND_VAR in BTF. .fi So for example, specifying \-\-btf_encode=var,enum64 will result in a BTF encoding that (as well as encoding basic BTF information) will contain variables and enum64 values. diff --git a/pahole.c b/pahole.c index b21a7f2..9f0dc59 100644 --- a/pahole.c +++ b/pahole.c @@ -1301,6 +1301,7 @@ struct btf_feature { BTF_DEFAULT_FEATURE(decl_tag_kfuncs, btf_decl_tag_kfuncs, false), BTF_NON_DEFAULT_FEATURE(reproducible_build, reproducible_build, false), BTF_NON_DEFAULT_FEATURE(distilled_base, btf_gen_distilled_base, false), + BTF_NON_DEFAULT_FEATURE(global_var, encode_btf_global_vars, false), }; #define BTF_MAX_FEATURE_STR 1024 @@ -1733,7 +1734,7 @@ static const struct argp_option pahole__options[] = { { .name = "skip_encoding_btf_vars", .key = ARGP_skip_encoding_btf_vars, - .doc = "Do not encode VARs in BTF." + .doc = "Do not encode any VARs in BTF [if this is not specified, only percpu variables are encoded. To encode global variables too, use --encode_btf_global_vars]." }, { .name = "btf_encode_force",