From patchwork Thu Sep 7 13:39:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 75445 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B244A3945C1C for ; Thu, 7 Sep 2023 13:40:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B244A3945C1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1694094025; bh=mAvuLUZKUk8j0pfTtNjdewOuGs2wLZm2G3hRVzptD+g=; h=To:Cc:Subject:References:Date:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Help:List-Subscribe:From: Reply-To:From; b=kKRL9EKBvO/mHDysMiPLIlszNmpzj6kYUQJJB04WqulNlokecvA7s+qJKv7SHLmpV t5jWrsxPuKz72w2ALrEj6P72Ggi9yXS7m1a4rC9fxrBaslDzoTw2SKMxE0q1dzvWjy Om0soZaRi+1LgxoL0rfkM3QZKFcEIDAlQ2KtsXS0= X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id B820C38A8164 for ; Thu, 7 Sep 2023 13:39:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B820C38A8164 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-284-cP3b7CwENCepfpRz4ubEWA-1; Thu, 07 Sep 2023 09:39:46 -0400 X-MC-Unique: cP3b7CwENCepfpRz4ubEWA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-649832c0cf3so10691826d6.0 for ; Thu, 07 Sep 2023 06:39:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694093985; x=1694698785; h=mime-version:user-agent:message-id:in-reply-to:date:references :organization:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mAvuLUZKUk8j0pfTtNjdewOuGs2wLZm2G3hRVzptD+g=; b=BQrnIcsZXAXLkpuZ7/4YM19cNchmOgDZuUV9Dg2Y2ESg9kNaY2ED5+CIYJuEIkSjW3 OLClClF8Bz09xPyDdS12Or4sJUn4rWuiy3Sv4p8uYvj2IIVsTDpm8ljHI9kSoPRTvXHu cnsSSnq4nPo4cqd3mJKNKDl677+V9YackXgFZfrGZXLp5n4PuZ8xsT7K3CIfYl8t9Amu XCHlx+HSpE+yaurhzlcd2j/24NiwRVJ0ExRVAX03PGk8lAVqfFEp8TXeiyyaPqgk4ZPk sMVc7SZkMhtQntOZp2P2Foge0R+csfpAzJO5NSJ7Qtdvot8jzfwKp4++Fn3hXQIsbvTy zz+g== X-Gm-Message-State: AOJu0YxhgTrhhE09m2gb8FhBgfiQjS+bTUTdviOrKKb23B9FiLbT8FZA ATCC2xvTcZgC4BoczkpMkI8q/k8KgY8K3614fVrcQIn8yl1bSbwTu0zSjgdjAyRbDt98FrJso5v L1fNJYdGII9CUnfJFEZOBm1ZIL0fj X-Received: by 2002:a0c:f508:0:b0:64f:420d:18ab with SMTP id j8-20020a0cf508000000b0064f420d18abmr16789293qvm.28.1694093985559; Thu, 07 Sep 2023 06:39:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG+gcmveodqN6wHwxmoe9EmrBLVMID1yf95KsXP9EqTfC6EsuqlKYV18nIYog/NX5XJucB6AQ== X-Received: by 2002:a0c:f508:0:b0:64f:420d:18ab with SMTP id j8-20020a0cf508000000b0064f420d18abmr16789281qvm.28.1694093985329; Thu, 07 Sep 2023 06:39:45 -0700 (PDT) Received: from localhost ([88.120.130.27]) by smtp.gmail.com with ESMTPSA id u16-20020a0cf1d0000000b0063d281e22f1sm6353739qvl.17.2023.09.07.06.39.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Sep 2023 06:39:44 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 6685FB4FD2; Thu, 7 Sep 2023 15:39:43 +0200 (CEST) To: Dodji Seketeli Cc: libabigail@sourceware.org Subject: [PATCH 05/16] abipkgdiff: Initialize libxml2 to use it in a multi-thread context Organization: Red Hat / France References: <87il8mglc1.fsf@redhat.com> X-Operating-System: CentOS Stream release 9 X-URL: http://www.redhat.com Date: Thu, 07 Sep 2023 15:39:43 +0200 In-Reply-To: <87il8mglc1.fsf@redhat.com> (Dodji Seketeli's message of "Thu, 07 Sep 2023 15:32:46 +0200") Message-ID: <87v8cmf6g0.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Dodji Seketeli via Libabigail From: Dodji Seketeli Reply-To: Dodji Seketeli Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libabigail" Hello, While running some test, I stumbled upon a transient deadlock happening when using libxml2's text reader to create a reader from a buffer. After reading the documentation at https://gitlab.gnome.org/GNOME/libxml2/-/wikis/Thread-safety, I realized that users of the library need to initialize libxml2 before using it in a multi-thread setting. So this patch is providing the abigail::tools_utils::initialize() function to be called prior to using the library. This is going to be the place where to perform this kind of one-time initialization. * include/abg-tools-utils.h (initialize): Declare ... * src/abg-tools-utils.cc (initialize): ... new function. * tools/abipkgdiff.cc (main): Invoke the new abigail::tools_utils::initialize() here. Signed-off-by: Dodji Seketeli Applied to master. --- include/abg-tools-utils.h | 1 + src/abg-tools-utils.cc | 17 ++++++++++++++++- tools/abipkgdiff.cc | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/abg-tools-utils.h b/include/abg-tools-utils.h index 7f931c5d..ef748871 100644 --- a/include/abg-tools-utils.h +++ b/include/abg-tools-utils.h @@ -30,6 +30,7 @@ using std::string; using std::set; using std::shared_ptr; +void initialize(); const char* get_system_libdir(); const char* get_anonymous_struct_internal_name_prefix(); const char* get_anonymous_union_internal_name_prefix(); diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index 2ea6f8b4..62a0ebb1 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -33,7 +33,8 @@ #include #include #include - +#include +#include #include #include #include @@ -76,6 +77,20 @@ using namespace abigail::ini; namespace tools_utils { +/// This function needs to be called before any libabigail function. +/// +/// Users of libabigail must call it prior to using any of the +/// functions of the library. +/// +/// It intends to initialize the underlying libraries that might need +/// initialization, especially, libxml2, in multi-threaded environments. +void +initialize() +{ + LIBXML_TEST_VERSION; + xmlInitParser(); +} + /// Get the value of $libdir variable of the autotools build /// system. This is where shared libraries are usually installed. /// diff --git a/tools/abipkgdiff.cc b/tools/abipkgdiff.cc index 69661c5b..5ab5c22c 100644 --- a/tools/abipkgdiff.cc +++ b/tools/abipkgdiff.cc @@ -3887,6 +3887,8 @@ main(int argc, char* argv[]) | abigail::tools_utils::ABIDIFF_ERROR); } + abigail::tools_utils::initialize(); + if (opts.self_check) return compare_to_self(first_package, opts);