forked from OSchip/llvm-project
[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. llvm-svn: 211772
This commit is contained in:
parent
7fb85256bc
commit
65e2464667
|
@ -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.
|
||||
|
|
|
@ -89,6 +89,17 @@ RUN: -L%p/Inputs %p/Inputs/use-shared.x86-64 \
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue