diff --git a/boringssl/build.sh b/boringssl/build.sh index 5f5b47edd..d2b0da59e 100755 --- a/boringssl/build.sh +++ b/boringssl/build.sh @@ -23,7 +23,7 @@ CXXFLAGS="$CXXFLAGS -DBORINGSSL_UNSAFE_FUZZER_MODE" cmake -GNinja -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \ -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \ - -DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS" \ + -DCMAKE_EXE_LINKER_FLAGS="$FUZZER_LDFLAGS" \ /src/boringssl/ ninja @@ -34,7 +34,7 @@ find . -name "*.a" for F in $fuzzerFiles; do fuzzerName=$(basename $F .cc) echo "Building fuzzer $fuzzerName" - $CXX $CXXFLAGS $LDFLAGS -std=c++11 \ + $CXX $CXXFLAGS $FUZZER_LDFLAGS -std=c++11 \ -o /out/openssl_${fuzzerName} /work/libfuzzer/*.o $F \ -I /src/boringssl/include ./ssl/libssl.a ./crypto/libcrypto.a done diff --git a/curl/build.sh b/curl/build.sh index 476322b57..c393e4cfc 100755 --- a/curl/build.sh +++ b/curl/build.sh @@ -19,4 +19,4 @@ cd /src/curl ./buildconf ./configure --disable-shared --enable-debug --enable-maintainer-mode --disable-symbol-hiding --disable-threaded-resolver --enable-ipv6 --with-random=/dev/null make -j4 -$CXX $CXXFLAGS /src/fuzzer.cc -Iinclude lib/.libs/libcurl.a -lssl -lcrypto -lz /work/libfuzzer/*.o -o /out/curl_fuzzer $LDFLAGS +$CXX $CXXFLAGS /src/fuzzer.cc -Iinclude lib/.libs/libcurl.a -lssl -lcrypto -lz /work/libfuzzer/*.o -o /out/curl_fuzzer $FUZZER_LDFLAGS diff --git a/docs/new_library.md b/docs/new_library.md index a719943f5..5dc27c7f2 100644 --- a/docs/new_library.md +++ b/docs/new_library.md @@ -104,7 +104,7 @@ make clean all $CXX $CXXFLAGS -std=c++11 -Ilib/ \ /src/oss-fuzz/expat/parse_fuzzer.cc -o /out/expat_parse_fuzzer \ /work/libfuzzer/*.o .libs/libexpat.a \ - $LDFLAGS + $FUZZER_LDFLAGS ``` ### build.sh Script Environment @@ -120,13 +120,11 @@ When build.sh script is executed, the following locations are available within t You *must* use special compiler flags to build your library and fuzzers. These flags are provided in following environment variables: -| Env Variable | Description -| ------------- | -------- -| `$CC` | The C compiler binary. -| `$CXX`, `$CCC` | The C++ compiler binary. -| `$CFLAGS` | C compiler flags. -| `$CXXFLAGS` | C++ compiler flags. -| `$LDFLAGS` | Linker flags for fuzzer binaries. +| Env Variable | Description +| ------------- | -------- +| `$CC`, `$CXX`, `$CCC` | The C and C++ compiler binaries. +| `$CFLAGS`, `$CXXFLAGS` | C and C++ compiler flags. +| `$FUZZER_LDFLAGS` | Linker flags for fuzzer binaries. Many well-crafted build scripts will automatically use these variables. If not, passing them manually to a build tool might be required. diff --git a/expat/build.sh b/expat/build.sh index 042c6ea66..f99443e96 100755 --- a/expat/build.sh +++ b/expat/build.sh @@ -7,6 +7,6 @@ make clean all $CXX $CXXFLAGS -std=c++11 -Ilib/ \ /src/parse_fuzzer.cc -o /out/expat_parse_fuzzer \ - /work/libfuzzer/*.o .libs/libexpat.a $LDFLAGS + /work/libfuzzer/*.o .libs/libexpat.a $FUZZER_LDFLAGS cp /src/*.dict /src/*.options /out/ \ No newline at end of file diff --git a/freetype2/build.sh b/freetype2/build.sh index f4799196f..cb78c47ac 100755 --- a/freetype2/build.sh +++ b/freetype2/build.sh @@ -21,7 +21,7 @@ cd /src/freetype2/ ./configure make clean all -$CXX $CXXFLAGS $LDFLAGS -std=c++11 \ +$CXX $CXXFLAGS $FUZZER_LDFLAGS -std=c++11 \ -I./include -I. \ ./src/tools/ftfuzzer/ftfuzzer.cc -o /out/freetype2_fuzzer \ ./objs/*.o /work/libfuzzer/*.o \ diff --git a/harfbuzz/build.sh b/harfbuzz/build.sh index 0d7fe286d..4fd0e1429 100755 --- a/harfbuzz/build.sh +++ b/harfbuzz/build.sh @@ -24,4 +24,4 @@ make clean all $CXX $CXXFLAGS -std=c++11 -Isrc \ /src/harfbuzz_fuzzer.cc -o /out/harfbuzz_fuzzer \ - /work/libfuzzer/*.o src/.libs/*.o src/hb-ucdn/.libs/*.o $LDFLAGS + /work/libfuzzer/*.o src/.libs/*.o src/hb-ucdn/.libs/*.o $FUZZER_LDFLAGS diff --git a/infra/base-images/base-libfuzzer/Dockerfile b/infra/base-images/base-libfuzzer/Dockerfile index bf41b3882..25a8e42eb 100644 --- a/infra/base-images/base-libfuzzer/Dockerfile +++ b/infra/base-images/base-libfuzzer/Dockerfile @@ -24,7 +24,7 @@ ENV SANITIZER_FLAGS="-fsanitize=address" ENV COV_FLAGS="-fsanitize-coverage=edge,indirect-calls,8bit-counters" ENV ASAN_OPTIONS="symbolize=1:detect_leaks=0" -ENV LDFLAGS "-Wl,-whole-archive /usr/local/lib/libc++.a /usr/local/lib/libc++abi.a -Wl,-no-whole-archive" +ENV FUZZER_LDFLAGS "-Wl,-whole-archive /usr/local/lib/libc++.a /usr/local/lib/libc++abi.a -Wl,-no-whole-archive" RUN mkdir /out diff --git a/infra/base-images/base-libfuzzer/README.md b/infra/base-images/base-libfuzzer/README.md index 09ef82f1d..b84a970ca 100644 --- a/infra/base-images/base-libfuzzer/README.md +++ b/infra/base-images/base-libfuzzer/README.md @@ -31,7 +31,7 @@ These flags are provided in following environment variables: | `$CXX`, `$CCC` | The C++ compiler binary. | `$CFLAGS` | C compiler flags. | `$CXXFLAGS` | C++ compiler flags. -| `$LDFLAGS` | Linker flags for fuzzer binaries. +| `$FUZZER_LDFLAGS` | Linker flags for fuzzer binaries. Many well-crafted build scripts will automatically use these variables. If not, passing them manually to a build tool might be required. diff --git a/infra/base-images/base-libfuzzer/compile b/infra/base-images/base-libfuzzer/compile index c2a4b8408..85eaddcd5 100755 --- a/infra/base-images/base-libfuzzer/compile +++ b/infra/base-images/base-libfuzzer/compile @@ -32,7 +32,7 @@ echo "CC=$CC" echo "CXX=$CXX" echo "CFLAGS=$CFLAGS" echo "CXXFLAGS=$CXXFLAGS" -echo "LDFLAGS=$LDFLAGS" +echo "FUZZER_LDFLAGS=$FUZZER_LDFLAGS" echo "---------------------------------------------------------------" diff --git a/json/build.sh b/json/build.sh index 57ec00e3a..861ac18ef 100755 --- a/json/build.sh +++ b/json/build.sh @@ -19,6 +19,6 @@ cd /src/json $CXX $CXXFLAGS -std=c++11 -I/src/json/src/ \ /src/parse_fuzzer.cc -o /out/parse_fuzzer \ - /work/libfuzzer/*.o $LDFLAGS + /work/libfuzzer/*.o $FUZZER_LDFLAGS cp /src/*.options /out/ diff --git a/libchewing/build.sh b/libchewing/build.sh index d7c029ea9..f129849ff 100755 --- a/libchewing/build.sh +++ b/libchewing/build.sh @@ -29,7 +29,7 @@ $CC $CFLAGS \ -o /out/chewing_fuzzer \ /src/chewing_fuzzer.c \ test/stress.o test/.libs/libtesthelper.a src/.libs/libchewing.a \ - /work/libfuzzer/*.o $LDFLAGS + /work/libfuzzer/*.o $FUZZER_LDFLAGS # install data files make -C data pkgdatadir=/out install diff --git a/libpng/build.sh b/libpng/build.sh index 19d15eb5a..0cd473440 100755 --- a/libpng/build.sh +++ b/libpng/build.sh @@ -30,6 +30,6 @@ make clean all # build libpng_read_fuzzer $CXX $CXXFLAGS -std=c++11 -I. -lz \ /src/libpng_read_fuzzer.cc -o /out/libpng_read_fuzzer \ - /work/libfuzzer/*.o .libs/libpng16.a $LDFLAGS + /work/libfuzzer/*.o .libs/libpng16.a $FUZZER_LDFLAGS cp /src/*.dict /src/*.options /out/ \ No newline at end of file diff --git a/libxml2/build.sh b/libxml2/build.sh index 1643543b6..41cfc308b 100755 --- a/libxml2/build.sh +++ b/libxml2/build.sh @@ -24,7 +24,7 @@ make clean all for fuzzer in libxml2_xml_read_memory_fuzzer libxml2_xml_regexp_compile_fuzzer; do $CXX $CXXFLAGS -std=c++11 -Iinclude/ \ /src/$fuzzer.cc -o /out/$fuzzer \ - /work/libfuzzer/*.o .libs/libxml2.a $LDFLAGS + /work/libfuzzer/*.o .libs/libxml2.a $FUZZER_LDFLAGS done cp /src/*.dict /src/*.options /out/ \ No newline at end of file diff --git a/nss/build.sh b/nss/build.sh index 645b33345..345c9053d 100755 --- a/nss/build.sh +++ b/nss/build.sh @@ -62,5 +62,5 @@ for fuzzer in $FUZZERS; do /work/libfuzzer/*.o \ /work/nss/lib/libnss.a /work/nss/lib/libnssutil.a \ /work/nss/lib/libnspr4.a /work/nss/lib/libplc4.a /work/nss/lib/libplds4.a \ - /work/nss/lib/prlog2.o -o /out/$fuzzer $LDFLAGS + /work/nss/lib/prlog2.o -o /out/$fuzzer $FUZZER_LDFLAGS done diff --git a/pcre2/build.sh b/pcre2/build.sh index 4c1358270..1eddf80e6 100755 --- a/pcre2/build.sh +++ b/pcre2/build.sh @@ -21,13 +21,11 @@ cd pcre2 # build the library. ./autogen.sh -SAVED_LDFLAGS="$LDFLAGS" -export LDFLAGS= # Can't use provided LDFLAGS to build pcre's .a targets. ./configure --enable-never-backslash-C --with-match-limit=1000 --with-match-limit-recursion=1000 make clean all # Build the target. $CXX $CXXFLAGS -std=c++11 -I src \ /src/pcre2_fuzzer.cc -o /out/pcre2_fuzzer \ - -Wl,--whole-archive .libs/*.a -Wl,-no-whole-archive $SAVED_LDFLAGS \ + -Wl,--whole-archive .libs/*.a -Wl,-no-whole-archive $FUZZER_LDFLAGS \ /work/libfuzzer/*.o diff --git a/re2/build.sh b/re2/build.sh index dc587970a..3f6c255ee 100755 --- a/re2/build.sh +++ b/re2/build.sh @@ -32,6 +32,6 @@ make obj/libre2.a # Second, build our fuzzers. $CXX $CXXFLAGS -std=c++11 -I. \ /src/re2_fuzzer.cc -o /out/re2_fuzzer \ - /work/libfuzzer/*.o ./obj/libre2.a $LDFLAGS + /work/libfuzzer/*.o ./obj/libre2.a $FUZZER_LDFLAGS cp /src/*.options /out/ diff --git a/scripts/templates.py b/scripts/templates.py index b35faf937..2b069ed25 100644 --- a/scripts/templates.py +++ b/scripts/templates.py @@ -94,5 +94,5 @@ cd /src/%s # e.g. # $CXX $CXXFLAGS -std=c++11 -Iinclude \\ # /path/to/name_of_fuzzer.cc -o /out/name_of_fuzzer \\ -# /work/libfuzzer/*.o /path/to/library.a $LDFLAGS +# /work/libfuzzer/*.o /path/to/library.a $FUZZER_LDFLAGS """ diff --git a/sqlite3/build.sh b/sqlite3/build.sh index d1a7b9707..93bc14493 100755 --- a/sqlite3/build.sh +++ b/sqlite3/build.sh @@ -34,6 +34,6 @@ make sqlite3.c $CXX $CXXFLAGS -std=c++11 -I. \ /src/sqlite3_fuzzer.cc -o /out/sqlite3_fuzzer \ - /work/libfuzzer/*.o ./sqlite3.o $LDFLAGS + /work/libfuzzer/*.o ./sqlite3.o $FUZZER_LDFLAGS cp /src/*.options /src/*.dict /out/ \ No newline at end of file diff --git a/woff2/build.sh b/woff2/build.sh index 6440766d2..0bdbe445d 100755 --- a/woff2/build.sh +++ b/woff2/build.sh @@ -31,8 +31,6 @@ cat Makefile | sed -e "s/-no-canonical-prefixes//" \ > Makefile.temp mv Makefile.temp Makefile -# woff2 uses LFLAGS instead of LDFLAGS. -export LFLAGS=$LDFLAGS make CC="$CC $CFLAGS" CXX="$CXX $CXXFLAGS" clean all # To avoid multiple main() definitions. @@ -42,6 +40,6 @@ rm src/woff2_compress.o src/woff2_decompress.o fuzzer=convert_woff2ttf_fuzzer $CXX $CXXFLAGS -std=c++11 -Isrc \ /src/$fuzzer.cc -o /out/$fuzzer \ - /work/libfuzzer/*.o src/*.o brotli/dec/*.o brotli/enc/*.o $LDFLAGS + /work/libfuzzer/*.o src/*.o brotli/dec/*.o brotli/enc/*.o $FUZZER_LDFLAGS cp /src/*.options /out/ diff --git a/zlib/build.sh b/zlib/build.sh index caa809106..214546c13 100755 --- a/zlib/build.sh +++ b/zlib/build.sh @@ -7,4 +7,4 @@ make clean all $CXX $CXXFLAGS -std=c++11 -I. \ /src/zlib_uncompress_fuzzer.cc -o /out/zlib_uncompress_fuzzer \ - /work/libfuzzer/*.o ./libz.a $LDFLAGS + /work/libfuzzer/*.o ./libz.a $FUZZER_LDFLAGS