From patchwork Wed Oct 13 21:11:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joakim Tjernlund X-Patchwork-Id: 71866 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 7A06B1365CC for ; Wed, 13 Oct 2010 23:14:02 +0200 (CEST) Received: from diddl.denx.de (localhost.localdomain [127.0.0.1]) by diddl.denx.de (Postfix) with ESMTP id 2FCD63230C06 for ; Wed, 13 Oct 2010 23:14:02 +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 23:14:02 +0200 (CEST) Received: from murder ([192.168.6.180]) by backend2 (Cyrus v2.2.12) with LMTPA; Wed, 13 Oct 2010 23:12:39 +0200 X-Sieve: CMU Sieve 2.2 Received: from mail.m-online.net (localhost [127.0.0.1]) by frontend3.mail.m-online.net (Cyrus v2.2.12) with LMTPA; Wed, 13 Oct 2010 23:12:38 +0200 Received: from scanner-4.m-online.net (scanner-4.mail.m-online.net [192.168.1.18]) by mail.m-online.net (Postfix) with ESMTP id AFDCE1C000E8; Wed, 13 Oct 2010 23:12:38 +0200 (CEST) Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by mxin-2.m-online.net (Postfix) with ESMTP id 3A32C46C0B8; Wed, 13 Oct 2010 23:12:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3A7E2280D0; Wed, 13 Oct 2010 23:12:17 +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 6VXfYKtoTO2N; Wed, 13 Oct 2010 23:12:16 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A19C0280D5; Wed, 13 Oct 2010 23:12:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 29344280B7 for ; Wed, 13 Oct 2010 23:12:08 +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 TziqomgcAs3U for ; Wed, 13 Oct 2010 23:12:06 +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 0843F280B4 for ; Wed, 13 Oct 2010 23:12:04 +0200 (CEST) Received: from sesr04.transmode.se (sesr04.transmode.se [192.168.201.15]) by gw1.transmode.se (Postfix) with ESMTP id 7403A2597C9; Wed, 13 Oct 2010 23:12:03 +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 2010101323120359-12510 ; Wed, 13 Oct 2010 23:12:03 +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 o9DLC3Rw021325; Wed, 13 Oct 2010 23:12:03 +0200 Received: (from jocke@localhost) by gentoo-jocke.transmode.se (8.14.4/8.14.4/Submit) id o9DLC2l6021324; Wed, 13 Oct 2010 23:12:02 +0200 From: Joakim Tjernlund To: u-boot@lists.denx.de, Scott Wood , Kim Phillips Date: Wed, 13 Oct 2010 23:11:59 +0200 Message-Id: <1287004319-21282-1-git-send-email-Joakim.Tjernlund@transmode.se> X-Mailer: git-send-email 1.7.2.2 In-Reply-To: <1286962876-5764-1-git-send-email-Joakim.Tjernlund@transmode.se> References: <1286962876-5764-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 23:12:03, Serialize by Router on sesr04/Transmode(Release 8.5.2 HF23|September 01, 2010) at 2010-10-13 23:12:03, Serialize complete at 2010-10-13 23:12:03 Cc: Joakim Tjernlund Subject: [U-Boot] [PATCHv3] 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 adds 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 upstream yet. Signed-off-by: Joakim Tjernlund --- v3: - Make the new -fpic code to have zero impact when not compled with -fpic - linker __got*_entries sysm needs to be defined outside the referenced scope. Add linker sym __got_entries for -fpic relocs. Very likely more *lds scripts needs fixing but that is somebody elses problem :) - NAND SPL still don't fit for MPC8315ERDB and SIMPC8313 but these didn't fit before either. Note that my tree isn't current so it migth be fixed in master. arch/powerpc/cpu/mpc83xx/start.S | 26 +++++++++++++++++++++- arch/powerpc/cpu/mpc83xx/u-boot.lds | 3 ++ nand_spl/board/freescale/mpc8313erdb/u-boot.lds | 7 ++++- nand_spl/board/freescale/mpc8315erdb/u-boot.lds | 7 ++++- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S index c7d85a8..c9bb0ea 100644 --- a/arch/powerpc/cpu/mpc83xx/start.S +++ b/arch/powerpc/cpu/mpc83xx/start.S @@ -296,7 +296,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 +954,25 @@ in_ram: add r0,r0,r11 stw r0,0(r3) 2: bdnz 1b - +#if defined(__pic__) && __pic__ == 1 + /* + * Relocation of *.got(-fpic) + * + * Adjust got pointers, no need to check for 0, this code + * already puts one entry in the table. + */ + li r0,__got_entries@sectoff@l + lwz r3,_GOT_TABLE_@got(r30) + add r3,r3,r11 + mtctr r0 + 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 +#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..8b189d9 100644 --- a/arch/powerpc/cpu/mpc83xx/u-boot.lds +++ b/arch/powerpc/cpu/mpc83xx/u-boot.lds @@ -67,12 +67,15 @@ SECTIONS PROVIDE (erotext = .); .reloc : { + _GOT_TABLE_ = .; + PROVIDE(_GLOBAL_OFFSET_TABLE_ = . + 4); *(.got) _GOT2_TABLE_ = .; *(.got2) _FIXUP_TABLE_ = .; *(.fixup) } + __got_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT_TABLE_) >> 2)-1; __got2_entries = (_FIXUP_TABLE_ - _GOT2_TABLE_) >> 2; __fixup_entries = (. - _FIXUP_TABLE_) >> 2; diff --git a/nand_spl/board/freescale/mpc8313erdb/u-boot.lds b/nand_spl/board/freescale/mpc8313erdb/u-boot.lds index ad82589..a3cacf6 100644 --- a/nand_spl/board/freescale/mpc8313erdb/u-boot.lds +++ b/nand_spl/board/freescale/mpc8313erdb/u-boot.lds @@ -38,11 +38,14 @@ SECTIONS .data : { *(.data*) *(.sdata*) + _GOT_TABLE_ = .; + PROVIDE(_GLOBAL_OFFSET_TABLE_ = . + 4); + *(.got) _GOT2_TABLE_ = .; *(.got2) - __got2_entries = (. - _GOT2_TABLE_) >> 2; } - + __got_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT_TABLE_) >> 2)-1; + __got2_entries = (. - _GOT2_TABLE_) >> 2; . = ALIGN(8); __bss_start = .; .bss (NOLOAD) : { *(.*bss) } diff --git a/nand_spl/board/freescale/mpc8315erdb/u-boot.lds b/nand_spl/board/freescale/mpc8315erdb/u-boot.lds index ad82589..a3cacf6 100644 --- a/nand_spl/board/freescale/mpc8315erdb/u-boot.lds +++ b/nand_spl/board/freescale/mpc8315erdb/u-boot.lds @@ -38,11 +38,14 @@ SECTIONS .data : { *(.data*) *(.sdata*) + _GOT_TABLE_ = .; + PROVIDE(_GLOBAL_OFFSET_TABLE_ = . + 4); + *(.got) _GOT2_TABLE_ = .; *(.got2) - __got2_entries = (. - _GOT2_TABLE_) >> 2; } - + __got_entries = ((_GLOBAL_OFFSET_TABLE_ - _GOT_TABLE_) >> 2)-1; + __got2_entries = (. - _GOT2_TABLE_) >> 2; . = ALIGN(8); __bss_start = .; .bss (NOLOAD) : { *(.*bss) }