summaryrefslogtreecommitdiff
path: root/lld/ELF/ScriptLexer.cpp
AgeCommit message (Collapse)Author
2025-05-25[lld] Remove unused includes (NFC) (#141421)Kazu Hirata
2025-02-01[ELF] Replace inExpr with lexState. NFCFangrui Song
We may add another state State::Wild to behave more lik GNU ld.
2024-11-16[ELF] Remove unneeded Twine()Fangrui Song
2024-11-14[ELF] Migrate away from global ctxFangrui Song
2024-11-07[ELF] Replace errorCount with errCount(ctx)Fangrui Song
to reduce reliance on the global context.
2024-11-06[ELF] Replace error(...) with ErrAlways or ErrFangrui Song
Most are migrated to ErrAlways mechanically. In the future we should change most to Err.
2024-09-21[ELF] ScriptParser: pass Ctx to ScriptParser and ScriptLexer. NFCFangrui Song
2024-07-28[ELF] Respect --sysroot for INCLUDEFangrui Song
If an included script is under the sysroot directory, when it opens an absolute path file (`INPUT` or `GROUP`), add sysroot before the absolute path. When the included script ends, the `isUnderSysroot` state is restored.
2024-07-27[ELF] Fix INCLUDE cycle detectionFangrui Song
Fix #93947: the cycle detection mechanism added by https://reviews.llvm.org/D37524 also disallowed including a file twice, which is an unnecessary limitation. Now that we have an include stack #100493, supporting multiple inclusion is trivial. Note: a filename can be referenced with many different paths, e.g. a.lds, ./a.lds, ././a.lds. We don't attempt to detect the cycle in the earliest point.
2024-07-27[ELF] Track line number preciselyFangrui Song
`getLineNumber` is both imprecise (when `INCLUDE` is used) and inefficient (see https://reviews.llvm.org/D104137). Track line number precisely now that we have `struct Buffer` abstraction from #100493.
2024-07-26[ELF] Add till and rewrite while (... consume("}"))Fangrui Song
After #100493, the idiom `while (!errorCount() && !consume("}"))` could lead to inaccurate diagnostics or dead loops. Introduce till to change the code pattern.
2024-07-26[ELF] ScriptLexer: generate tokens lazilyFangrui Song
The current tokenize-whole-file approach has a few limitations. * Lack of state information: `maybeSplitExpr` is needed to parse expressions. It's infeasible to add new states to behave more like GNU ld. * `readInclude` may insert tokens in the middle, leading to a time complexity issue with N-nested `INCLUDE`. * line/column information for diagnostics are inaccurate, especially after an `INCLUDE`. * `getLineNumber` cannot be made more efficient without significant code complexity and memory consumption. https://reviews.llvm.org/D104137 The patch switches to a traditional lexer that generates tokens lazily. * `atEOF` behavior is modified: we need to call `peek` to determine EOF. * `peek` and `next` cannot call `setError` upon `atEOF`. * Since `consume` no longer reports an error upon `atEOF`, the idiom `while (!errorCount() && !consume(")"))` would cause a dead loop. Use `while (peek() != ")" && !atEOF()) { ... } expect(")")` instead. * An include stack is introduced to handle `readInclude`. This can be utilized to address #93947 properly. * `tokens` and `pos` are removed. * `commandString` is reimplemented. Since it is used in -Map output, `\n` needs to be replaced with space. Pull Request: https://github.com/llvm/llvm-project/pull/100493
2024-07-25[ELF] Remove obsoleted comment after #99567Fangrui Song
2024-07-23[ELF] Remove `consumeLabel` in ScriptLexer (#99567)Hongyu Chen
This commit removes `consumeLabel` since we can just use consume function to have the same functionalities.
2024-07-20 [ELF] Delete peek2 in Lexer (#99790)Hongyu Chen
Thanks to Fangrui's change https://github.com/llvm/llvm-project/commit/28045ceab08d41a8a42d93ebc445e8fe906f884c so peek2 can be removed.
2024-07-20[ELF] Simplify ScriptLexer::consume. NFCFangrui Song
2023-07-15[ELF] Support operator ^ and ^=Fangrui Song
GNU ld added ^ support in July 2023 and it looks like ^= is in plan as well. For now, we don't support `a^=0` (^= without a preceding space).
2023-06-05[lld] StringRef::{starts,ends}with => {starts,ends}_with. NFCFangrui Song
The latter form is now preferred to be similar to C++20 starts_with. This replacement also removes one function call when startswith is not inlined.
2022-06-25[ELF] Support -= *= /= <<= >>= &= |= in symbol assignmentsFangrui Song
2022-06-25[ELF] Allow ? without adjacent spaceFangrui Song
GNU ld allows 1 ? 2?3:4 : 5?6 :7
2022-02-07[ELF] Clean up headers. NFCFangrui Song
2021-06-22[ELF] Optimize ScriptLexer::getLineNumber by caching the previous line ↵Colin Cross
number and offset getLineNumber() was counting the number of line feeds from the start of the buffer to the current token. For large linker scripts this became a performance bottleneck. For one 4MB linker script over 4 minutes was spent in getLineNumber's StringRef::count. Store the line number from the last token, and only count the additional line feeds since the last token. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D104137
2020-07-24[LLD][ELF] - Linkerscript: report location for the "unclosed comment in a ↵Georgii Rymar
linker script" error. Currently we print "error: unclosed comment in a linker script", which doesn't provide information about the real error location. Fixes https://bugs.llvm.org/show_bug.cgi?id=46793. Differential revision: https://reviews.llvm.org/D84300
2020-06-05[ELF] Don't cause assertion failure if --dynamic-list or --version-script ↵Fangrui Song
takes an empty file Fixes PR46184 Report line 1 of the last memory buffer.
2020-05-15[ELF] Use namespace qualifiers (lld:: or elf::) instead of `namespace lld { ↵Fangrui Song
namespace elf {` Similar to D74882. This reverts much code from commit bd8cfe65f5fee4ad573adc2172359c9552e8cdc0 (D68323) and fixes some problems before D68323. Sorry for the churn but D68323 was a mistake. Namespace qualifiers avoid bugs where the definition does not match the declaration from the header. See https://llvm.org/docs/CodingStandards.html#use-namespace-qualifiers-to-implement-previously-declared-functions (D74515) Differential Revision: https://reviews.llvm.org/D79982
2020-04-02[lld] NFC: fix trivial typos in commentsKazuaki Ishizaki
Differential Revision: https://reviews.llvm.org/D72339
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-10-07[ELF] Wrap things in `namespace lld { namespace elf {`, NFCFangrui Song
This makes it clear `ELF/**/*.cpp` files define things in the `lld::elf` namespace and simplifies `elf::foo` to `foo`. Reviewed By: atanasyan, grimar, ruiu Differential Revision: https://reviews.llvm.org/D68323 llvm-svn: 373885
2019-07-10[Coding style change] Rename variables so that they start with a lowercase ↵Rui Ueyama
letter This patch is mechanically generated by clang-llvm-rename tool that I wrote using Clang Refactoring Engine just for creating this patch. You can see the source code of the tool at https://reviews.llvm.org/D64123. There's no manual post-processing; you can generate the same patch by re-running the tool against lld's code base. Here is the main discussion thread to change the LLVM coding style: https://lists.llvm.org/pipermail/llvm-dev/2019-February/130083.html In the discussion thread, I proposed we use lld as a testbed for variable naming scheme change, and this patch does that. I chose to rename variables so that they are in camelCase, just because that is a minimal change to make variables to start with a lowercase letter. Note to downstream patch maintainers: if you are maintaining a downstream lld repo, just rebasing ahead of this commit would cause massive merge conflicts because this patch essentially changes every line in the lld subdirectory. But there's a remedy. clang-llvm-rename tool is a batch tool, so you can rename variables in your downstream repo with the tool. Given that, here is how to rebase your repo to a commit after the mass renaming: 1. rebase to the commit just before the mass variable renaming, 2. apply the tool to your downstream repo to mass-rename variables locally, and 3. rebase again to the head. Most changes made by the tool should be identical for a downstream repo and for the head, so at the step 3, almost all changes should be merged and disappear. I'd expect that there would be some lines that you need to merge by hand, but that shouldn't be too many. Differential Revision: https://reviews.llvm.org/D64121 llvm-svn: 365595
2019-07-04[LLD][ELF] - Linkerscript: add a support for expressions for section's fillingGeorge Rimar
Imagine the script: .section: { ... } = FILL_EXPR LLD assumes that FILL_EXPR is a number, and does not allow it to be an expression. Though that is allowed by specification: https://sourceware.org/binutils/docs-2.32/ld/Output-Section-Fill.html This patch adds a support for cases when FILL_EXPR is simple math expression. Fixes https://bugs.llvm.org/show_bug.cgi?id=42482. Differential revision: https://reviews.llvm.org/D64130 llvm-svn: 365143
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-08-28[LLD][ELD] - Do not reject INFO output section type when used with a start ↵George Rimar
address. This is https://bugs.llvm.org/show_bug.cgi?id=38625 LLD accept this: ".stack (INFO) : {", but not this: ".stack address_expression (INFO) :" The patch fixes it. Differential revision: https://reviews.llvm.org/D51027 llvm-svn: 340804
2018-07-06[ELF] - Remove dead code #2.George Rimar
'Pos' is never can be 0 here. llvm-svn: 336436
2018-07-06[ELF] - Remove dead code. NFC.George Rimar
'Pos' can never be 0. llvm-svn: 336435
2018-07-03[ELF] - Add a comment. NFC.George Rimar
Minor follow up for r336197 "[ELF] - Add support for '||' and '&&' in linker scripts." llvm-svn: 336199
2018-07-03[ELF] - Add support for '||' and '&&' in linker scripts.George Rimar
This is https://bugs.llvm.org//show_bug.cgi?id=37976, we had no support, but seems someone faced it. llvm-svn: 336197
2017-12-26Simplify script lexer.Rui Ueyama
Differential Revision: https://reviews.llvm.org/D41577 llvm-svn: 321453
2017-10-25[lld] unified COFF and ELF error handling on new Common/ErrorHandlerBob Haarman
Summary: The COFF linker and the ELF linker have long had similar but separate Error.h and Error.cpp files to implement error handling. This change introduces new error handling code in Common/ErrorHandler.h, changes the COFF and ELF linkers to use it, and removes the old, separate implementations. Reviewers: ruiu Reviewed By: ruiu Subscribers: smeenai, jyknight, emaste, sdardis, nemanjai, nhaehnle, mgorny, javed.absar, kbarton, fedor.sergeev, llvm-commits Differential Revision: https://reviews.llvm.org/D39259 llvm-svn: 316624
2017-10-12[ELF] - Linkerscript: Add `~` as separate math token.George Rimar
Previously we did not support following: foo = ~0xFF; and had to add space before numeric value: foo = ~ 0xFF That was constistent with ld.bfd < 2.30, which shows: script.txt:3: undefined symbol `~2' referenced in expression, but inconsistent with gold. It was fixed for ld.bfd 2.30 as well: https://sourceware.org/bugzilla/show_bug.cgi?id=22267 Differential revision: https://reviews.llvm.org/D36508 llvm-svn: 315569
2017-10-11[ELF] - Fix out of sync comment. NFC.George Rimar
llvm-svn: 315442
2017-08-23[ELF] - Do not report multiple errors for single one in ScriptLexer::setError.George Rimar
Previously up to 3 errors were reported at once, with patch we always will report only one, just like in other linker code. Differential revision: https://reviews.llvm.org/D37015 llvm-svn: 311537
2017-08-10[ELF, LinkerScript] Support ! operator in linker script.Hafiz Abid Qadeer
Summary: This small patch adds the support for ! operator in linker scripts. Reviewers: ruiu, rafael Reviewed By: ruiu Subscribers: meadori, grimar, emaste, llvm-commits Differential Revision: https://reviews.llvm.org/D36451 llvm-svn: 310607
2017-08-04[ELF] - Remove ScriptLexer::Error field and check ErrorCount instead.George Rimar
D35945 introduces change when there is useless to check Error flag in few places, but ErrorCount must be checked instead. But then we probably can just check ErrorCount always. That should simplify things. Patch do that. Differential revision: https://reviews.llvm.org/D36266 llvm-svn: 310046
2017-03-09Handle ":" as a regular token character in linker scripts.Rui Ueyama
This is an alternative to https://reviews.llvm.org/D30500 to simplify the version definition parser and allow ":" in symbol names. Differential Revision: https://reviews.llvm.org/D30722 llvm-svn: 297402
2017-02-15Apply different tokenization rules to linker script expressions.Rui Ueyama
The linker script lexer is context-sensitive. In the regular context, arithmetic operator characters are regular characters, but in the expression context, they are independent tokens. This afects how the lexer tokenizes "3*4", for example. (This kind of expression is real; the Linux kernel uses it.) This patch defines function `maybeSplitExpr`. This function splits the current token into multiple expression tokens if the lexer is in the expression context. Differential Revision: https://reviews.llvm.org/D29963 llvm-svn: 295225
2017-02-14Add file comments for ScriptParser.cpp.Rui Ueyama
llvm-svn: 295023
2017-02-14Rename ScriptParser.{cpp,h} -> ScriptLexer.{cpp,h}.Rui Ueyama
These files contain a lexer, so the new names are better. The parser is in LinkerScript.{cpp,h}. llvm-svn: 295022