[lld] r294006 - Handle numbers followed by ":" in linker scripts.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 16:21:08 PST 2017


On Fri, Feb 3, 2017 at 4:14 PM, Mikulin, Dmitry <dmitry.mikulin at sony.com>
wrote:

> The following patch fixes it, but yeah, we need to look ahead 2 tokens.
>

Hmm, that is not necessarily a bad thing, but the beauty of the current
parser is its simplicity, so adding arbitrary number of look-ahead is not
ideal.

The current parser has limitations as it was discussed in the thread about
linking the Linux kernel with LLD. Maybe it's time to rewrite the lexer to
fix all the issues once and for all?


>
> ===========================================================
> diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp
> index 34d6be2..f59323f 100644
> --- a/ELF/LinkerScript.cpp
> +++ b/ELF/LinkerScript.cpp
> @@ -1998,7 +1998,7 @@ std::vector<SymbolVersion>
> ScriptParser::readSymbols() {
>        continue;
>      }
>
> -    if (peek() == "}" || peek() == "local" || Error)
> +    if (peek() == "}" || (peek() == "local" && peek(1) == ":") || Error)
>        break;
>      StringRef Tok = next();
>      Ret.push_back({unquote(Tok), false, hasWildcard(Tok)});
> diff --git a/ELF/ScriptParser.cpp b/ELF/ScriptParser.cpp
> index 79f3cd3..9617860 100644
> --- a/ELF/ScriptParser.cpp
> +++ b/ELF/ScriptParser.cpp
> @@ -156,11 +156,15 @@ StringRef ScriptParserBase::next() {
>    return Tokens[Pos++];
>  }
>
> -StringRef ScriptParserBase::peek() {
> -  StringRef Tok = next();
> -  if (Error)
> -    return "";
> -  --Pos;
> +StringRef ScriptParserBase::peek(size_t n) {
> +  StringRef Tok;
> +  size_t i = 0;
> +  while (i++ <= n) {
> +    Tok = next();
> +    if (Error)
> +      return "";
> +  }
> +  Pos -= (n + 1);
>    return Tok;
>  }
>
> diff --git a/ELF/ScriptParser.h b/ELF/ScriptParser.h
> index 264c497..944cc67 100644
> --- a/ELF/ScriptParser.h
> +++ b/ELF/ScriptParser.h
> @@ -28,7 +28,7 @@ public:
>    static StringRef skipSpace(StringRef S);
>    bool atEOF();
>    StringRef next();
> -  StringRef peek();
> +  StringRef peek(size_t n = 0);
>    void skip();
>    bool consume(StringRef Tok);
>    void expect(StringRef Expect);
> ===========================================================
>
>
> On Feb 3, 2017, at 1:21 PM, Rui Ueyama <ruiu at google.com> wrote:
>
> On Fri, Feb 3, 2017 at 1:19 PM, Mikulin, Dmitry via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>>
>> > On Feb 3, 2017, at 10:30 AM, Rafael Avila de Espindola <
>> rafael.espindola at gmail.com> wrote:
>> >
>> > Peter Collingbourne <peter at pcc.me.uk> writes:
>> >
>> >> Does this accept "{ global: local; }”?
>>
>> Meaning ‘a global named “local”’? Yeah, that’s a problem. We need a test
>> case for this.
>> I’ll fix it.
>>
>
> Does that require to change the grammar from LL(1) to LL(2)? I think the
> current parser is LL(1).
>
>
>> Dmitry.
>>
>>
>> >>
>> >
>> > No, it fails.
>> >
>> > Dimitry, can you take a look?
>> >
>> > Cheers,
>> > Rafael
>> >
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170203/20f8bf43/attachment.html>


More information about the llvm-commits mailing list