From patchwork Fri Aug 5 23:04:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 9265781 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 13F6B60839 for ; Fri, 5 Aug 2016 23:08:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01D9828462 for ; Fri, 5 Aug 2016 23:08:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA6112848E; Fri, 5 Aug 2016 23:08:17 +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 3480728462 for ; Fri, 5 Aug 2016 23:08:17 +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 1bVoBJ-00031t-R9; Fri, 05 Aug 2016 23:05:33 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVoBI-000313-4C for xen-devel@lists.xenproject.org; Fri, 05 Aug 2016 23:05:32 +0000 Received: from [85.158.139.211] by server-15.bemta-5.messagelabs.com id 6C/E8-12460-BBB15A75; Fri, 05 Aug 2016 23:05:31 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnkeJIrShJLcpLzFFi42KZM10+UHeX9NJ wg/Y1phbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bOe++YCs6oVCy/d4+xgfGRTBcjJ4eQQDuT RMcLmy5GLiD7M6PEvc+7WSESGxgl9r2WgkhMZJRYs/w/O0iCTUBH4uKXh2C2iICSxL1Vk5lAi pgFjjJJ/J/8GKibg0NYwFOifUsASA2LgKrEg3WzmUFsXgE3iYZTrWwgtoSAokT3swlgNqeAu8 S8jc/ZIBa7SXzsns8KUWMs0f72ItsERr4FjAyrGDWKU4vKUot0DQ30kooy0zNKchMzc4A8U73 c1OLixPTUnMSkYr3k/NxNjMBAYQCCHYxrpjofYpTkYFIS5T1/eUm4EF9SfkplRmJxRnxRaU5q 8SFGGQ4OJQneqVJLw4UEi1LTUyvSMnOAIQuTluDgURLhnQWS5i0uSMwtzkyHSJ1i1OU4NvfGW iYhlrz8vFQpcd5zIEUCIEUZpXlwI2Dxc4lRVkqYlxHoKCGegtSi3MwSVPlXjOIcjErCEKt4Mv NK4Da9AjqCCeiIj1ZLQI4oSURISTUwdrEHypxfOGPutuXfhLZN6TrVGdLCKn35pNqu3Uq/N05 dr6wRc7mMzzvXrsUldlPoNZ61Wrq/SxjX/6iKTju32rPvaTaHET+f0zbLOTy9K804GQ+2T7zJ 2nXGsFHba3NhWMa7po12DzWiwzpt2sQ/F8ukP9aaMyXg3uNdGwR7LFKkrrqqLmtUYinOSDTUY i4qTgQAD4rfuZoCAAA= X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1470438329!16809348!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61124 invoked from network); 5 Aug 2016 23:05:30 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 5 Aug 2016 23:05:30 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u75N5Iu4015712 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:18 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id u75N5HGk019372 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 5 Aug 2016 23:05:18 GMT Received: from abhmp0006.oracle.com (abhmp0006.oracle.com [141.146.116.12]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u75N5GOg010182; Fri, 5 Aug 2016 23:05:16 GMT Received: from olila.local.net-space.pl (/10.175.255.156) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 05 Aug 2016 16:05:16 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Sat, 6 Aug 2016 01:04:26 +0200 Message-Id: <1470438282-4226-4-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1470438282-4226-1-git-send-email-daniel.kiper@oracle.com> References: <1470438282-4226-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] 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, richard.l.maliszewski@intel.com, gang.wei@intel.com, fu.wei@linaro.org Subject: [Xen-devel] [PATCH v4 03/19] 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 required 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 --- 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 | 51 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/boot/build32.mk | 10 +++++--- 2 files changed, 58 insertions(+), 3 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..b14c7d5 --- /dev/null +++ b/xen/arch/x86/boot/build32.lds @@ -0,0 +1,51 @@ +/* + * 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.*) + *(.rodata) + } + + /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..eb02b4b 100644 --- a/xen/arch/x86/boot/build32.mk +++ b/xen/arch/x86/boot/build32.mk @@ -12,20 +12,24 @@ 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 $< $@ + $(OBJCOPY) -O binary -R .got.plt $< $@ %.lnk: %.o $(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.*) \ + .data|.data.*|.rodata.*|.bss|.bss.*) \ test $$sz != 0 || continue; \ echo "Error: non-empty $$name: 0x$$sz" >&2; \ exit $$(expr $$idx + 1);; \ esac; \ done - $(LD) $(LDFLAGS_DIRECT) -N -Ttext 0 -o $@ $< + $(LD) $(LDFLAGS_DIRECT) -N -T build32.lds -o $@ $< %.o: %.c $(CC) $(CFLAGS) -c -fpic $< -o $@