All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support
@ 2019-05-01 19:40 Matt Weber
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools Matt Weber
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Matt Weber @ 2019-05-01 19:40 UTC (permalink / raw)
  To: buildroot

This series adds the ability to perform security fuzzing on
target for custom applications as well as against other open
source projects which have existing libfuzzer frameworks.

What is Fuzzing?

"Fuzz testing or fuzzing is a software testing technique, often
automated or semi-automated, that involves providing invalid,
unexpected, or random data to the inputs of a computer program.
The program is then monitored for exceptions such as crashes, or
failing built-in code assertions or for finding potential memory
Leaks.? - Wikipedia

Compiler-RT's Libfuzzer - https://llvm.org/docs/LibFuzzer.html
Works at the software level like a unit or component test
- Target is code rather than system interface
- Specifically for C and C++
Catch bugs sooner in the development cycle
- Testing can begin before software is fully integrated
Evolutionary fuzzer
- No structural data modeling required
- Uses code coverage of a test case to compute fitness score
  in evolutionary algorithm

Sanitizers
- Dynamic analysis tools designed to look for runtime errors
- The sanitizers in this series are built with debug symbols
  and will point to the exact line of code where the error
  occurs. Sanitizers can be used with both GCC and CLANG.
   Address Sanitizer
    -fsanitize=address
   Leak Sanitizer
    -fsanitize=leak
   Undefined behavior Sanitizer
    -fsanitize=undefined
   Thread Sanitizer
    -fsanitize=thread


Matt Weber (5):
  package/llvm: install target binary/debug tools
  package llvm/clang: note about version bumping dep
  package/llvm: disable libxml2
  package/compiler-rt: new package
  testing/tests: CLANG compiler-rt runtime test

 .gitlab-ci.yml                                |  1 +
 DEVELOPERS                                    |  1 +
 package/Config.in                             |  1 +
 package/clang/clang.mk                        |  1 +
 package/compiler-rt/Config.in                 | 14 ++++++
 package/compiler-rt/compiler-rt.hash          |  3 ++
 package/compiler-rt/compiler-rt.mk            | 36 +++++++++++++++
 package/llvm/llvm.mk                          | 17 ++++++-
 .../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 +++++++++++++++++++
 15 files changed, 155 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
 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

-- 
2.17.1

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools
  2019-05-01 19:40 [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support Matt Weber
@ 2019-05-01 19:40 ` Matt Weber
  2019-08-01  8:28   ` Romain Naour
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 2/5] package llvm/clang: note about version bumping dep Matt Weber
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Matt Weber @ 2019-05-01 19:40 UTC (permalink / raw)
  To: buildroot

The compiler-rt fuzzer and address sanitizer tools require additional
LLVM binary tools installed to allow stack trace decoding actively during
executable analysis.

https://github.com/google/sanitizers/wiki/AddressSanitizerCallStack

Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
Reviewed-by: Romain Naour <romain.naour@smile.fr>
---
Changes
v1 -> v3
 - None

v4
 - Added new patch for llvm dependency on libxml2 which was noticed
   during testing

v5
 - Rebased post 2018.11 on master

v6
 - Testing against LLVM/Clang version bump 7.0.1

v7
 - Testing against LLVM/CLang version bump to 8.0
---
 package/llvm/llvm.mk | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
index 3c62285188..7186c91cb7 100644
--- a/package/llvm/llvm.mk
+++ b/package/llvm/llvm.mk
@@ -207,8 +207,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
 
 # Compiler-rt not in the source tree.
 # llvm runtime libraries are not in the source tree.
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 2/5] package llvm/clang: note about version bumping dep
  2019-05-01 19:40 [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support Matt Weber
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools Matt Weber
@ 2019-05-01 19:40 ` Matt Weber
  2019-08-01 16:42   ` Arnout Vandecappelle
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 3/5] package/llvm: disable libxml2 Matt Weber
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Matt Weber @ 2019-05-01 19:40 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
Acked-by: Romain Naour <romain.naour@smile.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
--

This patch can be applied independent of the compiler-rt series.

Changes
v1 -> v2
 - None

