From 06b1eff6eca2980fe49fafd90b64ba3e93ea3748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 17 Jul 2024 19:30:12 +0200 Subject: [PATCH] zydis: build static lib * for GCC2 build with a modern GCC as suggested by waddlesplash * make the headers compatible with GCC2 Change-Id: Ice74eeddbe10bc8f9cf9ae90baa833a46bb3c676 Reviewed-on: https://review.haiku-os.org/c/haiku/+/7848 Reviewed-by: waddlesplash --- headers/libs/zydis/Zycore/Format.h | 2 + headers/libs/zydis/Zydis/FormatterBuffer.h | 4 ++ headers/libs/zydis/Zydis/ShortString.h | 4 +- src/libs/Jamfile | 1 + src/libs/zydis/Jamfile | 63 ++++++++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/libs/zydis/Jamfile diff --git a/headers/libs/zydis/Zycore/Format.h b/headers/libs/zydis/Zycore/Format.h index 006ca3126e..2dd05db84b 100644 --- a/headers/libs/zydis/Zycore/Format.h +++ b/headers/libs/zydis/Zycore/Format.h @@ -61,10 +61,12 @@ ZYAN_INLINE ZyanU64 ZyanAbsI64(ZyanI64 x) // INT_MIN special case. Can't use the value directly because GCC thinks // it's too big for an INT64 literal, however is perfectly happy to accept // this expression. This is also hit INT64_MIN is defined in `stdint.h`. +#if defined(__GNUC__) && (__GNUC__ >= 4) if (x == (-0x7fffffffffffffff - 1)) { return 0x8000000000000000u; } +#endif return (ZyanU64)(x < 0 ? -x : x); } diff --git a/headers/libs/zydis/Zydis/FormatterBuffer.h b/headers/libs/zydis/Zydis/FormatterBuffer.h index 3a397e5eef..fbfb5d7258 100644 --- a/headers/libs/zydis/Zydis/FormatterBuffer.h +++ b/headers/libs/zydis/Zydis/FormatterBuffer.h @@ -127,7 +127,9 @@ typedef ZyanU8 ZydisTokenType; /* Token */ /* ---------------------------------------------------------------------------------------------- */ +#if !defined(__HAIKU__) || (defined(__GNUC__) && (__GNUC__ >= 4)) #pragma pack(push, 1) +#endif /** * Defines the `ZydisFormatterToken` struct. @@ -147,7 +149,9 @@ typedef struct ZydisFormatterToken_ ZyanU8 next; } ZydisFormatterToken; +#if !defined(__HAIKU__) || (defined(__GNUC__) && (__GNUC__ >= 4)) #pragma pack(pop) +#endif /** * Defines the `ZydisFormatterTokenConst` data-type. diff --git a/headers/libs/zydis/Zydis/ShortString.h b/headers/libs/zydis/Zydis/ShortString.h index cac57a37e5..1b6ea2af5d 100644 --- a/headers/libs/zydis/Zydis/ShortString.h +++ b/headers/libs/zydis/Zydis/ShortString.h @@ -44,7 +44,7 @@ extern "C" { /* Enums and types */ /* ============================================================================================== */ -#if !defined(ZYAN_APPLE) +#if !defined(ZYAN_APPLE) && (!defined(__HAIKU__) || (defined(__GNUC__) && (__GNUC__ >= 4))) # pragma pack(push, 1) #endif @@ -68,7 +68,7 @@ typedef struct ZydisShortString_ ZyanU8 size; } ZydisShortString; -#if !defined(ZYAN_APPLE) +#if !defined(ZYAN_APPLE) && (!defined(__HAIKU__) || (defined(__GNUC__) && (__GNUC__ >= 4))) # pragma pack(pop) #endif diff --git a/src/libs/Jamfile b/src/libs/Jamfile index f7415025f0..9b382e825e 100644 --- a/src/libs/Jamfile +++ b/src/libs/Jamfile @@ -17,3 +17,4 @@ SubInclude HAIKU_TOP src libs stdc++ ; SubInclude HAIKU_TOP src libs udis86 ; SubInclude HAIKU_TOP src libs uuid ; SubInclude HAIKU_TOP src libs util ; +SubInclude HAIKU_TOP src libs zydis ; diff --git a/src/libs/zydis/Jamfile b/src/libs/zydis/Jamfile new file mode 100644 index 0000000000..909d9469f2 --- /dev/null +++ b/src/libs/zydis/Jamfile @@ -0,0 +1,63 @@ +SubDir HAIKU_TOP src libs zydis ; + +local zydisSourceDirectory = [ FDirName $(HAIKU_TOP) src libs zydis ] ; +UseHeaders [ LibraryHeaders zydis ] : true ; +UseHeaders [ FDirName $(zydisSourceDirectory) Zydis ] : true ; + +SubDirCcFlags -Wno-error=missing-prototypes ; + +DEFINES += __posix ; +DEFINES += ZYDIS_DISABLE_ENCODER ; + +local zydisSources = + Decoder.c + DecoderData.c + Disassembler.c + Formatter.c + FormatterBuffer.c + FormatterATT.c + FormatterBase.c + FormatterIntel.c + MetaInfo.c + Mnemonic.c + Register.c + SharedData.c + String.c + Utils.c + Zydis.c +; + +local zycoreSources = + Zycore.c + Allocator.c + Bitset.c + Format.c + List.c + String.c + Vector.c +; + + +if $(TARGET_PACKAGING_ARCH) = x86_gcc2 { + # GCC 2 can't compile C11, so we use the modern GCC . + original_TARGET_CC_x86_gcc2 = $(TARGET_CC_x86_gcc2) ; + TARGET_CC_x86_gcc2 = $(TARGET_CC_x86) -Wa,-mrelax-relocations=no ; +} + +SOURCE_GRIST = [ FGrist $(SUBDIR_TOKENS) zydis ] ; +MakeLocate [ FGristFiles $(zydisSources:S=$(SUFOBJ)) ] + : [ FDirName $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) zydis ] ; +StaticLibrary libzydis.a : $(zydisSources) ; +LOCATE on [ FGristFiles $(zydisSources) ] = [ FDirName $(zydisSourceDirectory) Zydis ] ; + +SOURCE_GRIST = [ FGrist $(SUBDIR_TOKENS) zycore ] ; +MakeLocate [ FGristFiles $(zycoreSources:S=$(SUFOBJ)) ] + : [ FDirName $(TARGET_DEBUG_$(DEBUG)_LOCATE_TARGET) zycore ] ; +StaticLibrary libzydis.a : $(zycoreSources) +; +LOCATE on [ FGristFiles $(zycoreSources) ] = [ FDirName $(zydisSourceDirectory) Zycore ] ; + +if $(TARGET_PACKAGING_ARCH) = x86_gcc2 { + TARGET_CC_x86_gcc2 = $(original_TARGET_CC_x86_gcc2) ; +} +