Skip to content

Commit d8adb0b

Browse files
committed
feat: include lld as an alternative to the gold and bfd linkers
1 parent 938e300 commit d8adb0b

6 files changed

Lines changed: 60 additions & 10 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ RUN wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /us
4040
&& jq -r 'to_entries | .[] | .key + "=" + .value' /tmp/apt-requirements-clang.json | xargs apt-get install -y --no-install-recommends \
4141
&& rm /tmp/apt-requirements* \
4242
&& rm -rf /var/lib/apt/lists/*
43+
ENV PATH="$PATH:/usr/lib/llvm-${CLANG_VERSION}/bin"
4344

4445
# Compile and install additional clang tools now that we have a clang toolchain
4546
# hadolint ignore=DL3008
@@ -83,11 +84,6 @@ RUN batstmp="$(mktemp -d /tmp/bats-core-${BATS_VERSION}.XXXX)" \
8384
RUN update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-${GCC_VERSION} 20 \
8485
&& update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-${GCC_VERSION} 20 \
8586
&& update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} 10 \
86-
&& update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${CLANG_VERSION} 10 \
87-
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang-cpp-${CLANG_VERSION} 10 \
88-
&& update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-${CLANG_VERSION} 10 \
89-
&& update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-${CLANG_VERSION} 10 \
90-
&& update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${CLANG_VERSION} 10 \
9187
&& update-alternatives --install /usr/bin/iwyu iwyu /usr/local/bin/include-what-you-use 10 \
9288
&& update-alternatives --install /usr/bin/mull-runner mull-runner /usr/local/bin/mull-runner-${CLANG_VERSION} 10 \
9389
&& update-alternatives --install /usr/lib/mull-ir-frontend mull-ir-frontend /usr/local/lib/mull-ir-frontend-${CLANG_VERSION} 10 \

.devcontainer/clang-15/apt-requirements.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"clang-tidy-15": "1:15.0.7~++20230112013400+948cadd6d424-1~exp1~20230112013414.108",
66
"clang-tools-15": "1:15.0.7~++20230112013400+948cadd6d424-1~exp1~20230112013414.108",
77
"libclang-rt-15-dev": "1:15.0.7~++20230112013400+948cadd6d424-1~exp1~20230112013414.108",
8+
"lld-15": "1:15.0.7~++20230112013400+948cadd6d424-1~exp1~20230112013414.108",
89
"llvm-15": "1:15.0.7~++20230112013400+948cadd6d424-1~exp1~20230112013414.108"
910
}

.github/workflows/update-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
2323
- name: Run update dependencies
2424
working-directory: .devcontainer
25-
run: ./update-dependencies.sh base gcc-10
25+
run: ./update-dependencies.sh base clang-15 gcc-10
2626
- uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04
2727
with:
2828
commit-message: "build(deps): update apt dependencies"

test/CMakePresets.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
"configurePreset": "gcc",
7777
"targets": ["test-gcc-fail"]
7878
},
79+
{
80+
"name": "gcc-lld",
81+
"configurePreset": "gcc",
82+
"targets": ["test-gcc-lld"]
83+
},
7984
{
8085
"name": "gcc-arm-none-eabi",
8186
"configurePreset": "gcc-arm-none-eabi",

test/gcc/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
add_executable(test-gcc EXCLUDE_FROM_ALL main.cpp)
22
add_executable(test-gcc-fail EXCLUDE_FROM_ALL main-fail.cpp)
3+
add_executable(test-gcc-lld EXCLUDE_FROM_ALL main.cpp)
4+
target_link_options(test-gcc-lld PRIVATE -fuse-ld=lld)

test/testsuite.bats

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ teardown() {
2929

3030
run cmake --build --preset gcc-arm-none-eabi
3131
assert_success
32+
33+
run readelf -h build/gcc-arm-none-eabi/gcc-arm-none-eabi/test-gcc-arm-none-eabi
34+
assert_output --partial "Type: EXEC"
35+
assert_output --partial "Machine: ARM"
3236
}
3337

3438
# bats test_tags=tc:4
@@ -41,16 +45,35 @@ teardown() {
4145
}
4246

4347
# bats test_tags=tc:5
44-
@test "ccache can be used as a compiler launcher" {
48+
@test "using ccache as a compiler launcher should result in cached build" {
49+
run ccache --clear --zero-stats
50+
51+
run cmake --preset gcc -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
52+
assert_success
53+
54+
run cmake --build --preset gcc
55+
assert_success
56+
57+
run ccache -s
58+
assert_output --partial "Hits: 0"
59+
assert_output --partial "Misses: 1"
60+
61+
run rm -rf build
62+
run ccache --zero-stats
63+
4564
run cmake --preset gcc -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
4665
assert_success
4766

4867
run cmake --build --preset gcc
4968
assert_success
69+
70+
run ccache -s
71+
assert_output --partial "Hits: 1"
72+
assert_output --partial "Misses: 0"
5073
}
5174

5275
# bats test_tags=tc:6
53-
@test "clang-tidy should be run as part of the build" {
76+
@test "running clang-tidy as part of the build should result in warning diagnostics" {
5477
run cmake --preset clang
5578
assert_success
5679

@@ -60,7 +83,7 @@ teardown() {
6083
}
6184

6285
# bats test_tags=tc:7
63-
@test "include-what-you-use should be run as part of the build" {
86+
@test "running include-what-you-use as part of the build should result in warning diagnostics" {
6487
run cmake --preset clang
6588
assert_success
6689

@@ -70,7 +93,7 @@ teardown() {
7093
}
7194

7295
# bats test_tags=tc:8
73-
@test "formatting tool included in image should format code" {
96+
@test "running clang-format should result in re-formatted code" {
7497
run clang-format clang-tools/unformatted.cpp
7598
assert_success
7699
assert_output "int main() {}"
@@ -129,3 +152,26 @@ teardown() {
129152
run arm-none-eabi-gdb --version
130153
assert_success
131154
}
155+
156+
# bats test_tags=tc14
157+
@test "clangd should be able check source files" {
158+
run clangd --check=gcc/main.cpp
159+
assert_success
160+
assert_output --partial "All checks completed, 0 errors"
161+
}
162+
163+
# bats test_tags=tc:15
164+
@test "using lld as an alternative linker should result in working host executable" {
165+
run cmake --preset gcc
166+
assert_success
167+
168+
run cmake --build --preset gcc-lld
169+
assert_success
170+
171+
run readelf --string-dump .comment build/gcc/gcc/test-gcc-lld
172+
assert_output --partial "Linker: Ubuntu LLD"
173+
174+
run build/gcc/gcc/test-gcc-lld
175+
assert_success
176+
assert_output "Hello World!"
177+
}

0 commit comments

Comments
 (0)