v2 -> v3
[Ricardo
 - Added compiler-rt to list of items to bump. I originaly had kept this
   patch independent of the compiler-rt series but since compiler-rt is
   first in the series, this one may as well include it in the statements

v4
 - None

v5
 - Rebased post 2018.11 on master

v6
 - Rebased after LLVM/Clang bump to 7.0.1

v7
 - Updated patch so it could be applied independent of compiler-rt
---
 package/clang/clang.mk | 1 +
 package/llvm/llvm.mk   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index 0cab1c7f89..07e7fced2a 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -4,6 +4,7 @@
 #
 ################################################################################
 
+# LLVM and Clang should be version bumped together
 CLANG_VERSION = 8.0.0
 CLANG_SITE = http://llvm.org/releases/$(CLANG_VERSION)
 CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
index 7186c91cb7..a1c0167ff6 100644
--- a/package/llvm/llvm.mk
+++ b/package/llvm/llvm.mk
@@ -4,6 +4,7 @@
 #
 ################################################################################
 
+# LLVM and Clang should be version bumped together
 LLVM_VERSION = 8.0.0
 LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
 LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 3/5] package/llvm: disable libxml2
  2019-05-01 19:40 [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support Matt Weber
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools Matt Weber
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 2/5] package llvm/clang: note about version bumping dep Matt Weber
@ 2019-05-01 19:40 ` Matt Weber
  2019-08-01 16:43   ` Arnout Vandecappelle
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package Matt Weber
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test Matt Weber
  4 siblings, 1 reply; 14+ messages in thread
From: Matt Weber @ 2019-05-01 19:40 UTC (permalink / raw)
  To: buildroot

libxml2 is needed during Windows builds to populate the COFF
file manifest info.  This isn't required for Linux builds.

Cc: Romain Naour <romain.naour@gmail.com>
Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
--
This change was discovered during testing of compiler-rt
patchset.  This patch could be independently applied.

v4
 - New patch

v5
 - Rebased post 2018.11 on master

v6
 - Updated comment about dependencies (Romain)
---
 package/llvm/llvm.mk | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
index a1c0167ff6..9d276c5190 100644
--- a/package/llvm/llvm.mk
+++ b/package/llvm/llvm.mk
@@ -133,6 +133,11 @@ HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_ZLIB=ON
 HOST_LLVM_DEPENDENCIES += host-zlib
 LLVM_CONF_OPTS += -DLLVM_ENABLE_ZLIB=OFF
 
