<p dir="ltr">> On Thu, Jul 21, 2016 at 3:45 AM, Rui Ueyama <<a href="mailto:ruiu@google.com">ruiu@google.com</a>> wrote:<br>
>><br>
>> I don't think it would work because parsing linker scripts is not a difficult part.<br>
><br>
><br>
> Maybe it isn't, but why rewrite tested, documented code? (I don't know if you remember, but the documentation on the linker script parser that we had was really, really good).</p>
<p dir="ltr">I took a quick look at the previous linker script parser to refresh my memory and realized that it's written in a totally different way than the current linker script processor. It also contains features which we don't need. If you import it, you got to ditch the current linker script implementation and star over from large refactoring. It doesn't seem an option for us at all.</p>
<p dir="ltr">> Also, there are some some nasty parts like context-dependent lexing that you probably don't want to waste time rewriting (IIRC the existing code handled them correctly).<br>
>  <br>
>><br>
>> That parser was not plugged into an actual logic to handle complex linker script commands.<br>
><br>
><br>
> Exactly. It seems more effective to focus on that instead of frivolously rewriting the AST generation part which we already have a good implementation of.<br>
><br>
> -- Sean Silva<br>
>  <br>
>><br>
>><br>
>> On Thu, Jul 21, 2016 at 2:57 AM, Sean Silva <<a href="mailto:chisophugis@gmail.com">chisophugis@gmail.com</a>> wrote:<br>
>>><br>
>>><br>
>>><br>
>>> On Wed, Jul 20, 2016 at 2:06 PM, Rui Ueyama via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
>>>><br>
>>>> ruiu added inline comments.<br>
>>>><br>
>>>> ================<br>
>>>> Comment at: ELF/LinkerScript.h:49-59<br>
>>>> @@ -48,8 +48,13 @@<br>
>>>><br>
>>>> +struct OutputSectionDescription {<br>
>>>> +  std::vector<StringRef> Phdrs;<br>
>>>> +  std::vector<uint8_t> Filler;<br>
>>>> +};<br>
>>>> +<br>
>>>>  struct SectionsCommand {<br>
>>>>    SectionsCommandKind Kind;<br>
>>>>    std::vector<StringRef> Expr;<br>
>>>>    StringRef Name;<br>
>>>> -  std::vector<StringRef> Phdrs;<br>
>>>> +  OutputSectionDescription Section;<br>
>>>>  };<br>
>>>><br>
>>>> ----------------<br>
>>>> I think this is towards the right direction, but it doesn't still reflect the structure of SECTIONS linker script command.<br>
>>>><br>
>>>> As per the linker script manual (#1), SECTIONS command contains one of the following sub-commands:<br>
>>>><br>
>>>>  - an ENTRY command<br>
>>>>  - an overlay description<br>
>>>>  - a symbol assignment<br>
>>>>  - an output section description<br>
>>>><br>
>>>> Since we do not support the first two, I'll ignore them in this comment. So focus on the last two. We can represent the two like this.<br>
>>>><br>
>>>>   enum SectionsCommandKind { AssignmentKind, DescriptionKind  };<br>
>>>><br>
>>>>   struct SectionsCommand {<br>
>>>>     SectionsCommandKind Kind;<br>
>>>>     std::vector<StringRef> Expr;  // For AssignmentKind<br>
>>>>     OutputSectionDescription Desc; // For DescriptionKind<br>
>>>>   };<br>
>>>><br>
>>>> The above struct doesn't have `Name` field because SECTIONS doesn't have a name.<br>
>>>><br>
>>>> Name is instead in output section description as described in #2. To reflect that grammar, you want to define a class like this.<br>
>>>><br>
>>>>   struct OutputSectionDescription {<br>
>>>>     StringRef Name;<br>
>>>>     std::vector<OutputSectionCommand> Commands;<br>
>>>>     std::vector<uint8_t> Filler;<br>
>>>>   };<br>
>>>><br>
>>>> And then you want to define OutputSectionCommand to reflect output-section-command as described in #2.<br>
>>>><br>
>>>> So the point is to construct an AST whose structure logically matches with the grammar.<br>
>>><br>
>>><br>
>>> Why don't we just bring back Rafael Auler's parser that was deleted? It was quite complete IIRC.<br>
>>><br>
>>> -- Sean Silva<br>
>>>  <br>
>>>><br>
>>>><br>
>>>> #1<a href="https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS"> https://sourceware.org/binutils/docs/ld/SECTIONS.html#SECTIONS</a><br>
>>>> #2<a href="https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description"> https://sourceware.org/binutils/docs/ld/Output-Section-Description.html#Output-Section-Description</a><br>
>>>><br>
>>>><br>
>>>><a href="https://reviews.llvm.org/D22589"> https://reviews.llvm.org/D22589</a><br>
>>>><br>
>>>><br>
>>>><br>
>>>> _______________________________________________<br>
>>>> llvm-commits mailing list<br>
>>>><a href="mailto:llvm-commits@lists.llvm.org"> llvm-commits@lists.llvm.org</a><br>
>>>><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits"> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
>>><br>
>>><br>
>><br>
></p>