From patchwork Fri Aug 19 22:43:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9291289 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 CE09A600CB for ; Fri, 19 Aug 2016 22:46:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2D2F295CE for ; Fri, 19 Aug 2016 22:46:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C723B295D6; Fri, 19 Aug 2016 22:46:22 +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, UNPARSEABLE_RELAY 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 2E5F8295CE for ; Fri, 19 Aug 2016 22:46:22 +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 1basWC-0002Fj-EN; Fri, 19 Aug 2016 22:44:04 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1basWA-0002FO-Tz for xen-devel@lists.xenproject.org; Fri, 19 Aug 2016 22:44:03 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 01/F7-28857-2BB87B75; Fri, 19 Aug 2016 22:44:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupikeJIrShJLcpLzFFi42LpnVTnqruxe3u 4wd3bshbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0b7mw/MBffVK6517mJqYJwl38XIxSEk0MYk 8fTUJ1YI5xujxKa5XSwQzkZGiR3fm6AyExklvu97BpTh5GAT0JG4+OUhO4gtIqAkcW/VZCaQI maBOUwSV3t3MYEkhAU8JTqOngSzWQRUJdbOeQ7WwCvgLrHo+lmwQRICihLdzyawgdicAh4Sfz Y9AqsXAqp5/OcHG0SNocTph9sYJzDyLWBkWMWoUZxaVJZapGtoppdUlJmeUZKbmJmja2hgppe bWlycmJ6ak5hUrJecn7uJERguDECwg/H+xoBDjJIcTEqivH5q28OF+JLyUyozEosz4otKc1KL DzHKcHAoSfAyAMNPSLAoNT21Ii0zBxi4MGkJDh4lEd4fXUBp3uKCxNzizHSI1ClGXY5jc2+sZ RJiycvPS5US5z0HUiQAUpRRmgc3AhZFlxhlpYR5GYGOEuIpSC3KzSxBlX/FKM7BqCTMuxtkCk 9mXgncpldARzABHcHLvwXkiJJEhJRUA2O/uPxkYZX7Dgdt4ubFh55iZr5tL6E+3Wqn/tP67De 615asN3T8apaWYM/048pZ49X+xVqK/mkyRU94T/0obX0dmiEhUbu0b4a0zv+CT9vMFxhOXZkz /fCpbQeLXvNwH7a4fnod99VjN959XaB+g8M8wcn+l6zIZhcmb67HoTd0T3hs6I3Q7VNiKc5IN NRiLipOBADmtfMfnQIAAA== X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1471646639!29364224!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10180 invoked from network); 19 Aug 2016 22:44:01 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-13.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Aug 2016 22:44:01 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7JMhrUk012701 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 19 Aug 2016 22:43:53 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u7JMhqLV009233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 19 Aug 2016 22:43:52 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u7JMholM012232; Fri, 19 Aug 2016 22:43:50 GMT Received: from olila.local.net-space.pl (/10.175.190.131) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 19 Aug 2016 15:43:50 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Sat, 20 Aug 2016 00:43:13 +0200 Message-Id: <1471646606-28519-4-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1471646606-28519-1-git-send-email-daniel.kiper@oracle.com> References: <1471646606-28519-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: jgross@suse.com, sstabellini@kernel.org, andrew.cooper3@citrix.com, cardoe@cardoe.com, pgnet.dev@gmail.com, ning.sun@intel.com, david.vrabel@citrix.com, jbeulich@suse.com, qiaowei.ren@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v5 03/16] x86/boot: create *.lnk files with linker script 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: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Newer GCC (e.g. gcc version 5.1.1 20150618 (Red Hat 5.1.1-4) (GCC)) does some code optimizations by creating data sections (e.g. jump addresses for C switch/case are calculated using data in .rodata section). This thing is not accepted by *.lnk build recipe which requires that only .text section lives in output. Potentially we can inhibit this GCC behavior by using special options, e.g. -fno-tree-switch-conversion. However, this does not guarantee that in the future new similar optimizations or anything else which creates not accepted sections will not break our build recipes again. I do not mention that probably this is not good idea to just disable random optimizations. So, take over full control on *.lnk linking process by using linker script and merge all text and data sections into one .text section. Additionally, remove .got.plt section which is not used in our final code. Signed-off-by: Daniel Kiper Reviewed-by: Jan Beulich --- v5 - suggestions/fixes: - merge __ALL__ text and data sections into one .text section (suggested by Jan Beulich), - check that .got.plt size is correct (suggested by Jan Beulich), - reformat comments (suggested by Jan Beulich), - improve commit message. v4 - suggestions/fixes: - remove my name from copyright (Oracle requirement) (suggested by Konrad Rzeszutek Wilk), - improve comments, (suggested by Jan Beulich), - improve commit message (suggested by Jan Beulich). --- xen/arch/x86/boot/build32.lds | 52 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/boot/build32.mk | 16 +++++++------ 2 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 xen/arch/x86/boot/build32.lds diff --git a/xen/arch/x86/boot/build32.lds b/xen/arch/x86/boot/build32.lds new file mode 100644 index 0000000..da35aee --- /dev/null +++ b/xen/arch/x86/boot/build32.lds @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +ENTRY(_start) + +SECTIONS +{ + /* Merge code and data into one section. */ + .text : { + *(.text) + *(.text.*) + *(.data) + *(.data.*) + *(.rodata) + *(.rodata.*) + *(.bss) + *(.bss.*) + } + + /DISCARD/ : { + /* + * PIC/PIE executable contains .got.plt section even if it is not linked + * with dynamic libraries. In such case it is just placeholder for + * _GLOBAL_OFFSET_TABLE_ symbol and .PLT0. .PLT0 is filled by dynamic + * linker and our code is not supposed to be loaded by dynamic linker. + * So, from our point of view .PLT0 is unused. This means that there is + * pretty good chance that we can safely drop .got.plt as a whole here. + * Sadly this is not true. _GLOBAL_OFFSET_TABLE_ is used as a reference + * for relative addressing (and only for that thing) and ld complains if + * we remove .got.plt section here because it cannot find required symbol. + * However, _GLOBAL_OFFSET_TABLE_ is no longer needed in final output. + * So, drop .got.plt section during conversion to plain binary format. + * + * Please check build32.mk for more details. + */ + /* *(.got.plt) */ + } +} diff --git a/xen/arch/x86/boot/build32.mk b/xen/arch/x86/boot/build32.mk index 4a7d388..39e6453 100644 --- a/xen/arch/x86/boot/build32.mk +++ b/xen/arch/x86/boot/build32.mk @@ -12,20 +12,22 @@ CFLAGS := $(filter-out -flto,$(CFLAGS)) (od -v -t x $< | tr -s ' ' | awk 'NR > 1 {print s} {s=$$0}' | \ sed 's/ /,0x/g' | sed 's/,0x$$//' | sed 's/^[0-9]*,/ .long /') >$@ +# Drop .got.plt during conversion to plain binary format. +# Please check build32.lds for more details. %.bin: %.lnk - $(OBJCOPY) -O binary $< $@ - -%.lnk: %.o - $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' |\ + $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | \ while read idx name sz rest; do \ case "$$name" in \ - .data|.data.*|.rodata|.rodata.*|.bss|.bss.*) \ - test $$sz != 0 || continue; \ + .got.plt) \ + test $$sz != 0c || continue; \ echo "Error: non-empty $$name: 0x$$sz" >&2; \ exit $$(expr $$idx + 1);; \ esac; \ done - $(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $< + $(OBJCOPY) -O binary -R .got.plt $< $@ + +%.lnk: %.o + $(LD) $(LDFLAGS_DIRECT) -N -T build32.lds -o $@ $< %.o: %.c $(CC) $(CFLAGS) -c -fpic $< -o $@