mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Renaud Barbier <renaud.barbier@ge.com>
Cc: barebox@lists.infradead.org
Subject: Re: arm: Question on linker script and start/end variables
Date: Tue, 8 Mar 2016 08:22:46 +0100	[thread overview]
Message-ID: <20160308072246.GA30994@pengutronix.de> (raw)
In-Reply-To: <56DDAE3A.3030808@ge.com>

On Mon, Mar 07, 2016 at 04:37:14PM +0000, Renaud Barbier wrote:
> I have a ARM-based board for which we have a running barebox.
> 
> In the low level code, when running from flash, I would like to get the
> start and end address of a section. For instance, &__barebox_cmd_start
> and &__barebox_cmd_end.
> 
> For both I am getting 0 unless I am running from memory.
> 
> Even assigning these addresses to variables always returns 0.
> 
> This is not an issue on PPC platforms.
> 
> All my tests and research to get the correct address on ARM has led to
> no positive results.
> 
> Has anybody an explanation why these addresses cannot be obtained on ARM
> platforms?

It doesn't work for two reasons. First of all the program is not running
at the address it is linked at. barebox on ARM is linked as position
independent executable (-pie) to address 0x0. Usually when called from the
SoC ROM the binary will run at another address though. This means that
pointers to global variables that are stored in the binary will point to
0x0 + offset in the binary. To use the variables we have to add the
offset between 0x0 and the address we are really running to the pointer.
The second reason comes with linker generated variables like
__bss_start. These are set to 0x0 in the binary. They need to be fixed
up during runtime using the dynsym table, see relocate_to_current_adr().
I don't know a way to access these in C. In barebox we have the ld_var
macro which uses assembly to access the linker generated variables. Note
that you can't access arbitrary variables, to access __barebox_cmd_start
you have to add the variable to arch/arm/lib/runtime-offset.S.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      reply	other threads:[~2016-03-08  7:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 16:37 Renaud Barbier
2016-03-08  7:22 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160308072246.GA30994@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=renaud.barbier@ge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox