Skip to content

"--sysroot /" mess up overlaid VFS #28283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
llvmbot opened this issue May 27, 2016 · 6 comments
Closed

"--sysroot /" mess up overlaid VFS #28283

llvmbot opened this issue May 27, 2016 · 6 comments
Labels
bugzilla Issues migrated from bugzilla clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'

Comments

@llvmbot
Copy link
Member

llvmbot commented May 27, 2016

Bugzilla Link 27909
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @benlangmuir,@bcardosolopes,@zygoloid

Extended Description

Virtual file system cannot find overlaid file if "--sysroot /" is specified.

Way to reproduce:
$ cat overlay.yml
{
"version": 0,
"use-external-names": false,
"roots": [
{
"type": "file",
"name": "/usr/include/stdio_vfs.h",
"external-contents": "/usr/include/stdio.h"
}
]
}
$ cat foo.c
#include <stdio_vfs.h>
int main() {
printf("foo");
}
$ clang -ivfsoverlay overlay.yml foo.c # NO PROBLEM
$ clang --sysroot / -ivfsoverlay overlay.yml foo.c
foo.c:1:10: fatal error: 'stdio_vfs.h' file not found
#include <stdio_vfs.h>
^
1 error generated.
$

@bcardosolopes
Copy link
Member

Thanks for reporting this! Which version of LLVM did you use?

Did you tests this on ToT? There were lots of VFS changes in the past month and I wonder whether they fix this.

Thanks,

@llvmbot
Copy link
Member Author

llvmbot commented May 28, 2016

I tested with

Ubuntu 15.10 clang
Ubuntu clang version 3.6.2-1 (tags/RELEASE_362/final) (based on LLVM 3.6.2)

and

https://github.com/apple/swift-llvm stable branch
https://github.com/apple/swift-clang stable branch
build.

I will try official trunk/trunk from now.

@llvmbot
Copy link
Member Author

llvmbot commented May 28, 2016

Reproduced with trunk

$ ~/Documents/repos/build/bin/clang -v --sysroot / -ivfsoverlay overlay.yml foo.c
clang version 3.9.0 (trunk 271088) (llvm/trunk 271087)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/rintaro/Documents/repos/build/bin
Found candidate GCC installation: //usr/lib/gcc/i686-linux-gnu/5.2.1
Found candidate GCC installation: //usr/lib/gcc/x86_64-linux-gnu/5.2.1
Selected GCC installation: //usr/lib/gcc/x86_64-linux-gnu/5.2.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@MX32
Selected multilib: .;@m64
"/home/rintaro/Documents/repos/build/bin/clang-3.9" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name foo.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -resource-dir /home/rintaro/Documents/repos/build/bin/../lib/clang/3.9.0 -ivfsoverlay overlay.yml -isysroot / -internal-isystem //usr/local/include -internal-isystem /home/rintaro/Documents/repos/build/bin/../lib/clang/3.9.0/include -internal-externc-isystem //usr/include/x86_64-linux-gnu -internal-externc-isystem //include -internal-externc-isystem //usr/include -fdebug-compilation-dir /home/rintaro -ferror-limit 19 -fmessage-length 191 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/foo-1cae04.o -x c foo.c
clang -cc1 version 3.9.0 based upon LLVM 3.9.0svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "//include"
#include "..." search starts here:
#include <...> search starts here:
//usr/local/include
/home/rintaro/Documents/repos/build/bin/../lib/clang/3.9.0/include
//usr/include/x86_64-linux-gnu
//usr/include
End of search list.
foo.c:1:10: fatal error: 'stdio_vfs.h' file not found
#include <stdio_vfs.h>
^
1 error generated.

@llvmbot
Copy link
Member Author

llvmbot commented May 30, 2016

This is because:
llvm::sys::path splits "//usr/include/vfs_stdio.h" as:
{ "//usr", "/", "include", "vfs_stdio.h" }
It doesn't match the path components in the YAML:
{ "/", "usr", "include", "vfs_stdio.h" }

Now, I'm not sure which we should fix, Driver or RedirectingFileSystem.

The really quick fix would be:

===================================================================
--- lib/Driver/Driver.cpp (revision 271112)
+++ lib/Driver/Driver.cpp (working copy)
@@ -490,6 +490,9 @@
}
if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
SysRoot = A->getValue();

  • // If specified value is just a root directory, set empty SysRoot.
  • if (llvm::sys::path::relative_path(SysRoot).empty())
  •  SysRoot = llvm::sys::path::root_name(SysRoot);
    
    if (const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))
    DyldPrefix = A->getValue();
    if (Args.hasArg(options::OPT_nostdlib))

But maybe, we should replace every SysRoot + ... in lib/Driver/Toolchain.cpp
with llvm::sys::path::append or such.

@benlangmuir
Copy link
Collaborator

We may want to explicitly teach the VFS that if it gets a root that is a net name (like //foo) and it doesn't find it, it should try treating it as "/foo".

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
egorzhdan added a commit to swiftlang/llvm-project that referenced this issue May 27, 2022
Currently if `--sysroot /` is passed to the Clang driver, the include paths generated by the Clang driver will start with a double slash: `//usr/include/...`.
 If VFS is used to inject files into the include paths (for example, the Swift compiler does this), VFS will get confused and the injected files won't be visible.

This change makes sure that the include paths start with a single slash.

Fixes llvm#28283.

Differential Revision: https://reviews.llvm.org/D126289
egorzhdan added a commit to swiftlang/llvm-project that referenced this issue May 27, 2022
Currently if `--sysroot /` is passed to the Clang driver, the include paths generated by the Clang driver will start with a double slash: `//usr/include/...`.
 If VFS is used to inject files into the include paths (for example, the Swift compiler does this), VFS will get confused and the injected files won't be visible.

This change makes sure that the include paths start with a single slash.

Fixes llvm#28283.

Differential Revision: https://reviews.llvm.org/D126289
@EugeneZelenko EugeneZelenko added clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' and removed clang:frontend Language frontend issues, e.g. anything involving "Sema" labels May 27, 2022
@llvmbot
Copy link
Member Author

llvmbot commented May 27, 2022

@llvm/issue-subscribers-clang-driver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl'
Projects
None yet
Development

No branches or pull requests

4 participants