This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Fix -Ttext and friends for ELF systems


Mark Mitchell <mark@codesourcery.com> writes:

> For a long time, -Ttext, -Tdata, and -Tbss have been useless (or
> broken, depending on how you look at it) on ELF systems.  Rather than
> setting the segment base address, these options set the address of a
> particular section.  That tended to result in the linker putting that
> section outside the relevant segment, without moving the rest of the
> contents of the segment, and then issuing none-too-helpful errors
> like:
> 
>   Not enough room for program headers (allocated 3, need 4)
> 
> This is a proto-patch that fixes this problem for ARM BPABI.  The key
> idea is that, rather than setting the section address directly, these
> options define symbols like "__text_segment_start".  Then, the linker
> script uses the value of these symbols to set the location counter at
> the start of particular segments.  The linker script also marks these
> symbols as local so that they do not actually show up in the generated
> executable or shared object.
> 
> What do people think of this approach?  My biggest concern so far is
> that I've probably broken these options on non-ELF systems due to the
> change in lexsup.c which no longer sets the section address.  I don't
> know how to check whether I'm on an ELF section at runtime in the
> linker.  I suppose that I could add a hook in the non-ELF *.em files;
> would that make the most sense?  (I'm not worried about breaking these
> options on ELF systems, since they are already broken.)

One problem with this approach is that if the linker script does not
cooperate by actually using __text_segment_start, this will be
ineffective.  The result will be that -Ttext silently fails for no
obvious reason (as opposed to the current situation, where it loudly
fails for no obvious reason, or (in cases where the linker script does
not use SIZEOF_HEADERS) quietly does something unexpected).

I do agree that the linker script has to cooperate.  Suppose that,
rather than the simple mechanism of setting a symbol, you use the more
complex mechanism of adding a new expression to the linker script:
SEGMENT_START(NAME, DEFAULT).  In your script, it might be used as
    TEXT_START_ADDR='SEGMENT_START ("text", ${TEXT_START_ADDR})'

SEGMENT_START would, of course, return the value of the -T{NAME}
option if defined, or DEFAULT otherwise.  When using -T{NAME}, it
marks it as having been used.

Then somewhere after parsing the whole script, you walk through the
list of all defined -T... options, and give a warning for each one
which was ignored by the linker script.

We should naturally leave the path open for defining more -T options;
the three usual ones were, of course, designed for a.out, and one
could imagine breaking out more aspects of an ELF file on an embedded
system.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]