From 20aae3c4388ac33af54bbe25328c5fe817c0bd5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarren=CC=83o?= Date: Tue, 28 Nov 2023 08:33:23 +0000 Subject: [PATCH] 8320533: Adjust capstone integration for v6 changes Reviewed-by: ihse, aph --- make/Hsdis.gmk | 2 +- make/autoconf/lib-hsdis.m4 | 14 ++++++++++++++ make/autoconf/spec.gmk.in | 1 + src/utils/hsdis/capstone/hsdis-capstone.c | 8 +++++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/make/Hsdis.gmk b/make/Hsdis.gmk index ec06a89aaab..bcf01dbe152 100644 --- a/make/Hsdis.gmk +++ b/make/Hsdis.gmk @@ -47,7 +47,7 @@ ifeq ($(HSDIS_BACKEND), capstone) CAPSTONE_ARCH := CS_ARCH_X86 CAPSTONE_MODE := CS_MODE_$(OPENJDK_TARGET_CPU_BITS) else ifeq ($(call isTargetCpuArch, aarch64), true) - CAPSTONE_ARCH := CS_ARCH_ARM64 + CAPSTONE_ARCH := CS_ARCH_$(CAPSTONE_ARCH_AARCH64_NAME) CAPSTONE_MODE := CS_MODE_ARM else $(error No support for Capstone on this platform) diff --git a/make/autoconf/lib-hsdis.m4 b/make/autoconf/lib-hsdis.m4 index c020bf45054..33d8a35f8fd 100644 --- a/make/autoconf/lib-hsdis.m4 +++ b/make/autoconf/lib-hsdis.m4 @@ -63,6 +63,19 @@ AC_DEFUN([LIB_SETUP_HSDIS_CAPSTONE], AC_MSG_ERROR([Cannot continue]) fi fi + + capstone_header="\"$CAPSTONE/include/capstone/capstone.h\"" + AC_MSG_CHECKING([capstone aarch64 arch name]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include $capstone_header],[[cs_arch test = CS_ARCH_AARCH64]])], + [ + AC_MSG_RESULT([AARCH64]) + CAPSTONE_ARCH_AARCH64_NAME="AARCH64" + ], + [ + AC_MSG_RESULT([ARM64]) + CAPSTONE_ARCH_AARCH64_NAME="ARM64" + ] + ) ]) ################################################################################ @@ -365,6 +378,7 @@ AC_DEFUN_ONCE([LIB_SETUP_HSDIS], AC_SUBST(HSDIS_CFLAGS) AC_SUBST(HSDIS_LDFLAGS) AC_SUBST(HSDIS_LIBS) + AC_SUBST(CAPSTONE_ARCH_AARCH64_NAME) AC_MSG_CHECKING([if hsdis should be bundled]) if test "x$ENABLE_HSDIS_BUNDLING" = "xtrue"; then diff --git a/make/autoconf/spec.gmk.in b/make/autoconf/spec.gmk.in index 25f985bd45d..26b7d3ec958 100644 --- a/make/autoconf/spec.gmk.in +++ b/make/autoconf/spec.gmk.in @@ -377,6 +377,7 @@ ENABLE_HSDIS_BUNDLING := @ENABLE_HSDIS_BUNDLING@ HSDIS_CFLAGS := @HSDIS_CFLAGS@ HSDIS_LDFLAGS := @HSDIS_LDFLAGS@ HSDIS_LIBS := @HSDIS_LIBS@ +CAPSTONE_ARCH_AARCH64_NAME := @CAPSTONE_ARCH_AARCH64_NAME@ # The boot jdk to use. This is overridden in bootcycle-spec.gmk. Make sure to keep # it in sync. diff --git a/src/utils/hsdis/capstone/hsdis-capstone.c b/src/utils/hsdis/capstone/hsdis-capstone.c index ef65a01efca..410b88eb2db 100644 --- a/src/utils/hsdis/capstone/hsdis-capstone.c +++ b/src/utils/hsdis/capstone/hsdis-capstone.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * The Universal Permissive License (UPL), Version 1.0 @@ -52,6 +52,12 @@ #include #include +/* Undefine macro to avoid generating invalid C code. + Capstone refactored cs_detail for AArch64 architecture + from `cs_arm64 arm64` to `cs_aarch64 aarch64` + and that causes invalid macro expansion. +*/ +#undef aarch64 #include #include "hsdis.h"