[PATCH] D38361: [ELF] Stop setting output section size early

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 01:08:58 PST 2017


> I don't like the idea of adding a member for the section position. At no
> point we need the position and the offset simultaneously and having both
> variables means they can get inconsistent.
>
> One way to look at the current issue is that the early estimate of the
> offset is correct in the common case, which makes it really easy to use
> it incorrectly before the final value is computed.
>
> If we make the value almost always wrong, that problem goes away. What
> do you think of the attached patch? We could rename OutSecOff to
> OutSecOffsetOrIndex, but that doesn't seem worth it.
>
>

A previous linker that I worked on tracked the state of some
properties of the link such as "All Sections Assigned An Offset", "All
Sections Given Final Address", functions would check properties that
they required as pre-conditions and would update the properties if
they invalidated them. I'm hesitant to propose that as a solution as
it requires quite a bit of discipline to check and update all the
state or introducing a lot of wrapper functions. Perhaps more
pre-condition comments using keywords might help.

> +  // Calculate the section offsets and size pre-compression. Doing this now
> +  // instead of delaying maybeCompress until after a run of assignAddresses
> +  // means that we don't support linker scripts adding data to compressed debug
> +  // sections. That is probably a reasonable restriction.
> +  Size = 0;
> +  for (BaseCommand *Cmd : SectionCommands)
> +    if (auto *ISD = dyn_cast<InputSectionDescription>(Cmd))
> +      for (InputSection *IS : ISD->Sections) {
> +        IS->OutSecOff = alignTo(Size, IS->Alignment);
> +        Size = IS->OutSecOff + IS->getSize();
> +      }
> +

I think that is a reasonable feature trade off. I'm wondering if it is
feasible to check and disable compression if a non input section
description command is detected in the debug section being compressed?

Peter


More information about the llvm-commits mailing list