Clang can't load some llvm symbol (doesn't work at all)

Hello!
I can’t really tell when it happened so i can’t just rewind my packages.
I needed to compile some program from the internet and noticed that .cpp files always return an error. I tried to run

clang --help

It gives

clang: symbol lookup error: /lib64/libclang-cpp.so.17: undefined symbol: LLVMInitializeNVPTXAsmPrinter, version LLVM_17

(Same error when compiling)
So my clang doesn’t really function at all. It gives the same ^^^ error no matter what command i type.
I tried to run clang --help as root to see if it was an environment variable error or PATH error. It was not. Still the same error.
Here is my dnf history to avoid unnecessary questions (if possible)

I installed llvm/clang to try it out myself to confirm that our llvm/clang packages weren’t broken. I’m not seeing the error you’re getting. I also see you’ve fully updated (dnf history number 321), so I suppose that rules that out.

[root@cm02 tmp]# nm -gD /lib64/libclang-cpp.so.17 | grep LLVMInitializeNVPTXAsmPrinter
                 U LLVMInitializeNVPTXAsmPrinter@LLVM_17
[root@cm02 tmp]# cat /tmp/hello.c
#include <stdio.h>

int main(int argc, char **argv) {
        printf("Hello\n");
}
[root@cm02 tmp]# clang /tmp/hello.c
[root@cm02 tmp]# ./a.out
Hello
[root@cm02 tmp]# clang /tmp/hello.c -S -emit-llvm -o -
; ModuleID = '/tmp/hello.c'
source_filename = "/tmp/hello.c"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-redhat-linux-gnu"

@.str = private unnamed_addr constant [7 x i8] c"Hello\0A\00", align 1

; Function Attrs: noinline nounwind optnone uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4
  store ptr %1, ptr %4, align 8
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  ret i32 0
}

declare dso_local i32 @printf(ptr noundef, ...) #1

attributes #0 = { noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"uwtable", i32 2}
!2 = !{i32 7, !"frame-pointer", i32 2}
!3 = !{!"clang version 17.0.6 (RESF 17.0.6-5.el9)"}

Are you doing anything to /etc/ld.so.conf or modifying $LD_LIBRARY_PATH in any way?

Well, now that you mentioned LD_LIBRARY_PRELOAD i checked that and it was unset(!!!). If i run

export LD_LIBRARY_PATH=/usr/lib64

before clang --help everything works!

I’m investigating the source of this. Should LD_LIBRARY_PATH be set by default? One suspicious variable in my env is MODULES_RUN_QUARANTINE=LD_LIBRARY_PATH LD_PRELOAD

Thanks for help and for quick reply!

After some research i found that clang tries to open /opt/amdgpu/lib64/libLLVM-17.so

(base) [robos@localhost ~]$ strace /usr/bin/clang
execve("/usr/bin/clang", ["/usr/bin/clang"], 0x7ffcc7b4f090 /* 69 vars */) = 0
brk(NULL)                               = 0x197c000
arch_prctl(0x3001 /* ARCH_??? */, 0x7ffc105ec6d0) = -1 EINVAL (Invalid argument)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=84871, ...}) = 0
mmap(NULL, 84871, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa5bfc42000
close(3)                                = 0
openat(AT_FDCWD, "/lib64/libclang-cpp.so.17", 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\0\0\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=69576544, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa5bfc40000
mmap(NULL, 68801408, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fa5bba00000
mmap(0x7fa5bc19f000, 47874048, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x79f000) = 0x7fa5bc19f000
mmap(0x7fa5bef47000, 10309632, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3547000) = 0x7fa5bef47000
mmap(0x7fa5bf91c000, 2564096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3f1b000) = 0x7fa5bf91c000
mmap(0x7fa5bfb8e000, 62336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fa5bfb8e000
close(3)                                = 0
openat(AT_FDCWD, "/opt/amdgpu/lib64/libLLVM-17.so", O_RDONLY|O_CLOEXEC) = 3
...

which in turn is defined in /etc/ld.so.cache (no need to set LD_LIBRARY_PRELOAD any value)

(base) [robos@localhost ~]$ strings /etc/ld.so.cache | grep LLVM
/lib/libLLVM-17.so
/opt/amdgpu/lib64/libLLVM-17.so

That concludes my problem for the most part, but I’m still not sure how i was able to compile other programms (maybe they didn’t use clang). And also maybe there’s a way to proiritize /lib64/ instead of /opt/amdgpu/lib64/