From patchwork Wed Aug 21 08:20:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wieczorkiewicz, Pawel" X-Patchwork-Id: 11106077 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 63E641395 for ; Wed, 21 Aug 2019 08:23:22 +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 404C22339F for ; Wed, 21 Aug 2019 08:23:22 +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="eAr3ee7t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 404C22339F 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 1i0Lt1-00030Q-12; Wed, 21 Aug 2019 08:22:31 +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 1i0Lt0-0002ym-Ao for xen-devel@lists.xen.org; Wed, 21 Aug 2019 08:22:30 +0000 X-Inumbo-ID: c1cafc4e-c3ec-11e9-adc2-12813bfff9fa Received: from smtp-fw-4101.amazon.com (unknown [72.21.198.25]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c1cafc4e-c3ec-11e9-adc2-12813bfff9fa; Wed, 21 Aug 2019 08:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1566375724; x=1597911724; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=H2Jobcf7/B4qcCN5zZ1DZ3Id7Yd870t7Njz94pqBXLQ=; b=eAr3ee7tQTcaoHUva/5OsGxcujEz+ZSoQyauRftzcabu/EcOtc4KoFsn pK2mHDMIv4h7o1F+gLjh7OWik/VBjf8DHIP09FMwe5EzN4WT7UnKci0DC /F4+1LF+R56LREMeDm7VsIh9oA/k4r+psW+OuV1tOpPIi/4TaFMszAXRC I=; X-IronPort-AV: E=Sophos;i="5.64,412,1559520000"; d="scan'208";a="780419169" Received: from iad6-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2c-2225282c.us-west-2.amazon.com) ([10.124.125.6]) by smtp-border-fw-out-4101.iad4.amazon.com with ESMTP; 21 Aug 2019 08:22:03 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx4-ws-svc-p6-lb7-vlan3.pdx.amazon.com [10.170.41.166]) by email-inbound-relay-2c-2225282c.us-west-2.amazon.com (Postfix) with ESMTPS id F3777A18C4; Wed, 21 Aug 2019 08:22:02 +0000 (UTC) Received: from EX13D05EUC001.ant.amazon.com (10.43.164.118) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:42 +0000 Received: from EX13MTAUEB001.ant.amazon.com (10.43.60.96) by EX13D05EUC001.ant.amazon.com (10.43.164.118) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Wed, 21 Aug 2019 08:21:41 +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, 21 Aug 2019 08:21:39 +0000 From: Pawel Wieczorkiewicz To: Date: Wed, 21 Aug 2019 08:20:56 +0000 Message-ID: <20190821082056.91090-21-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 20/20] livepatch-build: Strip all metadata symbols from hotpatch modules 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" Strip all unneeded metadata symbols from generated hotpatch modules. The metadata symbols are the symbols from metadata-like sections (e.g. '.livepatch.funcs') or livepatch hooks symbols (defined by a set of prefixes. E.g. 'livepatch_load_data_'). By default the create-diff-object does not create symbols in metadata sections. However, such symbols may be implicitly added by speciying extra entries in the sections manually (in a given patch). The symbols are not needed for the hotpatch modules and should be stripped to avoid symbol names collisions and to save hotpatch files space. Signed-off-by: Pawel Wieczorkiewicz --- livepatch-build | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/livepatch-build b/livepatch-build index cc71640..e7c7c11 100755 --- a/livepatch-build +++ b/livepatch-build @@ -111,10 +111,39 @@ function build_special() unset LIVEPATCH_CAPTURE_DIR } -strip_extra_symbols () +elf_section_exists () +{ + local ELF="$1" + local SEC="$2" + + objdump -h -j "$SEC" "$ELF" &> /dev/null +} + +# Extract a set of unique symbols for a specified section. +elf_extract_section_symbols () +{ + local -r ELF="$1" + local -r SEC="$2" + + if elf_section_exists "$ELF" "$SEC" + then + # Example objdump command output to be parsed: + # + # SYMBOL TABLE: + # 0000000000000000 l d .livepatch.funcs 0000000000000000 .livepatch.funcs + objdump -w -j "$SEC" -t "$ELF" | awk '/^SYMBOL TABLE:/ {seen = 1; next} seen && $NF {print $NF}' | sort -u + fi +} + +# Strip all metadata symbols belonging to a metadata section +# or whose name starts with a livepatch hook prefix. +# The function constructs the 'strip' utility command line +# and then invokes strip with that command line. +strip_metadata_symbols () { local -r FILE="$1" local -a STRIP_CMD_OPTS=() + local -a SYM_SECTIONS=(".livepatch.funcs") local -a SYM_PREFIX=("livepatch_load_data_" "livepatch_unload_data_" "livepatch_preapply_data_" @@ -123,13 +152,35 @@ strip_extra_symbols () "livepatch_prerevert_data_" "livepatch_revert_data_" "livepatch_postrevert_data_") + local -a SYMS=() + # Enable wildcard STRIP_CMD_OPTS+=("-w") + + # Strip all livepatch hooks metadata symbols for sym in "${SYM_PREFIX[@]}"; do STRIP_CMD_OPTS+=("-N") STRIP_CMD_OPTS+=("\"${sym}*\"") done + # Find all symbols from metadata sections + # Note: There may be name conflicts between global + # and local symbols belonging to the same section. + # For the '.livepatch.funcs' section it is not a + # problem. Think about it before adding more sections. + for sec in "${SYM_SECTIONS[@]}"; do + SYMS+=($(elf_extract_section_symbols "$FILE" "$sec")) + done + + # Strip metadata sections' symbols + if [ ${#SYMS[@]} -gt 0 ] + then + for sym in "${SYMS[@]}"; do + STRIP_CMD_OPTS+=("-N") + STRIP_CMD_OPTS+=("${sym}") + done + fi + strip "${STRIP_CMD_OPTS[@]}" "$FILE" } @@ -199,7 +250,7 @@ function create_patch() "${TOOLSDIR}"/prelink $debugopt output.o "${PATCHNAME}.livepatch" "$XENSYMS" &>> "${OUTPUT}/prelink.log" || die fi - strip_extra_symbols "${PATCHNAME}.livepatch" + strip_metadata_symbols "${PATCHNAME}.livepatch" objcopy --add-section .livepatch.depends=depends.bin "${PATCHNAME}.livepatch" objcopy --set-section-flags .livepatch.depends=alloc,readonly "${PATCHNAME}.livepatch"