Skip to content

Commit 6cd398a

Browse files
committed
ci: Install clang in version that matches LLVM version
LLVM bitcode is not backwards compatible and linking bitode objects produced by different LLVM versions, even when it does not always trigger any error in the backend, can lead to miscompilation (e.g. #318). Using clang 15 for a compile test was "working" out of luck, because the program was simple enough to not cause a miscompilation. But given that it's wrong, ensure that clang version matches LLVM version
1 parent b046f1b commit 6cd398a

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,28 @@ jobs:
9696
run: cargo install btfdump
9797

9898
- name: Install prerequisites
99-
# ubuntu-22.04 comes with clang 13-15[0]; support for signed and 64bit
100-
# enum values was added in clang 15[1] which isn't in `$PATH`.
101-
#
10299
# gcc-multilib provides at least <asm/types.h> which is referenced by libbpf.
103-
#
104-
# [0] https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
105-
#
106-
# [1] https://github.com/llvm/llvm-project/commit/dc1c43d
107100
run: |
108101
set -euxo pipefail
109102
sudo apt update
110103
sudo apt -y install gcc-multilib
111-
echo /usr/lib/llvm-15/bin >> $GITHUB_PATH
112104
113-
- name: Install LLVM
114-
if: matrix.llvm-from == 'apt'
105+
- name: Install clang
106+
# We use clang in compiletests to test linking of bitcode produced by
107+
# both C and Rust. The major version of clang must match the version of
108+
# LLVM that bpf-linker is using.
115109
run: |
116110
set -euxo pipefail
117111
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
118112
echo -e deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${{ matrix.llvm-version }} main | sudo tee /etc/apt/sources.list.d/llvm.list
119113
120114
sudo apt update
115+
sudo apt -y install clang-${{ matrix.llvm-version }}
116+
117+
- name: Install LLVM libraries and headers
118+
if: matrix.llvm-from == 'apt'
119+
run: |
120+
set -euxo pipefail
121121
# TODO(vadorovsky): Remove the requirement of libpolly.
122122
#
123123
# Packages from apt.llvm.org are being built all at once, with one

tests/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ where
8484
.arg("-o")
8585
.arg(dst.as_ref())
8686
.arg(src.as_ref())
87+
// `LD_LIBRARY_PATH` set to a custom LLVM build might mess up with
88+
// clang, if it's dynamically linked to libLLVM that was build with
89+
// larger configuration than the custom one, causing errors like:
90+
// ```
91+
// /usr/bin/clang-21: symbol lookup error: /usr/lib/llvm-21/bin/../lib/libclang-cpp.so.21.1:
92+
// undefined symbol: _ZTIN4llvm5MachO13RecordVisitorE, version
93+
// ```
94+
.env_remove("LD_LIBRARY_PATH")
8795
.output()
8896
.expect("failed to execute clang");
8997

0 commit comments

Comments
 (0)