mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-07-24 15:27:41 +08:00
fix(shutdown): make AddressSanitizer check portable on GCC
GCC does not provide __has_feature, and its preprocessor tokenizes both
operands of && before evaluating the operator, so
#if defined(__SANITIZE_ADDRESS__) || defined(__has_feature) && __has_feature(address_sanitizer)
failed to compile with 'missing binary operator before token "("' on
toolchains such as the voxl2 linaro GCC. Add the standard __has_feature
fallback shim so the check uses __SANITIZE_ADDRESS__ on GCC and the real
__has_feature on Clang. Behavior is unchanged.
Signed-off-by: Julian Oes <julian@oes.ch>
This commit is contained in:
@@ -62,6 +62,14 @@
|
||||
|
||||
#include <sys/boardctl.h>
|
||||
|
||||
// Clang provides __has_feature; GCC does not. Define a fallback so the
|
||||
// AddressSanitizer check below is portable: GCC's preprocessor otherwise
|
||||
// chokes on __has_feature(...) even when guarded by defined(__has_feature),
|
||||
// because both operands of && are tokenized before the && is evaluated.
|
||||
#ifndef __has_feature
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
static pthread_mutex_t shutdown_mutex =
|
||||
@@ -283,7 +291,7 @@ static void shutdown_worker(void *arg)
|
||||
#elif defined(__PX4_POSIX)
|
||||
// simply exit on posix if real shutdown (poweroff) not available
|
||||
PX4_INFO_RAW("Exiting NOW.");
|
||||
#if defined(__SANITIZE_ADDRESS__) || defined(__has_feature) && __has_feature(address_sanitizer)
|
||||
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
|
||||
exit(0); // Use exit() instead of _exit() so ASAN can report errors
|
||||
#else
|
||||
system_exit(0);
|
||||
|
||||
Reference in New Issue
Block a user