Skip to content

Fix static compilation regexp linking errors #21320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 3, 2023
Merged

Conversation

Leont
Copy link
Contributor

@Leont Leont commented Aug 1, 2023

This aims to fix #21319, but has some failing use re 'strict' tests that I can't quite explain.

Possibly @demerphq needs to look at it since it seems to involve 85900e2

@Leont Leont requested a review from demerphq August 1, 2023 18:58
@Leont Leont changed the title Leont/regcomp static Fix static compilation regexp linking errors Aug 1, 2023
@demerphq
Copy link
Collaborator

demerphq commented Aug 1, 2023

Really wish you would list the main file changed on the subject line of your commits. Other than that I have fixed the PR with the last two patches I pushed into the branch. There are still some outstanding issues. 'make test_reonly' shouldnt throw its toys out of the pram. Also we produce a fair bit of warning noise during make test.

@demerphq
Copy link
Collaborator

demerphq commented Aug 1, 2023

I see that i onyl fixed it under DEBUGGING. I will dig more tomorrow.

@demerphq
Copy link
Collaborator

demerphq commented Aug 2, 2023

Ok, so that last patch fixes things with -Uusedl without -DEBUGGING, but apparently it breaks normal builds. I will have to pick it up again later.

@demerphq demerphq force-pushed the leont/regcomp_static branch from 4c8ea0d to 774e280 Compare August 3, 2023 11:10
@demerphq
Copy link
Collaborator

demerphq commented Aug 3, 2023

Third time lucky hopefully!

@Leont Leont marked this pull request as ready for review August 3, 2023 11:17
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.
@demerphq demerphq force-pushed the leont/regcomp_static branch from 774e280 to d1bb10e Compare August 3, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5.38.0: static build fails due to some functions being multiply defined
2 participants