+# libxml2 can be disabled as it is used for LLVM Windows builds where COFF
+# files include manifest info
+HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_LIBXML2=OFF
+LLVM_CONF_OPTS += -DLLVM_ENABLE_LIBXML2=OFF
+
 # We don't use llvm for static only build, so enable PIC
 HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_PIC=ON
 LLVM_CONF_OPTS += -DLLVM_ENABLE_PIC=ON
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package
  2019-05-01 19:40 [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support Matt Weber
                   ` (2 preceding siblings ...)
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 3/5] package/llvm: disable libxml2 Matt Weber
@ 2019-05-01 19:40 ` Matt Weber
  2019-05-07 11:54   ` Romain Naour
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test Matt Weber
  4 siblings, 1 reply; 14+ messages in thread
From: Matt Weber @ 2019-05-01 19:40 UTC (permalink / raw)
  To: 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.

Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
Cc: Romain Naour <romain.naour@smile.fr>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
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)
---
 DEVELOPERS                           |  1 +
 package/Config.in                    |  1 +
 package/clang/clang.mk               |  2 +-
 package/compiler-rt/Config.in        | 14 +++++++++++
 package/compiler-rt/compiler-rt.hash |  3 +++
 package/compiler-rt/compiler-rt.mk   | 36 ++++++++++++++++++++++++++++
 package/llvm/llvm.mk                 |  2 +-
 7 files changed, 57 insertions(+), 2 deletions(-)
 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 6ccb0afaf6..72a635a81a 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1467,6 +1467,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 f592e74a99..99fcf49a63 100644
--- a/package/Config.in
+++ b/package/Config.in
@@ -1652,6 +1652,7 @@ menu "Other"
 	source "package/clapack/Config.in"
 	source "package/classpath/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/clang/clang.mk b/package/clang/clang.mk
index 07e7fced2a..87a80ab258 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-# LLVM and Clang should be version bumped together
+# LLVM, Compiler-rt and Clang should be version bumped together
 CLANG_VERSION = 8.0.0
 CLANG_SITE = http://llvm.org/releases/$(CLANG_VERSION)
 CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
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..4b6bd1a75e
--- /dev/null
+++ b/package/compiler-rt/compiler-rt.hash
@@ -0,0 +1,3 @@
+# Locally computed:
+sha256 782edfc119ee172f169c91dd79f2c964fb6b248bd9b73523149030ed505bbe18  compiler-rt-7.0.1.src.tar.xz
+sha256 417541d990edb3f96327ac03cb67e52eac80fc5c3e7afc69213cd04d7c3b9b27  LICENSE.TXT
diff --git a/package/compiler-rt/compiler-rt.mk b/package/compiler-rt/compiler-rt.mk
new file mode 100644
index 0000000000..7eda3bc4fe
--- /dev/null
+++ b/package/compiler-rt/compiler-rt.mk
@@ -0,0 +1,36 @@
+################################################################################
+#
+# 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 = 8.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
+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 9d276c5190..cd07860068 100644
--- a/package/llvm/llvm.mk
+++ b/package/llvm/llvm.mk
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-# LLVM and Clang should be version bumped together
+# LLVM, Compiler-rt and Clang should be version bumped together
 LLVM_VERSION = 8.0.0
 LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
 LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test
  2019-05-01 19:40 [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support Matt Weber
                   ` (3 preceding siblings ...)
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package Matt Weber
@ 2019-05-01 19:40 ` Matt Weber
  2019-05-07 21:12   ` Romain Naour
  4 siblings, 1 reply; 14+ messages in thread
From: Matt Weber @ 2019-05-01 19:40 UTC (permalink / raw)
  To: 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

Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>

Reviewed-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
[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 <ricardo.martincoski@gmail.com>
---
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)
---
 .gitlab-ci.yml                                |  1 +
 package/compiler-rt/compiler-rt.hash          |  4 +-
 .../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 +++++++++++++++++++
 9 files changed, 85 insertions(+), 2 deletions(-)
 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 558676709f..9a35a1cab8 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -357,6 +357,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_docker_compose.TestDockerCompose: { extends: .runtime_test }
 tests.package.test_dropbear.TestDropbear: { extends: .runtime_test }
 tests.package.test_glxinfo.TestGlxinfo: { extends: .runtime_test }
diff --git a/package/compiler-rt/compiler-rt.hash b/package/compiler-rt/compiler-rt.hash
index 4b6bd1a75e..ead0171551 100644
--- a/package/compiler-rt/compiler-rt.hash
+++ b/package/compiler-rt/compiler-rt.hash
@@ -1,3 +1,3 @@
 # Locally computed:
-sha256 782edfc119ee172f169c91dd79f2c964fb6b248bd9b73523149030ed505bbe18  compiler-rt-7.0.1.src.tar.xz
-sha256 417541d990edb3f96327ac03cb67e52eac80fc5c3e7afc69213cd04d7c3b9b27  LICENSE.TXT
+sha256 b435c7474f459e71b2831f1a4e3f1d21203cb9c0172e94e9d9b69f50354f21b1  compiler-rt-8.0.0.src.tar.xz
+sha256 dd27f8c290bcdc8368549cd7cd98710a9dbdc34122f2e096a1edb97824ed4148  LICENSE.TXT
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..7d6f83b4d3
--- /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++ -mcpu=cortex-a53 --sysroot=$(STAGING_DIR) \
+		-B $(HOST_DIR)/opt/ext-toolchain -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..84a2528b00
--- /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 both that the application executes and that
+        # the symbolizer is working to decode the stack trace
+        cmd = "fuzz_me 2>&1 | grep _M_replace"
+        _, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT)
+        self.assertEqual(exit_code, 0)
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package Matt Weber
@ 2019-05-07 11:54   ` Romain Naour
  2019-05-07 13:19     ` Matthew Weber
  0 siblings, 1 reply; 14+ messages in thread
From: Romain Naour @ 2019-05-07 11:54 UTC (permalink / raw)
  To: buildroot

