This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: Porting the linker
- From: Jean Christophe Beyler <jean dot christophe dot beyler at gmail dot com>
- To: Nick Clifton <nickc at redhat dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 17 May 2010 17:03:11 -0400
- Subject: Re: Porting the linker
- References: <c568a2601002240753g5a74268bo2be8976ed2b678fa@mail.gmail.com> <4B8BF868.7010006@redhat.com> <c568a2601003091326g2d3f1191t5e76d7bbe9cad987@mail.gmail.com> <4B979A8E.3070209@redhat.com>
I've continued my investigations and, doing what you said to do, I
figured that I could :
- Modify the output segments to point to the bigger segment versions
of them with a function such as this one after the lang_place_orphans
:
void
moveToBiggerSegment (char* segment_suffix)
{
LANG_FOR_EACH_INPUT_STATEMENT (file)
{
asection *s;
for (s = file->the_bfd->sections; s != NULL; s = s->next)
{
if (s->output_section)
{
asection *os = s->output_section;
if (os != NULL)
{
/* Let's move these to bigger segment */
static char *whatToMove[] = { ".bss", ".sbss",
".lbss", ".data"};
char buf[256];
unsigned int i;
for (i=0; i < sizeof (whatToMove) / sizeof
(whatToMove[0]); i++)
{
if (strcmp (os->name, whatToMove[i]) == 0)
{
sprintf (buf, "%s_%s", whatToMove[i],
segment_suffix);
lang_output_section_statement_type *new_sec = NULL;
new_sec = lang_output_section_statement_lookup(buf);
s->output_section = new_sec->bfd_section;
}
}
}
}
}
}
}
(a) However, for a reason I don't know, this doesn't work with archive
files such as what is in newlib. I'll have to see why, I know it has
to do with the moving of .data to .data_segment_suffix...
Second, once I've done that, I've lost what variables have to go into
the smaller zone so I don't know yet how to do that.
The one idea I had was:
For example, let's consider the .bss, instead of sending it to
.bss_segment_suffix, I'll send it to : .bss_temp
And define .bss_temp, that should allow me to then go to all the data
and add them into .bss until I fill that in. Then I'll send the rest
to the bigger zone.
(b) However, I still don't know how to, once segments have been sized
up, see every variable/symbol and which segment it goes into.
Any ideas about (a) or (b) would be appreciated.
Thanks again,
Jean Christophe Beyler
On Wed, Mar 10, 2010 at 9:11 AM, Nick Clifton <nickc@redhat.com> wrote:
> Hi Jean Christophe,
>
>>> Just a thought - it might be easier in the linker to fill the large text
>>> and
>>> data sections first and then, as late as possible, extract portions of
>>> those
>>> sections to go into the smaller text and data sections.
>>
>> That could be a solution, any hints as to how to do that ?
>
> As a guess - how about putting the code in where the section garbage
> collection occurs ? ?(Search for "gc_section" in the bfd/ directory for lots
> of examples). ?Currently the garbage collection code is used to strip out
> unneeded sections, but maybe it will also prove to be a suitable place to
> move parts of sections around.
>
> Cheers
> ?Nick
>