Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Andreas_Schwab:riscv:postgresql
postgresql17
riscv.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File riscv.patch of Package postgresql17
Index: postgresql-17.0/config/llvm.m4 =================================================================== --- postgresql-17.0.orig/config/llvm.m4 +++ postgresql-17.0/config/llvm.m4 @@ -76,6 +76,7 @@ AC_DEFUN([PGAC_LLVM_SUPPORT], engine) pgac_components="$pgac_components $pgac_component";; debuginfodwarf) pgac_components="$pgac_components $pgac_component";; orcjit) pgac_components="$pgac_components $pgac_component";; + jitlink) pgac_components="$pgac_components $pgac_component";; passes) pgac_components="$pgac_components $pgac_component";; native) pgac_components="$pgac_components $pgac_component";; perfjitevents) pgac_components="$pgac_components $pgac_component";; Index: postgresql-17.0/configure =================================================================== --- postgresql-17.0.orig/configure +++ postgresql-17.0/configure @@ -5234,6 +5234,7 @@ fi engine) pgac_components="$pgac_components $pgac_component";; debuginfodwarf) pgac_components="$pgac_components $pgac_component";; orcjit) pgac_components="$pgac_components $pgac_component";; + jitlink) pgac_components="$pgac_components $pgac_component";; passes) pgac_components="$pgac_components $pgac_component";; native) pgac_components="$pgac_components $pgac_component";; perfjitevents) pgac_components="$pgac_components $pgac_component";; Index: postgresql-17.0/src/backend/jit/llvm/llvmjit.c =================================================================== --- postgresql-17.0.orig/src/backend/jit/llvm/llvmjit.c +++ postgresql-17.0/src/backend/jit/llvm/llvmjit.c @@ -333,6 +333,11 @@ llvm_release_context(JitContext *context LLVMModuleRef llvm_mutable_module(LLVMJitContext *context) { +#ifdef __riscv + const char *abiname; + const char *target_abi = "target-abi"; + LLVMMetadataRef abi_metadata; +#endif llvm_assert_in_fatal_section(); /* @@ -345,6 +350,40 @@ llvm_mutable_module(LLVMJitContext *cont context->module = LLVMModuleCreateWithNameInContext("pg", llvm_context); LLVMSetTarget(context->module, llvm_triple); LLVMSetDataLayout(context->module, llvm_layout); +#ifdef __riscv +#if __riscv_xlen == 64 +#ifdef __riscv_float_abi_double + abiname = "lp64d"; +#elif defined(__riscv_float_abi_single) + abiname = "lp64f"; +#else + abiname = "lp64"; +#endif +#elif __riscv_xlen == 32 +#ifdef __riscv_float_abi_double + abiname = "ilp32d"; +#elif defined(__riscv_float_abi_single) + abiname = "ilp32f"; +#else + abiname = "ilp32"; +#endif +#else + elog(ERROR, "unsupported riscv xlen %d", __riscv_xlen); +#endif + /* + * set this manually to avoid llvm defaulting to soft float and + * resulting in linker error: `can't link double-float modules + * with soft-float modules` + * we could set this for TargetMachine via MCOptions, but there + * is no C API for it + * ref: https://github.com/llvm/llvm-project/blob/afa520ab34803c82587ea6759bfd352579f741b4/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp#L90 + */ + abi_metadata = LLVMMDStringInContext2( + LLVMGetModuleContext(context->module), + abiname, strlen(abiname)); + LLVMAddModuleFlag(context->module, LLVMModuleFlagBehaviorOverride, + target_abi, strlen(target_abi), abi_metadata); +#endif } return context->module; @@ -896,6 +935,8 @@ llvm_session_initialize(void) char *cpu = NULL; char *host_features = NULL; char *features = NULL; + LLVMRelocMode reloc = LLVMRelocDefault; + LLVMCodeModel codemodel = LLVMCodeModelJITDefault; LLVMTargetMachineRef opt0_tm; LLVMTargetMachineRef opt3_tm; @@ -963,16 +1004,21 @@ llvm_session_initialize(void) sprintf(features, "%s%s", host_features, no_vector); } +#ifdef __riscv + reloc = LLVMRelocPIC; + codemodel = LLVMCodeModelMedium; +#endif + opt0_tm = LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features, LLVMCodeGenLevelNone, - LLVMRelocDefault, - LLVMCodeModelJITDefault); + reloc, + codemodel); opt3_tm = LLVMCreateTargetMachine(llvm_targetref, llvm_triple, cpu, features, LLVMCodeGenLevelAggressive, - LLVMRelocDefault, - LLVMCodeModelJITDefault); + reloc, + codemodel); LLVMDisposeMessage(cpu); cpu = NULL; @@ -1315,6 +1361,10 @@ llvm_log_jit_error(void *ctx, LLVMErrorR static LLVMOrcObjectLayerRef llvm_create_object_layer(void *Ctx, LLVMOrcExecutionSessionRef ES, const char *Triple) { +#if defined(USE_JITLINK) + LLVMOrcObjectLayerRef objlayer = + LLVMOrcCreateJitlinkObjectLinkingLayer(ES); +#else LLVMOrcObjectLayerRef objlayer = LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(ES); @@ -1326,6 +1376,7 @@ llvm_create_object_layer(void *Ctx, LLVM LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l); } #endif +#endif #if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER if (jit_profiling_support) Index: postgresql-17.0/src/backend/jit/llvm/llvmjit_wrap.cpp =================================================================== --- postgresql-17.0.orig/src/backend/jit/llvm/llvmjit_wrap.cpp +++ postgresql-17.0/src/backend/jit/llvm/llvmjit_wrap.cpp @@ -24,6 +24,10 @@ extern "C" #include <llvm/IR/Function.h> #include "jit/llvmjit.h" +#ifdef USE_JITLINK +#include "llvm/ExecutionEngine/JITLink/EHFrameSupport.h" +#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" +#endif /* @@ -41,3 +45,21 @@ LLVMGetFunctionType(LLVMValueRef r) { return llvm::wrap(llvm::unwrap<llvm::Function>(r)->getFunctionType()); } + +#ifdef USE_JITLINK +/* + * There is no public C API to create ObjectLinkingLayer for JITLINK, create our own + */ +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::ExecutionSession, LLVMOrcExecutionSessionRef) +DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::orc::ObjectLayer, LLVMOrcObjectLayerRef) + +LLVMOrcObjectLayerRef +LLVMOrcCreateJitlinkObjectLinkingLayer(LLVMOrcExecutionSessionRef ES) +{ + assert(ES && "ES must not be null"); + auto ObjLinkingLayer = new llvm::orc::ObjectLinkingLayer(*unwrap(ES)); + ObjLinkingLayer->addPlugin(std::make_unique<llvm::orc::EHFrameRegistrationPlugin>( + *unwrap(ES), std::make_unique<llvm::jitlink::InProcessEHFrameRegistrar>())); + return wrap(ObjLinkingLayer); +} +#endif Index: postgresql-17.0/src/include/jit/llvmjit.h =================================================================== --- postgresql-17.0.orig/src/include/jit/llvmjit.h +++ postgresql-17.0/src/include/jit/llvmjit.h @@ -19,6 +19,11 @@ #include <llvm-c/Types.h> +#if defined(__riscv) && LLVM_VERSION_MAJOR >= 15 +#include <llvm-c/Orc.h> +#define USE_JITLINK +/* else use legacy RTDyld */ +#endif /* * File needs to be includable by both C and C++ code, and include other @@ -136,6 +141,10 @@ extern LLVMValueRef slot_compile_deform( extern LLVMTypeRef LLVMGetFunctionReturnType(LLVMValueRef r); extern LLVMTypeRef LLVMGetFunctionType(LLVMValueRef r); +#ifdef USE_JITLINK +extern LLVMOrcObjectLayerRef LLVMOrcCreateJitlinkObjectLinkingLayer(LLVMOrcExecutionSessionRef ES); +#endif + #ifdef __cplusplus } /* extern "C" */ #endif
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor