This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: putting a variable in an own section


Torsten Mohr <tmohr at s dot netic dot de> writes:

> I just don't want ld to also put the .bss at the same address
> as the .data section.  That's why i thought it was necessary to
> generate a section ".data".
> Is this unnecessary?
> If i just put all the values in section .rodata, how does
> ld know to reserve some space and NOT use it for .bss?

The linker tracks the VMA and the LMA separately.  You are using AT to
set the LMA, while in your case the VMA is coming from a memory
region.  The linker will ensure that the VMA of the .data and the .bss
do not overlap.  The LMA of the .bss is not interesting.  In general I
think that you have to ensure that the LMA of the .data section does
not overlap with the VMA of any other section--at least, I can't
recall that the linker will handle this for you.  In most situations
this is not a problem as the LMA and VMA are at noticeably different
addresses.

> > > I'm testing this on v850-unknown-elf and i have
> > > for V850/SF1:
> > >
> > > 	.text : { *(.text) _etext = . ; } >rom
> > > 	.rodata : { *(.rodata) } >rom
> > > 	.data : AT(ADDR(.rodata)) { *(.data) } >ram
> > >
> > >
> > > But this leads to an error in the line with ".data":
> > > v850-unknown-elf-ld: ADDR forward reference of section .rodata
> > > What's wrong here?
> >
> > Not sure, really.  It might be a bug.  On the other hand, the script
> > doesn't really make sense, because you're trying to load both .rodata
> > and .data at the same LMA.
> 
> That's true, but .rodata should be just empty, so i assumed i should be
> able to use the address.

If you know for sure that .rodata is empty, then that is fine.

> > > Now i've tried the following, basically i put everything that
> > > goes in .data into .rodata and set the size of .data
> > > to the size of .rodata:
> > >
> > > 	.text : { *(.text) _etext = . ; } >rom
> > > 	.rodata : { *(.data) } >rom
> > > 	.data : { . += SIZEOF(.rodata); } >ram
> >
> > I don't see any need to create the .data section at all.
> 
> If i omit that section, .bss is placed there.  I've generated this
> section, so ld knows it can't use it for .bss .  In my ld script,
> .bss is following .data, at the moment.

OK, I think we were both slightly confused.  If you don't have an
input .rodata section, then you don't need an output .rodata section.
You certainly don't want to put *(.data) there, since that would
effectively make the VMA of your .data section in the `rom' memory
region, which is exactlywhat you don't want.

You want something more like

  .text : { *(.text) _etext = . ; } >rom
  .data : AT(ADDR(.text) + SIZEOF(.text)) { *(.data) } >ram
  .bss : { (*.bss) } >ram

This will set the VMA of the .data section in the `ram' memory region,
while setting the LMA just after .text in the `rom' memory region.  In
fact, since you are using memory regions, you probably want to do
something like this:

  .text : { *(.text) _etext = . ; } >rom
  .data : AT>rom { *(.data) } >ram
  .bss : { (*.bss) } > ram

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]