This is the mail archive of the binutils@sourceware.org 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: RFH: Assignments folded too early


On Wed, Apr 07, 2010 at 06:14:23PM -0400, Hans-Peter Nilsson wrote:
> Yes, and I also see that it isn't "defined *before* the
> statement using DEFINED in the script" any more (my emphasis),
> but it seems you read those words differently from how I do?

IMO the symbol is already defined before this point, even though its
input section is assigned later; it was defined by the input object
file.  A symbol defined further down in the linker script, on
the other hand, would not be defined yet:

SECTIONS {
  .text : {
    begin = DEFINED(later) ? begin : later; /* Lose.  */
    later = .;
  }
}

We could argue about the semantics of this, but I was also using this
as shorthand for another potential problem.  Suppose we have the
layout:

SECTIONS {
  .text : {
    *(.text)
    *(.text1)
    begin = DEFINED(begin) ? begin : fallback;
  }
}

Now suppose the linker needs to insert a long branch or mode change
stub between .text and .text1.  We'll go back through section sizing,
change all the output_offsets... but begin is now defined in terms of
the .text *output* section.  It's harder to produce, but as dangerous.

On Wed, Apr 07, 2010 at 06:30:51PM -0400, Hans-Peter Nilsson wrote:
> On Wed, 7 Apr 2010, Daniel Jacobowitz wrote:
> > Interestingly, scan_for_self_assignment checks for this case and
> > changes how it is printed in map files to avoid the problem... but
> > that's the only effect it has!  That can't be right.
> 
> Eeek!  Really?  I thought we had test-cases for this?
> 
> Looking... certainly, in ld-scripts/
> Nothing there matching your situation?

No, don't think so.  The only self assignments are in defined3.t
[defined1 is not defined yet]:

defined1 = DEFINED (defined1) ? defined1 + 1 : 512;

and in default-script.t.  Given what I've found debugging ld today,
I'm not surprised that a simple modification of this test blows up:

.globl defined1
defined1 = 0x400

SECTIONS {
        .text : { *(.text) sym2 = .; }
        .data : { *(.data) }
        .bss : { *(.bss) *(COMMON) }
	defined1 = DEFINED (defined1) ? defined1 + 1 : 512;
}

Produces not the 0x401 you might expect, but 0x405.

I don't have a good solution on how to handle this case.  IMO it's a
pretty useful thing to do...

-- 
Daniel Jacobowitz
CodeSourcery


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