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);