From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <3dpSeXggKChU7vz883x219916z.x9763wvw31v36D9FCxzHvCz.9C1@flex--maennich.bounces.google.com> Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by sourceware.org (Postfix) with ESMTPS id 962F2384B0C1 for ; Tue, 21 Apr 2020 06:36:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 962F2384B0C1 Received: by mail-wm1-x34a.google.com with SMTP id l21so1070601wmh.2 for ; Mon, 20 Apr 2020 23:36:39 -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:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=yKQpAwU3s5NPmtaZzH/WQIUuCcc07xkYEJX3HS+ZUTo=; b=fTfZ950TXKkEcvVkZC21/PGsaYAp/Tgx6fSHJxM19BjALP8UEUvUbU9h4dnFvLlOZM Zmb9Dz4zjBbUYS7fZN7+ietbk/UicmJZL7L5WUxBNoxtrhOwTcvUqhWg89o7IoMCi95G azTn94Kp0LnO4/QHqoplLrxT+xJXGb5j+/6aIUQWi4zCvHynVlneon39N1qyXX5tcd+W 6LuLqDqOAK/Fhd3/Ahwql5tZmdNcIVxnYBuycw1a5Aya3oWugIiTo/7z5qKE2CH40PRR KiG1Jxna6GDMuKuUu/jlt/reGFAe5C0vRR6rkGG1WW6+eBIqF9pXH/OwKs94tvL82+Am RYdA== X-Gm-Message-State: AGi0PuYsk9/pIlafiFDYEWIq8C6NKhDnyuuIryoD22j/3CUOhQ7rRTdR El9ZTmQihoaIvoK64wbdqkeHS9z0KiSEa9JB26iTMxNAeeZiTk9/Ph1Hb3tWWXRwGWOGYhNN5Ql nQcF+6UnQhpGUBwDrAkdFw2CVpaO5yMpeNWL4nZ/Zinsc3X9w1Wc7DSJS96GI2ZCZgKcgdPQ= X-Google-Smtp-Source: APiQypI+aXcxcSQDigxqBTFEIs1TQlZPzq+FNiwwpApsfETpAj2Brliwy87rrFxO929mZGTLbHgkmffmmJXDcw== X-Received: by 2002:adf:90c6:: with SMTP id i64mr21284681wri.88.1587450998472; Mon, 20 Apr 2020 23:36:38 -0700 (PDT) Date: Tue, 21 Apr 2020 08:35:47 +0200 In-Reply-To: <20200421063551.222511-1-maennich@google.com> Message-Id: <20200421063551.222511-5-maennich@google.com> Mime-Version: 1.0 References: <20200420110846.218792-1-maennich@google.com> <20200421063551.222511-1-maennich@google.com> X-Mailer: git-send-email 2.26.1.301.g55bc3eb7cb9-goog Subject: [PATCH v2 4/8] abg-elf-helpers: move some kernel helpers from abg-dwarf-reader From: Matthias Maennich To: libabigail@sourceware.org Cc: dodji@seketeli.org, gprocida@google.com, kernel-team@android.com, maennich@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-33.4 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libabigail mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Apr 2020 06:36:41 -0000 Move some definitions from abg-dwarf-reader to abg-elf-helpers that are strictly only related to ELF. * abg-dwarf-reader.cc(binary_is_linux_kernel): Move function out. (binary_is_linux_kernel_module): Likewise. (find_ksymtab_strings_section): Likewise. * abg-elf-helpers.cc(binary_is_linux_kernel): Move function in. (binary_is_linux_kernel_module): Likewise. (find_ksymtab_strings_section): Likewise. * abg-elf-helpers.h(binary_is_linux_kernel): Add declaration. (binary_is_linux_kernel_module): Likewise. (find_ksymtab_strings_section): Likewise. Reviewed-by: Giuliano Procida Signed-off-by: Matthias Maennich --- src/abg-dwarf-reader.cc | 46 ----------------------------------------- src/abg-elf-helpers.cc | 45 ++++++++++++++++++++++++++++++++++++++++ src/abg-elf-helpers.h | 14 +++++++++++++ 3 files changed, 59 insertions(+), 46 deletions(-) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 303c1f8df4c2..3adb978b784b 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -542,52 +542,6 @@ compare_dies(const read_context& ctxt, bool update_canonical_dies_on_the_fly); =20 =20 -/// Test if the ELF binary denoted by a given ELF handle is a Linux -/// Kernel Module. -/// -/// @param elf_handle the ELF handle to consider. -/// -/// @return true iff the binary denoted by @p elf_handle is a Linux -/// kernel module. -static bool -binary_is_linux_kernel_module(Elf *elf_handle) -{ - return (find_section(elf_handle, ".modinfo", SHT_PROGBITS) - && find_section(elf_handle, - ".gnu.linkonce.this_module", - SHT_PROGBITS)); -} - -/// Test if the ELF binary denoted by a given ELF handle is a Linux -/// Kernel binary (either vmlinux or a kernel module). -/// -/// @param elf_handle the ELF handle to consider. -/// -/// @return true iff the binary denoted by @p elf_handle is a Linux -/// kernel binary -static bool -binary_is_linux_kernel(Elf *elf_handle) -{ - return (find_section(elf_handle, - "__ksymtab_strings", - SHT_PROGBITS) - || binary_is_linux_kernel_module(elf_handle)); -} - -/// Find the __ksymtab_strings section of a Linux kernel binary. -/// -/// -/// @return the find_ksymtab_strings_section of the linux kernel -/// binary denoted by @p elf_handle, or nil if such a section could -/// not be found. -static Elf_Scn* -find_ksymtab_strings_section(Elf *elf_handle) -{ - if (binary_is_linux_kernel(elf_handle)) - return find_section(elf_handle, "__ksymtab_strings", SHT_PROGBITS); - return 0; -} - /// Get the address at which a given binary is loaded in memory=E2=8B=85 /// /// @param elf_handle the elf handle for the binary to consider. diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc index b7b868a332ec..ff0941dc6536 100644 --- a/src/abg-elf-helpers.cc +++ b/src/abg-elf-helpers.cc @@ -548,6 +548,21 @@ get_symbol_versionning_sections(Elf* elf_handle, return false; } =20 +/// Find the __ksymtab_strings section of a Linux kernel binary. +/// +/// @param elf_handle the elf handle to use. +/// +/// @return the find_ksymtab_strings_section of the linux kernel +/// binary denoted by @p elf_handle, or nil if such a section could +/// not be found. +Elf_Scn* +find_ksymtab_strings_section(Elf *elf_handle) +{ + if (binary_is_linux_kernel(elf_handle)) + return find_section(elf_handle, "__ksymtab_strings", SHT_PROGBITS); + return 0; +} + /// Get the version definition (from the SHT_GNU_verdef section) of a /// given symbol represented by a pointer to GElf_Versym. /// @@ -750,7 +765,37 @@ get_version_for_symbol(Elf* elf_handle, return false; } =20 +/// Test if the ELF binary denoted by a given ELF handle is a Linux +/// Kernel Module. +/// +/// @param elf_handle the ELF handle to consider. +/// +/// @return true iff the binary denoted by @p elf_handle is a Linux +/// kernel module. +bool +binary_is_linux_kernel_module(Elf *elf_handle) +{ + return (find_section(elf_handle, ".modinfo", SHT_PROGBITS) + && find_section(elf_handle, + ".gnu.linkonce.this_module", + SHT_PROGBITS)); +} =20 +/// Test if the ELF binary denoted by a given ELF handle is a Linux +/// Kernel binary (either vmlinux or a kernel module). +/// +/// @param elf_handle the ELF handle to consider. +/// +/// @return true iff the binary denoted by @p elf_handle is a Linux +/// kernel binary +bool +binary_is_linux_kernel(Elf *elf_handle) +{ + return (find_section(elf_handle, + "__ksymtab_strings", + SHT_PROGBITS) + || binary_is_linux_kernel_module(elf_handle)); +} =20 } // end namespace elf_helpers } // end namespace abigail diff --git a/src/abg-elf-helpers.h b/src/abg-elf-helpers.h index 7e1c231ccc4e..33348126028c 100644 --- a/src/abg-elf-helpers.h +++ b/src/abg-elf-helpers.h @@ -102,6 +102,9 @@ get_symbol_versionning_sections(Elf* elf_handle, Elf_Scn*& verdef_section, Elf_Scn*& verneed_section); =20 +Elf_Scn* +find_ksymtab_strings_section(Elf *elf_handle); + // // Helpers for symbol versioning // @@ -124,6 +127,17 @@ get_version_for_symbol(Elf* elf_handle, bool get_def_version, elf_symbol::version& version); =20 +// +// Helpers for Linux Kernel Binaries +// + +bool +binary_is_linux_kernel_module(Elf *elf_handle); + +bool +binary_is_linux_kernel(Elf *elf_handle); + + } // end namespace elf_helpers } // end namespace abigail =20 --=20 2.26.1.301.g55bc3eb7cb9-goog