From patchwork Tue Aug 20 11:26:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11103601 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 0E254912 for ; Tue, 20 Aug 2019 11:29:25 +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 DD40D2082F for ; Tue, 20 Aug 2019 11:29:24 +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="uOyStAN/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD40D2082F 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 1i02Id-000103-SX; Tue, 20 Aug 2019 11:27:39 +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 1i02Ic-0000zy-Ls for xen-devel@lists.xen.org; Tue, 20 Aug 2019 11:27:38 +0000 X-Inumbo-ID: 83c34974-c33d-11e9-8bf7-12813bfff9fa Received: from smtp-fw-2101.amazon.com (unknown [72.21.196.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 83c34974-c33d-11e9-8bf7-12813bfff9fa; Tue, 20 Aug 2019 11:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566300458; x=1597836458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=8P7/zuNikWYOGhgpWS+eSBxU6qF2k9MuftOdGjIOLG4=; b=uOyStAN/y8d/B/geuuto2Y68Zq5Nh0dhWUDSHqIBAtjS2PT29GXv5xde dDTzgfpFlFEvub5Gd4w+clp6WDW7bsXFk40YDMzPV5vjkbpDfr6DOUVih iApaUzcqAFeRqlDFAhlgJ7Ij63YyhTTX4YEiit0hHpC5sEvLNGv/A7WRF Y=; X-IronPort-AV: E=Sophos;i="5.64,408,1559520000"; d="scan'208";a="747561900" Received: from iad6-co-svc-p1-lb1-vlan2.amazon.com (HELO email-inbound-relay-2a-1c1b5cdd.us-west-2.amazon.com) ([10.124.125.2]) by smtp-border-fw-out-2101.iad2.amazon.com with ESMTP; 20 Aug 2019 11:27:37 +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 B49DCA23D2; Tue, 20 Aug 2019 11:27:36 +0000 (UTC) Received: from EX13D03EUC002.ant.amazon.com (10.43.164.60) by EX13MTAUEA001.ant.amazon.com (10.43.61.243) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 20 Aug 2019 11:27:36 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D03EUC002.ant.amazon.com (10.43.164.60) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 20 Aug 2019 11:27: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.61.243) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Tue, 20 Aug 2019 11:27:33 +0000 From: Pawel Wieczorkiewicz To: Date: Tue, 20 Aug 2019 11:26:48 +0000 Message-ID: <20190820112648.65518-1-wipawel@amazon.de> X-Mailer: git-send-email 2.16.5 In-Reply-To: <20190808123916.8706-1-wipawel@amazon.de> References: <20190808123916.8706-1-wipawel@amazon.de> MIME-Version: 1.0 Precedence: Bulk Subject: [Xen-devel] [livepatch-build-tools part2 v3 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" Older versions of GCC did not split .rodata.str sections by function. Because of that, the entire section was always included. The livepatch-build-tools commit [1] fixed patch creation and kept including all .rodata.str sections, in order to maintain existing behavior for GCC 6.1+. This means all .rodata.str sections are always included by default, regardless of whether they are needed or not. During stacked hotpatch builds it leads to unnecessary accumulation of the .rodata.str sections as each and every consecutive hotpatch module contains all the .rodata.str sections of previous modules. To prevent this situation, mark the .rodata.str sections 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. Rename should_include_str_section() to is_rodata_str_section(). [1] 2af6f1aa6233 Fix patch creation with GCC 6.1+ Signed-off-by: Pawel Wieczorkiewicz Reviewed-by: Andra-Irina Paraschiv Reviewed-by: Bjoern Doebel Reviewed-by: Norbert Manthey --- v3: * Fixed the comment above should_include_str_section() * Renamed should_include_str_section() to is_rodata_str_section() v2: * Made the commit message more precise and accurate (based on Ross' comments to the v1 patch) * Kept lines limited to 80 chars --- create-diff-object.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index 8365af0..bcccb37 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1315,14 +1315,13 @@ static bool isnumber(const char *s) } /* - * String sections are always included even if unchanged. - * The format is either: + * The format of string sections is either: * .rodata..str1.[0-9]+ (new in GCC 6.1.0) * or .rodata.str1.[0-9]+ (older versions of GCC) - * For the new format we could be smarter and only include the needed - * strings sections. + * For the new format we only include the needed strings sections. + * For the old format all string sections are always included. */ -static bool should_include_str_section(const char *name) +static bool is_rodata_str_section(const char *name) { #define GCC_5_SECTION_NAME ".rodata.str1." #define GCC_6_SECTION_NAME ".str1." @@ -1350,8 +1349,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; @@ -1362,6 +1360,20 @@ 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 (is_rodata_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__); @@ -1541,6 +1553,17 @@ 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) @@ -2072,6 +2095,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);