This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Regarding linker code generation
- From: Nick Clifton <nickc at redhat dot com>
- To: Bhushan Verma <bhushan dot verma at iap-online dot com>
- Cc: binutils at sourceware dot org
- Date: Fri, 07 Sep 2007 16:38:47 +0100
- Subject: Re: Regarding linker code generation
- References: <OIEOKFKBHBJGOGBPDDFIAEJCCBAA.bhushan.verma@iap-online.com>
Hi Bhushan,
Now problem is that we are unable to give the execute permission (RWX) to
data segment. This is requirement for run time linker.
An unusual requirement, but OK...
Could you please help me how can I do this ,is there any provision to change
the default linker script.
Yes. The -T command line switch to the linker (or to gcc) will override the
default linker script and let you specify your own script.
Here is one way of doing this:
1. Run "ld --verbose" and save the output. This gives you a copy of the
built-in, default linker script. You will need to edit the output to remove a
few lines of text at the beginning and end of the output.
2. Read the linker manual's section on linker scripts and in particular the
part about defining your segments. Then add a set of segment definitions to
your new linker script. For example I used this:
PHDRS
{
exec_data PT_LOAD FLAGS (7) ;
code PT_LOAD FLAGS (5) ;
data PT_LOAD FLAGS (6) ;
}
3. Now you can annotate the entries in the SECTIONS part of the linker
script with the segment that you want them to use. eg:
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) } :exec_data
You may need to experiment a bit but you should be able to achieve the results
you want.
Cheers
Nick