This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: relations between Linker and Map File
- From: Nick Clifton <nickc at redhat dot com>
- To: Dong Phuong <dongphuong2410 at yahoo dot com>
- Cc: binutils at sourceware dot org
- Date: Tue, 23 Dec 2008 09:42:41 +0000
- Subject: Re: relations between Linker and Map File
- References: <350218.94676.qm@web31910.mail.mud.yahoo.com>
Hi Dong,
I'm using as to assemble for source code. This
requires a file called "filenam.link", :
Actually it is the linker, not the assembler, that is using this file.
I think this file is used to decides where the data an
code will be allocated in memory.
It is *part* of the process yes.
But now I want to change it, I want the code area will
including many areas which are not contiguous in
memory. I don't know if this is possible.
First of all read the linker documentation. Especially the section on
linker scripts. The linker script determines how your application is
laid out in memory.
You may find that it is still difficult to implement exactly what you
want however, since the linker is not smart enough on its own to
distribute executable code amongst multiple, non-contiguous, regions of
memory.
The usual answer to this problem is for the programmer to tell the
linker which pieces of code should be allocated to which sections of
memory by assigning each function in the source code to a specific
section and then having the linker script map these sections to the
specific memory regions.
So for example the source program might look like this:
int func (void) __attribute__((section (".code_1")));
int func (void) { return 7; }
int main (void) __attribute__((section (".code_2")));
int main (void) { return func (); }
and the linker script might look something like this:
MEMORY
{
execcode_area_1: o = 0x10002, l = 0x1000
execcode_area_2: o = 0x30002, l = 0x1000
dram: o = 0x20000, l = 0x1000
}
SECTIONS
{
.code_1 { *(.code_1) } > execcode_area_1
.code_2 { *(.code_2) } > execcode_area_2
.data { *(.data) } > dram
}
(This is just an example, not a full linker script...)
Cheers
Nick