This patch implements minimal support for symbol assignment. Only assignment within SECTIONS block is supported
Diff Detail
Event Timeline
ELF/LinkerScript.cpp | ||
---|---|---|
235 | Why don't you directly call SymbolTable::addAbsolute here? | |
511–514 | Hmm, so you are changing the grammar to LL(2). Do you really need to do that? I think you could do something like this to keep it LL(1). if (Tok == ".") { readLocationCounterValue(); continue; } next(); if (peek() == "=") readSymbolAssignment(Tok); else readOutputSectionDescription(Tok); | |
ELF/LinkerScript.h | ||
13–14 | Instead of including these headers, please declare the classes you need in this header. namespace lld { namespace elf { template <class ELFT> class SymbolTable; ... } } | |
84 | The symbol table is globally visible as Symtab<ELFT>::X, so you don't need to pass it around. |
ELF/LinkerScript.cpp | ||
---|---|---|
235 | I doubt this is possible. | |
511–514 | Makes sense. Although, strictly speaking, this doesn't make grammar LL(1) - you still have two lookahead tokens (one is saved in Tok) |
Review updated. Symbols.h header file is still required in LinkerScript.h for DefinedRegular<ELFT>
ELF/LinkerScript.cpp | ||
---|---|---|
235 | Can you replace this with Symtab<ELFT>::X->find(Cmd.Name)->Value = evalExpr(Cmd.Expr, Dot); so that we can remove SymIndex and Symbols from this class? This code is slightly slower because it looks up the symbol table, but it should be negligible because the number of symbols appear in symbol scripts is small. | |
511–514 | Well, I think technically it is LL(1) because it recognizes the language with one token look ahead. For semantic actions, we save a token, but it is different from recognizing a language, I think. | |
575 | I'd make this function return a std::vector<StringRef> and use that as Opt.Command = readSectionsCommandExpr(); It is slightly inefficient, but I believe it's easier to read. | |
ELF/LinkerScript.h | ||
21 | I think you can add template <class ELFT> class DefinedRegular; to remove #include "Symbols.h". | |
48 | It is very confusing to reuse SectionName field for symbol name because symbol name is not a section name. Maybe we should rename this Name. |
ELF/LinkerScript.cpp | ||
---|---|---|
237 | Do you need this assert? If there's a bug, it would crash with a null pointer dereference. | |
314 | You can remove {} | |
523–524 | This can be Opt.Commands.push_back({ExprKind, readSectionsCommandExpr(), ""}); | |
571 | This can be std::vector<StringRef> Exprs = readSectionsCommandExpr(); if (Exprs.empty()) error(...); Opt.Command.push_back({SymbolAssignmentKind, Exprs, Name}); | |
ELF/Writer.cpp | ||
788 | Add a blank line before this comment. | |
test/ELF/linkerscript-symbols.s | ||
13 | Remove this blank line at end of file. |
Instead of including these headers, please declare the classes you need in this header.