This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
MEMORY attributes in linker script
- From: James Murray <james at nscc dot info>
- To: binutils at sourceware dot org
- Date: Fri, 17 Apr 2015 14:27:54 +0100
- Subject: MEMORY attributes in linker script
- Authentication-results: sourceware.org; auth=none
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