Skip to content

Commit

Permalink
8320533: Adjust capstone integration for v6 changes
Browse files Browse the repository at this point in the history
Reviewed-by: ihse, aph
  • Loading branch information
galderz authored and adinn committed Nov 28, 2023
1 parent 0678253 commit 20aae3c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion make/Hsdis.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions make/autoconf/lib-hsdis.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
)
])

################################################################################
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions make/autoconf/spec.gmk.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion src/utils/hsdis/capstone/hsdis-capstone.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -52,6 +52,12 @@
#include <inttypes.h>
#include <string.h>

/* 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 <capstone.h>

#include "hsdis.h"
Expand Down

1 comment on commit 20aae3c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.