How to align load address?

OP #1288699
I have some initialized variables that I want to place in a special area 
of RAM.  I want the initialized values stored in ROM after the load area 
for .ramcode.  Like this:
1
. = ALIGN(4);
2
_ramcodeload = .;     /* at this point "dot" is still in ROM */
3
.ramcode : 
4
{
5
   _ramcodestart = .;
6
   *(.ramcode);
7
   _ramcodeend = .;
8
} > ram
9

10
. = ALIGN(4);
11
_where_am_i = .;     /* Now in RAM. This is = _ramcodeend + alignment */
12
/* ALIGN(4) only works on the "dot" location marker */
13

14
_usbload = ( LOADADDR(.ramcode) + SIZEOF(.ramcode) );
15
.usbram : AT ( _usbload )     /* I want _usbload aligned! */
16
{
17
   _usbstart    = .;
18
   *(.usbram)
19
   _usbend    = .;
20
} > usbram

But the end of .ramcode stored in ROM may not be aligned. How I do I 
force the linker to align where the initialized values for the .usbram 
section are to be stored in ROM?
Guest #1288842
Placeing . = ALIGN(4); inside the definitions of the output-sections 
should do. This can be checked by looking into the map-file and/or 
symbol-list. If it does not work, please create a minimal example with 
all needed files for a "make all" to reproduce the issue, pack it into a 
zip-archive and attach it to a message.
OP #1294755
I replaced
1
_usbload = ( LOADADDR(.ramcode) + SIZEOF(.ramcode) );
2
.usbram : AT ( _usbload )     /* I want _usbload aligned! */
3
{
4
   _usbstart    = .;
5
   *(.usbram)
6
   _usbend    = .;
7
} > usbram

with
1
.usbram : 
2
{
3
   _usbstart    = .;
4
   *(.usbram)
5
   _usbend    = .;
6
} > usbram AT>flash
7
_usbload = LOADADDR(.usbram);

and the alignment happens automatically.

Reply

A question of your own? This thread is over 17 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.