* MEMORY attributes in linker script
@ 2015-04-17 13:27 James Murray
2015-04-17 18:04 ` Cary Coutant
0 siblings, 1 reply; 3+ messages in thread
From: James Murray @ 2015-04-17 13:27 UTC (permalink / raw)
To: binutils
I apologise if I'm missing something obvious here, but I got confused by
ld's handling of attributes in the MEMORY section of linker scripts.
I've seen this on a couple of embedded architectures.
Here:
https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY
It says:
------------------
MEMORY
{
name [(attr)] : ORIGIN = origin, LENGTH = len
...
}
The attr string is an optional list of attributes....
------------------
However, setting that attribute does not actually set the generated
section attributes in the linker output. I assumed that it would.
Somewhere else (can't find the link now) it said that the section
attributes are checked but ignored?
e.g.
I'm trying to link in a section .boot that contains a reset vector.
------------------
linker script extract
------------------
MEMORY
{
boot (rx) : ORIGIN = 0x00000000, LENGTH = 1K
...
}
...
SECTIONS
{
.boot :
{
. = ALIGN(4);
*(.boot)
} > boot
...
-------------
boot.s source
-------------
.sect .boot
.org 0
.long 0x005a0000
.long __start
Having compiled, assembled and linked:
--------------
objdump output
--------------
Sections:
Idx Name Size VMA LMA File off Algn
0 .boot 00000008 00000000 00000000 00020014 2**0
CONTENTS, READONLY
1 .text 00000564 00020000 00020000 00010000 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
My .boot section does not have the "LOAD" attribute set and is then
ignored by my firmware loader.
What I found (after a lot of fumbling around) was that I needed to
specify a section flag in my source file. Is it correct that ld is
picking the section flag from the input object files rather than using
the memory section attributes?
--------------
boot.s revised
--------------
.sect .boot, "ax"
.org 0
.long 0x005a0000
.long __start
----------------------
objdump output revised
----------------------
Sections:
Idx Name Size VMA LMA File off Algn
0 .boot 00000008 00000000 00000000 00010000 2**0
CONTENTS, ALLOC, LOAD, READONLY, CODE
This then IS accepted by my firmware loader and all is good.
I've tripped over this once before when I was trying to include some raw
data in an assembler file and it wasn't getting loaded to the chip.
Putting some dummy C code into the same memory section resolved it. (I
assume now that gcc was setting the relevant section flags.)
If this is all behaving as expected, perhaps it would help future coders
like myself by adding a note to the ld manual page something like this:
"Note that output section attributes are derived from the input object
files and not from the MEMORY section. Tip: see the 'gas' manual for
section flags."
regards
James Murray
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: MEMORY attributes in linker script
2015-04-17 13:27 MEMORY attributes in linker script James Murray
@ 2015-04-17 18:04 ` Cary Coutant
2015-04-17 18:20 ` James Murray
0 siblings, 1 reply; 3+ messages in thread
From: Cary Coutant @ 2015-04-17 18:04 UTC (permalink / raw)
To: James Murray; +Cc: Binutils
> However, setting that attribute does not actually set the generated
> section attributes in the linker output. I assumed that it would.
>
> Somewhere else (can't find the link now) it said that the section
> attributes are checked but ignored?
The MEMORY block in the linker script doesn't define a section or
segment; it describes a region of memory that's available for
placement of sections. If you specify attributes, the linker uses them
to decide whether a section is eligible to be placed in that memory
region, but it's the attributes of the sections themselves that
determine the attributes of the output section.
-cary
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: MEMORY attributes in linker script
2015-04-17 18:04 ` Cary Coutant
@ 2015-04-17 18:20 ` James Murray
0 siblings, 0 replies; 3+ messages in thread
From: James Murray @ 2015-04-17 18:20 UTC (permalink / raw)
To: Binutils, Cary Coutant
On Fri, 2015-04-17 at 11:04 -0700, Cary Coutant wrote:
> > However, setting that attribute does not actually set the generated
> > section attributes in the linker output. I assumed that it would.
> >
> > Somewhere else (can't find the link now) it said that the section
> > attributes are checked but ignored?
>
> The MEMORY block in the linker script doesn't define a section or
> segment; it describes a region of memory that's available for
> placement of sections. If you specify attributes, the linker uses them
> to decide whether a section is eligible to be placed in that memory
> region, but it's the attributes of the sections themselves that
> determine the attributes of the output section.
Thanks for that clarification.
Are those words already in the documentation? If not, is there any
chance of adding them and possibly a few of the words I suggested
before?
regards
James Murray
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-17 18:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-17 13:27 MEMORY attributes in linker script James Murray
2015-04-17 18:04 ` Cary Coutant
2015-04-17 18:20 ` James Murray
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).