summaryrefslogtreecommitdiffstats
path: root/lld/ELF/ScriptParser.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-09-06 18:14:08 +0000
committerRui Ueyama <ruiu@google.com>2017-09-06 18:14:08 +0000
commit0440be4a42e53e179b013f95bb805a7fe4296521 (patch)
tree60f3a56ba7daa98d42672cb5ca636d57227558cc /lld/ELF/ScriptParser.cpp
parentfd06b02558fe5678ce67996dd40ad616715697d9 (diff)
downloadbcm5719-llvm-0440be4a42e53e179b013f95bb805a7fe4296521.tar.gz
bcm5719-llvm-0440be4a42e53e179b013f95bb805a7fe4296521.zip
Detect linker script INCLUDE cycles.
Differential Revision: https://reviews.llvm.org/D37524 llvm-svn: 312656
Diffstat (limited to 'lld/ELF/ScriptParser.cpp')
-rw-r--r--lld/ELF/ScriptParser.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index 4939ca9c5b4..6d6af301a6d 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -24,6 +24,7 @@
#include "Target.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Support/Casting.h"
@@ -113,6 +114,9 @@ private:
// True if a script being read is in a subdirectory specified by -sysroot.
bool IsUnderSysroot;
+
+ // A set to detect an INCLUDE() cycle.
+ StringSet<> Seen;
};
} // namespace
@@ -318,6 +322,11 @@ void ScriptParser::readGroup() {
void ScriptParser::readInclude() {
StringRef Tok = unquote(next());
+ if (!Seen.insert(Tok).second) {
+ setError("there is a cycle in linker script INCLUDEs");
+ return;
+ }
+
// https://sourceware.org/binutils/docs/ld/File-Commands.html:
// The file will be searched for in the current directory, and in any
// directory specified with the -L option.
OpenPOWER on IntegriCloud