[PATCH] D29391: [ELF] - Postpone the evaluation of DefinedSynthetic value

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 2 12:17:27 PST 2017


grimar added inline comments.


================
Comment at: ELF/LinkerScript.cpp:388
+  // It can happen when non-absolute value is assigned before processing
+  // first section. Example: Sym = . + 0x1; .sec : { ... };
+  // In that case Sym contains offset depending on VA of the .sec, but VA value
----------------
ruiu wrote:
> grimar wrote:
> > ruiu wrote:
> > > I don't think I understand this comment. Why `Sym` value is affected by the following `.sec`?
> > > 
> > > I do understand that `Sym` is affected if it is `.sec : { ... }; Sym = .`, but this is `Sym = .; .sec { ... };`. Can a following expression affects the results of preceding expressions?
> > > 
> > > By the way, why ` + 0x1`?
> > >but this is Sym = .; .sec { ... };. Can a following expression affects the results of preceding expressions?
> > 
> > Yes. Please take a look on non-absolute.s:
> > 
> > ```
> > { A = . - 0x10; B = A + 0x1; . += 0x1000; }
> > ```
> > 
> > B is non-absolute expression, because depends on A which uses location counter for evaluation.
> > That way B is non absolute symbol and belongs to next section, which is .text in testcase.
> > 
> > That is a different behavior in compare with gold/bfd. As you can see in description BFD makes vvar_start to belong to .text,
> > but other symbols are ABS, gold makes all symbols as ABS. It was discussed with Rafael in D29332 thread that it looks as a bug of gnu linkers.
> > 
> > >By the way, why  + 0x1?
> > Just shows the common case. Some expression that has location counter and operation. I think it is pretty common case in scripts. I can replace with "Sym = .;" if you want, though my way probably a bit more readable and common to see.
> I think that doesn't answer my question. My question is how a following expression can affect a preceding expression. Your expression,
> 
>   A = . - 0x10; B = A + 0x1; . += 0x1000;
> 
> can be computed from left to right, so it doesn't seems to be a counter example.
It should not affect on final value and that what patch fixes.

Current non-absolute.s contains:

```
SECTIONS { A = . - 0x10; B = A + 0x1; }
# SYMBOL:        Name: B
# SYMBOL-NEXT:   Value: 0xFFFFFFFFFFFFFFF1
```

If you just do: "SECTIONS { A = . - 0x10; B = A + 0x1; . += 0x1234; }"
and run test, you'll see that value of B changed:

```
23>    Symbol {
23>      Name: B (1)
23>      Value: 0x1225
```

That is wrong and happens because B is DefinedSynthetic and it is relative to section VA.
Patch fixes the calculation of B.


https://reviews.llvm.org/D29391





More information about the llvm-commits mailing list