From patchwork Mon Dec 12 14:52:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ross Lagerwall X-Patchwork-Id: 9470797 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2ADF560573 for ; Mon, 12 Dec 2016 14:55:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D10F2831B for ; Mon, 12 Dec 2016 14:55:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11D62284AB; Mon, 12 Dec 2016 14:55:37 +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, 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 AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A41F42831B for ; Mon, 12 Dec 2016 14:55:36 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGRyf-0000ZO-TN; Mon, 12 Dec 2016 14:53:17 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGRyf-0000ZH-Du for xen-devel@lists.xen.org; Mon, 12 Dec 2016 14:53:17 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id CC/30-28843-CD9BE485; Mon, 12 Dec 2016 14:53:16 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDLMWRWlGSWpSXmKPExsXitHRDpO6dnX4 RBp9ec1ks+biYxYHR4+ju30wBjFGsmXlJ+RUJrBmv571lKmgQqbjZfIaxgXGZQBcjJ4eEgL/E ptezWUFsNgEDiVuXvjOD2CICshKru+awg9jMAvES6+dMBKsRFvCT+HRiM0sXIwcHi4CqxKTVz iBhXgEPife3N7BCjJSTuHmuE2yMkICaxNvlZ1ggagQlTs58wgIxUkLi4IsXzBMYuWchSc1Ckl rAyLSKUaM4tagstUjX0EQvqSgzPaMkNzEzR9fQwEwvN7W4ODE9NScxqVgvOT93EyMwFBiAYAf j9Y0BhxglOZiURHl/ePtFCPEl5adUZiQWZ8QXleakFh9ilOHgUJLgdd8BlBMsSk1PrUjLzAEG JUxagoNHSYS3ZytQmre4IDG3ODMdInWKUVFKnDcMpE8AJJFRmgfXBouES4yyUsK8jECHCPEUp BblZpagyr9iFOdgVBLmnQMyhSczrwRu+iugxUxAi5/v8wZZXJKIkJJqYDyzQKaF/95xIw7mlV lqt553c+k/n5Js83HZk189xwqU9n984L7p6kZutgML9Y9v2G+k/pnrb2KhhWHVj40boufmM63 yf3v3bnkD68UzqU2Np94nP2guFIuQLveuMFB9oCf+7cWFHgeR5ou2t5ZelXq/7NxVwzMzyt/G HT01ZavCzed67686756qxFKckWioxVxUnAgAdlCz5H8CAAA= X-Env-Sender: prvs=147044df7=ross.lagerwall@citrix.com X-Msg-Ref: server-6.tower-27.messagelabs.com!1481554394!77127047!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 53426 invoked from network); 12 Dec 2016 14:53:15 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 12 Dec 2016 14:53:15 -0000 X-IronPort-AV: E=Sophos;i="5.33,336,1477958400"; d="scan'208";a="394284353" From: Ross Lagerwall To: Date: Mon, 12 Dec 2016 14:52:34 +0000 Message-ID: <1481554354-1992-1-git-send-email-ross.lagerwall@citrix.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Cc: Ross Lagerwall Subject: [Xen-devel] [PATCH v2] create-diff-object: Update fixup offsets in .rela.ex_table X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP When pruning entries from the fixup table, update the offsets in .rela.ex_table otherwise the relas might point to the wrong fixup entry or even out of the .fixup section. This is a port of kpatch's commit 13d61012f9b2 ("create-diff-object: Update fixup offsets in .rela__ex_table"). Signed-off-by: Ross Lagerwall Reviewed-by: Konrad Rzeszutek Wilk --- Changed in v2: * Updated to match the patch which went into kpatch. create-diff-object.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index b0d1348..f07e727 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1057,6 +1057,31 @@ static int should_keep_rela_group(struct section *sec, int start, int size) return found; } +/* + * When updating .fixup, the corresponding addends in .ex_table need to be + * updated too. Stash the result in rela.r_addend so that the calculation in + * fixup_group_size() is not affected. + */ +void kpatch_update_ex_table_addend(struct kpatch_elf *kelf, + struct special_section *special, + int src_offset, int dest_offset, + int group_size) +{ + struct rela *rela; + struct section *sec; + + sec = find_section_by_name(&kelf->sections, ".rela.ex_table"); + if (!sec) + ERROR("missing .rela.ex_table section"); + + list_for_each_entry(rela, &sec->relas, list) { + if (!strcmp(rela->sym->name, ".fixup") && + rela->addend >= src_offset && + rela->addend < src_offset + group_size) + rela->rela.r_addend = rela->addend - (src_offset - dest_offset); + } +} + static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, struct special_section *special, struct section *sec) @@ -1073,6 +1098,14 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, if (!dest) ERROR("malloc"); + /* Restore the stashed r_addend from kpatch_update_ex_table_addend. */ + if (!strcmp(special->name, ".ex_table")) { + list_for_each_entry(rela, &sec->relas, list) { + if (!strcmp(rela->sym->name, ".fixup")) + rela->addend = rela->rela.r_addend; + } + } + group_size = 0; src_offset = 0; dest_offset = 0; @@ -1100,6 +1133,12 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, rela->rela.r_offset = rela->offset; rela->sym->include = 1; + + if (!strcmp(special->name, ".fixup")) + kpatch_update_ex_table_addend(kelf, special, + src_offset, + dest_offset, + group_size); } }