Symlink to llvm-config returns wrong results on Linux

It should be noted that a symlink to the built llvm-config will return
the paths for the system llvm instead of the built llvm; it's fine on
OS X though. Some differences in realpath?

The strace doesn't make any sense either.

$ strace llvm-config --src-root
execve("/home/artagnon/bin/llvm-config", ["llvm-config",
"--src-root"], [/* 40 vars */]) = 0
brk(0) = 0x19f7000
readlink("/proc/self/exe", "/home/artagnon/src/rhine/llvm/De"..., 4096) = 59
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f49000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/tls/x86_64/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/tls/x86_64",
0x7fff283fb470) = -1 ENOENT (No such file or directory)
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/tls/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/tls",
0x7fff283fb470) = -1 ENOENT (No such file or directory)
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/x86_64/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/x86_64",
0x7fff283fb470) = -1 ENOENT (No such file or directory)
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib",
{st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/usr/local/lib/tls/x86_64/libz.so.1", O_RDONLY|O_CLOEXEC) = -1
ENOENT (No such file or directory)
stat("/usr/local/lib/tls/x86_64", 0x7fff283fb470) = -1 ENOENT (No such
file or directory)
open("/usr/local/lib/tls/libz.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT
(No such file or directory)
stat("/usr/local/lib/tls", 0x7fff283fb470) = -1 ENOENT (No such file
or directory)
open("/usr/local/lib/x86_64/libz.so.1", O_RDONLY|O_CLOEXEC) = -1
ENOENT (No such file or directory)
stat("/usr/local/lib/x86_64", 0x7fff283fb470) = -1 ENOENT (No such
file or directory)
open("/usr/local/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No
such file or directory)
stat("/usr/local/lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
open("/home/artagnon/src/linux/tools/perf/tls/x86_64/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/linux/tools/perf/tls/x86_64", 0x7fff283fb470)
= -1 ENOENT (No such file or directory)
open("/home/artagnon/src/linux/tools/perf/tls/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/linux/tools/perf/tls", 0x7fff283fb470) = -1
ENOENT (No such file or directory)
open("/home/artagnon/src/linux/tools/perf/x86_64/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/linux/tools/perf/x86_64", 0x7fff283fb470) =
-1 ENOENT (No such file or directory)
open("/home/artagnon/src/linux/tools/perf/libz.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/home/artagnon/src/linux/tools/perf", 0x7fff283fb470) = -1
ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=34644, ...}) = 0
mmap(NULL, 34644, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7e48f40000
close(3) = 0
open("/usr/lib/libz.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000#\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=88592, ...}) = 0
mmap(NULL, 2183688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e48b17000
mprotect(0x7f7e48b2c000, 2093056, PROT_NONE) = 0
mmap(0x7f7e48d2b000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x14000) = 0x7f7e48d2b000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libpthread.so.0",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT
(No such file or directory)
open("/usr/lib/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300`\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=138242, ...}) = 0
mmap(NULL, 2208912, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e488fb000
mprotect(0x7f7e48912000, 2093056, PROT_NONE) = 0
mmap(0x7f7e48b11000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16000) = 0x7f7e48b11000
mmap(0x7f7e48b13000, 13456, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7e48b13000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libedit.so.0",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libedit.so.0", O_RDONLY|O_CLOEXEC) = -1 ENOENT
(No such file or directory)
open("/usr/lib/libedit.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0
\326\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=230080, ...}) = 0
mmap(NULL, 2340544, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e486bf000
mprotect(0x7f7e486f5000, 2093056, PROT_NONE) = 0
mmap(0x7f7e488f4000, 12288, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x35000) = 0x7f7e488f4000
mmap(0x7f7e488f7000, 14016, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7e488f7000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libncursesw.so.5",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libncursesw.so.5", O_RDONLY|O_CLOEXEC) = -1
ENOENT (No such file or directory)
open("/usr/lib/libncursesw.so.5", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0P\1\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=411648, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f3f000
mmap(NULL, 2508816, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e4845a000
mprotect(0x7f7e484b9000, 2097152, PROT_NONE) = 0
mmap(0x7f7e486b9000, 24576, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5f000) = 0x7f7e486b9000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libdl.so.2",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No
such file or directory)
open("/usr/lib/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\320\16\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=14648, ...}) = 0
mmap(NULL, 2109712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e48256000
mprotect(0x7f7e48259000, 2093056, PROT_NONE) = 0
mmap(0x7f7e48458000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f7e48458000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libstdc++.so.6",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT
(No such file or directory)
open("/usr/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\271\5\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1486871, ...}) = 0
mmap(NULL, 3204768, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e47f47000
mprotect(0x7f7e48037000, 2097152, PROT_NONE) = 0
mmap(0x7f7e48237000, 40960, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xf0000) = 0x7f7e48237000
mmap(0x7f7e48241000, 83616, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7e48241000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libm.so.6",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No
such file or directory)
open("/usr/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200U\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1067432, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f3e000
mmap(NULL, 3162456, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e47c42000
mprotect(0x7f7e47d45000, 2097152, PROT_NONE) = 0
mmap(0x7f7e47f45000, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x103000) = 0x7f7e47f45000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libgcc_s.so.1",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT
(No such file or directory)
open("/usr/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260*\0\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=544468, ...}) = 0
mmap(NULL, 2185952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e47a2c000
mprotect(0x7f7e47a42000, 2093056, PROT_NONE) = 0
mmap(0x7f7e47c41000, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7f7e47c41000
close(3) = 0
open("/home/artagnon/src/rhine/llvm/Debug+Asserts/bin/../lib/libc.so.6",
O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/local/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No
such file or directory)
open("/usr/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`\1\2\0\0\0\0\0"...,
832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1984416, ...}) = 0
mmap(NULL, 3813200, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3,
0) = 0x7f7e47689000
mprotect(0x7f7e47822000, 2097152, PROT_NONE) = 0
mmap(0x7f7e47a22000, 24576, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x199000) = 0x7f7e47a22000
mmap(0x7f7e47a28000, 16208, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7e47a28000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f3d000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f3c000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f3a000
arch_prctl(ARCH_SET_FS, 0x7f7e48f3a740) = 0
mprotect(0x7f7e47a22000, 16384, PROT_READ) = 0
mprotect(0x7f7e47f45000, 4096, PROT_READ) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0x7f7e48f39000
mprotect(0x7f7e48237000, 32768, PROT_READ) = 0
mprotect(0x7f7e48458000, 4096, PROT_READ) = 0
mprotect(0x7f7e486b9000, 16384, PROT_READ) = 0
mprotect(0x7f7e488f4000, 8192, PROT_READ) = 0
mprotect(0x7f7e48b11000, 4096, PROT_READ) = 0
mprotect(0x7f7e48d2b000, 4096, PROT_READ) = 0
mprotect(0x7f7e48f4e000, 4096, PROT_READ) = 0
munmap(0x7f7e48f40000, 34644) = 0
set_tid_address(0x7f7e48f3aa10) = 24365
set_robust_list(0x7f7e48f3aa20, 24) = 0
rt_sigaction(SIGRTMIN, {0x7f7e48900b90, [], SA_RESTORER|SA_SIGINFO,
0x7f7e4890b210}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0x7f7e48900c20, [],
SA_RESTORER|SA_RESTART|SA_SIGINFO, 0x7f7e4890b210}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
brk(0) = 0x19f7000
brk(0x1a18000) = 0x1a18000
access("/proc/self/exe", F_OK) = 0
readlink("/proc/self/exe", "/home/artagnon/src/rhine/llvm/De"..., 4096) = 59
stat("/home/artagnon/src/rhine/llvm/Debug+Asserts",
{st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/home/artagnon/src/rhine/llvm/Debug+Asserts",
{st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lseek(1, 0, SEEK_CUR) = 11998
fstat(1, {st_mode=S_IFREG|0644, st_size=12035, ...}) = 0
write(1, "/home/artagnon/src/rhine/llvm\n", 30/home/artagnon/src/rhine/llvm
) = 30
rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
close(1) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
exit_group(0) = ?
+++ exited with 0 +++
$ llvm-config --src-root
/build/llvm/src/llvm-3.5.0.src

Either I’m not seeing this or not sure what you mean, could you post an example set of commands that shows what you’re trying to highlight?

-eric

It seemed to be a very strange caching issue: on my VM, in two
sequential commands, one call to llvm-config would go to the
system-built one (when I tried it plain), and another would go to the
symlink in my PATH (when I tried it with strace). I can't reproduce it
anymore, and I still don't know what caused the Linux system to behave
so unpredictably.

Anyway, it's not an LLVM issue. Thanks for prodding me to post a conclusion.