[ELF] Fix INCLUDE cycle detection

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.
This commit is contained in:
Fangrui Song
2024-07-27 17:25:13 -07:00
parent aad2238f78
commit 8f72b0cb08
4 changed files with 14 additions and 9 deletions

View File

@@ -24,7 +24,6 @@
#include "lld/Common/CommonLinkerContext.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"
@@ -139,9 +138,6 @@ private:
// True if a script being read is in the --sysroot directory.
bool isUnderSysroot = false;
// A set to detect an INCLUDE() cycle.
StringSet<> seen;
// If we are currently parsing a PROVIDE|PROVIDE_HIDDEN command,
// then this member is set to the PROVIDE symbol name.
std::optional<llvm::StringRef> activeProvideSym;
@@ -406,7 +402,7 @@ void ScriptParser::readGroup() {
void ScriptParser::readInclude() {
StringRef name = readName();
if (!seen.insert(name).second) {
if (!activeFilenames.insert(name).second) {
setError("there is a cycle in linker script INCLUDEs");
return;
}