From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by sourceware.org (Postfix) with ESMTPS id 92C8E3858422 for ; Tue, 9 Nov 2021 09:54:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 92C8E3858422 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=seketeli.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=seketeli.org Received: (Authenticated sender: dodji@seketeli.org) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 15958240003; Tue, 9 Nov 2021 09:54:16 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id 4E06658010A; Tue, 9 Nov 2021 10:54:16 +0100 (CET) From: Dodji Seketeli To: "Jose E. Marchesi via Libabigail" Subject: Re: [PATCH] ctf: make libabigail::ctf_reader::read_corpus reentrant Organization: Me, myself and I References: <20211103133735.31664-1-jose.marchesi@oracle.com> X-Operating-System: Fedora 36 X-URL: http://www.seketeli.net/~dodji Date: Tue, 09 Nov 2021 10:54:16 +0100 In-Reply-To: <20211103133735.31664-1-jose.marchesi@oracle.com> (Jose E. Marchesi via Libabigail's message of "Wed, 3 Nov 2021 14:37:35 +0100") Message-ID: <87k0hh8xiv.fsf@seketeli.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 09:54:20 -0000 Hello Jose, "Jose E. Marchesi via Libabigail" a =C3=A9crit: > The libctf call ctf_open is not reentrant. This is because it uses > bfd_open (and other BFD calls) internally in order to fetch the > different bits of CTF from the ELF file. > > This is unfortunate, as it makes libabigail::ctf_reader::read_corpus > non-reentrant. We detected this problem thanks to one of the > libabigail test driver, that exercises tests in parallel using > threads. > > Fortunately libctf provides an alternate way to decode CTF data, that > involves the user to provide the raw contents of the relevant ELF > sections (.ctf, the symtab, the string table) to ctf_arc_bufopen > call. > > This patch changes the CTF reader in libabigail to use this > mechanism. libelf is used in order to extract the contents of these > sections. > > * src/abg-ctf-reader.cc (class read_context): New attributes > elf_handler, elf_fd, ctf_sect, symtab_sec and strtab_sect. > (read_context): Do not read the CTF archive here. > (slurp_elf_info): Adjust to use attributes instead of locals, and > fetch the raw ELF section contents for libctf. > (close_elf_handler): New function. > (fill_ctf_section): Likewise. > (read_corpus): Call open_elf_handler, close_elf_handler and build > the CTF archive using ctf_arc_bufopen instead of ctf_open. > > Signed-by: Jose E. Marchesi The patch looks great to me. I just picked some minor nits below and applied the result to master. [...] > src/abg-ctf-reader.cc | 135 ++++++++++++++++++++++++++++++++++++++------= ------ [...] > static int > -slurp_elf_info(read_context *ctxt, corpus_sptr corp) > +open_elf_handler (read_context *ctxt) I removed the space before the parenthesis. > { > /* libelf requires to negotiate/set the version of ELF. */ > if (elf_version(EV_CURRENT) =3D=3D EV_NONE) > return 0; [...] > @@ -1012,19 +1077,27 @@ read_corpus(read_context *ctxt) > corpus_sptr corp > =3D std::make_shared(ctxt->ir_env, ctxt->filename); [...] > + /* Build the cfta from the contents of the relevant ELF sections, I changed cfta into ctfa. > + and process the CTF archive in the read context, if any. > + Information about the types, variables, functions, etc contained > + in the archive are added to the given corpus. */ > + int errp; > + ctxt->ctfa =3D ctf_arc_bufopen(&ctxt->ctf_sect, &ctxt->symtab_sect, > + &ctxt->strtab_sect, &errp); > + if (ctxt->ctfa !=3D NULL) > + process_ctf_archive(ctxt, corp); > + > + /* Cleanup and return. */ > + close_elf_handler(ctxt); > return corp; > } [...] Applied to master. Thanks! Cheers, --=20 Dodji