aboutsummaryrefslogtreecommitdiff
path: root/lld/ELF/ScriptParser.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-07-28 11:43:27 -0700
committerFangrui Song <i@maskray.me>2024-07-28 11:43:27 -0700
commita7e8bddfc1ce3e9ef86f104a34f72ece72c23ba7 (patch)
treeccfe221bfd5d510919ec3a065e5d5178048b4f47 /lld/ELF/ScriptParser.cpp
parent30fa01141390a8d60ab661f763a22329337bd97d (diff)
downloadllvm-a7e8bddfc1ce3e9ef86f104a34f72ece72c23ba7.zip
llvm-a7e8bddfc1ce3e9ef86f104a34f72ece72c23ba7.tar.gz
llvm-a7e8bddfc1ce3e9ef86f104a34f72ece72c23ba7.tar.bz2
[ELF] Respect --sysroot for INCLUDE
If an included script is under the sysroot directory, when it opens an absolute path file (`INPUT` or `GROUP`), add sysroot before the absolute path. When the included script ends, the `isUnderSysroot` state is restored.
Diffstat (limited to 'lld/ELF/ScriptParser.cpp')
-rw-r--r--lld/ELF/ScriptParser.cpp15
1 files changed, 1 insertions, 14 deletions
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index c033733..714e2905 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -48,16 +48,6 @@ namespace {
class ScriptParser final : ScriptLexer {
public:
ScriptParser(MemoryBufferRef mb) : ScriptLexer(mb) {
- // Initialize IsUnderSysroot
- if (config->sysroot == "")
- return;
- StringRef path = mb.getBufferIdentifier();
- for (; !path.empty(); path = sys::path::parent_path(path)) {
- if (!sys::fs::equivalent(config->sysroot, path))
- continue;
- isUnderSysroot = true;
- return;
- }
}
void readLinkerScript();
@@ -135,9 +125,6 @@ private:
std::pair<SmallVector<SymbolVersion, 0>, SmallVector<SymbolVersion, 0>>
readSymbols();
- // True if a script being read is in the --sysroot directory.
- bool isUnderSysroot = false;
-
// 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;
@@ -319,7 +306,7 @@ void ScriptParser::readNoCrossRefs(bool to) {
}
void ScriptParser::addFile(StringRef s) {
- if (isUnderSysroot && s.starts_with("/")) {
+ if (curBuf.isUnderSysroot && s.starts_with("/")) {
SmallString<128> pathData;
StringRef path = (config->sysroot + s).toStringRef(pathData);
if (sys::fs::exists(path))