public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Variables in linker script
@ 2010-09-21 11:43 Nikola Ikonic
  2010-09-22  1:11 ` Alan Modra
  0 siblings, 1 reply; 5+ messages in thread
From: Nikola Ikonic @ 2010-09-21 11:43 UTC (permalink / raw)
  To: binutils

Hello all,

I have an issue with variables in linker script and I was wondering
would someone be kind enough to answer me on some questions.

Linker would not "swallow" following piece of code in linker script:

"OR = 0x40132d00;

MEMORY
{
   /*These commands describe block locations (execution area)*/
   MODULE2      : ORIGIN = OR, LENGTH = 0x6d7b00
}"

It gives error: "nonconstant expression for.."

From what I understand, currently, linker does not support this
feature (usage of variables in memory region definition).
I would like to implement this in linker.

I've looked little bit at linker code already (saw the ldexp.c file
and exp_get_vma() where this error message comes from).

First, I would like to ask if there is a table of variables in linker?
I am asking this because linker does process simple statements with
variables such as:

"OR = 0x40132d00;"

I was wondering if someone could answer me, which part of code process
this statement? Where is value of OR variable held (in this example)?
Could this kind of table be used for solving my problem?

Thank you in advance.

Regards,
	Nikola

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variables in linker script
  2010-09-21 11:43 Variables in linker script Nikola Ikonic
@ 2010-09-22  1:11 ` Alan Modra
  2010-09-22  4:59   ` Dave Korn
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Modra @ 2010-09-22  1:11 UTC (permalink / raw)
  To: Nikola Ikonic; +Cc: binutils

On Tue, Sep 21, 2010 at 01:43:17PM +0200, Nikola Ikonic wrote:
> First, I would like to ask if there is a table of variables in linker?

No.  Symbol values are held in the main linker symbol table.  Linker
script (and --defsym) values are set by lang_do_assignments.  This
happens too late to use their values in statements setting section
addresses.  Running lang_do_assignments earlier is possible but you
will likely need to fix quite a lot of fallout.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variables in linker script
  2010-09-22  1:11 ` Alan Modra
@ 2010-09-22  4:59   ` Dave Korn
  2010-09-22 12:22     ` Nikola Ikonic
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Korn @ 2010-09-22  4:59 UTC (permalink / raw)
  To: Nikola Ikonic, binutils

On 22/09/2010 02:11, Alan Modra wrote:
> On Tue, Sep 21, 2010 at 01:43:17PM +0200, Nikola Ikonic wrote:
>> First, I would like to ask if there is a table of variables in linker?
> 
> No.  Symbol values are held in the main linker symbol table.  Linker
> script (and --defsym) values are set by lang_do_assignments.  This
> happens too late to use their values in statements setting section
> addresses.  Running lang_do_assignments earlier is possible but you
> will likely need to fix quite a lot of fallout.
> 

  As an alternative to rewriting the linker, what a lot of people do is use
the C pre-processor to generate a linker script from a template (as part of a
makefile), that way you can use #defines for/instead of/as well as symbol
definitions.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variables in linker script
  2010-09-22  4:59   ` Dave Korn
@ 2010-09-22 12:22     ` Nikola Ikonic
  2010-09-23  2:01       ` Dave Korn
  0 siblings, 1 reply; 5+ messages in thread
From: Nikola Ikonic @ 2010-09-22 12:22 UTC (permalink / raw)
  To: Dave Korn; +Cc: binutils

Hello all,

thanks for your replies. Dave, would it be possible to create a
preprocessor file which would create linker scripts which do some kind
of arithmetics with variables? I made an example with OR = 0x40132d00;

but what if would have

LEN = 0x5000;
OR = 0x40132d00;
End = OR+LEN;

MEMORY
{
 /*These commands describe block locations (execution area)*/
 MODULE2      : ORIGIN = OR, LENGTH = END;
}"

Or there could be some other kind of arithmetics (multiplying etc).

Thank you in advance.

Best regards,
          Nikola


On Wed, Sep 22, 2010 at 6:23 AM, Dave Korn <dave.korn.cygwin@gmail.com> wrote:
> On 22/09/2010 02:11, Alan Modra wrote:
>> On Tue, Sep 21, 2010 at 01:43:17PM +0200, Nikola Ikonic wrote:
>>> First, I would like to ask if there is a table of variables in linker?
>>
>> No.  Symbol values are held in the main linker symbol table.  Linker
>> script (and --defsym) values are set by lang_do_assignments.  This
>> happens too late to use their values in statements setting section
>> addresses.  Running lang_do_assignments earlier is possible but you
>> will likely need to fix quite a lot of fallout.
>>
>
>  As an alternative to rewriting the linker, what a lot of people do is use
> the C pre-processor to generate a linker script from a template (as part of a
> makefile), that way you can use #defines for/instead of/as well as symbol
> definitions.
>
>    cheers,
>      DaveK
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Variables in linker script
  2010-09-22 12:22     ` Nikola Ikonic
@ 2010-09-23  2:01       ` Dave Korn
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Korn @ 2010-09-23  2:01 UTC (permalink / raw)
  To: Nikola Ikonic; +Cc: binutils

On 22/09/2010 13:22, Nikola Ikonic wrote:

> thanks for your replies. Dave, would it be possible to create a
> preprocessor file which would create linker scripts which do some kind
> of arithmetics with variables? I made an example with OR = 0x40132d00;
> 
> but what if would have
> 
> LEN = 0x5000;
> OR = 0x40132d00;
> End = OR+LEN;
> 
> MEMORY
> {
>  /*These commands describe block locations (execution area)*/
>  MODULE2      : ORIGIN = OR, LENGTH = END;
> }"
> 
> Or there could be some other kind of arithmetics (multiplying etc).

  LD can parse expressions just fine, just so long as all the symbols are
defined as constants, so

#define LEN 0x5000
#define OR  0x40132d00
#define END (LEN + OR)

MEMORY
{
  /*These commands describe block locations (execution area)*/
  MODULE2      : ORIGIN = OR, LENGTH = END;
}

... ought to do what you want, I think.

    cheers,
      DaveK

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-09-23  2:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-21 11:43 Variables in linker script Nikola Ikonic
2010-09-22  1:11 ` Alan Modra
2010-09-22  4:59   ` Dave Korn
2010-09-22 12:22     ` Nikola Ikonic
2010-09-23  2:01       ` Dave Korn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).