[PATCH] D23716: [ELF] Linkerscript: allow adding start/end symbols to arbitrary section

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 02:54:33 PDT 2016


evgeny777 added inline comments.

================
Comment at: ELF/LinkerScript.cpp:321
@@ +320,3 @@
+                        OutputSectionBase<ELFT> *Sec) {
+  bool Start = true, LastSymType = Start;
+  for (std::unique_ptr<BaseCommand> &Base : Cmd->Commands) {
----------------
ruiu wrote:
> evgeny777 wrote:
> > ruiu wrote:
> > > It seems unnecessarily complicated to me. Why don't you do something like this?
> > > 
> > >   // Add start symbols.
> > >   for (int I = 0, E = Cmd->Commands.size(); I < E; ++I) {
> > >     if (!isa<SymbolAssignment>(Cmd->Commands[I]))
> > >       break;
> > >     ....
> > >   }
> > > 
> > >   // Add end symbols.
> > >   for (int I = Cmd->Commands.size() - 1; I >= 0; --I) {
> > >     if (!isa<SymbolAssignment>(Cmd->Commands[I]))
> > >       break;
> > >     ....
> > >   }
> > > 
> > That's fine, but what about error diagnostics, you suggested to add last time?
> Well, maybe something like this?
> 
>    // Add start symbols.
>    int I = 0;
>    for (int E = Cmd->Commands.size(); I < E; ++I) {
>      if (!isa<SymbolAssignment>(Cmd->Commands[I]))
>        break;
>      ....
>    }
> 
>    // Add end symbols.
>    int J = Cmd->Commands.size() - 1;
>    for (; J >= 0; --J) {
>      if (!isa<SymbolAssignment>(Cmd->Commands[J]))
>        break;
>      ....
>    }
> 
>   // Warn on stray assignment expressions.
>   for (; I <= J; ++I)
>     if (auto *Foo = dyn_cast<SymbolAssignment>(Cmd->Commands[I])
>       ....
The problem in this implementation is that it add 'end' symbols in reverse order. The following one will not work:


```
.eh_frame_hdr : {
    foo = .;
    *(.eh_frame_hdr)
    bar1 = .;
    bar2 = bar1 + 1;
}
```


https://reviews.llvm.org/D23716





More information about the llvm-commits mailing list