[PATCH] D74736: [ELF] Ignore the maximum of input section alignments for two cases

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 19 10:49:01 PST 2020


MaskRay marked an inline comment as done.
MaskRay added inline comments.


================
Comment at: lld/ELF/Writer.cpp:2219
+      return;
+    cmd->alignExpr = [align = cmd->alignment]() { return align; };
+    if (!cmd->addrExpr) {
----------------
psmith wrote:
> I'm struggling a bit with this one from the just the context. As far as I can tell there are only two uses of AlignExpr, in switchTo and in 
> `void LinkerScript::adjustSectionsBeforeSorting()`
> ````
>     // Handle align (e.g. ".foo : ALIGN(16) { ... }").
>     if (sec->alignExpr)
>       sec->alignment =
>           std::max<uint32_t>(sec->alignment, sec->alignExpr().getValue());
> ```
> In both cases I can't easily see why adding `cmd->alignExpr = [align = cmd->alignment]() { return align; };` would change the calculated alignment. For example `sec->alignment` should be the same as `alignExpr().getValue()` and in `switchTo`
> 
> ```
> uint32_t align =
>         sec->alignExpr ? sec->alignExpr().getValue() : ctx->outSec->alignment;
> ```
> When there isn't alignExpr isn't `ctx->outSec->alignment` the same as `alignExpr.getValue()`?
> 
> Can you let me know if I'm missing something?
fixSectionAlignments() sets addrExpr but not alignExpr.

In LinkerScript::switchTo, the following branch applies:

```lang=cpp
if (sec->addrExpr && !sec->alignExpr) {
    // The alignment is ignored.
    ctx->outSec->addr = pos;
}
```

i.e. `max_input_align` is not respected.

We need it to take the `else` branch, thus set `alignExpr` as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74736/new/

https://reviews.llvm.org/D74736





More information about the llvm-commits mailing list