From patchwork Thu Mar 14 16:59:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 87202 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 829A53857704 for ; Thu, 14 Mar 2024 16:59:45 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 30AF63858C3A for ; Thu, 14 Mar 2024 16:59:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30AF63858C3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30AF63858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710435581; cv=none; b=bwgFA4fW0uoI928wjsB09JNs7mwKXRs4MTFlsXAo/X0DSHz3h1nhrVOWhBzgy/Yk/Ya6oczaSWMQ4w3zfx2mjoqvYwAQbJuKj8dP0HgDs6iNYTsGNaO4UylE/F43qqPLlIThI2KoKv8ebBgwT4dPTa+yec/Rtx0Q15AkwWdcYFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710435581; c=relaxed/simple; bh=x9f8E0NF0oBvHTCTDJFYjgkNJ5XxJrcClGOADCoAe04=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Evy3V/d2YycsO+NI0pqiayM52BjfFYkr+A/YxXhwYZvo1EwxcmlYzA0tDHK9sGbcDwbXgFCr5xjhY/qDYiR3ZC23QUsP+IjAUXfNwnsrPb6fpnogVO+N+Fdh4PozoMIUSNSAMuCZ9hFBxogNgMJV6p+pF2xKnKF5m19blS424HQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710435578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tBa2C+Mj7Nhbp0YQQMOHey3DrCPTrPBAIZF0AlS+K5c=; b=Tx0zNoKmUl+r7BdxHVb4zCHZ4B5joyjRQnoFwjSgFJ5KsYytov9ig+mu3sVbDdvtZng/re wFnCIxPuUePjnXzN5HfblLWmqsB03a7cu0l8uUk427YX/XNxWGYfoo+O+i7GAoFxkgHqh1 A4HrPyDlJCQHSXzlpGyS1GoaNaDyjcg= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-159-WtSaaRHiOn6tic-13bdT7w-1; Thu, 14 Mar 2024 12:59:36 -0400 X-MC-Unique: WtSaaRHiOn6tic-13bdT7w-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-413f625c65cso3980125e9.3 for ; Thu, 14 Mar 2024 09:59:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710435574; x=1711040374; 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=tBa2C+Mj7Nhbp0YQQMOHey3DrCPTrPBAIZF0AlS+K5c=; b=PJh+TS9wjiQ5w19Efs7m63M+IcPr3K6o1WhqZ1Dn1SNufTzVkbgq01fz1oRUNDg8Lx BJAqPy3JKTg1a4Ycv8mycYEZlgLwAOLsDNmMuIChcp4sXessiF2WGjGfQsJQO3pOFdGc t/C4/xJlN79e1R9kkdSWdaaOSrMCDHMtjzD6Skm9O5Q5cPfuMn1d73c64SdZ8i19hQtp iVwn+1vH7Lw2B+4rD1xe52SRyjMFy3ndyKm7D9XEz17nf0c4+3DOIT4/WghRtigNIA+c fYS8WC4Zi8Naf8YoNH+FhFLLpvZKqsMXnQyMKhWtBz/k5yprCqZ9YSl1+RPZiuAHpcP0 4ffw== X-Gm-Message-State: AOJu0Yy0t+No2thhz8A41FdxyjUsfjbHxEuh2006BLxd5nZ4Eb1ajz7u lztaOJ176YseYXROhncE4N4cwObTKKd+RWzcaLohmo1W2I3rodipyx8Rm4wAWtsDfYwNTVNmWMR IU6wrQ0HAAgEVDzpBtT9WJaaAmBwkNIWasTgBRW+nNdLWpAeyRP2F0xrDsulK34i5Uw== X-Received: by 2002:a05:600c:1f8c:b0:413:f2c6:df3d with SMTP id je12-20020a05600c1f8c00b00413f2c6df3dmr442522wmb.13.1710435574581; Thu, 14 Mar 2024 09:59:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEqhh33nKC7DGN4YqzCvkzOAivjjqQSpWdCtx136YBPgiga2qWqawOGFwJvSzNrujpKh3yng== X-Received: by 2002:a05:600c:1f8c:b0:413:f2c6:df3d with SMTP id je12-20020a05600c1f8c00b00413f2c6df3dmr442512wmb.13.1710435574158; Thu, 14 Mar 2024 09:59:34 -0700 (PDT) Received: from localhost ([78.243.217.51]) by smtp.gmail.com with ESMTPSA id m36-20020a05600c3b2400b00412b6fbb9b5sm6189851wms.8.2024.03.14.09.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 09:59:33 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id CB2055071022; Thu, 14 Mar 2024 17:59:32 +0100 (CET) From: Dodji Seketeli To: dodji@redhat.com Cc: libabigail@sourceware.org Subject: [PATCH 2/4] Factorize elf-reader::{variable,function}_symbol_is_exported into symtab Organization: Red Hat / France References: <87ttl83gaw.fsf@redhat.com> X-Operating-System: AlmaLinux 9.3 X-URL: http://www.redhat.com Date: Thu, 14 Mar 2024 17:59:32 +0100 In-Reply-To: <87ttl83gaw.fsf@redhat.com> (Dodji Seketeli's message of "Thu, 14 Mar 2024 17:54:15 +0100") Message-ID: <87le6k3g23.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=-12.2 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces+patchwork=sourceware.org@sourceware.org Hello, Move the code of elf-reader::{variable,function}_symbol_is_exported into symtab::{variable,function}_symbol_is_exported (where it belongs) and make the former use the later. * src/abg-elf-reader.cc (reader::function_symbol_is_exported): Use the new symtab::function_symbol_is_exported. (reader::variable_symbol_is_exported): Use the new symtab::variable_symbol_is_exported. * src/abg-symtab-reader.cc (symtab::{function,variable}_symbol_is_exported): Factorize elf::reader::{function,variable}_symbol_is_exported into this. * src/abg-symtab-reader.h (symtab::{function,variable}_symbol_is_exported): Declare new member functions. Signed-off-by: Dodji Seketeli --- src/abg-elf-reader.cc | 59 ++++++++++++--------------- src/abg-symtab-reader.cc | 87 ++++++++++++++++++++++++++++++++++++++++ src/abg-symtab-reader.h | 12 ++++++ 3 files changed, 124 insertions(+), 34 deletions(-) diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc index afb038ff..14f8ce6a 100644 --- a/src/abg-elf-reader.cc +++ b/src/abg-elf-reader.cc @@ -788,13 +788,12 @@ reader::symtab() const elf_symbol_sptr reader::function_symbol_is_exported(GElf_Addr symbol_address) const { - elf_symbol_sptr symbol = symtab()->lookup_symbol(symbol_address); + + elf_symbol_sptr symbol = + symtab()->function_symbol_is_exported(symbol_address); if (!symbol) return symbol; - if (!symbol->is_function() || !symbol->is_public()) - return elf_symbol_sptr(); - address_set_sptr set; bool looking_at_linux_kernel_binary = load_in_linux_kernel_mode() && elf_helpers::is_linux_kernel(elf_handle()); @@ -820,13 +819,11 @@ reader::function_symbol_is_exported(GElf_Addr symbol_address) const elf_symbol_sptr reader::variable_symbol_is_exported(GElf_Addr symbol_address) const { - elf_symbol_sptr symbol = symtab()->lookup_symbol(symbol_address); + elf_symbol_sptr symbol = + symtab()->variable_symbol_is_exported(symbol_address); if (!symbol) return symbol; - if (!symbol->is_variable() || !symbol->is_public()) - return elf_symbol_sptr(); - address_set_sptr set; bool looking_at_linux_kernel_binary = load_in_linux_kernel_mode() && elf_helpers::is_linux_kernel(elf_handle()); @@ -849,23 +846,20 @@ reader::variable_symbol_is_exported(GElf_Addr symbol_address) const elf_symbol_sptr reader::function_symbol_is_exported(const string& name) const { - const elf_symbols& syms = symtab()->lookup_symbol(name); - for (auto s : syms) + const elf_symbol_sptr s = symtab()->function_symbol_is_exported(name); + if (s && s->is_function() && s->is_public()) { - if (s->is_function() && s->is_public()) - { - bool looking_at_linux_kernel_binary = - (load_in_linux_kernel_mode() - && elf_helpers::is_linux_kernel(elf_handle())); + bool looking_at_linux_kernel_binary = + (load_in_linux_kernel_mode() + && elf_helpers::is_linux_kernel(elf_handle())); - if (looking_at_linux_kernel_binary) - { - if (s->is_in_ksymtab()) - return s; - } - else + if (looking_at_linux_kernel_binary) + { + if (s->is_in_ksymtab()) return s; } + else + return s; } return elf_symbol_sptr(); } @@ -879,23 +873,20 @@ reader::function_symbol_is_exported(const string& name) const elf_symbol_sptr reader::variable_symbol_is_exported(const string& name) const { - const elf_symbols& syms = symtab()->lookup_symbol(name); - for (auto s : syms) + const elf_symbol_sptr s = symtab()->variable_symbol_is_exported(name); + if (s->is_variable() && s->is_public()) { - if (s->is_variable() && s->is_public()) - { - bool looking_at_linux_kernel_binary = - (load_in_linux_kernel_mode() - && elf_helpers::is_linux_kernel(elf_handle())); + bool looking_at_linux_kernel_binary = + (load_in_linux_kernel_mode() + && elf_helpers::is_linux_kernel(elf_handle())); - if (looking_at_linux_kernel_binary) - { - if (s->is_in_ksymtab()) - return s; - } - else + if (looking_at_linux_kernel_binary) + { + if (s->is_in_ksymtab()) return s; } + else + return s; } return elf_symbol_sptr(); } diff --git a/src/abg-symtab-reader.cc b/src/abg-symtab-reader.cc index 2eebc282..51177369 100644 --- a/src/abg-symtab-reader.cc +++ b/src/abg-symtab-reader.cc @@ -166,6 +166,93 @@ symtab::lookup_undefined_variable_symbol(const std::string& sym_name) return result; } +/// Test if a given function symbol has been exported. +/// +/// Note that this doesn't test if the symbol is defined or not, but +/// assumes the symbol is defined. +/// +/// @param name the name of the symbol we are looking for. +/// +/// @return the elf symbol if found, or nil otherwise. +elf_symbol_sptr +symtab::function_symbol_is_exported(const string& name) +{ + const elf_symbols& syms = lookup_symbol(name); + for (auto s : syms) + if (s->is_function() && s->is_public()) + return s; + + return elf_symbol_sptr(); +} + +/// Test if a given function symbol has been exported. +/// +/// Note that this doesn't test if the symbol is defined or not, but +/// assumes the symbol is defined. +/// +/// @param symbol_address the address of the symbol we are looking +/// for. Note that this address must be a relative offset from the +/// beginning of the .text section, just like the kind of addresses +/// that are present in the .symtab section. +/// +/// @return the elf symbol if found, or nil otherwise. +elf_symbol_sptr +symtab::function_symbol_is_exported(const GElf_Addr symbol_address) +{ + elf_symbol_sptr symbol = lookup_symbol(symbol_address); + if (!symbol) + return symbol; + + if (!symbol->is_function() || !symbol->is_public()) + return elf_symbol_sptr(); + + return symbol; +} + +/// Test if a given variable symbol has been exported. +/// +/// Note that this assumes the symbol is exported but doesn't test for +/// it. +/// +/// @param name the name of the symbol we are looking +/// for. +/// +/// @return the elf symbol if found, or nil otherwise. +elf_symbol_sptr +symtab::variable_symbol_is_exported(const string& name) +{ + const elf_symbols& syms = lookup_symbol(name); + for (auto s : syms) + if (s->is_variable() && s->is_public()) + return s; + + return elf_symbol_sptr(); +} + +/// Test if a given variable symbol has been exported. +/// +/// Note that this assumes the symbol is exported but doesn't test for +/// it. +/// +/// @param symbol_address the address of the symbol we are looking +/// for. Note that this address must be a relative offset from the +/// beginning of the .text section, just like the kind of addresses +/// that are present in the .symtab section. +/// +/// @return the elf symbol if found, or nil otherwise. +elf_symbol_sptr +symtab::variable_symbol_is_exported(const GElf_Addr symbol_address) +{ + elf_symbol_sptr symbol = lookup_symbol(symbol_address); + if (!symbol) + return symbol; + + if (!symbol->is_variable() || !symbol->is_public()) + return elf_symbol_sptr(); + + return symbol; +} + /// Test if a name is a the name of an undefined function symbol. /// /// @param sym_name the symbol name to consider. diff --git a/src/abg-symtab-reader.h b/src/abg-symtab-reader.h index cc284453..43b40b79 100644 --- a/src/abg-symtab-reader.h +++ b/src/abg-symtab-reader.h @@ -248,6 +248,18 @@ public: const elf_symbol_sptr lookup_undefined_variable_symbol(const std::string& name); + elf_symbol_sptr + function_symbol_is_exported(const string&); + + elf_symbol_sptr + function_symbol_is_exported(const GElf_Addr symbol_address); + + elf_symbol_sptr + variable_symbol_is_exported(const string&); + + elf_symbol_sptr + variable_symbol_is_exported(const GElf_Addr symbol_address); + bool function_symbol_is_undefined(const string&);