diff --git a/debian/changelog b/debian/changelog index 89d1b35f..cc8e378b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -126,6 +126,13 @@ llvm-toolchain-snapshot (1:10~svn366440-1~exp1) experimental; urgency=medium -- Sylvestre Ledru Thu, 18 Jul 2019 18:58:32 +0200 +llvm-toolchain-9 (1:9.0.0-2) unstable; urgency=medium + + * polly, openmp & lldb aren't enabled for every platform + So, add to PROJECTS only when enabled + + -- Sylvestre Ledru Sun, 20 Oct 2019 17:27:50 +0200 + llvm-toolchain-9 (1:9.0.0-1) unstable; urgency=medium * Repack to move to git diff --git a/debian/qualify-clang.sh b/debian/qualify-clang.sh index 6d04d90b..5f255b19 100755 --- a/debian/qualify-clang.sh +++ b/debian/qualify-clang.sh @@ -201,7 +201,7 @@ if ! ldd o 2>&1|grep -q libclang-cpp; then echo "Didn't link against libclang-cpp$VERSION" # exit 42 fi -./o > /dev/null +#./o > /dev/null # Check that the symlink is correct ls -al /usr/lib/llvm-$VERSION/lib/libclang-cpp.so.1 > /dev/null @@ -328,14 +328,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { __builtin_trap(); return 0; } + EOF clang++-$VERSION -fsanitize=address -fsanitize-coverage=edge,trace-pc test_fuzzer.cc /usr/lib/llvm-$VERSION/lib/libFuzzer.a if ! ./a.out 2>&1 | grep -q -E "(Test unit written|PreferSmall)"; then - echo "fuzzer" + echo "fuzzer failed" exit 42 fi +clang++-$VERSION -fsanitize=address,fuzzer test_fuzzer.cc +if ! ./a.out 2>&1 | grep -q "libFuzzer: deadly signal"; then + echo "fuzzer failed" +fi + echo 'int main(int argc, char **argv) { int *array = new int[100]; delete [] array; @@ -381,6 +387,79 @@ if ! grep -q "foo.cpp:3:3" foo.log; then exit 42 fi +# Example from https://github.com/google/fuzzing/blob/master/tutorial/libFuzzerTutorial.md +# coverage fuzzing +cat << EOF > StandaloneFuzzTargetMain.c +#include +#include +#include + +extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); +__attribute__((weak)) extern int LLVMFuzzerInitialize(int *argc, char ***argv); +int main(int argc, char **argv) { + fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1); + if (LLVMFuzzerInitialize) + LLVMFuzzerInitialize(&argc, &argv); + for (int i = 1; i < argc; i++) { + fprintf(stderr, "Running: %s\n", argv[i]); + FILE *f = fopen(argv[i], "r"); + assert(f); + fseek(f, 0, SEEK_END); + size_t len = ftell(f); + fseek(f, 0, SEEK_SET); + unsigned char *buf = (unsigned char*)malloc(len); + size_t n_read = fread(buf, 1, len, f); + fclose(f); + assert(n_read == len); + LLVMFuzzerTestOneInput(buf, len); + free(buf); + fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read); + } +} +EOF + +cat << EOF > fuzz_me.cc +#include +#include + +bool FuzzMe(const uint8_t *Data, size_t DataSize) { + return DataSize >= 3 && + Data[0] == 'F' && + Data[1] == 'U' && + Data[2] == 'Z' && + Data[3] == 'Z'; +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + FuzzMe(Data, Size); + return 0; +} +EOF +clang-9 -fprofile-instr-generate -fcoverage-mapping fuzz_me.cc StandaloneFuzzTargetMain.c + +rm -rf CORPUS +mkdir -p CORPUS +echo -n A > CORPUS/A +./a.out CORPUS/* +if ! ./a.out CORPUS/* 2>&1 | grep -q "running 1 inputs"; then + echo "Coverage fuzzing failed" + exit 1 +fi +llvm-profdata-$VERSION merge -sparse *.profraw -o default.profdata +llvm-cov-$VERSION show a.out -instr-profile=default.profdata -name=FuzzMe &> foo.log +if ! grep -q "return DataSize >= 3" foo.log; then + echo "llvm-cov didn't show the expected output in fuzzing" + exit 1 +fi +echo -n FUZA > CORPUS/FUZA && ./a.out CORPUS/* +llvm-profdata-$VERSION merge -sparse *.profraw -o default.profdata +llvm-cov-$VERSION show a.out -instr-profile=default.profdata -name=FuzzMe &> foo.log +if ! grep -q "Data\[3\] == 'Z';" foo.log; then + echo "llvm-cov didn't show the expected output in fuzzing" + exit 1 +fi +rm -rf CORPUS fuzz_me.cc StandaloneFuzzTargetMain.c + echo "Testing sanitizers ..." echo '#include diff --git a/debian/rules b/debian/rules index 5b2ba1fd..9895ad7e 100755 --- a/debian/rules +++ b/debian/rules @@ -1,6 +1,7 @@ #!/usr/bin/make -f -PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;lldb;compiler-rt;lld;polly;debuginfo-tests;openmp" +# polly, openmp & lldb aren't enabled for every platform +PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;compiler-rt;lld;debuginfo-tests" TARGET_BUILD := build-llvm TARGET_BUILD_STAGE2 := $(TARGET_BUILD)/tools/clang/stage2-bins @@ -175,12 +176,16 @@ BOOTSTRAP_CFLAGS_EXTRA = $(CFLAGS_EXTRA) # Nothing for now. Keeping in case w POLLY_ENABLE=yes ifneq (,$(filter $(DEB_HOST_ARCH), powerpc powerpcspe)) POLLY_ENABLE=no +else + PROJECTS += ";polly" endif # Enable openmp (or not) OPENMP_ENABLE=yes ifneq (,$(filter $(DEB_HOST_ARCH), mips mipsel powerpc powerpcspe riscv64 sparc64 s390x x32)) OPENMP_ENABLE=no +else + PROJECTS= += ";openmp" endif RUN_TEST=yes @@ -224,11 +229,12 @@ LLDB_DISABLE_ARCHS := hurd-i386 ia64 powerpc powerpcspe ppc64 riscv64 sparc64 # hurd has threading issues ifeq (,$(filter-out $(LLDB_DISABLE_ARCHS), $(DEB_HOST_ARCH))) # Disable LLDB for this arch. - LLDB_ENABLE=no + LLDB_ENABLE=no else # See https://llvm.org/bugs/show_bug.cgi?id=28898 # Enable it again as it seems it is fixed upstream https://bugs.llvm.org/show_bug.cgi?id=35291 # CMAKE_EXTRA += -DLLDB_DISABLE_LIBEDIT=ON + PROJECTS += ";lldb" endif LLD_ENABLE=yes diff --git a/debian/unpack.sh b/debian/unpack.sh index 0ef550e4..5c960878 100644 --- a/debian/unpack.sh +++ b/debian/unpack.sh @@ -3,7 +3,6 @@ ORIG_VERSION=snapshot MAJOR_VERSION=10 # 8.0.1 REV=`ls -1 *${ORIG_VERSION}_${MAJOR_VERSION}*~+*xz | tail -1|perl -ne 'print "$1\n" if /~\+(.*)\.orig/;' | sort -ru` -#SVN_REV=347285 VERSION=$REV echo $VERSION #VERSION=+rc3