From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3FwopYQgKDt4ABDULRASGOOGLE.COMELFUTILS-DEVELSOURCEWARE.ORG@flex--abdulras.bounces.google.com> Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by sourceware.org (Postfix) with ESMTPS id 63F633858C60 for ; Fri, 27 Aug 2021 15:51:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 63F633858C60 Received: by mail-yb1-xb4a.google.com with SMTP id z8-20020a25ad88000000b0059a94ada16fso6938310ybi.4 for ; Fri, 27 Aug 2021 08:51:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Q9A/OfqA3mObpxTPMfgXeCC1LGwgDCzV/3x4wneoDOs=; b=LmWYg5F6GiwNd27rvuxFwp4v0dTmbrhNuK0A+jyAiE7Tp12dwWyMnvSDKze18Emyzn RMfotVQ+7GOd5kyVLZY/KI+Gwjx0sa4MppsYJyrKS8PHhEXKs8jnQBZvNiihRaDMR7/D oRVH3gg2KciWYrFzZcIWe4HcG04uLIbmW+opqCiR7XafEXSBsCDEmLT+dN02FSJVJ0R1 MLjGmXsk7rCIa2MMGltoHsDx+dLl6WuA/73UQM7v3f1k3pFL+l7PfYhC/A36trks73wx 5VUr/w2Wof4uQFkrGo6ljiM5Oix8uWyDZGEEE0EjS6g8dFBlKfb5RDHVPzS0qLix5MT0 syDQ== X-Gm-Message-State: AOAM530EcSAwJ8PZsnN41NuEIswfxYsjoFuGcbZri5cEmSsb9fW5pFXd QtDBtlIWLIXOmg/5CJMJNf9eUGVE+gwEEmnwrSdS8/qdfzaFzn2Evb5b5e6Fa4zgUsZ8s/v1inf jH0ZZx/Snz1CfSKBH/E7Gyghifb42rWwICQvwqF3dr/HJQ67CLMS8V8YemEX/JSzqmNjktO3m39 pU X-Google-Smtp-Source: ABdhPJxXWJOzg4bde/byTREi4TXnVA/B1MtGhbyT7sgLN27Rhx8eDJUY3mkRjjrrPR63gpobfSmv1S1HKVYy6g== X-Received: from abdulras-llvm.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:219b]) (user=abdulras job=sendgmr) by 2002:a25:4d0:: with SMTP id 199mr5947216ybe.411.1630079511945; Fri, 27 Aug 2021 08:51:51 -0700 (PDT) Date: Fri, 27 Aug 2021 15:51:47 +0000 Message-Id: <20210827155147.4069858-1-abdulras@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.259.gc128427fd7-goog Subject: [PATCH] lib: avoid potential problems with `-fno-common` From: Saleem Abdulrasool To: elfutils-devel@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-21.2 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_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 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:52:02 -0000 This properly homes the fallback function into a translation unit rather than trying to define an inline common definition for the fallback path. The intent of the original approach was to actually simply avoid adding a new source file that is used for the fallback path. However, that may cause trouble with multiple definitions if the symbol does not get vague linkage (which itself is not particularly great). This simplifies the behaviour at the cost of an extra inode. --- lib/ChangeLog | 9 +++++++++ lib/Makefile.am | 2 +- lib/error.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/system.h | 17 ++--------------- 4 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 lib/error.c diff --git a/lib/ChangeLog b/lib/ChangeLog index 589953cf..c784b689 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,12 @@ +2021-08-23 Saleem Abdulrasool + + * system.h: Remove inline definition for error and error_message_count + in the fallback path. + * Makefile.am (libeu_a_SOURCES): Add error.c. + * error.c: New file, moves the previous inline definitions to avoid + multiple definitions properly rather than relying on -fcommon and vague + linkage. + 2021-08-20 Saleem Abdulrasool * system.h: Check for HAVE_ERROR_H and HAVE_ERR_H and define diff --git a/lib/Makefile.am b/lib/Makefile.am index 97bf7329..766fbcd7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -35,7 +35,7 @@ noinst_LIBRARIES = libeu.a libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \ crc32.c crc32_file.c \ - color.c printversion.c + color.c error.c printversion.c noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \ eu-config.h color.h printversion.h bpf.h \ diff --git a/lib/error.c b/lib/error.c new file mode 100644 index 00000000..75e964fd --- /dev/null +++ b/lib/error.c @@ -0,0 +1,49 @@ +/* Definitions for error fallback functions. + Copyright (C) 2021 Google, Inc. + This file is part of elfutils. + + This file is free software; you can redistribute it and/or modify + it under the terms of either + + * the GNU Lesser General Public License as published by the Free + Software Foundation; either version 3 of the License, or (at + your option) any later version + + or + + * the GNU General Public License as published by the Free + Software Foundation; either version 2 of the License, or (at + your option) any later version + + or both in parallel, as here. + + elfutils is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received copies of the GNU General Public License and + the GNU Lesser General Public License along with this program. If + not, see . */ + +#include + +#if !defined(HAVE_ERROR_H) && defined(HAVE_ERR_H) +#include +#include +#include + +unsigned int error_message_count = 0; + +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; +} +#endif diff --git a/lib/system.h b/lib/system.h index b963fd15..edbc8488 100644 --- a/lib/system.h +++ b/lib/system.h @@ -45,21 +45,8 @@ #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; -} +extern int error_message_count; +void error(int status, int errnum, const char *format, ...); #else #error "err.h or error.h must be available" #endif -- 2.33.0.259.gc128427fd7-goog