[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.
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user