From patchwork Wed Aug 21 08:20:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E43F174A for ; Wed, 21 Aug 2019 08:23:03 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2AAA62339E for ; Wed, 21 Aug 2019 08:23:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="rDQVCw5m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2AAA62339E Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i0LsJ-0001ec-8J; Wed, 21 Aug 2019 08:21:47 +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 1i0LsH-0001a2-A0 for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:21:45 +0000 X-Inumbo-ID: aea4f6a7-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-6001.amazon.com (unknown [52.95.48.154]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id aea4f6a7-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:21:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375693; x=1597911693; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=QBL7vyAB8sS7gLIt9JcObmzXvg/bnnm2aii2dcmq544=; b=rDQVCw5m0BkwFqFzugALD1t4fKL4gVM2VFQAR6KzijeoOch7aGwaZDZs ZsdGjUmTLeMP/XeGo/7/YFn4GqOlc/N8BQyLyzowQvP5WIrJm1ApgM/IN 98gfp4pLn+YmyBSsyXTJ/FUrSzspY0WyaA+gWTo4LJxUxKd+ZMdSyNDWy w=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="410765150" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP; 21 Aug 2019 08:21:32 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan2.pdx.amazon.com [10.170.41.162]) by email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com (Postfix) with ESMTPS id 5F2A3A073A; Wed, 21 Aug 2019 08:21:32 +0000 (UTC) Received: from EX13D03EUC001.ant.amazon.com (10.43.164.245) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:16 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D03EUC001.ant.amazon.com (10.43.164.245) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 01:21:15 -0700 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, 21 Aug 2019 08:21:13 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:42 +0000 Message-ID: <20190821082056.91090-7-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190821082056.91090-1-wipawel@amazon.de> References: <20190821082056.91090-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [PATCH 06/20] 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: wipawel@amazon.com, Konrad Rzeszutek Wilk , Andrew Cooper , Ross Lagerwall , mpohlack@amazon.com, Pawel Wieczorkiewicz Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 --- 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);