Skip to content

Commit d86d178

Browse files
committed
Create perlstatic.h
This is used for functions that we don't suggest should be inlined, but we think the compiler will generate better code if it has full knowledge about them. At the moment, it only contains a single function which can be tail-call optimized. The Lord of the Rings quote for this file was suggested by Leon Timmermans. The proximal cause of this commit can be gleaned from this email: From - Mon Nov 16 09:20:50 2020 X-Mozilla-Status: 0001 X-Mozilla-Status2: 00800000 X-Mozilla-Keys: Subject: Re: about commit "Revert "croak_memory_wrap is an inline function."" (khw) To: bulk88 <[email protected]>, [email protected] References: <[email protected]> From: Karl Williamson <[email protected]> Message-ID: <[email protected]> Date: Mon, 16 Nov 2020 09:20:41 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <[email protected]> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 4/28/20 7:19 PM, bulk88 wrote: > https://perl5.git.perl.org/perl5.git/commitdiff/d68c938a1e6c6b4bfe907decbb4929780ee06eae > > > Why was this done? Perl_croak_memory_wrap is supposed to be a static > linkage, not globally visible C function, in every perl .o file that the > CC/linker should toss the static func if its not used. I wanted to avoid > the PLT/GOT runtime C symbol substitution/LDPRELOAD mechanism and let > the CC turn Perl_croak_memory_wrap into a single conditional jump > (offset from current instruction pointer), with no return and no C stack > entry, jump instruction instead of > > call get_EIP //x86 32 only > mov eax, *(eax_aka_eip+offset into PLT) > call eax I reverted this because, first of all, gcc with the appropriate -W options raised warnings that it was disregarding the request and was not inlining this function, and 2nd of all, there was no indication in the comments as to why this function had been inlined.
1 parent c43e2db commit d86d178

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -5230,6 +5230,7 @@ perlio.h PerlIO abstraction
52305230
perlio.sym Symbols for PerlIO abstraction
52315231
perliol.h PerlIO Layer definition
52325232
perlsdio.h Fake stdio using perlio
5233+
perlstatic.h Like inline.h, but functions not declared inline
52335234
perlvars.h Global variables
52345235
perly.act parser actions; derived from perly.y
52355236
perly.c parser code (NOT derived from perly.y)

embed.fnc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2696,7 +2696,7 @@ ATdpa |Malloc_t|safesysmalloc |MEM_SIZE nbytes
26962696
ATdpa |Malloc_t|safesyscalloc |MEM_SIZE elements|MEM_SIZE size
26972697
ATdpR |Malloc_t|safesysrealloc|Malloc_t where|MEM_SIZE nbytes
26982698
AdTp |Free_t |safesysfree |Malloc_t where
2699-
CrTp |void |croak_memory_wrap
2699+
CsrT |void |croak_memory_wrap
27002700
Cpdh |int |runops_standard
27012701
Cpdh |int |runops_debug
27022702
Afpd |void |sv_catpvf_mg |NN SV *const sv|NN const char *const pat|...

perl.h

+1
Original file line numberDiff line numberDiff line change
@@ -7329,6 +7329,7 @@ cannot have changed since the precalculation.
73297329

73307330
START_EXTERN_C
73317331

7332+
# include "perlstatic.h"
73327333
# include "inline.h"
73337334
# include "sv_inline.h"
73347335

perlstatic.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* perlstatic.h
2+
*
3+
* 'I don't know half of you half as well as I should like; and I like less
4+
* than half of you half as well as you deserve.'
5+
*
6+
* Copyright (C) 2020 by Larry Wall and others
7+
*
8+
* You may distribute under the terms of either the GNU General Public
9+
* License or the Artistic License, as specified in the README file.
10+
*
11+
* This file is a home for static functions that we don't consider suitable for
12+
* inlining, but for which giving the compiler full knowledge of may be
13+
* advantageous. Functions that have potential tail call optimizations are a
14+
* likely component.
15+
16+
*/
17+
18+
/* saves machine code for a common noreturn idiom typically used in Newx*() */
19+
GCC_DIAG_IGNORE_DECL(-Wunused-function);
20+
21+
STATIC void
22+
Perl_croak_memory_wrap(void)
23+
{
24+
Perl_croak_nocontext("%s",PL_memory_wrap);
25+
}
26+
27+
GCC_DIAG_RESTORE_DECL;
28+
29+
30+
/*
31+
* ex: set ts=8 sts=4 sw=4 et:
32+
*/
33+

proto.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ PERL_CALLCONV_NO_RET void Perl_croak_caller(const char* pat, ...)
776776
__attribute__format__null_ok__(__printf__,1,2);
777777
#define PERL_ARGS_ASSERT_CROAK_CALLER
778778

779-
PERL_CALLCONV_NO_RET void Perl_croak_memory_wrap(void)
779+
PERL_STATIC_NO_RET void Perl_croak_memory_wrap(void)
780780
__attribute__noreturn__;
781781
#define PERL_ARGS_ASSERT_CROAK_MEMORY_WRAP
782782

util.c

-9
Original file line numberDiff line numberDiff line change
@@ -2054,15 +2054,6 @@ Perl_croak_nocontext(const char *pat, ...)
20542054
}
20552055
#endif /* MULTIPLICITY */
20562056

2057-
/* saves machine code for a common noreturn idiom typically used in Newx*() */
2058-
GCC_DIAG_IGNORE_DECL(-Wunused-function);
2059-
void
2060-
Perl_croak_memory_wrap(void)
2061-
{
2062-
Perl_croak_nocontext("%s",PL_memory_wrap);
2063-
}
2064-
GCC_DIAG_RESTORE_DECL;
2065-
20662057
void
20672058
Perl_croak(pTHX_ const char *pat, ...)
20682059
{

0 commit comments

Comments
 (0)