<div dir="ltr">Actually, the problem is the *if* part. If you invoke the loader as the binary name, /proc/self/exe returns the path to the loader, not the path to clang.<div><br></div><div>E.g.:</div><div><br></div><div>$ /bin/ls -l /proc/self/exe</div><div><div>lrwxrwxrwx 1 jyknight eng 0 Dec 9 12:49 /proc/self/exe -> /bin/ls</div><div><br></div><div><div>$ /lib64/ld-linux-x86-64.so.2 /bin/ls -l /proc/self/exe</div><div>lrwxrwxrwx 1 jyknight eng 0 Dec 9 12:49 /proc/self/exe -> /lib/x86_64-linux-gnu/<a href="http://ld-2.19.so">ld-2.19.so</a></div></div></div><div><br></div><div>Further, even if it *DID* return the path to the clang binary, you'd still be in trouble, since the exec would then bypass your loader choice when invoking the subprocess.</div><div><br></div><div>I'd suggest running patchelf to change the interpreter embedded in the binary, if that's what you need to do, instead of running the loader manually.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 9, 2016 at 11:32 AM, Reid Kleckner via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Clang uses this logic in llvm/lib/Support/Unix/Path.inc to find itself (<a href="https://github.com/llvm-mirror/llvm/blob/84d1e9104a43f9940a76467d58156ade4b1c8d52/lib/Support/Unix/Path.inc#L170" target="_blank">https://github.com/llvm-<wbr>mirror/llvm/blob/<wbr>84d1e9104a43f9940a76467d58156a<wbr>de4b1c8d52/lib/Support/Unix/<wbr>Path.inc#L170</a>):</div><div class="gmail_quote"><br></div><div class="gmail_quote">...</div><div class="gmail_quote"><div class="gmail_quote">#elif defined(__linux__) || defined(__CYGWIN__)</div><div class="gmail_quote"> char exe_path[MAXPATHLEN];</div><div class="gmail_quote"> StringRef aPath("/proc/self/exe");</div><div class="gmail_quote"> if (sys::fs::exists(aPath)) {</div><div class="gmail_quote"> // /proc is not always mounted under Linux (chroot for example).</div><div class="gmail_quote"> ssize_t len = readlink(aPath.str().c_str(), exe_path, sizeof(exe_path));</div><div class="gmail_quote"> if (len >= 0)</div><div class="gmail_quote"> return std::string(exe_path, len);</div><div class="gmail_quote"> } else {</div><div class="gmail_quote"> // Fall back to the classical detection.</div><div class="gmail_quote"> if (getprogpath(exe_path, argv0))</div><div class="gmail_quote"> return exe_path;</div><div class="gmail_quote"> }</div><div class="gmail_quote">#elif defined(HAVE_DLFCN_H)</div><div>...</div><div><br></div><div>Presumably we are hitting the else, which would explain the bad behavior in the first example, where clang uses the musl loader for the -cc1 action. I don't know what went wrong in the chroot.</div><div><br></div><div>You can send patches to <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a> and file bugs at <a href="http://llvm.org/bugs" target="_blank">http://llvm.org/bugs</a>.</div><div><br></div><div>Thanks for looking into this!</div></div><div><div class="h5"><div class="gmail_quote"><br></div><div class="gmail_quote">On Fri, Dec 9, 2016 at 1:42 AM, Dmitry Golovin via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I have managed to compile llvm and clang against musl, but it behaves really strange:<br>
<br>
At first I tried to launch the compiler with musl dynamic loader:<br>
<br>
$ LD_LIBRARY_PATH=/path/to/musl/<wbr>lib /path/to/musl/lib/ld-musl-x86_<wbr>64.so.1 /path/to/llvm/bin/clang -v<br>
clang version 4.0.0 (<a href="https://github.com/llvm-mirror/clang" rel="noreferrer" target="_blank">https://github.com/llvm-mirro<wbr>r/clang</a> 40adebeca0f99006d407508653c2cb<wbr>d270a1a51c) (<a href="https://github.com/llvm-mirror/llvm" rel="noreferrer" target="_blank">https://github.com/llvm-mirro<wbr>r/llvm</a> 943496ffc4e7cb9d7dd6f5119325a7<wbr>583e2cc31f)<br>
Target: x86_64-pc-linux-musl<br>
Thread model: posix<br>
InstalledDir: /path/to/llvm/bin<br>
<br>
It worked, but couldn't compile binaries:<br>
<br>
$ LD_LIBRARY_PATH=/path/to/musl/<wbr>lib /path/to/musl/lib/ld-musl-x86_<wbr>64.so.1 /path/to/llvm/bin/clang -v -c hello.c<br>
clang version 4.0.0 (<a href="https://github.com/llvm-mirror/clang" rel="noreferrer" target="_blank">https://github.com/llvm-mirro<wbr>r/clang</a> 40adebeca0f99006d407508653c2cb<wbr>d270a1a51c) (<a href="https://github.com/llvm-mirror/llvm" rel="noreferrer" target="_blank">https://github.com/llvm-mirro<wbr>r/llvm</a> 943496ffc4e7cb9d7dd6f5119325a7<wbr>583e2cc31f)<br>
Target: x86_64-pc-linux-musl<br>
Thread model: posix<br>
InstalledDir: /path/to/llvm/bin<br>
"/path/to/musl/lib/ld-musl-x8<wbr>6_64.so.1" -cc1 -triple x86_64-pc-linux-musl -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /path/to/hello/hello.gcno -resource-dir /path/to/musl/lib/clang/4.0.0 -isysroot /path/to/musl -internal-isystem /path/to/musl/usr/local/includ<wbr>e -internal-isystem /path/to/musl/lib/clang/4.0.0/<wbr>include -internal-externc-isystem /path/to/musl/include -internal-externc-isystem /path/to/musl/usr/include -fdebug-compilation-dir /path/to/hello -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -o hello.o -x c hello.c<br>
/path/to/musl/lib/ld-musl-x86_<wbr>64.so.1: cannot load -cc1: No such file or directory<br>
<br>
As you can see it is trying to execute a compilation command with omitted clang binary path.<br>
<br>
So I thought that it would work in chroot with nothing but musl and clang in it. So I chrooted to a newly created directory, put musl and clang in it, and it still didn't work:<br>
<br>
(chroot)$ clang -v -I/include -c hello.c<br>
clang version 4.0.0 (<a href="https://github.com/llvm-mirror/clang" rel="noreferrer" target="_blank">https://github.com/llvm-mirro<wbr>r/clang</a> 40adebeca0f99006d407508653c2cb<wbr>d270a1a51c) (<a href="https://github.com/llvm-mirror/llvm" rel="noreferrer" target="_blank">https://github.com/llvm-mirro<wbr>r/llvm</a> 943496ffc4e7cb9d7dd6f5119325a7<wbr>583e2cc31f)<br>
Target: x86_64-pc-linux-musl<br>
Thread model: posix<br>
InstalledDir: /bin<br>
"" -cc1 -triple x86_64-pc-linux-musl -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -v -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /hello/hello.gcno -resource-dir ../lib/clang/4.0.0 -I /include -isysroot /path/to/musl -internal-isystem /path/to/musl/usr/local/includ<wbr>e -internal-isystem ../lib/clang/4.0.0/include -internal-externc-isystem /path/to/musl/include -internal-externc-isystem /path/to/musl/usr/include -fdebug-compilation-dir /hello -ferror-limit 19 -fmessage-length 139 -fobjc-runtime=gcc -fdiagnostics-show-option -o hello.o -x c hello.c<br>
error: unable to execute command: Executable "" doesn't exist!<br>
<br>
So it still doesn't launch clang as it should. But if I just copy and paste the produced line replacing `""` with `clang` it works and produces fine object file.<br>
<br>
What else can I try to make it work? Does clang have public bugzilla?<br>
<br>
Where can I send my musl support patches?<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>