From 5ffc05f7a72e9e0eb0906ba60c15a425e11214b0 Mon Sep 17 00:00:00 2001 From: Dale Glass Date: Sun, 28 Mar 2021 18:42:35 +0200 Subject: [PATCH] Fix HIFI_MEMORY_DEBUGGING on Linux/gcc It seems that libasan was running into some sort of trouble due to static linking. Additionally, -fstack-protector-strong has been enabled by disabling the usage of the FIR_1x4_AVX512 function under memory debugging. --- cmake/macros/MemoryDebugger.cmake | 11 ++++++++--- libraries/audio/src/AudioHRTF.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cmake/macros/MemoryDebugger.cmake b/cmake/macros/MemoryDebugger.cmake index 09716715f0..ebcd55a7dc 100644 --- a/cmake/macros/MemoryDebugger.cmake +++ b/cmake/macros/MemoryDebugger.cmake @@ -21,9 +21,14 @@ if (HIFI_MEMORY_DEBUGGING) SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -shared-libasan -fsanitize=undefined -fsanitize=address -fsanitize-recover=address") else () # for gcc on Linux - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address -U_FORTIFY_SOURCE -fno-stack-protector -fno-omit-frame-pointer") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libasan -static-libstdc++ -fsanitize=undefined -fsanitize=address") - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libasan -static-libstdc++ -fsanitize=undefined -fsanitize=address") + # For some reason, using -fstack-protector results in this error: + # usr/bin/ld: ../../libraries/audio/libaudio.so: undefined reference to `FIR_1x4_AVX512(float*, float*, float*, float*, float*, float (*) [64], int)' + # The '-DSTACK_PROTECTOR' argument below disables the usage of this function in the code. This should be fine as it only works on the latest Intel hardware, + # and is an optimization that should make no functional difference. + + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fsanitize=address -U_FORTIFY_SOURCE -DSTACK_PROTECTOR -fstack-protector-strong -fno-omit-frame-pointer") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address") + SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address") endif() endif (UNIX) endif () diff --git a/libraries/audio/src/AudioHRTF.cpp b/libraries/audio/src/AudioHRTF.cpp index be7fecb450..fa8665d1a9 100644 --- a/libraries/audio/src/AudioHRTF.cpp +++ b/libraries/audio/src/AudioHRTF.cpp @@ -91,8 +91,8 @@ static const float azimuthTable[NAZIMUTH][3] = { // A first-order shelving filter is used to minimize the disturbance in ITD. // // Loosely based on data from S. Spagnol, "Distance rendering and perception of nearby virtual sound sources -// with a near-field filter model,” Applied Acoustics (2017) -// +// with a near-field filter model," Applied Acoustics (2017) +// static const int NNEARFIELD = 9; static const float nearFieldTable[NNEARFIELD][3] = { // { b0, b1, a1 } { 0.008410604f, -0.000262748f, -0.991852144f }, // gain = 1/256 @@ -388,7 +388,12 @@ void crossfade_4x2_AVX2(float* src, float* dst, const float* win, int numFrames) void interpolate_AVX2(const float* src0, const float* src1, float* dst, float frac, float gain); static void FIR_1x4(float* src, float* dst0, float* dst1, float* dst2, float* dst3, float coef[4][HRTF_TAPS], int numFrames) { +#ifndef STACK_PROTECTOR + // Enabling -fstack-protector on gcc causes an undefined reference to FIR_1x4_AVX512 here static auto f = cpuSupportsAVX512() ? FIR_1x4_AVX512 : (cpuSupportsAVX2() ? FIR_1x4_AVX2 : FIR_1x4_SSE); +#else + static auto f = cpuSupportsAVX2() ? FIR_1x4_AVX2 : FIR_1x4_SSE; +#endif (*f)(src, dst0, dst1, dst2, dst3, coef, numFrames); // dispatch }