From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-0010f301.pphosted.com (mx0a-0010f301.pphosted.com [148.163.149.254]) by sourceware.org (Postfix) with ESMTPS id 821873858423 for ; Tue, 17 Oct 2023 19:06:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 821873858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=rice.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rice.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 821873858423 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.149.254 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697569575; cv=none; b=WlWitEKE4ju6U33eAevfOb9wZexIbjpwR6jio4CzffkCaw4HxZWJusLJ/qBQTALOfI19JZeAaegi4179QhMpEEWMcoYYKVwGf85FtbFuGpjaw/p3O5C5/byI+WV4aslzghYobCNEKZOiHv6V0ZgFq+6M366Fhg+b/JfnV/4Tn+U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697569575; c=relaxed/simple; bh=7Xxt8mCoKyc5YAF+riNR8uQinnT8ku70YD1d4IAOTgU=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SZtQ8XWyes/ZhRgGILh07ySNg32s3HsUNl8iZt8QUIR2lbN3YZXx4pg41fE3qNmW8qOZGgWvNfQbodGApDFgqT6N5HcRogEKncPhD8f0Qy9DqvCR1/fzmuLGyRiVqoEDVnVWcP2Fb5sBTJ3hF30EN93dBMhKwyDEBn1Qkk6ON8o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0102856.ppops.net [127.0.0.1]) by mx0b-0010f301.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 39HHSpx7024263 for ; Tue, 17 Oct 2023 14:06:12 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rice.edu; h= mime-version:references:in-reply-to:from:date:message-id:subject :to:cc:content-type; s=ricemail; bh=AKO9LPZMz+zzd5RoadFeadzZhfbO GHo+fxmLZpHfaG8=; b=cZwBIHCmYl8rZdBjC9sO/htSBhsfzXs2N48RzDLFyPBy b/uZCqaNhb/fZyAwrSy1L7m69ht5yhNi6kmMbxOTQcy8DRaQVeAXlvLwXePDId2g fnMQKu24ffsIvx8IHX/WZ6rtW6v2B2XgsZZtlJ1qbM2NOe3v/G6jQ7p9Tjjl0YAG JE2DocCsoQmP+zyaw342G3seMnwugrKZF5rzXVZZAmQT5emGRgx2iIIp5ie2KwLX xB2iy6Vk6EV6zweCtljYcXsdfrQVY0UNQMKqHn8aGIyM8+4QypDSdi4gM739eCnL /3ctP8e8hlqQWC7G1ZjEm/Msto4aFOKizjue2gZ2uQ== Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by mx0b-0010f301.pphosted.com (PPS) with ESMTPS id 3tqr41562k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 17 Oct 2023 14:06:12 -0500 (CDT) Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4055ce1e8c4so31837215e9.0 for ; Tue, 17 Oct 2023 12:06:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697569569; x=1698174369; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AKO9LPZMz+zzd5RoadFeadzZhfbOGHo+fxmLZpHfaG8=; b=cMTU7b5qXvCBsc+v6KNvrLlEmMuh0B+E98RV54dufNR073K5HQhP6GxoWrp0Mr57kx sbeGsEYNqatO1nUbbkm5NXqrtkdoPhjxw/WhxVbiMvQm0vjkLx1hk8bQQjthEDuS+vi1 oqDJQgl1oj8CUcFrFMWGoovjhfe8wiU3FPQLtmqTbB0Be9Ol3xYWQVxD0YFhi8DwuoPZ ZymJeGr7jHTrSCbGb3PIlg0IZk1pfSLd1amS2yi3AxKI7oYiMy/Ajcp4pZIyhJAFoJS1 tB2pK8CIVoRFOkx6EX50lJ0nvG6N3B4kTycW0jVdeDLCWQN4JzmkGDKL3sydNiqNuYwD RCZA== X-Gm-Message-State: AOJu0YzA2XkpDfEXjJE4eOWB9UIxpRXOS5wgG6bFEgC+Ejx2yB629rRR ZtYfUXrHBD34mmdVuK41KqGKjcm2PMIduouGhDJsmFqstPKBTC4qQswuonPgCYyzUtkYC1SCFUS swx/AJfTnpHxMep34zuro4Htp8ENJ/CO/K9LVcteD87ZKJgVI25KCktp3YlM2aAM1i0bYyiUVAZ wumaU= X-Received: by 2002:adf:b305:0:b0:32d:a2c2:bad with SMTP id j5-20020adfb305000000b0032da2c20badmr2514393wrd.2.1697569569767; Tue, 17 Oct 2023 12:06:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFi9SiNQ0z86l/owqqFlaZW28+G3XKdOHXVFWtRUpjkgOPNNUB/gw/8aIaD2j5D6J5+SeEy6rNsEH93R9cZ1zA= X-Received: by 2002:adf:b305:0:b0:32d:a2c2:bad with SMTP id j5-20020adfb305000000b0032da2c20badmr2514382wrd.2.1697569569385; Tue, 17 Oct 2023 12:06:09 -0700 (PDT) MIME-Version: 1.0 References: <301fac87e83ebbbd677750579ae9a3429b461bdf.camel@klomp.org> <20231010134300.53830-1-mark@klomp.org> <20231010134300.53830-2-mark@klomp.org> <99c0df19c4fe86f9142597b62fedac1bc1b85e75.camel@klomp.org> In-Reply-To: <99c0df19c4fe86f9142597b62fedac1bc1b85e75.camel@klomp.org> From: Heather McIntyre Date: Tue, 17 Oct 2023 14:05:58 -0500 Message-ID: Subject: Re: [PATCH 02/16] libelf: Make elf_version thread-safe To: Mark Wielaard Cc: elfutils-devel@sourceware.org Content-Type: multipart/alternative; boundary="0000000000002a4d210607ee37fe" X-Proofpoint-DLP: Gmail-Outbound X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_03,2023-10-17_01,2023-05-22_02 X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,HTML_MESSAGE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000002a4d210607ee37fe Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable John and I discussed that atomic_compare_exchange_strong could have been used here. I see that this has been pushed to the main branch, but I can make the change to the atomic operation if you think that is a better option. Best, Heather On Tue, Oct 10, 2023 at 9:00=E2=80=AFAM Mark Wielaard wrot= e: > Hi Heather, > > On Tue, 2023-10-10 at 15:42 +0200, Mark Wielaard wrote: > > From: Heather McIntyre > > > > * elf_version.c (version_once): Define once. > > (initialize_version): New static function. > > (elf_version): Use initialize_version version_once. > > > > Signed-off-by: Heather S. McIntyre > > Signed-off-by: Mark Wielaard > > --- > > libelf/elf_version.c | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/libelf/elf_version.c b/libelf/elf_version.c > > index 6ec534ab..8296bb65 100644 > > --- a/libelf/elf_version.c > > +++ b/libelf/elf_version.c > > @@ -32,12 +32,21 @@ > > #endif > > > > #include > > +#include > > > > +/* Multiple threads may initialize __libelf_version. > > + pthread_once() ensures that __libelf_version is initialized only > once. */ > > +once_define(static, version_once); > > > > /* Currently selected version. Should be EV_CURRENT. > > Will be EV_NONE if elf_version () has not been called yet. */ > > unsigned int __libelf_version =3D EV_NONE; > > > > +static void initialize_version(void) > > +{ > > + __libelf_version =3D EV_CURRENT; > > +} > > + > > unsigned int > > elf_version (unsigned int version) > > { > > @@ -49,7 +58,7 @@ elf_version (unsigned int version) > > /* Phew, we know this version. */ > > > > /* Signal that the version is now initialized. */ > > - __libelf_version =3D EV_CURRENT; > > + once(version_once, initialize_version); > > > > /* And return the last (or initial) version. */ > > return EV_CURRENT; > > This is an odd function. The intention clearly was to support more "ELF > versions" at some point. But (luckily) that never happened and I doubt > there will ever be a different (incompatible) ELF version that we'll > have to support. So in the end this will always be EV_CURRENT =3D=3D 1. B= ut > the function has to be called to make the rest of the library work. > > I think this works and is fine. There will most likely never be real > contention calling elf_version because normally a program just calls it > once at the start. > > But have you thought about using some atomic operation here instead? > > Cheers, > > Mark > --0000000000002a4d210607ee37fe--