From patchwork Wed Jun 3 12:09:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 1302965 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49cSR00p8Pz9sRW for ; Wed, 3 Jun 2020 22:10:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D0BFF2041A; Wed, 3 Jun 2020 12:10:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id VOJj6yop4A6w; Wed, 3 Jun 2020 12:10:12 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 3790420445; Wed, 3 Jun 2020 12:10:12 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by ash.osuosl.org (Postfix) with ESMTP id 32CFD1BF39F for ; Wed, 3 Jun 2020 12:10:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 2F30A850E6 for ; Wed, 3 Jun 2020 12:10:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PQXkvVg3EjZP for ; Wed, 3 Jun 2020 12:10:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from da1vs05.rockwellcollins.com (da1vs05.rockwellcollins.com [205.175.227.130]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 311F286B84 for ; Wed, 3 Jun 2020 12:09:33 +0000 (UTC) IronPort-SDR: dErN5tF8e6PDMScX2ULFv26SzITMyntU1bDgcfGZqfHQt269NPTSPuSCfZQ2HrG9Gp7323g0gg oVWNwHXQROlbTuofvhvT27sa2DUVWyxAn6Rp5yHwZJfu4bCw0R4YmnI5uMTbYsdbUBnoh4lqFk btEzv3sq6T5+ayYMVcPdSRJszJ7D9WnCkocVpLuJoiQ9M8nUfKI6UCq4T9pOgcZwnBHaF/uOnH EroV2mB3AYC0f+B/kKvcsux9aGVMNYZOnBp3i0pbLbmlH+WK0PD6CNzq+wFIRkjTkGqHMfnoPT j+w= Received: from ofwda1n02.rockwellcollins.com (HELO dtulimr02.rockwellcollins.com) ([205.175.227.14]) by da1vs05.rockwellcollins.com with ESMTP; 03 Jun 2020 07:09:33 -0500 X-Received: from biscuits.rockwellcollins.com (biscuits.rockwellcollins.lab [10.148.119.137]) by dtulimr02.rockwellcollins.com (Postfix) with ESMTP id 4914320042; Wed, 3 Jun 2020 07:09:32 -0500 (CDT) From: Matt Weber To: buildroot@buildroot.org Date: Wed, 3 Jun 2020 07:09:30 -0500 Message-Id: <20200603120931.20551-1-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 2.17.1 Subject: [Buildroot] [PATCH v9 1/2] package/compiler-rt: new package X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matt Weber , Romain Naour , Michael Drake , Ricardo Martincoski , Valentin Korenblit MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch adds support for the compiler-rt (CLANG runtime) library. It builds a set of static libraries and installs them into the CLANG/LLVM toolchain resource folder. The compiler-rt fuzzer and address sanitizer tools require additional LLVM binary tools installed to allow stack trace decoding actively during executable analysis. This patch conditionally enables these tools. https://github.com/google/sanitizers/wiki/AddressSanitizerCallStack Signed-off-by: Matthew Weber Cc: Romain Naour Cc: Ricardo Martincoski Cc: Valentin Korenblit Cc: Michael Drake --- Changes v1 -> v2 [Romain - Removed unnecessary host-cmake dependency v2 -> v3 [Romain - Update to use COMPILER_RT_INSTALL_PATH for library install [Ricardo - Fixed check-package extra line - Spelling in commit message v3 -> v4 [Valentin - Pointed out that non-glibc libraries won't build. Further investigation shows that the lib asan support in compiler-rt doesn't have the libc checks yet to support multiple libraries. (https://patchwork.ozlabs.org/patch/339938/ was the best example I could find and it doesn't look like anything has changed in the recent codebase) v4 -> v5 [Thomas P - Revisited staging install step and found a cleaner way to use the default and then a hook to setup the runtime library path v6 - Bumped to 7.0.1 to match current LLVM/Clang version v7 - Rebased on master for 8.0 LLVM/Clang version - Added comment about bumping verions of LLVM/Clang and Compiler-rt together [Romain - Disabled test cases (-DCOMPILER_RT_INCLUDE_TESTS=OFF) v8 - Rebased and updated version to 9.x to match llvm/clang [Romain - Squashed "[v7,1/5]package/llvm: install target binary/debug tools" to be included in this patch [Michael D - compiler-rt symlink creation to include shared folder such that control flow lists work v9 - Rebased post 2020.05 --- DEVELOPERS | 1 + package/Config.in | 1 + package/compiler-rt/Config.in | 14 +++++++++++ package/compiler-rt/compiler-rt.hash | 3 +++ package/compiler-rt/compiler-rt.mk | 37 ++++++++++++++++++++++++++++ package/llvm/llvm.mk | 11 ++++++++- 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 package/compiler-rt/Config.in create mode 100644 package/compiler-rt/compiler-rt.hash create mode 100644 package/compiler-rt/compiler-rt.mk diff --git a/DEVELOPERS b/DEVELOPERS index e3ac8aa06a..76d9f99d6f 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1645,6 +1645,7 @@ F: package/bridge-utils/ F: package/checkpolicy/ F: package/checksec/ F: package/cgroupfs-mount/ +F: package/compiler-rt/ F: package/crda/ F: package/cunit/ F: package/dacapo/ diff --git a/package/Config.in b/package/Config.in index 2a928057f6..82b5b1f99a 100644 --- a/package/Config.in +++ b/package/Config.in @@ -1790,6 +1790,7 @@ menu "Other" source "package/clang/Config.in" source "package/clapack/Config.in" source "package/cmocka/Config.in" + source "package/compiler-rt/Config.in" source "package/cppcms/Config.in" source "package/cracklib/Config.in" source "package/dawgdic/Config.in" diff --git a/package/compiler-rt/Config.in b/package/compiler-rt/Config.in new file mode 100644 index 0000000000..9afc0d9d60 --- /dev/null +++ b/package/compiler-rt/Config.in @@ -0,0 +1,14 @@ +config BR2_PACKAGE_COMPILER_RT + bool "compiler-rt" + depends on BR2_PACKAGE_LLVM + depends on BR2_TOOLCHAIN_USES_GLIBC # asan lib requires + help + A collection of runtime libraries primarily used by clang and + llvm to provide builtins, sanitizer runtimes, and profiling + at runtime. + + https://compiler-rt.llvm.org/ + +comment "compiler-rt requires llvm to be enabled and a glibc toolchain" + depends on !BR2_PACKAGE_LLVM + depends on !BR2_TOOLCHAIN_USES_GLIBC diff --git a/package/compiler-rt/compiler-rt.hash b/package/compiler-rt/compiler-rt.hash new file mode 100644 index 0000000000..cf2f1890ad --- /dev/null +++ b/package/compiler-rt/compiler-rt.hash @@ -0,0 +1,3 @@ +# Locally computed: +sha256 56e4cd96dd1d8c346b07b4d6b255f976570c6f2389697347a6c3dcb9e820d10e compiler-rt-9.0.0.src.tar.xz +sha256 dd27f8c290bcdc8368549cd7cd98710a9dbdc34122f2e096a1edb97824ed4148 LICENSE.TXT diff --git a/package/compiler-rt/compiler-rt.mk b/package/compiler-rt/compiler-rt.mk new file mode 100644 index 0000000000..3d2cbcbff5 --- /dev/null +++ b/package/compiler-rt/compiler-rt.mk @@ -0,0 +1,37 @@ +################################################################################ +# +# compiler-rt +# +################################################################################ + +# Compiler-RT should be bumped together with LLVM and Clang as the run-time is +# tied to the version of those tools +COMPILER_RT_VERSION = 9.0.0 +COMPILER_RT_SOURCE = compiler-rt-$(COMPILER_RT_VERSION).src.tar.xz +COMPILER_RT_SITE = http://llvm.org/releases/$(COMPILER_RT_VERSION) +COMPILER_RT_LICENSE = NCSA MIT +COMPILER_RT_LICENSE_FILES = LICENSE.TXT +COMPILER_RT_DEPENDENCIES = host-clang llvm + +COMPILER_RT_INSTALL_STAGING = YES +COMPILER_RT_INSTALL_TARGET = NO + +COMPILER_RT_CONF_OPTS=-DCOMPILER_RT_STANDALONE_BUILD=OFF \ + -DCOMPILER_RT_STANDALONE_BUILD=ON \ + -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=$(GNU_TARGET_NAME) \ + -DLLVM_CONFIG_PATH=$(HOST_DIR)/usr/bin/llvm-config + +# The installation of the target runtime libraries defaults to DESTDIR, however +# host-clang resources directory needs a link so Clang can find the runtime +# libraries in the same location they would be if built as part of the Clang +# build. The "resources" directory is loosely documented and seems to be +# assumed, as compiler-rt is usually build at the same time as Clang and not +# standalone. +define COMPILER_RT_SETUP_RUNTIME_LIBS + mkdir -p $(HOST_DIR)/lib/clang/$(HOST_CLANG_VERSION)/lib + ln -sf ../../../../$(GNU_TARGET_NAME)/sysroot/usr/lib/linux $(HOST_DIR)/lib/clang/$(HOST_CLANG_VERSION)/lib/linux + ln -sf ../../../../$(GNU_TARGET_NAME)/sysroot/usr/share $(HOST_DIR)/lib/clang/$(HOST_CLANG_VERSION)/share +endef +COMPILER_RT_POST_INSTALL_STAGING_HOOKS += COMPILER_RT_SETUP_RUNTIME_LIBS + +$(eval $(cmake-package)) diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk index 24d033d124..3b1a238e3f 100644 --- a/package/llvm/llvm.mk +++ b/package/llvm/llvm.mk @@ -214,8 +214,17 @@ HOST_LLVM_CONF_OPTS += \ # We need to activate LLVM_INCLUDE_TOOLS, otherwise it does not generate # libLLVM.so LLVM_CONF_OPTS += \ - -DLLVM_INCLUDE_TOOLS=ON \ + -DLLVM_INCLUDE_TOOLS=ON + +# The llvm-symbolizer binary is used by the Compiler-RT Fuzzer +# and AddressSanitizer tools for stack traces. +ifeq ($(BR2_PACKAGE_COMPILER_RT),y) +LLVM_CONF_OPTS += \ + -DLLVM_BUILD_TOOLS=ON +else +LLVM_CONF_OPTS += \ -DLLVM_BUILD_TOOLS=OFF +endif ifeq ($(BR2_PACKAGE_LLVM_RTTI),y) HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_RTTI=ON From patchwork Wed Jun 3 12:09:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Weber X-Patchwork-Id: 1302964 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=busybox.net (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rockwellcollins.com Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49cSQR3QScz9sRW for ; Wed, 3 Jun 2020 22:09:50 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 39963883A3; Wed, 3 Jun 2020 12:09:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FgXhfDxZ0dej; Wed, 3 Jun 2020 12:09:43 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 18ED088398; Wed, 3 Jun 2020 12:09:43 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id C165C1BF39F for ; Wed, 3 Jun 2020 12:09:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id BD96588367 for ; Wed, 3 Jun 2020 12:09:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TN+5om1d1c38 for ; Wed, 3 Jun 2020 12:09:34 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ch3vs03.rockwellcollins.com (ch3vs03.rockwellcollins.com [205.175.226.47]) by hemlock.osuosl.org (Postfix) with ESMTPS id 5AC1688360 for ; Wed, 3 Jun 2020 12:09:34 +0000 (UTC) IronPort-SDR: q7ayAzcx5cV+T/iOX3rYlLk3JP0xWhmFz+HQc5qtFVBqtJhNc3s1XTwkzdw9Rkg1I1nvrom8rG xLBaqs8I0tQui9unfdNyYw+ctr+Q8w0BLnvC45LTTvztdAFUcMGZGDv3b4FZ/nyWGdko8q8H6L Z5Ce/mJDf/Fb0N6VCIIC8/8onbMe1HH6UGTt7VzNcADiw4scqwcl1D5GfkPXpdR1MXJW4joeVv hh+CbyBe07pzR3eHbWmHC4g3LySq3eYzjXIVnOCha3iV0kZPY7dh29cAEhviV+6RWnYYdPJriF a9g= Received: from ofwch3n02.rockwellcollins.com (HELO dtulimr02.rockwellcollins.com) ([205.175.226.14]) by ch3vs03.rockwellcollins.com with ESMTP; 03 Jun 2020 07:09:33 -0500 X-Received: from biscuits.rockwellcollins.com (biscuits.rockwellcollins.lab [10.148.119.137]) by dtulimr02.rockwellcollins.com (Postfix) with ESMTP id 222E920042; Wed, 3 Jun 2020 07:09:33 -0500 (CDT) From: Matt Weber To: buildroot@buildroot.org Date: Wed, 3 Jun 2020 07:09:31 -0500 Message-Id: <20200603120931.20551-2-matthew.weber@rockwellcollins.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200603120931.20551-1-matthew.weber@rockwellcollins.com> References: <20200603120931.20551-1-matthew.weber@rockwellcollins.com> Subject: [Buildroot] [PATCH v9 2/2] testing/tests: CLANG compiler-rt runtime test X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matt Weber , Romain Naour , Ricardo Martincoski MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This patch adds a test case that 1) Builds the complete LLVM and CLANG set of host tools 2) Cross-compiles the compiler-rt runtime using CLANG 3) Builds a cross-compiled application using CLANG and the libfuzzer compiler-rt library. 4) Executes the fuzz application (part of the libfuzzer package) on target and checks expected output for a heap-buffer-overflow. Depends on the following Clang cross-compiler series to be applied first. http://patchwork.ozlabs.org/project/buildroot/list/?series=129565 Signed-off-by: Matthew Weber Cc: Ricardo Martincoski Cc: Romain Naour Reviewed-by: Ricardo Martincoski [with the entire series applied on next branch: https://gitlab.com/RicardoMartincoski/buildroot/-/jobs/121908178 NOTE: this test case takes longer than test_rust, ~2 hours in my host machine with all tarballs previously downloaded] Tested-by: Ricardo Martincoski --- Changes v1 -> v2 [Ricardo - updated yml with test case - moved emulator launch cmd to test case from infra - defconfig in the order provided by savedefconfig - indent defconfig - add full package for test code to the test br2-external - consolidated to one class only v2 -> v3 - Added Review/tested by v4 - None v5 - Rebased post 2018.11 on master v6 - Testing of LLVM/Clang bump v7 - Rebase on master and testing of LLVM/Clang bump to 8.0 - Updated hashes for archive and legal info (legal info changed because of spelling cleanup) v8 - Cleaned up wording the 4th item of the message above. [Romain - Removes a hardcoded toolchain/sysroot path "b option" for libfuzzer pkg build, however requires this series applied. http://patchwork.ozlabs.org/project/buildroot/list/?series=129565 - updated test case to check for heap overflow string to keep arch generic - Removed the fixed mcpu arg from clang++ build and dropped --sysroot as cross compiler wrapper now provides this for libfuzzer build v9 - Rebased post 2020.05 --- .gitlab-ci.yml | 1 + .../br2-external/clang-compiler-rt/Config.in | 1 + .../clang-compiler-rt/external.desc | 1 + .../clang-compiler-rt/external.mk | 1 + .../package/libfuzzer/Config.in | 7 +++ .../package/libfuzzer/libfuzzer.hash | 2 + .../package/libfuzzer/libfuzzer.mk | 24 ++++++++++ support/testing/tests/package/test_clang.py | 46 +++++++++++++++++++ 8 files changed, 83 insertions(+) create mode 100644 support/testing/tests/package/br2-external/clang-compiler-rt/Config.in create mode 100644 support/testing/tests/package/br2-external/clang-compiler-rt/external.desc create mode 100644 support/testing/tests/package/br2-external/clang-compiler-rt/external.mk create mode 100644 support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/Config.in create mode 100644 support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.hash create mode 100644 support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.mk create mode 100644 support/testing/tests/package/test_clang.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0bf8a73b36..96a8638717 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -399,6 +399,7 @@ tests.init.test_systemd.TestInitSystemSystemdRwFull: { extends: .runtime_test } tests.init.test_systemd.TestInitSystemSystemdRwIfupdown: { extends: .runtime_test } tests.init.test_systemd.TestInitSystemSystemdRwNetworkd: { extends: .runtime_test } tests.package.test_atop.TestAtop: { extends: .runtime_test } +tests.package.test_clang.TestClangCompilerRT: { extends: .runtime_test } tests.package.test_crudini.TestCrudiniPy2: { extends: .runtime_test } tests.package.test_crudini.TestCrudiniPy3: { extends: .runtime_test } tests.package.test_docker_compose.TestDockerCompose: { extends: .runtime_test } diff --git a/support/testing/tests/package/br2-external/clang-compiler-rt/Config.in b/support/testing/tests/package/br2-external/clang-compiler-rt/Config.in new file mode 100644 index 0000000000..e1f9f8c598 --- /dev/null +++ b/support/testing/tests/package/br2-external/clang-compiler-rt/Config.in @@ -0,0 +1 @@ +source "$BR2_EXTERNAL_CLANG_COMPILER_RT_PATH/package/libfuzzer/Config.in" diff --git a/support/testing/tests/package/br2-external/clang-compiler-rt/external.desc b/support/testing/tests/package/br2-external/clang-compiler-rt/external.desc new file mode 100644 index 0000000000..92df85911d --- /dev/null +++ b/support/testing/tests/package/br2-external/clang-compiler-rt/external.desc @@ -0,0 +1 @@ +name: CLANG_COMPILER_RT diff --git a/support/testing/tests/package/br2-external/clang-compiler-rt/external.mk b/support/testing/tests/package/br2-external/clang-compiler-rt/external.mk new file mode 100644 index 0000000000..6fa55c1211 --- /dev/null +++ b/support/testing/tests/package/br2-external/clang-compiler-rt/external.mk @@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_CLANG_COMPILER_RT_PATH)/package/*/*.mk)) diff --git a/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/Config.in b/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/Config.in new file mode 100644 index 0000000000..5af5d1b6b9 --- /dev/null +++ b/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/Config.in @@ -0,0 +1,7 @@ +config BR2_PACKAGE_LIBFUZZER + bool "libfuzzer" + help + This is a set of tests (benchmarks) for fuzzing + engines (fuzzers). + + https://github.com/google/fuzzer-test-suite diff --git a/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.hash b/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.hash new file mode 100644 index 0000000000..6baf5763cf --- /dev/null +++ b/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.hash @@ -0,0 +1,2 @@ +sha256 c0addb4d7f0447fc9fd7c80e5721fafe4c137f29a8ebd94c5fef7e1d6a2c944c libfuzzer-64e4d9aa19a8d33b61882154addbf8419d7416e1.tar.gz +sha256 cfc7749b96f63bd31c3c42b5c471bf756814053e847c10f3eb003417bc523d30 LICENSE diff --git a/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.mk b/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.mk new file mode 100644 index 0000000000..1b6f9b8fee --- /dev/null +++ b/support/testing/tests/package/br2-external/clang-compiler-rt/package/libfuzzer/libfuzzer.mk @@ -0,0 +1,24 @@ +################################################################################ +# +# libfuzzer +# +################################################################################ + +LIBFUZZER_VERSION = 64e4d9aa19a8d33b61882154addbf8419d7416e1 +LIBFUZZER_SITE = $(call github,google,fuzzer-test-suite,$(LIBFUZZER_VERSION)) +LIBFUZZER_LICENSE = Apache-2.0 +LIBFUZZER_LICENSE_FILES = LICENSE +LIBFUZZER_DEPENDENCIES = compiler-rt + +define LIBFUZZER_BUILD_CMDS + $(HOST_DIR)/bin/clang++ \ + -fsanitize=address,fuzzer \ + $(@D)/tutorial/fuzz_me.cc \ + -o $(@D)/fuzz_me +endef + +define LIBFUZZER_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 755 $(@D)/fuzz_me $(TARGET_DIR)/usr/bin/fuzz_me +endef + +$(eval $(generic-package)) diff --git a/support/testing/tests/package/test_clang.py b/support/testing/tests/package/test_clang.py new file mode 100644 index 0000000000..df3990c6be --- /dev/null +++ b/support/testing/tests/package/test_clang.py @@ -0,0 +1,46 @@ +import os + +import infra.basetest + +FUZZ_TIMEOUT = 120 + + +class TestClangCompilerRT(infra.basetest.BRTest): + br2_external = [infra.filepath("tests/package/br2-external/clang-compiler-rt")] + config = \ + """ + BR2_aarch64=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0" + BR2_LINUX_KERNEL=y + BR2_LINUX_KERNEL_CUSTOM_VERSION=y + BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.16.7" + BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y + BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="board/qemu/aarch64-virt/linux.config" + BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y + BR2_PACKAGE_COMPILER_RT=y + BR2_PACKAGE_LLVM=y + BR2_TARGET_ROOTFS_CPIO=y + BR2_TARGET_ROOTFS_CPIO_GZIP=y + # BR2_TARGET_ROOTFS_TAR is not set + BR2_PACKAGE_LIBFUZZER=y + """ + + def login(self): + img = os.path.join(self.builddir, "images", "rootfs.cpio.gz") + kern = os.path.join(self.builddir, "images", "Image") + # Sanitizers overallocate memory and the minimum that seemed to work was 512MB + self.emulator.boot(arch="aarch64", + kernel=kern, + kernel_cmdline=["console=ttyAMA0"], + options=["-M", "virt", "-cpu", "cortex-a53", "-m", "512", "-initrd", img]) + self.emulator.login() + + def test_run(self): + self.login() + + # The test case verifies the application executes and that + # the symbolizer is working to decode the stack trace. + cmd = "fuzz_me 2>&1 | grep heap-buffer-overflow" + _, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT) + self.assertEqual(exit_code, 0)