Skip to content

Commit 05e22bb

Browse files
committed
de-mathom Perl_sv_taint() part 3 (SvTAINT() branch remove)
"SvTAINT();" contains "if(PL_tainting && PL_tainted) sv_taint(sv);" that is 2 One Byte reads and 2 branches. Collapse the 2 bool chars, to a U16, so it is exactly 1 read, and 1 branch. Strips complexity from the very bottom of the very hot newSVuv/newSViv/newSVuv, and other callers. sv_taint(sv) has 62 callers, not sure how many do the 2 reads, 2 branches SvTAINT(sv);, but the change decreased the size of miniperl.exe and therefore perl541.dll, and branches were removed from the newSVuv/newSViv/newSVuv trio. Delta machine code bytes, between part 2 & 3 (this commit). previous miniperl.exe Win64 .text section, VC 2022 -O1 0x1240AC bytes long after 0x12408C bytes long
1 parent 83ddcb8 commit 05e22bb

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

embedvar.h

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intrpvar.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ PERLVAR(I, multideref_pc, UNOP_AUX_item *)
7474
PERLVAR(I, curpm, PMOP *) /* what to do \ interps in REs from */
7575
PERLVAR(I, curpm_under, PMOP *) /* what to do \ interps in REs from */
7676

77-
PERLVAR(I, tainting, bool) /* ? doing taint checks */
78-
PERLVARI(I, tainted, bool, FALSE) /* using variables controlled by $< */
77+
/* bool PL_tainting --- ? doing taint checks */
78+
/* bool PL_tainted --- using variables controlled by $< */
79+
PERLVAR(I, taint, TAINT_U)
7980

8081
/* PL_delaymagic is currently used for two purposes: to assure simultaneous
8182
* updates in ($<,$>) = ..., and to assure atomic update in push/unshift

perl.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ perl_construct(pTHXx)
249249
SvREADONLY_on(&PL_sv_placeholder);
250250
SvREFCNT(&PL_sv_placeholder) = SvREFCNT_IMMORTAL;
251251

252+
STATIC_ASSERT_STMT(
253+
sizeof(((TAINT_U *)0)->both)
254+
== (sizeof(((TAINT_U *)0)->u.tainting) + sizeof(((TAINT_U *)0)->u.tainted))
255+
);
256+
STATIC_ASSERT_STMT(
257+
sizeof(((TAINT_U *)0)->both)
258+
== (STRUCT_OFFSET(TAINT_U, u.tainted) + sizeof(((TAINT_U *)0)->u.tainted))
259+
);
260+
STATIC_ASSERT_STMT(STRUCT_OFFSET(TAINT_U, both) == STRUCT_OFFSET(TAINT_U, u.tainting));
261+
/* PL_taint.u.both = 0; */
262+
252263
PL_sighandlerp = Perl_sighandler;
253264
PL_sighandler1p = Perl_sighandler1;
254265
PL_sighandler3p = Perl_sighandler3;

perl.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,8 @@ symbol would not be defined on C<L</EBCDIC>> platforms.
940940
* know what you're doing: tests and CPAN modules' tests are bound to fail.
941941
*/
942942
#ifdef NO_TAINT_SUPPORT
943+
# define PL_tainting PL_taint.u.tainting
944+
# define PL_tainted PL_taint.u.tainted
943945
# define TAINT NOOP
944946
# define TAINT_NOT NOOP
945947
# define TAINT_IF(c) NOOP
@@ -948,6 +950,7 @@ symbol would not be defined on C<L</EBCDIC>> platforms.
948950
# define TAINT_set(s) NOOP
949951
# define TAINT_get 0
950952
# define TAINTING_get 0
953+
# define TAINT_AND_TAINTING_get 0
951954
# define TAINTING_set(s) NOOP
952955
# define TAINT_WARN_get 0
953956
# define TAINT_WARN_set(s) NOOP
@@ -1014,6 +1017,10 @@ violations are fatal.
10141017
10151018
=cut
10161019
*/
1020+
1021+
#define PL_tainting PL_taint.u.tainting
1022+
#define PL_tainted PL_taint.u.tainted
1023+
10171024
/* Set to tainted if we are running under tainting mode */
10181025
# define TAINT (PL_tainted = PL_tainting)
10191026

@@ -1027,6 +1034,8 @@ violations are fatal.
10271034
# define TAINT_set(s) (PL_tainted = cBOOL(s))
10281035
# define TAINT_get (cBOOL(UNLIKELY(PL_tainted))) /* Is something tainted? */
10291036
# define TAINTING_get (cBOOL(UNLIKELY(PL_tainting)))
1037+
/* Efficient version of (PL_tainted && PL_tainting) */
1038+
# define TAINT_AND_TAINTING_get (UNLIKELY(PL_taint.both == (TRUE | (TRUE << 8))))
10301039
# define TAINTING_set(s) (PL_tainting = cBOOL(s))
10311040
# define TAINT_WARN_get (PL_taint_warn)
10321041
# define TAINT_WARN_set(s) (PL_taint_warn = cBOOL(s))
@@ -3309,6 +3318,14 @@ typedef struct padname PADNAME;
33093318
#include "handy.h"
33103319
#include "charclass_invlists.h"
33113320

3321+
typedef union {
3322+
U16 both;
3323+
struct {
3324+
bool tainting;
3325+
bool tainted;
3326+
} u;
3327+
} TAINT_U;
3328+
33123329
#if defined(USE_LARGE_FILES) && !defined(NO_64_BIT_RAWIO)
33133330
# if LSEEKSIZE == 8 && !defined(USE_64_BIT_RAWIO)
33143331
# define USE_64_BIT_RAWIO /* implicit */

sv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15909,7 +15909,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
1590915909

1591015910
#ifndef NO_TAINT_SUPPORT
1591115911
/* Set tainting stuff before PerlIO_debug can possibly get called */
15912-
PL_tainting = proto_perl->Itainting;
15912+
PL_tainting = proto_perl->Itaint.u.tainting;
1591315913
PL_taint_warn = proto_perl->Itaint_warn;
1591415914
#else
1591515915
PL_tainting = FALSE;
@@ -16054,7 +16054,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
1605416054
PL_statcache = proto_perl->Istatcache;
1605516055

1605616056
#ifndef NO_TAINT_SUPPORT
16057-
PL_tainted = proto_perl->Itainted;
16057+
PL_tainted = proto_perl->Itaint.u.tainted;
1605816058
#else
1605916059
PL_tainted = FALSE;
1606016060
#endif

sv.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,8 @@ attention to precisely which outputs are influenced by which inputs.
17351735
#define SvTAINT(sv) \
17361736
STMT_START { \
17371737
assert(TAINTING_get || !TAINT_get); \
1738-
if (UNLIKELY(TAINT_get)) \
1739-
SvTAINTED_on(sv); \
1738+
if (TAINT_AND_TAINTING_get) \
1739+
sv_taint(sv); \
17401740
} STMT_END
17411741

17421742
/*

0 commit comments

Comments
 (0)