From patchwork Tue Aug 28 01:36:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Terrell X-Patchwork-Id: 10577739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23C2C15A7 for ; Tue, 28 Aug 2018 01:38:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16343295DB for ; Tue, 28 Aug 2018 01:38:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0AA5C29612; Tue, 28 Aug 2018 01:38:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A9AC295DB for ; Tue, 28 Aug 2018 01:38:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726323AbeH1F2A (ORCPT ); Tue, 28 Aug 2018 01:28:00 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:53198 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725724AbeH1F2A (ORCPT ); Tue, 28 Aug 2018 01:28:00 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.22/8.16.0.22) with SMTP id w7S1chkU001535 for ; Mon, 27 Aug 2018 18:38:43 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=facebook; bh=LdnWscL+IGCxRODogTkWsfR8/fv3yk/DVHQls1lp9aE=; b=WXMTyUOqXvcU+cypGUW10Agdx3QcKENe+XA7L3xQ3DNR9MZMRRaSpmu6rF1U3jZbdVjI I8dx0tW1u5SXdtBHbaHzGSv0v92o5DiYtsWKp4Cu+xBYblqa24vSkVl0jy67Mj7klisW RL0pt2l0Ee6NlB+LdJToqrAnE72/RJwwQd4= Received: from mail.thefacebook.com ([199.201.64.23]) by m0089730.ppops.net with ESMTP id 2m4vhb01cn-3 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Mon, 27 Aug 2018 18:38:43 -0700 Received: from mx-out.facebook.com (192.168.52.123) by mail.thefacebook.com (192.168.16.18) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 27 Aug 2018 18:38:42 -0700 Received: by devvm4508.prn2.facebook.com (Postfix, from userid 32154) id AE776674D167; Mon, 27 Aug 2018 18:38:32 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Nick Terrell Smtp-Origin-Hostname: devvm4508.prn2.facebook.com To: Nick Terrell CC: David Sterba , , , Smtp-Origin-Cluster: prn2c23 Subject: [PATCH 2/3] btrfs: Patch the kernel zstd Date: Mon, 27 Aug 2018 18:36:53 -0700 Message-ID: <20180828013654.1627080-3-terrelln@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180828013654.1627080-1-terrelln@fb.com> References: <20180828013654.1627080-1-terrelln@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-27_10:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Applies patches to the upstream kernel zstd needed to compile in grub. * Replace kernel headers with "kerncompat.h". * Replace the unaligned memory access functions. * Add fallthrough statements for newer gcc versions. * Rename a variable from "byte" because of a conflicting typedef. * Remove the module code. * Switch the memcpy() in ZSTD_copy8() to __builtin_memcpy(). Signed-off-by: Nick Terrell --- grub-core/lib/zstd/bitstream.h | 6 ++++ grub-core/lib/zstd/decompress.c | 56 ++++++------------------------ grub-core/lib/zstd/error_private.h | 3 +- grub-core/lib/zstd/fse.h | 2 +- grub-core/lib/zstd/fse_decompress.c | 3 -- grub-core/lib/zstd/huf.h | 2 +- grub-core/lib/zstd/huf_decompress.c | 3 -- grub-core/lib/zstd/kerncompat.h | 69 +++++++++++++++++++++++++++++++++++++ grub-core/lib/zstd/mem.h | 42 ++++++++++++---------- grub-core/lib/zstd/xxhash.c | 22 ++---------- grub-core/lib/zstd/xxhash.h | 2 +- grub-core/lib/zstd/zstd.h | 2 +- grub-core/lib/zstd/zstd_common.c | 2 +- grub-core/lib/zstd/zstd_internal.h | 12 ++++--- 14 files changed, 124 insertions(+), 102 deletions(-) create mode 100644 grub-core/lib/zstd/kerncompat.h -- 2.16.2 diff --git a/grub-core/lib/zstd/bitstream.h b/grub-core/lib/zstd/bitstream.h index a826b99e1..92a6c3fb9 100644 --- a/grub-core/lib/zstd/bitstream.h +++ b/grub-core/lib/zstd/bitstream.h @@ -51,6 +51,7 @@ * Dependencies ******************************************/ #include "error_private.h" /* error codes and messages */ +#include "kerncompat.h" #include "mem.h" /* unaligned access routines */ /*========================================= @@ -259,10 +260,15 @@ ZSTD_STATIC size_t BIT_initDStream(BIT_DStream_t *bitD, const void *srcBuffer, s bitD->bitContainer = *(const BYTE *)(bitD->start); switch (srcSize) { case 7: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[6]) << (sizeof(bitD->bitContainer) * 8 - 16); + /* fallthrough */ case 6: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[5]) << (sizeof(bitD->bitContainer) * 8 - 24); + /* fallthrough */ case 5: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[4]) << (sizeof(bitD->bitContainer) * 8 - 32); + /* fallthrough */ case 4: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[3]) << 24; + /* fallthrough */ case 3: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[2]) << 16; + /* fallthrough */ case 2: bitD->bitContainer += (size_t)(((const BYTE *)(srcBuffer))[1]) << 8; default:; } diff --git a/grub-core/lib/zstd/decompress.c b/grub-core/lib/zstd/decompress.c index b17846725..e7af8df09 100644 --- a/grub-core/lib/zstd/decompress.c +++ b/grub-core/lib/zstd/decompress.c @@ -33,9 +33,6 @@ #include "huf.h" #include "mem.h" /* low level memory routines */ #include "zstd_internal.h" -#include -#include -#include /* memcpy, memmove, memset */ #define ZSTD_PREFETCH(ptr) __builtin_prefetch(ptr, 0, 0) @@ -123,6 +120,7 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx *dctx) return 0; } +static ZSTD_DCtx *ZSTD_createDCtx_advanced(ZSTD_customMem customMem) { ZSTD_DCtx *dctx; @@ -391,6 +389,7 @@ typedef struct { /*! ZSTD_getcBlockSize() : * Provides the size of compressed block from block header `src` */ +static size_t ZSTD_getcBlockSize(const void *src, size_t srcSize, blockProperties_t *bpPtr) { if (srcSize < ZSTD_blockHeaderSize) @@ -429,6 +428,7 @@ static size_t ZSTD_setRleBlock(void *dst, size_t dstCapacity, const void *src, s /*! ZSTD_decodeLiteralsBlock() : @return : nb of bytes read from src (< srcSize ) */ +static size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx *dctx, const void *src, size_t srcSize) /* note : srcSize < BLOCKSIZE */ { if (srcSize < MIN_CBLOCK_SIZE) @@ -791,6 +791,7 @@ static size_t ZSTD_buildSeqTable(FSE_DTable *DTableSpace, const FSE_DTable **DTa } } +static size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx *dctx, int *nbSeqPtr, const void *src, size_t srcSize) { const BYTE *const istart = (const BYTE *const)src; @@ -1494,11 +1495,12 @@ size_t ZSTD_insertBlock(ZSTD_DCtx *dctx, const void *blockStart, size_t blockSiz return blockSize; } -size_t ZSTD_generateNxBytes(void *dst, size_t dstCapacity, BYTE byte, size_t length) +static +size_t ZSTD_generateNxBytes(void *dst, size_t dstCapacity, BYTE value, size_t length) { if (length > dstCapacity) return ERROR(dstSize_tooSmall); - memset(dst, byte, length); + memset(dst, value, length); return length; } @@ -1768,6 +1770,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx *dctx, void *dst, size_t dstCapacity, c return 0; } dctx->expected = 0; /* not necessary to copy more */ + /* fallthrough */ case ZSTDds_decodeFrameHeader: memcpy(dctx->headerBuffer + ZSTD_frameHeaderSize_prefix, src, dctx->expected); @@ -2376,6 +2379,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB zds->stage = zdss_read; } /* pass-through */ + /* fallthrough */ case zdss_read: { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds->dctx); @@ -2404,6 +2408,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB zds->stage = zdss_load; /* pass-through */ } + /* fallthrough */ case zdss_load: { size_t const neededInSize = ZSTD_nextSrcSizeToDecompress(zds->dctx); @@ -2436,6 +2441,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB /* pass-through */ } } + /* fallthrough */ case zdss_flush: { size_t const toFlushSize = zds->outEnd - zds->outStart; @@ -2486,43 +2492,3 @@ size_t ZSTD_decompressStream(ZSTD_DStream *zds, ZSTD_outBuffer *output, ZSTD_inB return nextSrcSizeHint; } } - -EXPORT_SYMBOL(ZSTD_DCtxWorkspaceBound); -EXPORT_SYMBOL(ZSTD_initDCtx); -EXPORT_SYMBOL(ZSTD_decompressDCtx); -EXPORT_SYMBOL(ZSTD_decompress_usingDict); - -EXPORT_SYMBOL(ZSTD_DDictWorkspaceBound); -EXPORT_SYMBOL(ZSTD_initDDict); -EXPORT_SYMBOL(ZSTD_decompress_usingDDict); - -EXPORT_SYMBOL(ZSTD_DStreamWorkspaceBound); -EXPORT_SYMBOL(ZSTD_initDStream); -EXPORT_SYMBOL(ZSTD_initDStream_usingDDict); -EXPORT_SYMBOL(ZSTD_resetDStream); -EXPORT_SYMBOL(ZSTD_decompressStream); -EXPORT_SYMBOL(ZSTD_DStreamInSize); -EXPORT_SYMBOL(ZSTD_DStreamOutSize); - -EXPORT_SYMBOL(ZSTD_findFrameCompressedSize); -EXPORT_SYMBOL(ZSTD_getFrameContentSize); -EXPORT_SYMBOL(ZSTD_findDecompressedSize); - -EXPORT_SYMBOL(ZSTD_isFrame); -EXPORT_SYMBOL(ZSTD_getDictID_fromDict); -EXPORT_SYMBOL(ZSTD_getDictID_fromDDict); -EXPORT_SYMBOL(ZSTD_getDictID_fromFrame); - -EXPORT_SYMBOL(ZSTD_getFrameParams); -EXPORT_SYMBOL(ZSTD_decompressBegin); -EXPORT_SYMBOL(ZSTD_decompressBegin_usingDict); -EXPORT_SYMBOL(ZSTD_copyDCtx); -EXPORT_SYMBOL(ZSTD_nextSrcSizeToDecompress); -EXPORT_SYMBOL(ZSTD_decompressContinue); -EXPORT_SYMBOL(ZSTD_nextInputType); - -EXPORT_SYMBOL(ZSTD_decompressBlock); -EXPORT_SYMBOL(ZSTD_insertBlock); - -MODULE_LICENSE("Dual BSD/GPL"); -MODULE_DESCRIPTION("Zstd Decompressor"); diff --git a/grub-core/lib/zstd/error_private.h b/grub-core/lib/zstd/error_private.h index 1a60b31f7..02e6736ea 100644 --- a/grub-core/lib/zstd/error_private.h +++ b/grub-core/lib/zstd/error_private.h @@ -22,8 +22,7 @@ /* **************************************** * Dependencies ******************************************/ -#include /* size_t */ -#include /* enum list */ +#include "zstd.h" /* **************************************** * Compiler-specific diff --git a/grub-core/lib/zstd/fse.h b/grub-core/lib/zstd/fse.h index 7460ab04b..b39639745 100644 --- a/grub-core/lib/zstd/fse.h +++ b/grub-core/lib/zstd/fse.h @@ -43,7 +43,7 @@ /*-***************************************** * Dependencies ******************************************/ -#include /* size_t, ptrdiff_t */ +#include "kerncompat.h" /*-***************************************** * FSE_PUBLIC_API : control library symbols visibility diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c index a84300e5a..35b05e3c0 100644 --- a/grub-core/lib/zstd/fse_decompress.c +++ b/grub-core/lib/zstd/fse_decompress.c @@ -47,9 +47,6 @@ ****************************************************************/ #include "bitstream.h" #include "fse.h" -#include -#include -#include /* memcpy, memset */ /* ************************************************************** * Error Management diff --git a/grub-core/lib/zstd/huf.h b/grub-core/lib/zstd/huf.h index 2143da28d..2b2ac96c2 100644 --- a/grub-core/lib/zstd/huf.h +++ b/grub-core/lib/zstd/huf.h @@ -41,7 +41,7 @@ #define HUF_H_298734234 /* *** Dependencies *** */ -#include /* size_t */ +#include "kerncompat.h" /* *** Tool functions *** */ #define HUF_BLOCKSIZE_MAX (128 * 1024) /**< maximum input size for a single block compressed with HUF_compress */ diff --git a/grub-core/lib/zstd/huf_decompress.c b/grub-core/lib/zstd/huf_decompress.c index 652648204..fdad9cf98 100644 --- a/grub-core/lib/zstd/huf_decompress.c +++ b/grub-core/lib/zstd/huf_decompress.c @@ -48,9 +48,6 @@ #include "bitstream.h" /* BIT_* */ #include "fse.h" /* header compression */ #include "huf.h" -#include -#include -#include /* memcpy, memset */ /* ************************************************************** * Error Management diff --git a/grub-core/lib/zstd/kerncompat.h b/grub-core/lib/zstd/kerncompat.h new file mode 100644 index 000000000..219749d7b --- /dev/null +++ b/grub-core/lib/zstd/kerncompat.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2007 Oracle. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License v2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 021110-1307, USA. + */ + +#ifndef KERNCOMPAT_H +#define KERNCOMPAT_H + +#include +#include +#include +#include +#include + +#include + +#define get_unaligned_le16(p) grub_le_to_cpu16(grub_get_unaligned16((p))) +#define get_unaligned_be16(p) grub_be_to_cpu16(grub_get_unaligned16((p))) +#define get_unaligned_16(p) grub_get_unaligned16((p)) +#define put_unaligned_le16(val,p) grub_set_unaligned16((p), grub_cpu_to_le16((val))) +#define put_unaligned_be16(val,p) grub_set_unaligned16((p), grub_cpu_to_be16((val))) +#define put_unaligned_16(val,p) grub_set_unaligned16((p), (val)) + +#define get_unaligned_le32(p) grub_le_to_cpu32(grub_get_unaligned32((p))) +#define get_unaligned_be32(p) grub_be_to_cpu32(grub_get_unaligned32((p))) +#define get_unaligned_32(p) grub_get_unaligned32((p)) +#define put_unaligned_le32(val,p) grub_set_unaligned32((p), grub_cpu_to_le32((val))) +#define put_unaligned_be32(val,p) grub_set_unaligned32((p), grub_cpu_to_be32((val))) +#define put_unaligned_32(val,p) grub_set_unaligned32((p), (val)) + +#define get_unaligned_le64(p) grub_le_to_cpu64(grub_get_unaligned64((p))) +#define get_unaligned_be64(p) grub_be_to_cpu64(grub_get_unaligned64((p))) +#define get_unaligned_64(p) grub_get_unaligned64((p)) +#define put_unaligned_le64(val,p) grub_set_unaligned64((p), grub_cpu_to_le64((val))) +#define put_unaligned_be64(val,p) grub_set_unaligned64((p), grub_cpu_to_be64((val))) +#define put_unaligned_64(val,p) grub_set_unaligned64((p), (val)) + +#ifndef noinline +# define noinline +#endif + +#ifndef __always_inline +# ifdef __GNUC__ +# define __always_inline inline __attribute__((__always_inline__)) +# else +# define __always_inline inline +# endif +#endif + +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) +#define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) +#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) + +#endif /* KERNCOMPAT_H */ diff --git a/grub-core/lib/zstd/mem.h b/grub-core/lib/zstd/mem.h index 3a0f34c87..0e0ede37c 100644 --- a/grub-core/lib/zstd/mem.h +++ b/grub-core/lib/zstd/mem.h @@ -20,9 +20,7 @@ /*-**************************************** * Dependencies ******************************************/ -#include -#include /* memcpy */ -#include /* size_t, ptrdiff_t */ +#include "kerncompat.h" /*-**************************************** * Compiler specifics @@ -32,15 +30,15 @@ /*-************************************************************** * Basic Types *****************************************************************/ -typedef uint8_t BYTE; -typedef uint16_t U16; -typedef int16_t S16; -typedef uint32_t U32; -typedef int32_t S32; -typedef uint64_t U64; -typedef int64_t S64; -typedef ptrdiff_t iPtrDiff; -typedef uintptr_t uPtrDiff; +#include +typedef grub_uint8_t BYTE; +typedef grub_uint16_t U16; +typedef grub_int16_t S16; +typedef grub_uint32_t U32; +typedef grub_int32_t S32; +typedef grub_uint64_t U64; +typedef grub_int64_t S64; +typedef grub_size_t uPtrDiff; /*-************************************************************** * Memory I/O @@ -56,19 +54,25 @@ ZSTD_STATIC unsigned ZSTD_64bits(void) { return sizeof(size_t) == 8; } ZSTD_STATIC unsigned ZSTD_isLittleEndian(void) { return ZSTD_LITTLE_ENDIAN; } -ZSTD_STATIC U16 ZSTD_read16(const void *memPtr) { return get_unaligned((const U16 *)memPtr); } +ZSTD_STATIC U16 ZSTD_read16(const void *memPtr) { return get_unaligned_16(memPtr); } -ZSTD_STATIC U32 ZSTD_read32(const void *memPtr) { return get_unaligned((const U32 *)memPtr); } +ZSTD_STATIC U32 ZSTD_read32(const void *memPtr) { return get_unaligned_32(memPtr); } -ZSTD_STATIC U64 ZSTD_read64(const void *memPtr) { return get_unaligned((const U64 *)memPtr); } +ZSTD_STATIC U64 ZSTD_read64(const void *memPtr) { return get_unaligned_64(memPtr); } -ZSTD_STATIC size_t ZSTD_readST(const void *memPtr) { return get_unaligned((const size_t *)memPtr); } +ZSTD_STATIC size_t ZSTD_readST(const void *memPtr) +{ + if (ZSTD_32bits()) + return get_unaligned_32(memPtr); + else + return get_unaligned_64(memPtr); +} -ZSTD_STATIC void ZSTD_write16(void *memPtr, U16 value) { put_unaligned(value, (U16 *)memPtr); } +ZSTD_STATIC void ZSTD_write16(void *memPtr, U16 value) { put_unaligned_16(value, memPtr); } -ZSTD_STATIC void ZSTD_write32(void *memPtr, U32 value) { put_unaligned(value, (U32 *)memPtr); } +ZSTD_STATIC void ZSTD_write32(void *memPtr, U32 value) { put_unaligned_32(value, memPtr); } -ZSTD_STATIC void ZSTD_write64(void *memPtr, U64 value) { put_unaligned(value, (U64 *)memPtr); } +ZSTD_STATIC void ZSTD_write64(void *memPtr, U64 value) { put_unaligned_64(value, memPtr); } /*=== Little endian r/w ===*/ diff --git a/grub-core/lib/zstd/xxhash.c b/grub-core/lib/zstd/xxhash.c index aa61e2a38..d5bd26097 100644 --- a/grub-core/lib/zstd/xxhash.c +++ b/grub-core/lib/zstd/xxhash.c @@ -38,13 +38,8 @@ * - xxHash source repository: https://github.com/Cyan4973/xxHash */ -#include -#include -#include -#include -#include -#include -#include +#include "kerncompat.h" +#include "xxhash.h" /*-************************************* * Macros @@ -80,13 +75,11 @@ void xxh32_copy_state(struct xxh32_state *dst, const struct xxh32_state *src) { memcpy(dst, src, sizeof(*dst)); } -EXPORT_SYMBOL(xxh32_copy_state); void xxh64_copy_state(struct xxh64_state *dst, const struct xxh64_state *src) { memcpy(dst, src, sizeof(*dst)); } -EXPORT_SYMBOL(xxh64_copy_state); /*-*************************** * Simple Hash Functions @@ -151,7 +144,6 @@ uint32_t xxh32(const void *input, const size_t len, const uint32_t seed) return h32; } -EXPORT_SYMBOL(xxh32); static uint64_t xxh64_round(uint64_t acc, const uint64_t input) { @@ -234,7 +226,6 @@ uint64_t xxh64(const void *input, const size_t len, const uint64_t seed) return h64; } -EXPORT_SYMBOL(xxh64); /*-************************************************** * Advanced Hash Functions @@ -251,7 +242,6 @@ void xxh32_reset(struct xxh32_state *statePtr, const uint32_t seed) state.v4 = seed - PRIME32_1; memcpy(statePtr, &state, sizeof(state)); } -EXPORT_SYMBOL(xxh32_reset); void xxh64_reset(struct xxh64_state *statePtr, const uint64_t seed) { @@ -265,7 +255,6 @@ void xxh64_reset(struct xxh64_state *statePtr, const uint64_t seed) state.v4 = seed - PRIME64_1; memcpy(statePtr, &state, sizeof(state)); } -EXPORT_SYMBOL(xxh64_reset); int xxh32_update(struct xxh32_state *state, const void *input, const size_t len) { @@ -334,7 +323,6 @@ int xxh32_update(struct xxh32_state *state, const void *input, const size_t len) return 0; } -EXPORT_SYMBOL(xxh32_update); uint32_t xxh32_digest(const struct xxh32_state *state) { @@ -372,7 +360,6 @@ uint32_t xxh32_digest(const struct xxh32_state *state) return h32; } -EXPORT_SYMBOL(xxh32_digest); int xxh64_update(struct xxh64_state *state, const void *input, const size_t len) { @@ -439,7 +426,6 @@ int xxh64_update(struct xxh64_state *state, const void *input, const size_t len) return 0; } -EXPORT_SYMBOL(xxh64_update); uint64_t xxh64_digest(const struct xxh64_state *state) { @@ -494,7 +480,3 @@ uint64_t xxh64_digest(const struct xxh64_state *state) return h64; } -EXPORT_SYMBOL(xxh64_digest); - -MODULE_LICENSE("Dual BSD/GPL"); -MODULE_DESCRIPTION("xxHash"); diff --git a/grub-core/lib/zstd/xxhash.h b/grub-core/lib/zstd/xxhash.h index 9e1f42cb5..b089a4abd 100644 --- a/grub-core/lib/zstd/xxhash.h +++ b/grub-core/lib/zstd/xxhash.h @@ -75,7 +75,7 @@ #ifndef XXHASH_H #define XXHASH_H -#include +#include "kerncompat.h" /*-**************************** * Simple Hash Functions diff --git a/grub-core/lib/zstd/zstd.h b/grub-core/lib/zstd/zstd.h index 249575e24..302581446 100644 --- a/grub-core/lib/zstd/zstd.h +++ b/grub-core/lib/zstd/zstd.h @@ -18,7 +18,7 @@ #define ZSTD_H /* ====== Dependency ======*/ -#include /* size_t */ +#include /*-***************************************************************************** diff --git a/grub-core/lib/zstd/zstd_common.c b/grub-core/lib/zstd/zstd_common.c index a282624ee..db6327744 100644 --- a/grub-core/lib/zstd/zstd_common.c +++ b/grub-core/lib/zstd/zstd_common.c @@ -17,9 +17,9 @@ /*-************************************* * Dependencies ***************************************/ +#include "kerncompat.h" #include "error_private.h" #include "zstd_internal.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */ -#include /*=************************************************************** * Custom allocator diff --git a/grub-core/lib/zstd/zstd_internal.h b/grub-core/lib/zstd/zstd_internal.h index 1a79fab9e..990f4f13f 100644 --- a/grub-core/lib/zstd/zstd_internal.h +++ b/grub-core/lib/zstd/zstd_internal.h @@ -28,10 +28,8 @@ ***************************************/ #include "error_private.h" #include "mem.h" -#include -#include -#include -#include +#include "xxhash.h" +#include "zstd.h" /*-************************************* * shared macros @@ -127,7 +125,11 @@ static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG; * Shared functions to include for inlining *********************************************/ ZSTD_STATIC void ZSTD_copy8(void *dst, const void *src) { - memcpy(dst, src, 8); + /* When compiled in freestanding mode, the compiler can't inline memcpy() + * unless explicitly told that it is allowed to. This is a major pessimization + * for zstd, since ZSTD_wildcopy() is hot. + */ + __builtin_memcpy(dst, src, 8); } /*! ZSTD_wildcopy() : * custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */