llvm / llvm/llvm-project

Two stage bootstrap build fails to compile with `-DCLANG_DEFAULT_UNWINDLIB=libunwind`

Open
#174,141 0 comments 0 reactions 0 assignees View on GitHub
build-problem
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

## Summary

A Two Stage bootstrap build as described in [Advanced Build Configurations](https://llvm.org/docs/AdvancedBuilds.html) fails to compile
when the Stage1 compiler is built with `CLANG_DEFAULT_UNWINDLIB=libunwind`

## Expected behaviour

It should be possible to perform a bootstrap build where the resulting Stage2 compiler has no external dependencies on GNU `libgcc_s` or ` libstdc++`

## Actual behaviour

Build fails because intermediate executables built as part of stage2 are run but the correct `RUNPATH` is not set so that it can locate stage1 binaries:

```
stage2-bins/bin/llvm-min-tblgen: error while loading shared libraries: libunwind.so.1: cannot open shared object file: No such file or directory
```

```
readelf -d tools/clang/stage2-bins/bin/llvm-min-tblgen

Dynamic section at offset 0x13b9e0 contains 34 entries:
Tag Type Name/Value
0x000000000000001d (RUNPATH) Library runpath: [$ORIGIN/../lib]
...
0x0000000000000001 (NEEDED) Shared library: [libunwind.so.1]
```

`RUNPATH` should contain `$ORIGIN/../../../../lib/x86_64-unknown-linux-gnu` which is where the `libunwind.so` from stage1 is located.

## Steps to reproduce

Use the attached [CMakeUserPresets.json](https://github.com/user-attachments/files/24401291/CMakeUserPresets.json)

```
cp CMakeUserPresets.json llvm/
cd llvm
cmake --preset bootstrap
cmake --build build/bootstrap --target stage2
```

## Workaround

Define `LD_LIBRARY_PATH`
```
LD_LIBRARY_PATH=$(pwd)/build/bootstrap/lib/x86_64-unknown-linux-gnu/ cmake --build build/bootstrap/ --target stage2
```

## Related Issues

* #53561
* #54955

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.