From 8151f388ebb1c48990598418f84b81955ddc5895 Mon Sep 17 00:00:00 2001 From: James Zern Date: Wed, 26 Apr 2023 13:22:52 -0700 Subject: [PATCH] move VP8GetCPUInfo declaration to cpu.c This avoids defining a version in each translation unit when using __declspec(dllexport) which causes failures due to multiply defined symbols with clang-cl: lld-link: error: duplicate symbol: VP8GetCPUInfo >>> defined at CMakeFiles\webpdecode.dir\Debug\src\dec\alpha_dec.c.obj >>> defined at CMakeFiles\webpdsp.dir\Debug\src\dsp\dec_sse41.c.obj ... Bug: webp:607 Change-Id: I6cd1ee75b3db984aa513263a05516e867a64925d --- sharpyuv/sharpyuv.c | 1 + sharpyuv/sharpyuv_dsp.c | 1 + src/dec/vp8_dec.c | 2 ++ src/dsp/alpha_processing.c | 1 + src/dsp/cost.c | 1 + src/dsp/cpu.c | 6 ++++++ src/dsp/cpu.h | 9 --------- src/dsp/dec.c | 1 + src/dsp/enc.c | 1 + src/dsp/filters.c | 1 + src/dsp/lossless.c | 1 + src/dsp/lossless_enc.c | 1 + src/dsp/rescaler.c | 1 + src/dsp/ssim.c | 1 + src/dsp/upsampling.c | 1 + src/dsp/yuv.c | 1 + src/enc/picture_csp_enc.c | 1 + tests/fuzzer/fuzz_utils.h | 5 +++++ 18 files changed, 27 insertions(+), 9 deletions(-) diff --git a/sharpyuv/sharpyuv.c b/sharpyuv/sharpyuv.c index 7de34fb0..a0745648 100644 --- a/sharpyuv/sharpyuv.c +++ b/sharpyuv/sharpyuv.c @@ -440,6 +440,7 @@ static int DoSharpArgbToYuv(const uint8_t* r_ptr, const uint8_t* g_ptr, // By default SharpYuvConvert calls it with SharpYuvGetCPUInfo. If needed, // users can declare it as extern and call it with an alternate VP8CPUInfo // function. +extern VP8CPUInfo SharpYuvGetCPUInfo; SHARPYUV_EXTERN void SharpYuvInit(VP8CPUInfo cpu_info_func); void SharpYuvInit(VP8CPUInfo cpu_info_func) { static volatile VP8CPUInfo sharpyuv_last_cpuinfo_used = diff --git a/sharpyuv/sharpyuv_dsp.c b/sharpyuv/sharpyuv_dsp.c index 31c272c4..0da3efc0 100644 --- a/sharpyuv/sharpyuv_dsp.c +++ b/sharpyuv/sharpyuv_dsp.c @@ -72,6 +72,7 @@ void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len, const uint16_t* best_y, uint16_t* out, int bit_depth); +extern VP8CPUInfo SharpYuvGetCPUInfo; extern void InitSharpYuvSSE2(void); extern void InitSharpYuvNEON(void); diff --git a/src/dec/vp8_dec.c b/src/dec/vp8_dec.c index 2003935e..20b92e84 100644 --- a/src/dec/vp8_dec.c +++ b/src/dec/vp8_dec.c @@ -494,6 +494,8 @@ static int GetCoeffsAlt(VP8BitReader* const br, return 16; } +extern VP8CPUInfo VP8GetCPUInfo; + WEBP_DSP_INIT_FUNC(InitGetCoeffs) { if (VP8GetCPUInfo != NULL && VP8GetCPUInfo(kSlowSSSE3)) { GetCoeffs = GetCoeffsAlt; diff --git a/src/dsp/alpha_processing.c b/src/dsp/alpha_processing.c index 1892929a..1d152f24 100644 --- a/src/dsp/alpha_processing.c +++ b/src/dsp/alpha_processing.c @@ -425,6 +425,7 @@ void (*WebPAlphaReplace)(uint32_t* src, int length, uint32_t color); //------------------------------------------------------------------------------ // Init function +extern VP8CPUInfo VP8GetCPUInfo; extern void WebPInitAlphaProcessingMIPSdspR2(void); extern void WebPInitAlphaProcessingSSE2(void); extern void WebPInitAlphaProcessingSSE41(void); diff --git a/src/dsp/cost.c b/src/dsp/cost.c index 460ec4f2..73d21401 100644 --- a/src/dsp/cost.c +++ b/src/dsp/cost.c @@ -374,6 +374,7 @@ static void SetResidualCoeffs_C(const int16_t* const coeffs, VP8GetResidualCostFunc VP8GetResidualCost; VP8SetResidualCoeffsFunc VP8SetResidualCoeffs; +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8EncDspCostInitMIPS32(void); extern void VP8EncDspCostInitMIPSdspR2(void); extern void VP8EncDspCostInitSSE2(void); diff --git a/src/dsp/cpu.c b/src/dsp/cpu.c index 62de73f7..2234c77b 100644 --- a/src/dsp/cpu.c +++ b/src/dsp/cpu.c @@ -173,6 +173,7 @@ static int x86CPUInfo(CPUFeature feature) { } return 0; } +WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; VP8CPUInfo VP8GetCPUInfo = x86CPUInfo; #elif defined(WEBP_ANDROID_NEON) // NB: needs to be before generic NEON test. static int AndroidCPUInfo(CPUFeature feature) { @@ -184,6 +185,7 @@ static int AndroidCPUInfo(CPUFeature feature) { } return 0; } +WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; VP8CPUInfo VP8GetCPUInfo = AndroidCPUInfo; #elif defined(EMSCRIPTEN) // also needs to be before generic NEON test // Use compile flags as an indicator of SIMD support instead of a runtime check. @@ -208,6 +210,7 @@ static int wasmCPUInfo(CPUFeature feature) { } return 0; } +WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; VP8CPUInfo VP8GetCPUInfo = wasmCPUInfo; #elif defined(WEBP_HAVE_NEON) // In most cases this function doesn't check for NEON support (it's assumed by @@ -236,6 +239,7 @@ static int armCPUInfo(CPUFeature feature) { return 1; #endif } +WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; VP8CPUInfo VP8GetCPUInfo = armCPUInfo; #elif defined(WEBP_USE_MIPS32) || defined(WEBP_USE_MIPS_DSP_R2) || \ defined(WEBP_USE_MSA) @@ -247,7 +251,9 @@ static int mipsCPUInfo(CPUFeature feature) { } } +WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; VP8CPUInfo VP8GetCPUInfo = mipsCPUInfo; #else +WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; VP8CPUInfo VP8GetCPUInfo = NULL; #endif diff --git a/src/dsp/cpu.h b/src/dsp/cpu.h index 785a0569..1b48eaa1 100644 --- a/src/dsp/cpu.h +++ b/src/dsp/cpu.h @@ -242,16 +242,7 @@ typedef enum { kMSA } CPUFeature; -#ifdef __cplusplus -extern "C" { -#endif - // returns true if the CPU supports the feature. typedef int (*VP8CPUInfo)(CPUFeature feature); -WEBP_EXTERN VP8CPUInfo VP8GetCPUInfo; - -#ifdef __cplusplus -} // extern "C" -#endif #endif // WEBP_DSP_CPU_H_ diff --git a/src/dsp/dec.c b/src/dsp/dec.c index 537c7012..33d8df8a 100644 --- a/src/dsp/dec.c +++ b/src/dsp/dec.c @@ -734,6 +734,7 @@ VP8SimpleFilterFunc VP8SimpleHFilter16i; void (*VP8DitherCombine8x8)(const uint8_t* dither, uint8_t* dst, int dst_stride); +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8DspInitSSE2(void); extern void VP8DspInitSSE41(void); extern void VP8DspInitNEON(void); diff --git a/src/dsp/enc.c b/src/dsp/enc.c index ea47a3fd..2ba97ba8 100644 --- a/src/dsp/enc.c +++ b/src/dsp/enc.c @@ -732,6 +732,7 @@ VP8QuantizeBlockWHT VP8EncQuantizeBlockWHT; VP8BlockCopy VP8Copy4x4; VP8BlockCopy VP8Copy16x8; +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8EncDspInitSSE2(void); extern void VP8EncDspInitSSE41(void); extern void VP8EncDspInitNEON(void); diff --git a/src/dsp/filters.c b/src/dsp/filters.c index 4506567b..85eee509 100644 --- a/src/dsp/filters.c +++ b/src/dsp/filters.c @@ -233,6 +233,7 @@ static void GradientUnfilter_C(const uint8_t* prev, const uint8_t* in, WebPFilterFunc WebPFilters[WEBP_FILTER_LAST]; WebPUnfilterFunc WebPUnfilters[WEBP_FILTER_LAST]; +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8FiltersInitMIPSdspR2(void); extern void VP8FiltersInitMSA(void); extern void VP8FiltersInitNEON(void); diff --git a/src/dsp/lossless.c b/src/dsp/lossless.c index fb86e58d..9f812094 100644 --- a/src/dsp/lossless.c +++ b/src/dsp/lossless.c @@ -588,6 +588,7 @@ VP8LConvertFunc VP8LConvertBGRAToBGR; VP8LMapARGBFunc VP8LMapColor32b; VP8LMapAlphaFunc VP8LMapColor8b; +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8LDspInitSSE2(void); extern void VP8LDspInitSSE41(void); extern void VP8LDspInitNEON(void); diff --git a/src/dsp/lossless_enc.c b/src/dsp/lossless_enc.c index b1f9f26d..cde12806 100644 --- a/src/dsp/lossless_enc.c +++ b/src/dsp/lossless_enc.c @@ -791,6 +791,7 @@ VP8LBundleColorMapFunc VP8LBundleColorMap; VP8LPredictorAddSubFunc VP8LPredictorsSub[16]; VP8LPredictorAddSubFunc VP8LPredictorsSub_C[16]; +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8LEncDspInitSSE2(void); extern void VP8LEncDspInitSSE41(void); extern void VP8LEncDspInitNEON(void); diff --git a/src/dsp/rescaler.c b/src/dsp/rescaler.c index 14620ce4..325d8be1 100644 --- a/src/dsp/rescaler.c +++ b/src/dsp/rescaler.c @@ -197,6 +197,7 @@ WebPRescalerImportRowFunc WebPRescalerImportRowShrink; WebPRescalerExportRowFunc WebPRescalerExportRowExpand; WebPRescalerExportRowFunc WebPRescalerExportRowShrink; +extern VP8CPUInfo VP8GetCPUInfo; extern void WebPRescalerDspInitSSE2(void); extern void WebPRescalerDspInitMIPS32(void); extern void WebPRescalerDspInitMIPSdspR2(void); diff --git a/src/dsp/ssim.c b/src/dsp/ssim.c index f85c2e6e..9a1341ed 100644 --- a/src/dsp/ssim.c +++ b/src/dsp/ssim.c @@ -137,6 +137,7 @@ VP8SSIMGetClippedFunc VP8SSIMGetClipped; VP8AccumulateSSEFunc VP8AccumulateSSE; #endif +extern VP8CPUInfo VP8GetCPUInfo; extern void VP8SSIMDspInitSSE2(void); WEBP_DSP_INIT_FUNC(VP8SSIMDspInit) { diff --git a/src/dsp/upsampling.c b/src/dsp/upsampling.c index 87f771f3..983b9c42 100644 --- a/src/dsp/upsampling.c +++ b/src/dsp/upsampling.c @@ -215,6 +215,7 @@ static void EmptyYuv444Func(const uint8_t* y, WebPYUV444Converter WebPYUV444Converters[MODE_LAST]; +extern VP8CPUInfo VP8GetCPUInfo; extern void WebPInitYUV444ConvertersMIPSdspR2(void); extern void WebPInitYUV444ConvertersSSE2(void); extern void WebPInitYUV444ConvertersSSE41(void); diff --git a/src/dsp/yuv.c b/src/dsp/yuv.c index d16c13d3..8a04b85d 100644 --- a/src/dsp/yuv.c +++ b/src/dsp/yuv.c @@ -70,6 +70,7 @@ void WebPSamplerProcessPlane(const uint8_t* y, int y_stride, WebPSamplerRowFunc WebPSamplers[MODE_LAST]; +extern VP8CPUInfo VP8GetCPUInfo; extern void WebPInitSamplersSSE2(void); extern void WebPInitSamplersSSE41(void); extern void WebPInitSamplersMIPS32(void); diff --git a/src/enc/picture_csp_enc.c b/src/enc/picture_csp_enc.c index 78c8ca47..3225df42 100644 --- a/src/enc/picture_csp_enc.c +++ b/src/enc/picture_csp_enc.c @@ -98,6 +98,7 @@ static int kLinearToGammaTab[GAMMA_TAB_SIZE + 1]; static uint16_t kGammaToLinearTab[256]; static volatile int kGammaTablesOk = 0; static void InitGammaTables(void); +extern VP8CPUInfo VP8GetCPUInfo; WEBP_DSP_INIT_FUNC(InitGammaTables) { if (!kGammaTablesOk) { diff --git a/tests/fuzzer/fuzz_utils.h b/tests/fuzzer/fuzz_utils.h index 3a4c5584..922950dc 100644 --- a/tests/fuzzer/fuzz_utils.h +++ b/tests/fuzzer/fuzz_utils.h @@ -74,6 +74,11 @@ static WEBP_INLINE uint32_t Extract(uint32_t max_value, //------------------------------------------------------------------------------ // Some functions to override VP8GetCPUInfo and disable some optimizations. +#ifdef __cplusplus +extern "C" VP8CPUInfo VP8GetCPUInfo; +#else +extern VP8CPUInfo VP8GetCPUInfo; +#endif static VP8CPUInfo GetCPUInfo; static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) {