Skip to content

Commit

Permalink
Create perlstatic.h
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
khwilliamson committed Jun 14, 2022
1 parent c43e2db commit d86d178
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -5230,6 +5230,7 @@ perlio.h PerlIO abstraction
perlio.sym Symbols for PerlIO abstraction
perliol.h PerlIO Layer definition
perlsdio.h Fake stdio using perlio
perlstatic.h Like inline.h, but functions not declared inline
perlvars.h Global variables
perly.act parser actions; derived from perly.y
perly.c parser code (NOT derived from perly.y)
Expand Down
2 changes: 1 addition & 1 deletion embed.fnc
Original file line number Diff line number Diff line change
Expand Up @@ -2696,7 +2696,7 @@ ATdpa |Malloc_t|safesysmalloc |MEM_SIZE nbytes
ATdpa |Malloc_t|safesyscalloc |MEM_SIZE elements|MEM_SIZE size
ATdpR |Malloc_t|safesysrealloc|Malloc_t where|MEM_SIZE nbytes
AdTp |Free_t |safesysfree |Malloc_t where
CrTp |void |croak_memory_wrap
CsrT |void |croak_memory_wrap
Cpdh |int |runops_standard
Cpdh |int |runops_debug
Afpd |void |sv_catpvf_mg |NN SV *const sv|NN const char *const pat|...
Expand Down
1 change: 1 addition & 0 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7329,6 +7329,7 @@ cannot have changed since the precalculation.

START_EXTERN_C

# include "perlstatic.h"
# include "inline.h"
# include "sv_inline.h"

Expand Down
33 changes: 33 additions & 0 deletions perlstatic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* perlstatic.h
*
* 'I don't know half of you half as well as I should like; and I like less
* than half of you half as well as you deserve.'
*
* Copyright (C) 2020 by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
* This file is a home for static functions that we don't consider suitable for
* inlining, but for which giving the compiler full knowledge of may be
* advantageous. Functions that have potential tail call optimizations are a
* likely component.
*/

/* saves machine code for a common noreturn idiom typically used in Newx*() */
GCC_DIAG_IGNORE_DECL(-Wunused-function);

STATIC void
Perl_croak_memory_wrap(void)
{
Perl_croak_nocontext("%s",PL_memory_wrap);
}

GCC_DIAG_RESTORE_DECL;


/*
* ex: set ts=8 sts=4 sw=4 et:
*/

2 changes: 1 addition & 1 deletion proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ PERL_CALLCONV_NO_RET void Perl_croak_caller(const char* pat, ...)
__attribute__format__null_ok__(__printf__,1,2);
#define PERL_ARGS_ASSERT_CROAK_CALLER

PERL_CALLCONV_NO_RET void Perl_croak_memory_wrap(void)
PERL_STATIC_NO_RET void Perl_croak_memory_wrap(void)
__attribute__noreturn__;
#define PERL_ARGS_ASSERT_CROAK_MEMORY_WRAP

Expand Down
9 changes: 0 additions & 9 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2054,15 +2054,6 @@ Perl_croak_nocontext(const char *pat, ...)
}
#endif /* MULTIPLICITY */

/* saves machine code for a common noreturn idiom typically used in Newx*() */
GCC_DIAG_IGNORE_DECL(-Wunused-function);
void
Perl_croak_memory_wrap(void)
{
Perl_croak_nocontext("%s",PL_memory_wrap);
}
GCC_DIAG_RESTORE_DECL;

void
Perl_croak(pTHX_ const char *pat, ...)
{
Expand Down

0 comments on commit d86d178

Please sign in to comment.