[PATCH] D37524: Detect linker script INCLUDE cycles.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 11:15:33 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL312656: Detect linker script INCLUDE cycles. (authored by ruiu).
Changed prior to commit:
https://reviews.llvm.org/D37524?vs=114033&id=114035#toc
Repository:
rL LLVM
https://reviews.llvm.org/D37524
Files:
lld/trunk/ELF/ScriptParser.cpp
lld/trunk/test/ELF/linkerscript/include-cycle.s
Index: lld/trunk/ELF/ScriptParser.cpp
===================================================================
--- lld/trunk/ELF/ScriptParser.cpp
+++ lld/trunk/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 @@
// 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::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.
Index: lld/trunk/test/ELF/linkerscript/include-cycle.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/include-cycle.s
+++ lld/trunk/test/ELF/linkerscript/include-cycle.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+
+# RUN: echo INCLUDE %t1.script > %t1.script
+# RUN: not ld.lld %t.o %t1.script 2>&1 | FileCheck %s
+
+# RUN: echo INCLUDE %t2.script > %t1.script
+# RUN: echo INCLUDE %t1.script > %t2.script
+# RUN: not ld.lld %t.o %t1.script 2>&1 | FileCheck %s
+
+# CHECK: there is a cycle in linker script INCLUDEs
+
+.globl _start
+_start:
+ ret
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37524.114035.patch
Type: text/x-patch
Size: 1698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170906/688f8aa1/attachment.bin>
More information about the llvm-commits
mailing list