Hello community, here is the log from the commit of package llvm9 for openSUSE:Factory checked in at 2020-01-16 18:18:04 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/llvm9 (Old) and /work/SRC/openSUSE:Factory/.llvm9.new.26092 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "llvm9" Thu Jan 16 18:18:04 2020 rev:7 rq:763932 version:9.0.1 Changes: -------- --- /work/SRC/openSUSE:Factory/llvm9/llvm9.changes 2020-01-06 16:01:50.213714848 +0100 +++ /work/SRC/openSUSE:Factory/.llvm9.new.26092/llvm9.changes 2020-01-16 18:18:16.692874262 +0100 @@ -1,0 +2,18 @@ +Sat Jan 11 20:14:12 UTC 2020 - Andreas Schwab <[email protected]> + +- riscv-eh-frame-fixup.patch: Remove changesets that alter the libLLVM ABI + +------------------------------------------------------------------- +Fri Jan 8 15:30:21 UTC 2020 - Jaime CaamaƱo Ruiz <[email protected]> + +- Add upstream patch to export compiler-rt FuzzedDataProvider header, + required by Envoy 1.12.2: + * compiler-rt-move-fdp.patch + +------------------------------------------------------------------- +Mon Jan 6 19:31:23 UTC 2020 - Andreas Schwab <[email protected]> + +- riscv-eh-frame-fixup.patch: Fix handling of .eh_frame on RISC-V +- polly-pthread.patch: Add missing -lpthread + +------------------------------------------------------------------- New: ---- compiler-rt-move-fdp.patch polly-pthread.patch riscv-eh-frame-fixup.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ llvm9.spec ++++++ --- /var/tmp/diff_new_pack.9a9Oca/_old 2020-01-16 18:18:28.376880871 +0100 +++ /var/tmp/diff_new_pack.9a9Oca/_new 2020-01-16 18:18:28.376880871 +0100 @@ -39,33 +39,27 @@ %else %bcond_without gold %endif - %ifarch x86_64 %bcond_without lldb - %if 0%{?suse_version} > 1320 # lldb python breaks with swig < 3.0.11 %bcond_without lldb_python %else %bcond_with lldb_python %endif - %else %bcond_with lldb %bcond_with lldb_python %endif - -%bcond_with ffi -%bcond_with oprofile -%bcond_with valgrind -%bcond_without pyclang - %ifarch %{arm} x86_64 %{ix86} ppc64le s390x %bcond_without thin_lto %else %bcond_with thin_lto %endif - +%bcond_with ffi +%bcond_with oprofile +%bcond_with valgrind +%bcond_without pyclang Name: llvm9 Version: 9.0.1 Release: 0 @@ -122,12 +116,17 @@ Patch31: riscv64-suse-linux.patch Patch32: llvm-riscv64-fix-cffi.diff Patch33: D60657-riscv-pcrel_lo.diff +# Backport of .eh_frame related RISC-V fixes (D61584, D63404, D66419) +Patch34: riscv-eh-frame-fixup.patch +# PATCH-FIX-OPENSUSE polly-pthread.patch -- Make sure -lpthread is linked after libPollly +Patch35: polly-pthread.patch +# PATCH-FEATURE_UPSTREAM compiler-rt-move-fdp.patch -- Move FuzzedDataProvider to include +Patch36: compiler-rt-move-fdp.patch BuildRequires: binutils-devel >= 2.21.90 -%if %{with gold} -BuildRequires: binutils-gold -%endif BuildRequires: cmake BuildRequires: fdupes +BuildRequires: gcc +BuildRequires: gcc-c++ BuildRequires: libstdc++-devel BuildRequires: libtool BuildRequires: ninja @@ -139,11 +138,12 @@ Requires: libLLVM%{_sonum} Requires(post): update-alternatives Requires(postun): update-alternatives -BuildRoot: %{_tmppath}/%{name}-%{version}-build +Recommends: %{name}-doc # llvm does not work on s390 ExcludeArch: s390 -BuildRequires: gcc -BuildRequires: gcc-c++ +%if %{with gold} +BuildRequires: binutils-gold +%endif %if %{with ffi} BuildRequires: pkgconfig(libffi) %endif @@ -153,7 +153,6 @@ %if %{with oprofile} BuildRequires: oprofile-devel %endif -Recommends: %{name}-doc %description LLVM is a compiler infrastructure designed for compile-time, @@ -180,9 +179,9 @@ Requires: llvm%{_sonum}-gold Requires: llvm%{_sonum}-polly-devel Requires: pkgconfig -Provides: llvm-devel-provider = %{version} Conflicts: llvm-devel-provider < %{version} Conflicts: cmake(LLVM) +Provides: llvm-devel-provider = %{version} %if %{with ffi} Requires: pkgconfig(libffi) %endif @@ -201,11 +200,11 @@ Summary: Documentation for LLVM Group: Documentation/HTML Requires: %{name} = %{version} -Provides: llvm-doc-provider = %{version} -Conflicts: llvm-doc-provider < %{version} -BuildArch: noarch # The docs used to be contained in the devel package. Conflicts: llvm-devel-provider < 9.0.0 +Conflicts: llvm-doc-provider < %{version} +Provides: llvm-doc-provider = %{version} +BuildArch: noarch %description doc This package contains documentation for the LLVM infrastructure. @@ -217,15 +216,15 @@ # Avoid multiple provider errors Requires: libLTO%{_sonum} Requires: libclang%{_sonum} +Requires(post): update-alternatives +Requires(postun): update-alternatives Recommends: clang%{_sonum}-checker +Recommends: clang%{_sonum}-doc Recommends: libstdc++-devel Suggests: libc++-devel %if %{with cxx} Requires: libc++%{_socxx} %endif -Recommends: clang%{_sonum}-doc -Requires(post): update-alternatives -Requires(postun): update-alternatives %description -n clang%{_sonum} This package contains the clang (C language) frontend for LLVM. @@ -293,13 +292,13 @@ Summary: Documentation for Clang Group: Documentation/HTML Requires: clang%{_sonum} = %{version} -Provides: clang-doc-provider = %{version} Conflicts: clang-doc-provider < %{version} -BuildArch: noarch # The docs used to be contained in the devel package. Conflicts: clang6-devel Conflicts: clang7-devel Conflicts: clang8-devel +Provides: clang-doc-provider = %{version} +BuildArch: noarch %description -n clang%{_sonum}-doc This package contains documentation for the Clang compiler. @@ -398,7 +397,7 @@ %package vim-plugins Summary: Vim plugins for LLVM Group: Productivity/Text/Editors -Supplements: packageand(llvm%{_sonum}:vim) +Supplements: (llvm%{_sonum} and vim) Conflicts: vim-plugin-llvm < %{version} Provides: vim-plugin-llvm = %{version} BuildArch: noarch @@ -409,7 +408,7 @@ %package emacs-plugins Summary: Emacs plugins for LLVM Group: Productivity/Text/Editors -Supplements: packageand(llvm%{_sonum}:emacs) +Supplements: (llvm%{_sonum} and emacs) Conflicts: emacs-llvm < %{version} Provides: emacs-llvm = %{version} BuildArch: noarch @@ -422,9 +421,9 @@ Group: Development/Libraries/Python Requires: clang%{_sonum}-devel = %{version} Requires: python3-base -BuildArch: noarch -Provides: %{python3_sitearch}/clang/ Conflicts: %{python3_sitearch}/clang/ +Provides: %{python3_sitearch}/clang/ +BuildArch: noarch %description -n python3-clang This package contains the Python bindings to clang (C language) @@ -446,9 +445,9 @@ BuildRequires: python3-base Requires: python3-PyYAML Requires: python3-Pygments -BuildArch: noarch Conflicts: opt-viewer < %{version} Provides: opt-viewer = %{version} +BuildArch: noarch %description opt-viewer Set of tools for visualising the LLVM optimization records generated with -fsave-optimization-record. Used for compiler-assisted performance analysis. @@ -458,6 +457,7 @@ Summary: Software debugger built using LLVM libraries Group: Development/Tools/Debuggers URL: https://lldb.llvm.org/ +BuildRequires: pkgconfig BuildRequires: pkgconfig(libedit) BuildRequires: pkgconfig(libffi) BuildRequires: pkgconfig(libxml-2.0) @@ -467,10 +467,10 @@ BuildRequires: pkgconfig(zlib) # Avoid multiple provider errors Requires: liblldb%{_sonum} = %{version} -Recommends: python3-lldb%{_sonum} -ExclusiveArch: x86_64 Requires(post): update-alternatives Requires(postun): update-alternatives +Recommends: python3-lldb%{_sonum} +ExclusiveArch: x86_64 %description -n lldb%{_sonum} LLDB is a next generation, high-performance debugger. It is built as a set @@ -497,8 +497,8 @@ Requires: llvm%{_sonum}-devel = %{version} Requires: pkgconfig(libedit) Requires: pkgconfig(libxml-2.0) -Provides: lldb-devel-provider = %{version} Conflicts: lldb-devel-provider < %{version} +Provides: lldb-devel-provider = %{version} %description -n lldb%{_sonum}-devel This package contains the development files for LLDB. @@ -512,8 +512,8 @@ Requires: liblldb%{_sonum} = %{version} Requires: python3-base Requires: python3-six -Provides: %{python3_sitearch}/lldb/ Conflicts: %{python3_sitearch}/lldb/ +Provides: %{python3_sitearch}/lldb/ %description -n python3-lldb%{_sonum} This package contains the Python bindings for LLDB. It also contains @@ -560,9 +560,12 @@ %patch24 -p1 %patch32 -p1 %patch33 -p1 +%patch34 -p1 +%patch35 -p1 pushd compiler-rt-%{version}.src %patch28 -p2 +%patch36 -p2 popd pushd clang-%{version}.src @@ -731,7 +734,7 @@ -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory" \ -DCMAKE_MODULE_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory" \ -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -Wl,--no-keep-memory" \ - -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 + -DPYTHON_EXECUTABLE:FILEPATH=%{_bindir}/python3 %if %{with thin_lto} ninja -v %{?_smp_mflags} clang llvm-tblgen clang-tblgen llvm-ar llvm-ranlib LLVMgold %else @@ -807,7 +810,7 @@ -DCMAKE_EXE_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1" \ -DCMAKE_MODULE_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1" \ -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed -Wl,--build-id=sha1" \ - -DPYTHON_EXECUTABLE:FILEPATH=/usr/bin/python3 \ + -DPYTHON_EXECUTABLE:FILEPATH=%{_bindir}/python3 \ -DPOLLY_BUNDLED_ISL:BOOL=ON # ThinLTO uses multiple threads from the linker process for optimizations, which @@ -872,8 +875,8 @@ %endif # Note that bfd-plugins is always in /usr/lib/bfd-plugins, no matter what _libdir is. -mkdir -p %{buildroot}/usr/lib/bfd-plugins -ln -s %{_libdir}/LLVMgold.so %{buildroot}/usr/lib/bfd-plugins/ +mkdir -p %{buildroot}%{_prefix}/lib/bfd-plugins +ln -s %{_libdir}/LLVMgold.so %{buildroot}%{_prefix}/lib/bfd-plugins/ install -m 755 -d %{buildroot}%{_datadir}/vim/site/ for i in ftdetect ftplugin indent syntax; do @@ -1012,7 +1015,7 @@ for script in %{buildroot}%{_bindir}/{{clang-{format,tidy}-diff,git-clang-format,\ hmaptool,run-clang-tidy}-%{_relver},{ccc,c++}-analyzer,scan-{build,view},opt-{diff,stats,viewer}} \ %{buildroot}%{python3_sitelib}/optrecord.py; do - sed -i '1s|/usr/bin/env *|/usr/bin/|;1s|/usr/bin/python$|/usr/bin/python3|' $script + sed -i '1s|%{_bindir}/env *|%{_bindir}/|;1s|%{_bindir}/python$|%{_bindir}/python3|' $script done # Remove executable bit where not needed. @@ -1727,8 +1730,8 @@ %license CREDITS.TXT LICENSE.TXT %{_libdir}/LLVMgold.so # Note that bfd-plugins is always in /usr/lib/bfd-plugins, no matter what _libdir is. -%dir /usr/lib/bfd-plugins/ -/usr/lib/bfd-plugins/LLVMgold.so +%dir %{_prefix}/lib/bfd-plugins/ +%{_prefix}/lib/bfd-plugins/LLVMgold.so %if %{with openmp} %files -n libomp%{_sonum}-devel ++++++ compiler-rt-move-fdp.patch ++++++ >From f1b0a93e3a777565485e165fba17c4e81ba6c127 Mon Sep 17 00:00:00 2001 From: Max Moroz <[email protected]> Date: Mon, 5 Aug 2019 19:55:52 +0000 Subject: [PATCH] [compiler-rt] Move FDP to include/fuzzer/FuzzedDataProvider.h for easier use. Summary: FuzzedDataProvider is a helper class for writing fuzz targets that fuzz multple inputs simultaneously. The header is supposed to be used for fuzzing engine agnostic fuzz targets (i.e. the same target can be used with libFuzzer, AFL, honggfuzz, and other engines). The common thing though is that fuzz targets are typically compiled with clang, as it provides all sanitizers as well as different coverage instrumentation modes. Therefore, making this FDP class a part of the compiler-rt installation package would make it easier to develop and distribute fuzz targets across different projects, build systems, etc. Some context also available in https://github.com/google/oss-fuzz/pull/2547. This CL does not delete the header from `lib/fuzzer/utils` directory in order to provide the downstream users some time for a smooth migration to the new header location. Reviewers: kcc, morehouse Reviewed By: morehouse Subscribers: lebedev.ri, kubamracek, dberris, mgorny, delcypher, #sanitizers, llvm-commits Tags: #llvm, #sanitizers Differential Revision: https://reviews.llvm.org/D65661 llvm-svn: 367917 --- compiler-rt/include/CMakeLists.txt | 9 + compiler-rt/include/fuzzer/FuzzedDataProvider.h | 245 +++++++++++++++++++++ compiler-rt/lib/fuzzer/FuzzerExtFunctions.def | 8 +- compiler-rt/lib/fuzzer/tests/CMakeLists.txt | 2 - .../fuzzer/tests/FuzzedDataProviderUnittest.cpp | 2 +- compiler-rt/lib/fuzzer/utils/FuzzedDataProvider.h | 4 +- .../lib/sanitizer_common/scripts/check_lint.sh | 4 +- 7 files changed, 264 insertions(+), 10 deletions(-) create mode 100644 compiler-rt/include/fuzzer/FuzzedDataProvider.h diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index 38bd6e41a91..57ed6c3ade2 100644 --- a/compiler-rt/include/CMakeLists.txt +++ b/compiler-rt/include/CMakeLists.txt @@ -14,6 +14,9 @@ if (COMPILER_RT_BUILD_SANITIZERS) sanitizer/tsan_interface.h sanitizer/tsan_interface_atomic.h ) + set(FUZZER_HEADERS + fuzzer/FuzzedDataProvider.h + ) endif(COMPILER_RT_BUILD_SANITIZERS) if (COMPILER_RT_BUILD_XRAY) @@ -26,6 +29,7 @@ endif(COMPILER_RT_BUILD_XRAY) set(COMPILER_RT_HEADERS ${SANITIZER_HEADERS} + ${FUZZER_HEADERS} ${XRAY_HEADERS}) set(output_dir ${COMPILER_RT_OUTPUT_DIR}/include) @@ -51,6 +55,11 @@ install(FILES ${SANITIZER_HEADERS} COMPONENT compiler-rt-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) +# Install fuzzer headers. +install(FILES ${FUZZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/fuzzer) # Install xray headers. install(FILES ${XRAY_HEADERS} COMPONENT compiler-rt-headers diff --git a/compiler-rt/include/fuzzer/FuzzedDataProvider.h b/compiler-rt/include/fuzzer/FuzzedDataProvider.h new file mode 100644 index 00000000000..e82f441d409 --- /dev/null +++ b/compiler-rt/include/fuzzer/FuzzedDataProvider.h @@ -0,0 +1,245 @@ +//===- FuzzedDataProvider.h - Utility header for fuzz targets ---*- C++ -* ===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// A single header library providing an utility class to break up an array of +// bytes. Whenever run on the same input, provides the same output, as long as +// its methods are called in the same order, with the same arguments. +//===----------------------------------------------------------------------===// + +#ifndef LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_ +#define LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_ + +#include <limits.h> +#include <stddef.h> +#include <stdint.h> + +#include <algorithm> +#include <cstring> +#include <initializer_list> +#include <string> +#include <type_traits> +#include <utility> +#include <vector> + +class FuzzedDataProvider { + public: + // |data| is an array of length |size| that the FuzzedDataProvider wraps to + // provide more granular access. |data| must outlive the FuzzedDataProvider. + FuzzedDataProvider(const uint8_t *data, size_t size) + : data_ptr_(data), remaining_bytes_(size) {} + ~FuzzedDataProvider() = default; + + // Returns a std::vector containing |num_bytes| of input data. If fewer than + // |num_bytes| of data remain, returns a shorter std::vector containing all + // of the data that's left. Can be used with any byte sized type, such as + // char, unsigned char, uint8_t, etc. + template <typename T> std::vector<T> ConsumeBytes(size_t num_bytes) { + num_bytes = std::min(num_bytes, remaining_bytes_); + return ConsumeBytes<T>(num_bytes, num_bytes); + } + + // Similar to |ConsumeBytes|, but also appends the terminator value at the end + // of the resulting vector. Useful, when a mutable null-terminated C-string is + // needed, for example. But that is a rare case. Better avoid it, if possible, + // and prefer using |ConsumeBytes| or |ConsumeBytesAsString| methods. + template <typename T> + std::vector<T> ConsumeBytesWithTerminator(size_t num_bytes, + T terminator = 0) { + num_bytes = std::min(num_bytes, remaining_bytes_); + std::vector<T> result = ConsumeBytes<T>(num_bytes + 1, num_bytes); + result.back() = terminator; + return result; + } + + // Returns a std::string containing |num_bytes| of input data. Using this and + // |.c_str()| on the resulting string is the best way to get an immutable + // null-terminated C string. If fewer than |num_bytes| of data remain, returns + // a shorter std::string containing all of the data that's left. + std::string ConsumeBytesAsString(size_t num_bytes) { + static_assert(sizeof(std::string::value_type) == sizeof(uint8_t), + "ConsumeBytesAsString cannot convert the data to a string."); + + num_bytes = std::min(num_bytes, remaining_bytes_); + std::string result( + reinterpret_cast<const std::string::value_type *>(data_ptr_), + num_bytes); + Advance(num_bytes); + return result; + } + + // Returns a number in the range [min, max] by consuming bytes from the + // input data. The value might not be uniformly distributed in the given + // range. If there's no input data left, always returns |min|. |min| must + // be less than or equal to |max|. + template <typename T> T ConsumeIntegralInRange(T min, T max) { + static_assert(std::is_integral<T>::value, "An integral type is required."); + static_assert(sizeof(T) <= sizeof(uint64_t), "Unsupported integral type."); + + if (min > max) + abort(); + + // Use the biggest type possible to hold the range and the result. + uint64_t range = static_cast<uint64_t>(max) - min; + uint64_t result = 0; + size_t offset = 0; + + while (offset < sizeof(T) * CHAR_BIT && (range >> offset) > 0 && + remaining_bytes_ != 0) { + // Pull bytes off the end of the seed data. Experimentally, this seems to + // allow the fuzzer to more easily explore the input space. This makes + // sense, since it works by modifying inputs that caused new code to run, + // and this data is often used to encode length of data read by + // |ConsumeBytes|. Separating out read lengths makes it easier modify the + // contents of the data that is actually read. + --remaining_bytes_; + result = (result << CHAR_BIT) | data_ptr_[remaining_bytes_]; + offset += CHAR_BIT; + } + + // Avoid division by 0, in case |range + 1| results in overflow. + if (range != std::numeric_limits<decltype(range)>::max()) + result = result % (range + 1); + + return static_cast<T>(min + result); + } + + // Returns a std::string of length from 0 to |max_length|. When it runs out of + // input data, returns what remains of the input. Designed to be more stable + // with respect to a fuzzer inserting characters than just picking a random + // length and then consuming that many bytes with |ConsumeBytes|. + std::string ConsumeRandomLengthString(size_t max_length) { + // Reads bytes from the start of |data_ptr_|. Maps "\\" to "\", and maps "\" + // followed by anything else to the end of the string. As a result of this + // logic, a fuzzer can insert characters into the string, and the string + // will be lengthened to include those new characters, resulting in a more + // stable fuzzer than picking the length of a string independently from + // picking its contents. + std::string result; + + // Reserve the anticipated capaticity to prevent several reallocations. + result.reserve(std::min(max_length, remaining_bytes_)); + for (size_t i = 0; i < max_length && remaining_bytes_ != 0; ++i) { + char next = ConvertUnsignedToSigned<char>(data_ptr_[0]); + Advance(1); + if (next == '\\' && remaining_bytes_ != 0) { + next = ConvertUnsignedToSigned<char>(data_ptr_[0]); + Advance(1); + if (next != '\\') + break; + } + result += next; + } + + result.shrink_to_fit(); + return result; + } + + // Returns a std::vector containing all remaining bytes of the input data. + template <typename T> std::vector<T> ConsumeRemainingBytes() { + return ConsumeBytes<T>(remaining_bytes_); + } + + // Prefer using |ConsumeRemainingBytes| unless you actually need a std::string + // object. + // Returns a std::vector containing all remaining bytes of the input data. + std::string ConsumeRemainingBytesAsString() { + return ConsumeBytesAsString(remaining_bytes_); + } + + // Returns a number in the range [Type's min, Type's max]. The value might + // not be uniformly distributed in the given range. If there's no input data + // left, always returns |min|. + template <typename T> T ConsumeIntegral() { + return ConsumeIntegralInRange(std::numeric_limits<T>::min(), + std::numeric_limits<T>::max()); + } + + // Reads one byte and returns a bool, or false when no data remains. + bool ConsumeBool() { return 1 & ConsumeIntegral<uint8_t>(); } + + // Returns a copy of a value selected from a fixed-size |array|. + template <typename T, size_t size> + T PickValueInArray(const T (&array)[size]) { + static_assert(size > 0, "The array must be non empty."); + return array[ConsumeIntegralInRange<size_t>(0, size - 1)]; + } + + template <typename T> + T PickValueInArray(std::initializer_list<const T> list) { + // static_assert(list.size() > 0, "The array must be non empty."); + return *(list.begin() + ConsumeIntegralInRange<size_t>(0, list.size() - 1)); + } + + // Return an enum value. The enum must start at 0 and be contiguous. It must + // also contain |kMaxValue| aliased to its largest (inclusive) value. Such as: + // enum class Foo { SomeValue, OtherValue, kMaxValue = OtherValue }; + template <typename T> T ConsumeEnum() { + static_assert(std::is_enum<T>::value, "|T| must be an enum type."); + return static_cast<T>(ConsumeIntegralInRange<uint32_t>( + 0, static_cast<uint32_t>(T::kMaxValue))); + } + + // Reports the remaining bytes available for fuzzed input. + size_t remaining_bytes() { return remaining_bytes_; } + + private: + FuzzedDataProvider(const FuzzedDataProvider &) = delete; + FuzzedDataProvider &operator=(const FuzzedDataProvider &) = delete; + + void Advance(size_t num_bytes) { + if (num_bytes > remaining_bytes_) + abort(); + + data_ptr_ += num_bytes; + remaining_bytes_ -= num_bytes; + } + + template <typename T> + std::vector<T> ConsumeBytes(size_t size, size_t num_bytes_to_consume) { + static_assert(sizeof(T) == sizeof(uint8_t), "Incompatible data type."); + + // The point of using the size-based constructor below is to increase the + // odds of having a vector object with capacity being equal to the length. + // That part is always implementation specific, but at least both libc++ and + // libstdc++ allocate the requested number of bytes in that constructor, + // which seems to be a natural choice for other implementations as well. + // To increase the odds even more, we also call |shrink_to_fit| below. + std::vector<T> result(size); + std::memcpy(result.data(), data_ptr_, num_bytes_to_consume); + Advance(num_bytes_to_consume); + + // Even though |shrink_to_fit| is also implementation specific, we expect it + // to provide an additional assurance in case vector's constructor allocated + // a buffer which is larger than the actual amount of data we put inside it. + result.shrink_to_fit(); + return result; + } + + template <typename TS, typename TU> TS ConvertUnsignedToSigned(TU value) { + static_assert(sizeof(TS) == sizeof(TU), "Incompatible data types."); + static_assert(!std::numeric_limits<TU>::is_signed, + "Source type must be unsigned."); + + // TODO(Dor1s): change to `if constexpr` once C++17 becomes mainstream. + if (std::numeric_limits<TS>::is_modulo) + return static_cast<TS>(value); + + // Avoid using implementation-defined unsigned to signer conversions. + // To learn more, see https://stackoverflow.com/questions/13150449. + if (value <= std::numeric_limits<TS>::max()) + return static_cast<TS>(value); + else { + constexpr auto TS_min = std::numeric_limits<TS>::min(); + return TS_min + static_cast<char>(value - TS_min); + } + } + + const uint8_t *data_ptr_; + size_t remaining_bytes_; +}; + +#endif // LLVM_FUZZER_FUZZED_DATA_PROVIDER_H_ diff --git a/compiler-rt/lib/fuzzer/FuzzerExtFunctions.def b/compiler-rt/lib/fuzzer/FuzzerExtFunctions.def index 87df4ecb812..7b53b085560 100644 --- a/compiler-rt/lib/fuzzer/FuzzerExtFunctions.def +++ b/compiler-rt/lib/fuzzer/FuzzerExtFunctions.def @@ -16,12 +16,12 @@ // Optional user functions EXT_FUNC(LLVMFuzzerInitialize, int, (int *argc, char ***argv), false); EXT_FUNC(LLVMFuzzerCustomMutator, size_t, - (uint8_t * Data, size_t Size, size_t MaxSize, unsigned int Seed), + (uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed), false); EXT_FUNC(LLVMFuzzerCustomCrossOver, size_t, - (const uint8_t * Data1, size_t Size1, - const uint8_t * Data2, size_t Size2, - uint8_t * Out, size_t MaxOutSize, unsigned int Seed), + (const uint8_t *Data1, size_t Size1, + const uint8_t *Data2, size_t Size2, + uint8_t *Out, size_t MaxOutSize, unsigned int Seed), false); // Sanitizer functions diff --git a/compiler-rt/lib/fuzzer/tests/CMakeLists.txt b/compiler-rt/lib/fuzzer/tests/CMakeLists.txt index 6f665107994..69e67ab0d50 100644 --- a/compiler-rt/lib/fuzzer/tests/CMakeLists.txt +++ b/compiler-rt/lib/fuzzer/tests/CMakeLists.txt @@ -75,8 +75,6 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST FUZZER_SUPPORTED_ARCH) set_target_properties(FuzzerUnitTests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - list(APPEND LIBFUZZER_UNITTEST_CFLAGS -I${COMPILER_RT_SOURCE_DIR}/lib/fuzzer/utils) - set(FuzzedDataProviderTestObjects) generate_compiler_rt_tests(FuzzedDataProviderTestObjects FuzzedDataProviderUnitTests "FuzzerUtils-${arch}-Test" ${arch} diff --git a/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp b/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp index e1b272227ff..0989ec9ec7e 100644 --- a/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp +++ b/compiler-rt/lib/fuzzer/tests/FuzzedDataProviderUnittest.cpp @@ -6,7 +6,7 @@ #include <cstdint> #include <cstdlib> -#include "FuzzedDataProvider.h" +#include <fuzzer/FuzzedDataProvider.h> // The test is intentionally extensive, as behavior of |FuzzedDataProvider| must // not be broken, given than many fuzz targets depend on it. Changing the diff --git a/compiler-rt/lib/fuzzer/utils/FuzzedDataProvider.h b/compiler-rt/lib/fuzzer/utils/FuzzedDataProvider.h index 1b5b4bb0126..e82f441d409 100644 --- a/compiler-rt/lib/fuzzer/utils/FuzzedDataProvider.h +++ b/compiler-rt/lib/fuzzer/utils/FuzzedDataProvider.h @@ -26,7 +26,7 @@ #include <vector> class FuzzedDataProvider { -public: + public: // |data| is an array of length |size| that the FuzzedDataProvider wraps to // provide more granular access. |data| must outlive the FuzzedDataProvider. FuzzedDataProvider(const uint8_t *data, size_t size) @@ -186,7 +186,7 @@ public: // Reports the remaining bytes available for fuzzed input. size_t remaining_bytes() { return remaining_bytes_; } -private: + private: FuzzedDataProvider(const FuzzedDataProvider &) = delete; FuzzedDataProvider &operator=(const FuzzedDataProvider &) = delete; diff --git a/compiler-rt/lib/sanitizer_common/scripts/check_lint.sh b/compiler-rt/lib/sanitizer_common/scripts/check_lint.sh index ed1cf010b6f..d78fb72f36f 100755 --- a/compiler-rt/lib/sanitizer_common/scripts/check_lint.sh +++ b/compiler-rt/lib/sanitizer_common/scripts/check_lint.sh @@ -66,7 +66,9 @@ fi LIT_TESTS=${COMPILER_RT}/test # Headers SANITIZER_INCLUDES=${COMPILER_RT}/include/sanitizer -run_lint ${SANITIZER_INCLUDES_LINT_FILTER} ${SANITIZER_INCLUDES}/*.h & +FUZZER_INCLUDES=${COMPILER_RT}/include/fuzzer +run_lint ${SANITIZER_INCLUDES_LINT_FILTER} ${SANITIZER_INCLUDES}/*.h \ + ${FUZZER_INCLUDES}/*.h & # Sanitizer_common COMMON_RTL=${COMPILER_RT}/lib/sanitizer_common -- 2.16.4 ++++++ polly-pthread.patch ++++++ Since libPolly uses std::call_once it needs to be linked against libpthread. Due to our use of --as-needed we need to make sure it is linked after libPolly. Index: llvm-9.0.1.src/polly-9.0.1.src/lib/CMakeLists.txt =================================================================== --- llvm-9.0.1.src.orig/polly-9.0.1.src/lib/CMakeLists.txt +++ llvm-9.0.1.src/polly-9.0.1.src/lib/CMakeLists.txt @@ -79,6 +79,7 @@ set_target_properties(PollyCore PROPERTI add_polly_library(Polly $<TARGET_OBJECTS:PollyCore>) target_link_libraries(Polly PRIVATE ${ISL_TARGET} + ${LLVM_PTHREAD_LIB} ) # Additional dependencies for Polly-ACC. ++++++ riscv-eh-frame-fixup.patch ++++++ commit 7cb3cd34e8d Author: Alex Bradbury <[email protected]> Date: Tue Aug 20 12:32:31 2019 +0000 [RISCV] Implement getExprForFDESymbol to ensure RISCV_32_PCREL is used for the FDE location Follow binutils in using RISCV_32_PCREL for the FDE initial location. As explained in the relevant binutils commit <https://github.com/riscv/riscv-binutils-gdb/commit/a6cbf936e3dce68114d28cdf60d510a3f78a6d40>, the ADD/SUB pair of relocations is problematic in the presence of linker relaxation. This patch has the same end goal as D64715 but includes test changes and avoids adding a new global VariantKind to MCExpr.h (preferring RISCVMCExpr VKs like the rest of the RISC-V backend). Differential Revision: https://reviews.llvm.org/D66419 llvm-svn: 369375 commit 1c1f8f215d8 Author: Alex Bradbury <[email protected]> Date: Mon Aug 19 13:23:02 2019 +0000 [RISCV] Don't force absolute FK_Data_X fixups to relocs The current behavior of shouldForceRelocation forces relocations for the majority of fixups when relaxation is enabled. This makes sense for fixups which incorporate symbols but is unnecessary for simple data fixups where the fixup target is already resolved to an absolute value. Differential Revision: https://reviews.llvm.org/D63404 Patch by Edward Jones. llvm-svn: 369257 commit 49a99788393 Author: Hsiangkai Wang <[email protected]> Date: Fri Jul 19 06:10:36 2019 +0000 [DebugInfo] Some fields do not need relocations even relax is enabled. In debug frame information, some fields, e.g., Length in CIE/FDE and Offset in FDE are attributes to describe the structure of CIE/FDE. They are not related to the relaxed code. However, these attributes are symbol differences. So, in current design, these attributes will be filled as zero and LLVM generates relocations for them. We only need to generate relocations for symbols in executable sections. So, if the symbols are not located in executable sections, we still evaluate their values under relaxation. Differential Revision: https://reviews.llvm.org/D61584 llvm-svn: 366531 Index: llvm-9.0.1.src/lib/MC/MCExpr.cpp =================================================================== --- llvm-9.0.1.src.orig/lib/MC/MCExpr.cpp +++ llvm-9.0.1.src/lib/MC/MCExpr.cpp @@ -577,6 +577,24 @@ static void AttemptToFoldSymbolOffsetDif A = B = nullptr; } +static bool canFold(const MCAssembler *Asm, const MCSymbolRefExpr *A, + const MCSymbolRefExpr *B, bool InSet) { + if (InSet) + return true; + + if (!Asm->getBackend().requiresDiffExpressionRelocations()) + return true; + + const MCSymbol &CheckSym = A ? A->getSymbol() : B->getSymbol(); + if (!CheckSym.isInSection()) + return true; + + if (!CheckSym.getSection().hasInstructions()) + return true; + + return false; +} + /// Evaluate the result of an add between (conceptually) two MCValues. /// /// This routine conceptually attempts to construct an MCValue: @@ -617,8 +635,7 @@ EvaluateSymbolicAdd(const MCAssembler *A // the backend requires this to be emitted as individual relocations, unless // the InSet flag is set to get the current difference anyway (used for // example to calculate symbol sizes). - if (Asm && - (InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) { + if (Asm && canFold(Asm, LHS_A, LHS_B, InSet)) { // First, fold out any differences which are fully resolved. By // reassociating terms in // Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst). Index: llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp =================================================================== --- llvm-9.0.1.src.orig/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp +++ llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp @@ -33,6 +33,13 @@ bool RISCVAsmBackend::shouldForceRelocat switch ((unsigned)Fixup.getKind()) { default: break; + case FK_Data_1: + case FK_Data_2: + case FK_Data_4: + case FK_Data_8: + if (Target.isAbsolute()) + return false; + break; case RISCV::fixup_riscv_got_hi20: case RISCV::fixup_riscv_tls_got_hi20: case RISCV::fixup_riscv_tls_gd_hi20: Index: llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp =================================================================== --- llvm-9.0.1.src.orig/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp +++ llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVELFObjectWriter.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "MCTargetDesc/RISCVFixupKinds.h" +#include "MCTargetDesc/RISCVMCExpr.h" #include "MCTargetDesc/RISCVMCTargetDesc.h" #include "llvm/MC/MCELFObjectWriter.h" #include "llvm/MC/MCFixup.h" @@ -47,6 +48,7 @@ unsigned RISCVELFObjectWriter::getRelocT const MCValue &Target, const MCFixup &Fixup, bool IsPCRel) const { + const MCExpr *Expr = Fixup.getValue(); // Determine the type of the relocation unsigned Kind = Fixup.getKind(); if (IsPCRel) { @@ -87,6 +89,9 @@ unsigned RISCVELFObjectWriter::getRelocT default: llvm_unreachable("invalid fixup kind!"); case FK_Data_4: + if (Expr->getKind() == MCExpr::Target && + cast<RISCVMCExpr>(Expr)->getKind() == RISCVMCExpr::VK_RISCV_32_PCREL) + return ELF::R_RISCV_32_PCREL; return ELF::R_RISCV_32; case FK_Data_8: return ELF::R_RISCV_64; Index: llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp =================================================================== --- llvm-9.0.1.src.orig/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp +++ llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.cpp @@ -11,7 +11,10 @@ //===----------------------------------------------------------------------===// #include "RISCVMCAsmInfo.h" +#include "MCTargetDesc/RISCVMCExpr.h" #include "llvm/ADT/Triple.h" +#include "llvm/BinaryFormat/Dwarf.h" +#include "llvm/MC/MCStreamer.h" using namespace llvm; void RISCVMCAsmInfo::anchor() {} @@ -25,3 +28,20 @@ RISCVMCAsmInfo::RISCVMCAsmInfo(const Tri Data16bitsDirective = "\t.half\t"; Data32bitsDirective = "\t.word\t"; } + +const MCExpr *RISCVMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym, + unsigned Encoding, + MCStreamer &Streamer) const { + if (!(Encoding & dwarf::DW_EH_PE_pcrel)) + return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer); + + // The default symbol subtraction results in an ADD/SUB relocation pair. + // Processing this relocation pair is problematic when linker relaxation is + // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation + // for the FDE initial location. + MCContext &Ctx = Streamer.getContext(); + const MCExpr *ME = + MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Ctx); + assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding"); + return RISCVMCExpr::create(ME, RISCVMCExpr::VK_RISCV_32_PCREL, Ctx); +} Index: llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.h =================================================================== --- llvm-9.0.1.src.orig/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.h +++ llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCAsmInfo.h @@ -23,6 +23,9 @@ class RISCVMCAsmInfo : public MCAsmInfoE public: explicit RISCVMCAsmInfo(const Triple &TargetTriple); + + const MCExpr *getExprForFDESymbol(const MCSymbol *Sym, unsigned Encoding, + MCStreamer &Streamer) const override; }; } // namespace llvm Index: llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp =================================================================== --- llvm-9.0.1.src.orig/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp +++ llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCCodeEmitter.cpp @@ -266,6 +266,7 @@ unsigned RISCVMCCodeEmitter::getImmOpVal switch (RVExpr->getKind()) { case RISCVMCExpr::VK_RISCV_None: case RISCVMCExpr::VK_RISCV_Invalid: + case RISCVMCExpr::VK_RISCV_32_PCREL: llvm_unreachable("Unhandled fixup kind!"); case RISCVMCExpr::VK_RISCV_TPREL_ADD: // tprel_add is only used to indicate that a relocation should be emitted Index: llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h =================================================================== --- llvm-9.0.1.src.orig/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h +++ llvm-9.0.1.src/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.h @@ -36,6 +36,7 @@ public: VK_RISCV_TLS_GD_HI, VK_RISCV_CALL, VK_RISCV_CALL_PLT, + VK_RISCV_32_PCREL, VK_RISCV_Invalid }; Index: llvm-9.0.1.src/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll =================================================================== --- llvm-9.0.1.src.orig/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll +++ llvm-9.0.1.src/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll @@ -6,14 +6,14 @@ ; Check that we actually have relocations, otherwise this is kind of pointless. ; READOBJ-RELOCS: Section (8) .rela.debug_info { -; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0x0 -; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 - 0x0 -; READOBJ-RELOCS: Section (11) .rela.debug_addr { -; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0x0 -; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 - 0x0 +; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 - 0x0 +; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 - 0x0 +; READOBJ-RELOCS: Section (15) .rela.debug_frame { +; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 - 0x0 +; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 - 0x0 ; READOBJ-RELOCS: Section (17) .rela.debug_line { -; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC -; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 .Lline_table_start0 0x0 +; READOBJ-RELOCS: 0x5A R_RISCV_ADD16 - 0x0 +; READOBJ-RELOCS-NEXT: 0x5A R_RISCV_SUB16 - 0x0 ; Check that we can print the source, even with relocations. ; OBJDUMP-SOURCE: Disassembly of section .text: Index: llvm-9.0.1.src/test/MC/RISCV/fde-reloc.s =================================================================== --- llvm-9.0.1.src.orig/test/MC/RISCV/fde-reloc.s +++ llvm-9.0.1.src/test/MC/RISCV/fde-reloc.s @@ -8,20 +8,8 @@ func: ret .cfi_endproc -# TODO: Should produce R_RISCV_32_PCREL for the FDE pc relocation. Many of the -# ADD32/SUB32 relocations also can be safely resolved even with linker -# relaxation enabled. This test is written to capture current behaviour, in -# preparation for follow-on patches to fix it. - # RELAX-RELOC: Section (4) .rela.eh_frame { -# RELAX-RELOC-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC -# RELAX-RELOC-NEXT: 0x0 R_RISCV_SUB32 - 0x0 -# RELAX-RELOC-NEXT: 0x14 R_RISCV_ADD32 - 0x0 -# RELAX-RELOC-NEXT: 0x14 R_RISCV_SUB32 - 0x0 -# RELAX-RELOC-NEXT: 0x18 R_RISCV_ADD32 - 0x0 -# RELAX-RELOC-NEXT: 0x18 R_RISCV_SUB32 - 0x0 -# RELAX-RELOC-NEXT: 0x1C R_RISCV_ADD32 - 0x0 -# RELAX-RELOC-NEXT: 0x1C R_RISCV_SUB32 - 0x0 +# RELAX-RELOC-NEXT: 0x1C R_RISCV_32_PCREL - 0x0 # RELAX-RELOC-NEXT: 0x20 R_RISCV_ADD32 - 0x0 # RELAX-RELOC-NEXT: 0x20 R_RISCV_SUB32 - 0x0 # RELAX-RELOC-NEXT: } Index: llvm-9.0.1.src/test/MC/RISCV/linker-relaxation.s =================================================================== --- llvm-9.0.1.src.orig/test/MC/RISCV/linker-relaxation.s +++ llvm-9.0.1.src/test/MC/RISCV/linker-relaxation.s @@ -136,3 +136,24 @@ sb t1, %pcrel_lo(2b)(a2) # RELAX-RELOC: R_RISCV_RELAX - 0x0 # RELAX-FIXUP: fixup A - offset: 0, value: %pcrel_lo(.Ltmp1), kind: fixup_riscv_pcrel_lo12_s # RELAX-FIXUP: fixup B - offset: 0, value: 0, kind: fixup_riscv_relax + +# Check that a relocation is not emitted for a symbol difference which has +# been folded to a fixup with an absolute value. This can happen when a +# difference expression refers to two symbols, at least one of which is +# not defined at the point it is referenced. Then during *assembler* +# relaxation when both symbols have become defined the difference may be folded +# down to a fixup simply containing the absolute value. We want to ensure that +# we don't force a relocation to be emitted for this absolute value even +# when linker relaxation is enabled. The reason for this is that one instance +# where this pattern appears in in the .eh_frame section (the CIE 'length' +# field), and the .eh_frame section cannot be parsed by the linker unless the +# fixup has been resolved to a concrete value instead of a relocation. + .data +lo: + .word hi-lo + .quad hi-lo +# NORELAX-RELOC-NOT: R_RISCV_32 +# NORELAX-RELOC-NOT: R_RISCV_64 +# RELAX-RELOC-NOT: R_RISCV_32 +# RELAX-RELOC-NOT: R_RISCV_64 +hi:
