From patchwork Tue Jun 23 15:30:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 50242 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3F1E921575 for ; Tue, 23 Jun 2015 15:31:47 +0000 (UTC) Received: by wgbhy7 with SMTP id hy7sf3860773wgb.3 for ; Tue, 23 Jun 2015 08:31:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:reply-to:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:errors-to:x-original-sender :x-original-authentication-results:mailing-list; bh=9AhbiJupWWYRdPrdW8xDaFx3E6MAeVjnRVBXt96j3us=; b=m1/XecFyQDiHefqpyk5x2hJNcj/lwDPIIEVFEq0gl0X3uhxJkMQQzBgnIurI0cWr98 tXwT4snQERFSj1lAdX0RV0gT5qfNfVBwpM7EcgO9/VdiyNqFWbWCnZQJNj4pLMjsvxSQ g8vfj6NHBCrWqwsOfjGFrJRfpwRQzsrH7kG6kLzbPvuo4fhwRyxOb90arbNCwrNVZ9uE 5A4AcpucEf8pksMLnmcaIWi7a6dhxdA6I6UzrDuDYpIFB6vDFmDjpmWGzmjiw3aTR3Cw KqhLlJLldX2oldXKVcMgmejEKGSkeZDxlk9dE5rTzwYci/kwhnAFr1YktpZn3XgPhxFD CsAw== X-Gm-Message-State: ALoCoQmoEs4rtDYZ3zZe/67NPjFo+DrH/mVtNpVyKtulY9YLjW+3PgWBm9FC1jlvpuri++MvAB/L X-Received: by 10.180.90.106 with SMTP id bv10mr1738620wib.6.1435073506527; Tue, 23 Jun 2015 08:31:46 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.40 with SMTP id kz8ls70670lab.24.gmail; Tue, 23 Jun 2015 08:31:46 -0700 (PDT) X-Received: by 10.152.23.234 with SMTP id p10mr35639857laf.52.1435073506358; Tue, 23 Jun 2015 08:31:46 -0700 (PDT) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id uh5si19567770lac.168.2015.06.23.08.31.46 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jun 2015 08:31:46 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by lagx9 with SMTP id x9so9044582lag.1 for ; Tue, 23 Jun 2015 08:31:46 -0700 (PDT) X-Received: by 10.112.199.133 with SMTP id jk5mr36600708lbc.32.1435073506060; Tue, 23 Jun 2015 08:31:46 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3155866lbb; Tue, 23 Jun 2015 08:31:44 -0700 (PDT) X-Received: by 10.107.135.22 with SMTP id j22mr1737743iod.20.1435073488513; Tue, 23 Jun 2015 08:31:28 -0700 (PDT) Received: from lists.sourceforge.net (lists.sourceforge.net. [216.34.181.88]) by mx.google.com with ESMTPS id p16si7766961ico.48.2015.06.23.08.31.27 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 23 Jun 2015 08:31:28 -0700 (PDT) Received-SPF: pass (google.com: domain of edk2-devel-bounces@lists.sourceforge.net designates 216.34.181.88 as permitted sender) client-ip=216.34.181.88; Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Z7QAO-000695-7u; Tue, 23 Jun 2015 15:31:16 +0000 Received: from sog-mx-2.v43.ch3.sourceforge.com ([172.29.43.192] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Z7QAM-00068r-IC for edk2-devel@lists.sourceforge.net; Tue, 23 Jun 2015 15:31:14 +0000 Received-SPF: pass (sog-mx-2.v43.ch3.sourceforge.com: domain of linaro.org designates 74.125.82.48 as permitted sender) client-ip=74.125.82.48; envelope-from=ard.biesheuvel@linaro.org; helo=mail-wg0-f48.google.com; Received: from mail-wg0-f48.google.com ([74.125.82.48]) by sog-mx-2.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1Z7QAL-000872-BS for edk2-devel@lists.sourceforge.net; Tue, 23 Jun 2015 15:31:14 +0000 Received: by wgck11 with SMTP id k11so13018191wgc.0 for ; Tue, 23 Jun 2015 08:31:07 -0700 (PDT) X-Received: by 10.180.79.73 with SMTP id h9mr4502228wix.35.1435073467387; Tue, 23 Jun 2015 08:31:07 -0700 (PDT) Received: from localhost.localdomain ([185.13.106.68]) by mx.google.com with ESMTPSA id ei8sm36242290wjd.32.2015.06.23.08.31.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Jun 2015 08:31:06 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.sourceforge.net, olivier.martin@arm.com, leif.lindholm@linaro.org Date: Tue, 23 Jun 2015 17:30:53 +0200 Message-Id: <1435073455-3268-3-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1435073455-3268-1-git-send-email-ard.biesheuvel@linaro.org> References: <1435073455-3268-1-git-send-email-ard.biesheuvel@linaro.org> X-Spam-Score: -1.1 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record 0.8 UPPERCASE_50_75 message body is 50-75% uppercase -0.4 AWL AWL: Adjusted score from AWL reputation of From: address X-Headers-End: 1Z7QAL-000872-BS Subject: [edk2] [RFC PATCH 2/4] BaseTools: AArch64: use an explicit linker script X-BeenThere: edk2-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: edk2-devel@lists.sourceforge.net List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.sourceforge.net X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ard.biesheuvel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Instead of relying on the builtin linker script of GNU ld, which may vary based on binutils version (which is not tightly coupled to the GCC version) and linker command line options, introduce a linker script for AArch64 to be used by all GCC/binutils versions. The script is laid out such that both the file and memory layout are identical between the ELF intermediate file and the final PE/COFF file. This should prevent problems with debuggers and other tooling that are ELF based. It also places the .text section such that, provided that the entire image is loaded at a 4 KB aligned offset, the build time and runtime relative alignment with respect to the nearest 4 KB boundary is the same. This allows the 'small' GCC C model to be used. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- BaseTools/Conf/tools_def.template | 23 +++++++++++++---------- BaseTools/Scripts/gcc-aarch64-ld-script | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template index fd7b4b55e8ba..9ba8d38a1791 100644 --- a/BaseTools/Conf/tools_def.template +++ b/BaseTools/Conf/tools_def.template @@ -3821,9 +3821,12 @@ DEFINE GCC_ARM_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mword-relocations -m DEFINE GCC_AARCH64_CC_FLAGS = DEF(GCC_ALL_CC_FLAGS) -mcmodel=large -mlittle-endian -fno-short-enums -save-temps -fverbose-asm -fsigned-char -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-builtin -Wno-address DEFINE GCC_DLINK_FLAGS_COMMON = -nostdlib --pie DEFINE GCC_IA32_X64_DLINK_COMMON = DEF(GCC_DLINK_FLAGS_COMMON) --gc-sections -DEFINE GCC_ARM_AARCH64_DLINK_COMMON= -Ttext=0x0 --emit-relocs -nostdlib --gc-sections -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map +DEFINE GCC_ARM_AARCH64_DLINK_COMMON= --emit-relocs -nostdlib --gc-sections -u $(IMAGE_ENTRY_POINT) -e $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map +DEFINE GCC_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) -Ttext=0x0 +DEFINE GCC_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --script=$(EDK_TOOLS_PATH)/Scripts/gcc-aarch64-ld-script DEFINE GCC_IA32_X64_ASLDLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) -DEFINE GCC_ARM_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --entry ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) +DEFINE GCC_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_DLINK_FLAGS) --entry ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) +DEFINE GCC_AARCH64_ASLDLINK_FLAGS = DEF(GCC_AARCH64_DLINK_FLAGS) --entry ReferenceAcpiTable -u $(IMAGE_ENTRY_POINT) DEFINE GCC_IA32_X64_DLINK_FLAGS = DEF(GCC_IA32_X64_DLINK_COMMON) --entry _$(IMAGE_ENTRY_POINT) --file-alignment 0x20 --section-alignment 0x20 -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map DEFINE GCC_IPF_DLINK_FLAGS = -nostdlib -O2 --gc-sections --dll -static --entry $(IMAGE_ENTRY_POINT) --undefined $(IMAGE_ENTRY_POINT) -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map DEFINE GCC_IPF_OBJCOPY_FLAGS = -I elf64-ia64-little -O efi-bsdrv-ia64 @@ -3866,8 +3869,8 @@ DEFINE GCC46_X64_DLINK_FLAGS = DEF(GCC45_X64_DLINK_FLAGS) DEFINE GCC46_ASM_FLAGS = DEF(GCC45_ASM_FLAGS) DEFINE GCC46_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ASM_FLAGS) -mlittle-endian DEFINE GCC46_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC44_ALL_CC_FLAGS) DEF(GCC_ARM_CC_FLAGS) -fstack-protector -DEFINE GCC46_ARM_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --oformat=elf32-littlearm -DEFINE GCC46_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS) --oformat=elf32-littlearm +DEFINE GCC46_ARM_DLINK_FLAGS = DEF(GCC_ARM_DLINK_FLAGS) --oformat=elf32-littlearm +DEFINE GCC46_ARM_ASLDLINK_FLAGS = DEF(GCC_ARM_ASLDLINK_FLAGS) --oformat=elf32-littlearm DEFINE GCC47_IA32_CC_FLAGS = DEF(GCC46_IA32_CC_FLAGS) DEFINE GCC47_X64_CC_FLAGS = DEF(GCC46_X64_CC_FLAGS) @@ -3881,9 +3884,9 @@ DEFINE GCC47_AARCH64_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) DEF(GC DEFINE GCC47_ARM_CC_FLAGS = DEF(GCC46_ARM_CC_FLAGS) -mno-unaligned-access DEFINE GCC47_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC44_ALL_CC_FLAGS) DEF(GCC_AARCH64_CC_FLAGS) DEFINE GCC47_ARM_DLINK_FLAGS = DEF(GCC46_ARM_DLINK_FLAGS) -DEFINE GCC47_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) +DEFINE GCC47_AARCH64_DLINK_FLAGS = DEF(GCC_AARCH64_DLINK_FLAGS) DEFINE GCC47_ARM_ASLDLINK_FLAGS = DEF(GCC46_ARM_ASLDLINK_FLAGS) -DEFINE GCC47_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS) +DEFINE GCC47_AARCH64_ASLDLINK_FLAGS = DEF(GCC_AARCH64_ASLDLINK_FLAGS) DEFINE GCC48_IA32_CC_FLAGS = DEF(GCC47_IA32_CC_FLAGS) DEFINE GCC48_X64_CC_FLAGS = DEF(GCC47_X64_CC_FLAGS) @@ -3897,9 +3900,9 @@ DEFINE GCC48_AARCH64_ASM_FLAGS = DEF(GCC47_AARCH64_ASM_FLAGS) DEFINE GCC48_ARM_CC_FLAGS = DEF(GCC47_ARM_CC_FLAGS) DEFINE GCC48_AARCH64_CC_FLAGS = DEF(GCC47_AARCH64_CC_FLAGS) DEFINE GCC48_ARM_DLINK_FLAGS = DEF(GCC47_ARM_DLINK_FLAGS) -DEFINE GCC48_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) +DEFINE GCC48_AARCH64_DLINK_FLAGS = DEF(GCC47_AARCH64_DLINK_FLAGS) DEFINE GCC48_ARM_ASLDLINK_FLAGS = DEF(GCC47_ARM_ASLDLINK_FLAGS) -DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS) +DEFINE GCC48_AARCH64_ASLDLINK_FLAGS = DEF(GCC47_AARCH64_ASLDLINK_FLAGS) DEFINE GCC49_IA32_CC_FLAGS = DEF(GCC48_IA32_CC_FLAGS) DEFINE GCC49_X64_CC_FLAGS = DEF(GCC48_X64_CC_FLAGS) @@ -3913,9 +3916,9 @@ DEFINE GCC49_AARCH64_ASM_FLAGS = DEF(GCC48_AARCH64_ASM_FLAGS) DEFINE GCC49_ARM_CC_FLAGS = DEF(GCC48_ARM_CC_FLAGS) DEFINE GCC49_AARCH64_CC_FLAGS = DEF(GCC48_AARCH64_CC_FLAGS) DEFINE GCC49_ARM_DLINK_FLAGS = DEF(GCC48_ARM_DLINK_FLAGS) -DEFINE GCC49_AARCH64_DLINK_FLAGS = DEF(GCC_ARM_AARCH64_DLINK_COMMON) +DEFINE GCC49_AARCH64_DLINK_FLAGS = DEF(GCC48_AARCH64_DLINK_FLAGS) DEFINE GCC49_ARM_ASLDLINK_FLAGS = DEF(GCC48_ARM_ASLDLINK_FLAGS) -DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS) +DEFINE GCC49_AARCH64_ASLDLINK_FLAGS = DEF(GCC48_AARCH64_ASLDLINK_FLAGS) #################################################################################### # diff --git a/BaseTools/Scripts/gcc-aarch64-ld-script b/BaseTools/Scripts/gcc-aarch64-ld-script new file mode 100644 index 000000000000..cf09b63d916f --- /dev/null +++ b/BaseTools/Scripts/gcc-aarch64-ld-script @@ -0,0 +1,33 @@ +SECTIONS { + + /* + * By positioning the .text section at 0x800, and aligning it at 0x800, it + * is guaranteed to end up at 0x800 offset in the resulting PE/COFF image as + * well. This allows us to use GCC's 'small' C model, which uses PC relative + * ADRP/ADD and ADRP/LDR pairs to reference global symbols, instead of 64-bit + * absolute addresses. + * Since some AArch64 code is aligned to 0x800 (i.e., the vector table), we + * need to use at least this alignment for .text. The actual PE/COFF headers + * are only around 0x260 bytes in size, so we are wasting around 1.5 KB here. + */ + .text 0x800 : ALIGN(0x800) { + *(.text .text.* .rodata .rodata.*) + } + .data : ALIGN(0x40) { + *(.data .data.*) + *(.bss .bss.* *COM*) + } + .rela ALIGN(0x20) : { + *(.rela .rela.*) + } + + /DISCARD/ : { + *(.note.GNU-stack) + *(.interp) + *(.dynsym) + *(.dynstr) + *(.dynamic) + *(.hash) + *(.comment) + } +}