Bug 2267690

Summary: clang fails to link libc++ due to missing libunwind
Product: [Fedora] Fedora Reporter: Jesus Checa <jchecahi>
Component: libcxxAssignee: Nikita Popov <npopov>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: npopov, sergesanspaille, siddharth.kde, spotrh, tstellar, tuliom
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: libcxx-18.1.0~rc4-2.fc41 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-03-04 14:41:19 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jesus Checa 2024-03-04 13:24:58 UTC
Trying to link a binary against libc++ will result in a linker error due to missing libunwind:

```
# echo "int main(){return 0 ;}" | clang++ -x c++  --stdlib=libc++ -o test - 
/usr/bin/ld: cannot find -lunwind: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

However libunwind.so.1 is installed and resolved by ldd:
```
# ldd /usr/lib64/libc++.so.1
        linux-vdso64.so.1 (0x000003ffcdbfe000)
        libc++abi.so.1 => /lib64/libc++abi.so.1 (0x000003ffad280000)
        libunwind.so.1 => /lib64/libunwind.so.1 (0x000003ffad200000)
        libc.so.6 => /lib64/libc.so.6 (0x000003ffad000000)
        /lib/ld64.so.1 (0x000003ffad500000)
# rpm -qf /lib64/libunwind.so.1
llvm-libunwind-18.1.0~rc4-1.fc41.s390x
```

If installing `llvm-libunwind-devel` (not installed through deps of libcxx), and we pass the lib directory that it provides, the linkage succeeds:
```
# echo "int main(){return 0 ;}" | clang++ -L/usr/lib64/llvm-unwind -x c++  --stdlib=libc++ -o test - 
# rpm -qf /usr/lib64/llvm-unwind/libunwind.so 
llvm-libunwind-devel-18.1.0~rc4-1.fc41.s390x
```


Reproducible: Always

Steps to Reproduce:
1. dnf install clang libcxx-devel
2. echo "int main(){return 0 ;}" | clang++ -v -x c++  --stdlib=libc++ -o test -

Actual Results:  
/usr/bin/ld: cannot find -lunwind: No such file or directory
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Expected Results:  
Link successfully

Reproduced in x86_64 and s390x, not tested in aarch64 and ppc64le.
Installed packages:
# rpm -q clang libcxx llvm-libunwind
clang-18.1.0~rc4-2.fc41.s390x
libcxx-18.1.0~rc4-1.fc41.s390x
llvm-libunwind-18.1.0~rc4-1.fc41.s390x

Comment 1 Nikita Popov 2024-03-04 13:44:49 UTC
I believe that https://src.fedoraproject.org/rpms/libcxx/pull-request/49 should fix this.

Comment 2 Fedora Update System 2024-03-04 14:37:11 UTC
FEDORA-2024-afa3476463 (libcxx-18.1.0~rc4-2.fc41) has been submitted as an update to Fedora 41.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-afa3476463

Comment 3 Fedora Update System 2024-03-04 14:41:19 UTC
FEDORA-2024-afa3476463 (libcxx-18.1.0~rc4-2.fc41) has been pushed to the Fedora 41 stable repository.
If problem still persists, please make note of it in this bug report.