From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerry Van Baren Date: Thu, 24 Jul 2008 08:23:08 -0400 Subject: [U-Boot-Users] Changing u-boot relocation scheme In-Reply-To: References: <20080724031826.ECD9B248B9@gemini.denx.de> Message-ID: <4888742C.3020207@ge.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de vb wrote: > Wolfgang, thank you for your reply, let me try to explain myself a bit clearer: > > On Wed, Jul 23, 2008 at 8:18 PM, Wolfgang Denk wrote: >> In message you wrote: >> >>> some companies). If these added modules were not written in position >>> independent manner (namely, using structures with multiple stage >>> indirect pointers interleaved with data), the effort to make these >>> modules work in u-boot is very exhausting. >> I don't understand what you mean. Either you link statically with the >> U-Boot image, or you use standalone programs. In both situations no >> such problem as described by you exists. > > we talk here about modules statically linked into the u-boot image. > Allow me to illustrate the problem I am trying to solve. Consider > adding this code to a u-boot source file on a ppc460gt platform: > > vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv > 87a88,105 >> int do_ptrt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); >> >> int (*pf)(struct cmd_tbl_s *, int, int, char *[]) = do_ptrt; >> >> int do_ptrt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) >> { >> printf ("pointer is %p\n", pf); >> printf ("function is %p\n", do_ptrt); >> return 0; >> } >> >> U_BOOT_CMD( >> ptrt, CFG_MAXARGS, 1, do_ptrt, >> "ptrt\n", >> "" >> ); >> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > And this is what happens when this command is invoked: > > vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv > => ptrt > pointer is fffb2754 > function is 0ffb7754 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > So, the value of 'pf' is equal to the address of do_ptrt() *before* > relocation. The fact that there is a GOT and a sophisticated linker > script did not prevent this from happening. OK, now I'm curious: what happens if you make the pf() pointer constant? This will (should) change it from an initialized variable in the .data section to a constant in the .rodata section. I'm wondering if the .rodata section gets relocation information where the .data section doesn't. int do_ptrt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); const int (*pf)(struct cmd_tbl_s *, int, int, char *[]) = do_ptrt; int do_ptrt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { printf ("pointer is %p\n", pf); printf ("function is %p\n", do_ptrt); return 0; } Thanks, gvb