}
static bool isPathUnderSysroot(StringRef sysroot, StringRef path) {
- // TODO: Handle the case when 'sysroot' and/or 'path' are symlinks.
- if (sysroot.empty() || sysroot.size() >= path.size())
- return false;
- if (llvm::sys::path::is_separator(sysroot.back()))
- sysroot = sysroot.substr(0, sysroot.size() - 1);
- if (!llvm::sys::path::is_separator(path[sysroot.size()]))
+ if (sysroot.empty())
return false;
- return llvm::sys::fs::equivalent(sysroot, path.substr(0, sysroot.size()));
+ while (!path.empty() && !llvm::sys::fs::equivalent(sysroot, path))
+ path = llvm::sys::path::parent_path(path);
+
+ return !path.empty();
}
/// \brief Handle GnuLD script for ELF.
*/
/*
+ This link should finish successfully. The group-cmd-search-2.ls
+ script contains GROUP command with an absolute path and the sysroot
+ directory is provided. The linker has to search the absolute path
+ under the sysroot directory.
+
+RUN: lld -flavor gnu -target x86_64 -shared --sysroot=%p/Inputs/../Inputs \
+RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \
+RUN: %p/Inputs/group-cmd-search-2.ls -o %t6
+*/
+
+/*
This link should fail with unknown input file format error.
The linker script from this file contains GROUP with an absolute
path which can be found under provided sysroot directory.