File tree 4 files changed +14
-9
lines changed
4 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,9 @@ using namespace llvm;
36
36
using namespace lld ;
37
37
using namespace lld ::elf;
38
38
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
+ }
40
42
41
43
// Returns a whole line containing the current token.
42
44
StringRef ScriptLexer::getLine () {
@@ -81,6 +83,7 @@ void ScriptLexer::lex() {
81
83
eof = true ;
82
84
return ;
83
85
}
86
+ activeFilenames.erase (curBuf.filename );
84
87
curBuf = buffers.pop_back_val ();
85
88
continue ;
86
89
}
Original file line number Diff line number Diff line change 10
10
#define LLD_ELF_SCRIPT_LEXER_H
11
11
12
12
#include " lld/Common/LLVM.h"
13
+ #include " llvm/ADT/DenseSet.h"
13
14
#include " llvm/ADT/SmallVector.h"
14
15
#include " llvm/ADT/StringRef.h"
15
16
#include " llvm/Support/MemoryBufferRef.h"
@@ -33,6 +34,9 @@ class ScriptLexer {
33
34
Buffer curBuf;
34
35
SmallVector<Buffer, 0 > buffers;
35
36
37
+ // Used to detect INCLUDE() cycles.
38
+ llvm::DenseSet<StringRef> activeFilenames;
39
+
36
40
struct Token {
37
41
StringRef str;
38
42
explicit operator bool () const { return !str.empty (); }
Original file line number Diff line number Diff line change 24
24
#include " lld/Common/CommonLinkerContext.h"
25
25
#include " llvm/ADT/SmallString.h"
26
26
#include " llvm/ADT/StringRef.h"
27
- #include " llvm/ADT/StringSet.h"
28
27
#include " llvm/ADT/StringSwitch.h"
29
28
#include " llvm/BinaryFormat/ELF.h"
30
29
#include " llvm/Support/Casting.h"
@@ -139,9 +138,6 @@ class ScriptParser final : ScriptLexer {
139
138
// True if a script being read is in the --sysroot directory.
140
139
bool isUnderSysroot = false ;
141
140
142
- // A set to detect an INCLUDE() cycle.
143
- StringSet<> seen;
144
-
145
141
// If we are currently parsing a PROVIDE|PROVIDE_HIDDEN command,
146
142
// then this member is set to the PROVIDE symbol name.
147
143
std::optional<llvm::StringRef> activeProvideSym;
@@ -406,7 +402,7 @@ void ScriptParser::readGroup() {
406
402
407
403
void ScriptParser::readInclude () {
408
404
StringRef name = readName ();
409
- if (!seen .insert (name).second ) {
405
+ if (!activeFilenames .insert (name).second ) {
410
406
setError (" there is a cycle in linker script INCLUDEs" );
411
407
return ;
412
408
}
Original file line number Diff line number Diff line change 6
6
# ERR1: error: 1.lds:1: there is a cycle in linker script INCLUDEs
7
7
8
8
# 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
10
10
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 **
13
15
14
16
#--- 0.lds
15
17
BYTE(42 )
You can’t perform that action at this time.
0 commit comments