File tree Expand file tree Collapse file tree 4 files changed +14
-9
lines changed Expand file tree Collapse file tree 4 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ using namespace llvm;
3636using namespace lld ;
3737using namespace lld ::elf;
3838
39- ScriptLexer::ScriptLexer (MemoryBufferRef mb) : curBuf(mb), mbs(1 , mb) {}
39+ ScriptLexer::ScriptLexer (MemoryBufferRef mb) : curBuf(mb), mbs(1 , mb) {
40+ activeFilenames.insert (mb.getBufferIdentifier ());
41+ }
4042
4143// Returns a whole line containing the current token.
4244StringRef ScriptLexer::getLine () {
@@ -81,6 +83,7 @@ void ScriptLexer::lex() {
8183 eof = true ;
8284 return ;
8385 }
86+ activeFilenames.erase (curBuf.filename );
8487 curBuf = buffers.pop_back_val ();
8588 continue ;
8689 }
Original file line number Diff line number Diff line change 1010#define LLD_ELF_SCRIPT_LEXER_H
1111
1212#include " lld/Common/LLVM.h"
13+ #include " llvm/ADT/DenseSet.h"
1314#include " llvm/ADT/SmallVector.h"
1415#include " llvm/ADT/StringRef.h"
1516#include " llvm/Support/MemoryBufferRef.h"
@@ -33,6 +34,9 @@ class ScriptLexer {
3334 Buffer curBuf;
3435 SmallVector<Buffer, 0 > buffers;
3536
37+ // Used to detect INCLUDE() cycles.
38+ llvm::DenseSet<StringRef> activeFilenames;
39+
3640 struct Token {
3741 StringRef str;
3842 explicit operator bool () const { return !str.empty (); }
Original file line number Diff line number Diff line change 2424#include " lld/Common/CommonLinkerContext.h"
2525#include " llvm/ADT/SmallString.h"
2626#include " llvm/ADT/StringRef.h"
27- #include " llvm/ADT/StringSet.h"
2827#include " llvm/ADT/StringSwitch.h"
2928#include " llvm/BinaryFormat/ELF.h"
3029#include " llvm/Support/Casting.h"
@@ -139,9 +138,6 @@ class ScriptParser final : ScriptLexer {
139138 // True if a script being read is in the --sysroot directory.
140139 bool isUnderSysroot = false ;
141140
142- // A set to detect an INCLUDE() cycle.
143- StringSet<> seen;
144-
145141 // If we are currently parsing a PROVIDE|PROVIDE_HIDDEN command,
146142 // then this member is set to the PROVIDE symbol name.
147143 std::optional<llvm::StringRef> activeProvideSym;
@@ -406,7 +402,7 @@ void ScriptParser::readGroup() {
406402
407403void ScriptParser::readInclude () {
408404 StringRef name = readName ();
409- if (!seen .insert (name).second ) {
405+ if (!activeFilenames .insert (name).second ) {
410406 setError (" there is a cycle in linker script INCLUDEs" );
411407 return ;
412408 }
Original file line number Diff line number Diff line change 66# ERR1: error: 1.lds:1: there is a cycle in linker script INCLUDEs
77
88# RUN: not ld.lld a.o -T 2a.lds 2>&1 | FileCheck %s --check-prefix=ERR2
9- # ERR2: error: 2a .lds:1: there is a cycle in linker script INCLUDEs
9+ # ERR2: error: 2b .lds:1: there is a cycle in linker script INCLUDEs
1010
11- # RUN: not ld.lld a.o -T 3.lds 2>&1 | FileCheck %s --check-prefix=ERR3
12- # ERR3: error: 3.lds:2: there is a cycle in linker script INCLUDEs
11+ # RUN: ld.lld a.o -T 3.lds -o 3
12+ # RUN: llvm-objdump -s 3 | FileCheck %s --check-prefix=CHECK3
13+ # CHECK3: Contents of section foo:
14+ # CHECK3-NEXT: 0000 2a2a **
1315
1416#--- 0.lds
1517BYTE(42 )
You can’t perform that action at this time.
0 commit comments