[lld] r211772 - [Driver] Improve the `isPathUnderSysroot()` function. Now it returns a
Simon Atanasyan
simon at atanasyan.com
Thu Jun 26 03:48:52 PDT 2014
Author: atanasyan
Date: Thu Jun 26 05:48:52 2014
New Revision: 211772
URL: http://llvm.org/viewvc/llvm-project?rev=211772&view=rev
Log:
[Driver] Improve the `isPathUnderSysroot()` function. Now it returns a
correct result even if checking paths: a) symlinks and/or b) contains relative
parts like /dir1/dir2/../dir2.
Modified:
lld/trunk/lib/Driver/GnuLdInputGraph.cpp
lld/trunk/test/elf/group-cmd-search.test
Modified: lld/trunk/lib/Driver/GnuLdInputGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdInputGraph.cpp?rev=211772&r1=211771&r2=211772&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdInputGraph.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdInputGraph.cpp Thu Jun 26 05:48:52 2014
@@ -70,15 +70,13 @@ std::error_code GNULdScript::parse(const
}
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.
Modified: lld/trunk/test/elf/group-cmd-search.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/group-cmd-search.test?rev=211772&r1=211771&r2=211772&view=diff
==============================================================================
--- lld/trunk/test/elf/group-cmd-search.test (original)
+++ lld/trunk/test/elf/group-cmd-search.test Thu Jun 26 05:48:52 2014
@@ -90,6 +90,17 @@ RUN: %p/Inputs/group-cmd-search-2.ls
*/
/*
+ 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.
More information about the llvm-commits
mailing list