This is an archive of the discontinued LLVM Phabricator instance.

Fix handling of "{ global : local; local: *; };" in version scripts
ClosedPublic

Authored by dmikulin on Feb 6 2017, 1:38 PM.

Details

Summary

This patch is related to https://reviews.llvm.org/D29434, an attempt to fix bug 31813.
Currently the following case is not handled correctly:
{ global : local; local: *; };
Added look-ahead one more token to tell a variable named 'local' from a keyword 'local:'.

Diff Detail

Event Timeline

dmikulin created this revision.Feb 6 2017, 1:38 PM
davide requested changes to this revision.Feb 6 2017, 1:49 PM
davide added inline comments.
ELF/LinkerScript.cpp
1999–2001

This patch looks alright, but it substantially diverges from what we did here.
In particular, we look ahead 2 tokens instead of one.
This is Rui's parser, so if he has no problems with that, I'm fine with it.

ELF/ScriptParser.cpp
161

Ditto.

ELF/ScriptParser.h
31

why size_t and not unsigned ?

This revision now requires changes to proceed.Feb 6 2017, 1:49 PM
rafael edited edge metadata.Feb 6 2017, 1:56 PM

I think this is fine. We do have to improve the lexer, but it is not clear if we want the lexer to return a single token for "local :".

Rui, what do you think?

dmikulin marked 2 inline comments as done.Feb 6 2017, 1:57 PM
dmikulin added inline comments.
ELF/ScriptParser.h
31

Why indeed...

dmikulin marked 3 inline comments as done.Feb 6 2017, 1:58 PM
ruiu edited edge metadata.Feb 6 2017, 2:13 PM

It is unfortunate that we change the grammar to LL(2) by this patch, but that's not necessarily a bad thing. We need to redesign the lexer as we had discussed in the linking Linux kernel thread, but until then, we need to improve this lexer.

ELF/ScriptParser.cpp
161–167

Capitalize the variables.

I think it is more natural to use a for loop here.

for (size_t I = 0; I <= N; ++I) {
  Tok = next();
  if (Error)
    return "";
}
Pos = Pos - N - 1;

(Note that ++I is more C++-ish than I++.)

ELF/ScriptParser.h
31

n -> N

dmikulin updated this revision to Diff 87307.Feb 6 2017, 2:32 PM
dmikulin marked 2 inline comments as done.
dmikulin edited edge metadata.

Updated patch

davide accepted this revision.Feb 6 2017, 6:55 PM

LGTM now.

This revision is now accepted and ready to land.Feb 6 2017, 6:55 PM
dmikulin closed this revision.Feb 7 2017, 12:03 PM

Committed r294343.