From c713f846168f4d6fd6a5e2150a115eaa661e5c77 Mon Sep 17 00:00:00 2001 From: James Zern Date: Fri, 14 Feb 2020 17:31:42 -0800 Subject: [PATCH] move common attribute defs to compiler_attributes.h BUG=b/148271109 Change-Id: I620e26ff1233fcd34ebe0723cb913e82eb58271c --- examples.mk | 2 ++ md5_utils.c | 14 +------- vp8/common/reconintra4x4.c | 2 +- vp9/encoder/vp9_pickmode.c | 2 +- vpx_dsp/x86/convolve.h | 2 +- vpx_ports/compiler_attributes.h | 59 +++++++++++++++++++++++++++++++++ vpx_ports/mem.h | 30 ----------------- vpx_ports/vpx_ports.mk | 1 + 8 files changed, 66 insertions(+), 46 deletions(-) create mode 100644 vpx_ports/compiler_attributes.h diff --git a/examples.mk b/examples.mk index 758ca7f88..a28e52935 100644 --- a/examples.mk +++ b/examples.mk @@ -65,6 +65,7 @@ endif # while EXAMPLES demonstrate specific portions of the API. UTILS-$(CONFIG_DECODERS) += vpxdec.c vpxdec.SRCS += md5_utils.c md5_utils.h +vpxdec.SRCS += vpx_ports/compiler_attributes.h vpxdec.SRCS += vpx_ports/mem_ops.h vpxdec.SRCS += vpx_ports/mem_ops_aligned.h vpxdec.SRCS += vpx_ports/msvc.h @@ -167,6 +168,7 @@ decode_to_md5.SRCS += y4minput.c y4minput.h decode_to_md5.SRCS += tools_common.h tools_common.c decode_to_md5.SRCS += video_common.h decode_to_md5.SRCS += video_reader.h video_reader.c +decode_to_md5.SRCS += vpx_ports/compiler_attributes.h decode_to_md5.SRCS += vpx_ports/mem_ops.h decode_to_md5.SRCS += vpx_ports/mem_ops_aligned.h decode_to_md5.SRCS += vpx_ports/msvc.h diff --git a/md5_utils.c b/md5_utils.c index 9ddb104c8..c4106525f 100644 --- a/md5_utils.c +++ b/md5_utils.c @@ -23,6 +23,7 @@ #include /* for memcpy() */ #include "md5_utils.h" +#include "vpx_ports/compiler_attributes.h" static void byteSwap(UWORD32 *buf, unsigned words) { md5byte *p; @@ -145,17 +146,6 @@ void MD5Final(md5byte digest[16], struct MD5Context *ctx) { #define MD5STEP(f, w, x, y, z, in, s) \ (w += f(x, y, z) + in, w = (w << s | w >> (32 - s)) + x) -#if defined(__clang__) && defined(__has_attribute) -#if __has_attribute(no_sanitize) -#define VPX_NO_UNSIGNED_OVERFLOW_CHECK \ - __attribute__((no_sanitize("unsigned-integer-overflow"))) -#endif -#endif - -#ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK -#define VPX_NO_UNSIGNED_OVERFLOW_CHECK -#endif - /* * The core of the MD5 algorithm, this alters an existing MD5 hash to * reflect the addition of 16 longwords of new data. MD5Update blocks @@ -244,6 +234,4 @@ VPX_NO_UNSIGNED_OVERFLOW_CHECK void MD5Transform(UWORD32 buf[4], buf[3] += d; } -#undef VPX_NO_UNSIGNED_OVERFLOW_CHECK - #endif diff --git a/vp8/common/reconintra4x4.c b/vp8/common/reconintra4x4.c index 64d33a287..be936df5e 100644 --- a/vp8/common/reconintra4x4.c +++ b/vp8/common/reconintra4x4.c @@ -16,7 +16,7 @@ #include "blockd.h" #include "reconintra4x4.h" #include "vp8/common/common.h" -#include "vpx_ports/mem.h" +#include "vpx_ports/compiler_attributes.h" typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride, const uint8_t *above, const uint8_t *left); diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 9b2e48505..23c943c21 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -19,7 +19,7 @@ #include "vpx/vpx_codec.h" #include "vpx_dsp/vpx_dsp_common.h" #include "vpx_mem/vpx_mem.h" -#include "vpx_ports/mem.h" +#include "vpx_ports/compiler_attributes.h" #include "vp9/common/vp9_blockd.h" #include "vp9/common/vp9_common.h" diff --git a/vpx_dsp/x86/convolve.h b/vpx_dsp/x86/convolve.h index 6fd40fef9..c33960055 100644 --- a/vpx_dsp/x86/convolve.h +++ b/vpx_dsp/x86/convolve.h @@ -14,7 +14,7 @@ #include "./vpx_config.h" #include "vpx/vpx_integer.h" -#include "vpx_ports/mem.h" +#include "vpx_ports/compiler_attributes.h" // TODO(chiyotsai@google.com): Refactor the code here. Currently this is pretty // hacky and awful to read. Note that there is a filter_x[3] == 128 check in diff --git a/vpx_ports/compiler_attributes.h b/vpx_ports/compiler_attributes.h new file mode 100644 index 000000000..354352016 --- /dev/null +++ b/vpx_ports/compiler_attributes.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 The WebM project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_ +#define VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_ + +#if !defined(__has_feature) +#define __has_feature(x) 0 +#endif // !defined(__has_feature) + +#if !defined(__has_attribute) +#define __has_attribute(x) 0 +#endif // !defined(__has_attribute) + +//------------------------------------------------------------------------------ +// Sanitizer attributes. + +#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) +#define VPX_WITH_ASAN 1 +#else +#define VPX_WITH_ASAN 0 +#endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) + +#if defined(__clang__) && __has_attribute(no_sanitize) +#define VPX_NO_UNSIGNED_OVERFLOW_CHECK \ + __attribute__((no_sanitize("unsigned-integer-overflow"))) +#endif + +#ifndef VPX_NO_UNSIGNED_OVERFLOW_CHECK +#define VPX_NO_UNSIGNED_OVERFLOW_CHECK +#endif + +//------------------------------------------------------------------------------ +// Variable attributes. + +#if __has_attribute(uninitialized) +// Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for +// the specified variable. +// +// -ftrivial-auto-var-init is security risk mitigation feature, so attribute +// should not be used "just in case", but only to fix real performance +// bottlenecks when other approaches do not work. In general the compiler is +// quite effective at eliminating unneeded initializations introduced by the +// flag, e.g. when they are followed by actual initialization by a program. +// However if compiler optimization fails and code refactoring is hard, the +// attribute can be used as a workaround. +#define VPX_UNINITIALIZED __attribute__((uninitialized)) +#else +#define VPX_UNINITIALIZED +#endif // __has_attribute(uninitialized) + +#endif // VPX_VPX_PORTS_COMPILER_ATTRIBUTES_H_ diff --git a/vpx_ports/mem.h b/vpx_ports/mem.h index 4e9041304..5eccfe8f5 100644 --- a/vpx_ports/mem.h +++ b/vpx_ports/mem.h @@ -41,34 +41,4 @@ #define CAST_TO_BYTEPTR(x) ((uint8_t *)((uintptr_t)(x))) #endif // CONFIG_VP9_HIGHBITDEPTH -#if !defined(__has_feature) -#define __has_feature(x) 0 -#endif // !defined(__has_feature) - -#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) -#define VPX_WITH_ASAN 1 -#else -#define VPX_WITH_ASAN 0 -#endif // __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) - -#if !defined(__has_attribute) -#define __has_attribute(x) 0 -#endif // !defined(__has_attribute) - -#if __has_attribute(uninitialized) -// Attribute "uninitialized" disables -ftrivial-auto-var-init=pattern for -// the specified variable. -// -// -ftrivial-auto-var-init is security risk mitigation feature, so attribute -// should not be used "just in case", but only to fix real performance -// bottlenecks when other approaches do not work. In general the compiler is -// quite effective at eliminating unneeded initializations introduced by the -// flag, e.g. when they are followed by actual initialization by a program. -// However if compiler optimization fails and code refactoring is hard, the -// attribute can be used as a workaround. -#define VPX_UNINITIALIZED __attribute__((uninitialized)) -#else -#define VPX_UNINITIALIZED -#endif // __has_attribute(uninitialized) - #endif // VPX_VPX_PORTS_MEM_H_ diff --git a/vpx_ports/vpx_ports.mk b/vpx_ports/vpx_ports.mk index 53fbd1e80..233177369 100644 --- a/vpx_ports/vpx_ports.mk +++ b/vpx_ports/vpx_ports.mk @@ -12,6 +12,7 @@ PORTS_SRCS-yes += vpx_ports.mk PORTS_SRCS-yes += bitops.h +PORTS_SRCS-yes += compiler_attributes.h PORTS_SRCS-yes += mem.h PORTS_SRCS-yes += msvc.h PORTS_SRCS-yes += static_assert.h -- 2.40.0