This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp*.c, regexec.c - fixup regex engine build under -Uusedl
authorYves Orton <demerphq@gmail.com>
Tue, 1 Aug 2023 21:12:46 +0000 (23:12 +0200)
committerYves Orton <demerphq@gmail.com>
Thu, 3 Aug 2023 13:25:02 +0000 (15:25 +0200)
commitba6e2c38aafc23cf114f3ba0d0ff3baead34328b
tree65a68b9e5a7ea1bbd4a90d80b3a722c9894d9230
parent725518fb3b518d3f9dbd5f9a74a27f44f51570ae
regcomp*.c, regexec.c - fixup regex engine build under -Uusedl

The regex engine is built a bit different from most of the perl
codebase. It is compiled as part of the main libperl.so and it is
also compiled (with DEBUGGING enabled) as part of the re extension.
When perl itself is compiled with DEBUGGING enabled then the code
in the re.so extension and the code in libperl.so is the same.

This all works fine and dandy until you have a static build where the
re.so is linked into libperl.so, which results in duplicate symbols
being defined. These symbols come in two flaviours: "auxiliary" and
"debugging" related symbols.

We have basically three cases:

1. USE_DYNAMIC_LOADING is defined. In this case we are doing a dynamic
   build and re.so will be separate from libperl.so, so it even if this
   is a DEBUGGING enabled build debug and auxiliary functions can be
   compiled into *both* re.so and libperl.so. This is basically the
   "standard build".

2. USE_DYNAMIC_LOADING is not defined, and DEBUGGING is not defined
   either. In this case auxiliary functions should only be compiled in
   libperl.so, and the debug functions should only be compiled into
   re.so

3. USE_DYNAMIC_LOADING is not defined, and DEBUGGING *is* defined. In
   this case auxiliary functions AND debug functions should only be
   compiled into libperl.so

It is possible to detect the different build options by looking at the
defines 'USE_DYNAMIC_LOADING', 'PERL_EXT_RE_DEBUG' and
'DEBUGGING_RE_ONLY'. 'USE_DYNAMIC_LOADING' is NOT defined when we are
building a static perl. 'PERL_EXT_RE_DEBUG' is defined only when we are
building re.so, and 'DEBUGGING_RE_ONLY' is defined only when we are
building re.so in a perl that is not itself already a DEBUGGING enabled
perl. The file ext/re/re_top.h responsible for setting up
DEBUGGING_RE_ONLY.

This patch uses 'PERL_EXT_RE_DEBUG', 'DEBUGGING_RE_ONLY' and
'USE_DYNAMIC_LOADING' to define in regcomp.h two further define flags
'PERL_RE_BUILD_DEBUG' and 'PERL_RE_BUILD_AUX'.

The 'PERL_RE_BUILD_DEBUG' flag determines if the debugging functions
should be compiled into libperl.so or re.so or both. The
'PERL_RE_BUILD_AUX' flag determines if the auxiliary functions should be
compiled into just libperl.so or into it and re.so. We then use these
flags to guard the different types of functions so that we can build in
all three modes without duplicate symbols.
regcomp.c
regcomp.h
regcomp_debug.c
regcomp_invlist.c
regexec.c