From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 A9E081B6D1A for ; Thu, 4 Dec 2025 19:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764875647; cv=none; b=dvFLjeNZG3Qbdu4wD7ouNd+Vcb0oZSfil/IdyUXI9jwE0+uPn/Oqf/BcP7zK97sE3Wci8+wXJrQH0zjAGUY6YdxXfcEzohCpcEsv1rhElmMGiIMjRnycOreIJvZtMSduQUEAB9zOgzSiFrK0DuJNYaUK/JxvzckiLGU9ZSKZs58= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764875647; c=relaxed/simple; bh=JQ5QxrsW4CdzbsKnoOQvJJ5PzEobus6odwezWhVo0rE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=NorDvBYLM7w1JKXgLM5qpp3bRrcxsIcj3E3otgrMGBOmlJ0p4NOFhuHxBnpiQfENAZGGFla/C2AV8Pbww68yJJ7C0oP1QWOVOKqhetMolvX+zY9cIk1oO6Kb2VcMxwA7YaNZ6Vzujz6FmaSx0S3A6iVHHsNI5YYXx4PtwcQAwzs= 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=fean+DgM; arc=none smtp.client-ip=209.85.210.169 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fean+DgM" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-7b86e0d9615so2222393b3a.0 for ; Thu, 04 Dec 2025 11:14:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764875645; x=1765480445; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=4iLBnCrKDlW6EVT4F6zHi2LCZGQ9e/O7rjq69QuiQOs=; b=fean+DgMkJaJWNycsXHznSm/HAYi0/4EqtVBqckRhe4v+TvqpVXWXoQWfA/3+dIw14 +7t4mUlqEyKfSOri3ATbWqqPjQbEEwQ77cI/nPOAS/tWX0UhYPQkWzdjVTSAIK3MjsL2 zSUKwT/QKxJqB4jKV5aGBpA5HUdp3n+CLZ4QOiqCcyfHfyHu6DZnVzGTfRsbvLtb7JYO Y/CL2WgqhSPHZbh4A7lLMK0CYgf2QZTBt47mZCNoLvWcNbMhhXhiCsfHQp50mUu4TJ3F 3sRfnoXoU6x5agBdeETGiJskNtaw4vX2/KBXHJc6n8Z3AIqKd1PvSDvnb5d2+4JuqGXy o3Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764875645; x=1765480445; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4iLBnCrKDlW6EVT4F6zHi2LCZGQ9e/O7rjq69QuiQOs=; b=wcn7w8H/34RMo7xINTpBsHavy2q7p4VVe8Im0wXmQEs9VE6U78arpkBCBZivsam81x hph88Opy3iDYLB4tLDa6uQ/I+m6E+a/wprp/g8hwv8672KDh1WN1/Wa37ZuG2v1Metn1 h/cZR1Zym93BtVaXPCKzNXXzWAPMX00YH9QAlsW8Zw/b/KfRhUyJM0yJxgzHpjJ2fHIT YZ0Hedhq8EdL75KNfHAMhrRHSNebSEb9/hYFEBok2GoRtBaVv2vBPKP02+Z1ZY69UMUv QkTpOuu6rfFJouOLojPQY0oSfAjg/XhCQfnThlkDX5LSigW4MTWuo+0osC/EU+NwnHzO QM/g== X-Forwarded-Encrypted: i=1; AJvYcCUX4lk/LVDDNkfEJkGNEhQrqZRKu/OucffaMknBizxrb/MWG5dbQMtuVBcxJZqBvWARH0g/CgIr4A/kFBk=@vger.kernel.org X-Gm-Message-State: AOJu0YzPEIXJW6/0LqEUkLdzavuUeNMaw4/05NalnbdS+R7n0xWSbVDj 6i5tdPfQFRGcYziVXpV6+Fr7dbkK2xqSCvO2qrpiMCwEA0+Ujk8Sk2Th X-Gm-Gg: ASbGncth2/2pBnLQTvM1ZxbioERMngjUElyFfCh74m1pqcOcCGwb6U1Ch+vKGQuIKIN 9j9jk3lf5ZesFtYzjhNJgDwLdMEv3pFX1F6uCuPKlGAbDF+RHhVik9rZbVz2EX3KOoqRkWWnktQ QGanVCsnA7ksvM6kKLt4zIWwB3w+FMd3rzp4xTMAVSFUtXIc3JVXpxcp0l1y7UpJKBcSqK+U/f3 stVsdI8feDW0dg8eVCgGv0rdAwYzS5VGk/YQkcvIclGjrq58dGoxEmbZOlYGWt5ENjGGJGai8XH kCWr7qYeaDlw867V+b4KTkSsDhpPoBDsggvT+TptKS43v4RFfsTA1z/8LDdt08DfZd2Ui2dCiCk QLxZyt3mbYwbO5tuwqZJCjn2Yty8GhG72mf3k8Pm+qN1pfcQJ/RusYr6t4OOKf6SP6qjHoImNcB +LkjyZhro7 X-Google-Smtp-Source: AGHT+IHDD2gcPeEJ2VqP0Gvh25ZpaJm4IY72MOY+qLFxj6wemLduQ7TOYEB8DY54v2FdPw9GuEZqCQ== X-Received: by 2002:a05:6300:210c:b0:35d:a823:2ff7 with SMTP id adf61e73a8af0-363f5d32a43mr9086859637.1.1764875644746; Thu, 04 Dec 2025 11:14:04 -0800 (PST) Received: from [192.168.0.226] ([38.34.87.7]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-bf6a2745cd3sm2509085a12.27.2025.12.04.11.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Dec 2025 11:14:04 -0800 (PST) Message-ID: <6cdae76c99bb74c3389a05e39c34732c2ca172c6.camel@gmail.com> Subject: Re: [PATCH bpf-next v2 4/4] resolve_btfids: change in-place update with raw binary output From: Eduard Zingerman To: Ihor Solodrai , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Alan Maguire , Donglin Peng Cc: bpf@vger.kernel.org, dwarves@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org Date: Thu, 04 Dec 2025 11:14:01 -0800 In-Reply-To: <131b4190-9c49-4f79-a99d-c00fac97fa44@linux.dev> References: <20251127185242.3954132-1-ihor.solodrai@linux.dev> <20251127185242.3954132-5-ihor.solodrai@linux.dev> <763200e4f55197da44789b97fd5379ae8bf32c08.camel@gmail.com> <79031f38-d131-4b78-982c-7ca6ab9de71e@linux.dev> <707080716569c7de7c3cb5869b67d62b55a96b68.camel@gmail.com> <131b4190-9c49-4f79-a99d-c00fac97fa44@linux.dev> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2 (3.56.2-2.fc42) Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2025-12-04 at 11:04 -0800, Ihor Solodrai wrote: > On 12/4/25 10:06 AM, Eduard Zingerman wrote: > > On Thu, 2025-12-04 at 09:29 -0800, Ihor Solodrai wrote: > >=20 > > [...] > >=20 > > > Ok, it seems you're conflating two separate issues. > > >=20 > > > There is a requirement to *link* .BTF section into vmlinux, because i= t > > > must have a SHF_ALLOC flag, which makes objcopying the section data > > > insufficient: linker has to do some magic under the hood. > > >=20 > > > The patch doesn't change this behavior, and this was (and is) covered > > > in the script comments. > > >=20 > > > A separate issue is what resolve_btfids does: updates ELF in-place > > > (before the patch) or outputs detached section data (after patch). > > >=20 > > > The paragraph in the commit message attempted to explain the decision > > > to output raw section data. And apparently I did a bad job of > > > that. I'll rewrite this part it in the next revision. > > >=20 > > > And I feel I should clarify that I didn't claim that libelf is buggy. > > > I meant that using it is complicated, which makes resolve_btfids bugg= y. > >=20 > > So, pahole does the following: > > - elf_begin(fildes: fd, cmd: ELF_C_RDWR, ref: NULL); > > - selects a section to modify and modifies it > > - elf_flagdata(data: btf_data, cmd: ELF_C_SET, flags: ELF_F_DIRTY); > > - elf_update(elf, cmd: ELF_C_WRITE) > > - elf_end(elf) > >=20 > > What exactly is complicated about that? >=20 > Take a look at the resolve_btfids code that is removed in this patch, > as a consequence of switching to read-only ELF. >=20 > Also consider that before these changes resolve_btfids had a simple > job: update data buffer of a single section, importantly, without > changing its size. >=20 > Now let's say we keep "update in-place" approach (which I tried to do, > btw). In addition to previous .BTF_ids data update, resolve_btfids may > need to either add or update .BTF section changing its size (triggering > reorg of sections in ELF, depending on the flags) and add .BTF.base > section. There is also a question of how to do it: do we elf_update() > multiple times or try to "batch" the updates? >=20 > All of this is possible, but the alternative is much simpler: >=20 > ${OBJCOPY} --add-section .BTF=3D${ELF_FILE}.btf ${ELF_FILE} >=20 > Why re-implement our own incomplete version of objcopy if we can just > use it to deal with the details of the ELF update? >=20 > Note also that even in pahole "add .BTF section" is implemented via > llvm-objcopy call. My guess is: to avoid the headache of figuring out > correct libelf usage. Please put this motivation in the commit message.