From 4a0abd6869710393b39f2cadbbff0dc8c55b883b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Guidi?= Date: Fri, 10 Mar 2023 10:03:17 -0500 Subject: [PATCH] configure: Check for membarrier support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Runtime dynamic patching requires cache synchronization. This is best achieved by using the 'MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE' memory barrier. However it was introduced in Linux 4.16. We set a flag indicating whether this membarrier can be used or if libmcount has to rely on other mechanisms (e.g. signals). Signed-off-by: Clément Guidi --- check-deps/Makefile | 1 + check-deps/Makefile.check | 4 ++++ check-deps/__have_membarrier.c | 10 ++++++++++ configure | 3 +++ 4 files changed, 18 insertions(+) create mode 100644 check-deps/__have_membarrier.c diff --git a/check-deps/Makefile b/check-deps/Makefile index 2ca41b3ee..8f06dfae4 100644 --- a/check-deps/Makefile +++ b/check-deps/Makefile @@ -14,6 +14,7 @@ CHECK_LIST += have_libdw CHECK_LIST += have_libunwind CHECK_LIST += have_libcapstone CHECK_LIST += cc_has_minline_all_stringops +CHECK_LIST += have_membarrier # # This is needed for checking build dependency diff --git a/check-deps/Makefile.check b/check-deps/Makefile.check index 93443e145..85042658d 100644 --- a/check-deps/Makefile.check +++ b/check-deps/Makefile.check @@ -82,3 +82,7 @@ endif ifneq ($(wildcard $(objdir)/check-deps/cc_has_minline_all_stringops),) LIB_CFLAGS += -minline-all-stringops endif + +ifneq ($(wildcard $(objdir)/check-deps/have_membarrier),) + LIB_CFLAGS += -DHAVE_MEMBARRIER +endif diff --git a/check-deps/__have_membarrier.c b/check-deps/__have_membarrier.c new file mode 100644 index 000000000..30a7c5a92 --- /dev/null +++ b/check-deps/__have_membarrier.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int main() +{ + syscall(__NR_membarrier, MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE, 0, 0); + syscall(__NR_membarrier, MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE, 0, 0); + return 0; +} diff --git a/configure b/configure index 237e5619c..fe7289afd 100755 --- a/configure +++ b/configure @@ -35,6 +35,7 @@ usage() { --without-capstone build without libcapstone (even if found on the system) --without-perf build without perf event (even if available) --without-schedule build without scheduler event (even if available) + --without-membarrier build without membarriers (even if available) --arch= set target architecture (default: system default arch) e.g. x86_64, aarch64, i386, or arm @@ -198,6 +199,7 @@ for dep in $IGNORE; do capstone) TARGET=have_libcapstone ;; perf*) TARGET=perf_clockid ;; sched*) TARGET=perf_context_switch;; + membarrier) TARGET=have_membarrier ;; *) ;; esac if [ ! -z "$TARGET" ]; then @@ -265,6 +267,7 @@ print_feature "perf_event" "perf_clockid" "perf (PMU) event support" print_feature "schedule" "perf_context_switch" "scheduler event support" print_feature "capstone" "have_libcapstone" "full dynamic tracing support" print_feature "libunwind" "have_libunwind" "stacktrace support (optional for debugging)" +print_feature "membarrier" "have_membarrier" "membarrier support (requires Linux 4.16)" cat >$output <