Re: [PATCH] Enable using llvm jitlink as an alternative llvm jit linker of old Rtdyld.

From: Alex Fan <alex(dot)fan(dot)q(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, "geidav(dot)pg(at)gmail(dot)com" <geidav(dot)pg(at)gmail(dot)com>, "luc(at)swarm64(dot)com" <luc(at)swarm64(dot)com>
Subject: Re: [PATCH] Enable using llvm jitlink as an alternative llvm jit linker of old Rtdyld.
Date: 2023-01-06 00:07:38
Message-ID: CAP8f6fB96uUruo6E2okR1KFcOKJaCwJCTdB7foiwubHe=UyT4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

There is discussion in
https://github.com/riscv-non-isa/riscv-toolchain-conventions/issues/13 to
change the abi default, but not much attention for some time. The consensus
seems to be set the abi and extension explicitly.

> I recommend proposing a patch for adding such an API to LLVM.

I would like to try some time later. Jitlink allows lots of flexibility to
inspect each linking process, I feel myself don't know enough use cases to
propose a good enough c-abi for it.

The thing I am thinking is these patch to llvm will take some time to land
especially for abi and extension default. But jitlink and orc for riscv is
very mature since llvm-15, and even llvm-14 with two minor patches. It
would be good to have these bits, though ugly, so that postgresql jit can
work with llvm-15 as most distros are still moving to it.

cheers,
Alex Fan

On Sun, Dec 25, 2022 at 11:02 PM Andres Freund <andres(at)anarazel(dot)de> wrote:

> Hi,
>
> On 2022-11-23 21:13:04 +1100, Alex Fan wrote:
> > > @@ -241,6 +246,40 @@ llvm_mutable_module(LLVMJitContext *context)
> > > context->module = LLVMModuleCreateWithName("pg");
> > > 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:
>
> I think this is something that should go into the llvm code, rather than
> postgres.
>
>
> > > @@ -820,16 +861,21 @@ llvm_session_initialize(void)
> > > elog(DEBUG2, "LLVMJIT detected CPU \"%s\", with features
> \"%s\"",
> > > cpu, features);
> > >
> > > +#ifdef __riscv
> > > + reloc=LLVMRelocPIC;
> > > + codemodel=LLVMCodeModelMedium;
> > > +#endif
>
> Same.
>
>
>
>
> > > +#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)
>
> I recommend proposing a patch for adding such an API to LLVM.
>
>
>
> Greetings,
>
> Andres Freund
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2023-01-06 00:26:46 Re: fix and document CLUSTER privileges
Previous Message Nathan Bossart 2023-01-06 00:00:27 Re: wake up logical workers after ALTER SUBSCRIPTION