Re: [pcre-dev] How do I support pcre1 JIT on all versions?

Page principale
Supprimer ce message
Auteur: Ævar Arnfjörð Bjarmason
Date:  
À: Zoltán Herczeg
CC: Philip Hazel, pcre-dev@exim.org
Sujet: Re: [pcre-dev] How do I support pcre1 JIT on all versions?
On Thu, Jun 1, 2017 at 5:50 AM, Zoltán Herczeg <hzmester@???> wrote:
> I would simply use the PCRE version number to detect jit_exec at compile
> time:
>
> #if (PCRE_MAJOR > 8 || (PCRE_MAJOR == 8 && PCRE_MINOR >= 32))
> #define PCRE_JIT_EXEC_AVAILABLE
> #endif


That'll only work if pcre isn't compiled with --disable-jit, if it is
even on the latest svn trunk linking against it results in:

    libgit.a(grep.o): In function `pcre1match':
    /home/avar/g/git/grep.c:411: undefined reference to `pcre_jit_exec'


If you look at pcre_jit_compile.c the whole structure of the file is:

#if defined SUPPORT_JIT
[...]
#define SLJIT_CONFIG_AUTO 1 /* ...and other macros */
int
PRIV(jit_exec)(const PUBL(extra) *extra_data, const pcre_uchar *subject,
[...]
#else /* SUPPORT_JIT */
[... no definition of pcre_jit_exec ...]
#endif

I.e. the pcre_jit_exec symbol won't be in the library, and thus
linking to it fails, so I need a macro accessible from pcre.h that
tells me whether it's going to be there, calling pcre_config() will be
too late.

AFAICT the best option for that is these SLJIT_* macros.


> -------- Eredeti levél --------
> Feladó: Ævar Arnfjörð Bjarmason < avarab@??? (Link ->
> mailto:avarab@gmail.com) >
> Dátum: 2017 május 31 18:44:28
> Tárgy: How do I support pcre1 JIT on all versions?
> Címzett: Philip Hazel < pcre-dev@??? (Link -> mailto:pcre-dev@exim.org)
>
>
> My patch to add JIT support to Git with the PCRE v1 API works all the
> way down to PCRE version 7.5 (the last one I could get to compile),
> but *only* if I compile the versions that support JIT with
> --enable-jit, not --disable-jit.
> The problem is that both PCRE_CONFIG_JIT and PCRE_STUDY_JIT_COMPILE
> will be defined even when JIT support isn't enabled, so I can't use
> them to check if I should ifdef a codepath that uses pcre_jit_exec()
> into existence, if a newer pcre library is compiled ith --disable-jit
> the git build will fail at link time since there's no such symbol.
> I have a hack around this, which as far as I can tell is the only way
> to do this, but I'd welcome a different way.
> Ever since the JIT support was added back in 2011 these macros have
> been conditionally defined:
> +#ifdef SUPPORT_JIT
> +
> +/* All-in-one: Since we use the JIT compiler only from here,
> +we just include it. This way we don't need to touch the build
> +system files. */
> +
> +#define SLJIT_CONFIG_AUTO 1
> +#define SLJIT_VERBOSE 0
> +#define SLJIT_DEBUG 0
> +
> +#include "sljit/sljitLir.c"
> +
> +#if defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED
> +#error "Unsupported architecture"
> +#endif
> So I'm guarding code that takes that pcre_exec_jit() codepath with
> `#ifdef SLJIT_CONFIG_AUTO`.
> This works on all pcre versions, and I'm going to use that unless
> someone tells me otherwise.
> Also, please apply my patch to the pcrejit docs for a related thing:
> https://bugs.exim.org/show_bug.cgi?id=2121
> Depending on the follow-ups to this post I'll submit another change to
> the docs to note how to support JIT on PCRE v1 with all combinations
> of versions & --{disable,enable}-jit.
>