accees constant defined in linker script

OP #1173821
Hello,

I define a constant in the linker script and want access it from C-code:

SECTIONS
{
...
 _bootsize = 0x00004000;
...
}

Here is code snippet:

extern unsigned long _bootsize;
char message[10];
...
siprintf(message, "Bootsize: 0x%x\n\r", _bootsize);
AT91F_DBGU_Frame(message);

But it always prints out "Bootsize: 0x2004d4" Why so?
As far as I understand, it's quite possible to do what I want.
#1173822
Roman Mashak wrote:
> Hello,
>
> I define a constant in the linker script and want access it from C-code:
>
> SECTIONS
> {
> ...
>  _bootsize = 0x00004000;
> ...
> }
>
> Here is code snippet:
>
> extern unsigned long _bootsize;
> char message[10];
> ...
> siprintf(message, "Bootsize: 0x%x\n\r", _bootsize);
> AT91F_DBGU_Frame(message);
>
> But it always prints out "Bootsize: 0x2004d4" Why so?
> As far as I understand, it's quite possible to do what I want.

Looking at the documentation here:
http://sourceware.org/binutils/docs-2.18/ld/Source-Code-Reference.html#Source-Code-Reference

If I understood it right _bootsize is the address of your constant, the
constant is allocated there as a word.
#1173823
Roman Mashak wrote:
> Hello,
>
> I define a constant in the linker script and want access it from C-code:
>
> SECTIONS
> {
> ...
>  _bootsize = 0x00004000;
> ...
> }
>
> Here is code snippet:
>
> extern unsigned long _bootsize;
> char message[10];
> ...
> siprintf(message, "Bootsize: 0x%x\n\r", _bootsize);
> AT91F_DBGU_Frame(message);
>
> But it always prints out "Bootsize: 0x2004d4" Why so?
> As far as I understand, it's quite possible to do what I want.

Look at a sample here with the file syscall.c, you will have a sample on
how to access a constant address from C source.

Jonathan
OP #1173824
Giovanni Di Sirio wrote:
> Looking at the documentation here:
> 
http://sourceware.org/binutils/docs-2.18/ld/Source-Code-Reference.html#Source-Code-Reference
>
> If I understood it right _bootsize is the address of your constant, the
> constant is allocated there as a word.
Hm.. After reading documentation at the link, I come to the conclusion
that there is no way to assign a value to a linker script defined
symbol. Such symbol will always hold only address.

Am I right, there is no way to get what I want?
OP #1173825
Jonathan Dumaresq wrote:
> Look at a sample here with the file syscall.c, you will have a sample on
> how to access a constant address from C source.
Before posting I studied that code and did as in there. It seems I can't
achieve what I need: to define a constant value in a linker script and
use it from the C code.

Reply

A question of your own? This thread is over 18 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.