From patchwork Thu Oct 3 22:48:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 280442 X-Patchwork-Delegate: albert.aribaud@free.fr Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 487102C00C7 for ; Fri, 4 Oct 2013 08:49:34 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 04A584A0CF; Fri, 4 Oct 2013 00:49:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pHIOw9W0F-gN; Fri, 4 Oct 2013 00:49:29 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 13DA34A0B5; Fri, 4 Oct 2013 00:49:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 21BEA4A09F for ; Fri, 4 Oct 2013 00:48:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EsQESJmR-B55 for ; Fri, 4 Oct 2013 00:48:53 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from db9outboundpool.messaging.microsoft.com (mail-db9lp0251.outbound.messaging.microsoft.com [213.199.154.251]) by theia.denx.de (Postfix) with ESMTPS id 617644A081 for ; Fri, 4 Oct 2013 00:48:42 +0200 (CEST) Received: from mail140-db9-R.bigfish.com (10.174.16.225) by DB9EHSOBE023.bigfish.com (10.174.14.86) with Microsoft SMTP Server id 14.1.225.22; Thu, 3 Oct 2013 22:48:40 +0000 Received: from mail140-db9 (localhost [127.0.0.1]) by mail140-db9-R.bigfish.com (Postfix) with ESMTP id 72800240183; Thu, 3 Oct 2013 22:48:40 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1f42h208ch1ee6h1de0h1fdah2073h1202h1e76h1d1ah1d2ah1fc6hzz1de098h1de097h8275bhz2dh2a8h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1b2fh1fb3h1d0ch1d2eh1d3fh1dfeh1dffh1e23h1fe8h1ff5h1155h) Received: from mail140-db9 (localhost.localdomain [127.0.0.1]) by mail140-db9 (MessageSwitch) id 1380840518155129_14117; Thu, 3 Oct 2013 22:48:38 +0000 (UTC) Received: from DB9EHSMHS010.bigfish.com (unknown [10.174.16.237]) by mail140-db9.bigfish.com (Postfix) with ESMTP id 1F5CF1A00A8; Thu, 3 Oct 2013 22:48:38 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by DB9EHSMHS010.bigfish.com (10.174.14.20) with Microsoft SMTP Server (TLS) id 14.16.227.3; Thu, 3 Oct 2013 22:48:37 +0000 Received: from az84smr01.freescale.net (10.64.34.197) by 039-SN1MMR1-002.039d.mgd.msft.net (10.84.1.15) with Microsoft SMTP Server (TLS) id 14.3.158.2; Thu, 3 Oct 2013 22:48:36 +0000 Received: from snotra.am.freescale.net ([10.214.86.120]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id r93MmWUo017148; Thu, 3 Oct 2013 15:48:35 -0700 From: Scott Wood To: Date: Thu, 3 Oct 2013 17:48:30 -0500 Message-ID: <1380840511-7414-4-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1380840511-7414-1-git-send-email-scottwood@freescale.com> References: <1380840511-7414-1-git-send-email-scottwood@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Cc: Scott Wood , York Sun Subject: [U-Boot] [PATCH 3/4] arm64: Non-manual relocation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This turns off CONFIG_NEEDS_MANUAL_RELOC and turns on -pie. The bss part of the linker script is changed to be more like arm32, as the previous arm64 approach was generating bad relocations (even readelf didn't like them). relocate_64.S is made to look more like relocate.S, and then changed to support RELA style relocations rather than REL. Signed-off-by: Scott Wood --- arch/arm/config.mk | 2 -- arch/arm/cpu/armv8/config.mk | 1 - arch/arm/cpu/armv8/u-boot.lds | 32 +++++++++++++++++++++++------- arch/arm/include/asm/config.h | 5 ----- arch/arm/lib/crt0_64.S | 7 ++----- arch/arm/lib/relocate_64.S | 41 ++++++++++++++++++++------------------- include/configs/vexpress_aemv8a.h | 3 +++ 7 files changed, 51 insertions(+), 40 deletions(-) diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 95c07ad..96d2d88 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -74,9 +74,7 @@ endif endif # needed for relocation -ifndef CONFIG_ARM64 LDFLAGS_u-boot += -pie -endif # # FIXME: binutils versions < 2.22 have a bug in the assembler where diff --git a/arch/arm/cpu/armv8/config.mk b/arch/arm/cpu/armv8/config.mk index 9f36d59..027a68c 100644 --- a/arch/arm/cpu/armv8/config.mk +++ b/arch/arm/cpu/armv8/config.mk @@ -13,4 +13,3 @@ PLATFORM_NO_UNALIGNED := $(PF_NO_UNALIGNED) PF_CPPFLAGS_ARMV8 := $(call cc-option, -march=armv8-a) PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARMV8) PLATFORM_CPPFLAGS += $(PF_NO_UNALIGNED) -PLATFORM_CPPFLAGS += -fpic diff --git a/arch/arm/cpu/armv8/u-boot.lds b/arch/arm/cpu/armv8/u-boot.lds index 328d477..4c12222 100644 --- a/arch/arm/cpu/armv8/u-boot.lds +++ b/arch/arm/cpu/armv8/u-boot.lds @@ -41,25 +41,43 @@ SECTIONS } . = ALIGN(8); - .reloc : { - __rel_got_start = .; - *(.got) - __rel_got_end = .; - } .image_copy_end : { *(.__image_copy_end) } + . = ALIGN(8); + + .rel_dyn_start : + { + *(.__rel_dyn_start) + } + + .rela.dyn : { + *(.rela*) + } + + .rel_dyn_end : + { + *(.__rel_dyn_end) + } + _end = .; . = ALIGN(8); + + .bss_start : { + KEEP(*(.__bss_start)); + } + .bss : { - __bss_start = .; *(.bss*) . = ALIGN(8); - __bss_end = .; + } + + .bss_end : { + KEEP(*(.__bss_end)); } /DISCARD/ : { *(.dynsym) } diff --git a/arch/arm/include/asm/config.h b/arch/arm/include/asm/config.h index 0ee131d..de4d01e 100644 --- a/arch/arm/include/asm/config.h +++ b/arch/arm/include/asm/config.h @@ -11,11 +11,6 @@ #define CONFIG_SYS_BOOT_RAMDISK_HIGH #ifdef CONFIG_ARM64 -/* - * Currently, GOT is used to relocate u-boot and - * configuration CONFIG_NEEDS_MANUAL_RELOC is needed. - */ -#define CONFIG_NEEDS_MANUAL_RELOC #define CONFIG_PHYS_64BIT #endif diff --git a/arch/arm/lib/crt0_64.S b/arch/arm/lib/crt0_64.S index ddd46eb..7756396 100644 --- a/arch/arm/lib/crt0_64.S +++ b/arch/arm/lib/crt0_64.S @@ -94,11 +94,8 @@ relocation_return: /* * Clear BSS section */ - ldr x9, [x18, #GD_RELOC_OFF] /* x9 <- gd->reloc_off */ - ldr x0, =__bss_start - add x0, x0, x9 /* x0 <- __bss_start in RAM */ - ldr x1, =__bss_end - add x1, x1, x9 /* x1 <- __bss_end in RAM */ + ldr x0, =__bss_start /* this is auto-relocated! */ + ldr x1, =__bss_end /* this is auto-relocated! */ mov x2, #0 clear_loop: str x2, [x0] diff --git a/arch/arm/lib/relocate_64.S b/arch/arm/lib/relocate_64.S index 29c3239..7fba9e2 100644 --- a/arch/arm/lib/relocate_64.S +++ b/arch/arm/lib/relocate_64.S @@ -16,40 +16,41 @@ * void relocate_code (addr_moni) * * This function relocates the monitor code. - * - * NOTE: - * GOT is used and configuration CONFIG_NEEDS_MANUAL_RELOC is needed. + * x0 holds the destination address. */ ENTRY(relocate_code) /* * Copy u-boot from flash to RAM */ - ldr x1, =__image_copy_start /* x1 <- copy source */ - cmp x1, x0 + ldr x1, =__image_copy_start /* x1 <- SRC &__image_copy_start */ + subs x9, x0, x1 /* x9 <- relocation offset */ b.eq relocate_done /* skip relocation */ - mov x2, x0 /* x2 <- copy destination */ - ldr x3, =__image_copy_end /* x3 <- source end address */ + ldr x2, =__image_copy_end /* x2 <- SRC &__image_copy_end */ copy_loop: ldp x10, x11, [x1], #16 /* copy from source address [x1] */ - stp x10, x11, [x2], #16 /* copy to target address [x2] */ - cmp x1, x3 /* until source end address [x3] */ + stp x10, x11, [x0], #16 /* copy to target address [x0] */ + cmp x1, x2 /* until source end address [x2] */ b.lo copy_loop /* - * Fix .reloc relocations + * Fix .rela.dyn relocations */ - ldr x9, [x18, #GD_RELOC_OFF]/* x9 <- relocation offset */ - ldr x1, =__rel_got_start /* x1 <- rel got start ofs */ - add x1, x1, x9 /* x1 <- rel got start in RAM */ - ldr x2, =__rel_got_end /* x2 <- rel got end ofs */ - add x2, x2, x9 /* x2 <- rel got end in RAM */ + ldr x2, =__rel_dyn_start /* x2 <- SRC &__rel_dyn_start */ + ldr x3, =__rel_dyn_end /* x3 <- SRC &__rel_dyn_end */ fixloop: - ldr x10, [x1] - add x10, x10, x9 /* x10 <- address to be fixed up */ - str x10, [x1] - add x1, x1, #8 /* each got entry is 8 bytes */ - cmp x1, x2 + ldp x0, x1, [x2], #16 /* (x0,x1) <- (SRC location, fixup) */ + ldr x4, [x2], #8 /* x4 <- addend */ + and x1, x1, #0xffffffff + cmp x1, #1027 /* relative fixup? */ + bne fixnext + + /* relative fix: store addend plus offset at dest location */ + add x0, x0, x9 + add x4, x4, x9 + str x4, [x0] +fixnext: + cmp x2, x3 b.lo fixloop relocate_done: diff --git a/include/configs/vexpress_aemv8a.h b/include/configs/vexpress_aemv8a.h index 01c95f5..3932e00 100644 --- a/include/configs/vexpress_aemv8a.h +++ b/include/configs/vexpress_aemv8a.h @@ -10,6 +10,9 @@ #define DEBUG +#define CONFIG_REMAKE_ELF +#define CONFIG_STATIC_RELA + /*#define CONFIG_BOOTING_EL1*/ /*#define CONFIG_SYS_GENERIC_BOARD*/