Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp643155rdb; Tue, 16 Jan 2024 11:06:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKuWIGtSG25ItMZNRaScNaNqNPK2tvr452/qekp+5U7GGytlmRBJ5w8spRMAsBuu15AqfR X-Received: by 2002:a17:906:4f8a:b0:a28:a7b0:b46f with SMTP id o10-20020a1709064f8a00b00a28a7b0b46fmr3355055eju.5.1705432013487; Tue, 16 Jan 2024 11:06:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705432013; cv=pass; d=google.com; s=arc-20160816; b=0euL592WaTMBsVR7mOB9yRB2/G7FZtBQIwDXeSt7Z3L/qwWsGykpPX3slEFA7DpDvP ylSvh9ZWURVgiy+BPpzUNZs2TznhtM621Vr8E1ewaO5YUeAJBvNRXKbx95YrMSBolBKI CqLu7rAyUCGF6Huolod/6oB+g7YNFU11+JbkGFzsz66pIjzotOAJo0XL43TTi8uG6JDK uaK2tg5C4vemxenSQNyRKeohdghc1cM7oGSf2rc5SqiSs/YMQHaGBIdAfs2xoOXGXo4a GRR+lkmXAZbItpj0yOmpFCiNE3gxkJiwTDFmaF6EdXKiDRAXK/75Bw/pQJk5RwCj/TvB cMOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=UfOZxNLHz3Nwirmv1G2Ad5uBEuonc/4mQsWpuQzqT/g=; fh=ufaWAs9F2XEuff/xWOrn95Jvf76B+vIjqd1wxBFb0uk=; b=qJM56xqf2ymoAiM46CWM78g3+Xj2OfUpoOgZzC0UYUlCEzNzUB3a5pKmJXM2U0rh9V xy6QSDs8lIEu46cKCImWZ1fNPQ9NdHVNjbzsOcaeOoveUya4xS1W/qJGZ9C1Z1Xs2134 znOgqGLKntJoVc7Sr9s0/EoTDeRfObCV0qZcmOPAleCNR5DX9UQffhbg31Pe2LdTCjrg f3s1cL5+uNY94EOvtS72p3BkHB/oOvfpCFDwrUqavxjzc2pLL/svT1y6ll8HMHisy8Cy 5Mt10lgeekvXo23trvQnTSWNbUCt2jTBon4GatiHGKb/R2zbdxNm3mBBXVLWINH1egeV 8O+w== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-27724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27724-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p13-20020a1709066a8d00b00a298c862147si4972258ejr.428.2024.01.16.11.06.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 11:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-27724-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27724-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id CE56D1F25A50 for ; Tue, 16 Jan 2024 18:59:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 28B1B1D52D; Tue, 16 Jan 2024 18:59:47 +0000 (UTC) Received: from 1wt.eu (ded1.1wt.eu [163.172.96.212]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D55B1D525 for ; Tue, 16 Jan 2024 18:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=1wt.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=1wt.eu Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705431586; cv=none; b=RRtq+thJylfROXO97yu4+9ioG8vPOc902ezD/TSVgsI4m0maIPVefdMySq76G1FBLIVtmYvqHswnl8Yxwa8NGDcjaA48X85XlWwifT7/MoMy+YQOos0UGkC8VfeY2jPXnDrtf8rQF0j3FO9nJbUHizuqVXJ2P4sLa65jqg5gdqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705431586; c=relaxed/simple; bh=jP3sejhrb6IEc/7ajYGJZqFr9VzJ4VBtRR3bsDSSObE=; h=Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=N12HOmagKrxsFGlGUZ72xm+SE/p9H6KuMH3mev0bLSVP9+W2eMVd5APPWIMDW7SYOG3bxeooU2RKn9HV9jua+uCoKxSBa+AU4Fk5GVLI6Ra0T1AnID0kWPZZJSqxSZEZvph54dv1aKhv7yw2OV6lE5yCfb5z/oRDUKF+fFFQpIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=163.172.96.212 Received: (from willy@localhost) by mail.home.local (8.17.1/8.17.1/Submit) id 40GIxdwM021066; Tue, 16 Jan 2024 19:59:39 +0100 Date: Tue, 16 Jan 2024 19:59:39 +0100 From: Willy Tarreau To: Ammar Faizi Cc: Charles Mirabile , linux-kernel@vger.kernel.org, Thomas =?iso-8859-1?Q?Wei=DFschuh?= Subject: Re: [PATCH] nolibc/stdlib: Improve `getauxval(3)` implementation Message-ID: References: <20240116181147.2230944-1-cmirabil@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jan 16, 2024 at 07:58:09PM +0100, Willy Tarreau wrote: > On Wed, Jan 17, 2024 at 01:52:06AM +0700, Ammar Faizi wrote: > > On Tue, Jan 16, 2024 at 01:11:47PM -0500, Charles Mirabile wrote: > > > At least on x86-64, the ABI only specifies that one more long will be > > > present with value 0 (type AT_NULL) after the pairs of auxv entries. > > > Whether or not it has a corresponding value is unspecified. This value is > > > present on linux, but there is no reason to check it as simply seeing an > > > auxv entry whose type value is AT_NULL should be enough. > > > > Yeah, I agree with that. I just read the ABI and confirmed that the > > 'a_un' member is ignored when the type is `AT_NULL`. Let's stop relying > > on an unspecified value. > > > > For others who want to check, see page 37 and 38: > > https://gitlab.com/x86-psABIs/x86-64-ABI/-/wikis/uploads/221b09355dd540efcbe61b783b6c0ece/x86-64-psABI-2023-09-26.pdf > > > > > This is a matter of taste, but I think processing the data in a structured > > > way by coercing it into an array of type value pairs, using multiple > > > return style, and a for loop with a clear exit condition is more readable > > > than the existing infinite loop with multiple exit points and a return > > > value variable. > > > > Ok. It's more readable using your way. One thing that bothers me a bit > > is type of 'a_type'. On page 37, the ABI defines the auxv type-val pair > > as: > > > > typedef struct > > { > > int a_type; > > union { > > long a_val; > > void *a_ptr; > > void (*a_fnc)(); > > } a_un; > > } auxv_t; > > > > Assuming the arch is x86-64 Linux. Note that 'a_type' is an 'int' which > > is 4 bytes in size, but we use 'unsigned long' instead of 'int' to > > represent it. However, since 'a_un' needs to be 8 bytes aligned, the > > compiler will put a 4 bytes padding between 'a_type' and 'a_un', so it > > ends up just fine (on x86-64). > > > > What do you think about other architectures? Will it potentially be > > misinterpreted? > > Indeed, it would fail on a 64-bit big endian architecture. Let's > just declare the local variable the same way as it is in the spec, > it will be much cleaner and more reliable. With that said, if previous code used to work on such architectures, maybe the definition above is only for x86_64 and differs on other archs. Maybe it's really defined as two longs ? Willy