From patchwork Tue Apr 16 12:07:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902893 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 970CB17E1 for ; Tue, 16 Apr 2019 12:09:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A1F62863E for ; Tue, 16 Apr 2019 12:09:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6D42D289C4; Tue, 16 Apr 2019 12:09:38 +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 F203B2863E for ; Tue, 16 Apr 2019 12:09:37 +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 1hGMsF-00005o-T6; Tue, 16 Apr 2019 12:07:39 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGMsE-00005j-Oc for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:07:38 +0000 X-Inumbo-ID: 39c12e5f-6040-11e9-92d7-bc764e045a96 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 39c12e5f-6040-11e9-92d7-bc764e045a96; Tue, 16 Apr 2019 12:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416457; x=1586952457; h=from:to:cc:subject:date:message-id:mime-version; bh=Qld9TkHpSIvU3/FtPf9CjSCtIQKEojbI+9O8Rg6OebA=; b=AFfwrO12gKHVdCgI1KZXFS3gQV5Z0yrgDmFocvdekbI57fRDYThfUj85 7QtZA2GZ7LY2bR6QsA8ZooZVHXf6WNm82eP9YzuwpzOZgnkaBQEu6P5uz zu2/nKE8ACzfVFbgyJHRGrwWMmSsv5piCTFDGwdVG4ODYJtoCNRg/B4NZ A=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="728339301" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1d-f273de60.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:07:36 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-f273de60.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7WGO031184 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:35 GMT 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; Tue, 16 Apr 2019 12:07:34 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05EUB003.ant.amazon.com (10.43.166.253) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:33 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:30 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:11 +0000 Message-ID: <20190416120716.26269-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 1/6] common: Add is_standard_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 Detect standard (always to be included) sections via their section header type. The standard sections: ".shstrtab", ".symtab", ".strtab" are either of type SHT_SYMTAB or SHT_STRTAB. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- common.c | 12 ++++++++++++ common.h | 1 + create-diff-object.c | 5 +---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/common.c b/common.c index bc63955..1fb07cb 100644 --- a/common.c +++ b/common.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "list.h" @@ -258,6 +259,17 @@ int is_debug_section(struct section *sec) return !strncmp(name, ".debug_", 7); } +int is_standard_section(struct section *sec) +{ + switch (sec->sh.sh_type) { + case SHT_STRTAB: + case SHT_SYMTAB: + return true; + default: + 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 7599fe7..cda690d 100644 --- a/common.h +++ b/common.h @@ -150,6 +150,7 @@ struct symbol *find_symbol_by_name(struct list_head *list, const char *name); 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_local_sym(struct symbol *sym); void rela_insn(struct section *sec, struct rela *rela, struct insn *insn); diff --git a/create-diff-object.c b/create-diff-object.c index 82f777e..1e6e617 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1278,10 +1278,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) list_for_each_entry(sec, &kelf->sections, list) { /* include these sections even if they haven't changed */ - if (!strcmp(sec->name, ".shstrtab") || - !strcmp(sec->name, ".strtab") || - !strcmp(sec->name, ".symtab") || - should_include_str_section(sec->name)) { + if (is_standard_section(sec) || should_include_str_section(sec->name)) { sec->include = 1; if (sec->secsym) sec->secsym->include = 1; From patchwork Tue Apr 16 12:07:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902903 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 179BC139A for ; Tue, 16 Apr 2019 12:12:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0164B289CC for ; Tue, 16 Apr 2019 12:12:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E850C289C7; Tue, 16 Apr 2019 12:12:10 +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 8C632289CB for ; Tue, 16 Apr 2019 12:12:10 +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 1hGMuX-0000Rc-JS; Tue, 16 Apr 2019 12:10:01 +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 1hGMuW-0000RM-8P for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:10:00 +0000 X-Inumbo-ID: 8e38bce6-6040-11e9-beda-e7113ee71213 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 8e38bce6-6040-11e9-beda-e7113ee71213; Tue, 16 Apr 2019 12:09:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416599; x=1586952599; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=NpJRyvLr2CEXPDBhiB1a+erXTu2tTja6/8opi5Ejqq0=; b=bnu25RaIA64iRu3uJaTsxQ2qBO1G5bxN7213ugdwrxE/Z+f0DLhrC6eV TPf1bk7Ogtb+XhIJItGsKyw6AbJSU1/CGXq/RRAwd4Xfu7aIzNuHG5Swo ot+Uzv/tt1k6jP/62hXQVwky1FQRX8jkr08IdZfO6WvApcVOFMhW2Acp8 I=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="799609849" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1e-c7c08562.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:08:45 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1e-c7c08562.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7abG039261 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:37 GMT Received: from EX13D03EUC002.ant.amazon.com (10.43.164.60) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:37 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D03EUC002.ant.amazon.com (10.43.164.60) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:35 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:33 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:12 +0000 Message-ID: <20190416120716.26269-2-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-1-wipawel@amazon.de> References: <20190416120716.26269-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 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 --- common.c | 22 +++++++++++++++++++++- common.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/common.c b/common.c index 1fb07cb..c968299 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,26 @@ 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..affe16b 100644 --- a/common.h +++ b/common.h @@ -151,6 +151,7 @@ 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); From patchwork Tue Apr 16 12:07:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902901 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 7AACE17E1 for ; Tue, 16 Apr 2019 12:11:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6195B287C0 for ; Tue, 16 Apr 2019 12:11:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 540C2289CA; Tue, 16 Apr 2019 12:11:18 +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 EFB41289D1 for ; Tue, 16 Apr 2019 12:11:17 +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 1hGMty-0000HD-Hs; Tue, 16 Apr 2019 12:09:26 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGMtx-0000H5-9D for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:09:25 +0000 X-Inumbo-ID: 79045809-6040-11e9-92d7-bc764e045a96 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 79045809-6040-11e9-92d7-bc764e045a96; Tue, 16 Apr 2019 12:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416564; x=1586952564; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=2uSYuau1/RpgGWuHrJjkQxuiufqVG6PyuR96NFLCe44=; b=XbAYNHtfc81BCsZUc0VyFRYuvGomZoly1u69xDoavqATJd7DA6WaS/we EfkFBD0BxdhGDd7nfGUSAxuek5HrBkkOV7Am+Mqce8Do4V3CelhGHt/rT 8O1QAQ6z0IKKwy30B8ZI76ykB/9Zw+pUSx84W1emafsK0PXn1R4iDjMR5 g=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="794603038" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1e-57e1d233.us-east-1.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:08:06 +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-57e1d233.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7eYx022932 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:40 GMT Received: from EX13D05EUB001.ant.amazon.com (10.43.166.87) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:40 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05EUB001.ant.amazon.com (10.43.166.87) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:39 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:36 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:13 +0000 Message-ID: <20190416120716.26269-3-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-1-wipawel@amazon.de> References: <20190416120716.26269-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 3/6] create-diff-object: Add is_special_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 determines, based on the given section name, if the sections belongs to the special sections category. It treats a name from the special_sections array as a prefix. Any sections whose name starts with special section prefix is considered a special section. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- common.c | 23 +++++++++++++++++++++++ common.h | 1 + 2 files changed, 24 insertions(+) diff --git a/common.c b/common.c index c968299..a2c860b 100644 --- a/common.c +++ b/common.c @@ -290,6 +290,29 @@ int is_referenced_section(const struct section *sec, const struct kpatch_elf *ke return false; } +int is_special_section(struct section *sec) +{ + static struct special_section_names { + const char *name; + } names[] = { + { .name = ".bug_frames" }, + { .name = ".fixup" }, + { .name = ".ex_table" }, + { .name = ".altinstructions" }, + { .name = ".altinstr_replacement" }, + { .name = ".livepatch.hooks" }, + { .name = NULL }, + }; + struct special_section_names *special; + + for (special = names; special->name; special++) { + if (!strncmp(sec->name, special->name, strlen(special->name))) + 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 affe16b..6d38e88 100644 --- a/common.h +++ b/common.h @@ -152,6 +152,7 @@ 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_special_section(struct section *sec); int is_local_sym(struct symbol *sym); void rela_insn(struct section *sec, struct rela *rela, struct insn *insn); From patchwork Tue Apr 16 12:07:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902897 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 BA05A17E1 for ; Tue, 16 Apr 2019 12:11:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1402289C6 for ; Tue, 16 Apr 2019 12:11:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95FF8289C9; Tue, 16 Apr 2019 12:11:07 +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 1863C289CA for ; Tue, 16 Apr 2019 12:11:07 +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 1hGMu0-0000Hk-Qb; Tue, 16 Apr 2019 12:09:28 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGMtz-0000HV-OM for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:09:27 +0000 X-Inumbo-ID: 79f57872-6040-11e9-92d7-bc764e045a96 Received: from smtp-fw-9101.amazon.com (unknown [207.171.184.25]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 79f57872-6040-11e9-92d7-bc764e045a96; Tue, 16 Apr 2019 12:09:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416565; x=1586952565; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=08Dlw/xFRKLf3C/QMzeNFODGPSjlMtj7Egts5GKTmBQ=; b=v9lhkq/UDPwoo3yxZI53WGkZJbsN3yeL1UidcZqQ9zHZALY6siaMccWE 446uhW76GMmepKVrstDva/NzJN+jCa83l+EEa8c92ScyrG5UT897Uqdo8 ooWvrBN0+azZYt09OIZSKq0UR/RF9FeC+vJYRHfdfFKwaz3n6Fy668psC 0=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="799609739" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9101.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:08:08 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7f6C051813 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:43 GMT Received: from EX13D03EUA001.ant.amazon.com (10.43.165.33) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:43 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D03EUA001.ant.amazon.com (10.43.165.33) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:42 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:39 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:14 +0000 Message-ID: <20190416120716.26269-4-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-1-wipawel@amazon.de> References: <20190416120716.26269-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 4/6] livepatch-build: detect special section group sizes 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 Hard-coding the special section group sizes is unreliable. Instead, determine them dynamically by finding the related struct definitions in the DWARF metadata. This is a livepatch backport of kpatch upstream commit [1]: kpatch-build: detect special section group sizes 170449847136a48b19fc Xen only deals with alt_instr, bug_frame and exception_table_entry structures, so sizes of these structers are obtained from xen-syms. This change is needed since with recent Xen the alt_instr structure has changed size from 12 to 14 bytes. [1] https://github.com/jpoimboe/kpatch/commit/170449847136a48b19fcceb19c1d4d257d386b56 Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Bjoern Doebel Reviewed-by: Martin Mazein --- create-diff-object.c | 60 ++++++++++++++++++++++++++++++++++++++++++++-------- livepatch-build | 23 ++++++++++++++++++++ 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index 1e6e617..b0b4dcb 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -958,12 +958,54 @@ static void kpatch_mark_constant_labels_same(struct kpatch_elf *kelf) } } -static int bug_frames_0_group_size(struct kpatch_elf *kelf, int offset) { return 8; } -static int bug_frames_1_group_size(struct kpatch_elf *kelf, int offset) { return 8; } -static int bug_frames_2_group_size(struct kpatch_elf *kelf, int offset) { return 8; } -static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset) { return 16; } -static int ex_table_group_size(struct kpatch_elf *kelf, int offset) { return 8; } -static int altinstructions_group_size(struct kpatch_elf *kelf, int offset) { return 12; } +static int bug_frames_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + if (!size) { + str = getenv("BUG_STRUCT_SIZE"); + size = str ? atoi(str) : 8; + } + + return size; +} + +static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + if (!size) { + str = getenv("BUG_STRUCT_SIZE"); + size = str ? atoi(str) : 16; + } + + return size; +} + +static int ex_table_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + if (!size) { + str = getenv("EX_STRUCT_SIZE"); + size = str ? atoi(str) : 8; + } + + return size; +} + +static int altinstructions_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + if (!size) { + str = getenv("ALT_STRUCT_SIZE"); + size = str ? atoi(str) : 12; + } + + printf("altinstr_size=%d\n", size); + return size; +} /* * The rela groups in the .fixup section vary in size. The beginning of each @@ -1016,15 +1058,15 @@ static int fixup_group_size(struct kpatch_elf *kelf, int offset) static struct special_section special_sections[] = { { .name = ".bug_frames.0", - .group_size = bug_frames_0_group_size, + .group_size = bug_frames_group_size, }, { .name = ".bug_frames.1", - .group_size = bug_frames_1_group_size, + .group_size = bug_frames_group_size, }, { .name = ".bug_frames.2", - .group_size = bug_frames_2_group_size, + .group_size = bug_frames_group_size, }, { .name = ".bug_frames.3", diff --git a/livepatch-build b/livepatch-build index c057fa1..a6cae12 100755 --- a/livepatch-build +++ b/livepatch-build @@ -284,6 +284,29 @@ echo "Output directory: ${OUTPUT}" echo "================================================" echo +if [ -f "$XENSYMS" ]; then + echo "Reading special section data" + SPECIAL_VARS=$(readelf -wi "$XENSYMS" | + gawk --non-decimal-data ' + BEGIN { a = b = e = 0 } + a == 0 && /DW_AT_name.* alt_instr/ {a = 1; next} + b == 0 && /DW_AT_name.* bug_frame/ {b = 1; next} + e == 0 && /DW_AT_name.* exception_table_entry/ {e = 1; next} + a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2} + b == 1 {printf("export BUG_STRUCT_SIZE=%d\n", $4); b = 2} + e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2} + a == 2 && b == 2 && e == 2 {exit}') + [[ -n $SPECIAL_VARS ]] && eval "$SPECIAL_VARS" + if [[ -z $ALT_STRUCT_SIZE ]] || [[ -z $BUG_STRUCT_SIZE ]] || [[ -z $EX_STRUCT_SIZE ]]; then + die "can't find special struct size" + fi + for i in $ALT_STRUCT_SIZE $BUG_STRUCT_SIZE $EX_STRUCT_SIZE; do + if [[ ! $i -gt 0 ]] || [[ ! $i -le 16 ]]; then + die "invalid special struct size $i" + fi + done +fi + if [ "${SKIP}" != "build" ]; then [ -e "${OUTPUT}" ] && die "Output directory exists" grep -q 'CONFIG_LIVEPATCH=y' "${CONFIGFILE}" || die "CONFIG_LIVEPATCH must be enabled" From patchwork Tue Apr 16 12:07:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902899 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 DF8FD139A for ; Tue, 16 Apr 2019 12:11:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2F7228671 for ; Tue, 16 Apr 2019 12:11:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B796427C0B; Tue, 16 Apr 2019 12:11:08 +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 4D0F628671 for ; Tue, 16 Apr 2019 12:11:08 +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 1hGMu2-0000IS-46; Tue, 16 Apr 2019 12:09:30 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hGMu0-0000Ho-Vw for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:09:29 +0000 X-Inumbo-ID: 7b64ea86-6040-11e9-92d7-bc764e045a96 Received: from smtp-fw-33001.amazon.com (unknown [207.171.190.10]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 7b64ea86-6040-11e9-92d7-bc764e045a96; Tue, 16 Apr 2019 12:09:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416567; x=1586952567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=LGjfG153Nl+yQdRVkWHnvtMi0awdDkFP0jLyLfljmX4=; b=v64i5HMOrfpqRujSWQCyhQ0ix14hgHZfd8/GRH9J4R6CkyyCSHbeCuaP UCB4EXllv0HqZ54jdZej7cUseeGFQxxQoP1dLXp/RkloPGPcs8/0NJ9sS 2X1IjjY7tt8Dxd6fcm0/vy/6fBsmyXVucRREPlLVqfOtjvF/WVVo3ns1r M=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="794603051" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-1e-62350142.us-east-1.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:08:12 +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-62350142.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7jcN116391 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:46 GMT Received: from EX13D05EUC004.ant.amazon.com (10.43.164.38) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:46 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05EUC004.ant.amazon.com (10.43.164.38) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:44 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:42 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:15 +0000 Message-ID: <20190416120716.26269-5-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-1-wipawel@amazon.de> References: <20190416120716.26269-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 5/6] create-diff-object: Add new entries to special sections array 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 Handle .livepatch.hooks* and .altinstr_replacement sections as the special sections with assigned group_size resolution function. By default each .livepatch.hooks* sections' entry is 8 bytes long (a pointer). The .altinstr_replacement section follows the .altinstructions section settings. Allow to specify different .livepatch.hooks* section entry size using shell environment variable HOOK_STRUCT_SIZE. Cleanup an incorrect indentation around group_size resulution functions. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey Signed-off-by: Pawel Wieczorkiewicz > Reviewed-by: Andra-Irina Paraschiv > Reviewed-by: Bjoern Doebel > Reviewed-by: Norbert Manthey > Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
Reviewed-by: Andra-Irina Paraschiv <andraprs@amazon.com>
Reviewed-by: Bjoern Doebel <doebel@amazon.de>
Reviewed-by: Norbert Manthey <nmanthey@amazon.de>
--- create-diff-object.c | 87 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index b0b4dcb..f6060cd 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -960,51 +960,64 @@ static void kpatch_mark_constant_labels_same(struct kpatch_elf *kelf) static int bug_frames_group_size(struct kpatch_elf *kelf, int offset) { - static int size = 0; - char *str; - if (!size) { - str = getenv("BUG_STRUCT_SIZE"); - size = str ? atoi(str) : 8; - } - - return size; + static int size = 0; + char *str; + if (!size) { + str = getenv("BUG_STRUCT_SIZE"); + size = str ? atoi(str) : 8; + } + + return size; } static int bug_frames_3_group_size(struct kpatch_elf *kelf, int offset) { - static int size = 0; - char *str; - if (!size) { - str = getenv("BUG_STRUCT_SIZE"); - size = str ? atoi(str) : 16; - } - - return size; + static int size = 0; + char *str; + if (!size) { + str = getenv("BUG_STRUCT_SIZE"); + size = str ? atoi(str) : 16; + } + + return size; } static int ex_table_group_size(struct kpatch_elf *kelf, int offset) { - static int size = 0; - char *str; - if (!size) { - str = getenv("EX_STRUCT_SIZE"); - size = str ? atoi(str) : 8; - } - - return size; + static int size = 0; + char *str; + if (!size) { + str = getenv("EX_STRUCT_SIZE"); + size = str ? atoi(str) : 8; + } + + return size; } static int altinstructions_group_size(struct kpatch_elf *kelf, int offset) { - static int size = 0; - char *str; - if (!size) { - str = getenv("ALT_STRUCT_SIZE"); - size = str ? atoi(str) : 12; - } - - printf("altinstr_size=%d\n", size); - return size; + static int size = 0; + char *str; + if (!size) { + str = getenv("ALT_STRUCT_SIZE"); + size = str ? atoi(str) : 12; + } + + printf("altinstr_size=%d\n", size); + return size; +} + +static int livepatch_hooks_group_size(struct kpatch_elf *kelf, int offset) +{ + static int size = 0; + char *str; + if (!size) { + str = getenv("HOOK_STRUCT_SIZE"); + size = str ? atoi(str) : 8; + } + + printf("livepatch_hooks_size=%d\n", size); + return size; } /* @@ -1084,6 +1097,14 @@ static struct special_section special_sections[] = { .name = ".altinstructions", .group_size = altinstructions_group_size, }, + { + .name = ".altinstr_replacement", + .group_size = altinstructions_group_size, + }, + { + .name = ".livepatch.hooks", + .group_size = livepatch_hooks_group_size, + }, {}, }; From patchwork Tue Apr 16 12:07:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 10902895 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 B4F991823 for ; Tue, 16 Apr 2019 12:09:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A27728678 for ; Tue, 16 Apr 2019 12:09:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E639289C0; Tue, 16 Apr 2019 12:09:39 +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 12F3028678 for ; Tue, 16 Apr 2019 12:09:37 +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 1hGMsT-00008V-5W; Tue, 16 Apr 2019 12:07:53 +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 1hGMsR-00007z-TI for xen-devel@lists.xen.org; Tue, 16 Apr 2019 12:07:51 +0000 X-Inumbo-ID: 41b12958-6040-11e9-abcf-272ddee1c570 Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 41b12958-6040-11e9-abcf-272ddee1c570; Tue, 16 Apr 2019 12:07:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1555416471; x=1586952471; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=8KiMgjzNZ+rdUh/ZaemlwBA8OUZCwiAyid/UHxxe7xY=; b=VgN3ex5LQmIBHbp/dKKp4mddqLj0XbjBxJny8cM2IdmtX9pYYtvMswRd UqG3UWrlBxRmV+VqAlOkT24sZbKZ/0jI2gI+JGL7bfIrkJjBqdvG16mez 9SkG4JnDjmRCvw36xtvCK5chu07d7AgLbmT9/WUEEKMG31axqWsNk9fp9 o=; X-IronPort-AV: E=Sophos;i="5.60,357,1549929600"; d="scan'208";a="728339337" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 16 Apr 2019 12:07:50 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1a-e34f1ddc.us-east-1.amazon.com (8.14.7/8.14.7) with ESMTP id x3GC7mO2085541 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 16 Apr 2019 12:07:49 GMT Received: from EX13D05EUB002.ant.amazon.com (10.43.166.45) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:49 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX13D05EUB002.ant.amazon.com (10.43.166.45) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 16 Apr 2019 12:07:47 +0000 Received: from dev-dsk-wipawel-1a-0c4e6d58.eu-west-1.amazon.com (10.4.134.33) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 16 Apr 2019 12:07:45 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 16 Apr 2019 12:07:16 +0000 Message-ID: <20190416120716.26269-6-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190416120716.26269-1-wipawel@amazon.de> References: <20190416120716.26269-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 6/6] create-diff-object: Do not include all .rodata sections 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 Starting with the "2af6f1aa6233 Fix patch creation with GCC 6.1+" commit all .rodata sections are included by default (regardless of whether they are needed or not). During stacked hotpatch builds it leads to unnecessary duplication of the .rodata sections as each and every consecutive hotpatch contains all the .rodata section of previous hotpatches. To prevent this situation, mark the .rodata section for inclusion only if they are referenced by any of the current hotpatch symbols (or a corresponding RELA section). Extend patchability verification to detect all non-standard, non-rela, non-debug and non-special sections that are not referenced by any of the symbols or RELA sections. Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- create-diff-object.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/create-diff-object.c b/create-diff-object.c index f6060cd..f7eb421 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1341,7 +1341,7 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) list_for_each_entry(sec, &kelf->sections, list) { /* include these sections even if they haven't changed */ - if (is_standard_section(sec) || should_include_str_section(sec->name)) { + if (is_standard_section(sec)) { sec->include = 1; if (sec->secsym) sec->secsym->include = 1; @@ -1352,6 +1352,19 @@ static void kpatch_include_standard_elements(struct kpatch_elf *kelf) list_entry(kelf->symbols.next, struct symbol, list)->include = 1; } +static void kpatch_include_standard_string_elements(struct kpatch_elf *kelf) +{ + struct section *sec; + + list_for_each_entry(sec, &kelf->sections, list) { + if (should_include_str_section(sec->name) && is_referenced_section(sec, kelf)) { + sec->include = 1; + if (sec->secsym) + sec->secsym->include = 1; + } + } +} + #define inc_printf(fmt, ...) \ log_debug("%*s" fmt, recurselevel, "", ##__VA_ARGS__); @@ -1531,6 +1544,16 @@ static void kpatch_verify_patchability(struct kpatch_elf *kelf) errs++; } + if (sec->include) { + if (!is_standard_section(sec) && !is_rela_section(sec) && + !is_debug_section(sec) && !is_special_section(sec)) { + if (!is_referenced_section(sec, kelf)) { + log_normal("section %s included, but not referenced\n", sec->name); + errs++; + } + } + } + /* * ensure we aren't including .data.* or .bss.* * (.data.unlikely is ok b/c it only has __warned vars) @@ -2062,6 +2085,8 @@ int main(int argc, char *argv[]) kpatch_include_debug_sections(kelf_patched); log_debug("Include hook elements\n"); kpatch_include_hook_elements(kelf_patched); + log_debug("Include standard string elements\n"); + kpatch_include_standard_string_elements(kelf_patched); log_debug("Include new globals\n"); new_globals_exist = kpatch_include_new_globals(kelf_patched); log_debug("new_globals_exist = %d\n", new_globals_exist);