From acd49010e65e399e15d7e85264b6e9a621d676bb Mon Sep 17 00:00:00 2001 From: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com> Date: Fri, 27 Sep 2024 18:47:35 +0300 Subject: [PATCH] Remove MSVC macros & implement weak linking properly for clang. --- PowerRecomp/recompiler.cpp | 8 ++++---- PowerSample/CMakeLists.txt | 2 ++ PowerUtils/ppc_context.h | 24 +++++++----------------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/PowerRecomp/recompiler.cpp b/PowerRecomp/recompiler.cpp index e27448e..ffe0ef9 100644 --- a/PowerRecomp/recompiler.cpp +++ b/PowerRecomp/recompiler.cpp @@ -1964,11 +1964,11 @@ bool Recompiler::Recompile(const Function& fn) auto symbol = image.symbols.find(fn.base); if (symbol != image.symbols.end()) { - println("PPC_FUNC({}) {{", symbol->name); + println("PPC_WEAK_FUNC({}) {{", symbol->name); } else { - println("PPC_FUNC(sub_{}) {{", fn.base); + println("PPC_WEAK_FUNC(sub_{}) {{", fn.base); } println("\tPPC_FUNC_PROLOGUE();"); @@ -2120,7 +2120,7 @@ void Recompiler::Recompile(const char* directoryPath) println("#include \n"); for (auto& symbol : image.symbols) - println("PPC_FUNC({});", symbol.name); + println("PPC_EXTERN_FUNC({});", symbol.name); SaveCurrentOutData(directoryPath, "ppc_recomp_shared.h"); } @@ -2128,7 +2128,7 @@ void Recompiler::Recompile(const char* directoryPath) { println("#include \"ppc_recomp_shared.h\"\n"); - println("extern \"C\" PPCFuncMapping PPCFuncMappings[] = {{"); + println("PPCFuncMapping PPCFuncMappings[] = {{"); for (auto& symbol : image.symbols) println("\t{{ 0x{:X}, {} }},", symbol.address, symbol.name); diff --git a/PowerSample/CMakeLists.txt b/PowerSample/CMakeLists.txt index 71e3f69..60c1cc8 100644 --- a/PowerSample/CMakeLists.txt +++ b/PowerSample/CMakeLists.txt @@ -1,8 +1,10 @@ project("PowerSample") add_compile_options( + "/D_HAS_EXCEPTIONS=0" "/fp:strict" "/GS-" + "/EHa-" "-march=haswell" "-fno-strict-aliasing") diff --git a/PowerUtils/ppc_context.h b/PowerUtils/ppc_context.h index 5e68e0d..d9f534a 100644 --- a/PowerUtils/ppc_context.h +++ b/PowerUtils/ppc_context.h @@ -4,28 +4,18 @@ #error "ppc_config.h must be included before ppc_context.h" #endif +#include +#include #include #include #include -#include -#include + #include - -#ifdef __clang__ #include -#define PPC_NOINLINE __attribute__((noinline)) -#else -#define __restrict__ __restrict -#define __builtin_bswap16 _byteswap_ushort -#define __builtin_bswap32 _byteswap_ulong -#define __builtin_bswap64 _byteswap_uint64 -#define __builtin_isnan isnan -#define __builtin_assume __assume -#define __builtin_unreachable() __assume(0) -#define PPC_NOINLINE __declspec(noinline) -#endif -#define PPC_FUNC(x) extern "C" PPC_NOINLINE void x(PPCContext& __restrict__ ctx, uint8_t* base) +#define PPC_FUNC(x) void x(PPCContext& __restrict ctx, uint8_t* base) +#define PPC_EXTERN_FUNC(x) extern PPC_FUNC(x) +#define PPC_WEAK_FUNC(x) __attribute__((weak,noinline)) PPC_FUNC(x) #define PPC_FUNC_PROLOGUE() __builtin_assume(((size_t)base & 0xFFFFFFFF) == 0) @@ -50,7 +40,7 @@ struct PPCFuncMapping PPCFunc* host; }; -extern "C" PPCFuncMapping PPCFuncMappings[]; +extern PPCFuncMapping PPCFuncMappings[]; struct PPCRegister {