From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 BBB582EDD64 for ; Thu, 4 Dec 2025 19:14:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764875648; cv=none; b=Cti933RGfgtGINrDol2/jjAmM2a/2Psy4xejyS9Uevok/rYZu5SWFXwAZR1Pkqma8+0Rz7fTFgeNcwE3J+vHftm2N2VOBzzolwGU0Agw/NZkeSYXR+0J2YJrPKriPHVpsGss/YyY7gQNmj1RMRv8iMc9jive+kJ1frFTGlqY4q0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764875648; c=relaxed/simple; bh=JQ5QxrsW4CdzbsKnoOQvJJ5PzEobus6odwezWhVo0rE=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=qEADrD+WWFQuaJh6t8/ZEsmlzcuezC6PVv6yG9qipZWiykteHYils9tYP0Ns/wfJ2qaNIGvh/iCfdrevX/yJo7ifEjro2Z6dhK9TOtnLQmkBPLDje0cDd2GU7+cRGCXFnxldYkFUS1LVABQq9/x5Vv55q8wEAd9ZYIO2gQ0YOxc= 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.182 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-f182.google.com with SMTP id d2e1a72fcca58-7b86e0d9615so2222392b3a.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=oEG1CGOefXgnivxtN6AsKdfTwT2iMmmq50pXbCX1s+mIu4wU2inytMhntNUgigWiNN /RqO4p7gXOe+ej24IFCKXwyMAAUlURRJlLtCrVW1sQevetitV5yuOeGs63CDkaVeWRdt jKJzzLmQ7y/WW8u+DmwLYh+xVqC2Vhi2F65fNJBmWtY2EUNE4p2OW1rqzG4sSF4Y/m+8 jGi43eRyVZwReeg2hBMmqaDMiHR/oTelYNH9HHH+GbTgZQWCfqlZPryW3ZIr54RSuCjW D5jSux/ONxGwcQS5w9QAC+LPrf5t30zjtqyzDeo3ctrYwXBsgcMb1p9ybSDVwigjjL0e Z16A== X-Forwarded-Encrypted: i=1; AJvYcCW2kpqpeoSAE/+WbGgnwlM9sd+XM3AfAanFPXD/Br0Co1sF/pc3eD19guzSfHUcl8wQWRXyQ8MtkhKPhiw=@vger.kernel.org X-Gm-Message-State: AOJu0YwhBJB2S72uaE7D70njA8/hP/NZNWxb+wt2grnDgODg7OGHkxwv lfaYswyx3sPRR8CS5PjYq0U6hYyz9EMnSYUdPNgTvLt+nl2UCnevNDtI X-Gm-Gg: ASbGncs+eauupxPGEDVKZ5lWr30aAnXrid8M/l5AszbHET9bZbqdemkF5DzE3XGm/uh mqcCTlqvUc6E3ke6rHKVL4iTug74snqhhZ1GbLwn02AgBXhwN9+H7Gc2Iyn66KlKqdSlBwPnzXb wVnPBKtiENxRyjDYOaLRrT35LuEMtWcmfbd03vPobAcaGhV3KEjpGu9debWkHF8qDnjZq6ULFS/ 0eyteoV821YLVrD72TuuZoMSFA/qu7oMKm+4+HdXEVl6rtQYrpIQauWyea0Z2ULlx5pIPt8wndS +hQGQA0NxON8RmOZAPmWWHGjxBP5CdJs0olwMI6jW3LF6yfz+tho5Dm7kiI4983hWAXWioyPJWk OahC/wXfW/dNUm937J5tKzBj3qAnwfhVoXlz2iz0372fXCFhnBrRoY4vybgPBFk39E30zOIPevv o90SQuv83w 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-kernel@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.