Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp652104rdb; Tue, 16 Jan 2024 11:24:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuB70k0qthbPT3nPIDzcu9NA+FfDvSjFogqVndhROw6wn5n69CLEzg+W/em/awjfQyYY5y X-Received: by 2002:a92:ad0b:0:b0:35f:c4c4:e3c2 with SMTP id w11-20020a92ad0b000000b0035fc4c4e3c2mr9547307ilh.24.1705433049014; Tue, 16 Jan 2024 11:24:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705433048; cv=pass; d=google.com; s=arc-20160816; b=Ev8F5bCg6XmecXc+D8DmwCqn7hi/3W0nAw8mMlQwKEF5N0qkOFxNVjNvClvKJf8LVq H9nQyAIxKmQkVG1nkxeZq7SJQgw2GtoLXuH7S7lGfgaCQei96HLmGCGCXKXkenzwy3Bt xK4G5/M1IaSs6wxb1XcIPFkcKWo0Tt2lWSpGVtMFzb0+rhb7vCQtgXuaKK57FeDakP7V TkXfXAHNQS4/Ns4T0XgNlMy6a/W2c9d6OWp2AAApNQipb3msDMYqE/LSPuqpPTwujjgc Ylq/Uca9Yw18sfwhR+ekOFybraCmi04VtSq7ctSevxTFBKMWeOpG/vUv4FKWnjAcIUw3 fM6g== 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:dkim-signature; bh=4FM75GwNhnkkxdE+yqIM4XYrD9N2td5C5RPdUU3EZXc=; fh=sLlGX4KwWmNNm5EEmMq1LSDk+0vAZSkHhOCDyXKXWSU=; b=SQlXYqYhiicXBy/LBSVpwg9KMLbK6PsSnvAZRJRo34OcAighdAjMfu7BjvS9hPl26+ tpiLFwKKGPdJ363Cnk3lk/JLaToVZBfank6Xrb2TeoSfUunqOvbEM3Rv3bvKMGugY66k SceqqKefAHFlfeyljK+psXgbazdgOEiOsnLeIuxA+wzdjAuu+Yh7duC7482GgYhP5lMQ avdQ5czJSDtDtlGzKNLjHs3y/woMQtFW2lzHr8ORz9DAm8DpTjoBY/W2KyspSoMFwcHf WaueFDKTdKjEjvO3/UEXCfBZzxkm6dcAqWxLM54TPNV90EFDpSn8HEgx6c6v3gVPiQN8 BcwA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=TJ9asV4B; arc=pass (i=1 dkim=pass dkdomain=gnuweeb.org); spf=pass (google.com: domain of linux-kernel+bounces-27749-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27749-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=gnuweeb.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k7-20020a6568c7000000b005ce06f2a3d0si11111531pgt.605.2024.01.16.11.24.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 11:24:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27749-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gnuweeb.org header.s=default header.b=TJ9asV4B; arc=pass (i=1 dkim=pass dkdomain=gnuweeb.org); spf=pass (google.com: domain of linux-kernel+bounces-27749-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27749-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=gnuweeb.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E9AA72861AE for ; Tue, 16 Jan 2024 19:24:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CAA01D529; Tue, 16 Jan 2024 19:24:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b="TJ9asV4B" Received: from gnuweeb.org (gnuweeb.org [51.81.211.47]) (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 352DF1D520 for ; Tue, 16 Jan 2024 19:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gnuweeb.org Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.81.211.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705433041; cv=none; b=apPcDXCDLla4EtY2MfaODt7uMohbGfuwJcU3cHJTMQnA8ngl3sX/BDrwkeHHAlivd0WluNbxUsFfbxYiwIPaN9LQKROl7skcMqx5/74Y6qX3yD0oj5NGHi01fwIvvXFGgjihJn+SYOvqsCErnIzPUZkgTvexNZTxkVwqCvUY6T4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705433041; c=relaxed/simple; bh=CJ7g0DeUZB0QrtvedOt7eXQmDHJZHSUzbYyX7LzgXWw=; h=DKIM-Signature:Received:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: In-Reply-To:X-Bpl; b=niwDBGBH874bm42cqJrcuYylVBzfhwwAL9BktkOtRB6DxDKLADLqKcUMbhzfPqxO18/L7P/yuFdEYs8LMb59bPwoWsk+GwS5GvEjdrC4jSujhhmOVvn2s9PHK8grYDIf47ZBcnC/hRXl7JuLuWCXhU5btjhYiPAzxoMXoTzc4zA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gnuweeb.org header.i=@gnuweeb.org header.b=TJ9asV4B; arc=none smtp.client-ip=51.81.211.47 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1705433039; bh=CJ7g0DeUZB0QrtvedOt7eXQmDHJZHSUzbYyX7LzgXWw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=TJ9asV4BoSng9oirPy4OMuQKteQlYm92oHmrprjdQYtR1ml+lHq4NPw53tPesfql9 5Ri8yQFWx7Bi13QIybjjPNDJIrqQhdCdW2i9cjh4FglZPV0+nWRFM8AB/G1FkxFkmW hsvy0o/lPRF8cuI2FRe/CMOqGcK4OAkbRw2mr1jJRuAPHyckY74lGnctZbHQERf5yH SQe+0eqiA8uRyiswc6V/xq1LUbrMnFakZdAK5OXGfwzgQAdA5Hm4K6Nn0BiqIgNMmn HpRVQgsiXjSPwjIQLEnKYORwJrFXkN7YgDaYJwDHSpbVWsEKkDXSnPHk8iq1iQn2BI alhqiRhGMXEMA== Received: from biznet-home.integral.gnuweeb.org (unknown [182.253.126.189]) by gnuweeb.org (Postfix) with ESMTPSA id BC4A724C3A2; Wed, 17 Jan 2024 02:23:57 +0700 (WIB) Date: Wed, 17 Jan 2024 02:23:53 +0700 From: Ammar Faizi To: Willy Tarreau 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: X-Bpl: hUx9VaHkTWcLO7S8CQCslj6OzqBx2hfLChRz45nPESx5VSB/xuJQVOKOB1zSXE3yc9ntP27bV1M1 On Wed, Jan 17, 2024 at 02:11:12AM +0700, Ammar Faizi wrote: > On Tue, Jan 16, 2024 at 07:59:39PM +0100, Willy Tarreau wrote: > > 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: > > > > 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 ? > > I just took a look at the kernel source code: > https://github.com/torvalds/linux/blob/v6.7/fs/binfmt_elf.c#L226-L261 > > The auxv is stored in `elf_info` variable, the type is `elf_addr_t`. Not > sure what kind of typedef is that. I'll check. > > Each auxv entry is added using this macro: > > #define NEW_AUX_ENT(id, val) \ > do { \ > *elf_info++ = id; \ > *elf_info++ = val; \ > } while (0) > > where `id` is the type. That clearly implies `type` and `val` have the > same size on the Linux kernel. So here is the result: 1. 'elf_addr_t' defintion ( https://github.com/torvalds/linux/blob/v6.7/include/linux/elf.h#L38-L62 ): (simplified) #if ELF_CLASS == ELFCLASS32 #define elf_addr_t Elf32_Off #else #define elf_addr_t Elf64_Off #endif 2. 'Elf32_Off' and 'Elf64_Off' typedefs ( https://github.com/torvalds/linux/blob/v6.7/include/uapi/linux/elf.h#L8-L23 ) typedef __u32 Elf32_Off; typedef __u64 Elf64_Off; Assuming 'ELFCLASS32' is for 32-bit architectures, then it's two __u64 on 64-bit arch, and two __u32 on 32-bit arch. That is identical to 'unsigned long' for both cases (on Linux). So it's fine to have 'unsigned long' for both 'type' and 'value'. -- Ammar Faizi