From patchwork Fri Apr 15 12:33:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kiper X-Patchwork-Id: 8850741 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 52C0FC0553 for ; Fri, 15 Apr 2016 12:36:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53DA8202EB for ; Fri, 15 Apr 2016 12:36:07 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 4C33120377 for ; Fri, 15 Apr 2016 12:36:06 +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 1ar2wt-0005Dt-5o; Fri, 15 Apr 2016 12:34:11 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ar2wr-0005CQ-RU for xen-devel@lists.xenproject.org; Fri, 15 Apr 2016 12:34:09 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id C0/FE-07120-1CFD0175; Fri, 15 Apr 2016 12:34:09 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpjkeJIrShJLcpLzFFi42LpnVTnqnvgvkC 4QdcXY4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNePGJY6CTYoVa9oXMTYwbpfqYuTiEBLoYJK4 fu4hO4TzhVFixv125i5GTiBnA6PE7DeiEImJjBL7D0xgB0mwCehIXPzyEMwWEVCSuLdqMhNIE bPAeSaJaZ2XWUASwgKeEn/+zWQDsVkEVCWW/1zFBGLzCrhLfJ/yFKxGQkBRovvZBLAaTgEPid WdTUBxDqBt7hL/popAlBhL9M3qY5nAyLeAkWEVo3pxalFZapGusV5SUWZ6RkluYmaOrqGBmV5 uanFxYnpqTmJSsV5yfu4mRmCYMADBDsaOf06HGCU5mJREeefuFQgX4kvKT6nMSCzOiC8qzUkt PsQow8GhJMH75B5QTrAoNT21Ii0zBxiwMGkJDh4lEd6XIGne4oLE3OLMdIjUKUZdjmNzb6xlE mLJy89LlRLnfQ9SJABSlFGaBzcCFj2XGGWlhHkZgY4S4ilILcrNLEGVf8UozsGoJMy7HmQKT2 ZeCdymV0BHMAEdUfaOF+SIkkSElFQDY6HhjxnPer6prv/etNdyTbjHwqOPdaQi/v4Tl1/Uv/V MWJOP+kvuoCJR96puwYlzf/w8Er0vw1CmIbBIcIbEn+8bnT8bcKpcknPm/brewKhNX3YKq4G0 ksRfa6OuFxsPCvYdsU1X9/M3cTms6vrUqHLL/Evfg1/6G0WqbJp8TIg3a9P5I3qblViKMxINt ZiLihMBJCWJ05kCAAA= X-Env-Sender: daniel.kiper@oracle.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1460723647!9521675!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.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 17838 invoked from network); 15 Apr 2016 12:34:08 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-14.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 15 Apr 2016 12:34:08 -0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u3FCXxXM026880 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Apr 2016 12:33:59 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u3FCXwFY027572 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Apr 2016 12:33:59 GMT Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u3FCXwNP009727; Fri, 15 Apr 2016 12:33:58 GMT Received: from olila.local.net-space.pl (/10.175.160.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Apr 2016 05:33:57 -0700 From: Daniel Kiper To: xen-devel@lists.xenproject.org Date: Fri, 15 Apr 2016 14:33:07 +0200 Message-Id: <1460723596-13261-8-git-send-email-daniel.kiper@oracle.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1460723596-13261-1-git-send-email-daniel.kiper@oracle.com> References: <1460723596-13261-1-git-send-email-daniel.kiper@oracle.com> X-Source-IP: aserv0021.oracle.com [141.146.126.233] Cc: jgross@suse.com, andrew.cooper3@citrix.com, stefano.stabellini@eu.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 v3 07/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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org 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 which creates not accepted sections will not break our build recipes again. Additionally, 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 --- xen/arch/x86/boot/build32.lds | 49 +++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/boot/build32.mk | 10 ++++++--- 2 files changed, 56 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..47db9c4 --- /dev/null +++ b/xen/arch/x86/boot/build32.lds @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. + * Daniel Kiper + * + * 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/ : { + /* + * .got.plt section is used only by dynamic linker + * and our output is not supposed to be loaded by + * dynamic linker. Additionally, it just contains + * .PLT0 which is referenced from nowhere. So, we + * can safely drop .got.plt here. + * + * Ha! This should be really discarded here. However, + * .got.plt section contains _GLOBAL_OFFSET_TABLE_ + * symbol too and it is used as a reference for relative + * addressing (and only for that thing). Hence, ld + * complains if we remove that section because it + * cannot find _GLOBAL_OFFSET_TABLE_. 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 $@