summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/lib/Driver/GnuLdInputGraph.cpp12
-rw-r--r--lld/test/elf/group-cmd-search.test11
2 files changed, 16 insertions, 7 deletions
diff --git a/lld/lib/Driver/GnuLdInputGraph.cpp b/lld/lib/Driver/GnuLdInputGraph.cpp
index d463e5f79bc..f634c2eba58 100644
--- a/lld/lib/Driver/GnuLdInputGraph.cpp
+++ b/lld/lib/Driver/GnuLdInputGraph.cpp
@@ -70,15 +70,13 @@ std::error_code GNULdScript::parse(const LinkingContext &ctx,
}
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.
diff --git a/lld/test/elf/group-cmd-search.test b/lld/test/elf/group-cmd-search.test
index 8b959774335..01af279b683 100644
--- a/lld/test/elf/group-cmd-search.test
+++ b/lld/test/elf/group-cmd-search.test
@@ -90,6 +90,17 @@ RUN: %p/Inputs/group-cmd-search-2.ls -o %t6
*/
/*
+ 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.
OpenPOWER on IntegriCloud