From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 13AD53858C60 for ; Fri, 27 Aug 2021 15:24:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13AD53858C60 Received: by mail-ej1-x634.google.com with SMTP id a25so14609744ejv.6 for ; Fri, 27 Aug 2021 08:24:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=nuvj9QxOI4vo1ZWuxEf53tVHNWjr9CPtnHX/tdrSV/8=; b=HPrFVztYw2JLDHahfZFpZxxtAQ9+uNJpTZ6jaS2BiF3uJI48FJbgRcpMaQTnS0zbyU iLwjlLzB4X7gCdE3TXu8wP1Mkceg4LMhE6jgtNFcTVP6bSxvptzzuZiBnrs+vVZNmuJm Svivsi6PWPNMtLz3Q0kxTtkYRTfb1Gfgb4WsimQOUW15UNcjcXQ6gBkz0jaLGuH9MSUZ dI9SlvQw3TXwURZKFBktYBu0yVYAY6DCAB2E/yeHwy906LcSeDbXt6XUeSBUZzv2VqNP iMGlwwPPCjaH3MgILdAgBFzKh5DGxEJNdMbkYtK3EmVXc/RTB9F0RBVca1EZeuLmJSQv LWfg== X-Gm-Message-State: AOAM532HvTQiLxPphdOrVH/SEoIpmu3WLKvRw89fDkQu7fgb0Dh85XTe 8wiDTYo54th/KUPDSGQ3XrkGpbl2OIwyGnRZZRyq1XhYrd0= X-Google-Smtp-Source: ABdhPJxDeKVvHlgDx+Cdz2CsIN5tsomn7MLRjiggEd/mMjfIm9XTt4IF65tWwGeDAFMxPffTk0HUpCBGjQUKfmi3s9g= X-Received: by 2002:a17:906:c443:: with SMTP id ck3mr10319074ejb.195.1630077867485; Fri, 27 Aug 2021 08:24:27 -0700 (PDT) MIME-Version: 1.0 References: <20210820202823.2865202-1-abdulras@google.com> In-Reply-To: <20210820202823.2865202-1-abdulras@google.com> From: Saleem Abdulrasool Date: Fri, 27 Aug 2021 08:24:16 -0700 Message-ID: Subject: Re: [PATCH v2] handle libc implemntations which do not provide `error.h` To: elfutils-devel@sourceware.org X-Spam-Status: No, score=-27.6 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2021 15:24:39 -0000 I think that this is not exactly ideal, as it will introduce a local error_message_count in each translation unit, rather than giving it vague linkage as I had hoped. I think it may be better to introduce a new source file here. I can move the implementation around though. A second issue is that playing with this further, it doesn't fully resolve the PR as this only fixes it for libelf (which I realized only recently). On Fri, Aug 20, 2021 at 1:28 PM Saleem Abdulrasool wrote: > Introduce a configure time check for the presence of `error.h`. In the > case that `error.h` is not available, we can fall back to `err.h`. > Although `err.h` is not a C standard header (it is a BSD extension), > many libc implementations provide. If there are targets which do not > provide an implementation of `err.h`, it would be possible to further > extend the implementation to be more portable. > > This resolves bug #21008. > > Signed-off-by: Saleem Abdulrasool > --- > configure.ac | 3 +++ > lib/system.h | 26 +++++++++++++++++++++++++- > 2 files changed, 28 insertions(+), 1 deletion(-) > > diff --git a/configure.ac b/configure.ac > index 7caff2c5..177bb1a2 100644 > --- a/configure.ac > +++ b/configure.ac > @@ -431,6 +431,9 @@ AC_CHECK_DECLS([reallocarray],[],[], > > AC_CHECK_FUNCS([process_vm_readv]) > > +AC_CHECK_HEADERS([error.h]) > +AC_CHECK_HEADERS([err.h]) > + > old_CFLAGS="$CFLAGS" > CFLAGS="$CFLAGS -D_GNU_SOURCE" > AC_FUNC_STRERROR_R() > diff --git a/lib/system.h b/lib/system.h > index 58d9deee..b963fd15 100644 > --- a/lib/system.h > +++ b/lib/system.h > @@ -29,8 +29,9 @@ > #ifndef LIB_SYSTEM_H > #define LIB_SYSTEM_H 1 > > +#include > + > #include > -#include > #include > #include > #include > @@ -38,8 +39,31 @@ > #include > #include > #include > +#include > #include > > +#if defined(HAVE_ERROR_H) > +#include > +#elif defined(HAVE_ERR_H) > +#include > + > +static int error_message_count = 0; > + > +static inline void error(int status, int errnum, const char *format, ...) > { > + va_list argp; > + > + va_start(argp, format); > + verr(status, format, argp); > + va_end(argp); > + > + if (status) > + exit(status); > + ++error_message_count; > +} > +#else > +#error "err.h or error.h must be available" > +#endif > + > #if __BYTE_ORDER == __LITTLE_ENDIAN > # define LE32(n) (n) > # define LE64(n) (n) > -- > 2.33.0.rc2.250.ged5fa647cd-goog > >