diff --git a/boringssl/build.sh b/boringssl/build.sh index 0fa94eef8..e9cbfe3a1 100755 --- a/boringssl/build.sh +++ b/boringssl/build.sh @@ -36,7 +36,7 @@ for F in $fuzzerFiles; do fuzzerName=$(basename $F .cc) echo "Building fuzzer $fuzzerName" $CXX $CXXFLAGS $FUZZER_LDFLAGS -std=c++11 \ - -o /out/openssl_${fuzzerName} /work/libfuzzer/*.o $F \ + -o /out/openssl_${fuzzerName} -lfuzzer $F \ -I /src/boringssl/include ./ssl/libssl.a ./crypto/libcrypto.a done diff --git a/curl/build.sh b/curl/build.sh index c393e4cfc..d83c38851 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 $FUZZER_LDFLAGS +$CXX $CXXFLAGS /src/fuzzer.cc -Iinclude lib/.libs/libcurl.a -lssl -lcrypto -lz -lfuzzer -o /out/curl_fuzzer $FUZZER_LDFLAGS diff --git a/docs/new_library.md b/docs/new_library.md index a14f17584..5815d9366 100644 --- a/docs/new_library.md +++ b/docs/new_library.md @@ -103,7 +103,7 @@ make clean all # build the fuzzer, linking with libFuzzer and libexpat.a $CXX $CXXFLAGS -std=c++11 -Ilib/ \ /src/oss-fuzz/expat/parse_fuzzer.cc -o /out/expat_parse_fuzzer \ - /work/libfuzzer/*.o .libs/libexpat.a \ + -lfuzzer .libs/libexpat.a \ $FUZZER_LDFLAGS ``` @@ -113,9 +113,9 @@ When build.sh script is executed, the following locations are available within t | Path | Description | ------ | ----- -| `/src/$LIB_NAME` | Source code for your library. -| `/src/oss-fuzz` | Checked out oss-fuzz source tree. -| `/work/libfuzzer/*.o` | Prebuilt libFuzzer object files that need to be linked into all fuzzers. +| `/src/$LIB_NAME` | Source code for your library. +| `/src/oss-fuzz` | Checked out oss-fuzz source tree. +| `/usr/lib/libfuzzer.a` | Prebuilt libFuzzer library that need to be linked into all fuzzers (`-lfuzzer`). You *must* use special compiler flags to build your library and fuzzers. These flags are provided in following environment variables: diff --git a/expat/build.sh b/expat/build.sh index f99443e96..8886e3a3a 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 $FUZZER_LDFLAGS + -lfuzzer .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 cb78c47ac..eb2767037 100755 --- a/freetype2/build.sh +++ b/freetype2/build.sh @@ -24,6 +24,6 @@ make clean all $CXX $CXXFLAGS $FUZZER_LDFLAGS -std=c++11 \ -I./include -I. \ ./src/tools/ftfuzzer/ftfuzzer.cc -o /out/freetype2_fuzzer \ - ./objs/*.o /work/libfuzzer/*.o \ + ./objs/*.o -lfuzzer \ /usr/lib/x86_64-linux-gnu/libarchive.a \ ./objs/.libs/libfreetype.a diff --git a/harfbuzz/build.sh b/harfbuzz/build.sh index 07726039a..6ac53afac 100755 --- a/harfbuzz/build.sh +++ b/harfbuzz/build.sh @@ -25,4 +25,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 $FUZZER_LDFLAGS + -lfuzzer src/.libs/*.o src/hb-ucdn/.libs/*.o $FUZZER_LDFLAGS diff --git a/infra/base-images/base-libfuzzer/README.md b/infra/base-images/base-libfuzzer/README.md index b84a970ca..7ac316e79 100644 --- a/infra/base-images/base-libfuzzer/README.md +++ b/infra/base-images/base-libfuzzer/README.md @@ -18,7 +18,7 @@ Supported commands: | -------- | ---------- | | `/out/` | build artifacts should be copied here | | `/work/` | used to store intermediate files | -| `/work/libfuzzer/*.o` | libfuzzer object files | +| `/usr/lib/libfuzzer.a` | libfuzzer static library | # Provided Environment Variables diff --git a/infra/base-images/base-libfuzzer/compile b/infra/base-images/base-libfuzzer/compile index 85eaddcd5..bbf8a0f6d 100755 --- a/infra/base-images/base-libfuzzer/compile +++ b/infra/base-images/base-libfuzzer/compile @@ -18,11 +18,12 @@ echo "---------------------------------------------------------------" -export LIBFUZZER_WORK_DIR=/work/libfuzzer -echo -n "Compiling libFuzzer into $LIBFUZZER_WORK_DIR ..." -cd $LIBFUZZER_WORK_DIR +echo -n "Compiling libFuzzer into /usr/lib/libfuzzer.a ..." +cd /work/libfuzzer $CXX $CXXFLAGS -std=c++11 $SANITIZER_FLAGS -c /src/libfuzzer/*.cpp -I/src/libfuzzer +ar ruv /usr/lib/libfuzzer.a /work/libfuzzer/*.o +# TODO(mike): remove /work/libfuzzer after all fuzzers are migrated to -lfuzzer echo "Done." export CFLAGS="$CFLAGS $SANITIZER_FLAGS $COV_FLAGS" diff --git a/json/build.sh b/json/build.sh index 861ac18ef..94eb3abbe 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 $FUZZER_LDFLAGS + -lfuzzer $FUZZER_LDFLAGS cp /src/*.options /out/ diff --git a/libass/build.sh b/libass/build.sh index eaf5259fb..3404aa7b2 100755 --- a/libass/build.sh +++ b/libass/build.sh @@ -33,7 +33,7 @@ make $CXX $CXXFLAGS -std=c++11 -I/src/libass \ /src/libass_fuzzer.cc -o /out/libass_fuzzer \ - /work/libfuzzer/*.o libass/.libs/libass.a \ + -lfuzzer libass/.libs/libass.a \ -Wl,-Bstatic -lfontconfig -lfribidi -lfreetype -lz -lpng12 -lexpat -Wl,-Bdynamic \ $FUZZER_LDFLAGS diff --git a/libchewing/build.sh b/libchewing/build.sh index f129849ff..b6fab1bc6 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 $FUZZER_LDFLAGS + -lfuzzer $FUZZER_LDFLAGS # install data files make -C data pkgdatadir=/out install diff --git a/libpng/build.sh b/libpng/build.sh index 0cd473440..5a125bf32 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 $FUZZER_LDFLAGS + -lfuzzer .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 41cfc308b..41aec5540 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 $FUZZER_LDFLAGS + -lfuzzer .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 345c9053d..acdde030c 100755 --- a/nss/build.sh +++ b/nss/build.sh @@ -59,7 +59,7 @@ FUZZERS="asn1_algorithmid_fuzzer \ for fuzzer in $FUZZERS; do $CXX $CXXFLAGS -std=c++11 /src/$fuzzer.cc \ -I/work/nss/include \ - /work/libfuzzer/*.o \ + -lfuzzer \ /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 $FUZZER_LDFLAGS diff --git a/pcre2/build.sh b/pcre2/build.sh index 1eddf80e6..e7518d492 100755 --- a/pcre2/build.sh +++ b/pcre2/build.sh @@ -28,4 +28,4 @@ make clean all $CXX $CXXFLAGS -std=c++11 -I src \ /src/pcre2_fuzzer.cc -o /out/pcre2_fuzzer \ -Wl,--whole-archive .libs/*.a -Wl,-no-whole-archive $FUZZER_LDFLAGS \ - /work/libfuzzer/*.o + -lfuzzer diff --git a/re2/build.sh b/re2/build.sh index 3f6c255ee..4ffc387a3 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 $FUZZER_LDFLAGS + -lfuzzer ./obj/libre2.a $FUZZER_LDFLAGS cp /src/*.options /out/ diff --git a/scripts/templates.py b/scripts/templates.py index 2b069ed25..4c7aa2216 100755 --- 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 $FUZZER_LDFLAGS +# -lfuzzer /path/to/library.a $FUZZER_LDFLAGS """ diff --git a/sqlite3/build.sh b/sqlite3/build.sh index 93bc14493..086f23dcc 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 $FUZZER_LDFLAGS + -lfuzzer ./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 f58272e10..7d4535061 100755 --- a/woff2/build.sh +++ b/woff2/build.sh @@ -42,6 +42,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 $FUZZER_LDFLAGS + -lfuzzer 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 214546c13..067af039c 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 $FUZZER_LDFLAGS + -lfuzzer ./libz.a $FUZZER_LDFLAGS