Le 01/05/2019 ? 21:40, Matt Weber a ?crit?:
> 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.
> 
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> Cc: Romain Naour <romain.naour@smile.fr>
> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
> ---
> 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)
> ---
>  DEVELOPERS                           |  1 +
>  package/Config.in                    |  1 +
>  package/clang/clang.mk               |  2 +-
>  package/compiler-rt/Config.in        | 14 +++++++++++
>  package/compiler-rt/compiler-rt.hash |  3 +++
>  package/compiler-rt/compiler-rt.mk   | 36 ++++++++++++++++++++++++++++
>  package/llvm/llvm.mk                 |  2 +-
>  7 files changed, 57 insertions(+), 2 deletions(-)
>  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 6ccb0afaf6..72a635a81a 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -1467,6 +1467,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 f592e74a99..99fcf49a63 100644
> --- a/package/Config.in
> +++ b/package/Config.in
> @@ -1652,6 +1652,7 @@ menu "Other"
>  	source "package/clapack/Config.in"
>  	source "package/classpath/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/clang/clang.mk b/package/clang/clang.mk
> index 07e7fced2a..87a80ab258 100644
> --- a/package/clang/clang.mk
> +++ b/package/clang/clang.mk
> @@ -4,7 +4,7 @@
>  #
>  ################################################################################
>  
> -# LLVM and Clang should be version bumped together
> +# LLVM, Compiler-rt and Clang should be version bumped together
>  CLANG_VERSION = 8.0.0
>  CLANG_SITE = http://llvm.org/releases/$(CLANG_VERSION)
>  CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
> 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..4b6bd1a75e
> --- /dev/null
> +++ b/package/compiler-rt/compiler-rt.hash
> @@ -0,0 +1,3 @@
> +# Locally computed:
> +sha256 782edfc119ee172f169c91dd79f2c964fb6b248bd9b73523149030ed505bbe18  compiler-rt-7.0.1.src.tar.xz
> +sha256 417541d990edb3f96327ac03cb67e52eac80fc5c3e7afc69213cd04d7c3b9b27  LICENSE.TXT

The hashes must be updated after the bump to llvm/clang 8.0.0 :)

Best regards,
Romain

> diff --git a/package/compiler-rt/compiler-rt.mk b/package/compiler-rt/compiler-rt.mk
> new file mode 100644
> index 0000000000..7eda3bc4fe
> --- /dev/null
> +++ b/package/compiler-rt/compiler-rt.mk
> @@ -0,0 +1,36 @@
> +################################################################################
> +#
> +# 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 = 8.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
> +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 9d276c5190..cd07860068 100644
> --- a/package/llvm/llvm.mk
> +++ b/package/llvm/llvm.mk
> @@ -4,7 +4,7 @@
>  #
>  ################################################################################
>  
> -# LLVM and Clang should be version bumped together
> +# LLVM, Compiler-rt and Clang should be version bumped together
>  LLVM_VERSION = 8.0.0
>  LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
>  LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package
  2019-05-07 11:54   ` Romain Naour
@ 2019-05-07 13:19     ` Matthew Weber
  0 siblings, 0 replies; 14+ messages in thread
From: Matthew Weber @ 2019-05-07 13:19 UTC (permalink / raw)
  To: buildroot

Romain,

On Tue, May 7, 2019 at 6:54 AM Romain Naour <romain.naour@smile.fr> wrote:
>
> Le 01/05/2019 ? 21:40, Matt Weber a ?crit :
> > 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.
> >
> > Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> > Cc: Romain Naour <romain.naour@smile.fr>
> > Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> > Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
> > ---
> > 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)
> > ---
> >  DEVELOPERS                           |  1 +
> >  package/Config.in                    |  1 +
> >  package/clang/clang.mk               |  2 +-
> >  package/compiler-rt/Config.in        | 14 +++++++++++
> >  package/compiler-rt/compiler-rt.hash |  3 +++
> >  package/compiler-rt/compiler-rt.mk   | 36 ++++++++++++++++++++++++++++
> >  package/llvm/llvm.mk                 |  2 +-
> >  7 files changed, 57 insertions(+), 2 deletions(-)
> >  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 6ccb0afaf6..72a635a81a 100644
> > --- a/DEVELOPERS
> > +++ b/DEVELOPERS
> > @@ -1467,6 +1467,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 f592e74a99..99fcf49a63 100644
> > --- a/package/Config.in
> > +++ b/package/Config.in
> > @@ -1652,6 +1652,7 @@ menu "Other"
> >       source "package/clapack/Config.in"
> >       source "package/classpath/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/clang/clang.mk b/package/clang/clang.mk
> > index 07e7fced2a..87a80ab258 100644
> > --- a/package/clang/clang.mk
> > +++ b/package/clang/clang.mk
> > @@ -4,7 +4,7 @@
> >  #
> >  ################################################################################
> >
> > -# LLVM and Clang should be version bumped together
> > +# LLVM, Compiler-rt and Clang should be version bumped together
> >  CLANG_VERSION = 8.0.0
> >  CLANG_SITE = http://llvm.org/releases/$(CLANG_VERSION)
> >  CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
> > 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..4b6bd1a75e
> > --- /dev/null
> > +++ b/package/compiler-rt/compiler-rt.hash
> > @@ -0,0 +1,3 @@
> > +# Locally computed:
> > +sha256 782edfc119ee172f169c91dd79f2c964fb6b248bd9b73523149030ed505bbe18  compiler-rt-7.0.1.src.tar.xz
> > +sha256 417541d990edb3f96327ac03cb67e52eac80fc5c3e7afc69213cd04d7c3b9b27  LICENSE.TXT
>
> The hashes must be updated after the bump to llvm/clang 8.0.0 :)

