This is an archive of the discontinued LLVM Phabricator instance.

Move Dot variable from LinkerScript to ScriptConfig.
AbandonedPublic

Authored by ruiu on Jul 24 2016, 6:09 PM.

Details

Reviewers
davide
grimar
Summary

The special variable "." is needed to evaluate expressions.
Currently we pass Dot variable to expressions as an argument.
But "." is actually not the only variable that needs to be passed
to expressions. SIZEOF_HEADERS is also need to be passed to
expressions in some way.

We could pass such variables as arguments. But if we do that way,
we'll end up having dozens of functions that takes many arguments.
Placing these varaibles in a shared place is probably a better way.

This patch moves Dot to ScriptConfig, so that it's accessible
both from LinkerScript and the expression evaluator.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 65284.Jul 24 2016, 6:09 PM
ruiu retitled this revision from to Move Dot variable from LinkerScript to ScriptConfig..
ruiu updated this object.
ruiu added reviewers: grimar, davide.
ruiu added a subscriber: llvm-commits.
grimar edited edge metadata.Jul 25 2016, 12:52 AM

I am not sure that this change reflects the script context properly.
I mean that documentation says: ". actually refers to the byte offset from the start of the current containing object. Normally this is the SECTIONS statement, whose start address is 0, hence . can be used as an absolute address. If . is used inside a section description however, it refers to the byte offset from the start of that section, not an absolute address. "
(https://sourceware.org/binutils/docs-2.23/ld/Location-Counter.html)

Currently we are using "." only in assignAddresses, so we use absolete address. But we also will need to support the second case. In this implementation looks like we will need to reset the location counter for each OutputSectionCommand in createSections():

for (const std::unique_ptr<BaseCommand> &Base : Opt.Commands) {
    auto *OutCmd = dyn_cast<OutputSectionCommand>(Base.get());
    if (!OutCmd)
      continue;

Opt.Dot = 0;
....

I am not sure how nice that will look. As Dot becoming not the configuration state, but just temporarily variable, moved to configuration class.

I think we do not want to pass other such things like SIZEOF_HEADERS as arguments, they always have the same meaning. But dot itself looks better as argument for me.

ruiu added a comment.Jul 25 2016, 9:53 AM

I don't think this patch changes the behavior at all. It just moves a variable from one class to another. So I don't think there's no concern on semantics.

In D22740#494857, @ruiu wrote:

I don't think this patch changes the behavior at all. It just moves a variable from one class to another. So I don't think there's no concern on semantics.

It does not change, and IMO does not help. It is just neutral.
What I meant that I just think we will probably want some different solution for Dot generally.
Since there is no big difference I am not against landing this if you feel it is better.

ELF/LinkerScript.h
27

I would really leave Expr type, that was nice and clear to have.

I am not sure how complex linker scripts expression will get, so it is hard to have an opinion on this.

In general when interpreting an expression, the interpretation is made in an Environment, which maps names to values. It would be another way of doing this, but tt is not clear if that generality is needed for linker scripts. Is Dot the only variable that can have different values in different contexts?

ELF/LinkerScript.h
27

Agreed.

davide edited edge metadata.Sep 22 2016, 2:43 PM

Rui, are you still pursuing this path?

ruiu added a comment.Sep 22 2016, 2:45 PM

It may not be a bad idea, but I'm not pursuing this at least at the moment. Will abandon.

ruiu abandoned this revision.Sep 22 2016, 2:45 PM