Porting the linker

Jean Christophe Beyler jean.christophe.beyler@gmail.com
Mon May 17 21:03:00 GMT 2010

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

moveToBiggerSegment (char* segment_suffix)
        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],
                            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

More information about the Binutils mailing list