From patchwork Wed Aug 7 11:49:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11081979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E1C01395 for ; Wed, 7 Aug 2019 11:50:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7B305287D3 for ; Wed, 7 Aug 2019 11:50:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6DB59287FE; Wed, 7 Aug 2019 11:50:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_ADSP_ALL, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A992225E13 for ; Wed, 7 Aug 2019 11:50:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvKRS-0003BW-KX; Wed, 07 Aug 2019 11:49:18 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hvKRR-0003BR-VN for xen-devel@lists.xen.org; Wed, 07 Aug 2019 11:49:18 +0000 X-Inumbo-ID: 61e74050-b909-11e9-aa9e-0b38ae8a4c24 Received: from smtp-fw-6002.amazon.com (unknown [52.95.49.90]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 61e74050-b909-11e9-aa9e-0b38ae8a4c24; Wed, 07 Aug 2019 11:49:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1565178555; x=1596714555; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=GQdefIVneOjbqb8v/0HDooKPuzARLdmj0NGoFQ+HreY=; b=JsRd5Y4IS/TeKgh/ecBW/2v6pvDILKoNyWpmvX9BIFZddiEQIgeiR/FN C3DJt4iC5LJYWVEUoWVfCdMnbP7XZm1yQH65ePjIzhjkGeKcs7dcexoWI d6Xagz8LsqcUAsz6alBUkW0uOZncJuuiIwZkxIKKBWmLMwenK5IbmBmaX Y=; X-IronPort-AV: E=Sophos;i="5.64,357,1559520000"; d="scan'208";a="414313099" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6002.iad6.amazon.com with ESMTP; 07 Aug 2019 11:49:14 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan3.iad.amazon.com [10.40.159.166]) by email-inbound-relay-1e-97fdccfd.us-east-1.amazon.com (Postfix) with ESMTPS id E1B86A212B; Wed, 7 Aug 2019 11:49:14 +0000 (UTC) Received: from EX13D05EUB003.ant.amazon.com (10.43.166.253) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 7 Aug 2019 11:49:14 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 7 Aug 2019 11:49:13 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.60.129) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Wed, 7 Aug 2019 11:49:12 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 7 Aug 2019 11:49:07 +0000 Message-ID: <20190807114907.74530-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-2-wipawel@amazon.de> References: <20190416120716.26269-2-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 v2 2/6] common: Add is_referenced_section() helper function X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: mpohlack@amazon.de, ross.lagerwall@citrix.com, Pawel Wieczorkiewicz , konrad.wilk@oracle.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This function checks if given section has an included corresponding RELA section and/or any of the symbols table symbols references the section. Section associated symbols are ignored here as there is always such a symbol for every section. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Reviewed-by: Ross Lagerwall --- v2: * Keep lines to 80 chars --- common.c | 23 ++++++++++++++++++++++- common.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common.c b/common.c index 1fb07cb..0ddc9fa 100644 --- a/common.c +++ b/common.c @@ -15,7 +15,7 @@ int is_rela_section(struct section *sec) { - return (sec->sh.sh_type == SHT_RELA); + return sec && (sec->sh.sh_type == SHT_RELA); } int is_local_sym(struct symbol *sym) @@ -270,6 +270,27 @@ int is_standard_section(struct section *sec) } } +int is_referenced_section(const struct section *sec, + const struct kpatch_elf *kelf) +{ + struct symbol *sym; + + if (is_rela_section(sec->rela) && sec->rela->include) + return true; + + list_for_each_entry(sym, &kelf->symbols, list) { + if (!sym->include || !sym->sec) + continue; + /* Ignore section associated sections */ + if (sym->type == STT_SECTION) + continue; + if (sym->sec->index == sec->index) + return true; + } + + return false; +} + /* returns the offset of the string in the string table */ int offset_of_string(struct list_head *list, char *name) { diff --git a/common.h b/common.h index cda690d..06e19e7 100644 --- a/common.h +++ b/common.h @@ -151,6 +151,8 @@ int is_text_section(struct section *sec); int is_debug_section(struct section *sec); int is_rela_section(struct section *sec); int is_standard_section(struct section *sec); +int is_referenced_section(const struct section *sec, + const struct kpatch_elf *kelf); int is_local_sym(struct symbol *sym); void rela_insn(struct section *sec, struct rela *rela, struct insn *insn);