From patchwork Wed Oct 13 09:41:16 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Tjernlund X-Patchwork-Id: 71865 Return-Path: X-Original-To: wd@gemini.denx.de Delivered-To: wd@gemini.denx.de Received: from diddl.denx.de (diddl.denx.de [10.0.0.6]) by gemini.denx.de (Postfix) with ESMTP id 8398F13558AC for ; Wed, 13 Oct 2010 11:42:08 +0200 (CEST) Received: from diddl.denx.de (localhost.localdomain [127.0.0.1]) by diddl.denx.de (Postfix) with ESMTP id 6EF083230C06 for ; Wed, 13 Oct 2010 11:42:08 +0200 (CEST) Received: from pop.mnet-online.de by diddl.denx.de with POP3 (fetchmail-6.3.17) for (single-drop); Wed, 13 Oct 2010 11:42:08 +0200 (CEST) Received: from murder ([192.168.8.180]) by backend2 (Cyrus v2.2.12) with LMTPA; Wed, 13 Oct 2010 11:41:48 +0200 X-Sieve: CMU Sieve 2.2 Received: from mail.m-online.net (localhost [127.0.0.1]) by frontend1.mail.m-online.net (Cyrus v2.2.12) with LMTPA; Wed, 13 Oct 2010 11:41:47 +0200 Received: from scanner-1.m-online.net (scanner-1.mail.m-online.net [192.168.8.165]) by mail.m-online.net (Postfix) with ESMTP id E64C01C003A5; Wed, 13 Oct 2010 11:41:47 +0200 (CEST) Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by mxin-1.m-online.net (Postfix) with ESMTP id 1DDE646C0AB; Wed, 13 Oct 2010 11:41:37 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E6387280A2; Wed, 13 Oct 2010 11:41:33 +0200 (CEST) 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 vxHM5IOnDhtu; Wed, 13 Oct 2010 11:41:33 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C07B5280A7; Wed, 13 Oct 2010 11:41:27 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0D70C2809F for ; Wed, 13 Oct 2010 11:41:24 +0200 (CEST) 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 pVzmZeTAYl2n for ; Wed, 13 Oct 2010 11:41:22 +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 gw1.transmode.se (gw1.transmode.se [213.115.205.20]) by theia.denx.de (Postfix) with ESMTPS id 0670728099 for ; Wed, 13 Oct 2010 11:41:19 +0200 (CEST) Received: from sesr04.transmode.se (sesr04.transmode.se [192.168.201.15]) by gw1.transmode.se (Postfix) with ESMTP id 5313D2597C9; Wed, 13 Oct 2010 11:41:19 +0200 (CEST) Received: from gentoo-jocke.transmode.se ([192.168.1.15]) by sesr04.transmode.se (Lotus Domino Release 8.5.2 HF23) with ESMTP id 2010101311411918-11087 ; Wed, 13 Oct 2010 11:41:19 +0200 Received: from gentoo-jocke.transmode.se (gentoo-jocke.transmode.se [127.0.0.1]) by gentoo-jocke.transmode.se (8.14.4/8.14.0) with ESMTP id o9D9fJ4x005815; Wed, 13 Oct 2010 11:41:19 +0200 Received: (from jocke@localhost) by gentoo-jocke.transmode.se (8.14.4/8.14.4/Submit) id o9D9fICw005814; Wed, 13 Oct 2010 11:41:18 +0200 From: Joakim Tjernlund To: u-boot@lists.denx.de, Scott Wood , Kim Phillips Date: Wed, 13 Oct 2010 11:41:16 +0200 Message-Id: <1286962876-5764-1-git-send-email-Joakim.Tjernlund@transmode.se> X-Mailer: git-send-email 1.7.2.2 In-Reply-To: <1286887081-23172-1-git-send-email-Joakim.Tjernlund@transmode.se> References: <1286887081-23172-1-git-send-email-Joakim.Tjernlund@transmode.se> X-MIMETrack: Itemize by SMTP Server on sesr04/Transmode(Release 8.5.2 HF23|September 01, 2010) at 2010-10-13 11:41:19, Serialize by Router on sesr04/Transmode(Release 8.5.2 HF23|September 01, 2010) at 2010-10-13 11:41:19, Serialize complete at 2010-10-13 11:41:19 Cc: Joakim Tjernlund Subject: [U-Boot] [PATCHv2] mpc83xx: Add -fpic relocation support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Virus-Scanned: by amavisd-new at m-online.net This add relocation of .got entries produced by -fpic. -fpic produces 2-3% smaller code and is faster. Unfortunately gcc promotes -fpic to -fPIC when -mrelocatable is used so one need a very small patch to gcc too(sent upstream). -fpic puts its GOT entries in .got section(s) and linker defines the symbol _GLOBAL_OFFSET_TABLE_ to point to the middle of this table. The entry at _GLOBAL_OFFSET_TABLE_-4 contains a blrl insn which is used to find the table's real address by branching to _GLOBAL_OFFSET_TABLE_-4. Here are some size examples for my board: size with -fPIC text data bss dec hex filename 224687 14400 24228 263315 40493 u-boot size with -mbss-plt -fPIC text data bss dec hex filename 222687 14400 24228 261315 3fcc3 u-boot size with -mbss-plt -fpic text data bss dec hex filename 225179 6580 24228 255987 3e7f3 u-boot size with -mbss-plt -fpic -msingle-pic-base text data bss dec hex filename 222091 6580 24228 252899 3dbe3 u-boot Note: -msingle-pic-base is not supported upstarem yet. Signed-off-by: Joakim Tjernlund --- v2: Better commit msg Fix linker script for two NAND boards. Only compile the new -fpic code if compiled with -fpic to reduce size. arch/powerpc/cpu/mpc83xx/start.S | 31 +++++++++++++++++++++- arch/powerpc/cpu/mpc83xx/u-boot.lds | 1 + nand_spl/board/freescale/mpc8313erdb/u-boot.lds | 2 + nand_spl/board/freescale/mpc8315erdb/u-boot.lds | 2 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S index c7d85a8..8b540bc 100644 --- a/arch/powerpc/cpu/mpc83xx/start.S +++ b/arch/powerpc/cpu/mpc83xx/start.S @@ -69,6 +69,10 @@ */ START_GOT GOT_ENTRY(_GOT2_TABLE_) +#if defined(__pic__) && __pic__ == 1 + GOT_ENTRY(_GOT_TABLE_) + GOT_ENTRY(_GLOBAL_OFFSET_TABLE_) +#endif GOT_ENTRY(__bss_start) GOT_ENTRY(_end) @@ -296,7 +300,11 @@ in_flash: /*------------------------------------------------------*/ GET_GOT /* initialize GOT access */ - +#if defined(__pic__) && __pic__ == 1 + /* Needed for upcoming -msingle-pic-base */ + bl _GLOBAL_OFFSET_TABLE_@local-4 + mflr r30 +#endif /* r3: IMMR */ lis r3, CONFIG_SYS_IMMR@h /* run low-level CPU init code (in Flash)*/ @@ -950,7 +958,26 @@ in_ram: add r0,r0,r11 stw r0,0(r3) 2: bdnz 1b - +#if defined(__pic__) && __pic__ == 1 + /* + * Relocation of *.got(-fpic) + */ + lwz r4,GOT(_GLOBAL_OFFSET_TABLE_) + addi r4,r4,-4 /* don't write over blrl in GOT */ + lwz r3,GOT(_GOT_TABLE_) + subf. r4,r3,r4 /* r4 - r3 */ + ble 3f + srwi r4,r4,2 /* r4/4 */ + mtctr r4 + addi r3,r3,-4 +1: lwzu r0,4(r3) + cmpwi r0,0 + beq- 2f + add r0,r0,r11 + stw r0,0(r3) +2: bdnz 1b +3: +#endif #ifndef CONFIG_NAND_SPL /* * Now adjust the fixups and the pointers to the fixups diff --git a/arch/powerpc/cpu/mpc83xx/u-boot.lds b/arch/powerpc/cpu/mpc83xx/u-boot.lds index 0b74a13..a498a37 100644 --- a/arch/powerpc/cpu/mpc83xx/u-boot.lds +++ b/arch/powerpc/cpu/mpc83xx/u-boot.lds @@ -67,6 +67,7 @@ SECTIONS PROVIDE (erotext = .); .reloc : { + _GOT_TABLE_ = .; *(.got) _GOT2_TABLE_ = .; *(.got2) diff --git a/nand_spl/board/freescale/mpc8313erdb/u-boot.lds b/nand_spl/board/freescale/mpc8313erdb/u-boot.lds index ad82589..1a3e44f 100644 --- a/nand_spl/board/freescale/mpc8313erdb/u-boot.lds +++ b/nand_spl/board/freescale/mpc8313erdb/u-boot.lds @@ -38,6 +38,8 @@ SECTIONS .data : { *(.data*) *(.sdata*) + _GOT_TABLE_ = .; + *(.got) _GOT2_TABLE_ = .; *(.got2) __got2_entries = (. - _GOT2_TABLE_) >> 2; diff --git a/nand_spl/board/freescale/mpc8315erdb/u-boot.lds b/nand_spl/board/freescale/mpc8315erdb/u-boot.lds index ad82589..1a3e44f 100644 --- a/nand_spl/board/freescale/mpc8315erdb/u-boot.lds +++ b/nand_spl/board/freescale/mpc8315erdb/u-boot.lds @@ -38,6 +38,8 @@ SECTIONS .data : { *(.data*) *(.sdata*) + _GOT_TABLE_ = .; + *(.got) _GOT2_TABLE_ = .; *(.got2) __got2_entries = (. - _GOT2_TABLE_) >> 2;