Skip to content

Commit 78dc3bd

Browse files
committed
infra: use LLD for all configurations
This makes it consistent to use LLD across all configurations. It also moves away from using gold linker, which has recently been deprecated. On top of that LLD is faster and has better compatibility with LLVM toolchain that is already used for building. This commit also fixes warnings that can sometimes occur with BFD linker that doesn't fully support DWARF 5, at least the version on the builder: DWARF: invalid or unhandled FORM value: 0x22 Some projects already replaced linker in their build scripts for this reason.
1 parent bb95bc3 commit 78dc3bd

File tree

13 files changed

+38
-60
lines changed

13 files changed

+38
-60
lines changed

docs/advanced-topics/fuzz_introspector.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,16 @@ There are some differences in build environment for Fuzz Introspector builds
101101
in comparison to e.g. ASAN or code coverage builds. The reason is that
102102
Fuzz Introspector relies on certain compile-time tools to do its analysis.
103103
This compile time tooling differs between languages, namely:
104-
- For C/C++, Fuzz Introspector relies on [LLVM LTO](https://llvm.org/docs/LinkTimeOptimization.html) and [LLVM Gold](https://llvm.org/docs/GoldPlugin.html)
104+
- For C/C++, Fuzz Introspector relies on [LLVM LTO](https://llvm.org/docs/LinkTimeOptimization.html)
105105
- For Python, Fuzz Introspector relies on a modified [PyCG](https://github.com/vitsalis/PyCG)
106106
- For Java, Fuzz Introspector relies on [Soot](https://soot-oss.github.io/soot/)
107107

108108
The consequence of this is your project must be compatible with these projects.
109109
PyCG and Soot have not shown to be a blocker for many projects, however, experience
110110
has shown that sometimes a project's build needs modification in order to compile
111111
with LLVM LTO. The easiest way to test if your project works with LLVM is checking
112-
whether your project can compile with the flags `-flto -fuse-ld=gold` and using
113-
the gold linker. OSS-Fuzz automatically sets these flags and linker options when
112+
whether your project can compile with the flags `-flto -fuse-ld=lld` and using
113+
the LLD linker. OSS-Fuzz automatically sets these flags and linker options when
114114
using `infra/helper.py` to build your project with `--sanitizer=introspector`, e.g.
115115

116116
```bash

infra/base-images/base-builder/Dockerfile

+13-12
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,25 @@ ENV BAZELISK_VERSION 1.9.0
6868
RUN curl -L https://github.com/bazelbuild/bazelisk/releases/download/v$BAZELISK_VERSION/bazelisk-linux-amd64 -o /usr/local/bin/bazel && \
6969
chmod +x /usr/local/bin/bazel
7070

71+
# Use '-Wno-unused-command-line-argument' to suppress "argument unused during compilation"
72+
# warnings which are treated as errors by some projects.
73+
ARG COMMON_SANITIZER_FLAGS="-fuse-ld=lld -Wno-unused-command-line-argument"
74+
7175
# Default build flags for various sanitizers.
72-
ENV SANITIZER_FLAGS_address "-fsanitize=address -fsanitize-address-use-after-scope"
73-
ENV SANITIZER_FLAGS_hwaddress "-fsanitize=hwaddress -fuse-ld=lld -Wno-unused-command-line-argument"
76+
ENV SANITIZER_FLAGS_address "${COMMON_SANITIZER_FLAGS} -fsanitize=address -fsanitize-address-use-after-scope"
77+
ENV SANITIZER_FLAGS_hwaddress "${COMMON_SANITIZER_FLAGS} -fsanitize=hwaddress"
7478

7579
# Set of '-fsanitize' flags matches '-fno-sanitize-recover' + 'unsigned-integer-overflow'.
76-
ENV SANITIZER_FLAGS_undefined "-fsanitize=array-bounds,bool,builtin,enum,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
80+
ENV SANITIZER_FLAGS_undefined "${COMMON_SANITIZER_FLAGS} -fsanitize=array-bounds,bool,builtin,enum,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,function,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
7781

7882
# Don't include "function" since it is unsupported on aarch64.
79-
ENV SANITIZER_FLAGS_undefined_aarch64 "-fsanitize=array-bounds,bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
83+
ENV SANITIZER_FLAGS_undefined_aarch64 "${COMMON_SANITIZER_FLAGS} -fsanitize=array-bounds,bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unsigned-integer-overflow,unreachable,vla-bound,vptr -fno-sanitize-recover=array-bounds,bool,builtin,enum,integer-divide-by-zero,null,object-size,return,returns-nonnull-attribute,shift,signed-integer-overflow,unreachable,vla-bound,vptr"
8084

81-
ENV SANITIZER_FLAGS_memory "-fsanitize=memory -fsanitize-memory-track-origins"
85+
ENV SANITIZER_FLAGS_memory "${COMMON_SANITIZER_FLAGS} -fsanitize=memory -fsanitize-memory-track-origins"
8286

83-
ENV SANITIZER_FLAGS_thread "-fsanitize=thread"
87+
ENV SANITIZER_FLAGS_thread "${COMMON_SANITIZER_FLAGS} -fsanitize=thread"
8488

85-
ENV SANITIZER_FLAGS_introspector "-O0 -flto -fno-inline-functions -fuse-ld=gold -Wno-unused-command-line-argument"
89+
ENV SANITIZER_FLAGS_introspector "${COMMON_SANITIZER_FLAGS} -O0 -flto -fno-inline-functions"
8690

8791
# Do not use any sanitizers in the coverage build.
8892
ENV SANITIZER_FLAGS_coverage ""
@@ -95,11 +99,8 @@ ENV UBSAN_OPTIONS="silence_unsigned_overflow=1"
9599
ENV DFSAN_OPTIONS='warn_unimplemented=0'
96100

97101
# Default build flags for coverage feedback.
98-
ENV COVERAGE_FLAGS="-fsanitize=fuzzer-no-link"
99-
100-
# Use '-Wno-unused-command-line-argument' to suppress "warning: -ldl: 'linker' input unused"
101-
# messages which are treated as errors by some projects.
102-
ENV COVERAGE_FLAGS_coverage "-fprofile-instr-generate -fcoverage-mapping -pthread -Wl,--no-as-needed -Wl,-ldl -Wl,-lm -Wno-unused-command-line-argument"
102+
ENV COVERAGE_FLAGS="${COMMON_SANITIZER_FLAGS} -fsanitize=fuzzer-no-link"
103+
ENV COVERAGE_FLAGS_coverage "${COMMON_SANITIZER_FLAGS} -fprofile-instr-generate -fcoverage-mapping -pthread -Wl,--no-as-needed -Wl,-ldl -Wl,-lm"
103104

104105
# Default sanitizer, fuzzing engine and architecture to use.
105106
ENV SANITIZER="address"

projects/connectedhomeip/build.sh

+1-9
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
################################################################################
1717

1818

19-
# workaround to get Fuzz Introspector to build; making it link with lld instead of the environment's gold linker which gives an error
20-
if [ "$SANITIZER" == "introspector" ]; then
21-
export CFLAGS=$(echo "$CFLAGS" | sed 's/gold/lld/g')
22-
export CXXFLAGS=$(echo "$CXXFLAGS" | sed 's/gold/lld/g')
23-
fi
24-
2519
cd $SRC/connectedhomeip
2620

2721
# Activate Pigweed environment
@@ -42,15 +36,13 @@ export PATH="/src/connectedhomeip/.environment/cipd/packages/zap/:$PATH"
4236
# error on GenericConnectivityManagerImpl_Thread.ipp and current fuzzing
4337
# does not differentiate between thread/Wifi/TCP/UDP/BLE connectivity
4438
# implementations.
45-
# - `target_ldflags` forces compiler to use LLVM's linker
4639
gn gen out/fuzz_targets \
4740
--args="
4841
oss_fuzz=true \
4942
is_clang=true \
5043
enable_rtti=true \
5144
chip_enable_thread_safety_checks=false \
52-
chip_enable_openthread=false \
53-
target_ldflags=[\"-fuse-ld=lld\"]"
45+
chip_enable_openthread=false
5446
5547
# Deactivate Pigweed environment to use OSS-Fuzz toolchains
5648
deactivate

projects/dbus-broker/build.sh

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ MESON_CXXFLAGS=${CXXFLAGS:-}
2525
MESON_LDFLAGS=${LDFLAGS:-}
2626

2727
if [[ "$SANITIZER" == introspector ]]; then
28-
MESON_CFLAGS="${MESON_CFLAGS//-fuse-ld=gold/ }"
29-
MESON_CXXFLAGS="${MESON_CXXFLAGS//-fuse-ld=gold/ }"
30-
MESON_LDFLAGS="${MESON_LDFLAGS//-fuse-ld=gold/ }"
28+
MESON_CFLAGS="${MESON_CFLAGS//-fuse-ld=lld/ }"
29+
MESON_CXXFLAGS="${MESON_CXXFLAGS//-fuse-ld=lld/ }"
30+
MESON_LDFLAGS="${MESON_LDFLAGS//-fuse-ld=lld/ }"
3131
MESON_LDFLAGS+=" -flto"
32-
export CC_LD=gold
33-
export CXX_LD=gold
32+
export CC_LD=lld
33+
export CXX_LD=lld
3434
fi
3535

3636
apt-get update -y

projects/ecc-diff-fuzzer/build.sh

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#
1616
################################################################################
1717

18-
# use a linker that supports Dwarf v5
19-
export LDFLAGS="-fuse-ld=lld"
20-
2118
# build projects
2219
#nettle
2320
(

projects/ffmpeg/build.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ else
4545
export PKG_CONFIG_PATH="$FFMPEG_DEPS_PATH/$LIBDIR/pkgconfig:$FFMPEG_DEPS_PATH/lib/pkgconfig"
4646
fi
4747

48-
# The option `-fuse-ld=gold` can't be passed via `CFLAGS` or `CXXFLAGS` because
48+
# The option `-fuse-ld=` can't be passed via `CFLAGS` or `CXXFLAGS` because
4949
# Meson injects `-Werror=ignored-optimization-argument` during compile tests.
5050
# Remove the `-fuse-ld=` and let Meson handle it.
5151
# https://github.com/mesonbuild/meson/issues/6377#issuecomment-575977919
5252
export MESON_CFLAGS="$CFLAGS"
53-
if [[ "$CFLAGS" == *"-fuse-ld=gold"* ]]; then
54-
export MESON_CFLAGS="${CFLAGS//-fuse-ld=gold/}"
55-
export CC_LD=gold
53+
if [[ "$CFLAGS" == *"-fuse-ld=lld"* ]]; then
54+
export MESON_CFLAGS="${CFLAGS//-fuse-ld=lld/}"
55+
export CC_LD=lld
5656
fi
5757
export MESON_CXXFLAGS="$CXXFLAGS"
58-
if [[ "$CXXFLAGS" == *"-fuse-ld=gold"* ]]; then
59-
export MESON_CXXFLAGS="${CXXFLAGS//-fuse-ld=gold/}"
60-
export CXX_LD=gold
58+
if [[ "$CXXFLAGS" == *"-fuse-ld=lld"* ]]; then
59+
export MESON_CXXFLAGS="${CXXFLAGS//-fuse-ld=lld/}"
60+
export CXX_LD=lld
6161
fi
6262

6363
meson_install() {

projects/halide/build.sh

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
################################################################################
1717
set euox pipefail
1818

19-
export LDFLAGS="-fuse-ld=lld"
20-
2119
declare -A LLVM_SANITIZER=( ["address"]="Address" ["undefined"]="Undefined" ["memory"]="Memory" )
2220

2321
if [[ -v LLVM_SANITIZER[$SANITIZER] ]]; then

projects/libiec61850/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $CC $CFLAGS $LIB_FUZZING_ENGINE ../fuzz/fuzz_mms_decode.c -c \
2525
-I../hal/inc -I../src/logging
2626

2727

28-
$CXX $CXXFLAGS -fuse-ld=lld $LIB_FUZZING_ENGINE fuzz_mms_decode.o -o $OUT/fuzz_mms_decode ./src/libiec61850.a ./hal/libhal.a
28+
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE fuzz_mms_decode.o -o $OUT/fuzz_mms_decode ./src/libiec61850.a ./hal/libhal.a
2929

3030
# Copy over the options file
3131
cp $SRC/fuzz_decode.options $OUT/fuzz_decode.options

projects/llhttp/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ npm ci
2222
yes | make build/libllhttp.a
2323

2424
$CC $CFLAGS -c ./test/fuzzers/fuzz_parser.c -I./build/ ./build/libllhttp.a -o $WORK/fuzz_parser.o
25-
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE -fuse-ld=lld -I./build/ ./build/libllhttp.a $WORK/fuzz_parser.o -o $OUT/fuzz_parser
25+
$CXX $CXXFLAGS $LIB_FUZZING_ENGINE -I./build/ ./build/libllhttp.a $WORK/fuzz_parser.o -o $OUT/fuzz_parser

projects/mpv/build.sh

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ make -j`nproc`
4747
make install
4848
popd
4949

50-
# The option `-fuse-ld=gold` can't be passed via `CFLAGS` or `CXXFLAGS` because
50+
# The option `-fuse-ld=` can't be passed via `CFLAGS` or `CXXFLAGS` because
5151
# Meson injects `-Werror=ignored-optimization-argument` during compile tests.
5252
# Remove the `-fuse-ld=` and let Meson handle it.
5353
# https://github.com/mesonbuild/meson/issues/6377#issuecomment-575977919
54-
if [[ "$CFLAGS" == *"-fuse-ld=gold"* ]]; then
55-
export CFLAGS="${CFLAGS//-fuse-ld=gold/}"
56-
export CC_LD=gold
54+
if [[ "$CFLAGS" == *"-fuse-ld=lld"* ]]; then
55+
export CFLAGS="${CFLAGS//-fuse-ld=lld/}"
56+
export CC_LD=lld
5757
fi
58-
if [[ "$CXXFLAGS" == *"-fuse-ld=gold"* ]]; then
59-
export CXXFLAGS="${CXXFLAGS//-fuse-ld=gold/}"
60-
export CXX_LD=gold
58+
if [[ "$CXXFLAGS" == *"-fuse-ld=lld"* ]]; then
59+
export CXXFLAGS="${CXXFLAGS//-fuse-ld=lld/}"
60+
export CXX_LD=lld
6161
fi
6262

6363
pushd $SRC/mpv

projects/ntp/build.sh

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
################################################################################
1717

1818
cd ntp-dev
19-
#avoids https://bugs.llvm.org/show_bug.cgi?id=34636
20-
cp /usr/bin/ld.gold /usr/bin/ld
2119
./bootstrap
2220
./configure --enable-fuzztargets
2321
make

projects/tdengine/build.sh

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ sed -i 's/-Werror//g' ./cmake/define.inc
2424
mkdir debug && cd debug
2525
export LDFLAGS="${CXXFLAGS}"
2626

27-
if [[ $SANITIZER = *coverage* ]]; then
28-
ln -f -s /usr/bin/gold /usr/bin/ld
29-
fi
30-
3127
cmake -DBUILD_HTTP=true ..
3228
cmake --build .
3329

projects/thrift/build.sh

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
# build project
1919
export ASAN_OPTIONS=detect_leaks=0
2020

21-
if [ "$SANITIZER" = "coverage" ]
22-
then
23-
cp /usr/bin/ld.gold /usr/bin/ld
24-
fi
2521
./bootstrap.sh
2622
# rust fails compilation with clippy warnings
2723
./configure --with-rs=no

0 commit comments

Comments
 (0)