Good call, I've made that update but it must have slipped out of my
rebase :-)  Will update pending other feedbac.

>
> Best regards,
> Romain
>
> > diff --git a/package/compiler-rt/compiler-rt.mk b/package/compiler-rt/compiler-rt.mk
> > new file mode 100644
> > index 0000000000..7eda3bc4fe
> > --- /dev/null
> > +++ b/package/compiler-rt/compiler-rt.mk
> > @@ -0,0 +1,36 @@
> > +################################################################################
> > +#
> > +# 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 = 8.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
> > +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 9d276c5190..cd07860068 100644
> > --- a/package/llvm/llvm.mk
> > +++ b/package/llvm/llvm.mk
> > @@ -4,7 +4,7 @@
> >  #
> >  ################################################################################
> >
> > -# LLVM and Clang should be version bumped together
> > +# LLVM, Compiler-rt and Clang should be version bumped together
> >  LLVM_VERSION = 8.0.0
> >  LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
> >  LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
> >
>


-- 

Matthew Weber | Pr. Software Engineer | Commercial Avionics

COLLINS AEROSPACE

400 Collins Road NE, Cedar Rapids, Iowa 52498, USA

Tel: +1 319 295 7349 | FAX: +1 319 263 6099

matthew.weber at collins.com | collinsaerospace.com



CONFIDENTIALITY WARNING: This message may contain proprietary and/or
privileged information of Collins Aerospace and its affiliated
companies. If you are not the intended recipient, please 1) Do not
disclose, copy, distribute or use this message or its contents. 2)
Advise the sender by return email. 3) Delete all copies (including all
attachments) from your computer. Your cooperation is greatly
appreciated.


Any export restricted material should be shared using my
matthew.weber at corp.rockwellcollins.com address.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test Matt Weber
@ 2019-05-07 21:12   ` Romain Naour
  2019-08-01  8:32     ` Romain Naour
  0 siblings, 1 reply; 14+ messages in thread
From: Romain Naour @ 2019-05-07 21:12 UTC (permalink / raw)
  To: buildroot

Hi Matt,

Le 01/05/2019 ? 21:40, Matt Weber a ?crit?:
> 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

Can you provide an example of expected output of fuzz_me ?
I tried on x86_64 bit but I get an error: AddressSanitizer: heap-buffer-overflow

I'm testing with aarch64 at the moment.

