Skip to content

Commit ba6e2c3

Browse files
committed
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.
1 parent 725518f commit ba6e2c3

File tree

5 files changed

+181
-160
lines changed

5 files changed

+181
-160
lines changed

regcomp.c

+12-1
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ S_edit_distance(const UV* src,
290290
/* END of edit_distance() stuff
291291
* ========================================================= */
292292

293+
#ifdef PERL_RE_BUILD_AUX
293294
/* add a data member to the struct reg_data attached to this regex, it should
294295
* always return a non-zero return. the 's' argument is the type of the items
295296
* being added and the n is the number of items. The length of 's' should match
@@ -340,6 +341,7 @@ Perl_reg_add_data(RExC_state_t* const pRExC_state, const char* const s, const U3
340341
assert(count>0);
341342
return count;
342343
}
344+
#endif /* PERL_RE_BUILD_AUX */
343345

344346
/*XXX: todo make this not included in a non debugging perl, but appears to be
345347
* used anyway there, in 'use re' */
@@ -7443,6 +7445,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
74437445
}
74447446

74457447

7448+
#ifdef PERL_RE_BUILD_AUX
74467449
void
74477450
Perl_populate_anyof_bitmap_from_invlist(pTHX_ regnode *node, SV** invlist_ptr)
74487451
{
@@ -7502,6 +7505,7 @@ Perl_populate_anyof_bitmap_from_invlist(pTHX_ regnode *node, SV** invlist_ptr)
75027505
}
75037506
}
75047507
}
7508+
#endif /* PERL_RE_BUILD_AUX */
75057509

75067510
/* Parse POSIX character classes: [[:foo:]], [[=foo=]], [[.foo.]].
75077511
Character classes ([:foo:]) can also be negated ([:^foo:]).
@@ -9095,6 +9099,7 @@ S_dump_regex_sets_structures(pTHX_ RExC_state_t *pRExC_state,
90959099
#undef IS_OPERATOR
90969100
#undef IS_OPERAND
90979101

9102+
#ifdef PERL_RE_BUILD_AUX
90989103
void
90999104
Perl_add_above_Latin1_folds(pTHX_ RExC_state_t *pRExC_state, const U8 cp, SV** invlist)
91009105
{
@@ -9182,6 +9187,8 @@ Perl_add_above_Latin1_folds(pTHX_ RExC_state_t *pRExC_state, const U8 cp, SV** i
91829187
}
91839188
}
91849189
}
9190+
#endif /* PERL_RE_BUILD_AUX */
9191+
91859192

91869193
STATIC void
91879194
S_output_posix_warnings(pTHX_ RExC_state_t *pRExC_state, AV* posix_warnings)
@@ -12105,6 +12112,7 @@ S_optimize_regclass(pTHX_
1210512112

1210612113
#undef HAS_NONLOCALE_RUNTIME_PROPERTY_DEFINITION
1210712114

12115+
#ifdef PERL_RE_BUILD_AUX
1210812116
void
1210912117
Perl_set_ANYOF_arg(pTHX_ RExC_state_t* const pRExC_state,
1211012118
regnode* const node,
@@ -12261,6 +12269,7 @@ Perl_set_ANYOF_arg(pTHX_ RExC_state_t* const pRExC_state,
1226112269
RExC_rxi->data->data[n] = (void*)rv;
1226212270
ARG1u_SET(node, n);
1226312271
}
12272+
#endif /* PERL_RE_BUILD_AUX */
1226412273

1226512274
SV *
1226612275

@@ -12999,6 +13008,8 @@ S_regtail_study(pTHX_ RExC_state_t *pRExC_state, regnode_offset p,
1299913008
}
1300013009
#endif
1300113010

13011+
13012+
#ifdef PERL_RE_BUILD_AUX
1300213013
SV*
1300313014
Perl_get_ANYOFM_contents(pTHX_ const regnode * n) {
1300413015

@@ -13047,7 +13058,7 @@ Perl_get_ANYOFHbbm_contents(pTHX_ const regnode * n) {
1304713058
UTF_CONTINUATION_MARK | 0));
1304813059
return cp_list;
1304913060
}
13050-
13061+
#endif /* PERL_RE_BUILD_AUX */
1305113062

1305213063

1305313064
SV *

regcomp.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,19 @@ typedef enum {
15541554
#define EVAL_OPTIMISTIC_FLAG 128
15551555
#define EVAL_FLAGS_MASK (EVAL_OPTIMISTIC_FLAG-1)
15561556

1557-
1557+
/* We define PERL_RE_BUILD_DEBUG if we are NOT compiling the re extension and
1558+
* we are under DEBUGGING, or if we are ARE compiling the re extension
1559+
* and this is not a DEBUGGING enabled build (identified by
1560+
* DEBUGGING_RE_ONLY being defined)
1561+
*/
1562+
#if ( defined(USE_DYNAMIC_LOADING) && defined(DEBUGGING)) || \
1563+
( defined(PERL_EXT_RE_BUILD) && defined(DEBUGGING_RE_ONLY)) || \
1564+
(!defined(PERL_EXT_RE_BUILD) && defined(DEBUGGING))
1565+
#define PERL_RE_BUILD_DEBUG
1566+
#endif
1567+
#if ( defined(USE_DYNAMIC_LOADING) || !defined(PERL_EXT_RE_BUILD) )
1568+
#define PERL_RE_BUILD_AUX
1569+
#endif
15581570

15591571
#endif /* PERL_REGCOMP_H_ */
15601572

0 commit comments

Comments
 (0)