> 
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> 
> Reviewed-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> [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 <ricardo.martincoski@gmail.com>
> ---

[snip]

6814053e847c10f3eb003417bc523d30  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..7d6f83b4d3
> --- /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++ -mcpu=cortex-a53 --sysroot=$(STAGING_DIR) \

There is no -mcpu option with clang++, I had to use -march=x86-64 instead.

> +		-B $(HOST_DIR)/opt/ext-toolchain -fsanitize=address,fuzzer \

Using $(HOST_DIR)/opt/ext-toolchain expect an external toolchain (this is the
case during the test), but it doesn't work for internal toolchain or external
pre-installed toolchain.

Clang++ is using the path provided by -B to find crtbegin.o. This object file is
not copied when using a pre-installed toolchain.

https://pastebin.com/Wm59Z9nz

Best regards,
Romain

> +		$(@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..84a2528b00
> --- /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 both that the application executes and that
> +        # the symbolizer is working to decode the stack trace
> +        cmd = "fuzz_me 2>&1 | grep _M_replace"
> +        _, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT)
> +        self.assertEqual(exit_code, 0)
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools Matt Weber
@ 2019-08-01  8:28   ` Romain Naour
  0 siblings, 0 replies; 14+ messages in thread
From: Romain Naour @ 2019-08-01  8:28 UTC (permalink / raw)
  To: buildroot

Hi Matt,

Le 01/05/2019 ? 21:40, Matt Weber a ?crit?:
> The compiler-rt fuzzer and address sanitizer tools require additional
> LLVM binary tools installed to allow stack trace decoding actively during
> executable analysis.
> 
> https://github.com/google/sanitizers/wiki/AddressSanitizerCallStack
> 
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> Reviewed-by: Romain Naour <romain.naour@smile.fr>
> ---
> Changes
> v1 -> v3
>  - None
> 
> v4
>  - Added new patch for llvm dependency on libxml2 which was noticed
>    during testing
> 
> v5
>  - Rebased post 2018.11 on master
> 
> v6
>  - Testing against LLVM/Clang version bump 7.0.1
> 
> v7
>  - Testing against LLVM/CLang version bump to 8.0
> ---
>  package/llvm/llvm.mk | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
> index 3c62285188..7186c91cb7 100644
> --- a/package/llvm/llvm.mk
> +++ b/package/llvm/llvm.mk
> @@ -207,8 +207,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)

Actually using a symbol before it's introduced by a follow-up patch is not
recommended.

Maybe this patch should be squashed to the patch 4/5

Best regards,
Romain

> +LLVM_CONF_OPTS += \
> +	-DLLVM_BUILD_TOOLS=ON
> +else
> +LLVM_CONF_OPTS += \
>  	-DLLVM_BUILD_TOOLS=OFF
> +endif
>  
>  # Compiler-rt not in the source tree.
>  # llvm runtime libraries are not in the source tree.
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test
  2019-05-07 21:12   ` Romain Naour
@ 2019-08-01  8:32     ` Romain Naour
  2019-08-02 18:13       ` Matthew Weber
  0 siblings, 1 reply; 14+ messages in thread
From: Romain Naour @ 2019-08-01  8:32 UTC (permalink / raw)
  To: buildroot

Hi Matt,

Le 07/05/2019 ? 23:12, Romain Naour a ?crit?:
> Hi Matt,
> 
> Le 01/05/2019 ? 21:40, Matt Weber a ?crit?:
>> 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
> 
> Can you provide an example of expected output of fuzz_me ?
> I tried on x86_64 bit but I get an error: AddressSanitizer: heap-buffer-overflow

Ok, getting a heap-buffer-overflow is the purpose of this example :p
> 
> I'm testing with aarch64 at the moment.
> 
>>
>> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
>> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
>>
>> Reviewed-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
>> [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 <ricardo.martincoski@gmail.com>
>> ---
> 
> [snip]
> 
> 6814053e847c10f3eb003417bc523d30  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..7d6f83b4d3
>> --- /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++ -mcpu=cortex-a53 --sysroot=$(STAGING_DIR) \
> 
> There is no -mcpu option with clang++, I had to use -march=x86-64 instead.
> 
>> +		-B $(HOST_DIR)/opt/ext-toolchain -fsanitize=address,fuzzer \
> 
> Using $(HOST_DIR)/opt/ext-toolchain expect an external toolchain (this is the
> case during the test), but it doesn't work for internal toolchain or external
> pre-installed toolchain.
> 
> Clang++ is using the path provided by -B to find crtbegin.o. This object file is
> not copied when using a pre-installed toolchain.
> 
> https://pastebin.com/Wm59Z9nz
> 
> Best regards,
> Romain
> 
>> +		$(@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..84a2528b00
>> --- /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 both that the application executes and that
>> +        # the symbolizer is working to decode the stack trace
>> +        cmd = "fuzz_me 2>&1 | grep _M_replace"

Can you explain why the test is looking at _M_replace in the log of fuzz_me ?
It seems specific to aarch64 backtrace.

Best regards,
Romain

>> +        _, exit_code = self.emulator.run(cmd, FUZZ_TIMEOUT)
>> +        self.assertEqual(exit_code, 0)
>>
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 2/5] package llvm/clang: note about version bumping dep
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 2/5] package llvm/clang: note about version bumping dep Matt Weber
@ 2019-08-01 16:42   ` Arnout Vandecappelle
  0 siblings, 0 replies; 14+ messages in thread
From: Arnout Vandecappelle @ 2019-08-01 16:42 UTC (permalink / raw)
  To: buildroot



On 01/05/2019 21:40, Matt Weber wrote:
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> Acked-by: Romain Naour <romain.naour@smile.fr>
> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>

 Applied to master, thanks.

 Regards,
 Arnout

> --
> 
> This patch can be applied independent of the compiler-rt series.
> 
> Changes
> v1 -> v2
>  - None
> 
> v2 -> v3
> [Ricardo
>  - Added compiler-rt to list of items to bump. I originaly had kept this
>    patch independent of the compiler-rt series but since compiler-rt is
>    first in the series, this one may as well include it in the statements
> 
> v4
>  - None
> 
> v5
>  - Rebased post 2018.11 on master
> 
> v6
>  - Rebased after LLVM/Clang bump to 7.0.1
> 
> v7
>  - Updated patch so it could be applied independent of compiler-rt
> ---
>  package/clang/clang.mk | 1 +
>  package/llvm/llvm.mk   | 1 +
>  2 files changed, 2 insertions(+)
> 
> diff --git a/package/clang/clang.mk b/package/clang/clang.mk
> index 0cab1c7f89..07e7fced2a 100644
> --- a/package/clang/clang.mk
> +++ b/package/clang/clang.mk
> @@ -4,6 +4,7 @@
>  #
>  ################################################################################
>  
> +# LLVM and Clang should be version bumped together
>  CLANG_VERSION = 8.0.0
>  CLANG_SITE = http://llvm.org/releases/$(CLANG_VERSION)
>  CLANG_SOURCE = cfe-$(CLANG_VERSION).src.tar.xz
> diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
> index 7186c91cb7..a1c0167ff6 100644
> --- a/package/llvm/llvm.mk
> +++ b/package/llvm/llvm.mk
> @@ -4,6 +4,7 @@
>  #
>  ################################################################################
>  
> +# LLVM and Clang should be version bumped together
>  LLVM_VERSION = 8.0.0
>  LLVM_SITE = http://llvm.org/releases/$(LLVM_VERSION)
>  LLVM_SOURCE = llvm-$(LLVM_VERSION).src.tar.xz
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 3/5] package/llvm: disable libxml2
  2019-05-01 19:40 ` [Buildroot] [PATCH v7 3/5] package/llvm: disable libxml2 Matt Weber
@ 2019-08-01 16:43   ` Arnout Vandecappelle
  0 siblings, 0 replies; 14+ messages in thread
From: Arnout Vandecappelle @ 2019-08-01 16:43 UTC (permalink / raw)
  To: buildroot



On 01/05/2019 21:40, Matt Weber wrote:
> libxml2 is needed during Windows builds to populate the COFF
> file manifest info.  This isn't required for Linux builds.
> 
> Cc: Romain Naour <romain.naour@gmail.com>
> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>

 Applied to master, thanks.

 Regards,
 Arnout

> --
> This change was discovered during testing of compiler-rt
> patchset.  This patch could be independently applied.
> 
> v4
>  - New patch
> 
> v5
>  - Rebased post 2018.11 on master
> 
> v6
>  - Updated comment about dependencies (Romain)
> ---
>  package/llvm/llvm.mk | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/package/llvm/llvm.mk b/package/llvm/llvm.mk
> index a1c0167ff6..9d276c5190 100644
> --- a/package/llvm/llvm.mk
> +++ b/package/llvm/llvm.mk
> @@ -133,6 +133,11 @@ HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_ZLIB=ON
>  HOST_LLVM_DEPENDENCIES += host-zlib
>  LLVM_CONF_OPTS += -DLLVM_ENABLE_ZLIB=OFF
>  
> +# libxml2 can be disabled as it is used for LLVM Windows builds where COFF
> +# files include manifest info
> +HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_LIBXML2=OFF
> +LLVM_CONF_OPTS += -DLLVM_ENABLE_LIBXML2=OFF
> +
>  # We don't use llvm for static only build, so enable PIC
>  HOST_LLVM_CONF_OPTS += -DLLVM_ENABLE_PIC=ON
>  LLVM_CONF_OPTS += -DLLVM_ENABLE_PIC=ON
> 

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test
  2019-08-01  8:32     ` Romain Naour
@ 2019-08-02 18:13       ` Matthew Weber
  0 siblings, 0 replies; 14+ messages in thread
From: Matthew Weber @ 2019-08-02 18:13 UTC (permalink / raw)
  To: buildroot

Romain,


On Thu, Aug 1, 2019 at 3:32 AM Romain Naour <romain.naour@smile.fr> wrote:
>
> Hi Matt,
>
> Le 07/05/2019 ? 23:12, Romain Naour a ?crit :
> > Hi Matt,
> >
> > Le 01/05/2019 ? 21:40, Matt Weber a ?crit :
> >> 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
> >
> > Can you provide an example of expected output of fuzz_me ?
> > I tried on x86_64 bit but I get an error: AddressSanitizer: heap-buffer-overflow
>
> Ok, getting a heap-buffer-overflow is the purpose of this example :p

I'll update my comment for 4)
"Executes the fuzz application (part of the libfuzzer package) on
target and checks expected output for a heap-buffer-overflow."

> >
> > I'm testing with aarch64 at the moment.
> >
> >>
> >> Signed-off-by: Matthew Weber <matthew.weber@rockwellcollins.com>
> >> Cc: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> >>
> >> Reviewed-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
> >> [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 <ricardo.martincoski@gmail.com>
> >> ---
> >
> > [snip]
> >
> > 6814053e847c10f3eb003417bc523d30  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..7d6f83b4d3
> >> --- /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++ -mcpu=cortex-a53 --sysroot=$(STAGING_DIR) \
> >
> > There is no -mcpu option with clang++, I had to use -march=x86-64 instead.
> >
> >> +            -B $(HOST_DIR)/opt/ext-toolchain -fsanitize=address,fuzzer \
> >
> > Using $(HOST_DIR)/opt/ext-toolchain expect an external toolchain (this is the
> > case during the test), but it doesn't work for internal toolchain or external
> > pre-installed toolchain.
> >
> > Clang++ is using the path provided by -B to find crtbegin.o. This object file is
> > not copied when using a pre-installed toolchain.
> >
> > https://pastebin.com/Wm59Z9nz

I assume I make have to do this conditionally based on the toolchain
type? I don't believe our host dir setup is consistent between the
toolchain type.

> >
> > Best regards,
> > Romain
> >
> >> +            $(@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..84a2528b00
> >> --- /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 both that the application executes and that
> >> +        # the symbolizer is working to decode the stack trace
> >> +        cmd = "fuzz_me 2>&1 | grep _M_replace"
>
> Can you explain why the test is looking at _M_replace in the log of fuzz_me ?
> It seems specific to aarch64 backtrace.

Correct, I just verify the application executes with an expected
symbolizer string being displayed.  It may not be arch independent as
you pointed out.

Thanks for the review, I'll do some investigation further on the
toolchain link path stuff above between the toolchain types.

Matt

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-08-02 18:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-01 19:40 [Buildroot] [PATCH v7 0/5] Compiler-rt Security Fuzzing Support Matt Weber
2019-05-01 19:40 ` [Buildroot] [PATCH v7 1/5] package/llvm: install target binary/debug tools Matt Weber
2019-08-01  8:28   ` Romain Naour
2019-05-01 19:40 ` [Buildroot] [PATCH v7 2/5] package llvm/clang: note about version bumping dep Matt Weber
2019-08-01 16:42   ` Arnout Vandecappelle
2019-05-01 19:40 ` [Buildroot] [PATCH v7 3/5] package/llvm: disable libxml2 Matt Weber
2019-08-01 16:43   ` Arnout Vandecappelle
2019-05-01 19:40 ` [Buildroot] [PATCH v7 4/5] package/compiler-rt: new package Matt Weber
2019-05-07 11:54   ` Romain Naour
2019-05-07 13:19     ` Matthew Weber
2019-05-01 19:40 ` [Buildroot] [PATCH v7 5/5] testing/tests: CLANG compiler-rt runtime test Matt Weber
2019-05-07 21:12   ` Romain Naour
2019-08-01  8:32     ` Romain Naour
2019-08-02 18:13       ` Matthew Weber

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.