Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 19d3c3e

Browse files
author
Reini Urban
committed
fix XS_EXTERNAL for solaris and -flto=thin
SunPro cc __global needs to be before the funcion decl, not after. use a new GLOBAL define for GLOBAL (exported) XS functions, similar to EXT with variables. Simplify the definition of XS_EXTERNAL and XSPROTO, by using GLOBAL. Fixup the wrong generated code for solaris by ExtUtils::ParseXS
1 parent 4fd8d91 commit 19d3c3e

File tree

10 files changed

+96
-72
lines changed

10 files changed

+96
-72
lines changed

EXTERN.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,26 @@
2323
/* miniperl should not export anything */
2424
# if defined(PERL_IS_MINIPERL) && !defined(UNDER_CE) && defined(_MSC_VER)
2525
# define EXT extern
26-
# define dEXT
26+
# define dEXT
2727
# define EXTCONST extern const
2828
# define dEXTCONST const
2929
# else
3030
# if defined(PERLDLL) || defined(__SYMBIAN32__)
3131
# define EXT EXTERN_C __declspec(dllexport)
32-
# define dEXT
32+
# define dEXT
3333
# define EXTCONST EXTERN_C __declspec(dllexport) const
3434
# define dEXTCONST const
3535
# else
3636
# define EXT EXTERN_C __declspec(dllimport)
37-
# define dEXT
37+
# define dEXT
3838
# define EXTCONST EXTERN_C __declspec(dllimport) const
3939
# define dEXTCONST const
4040
# endif
4141
# endif
4242
# else
4343
# if defined(__CYGWIN__) && defined(USEIMPORTLIB)
4444
# define EXT extern __declspec(dllimport)
45-
# define dEXT
45+
# define dEXT
4646
# define EXTCONST extern __declspec(dllimport) const
4747
# define dEXTCONST const
4848
# else

XSUB.h

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,31 +124,25 @@ is a lexical C<$_> in scope.
124124
* "STATIC", ie. it exports XSUB symbols. You probably don't want that.
125125
*/
126126

127-
#define XSPROTO(name) void name(pTHX_ CV* cv)
127+
#if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
128+
# define XSPROTO(name) void name(pTHX_ CV* cv __attribute__unused__)
129+
#else
130+
# define XSPROTO(name) void name(pTHX_ CV* cv)
131+
#endif
128132

129133
#undef XS
130134
#undef XS_EXTERNAL
131135
#undef XS_INTERNAL
132-
#if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
133-
# define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
134-
# define XS_INTERNAL(name) STATIC XSPROTO(name)
135-
#endif
136136
#if defined(__SYMBIAN32__)
137137
# define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
138138
# define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
139-
#endif
140-
#ifndef XS_EXTERNAL
141-
# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
142-
# define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
143-
# define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
139+
#else
140+
# ifdef __cplusplus
141+
# define XS_EXTERNAL(name) extern "C" GLOBAL XSPROTO(name)
142+
# define XS_INTERNAL(name) static XSPROTO(name)
144143
# else
145-
# ifdef __cplusplus
146-
# define XS_EXTERNAL(name) extern "C" XSPROTO(name)
147-
# define XS_INTERNAL(name) static XSPROTO(name)
148-
# else
149-
# define XS_EXTERNAL(name) XSPROTO(name)
150-
# define XS_INTERNAL(name) STATIC XSPROTO(name)
151-
# endif
144+
# define XS_EXTERNAL(name) GLOBAL XSPROTO(name)
145+
# define XS_INTERNAL(name) STATIC XSPROTO(name)
152146
# endif
153147
#endif
154148

dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -893,13 +893,8 @@ EOF
893893

894894
# Windows already has __declspec(dllexport) in XS_EXTERNAL
895895
print Q(<<"EOF");
896-
#XS_EXTERNAL(boot_$self->{Module_cname}) /* prototype to pass -Wmissing-prototypes */
897-
##if defined(__GNUC__)
898-
# __attribute__((__visibility__("default")))
899-
##elif defined(__SUNPRO_C)
900-
# __global
901-
##endif
902-
;
896+
#XS_EXTERNAL(boot_$self->{Module_cname}) __attribute__global__ ;
897+
#
903898
#XS_EXTERNAL(boot_$self->{Module_cname})
904899
#[[
905900
##if PERL_VERSION_LE(5, 21, 5)

embed.fnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2905,7 +2905,7 @@ Apo |void* |my_cxt_init |NN int *index|size_t size
29052905
so |void |xs_version_bootcheck|U32 items|U32 ax|NN const char *xs_p \
29062906
|STRLEN xs_len
29072907
#endif
2908-
Xpon |I32 |xs_handshake |const U32 key|NN void * v_my_perl\
2908+
Apon |I32 |xs_handshake |const U32 key|NN void * v_my_perl\
29092909
|NN const char * file| ...
29102910
Xp |void |xs_boot_epilog |const I32 ax
29112911
#ifndef HAS_STRLCAT

ext/DynaLoader/dlboot_c.PL

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ const char ldlibpthname[] = LDLIBPTHNAME;
8080
8181
static SV * dl_findfile(pTHX_ AV* args, int gimme);
8282
static char * av_tostr(pTHX_ AV *args);
83-
PERL_CALLCONV void XS_DynaLoader_bootstrap_inherit(pTHX_ CV *cv);
84-
PERL_CALLCONV void XS_DynaLoader_bootstrap(pTHX_ CV *cv);
85-
PERL_CALLCONV void XS_DynaLoader_dl_findfile(pTHX_ CV *cv);
83+
XS_EXTERNAL(XS_DynaLoader_bootstrap_inherit);
84+
XS_EXTERNAL(XS_DynaLoader_bootstrap);
85+
XS_EXTERNAL(XS_DynaLoader_dl_findfile);
8686
#ifndef VMS
87-
PERL_CALLCONV void XS_DynaLoader_dl_expandspec(pTHX_ CV *cv);
87+
XS_EXTERNAL(XS_DynaLoader_dl_expandspec);
8888
#endif
89-
PERL_CALLCONV void XS_DynaLoader_dl_find_symbol_anywhere(pTHX_ CV *cv);
89+
XS_EXTERNAL(XS_DynaLoader_dl_find_symbol_anywhere);
9090
#ifdef HAS_LIBNAME_UNIQUE
91-
PERL_CALLCONV void XS_DynaLoader_mod2fname(pTHX_ CV *cv);
91+
XS_EXTERNAL(XS_DynaLoader_mod2fname);
9292
#endif
93-
PERL_CALLCONV void XS_XSLoader_load(pTHX_ CV *cv);
94-
PERL_CALLCONV void XS_XSLoader_load_file(pTHX_ CV *cv);
95-
PERL_CALLCONV void XS_XSLoader_bootstrap_inherit(pTHX_ CV *cv);
93+
XS_EXTERNAL(XS_XSLoader_load);
94+
XS_EXTERNAL(XS_XSLoader_load_file);
95+
XS_EXTERNAL(XS_XSLoader_bootstrap_inherit);
9696
9797
EXTERN_C void
9898
dl_boot (pTHX) {

hv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct he {
5252
struct hek {
5353
U32 hek_hash; /* hash of key */
5454
I32 hek_len; /* length of hash key */
55-
#ifdef PERL_GCC_BRACE_GROUPS_FORBIDDEN
55+
#if defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) || defined(__SUNPRO_C)
5656
char hek_key[1]; /* variable-length hash key */
5757
#else
5858
char hek_key[]; /* for easier debugging */

perl.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3647,15 +3647,23 @@ EXTERN_C int perl_tsa_mutex_unlock(perl_mutex* mutex)
36473647
# endif
36483648
#endif
36493649

3650-
/* We could also use GLOBAL instead of __attribute__global__.
3651-
But GLOBAL would be expected at the front of the declaration,
3652-
whilst the attribute needs to be put behind. */
3650+
/* GLOBAL is in front of the declaration: sun cc, MSVC,
3651+
Similar to EXT, which is for exported perl.h variables.
3652+
__attribute__global__ after: gnuc, clang. */
36533653
#if defined(__clang__) && defined(LTO)
3654+
# define GLOBAL
36543655
# define __attribute__global__ __attribute__((__visibility__("default")))
36553656
#elif defined(__SUNPRO_C) && defined(LTO)
3656-
# define __attribute__global__ __global
3657+
# define GLOBAL __global
3658+
# define __attribute__global__
3659+
#elif defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
3660+
# define GLOBAL __declspec(dllexport)
3661+
# define __attribute__global__
3662+
#elif !defined(UNDER_CE) && defined(WIN32) && defined(USE_DYNAMIC_LOADING)
3663+
# define GLOBAL __declspec(dllexport)
3664+
# define __attribute__global__
36573665
#else
3658-
/* on windows __declspec(dllexport) is already in the front. put nothing here */
3666+
# define GLOBAL
36593667
# define __attribute__global__
36603668
#endif
36613669
#ifdef HASATTRIBUTE_DEPRECATED

pod/perlcdelta.pod

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ any NULL-sensitive op-tree structure. See how many with C<-Dk>.
163163
C<-DPERL_FAKE_SIGNATURE> is now default, making most function calls 2x faster.
164164
See L</fake_signatures>
165165

166+
=item *
167+
168+
The new compiler option support allows generation of much faster
169+
code. I.e. clang-4.0 with -flto or zapcc produce ~20% faster code.
170+
166171
=back
167172

168173
=head1 Modules and Pragmata
@@ -424,6 +429,21 @@ L<[cperl #217]|https://github.com/perl11/cperl/issues/217>.
424429

425430
=back
426431

432+
=head1 Platform Support
433+
434+
=head2 Platform-Specific Notes
435+
436+
=over 4
437+
438+
=item Solaris
439+
440+
With the SunPro cc compiler we use now the C<__global> declaration
441+
for exported functions, similar to Windows C<__declspec(dllexport)>.
442+
443+
This is hidden under the new C<GLOBAL> macro.
444+
445+
=back
446+
427447
=head1 Configuration and Compilation
428448

429449
=over 4
@@ -525,18 +545,28 @@ This is related to the new C<-Wc++11-compat> and C<-fpermissive> fixes.
525545
=item *
526546

527547
Support for clang C<-flto> and the new C<-flto=thin> optimization was
528-
added, via C<__attribute__global__> for global visibility for all
529-
exported API functions, even if not used, and C<-DLTO>. Note that is
530-
not needed for C<gcc -flto>, and the clang variant produces slower code.
548+
added, via C<GLOBAL> declaration and C<__attribute__global__> for
549+
global visibility for all exported API functions, even if not used,
550+
and C<-DLTO>. Note that is not needed for C<gcc -flto>, and the clang
551+
variant produces slower code.
531552

532553
Rudimentary support for C<-fsanitize=cfi> was also added, which is
533554
safer than the old C<-fstack-protector-strong>, but this is not yet
534555
finished.
535556

536-
ExtUtils-ParseXS adds now a correct visibility declaration of
557+
L<ExtUtils::ParseXS> adds now a correct visibility declaration of
537558
C<XS_EXTERNAL> for C<-flto> and C<-fvisibility=hidden>, which is needed for
538559
C<-fsanitize=cfi> support.
539560

561+
C<Perl_xs_handshake> is now properly exported, which is needed for
562+
C<clang -flto=thin>.
563+
564+
=item *
565+
566+
C<XS_EXTERNAL> and C<XSPROTO> were simplified to use the new C<GLOBAL>
567+
declaration and C<__attribute__global__> attribute, for easier
568+
platform abstractions.
569+
540570
=item *
541571

542572
Added many OP read-write field accessor macros, like C<OpFIRST>,
@@ -551,9 +581,6 @@ See L<[cperl #219]|https://github.com/perl11/cperl/issues/219>.
551581

552582
=head1 Selected Bug Fixes
553583

554-
XXX Important bug fixes in the core language are summarized here. Bug fixes in
555-
files in F<ext/> and F<lib/> are best summarized in L</Modules and Pragmata>.
556-
557584
=over 4
558585

559586
=item *

t/porting/customized.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ExtUtils::MakeMaker cpan/ExtUtils-MakeMaker/t/Mkbootstrap.t 2f88adc65c55c7bd2e23
5757
ExtUtils::MakeMaker cpan/ExtUtils-MakeMaker/t/pm_to_blib.t 71ebcee355691ce374fcad251b12d8b2412462b3
5858
ExtUtils::MakeMaker cpan/ExtUtils-MakeMaker/t/prereq.t c1fe6e8ce96e8a648043ee8066e60a871fb4e0ba
5959
ExtUtils::MakeMaker cpan/ExtUtils-MakeMaker/t/vstrings.t c60ad8cfd3496f136aeb71008f51d2db0a34eb5f
60-
ExtUtils::ParseXS dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm 3c74d16f9e837bdea95326c2860f130e6739be5a
60+
ExtUtils::ParseXS dist/ExtUtils-ParseXS/lib/ExtUtils/ParseXS.pm dd71fa31e2b2a38344fd91eec22fd6948d08307e
6161
File::Path cpan/File-Path/lib/File/Path.pm 623799e76e11a756ca5e18749d8bc1bdc3800ecd
6262
File::Path cpan/File-Path/t/Path_win32.t 94b9276557ce7f80b91f6fd9bfa7a0cd9bf9683e
6363
File::Spec dist/PathTools/t/rel2abs_vs_symlink.t abbf1a890a1b6fefebc0c8a9e2849694ade89fa9

xsutils.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@
2525

2626
/* public XS package methods */
2727
/* -- converted to XS */
28-
PERL_CALLCONV void XS_strict_bits(pTHX_ CV *cv);
29-
PERL_CALLCONV void XS_strict_import(pTHX_ CV *cv);
30-
PERL_CALLCONV void XS_strict_unimport(pTHX_ CV *cv);
31-
PERL_CALLCONV void XS_attributes_reftype(pTHX_ CV *cv);
32-
PERL_CALLCONV void XS_attributes__fetch_attrs(pTHX_ CV *cv);
33-
PERL_CALLCONV void XS_attributes__modify_attrs(pTHX_ CV *cv);
34-
PERL_CALLCONV void XS_attributes__guess_stash(pTHX_ CV *cv);
35-
PERL_CALLCONV void XS_attributes_bootstrap(pTHX_ CV *cv);
28+
XS_EXTERNAL(XS_strict_bits);
29+
XS_EXTERNAL(XS_strict_import);
30+
XS_EXTERNAL(XS_strict_unimport);
31+
XS_EXTERNAL(XS_attributes_reftype);
32+
XS_EXTERNAL(XS_attributes__fetch_attrs);
33+
XS_EXTERNAL(XS_attributes__modify_attrs);
34+
XS_EXTERNAL(XS_attributes__guess_stash);
35+
XS_EXTERNAL(XS_attributes_bootstrap);
3636
/* converted to XS */
37-
PERL_CALLCONV void XS_attributes_import(pTHX_ CV *cv);
38-
PERL_CALLCONV void XS_attributes_get(pTHX_ CV *cv);
37+
XS_EXTERNAL(XS_attributes_import);
38+
XS_EXTERNAL(XS_attributes_get);
3939

4040
/* internal only */
4141
static HV* S_guess_stash(pTHX_ SV*);
@@ -296,7 +296,7 @@ Perl_boot_core_xsutils(pTHX)
296296
| HINT_EXPLICIT_STRICT_VARS)
297297

298298
/* Needed by B::Deparse and vars */
299-
XS(XS_strict_bits)
299+
XS_EXTERNAL(XS_strict_bits)
300300
{
301301
dVAR;
302302
dXSARGS;
@@ -325,7 +325,7 @@ XS(XS_strict_bits)
325325
/*
326326
See L<strict>
327327
*/
328-
XS(XS_strict_import)
328+
XS_EXTERNAL(XS_strict_import)
329329
{
330330
dVAR;
331331
dXSARGS;
@@ -357,7 +357,7 @@ XS(XS_strict_import)
357357
/*
358358
See L<strict>
359359
*/
360-
XS(XS_strict_unimport)
360+
XS_EXTERNAL(XS_strict_unimport)
361361
{
362362
dVAR;
363363
dXSARGS;
@@ -564,7 +564,7 @@ S_guess_stash(pTHX_ SV* sv)
564564
}
565565
}
566566

567-
XS(XS_attributes_bootstrap)
567+
XS_EXTERNAL(XS_attributes_bootstrap)
568568
{
569569
dVAR;
570570
dXSARGS;
@@ -610,7 +610,7 @@ If there are any bad attributes C<import> croaks.
610610
611611
*/
612612

613-
XS(XS_attributes_import)
613+
XS_EXTERNAL(XS_attributes_import)
614614
{
615615
/*
616616
@_ > 2 && ref $_[2] or do {
@@ -691,7 +691,7 @@ S_attributes__push_fetch(pTHX_ SV *sv)
691691
Handling"> below. Otherwise, only L<built-in attributes|"Built-in
692692
Attributes"> will be returned.
693693
*/
694-
XS(XS_attributes_get)
694+
XS_EXTERNAL(XS_attributes_get)
695695
{
696696
dVAR;
697697
dXSARGS;
@@ -751,7 +751,7 @@ XS(XS_attributes_get)
751751
}
752752

753753
/* default modify handler for builtin attributes */
754-
XS(XS_attributes__modify_attrs)
754+
XS_EXTERNAL(XS_attributes__modify_attrs)
755755
{
756756
dVAR;
757757
dXSARGS;
@@ -773,7 +773,7 @@ XS(XS_attributes__modify_attrs)
773773
}
774774

775775
/* default fetch handler for builtin attributes */
776-
XS(XS_attributes__fetch_attrs)
776+
XS_EXTERNAL(XS_attributes__fetch_attrs)
777777
{
778778
dVAR;
779779
dXSARGS;
@@ -794,7 +794,7 @@ XS(XS_attributes__fetch_attrs)
794794
}
795795

796796
/* helper function to return and set the stash of the svref */
797-
XS(XS_attributes__guess_stash)
797+
XS_EXTERNAL(XS_attributes__guess_stash)
798798
{
799799
dVAR;
800800
dXSARGS;
@@ -828,7 +828,7 @@ XS(XS_attributes__guess_stash)
828828
This can be useful for determining the I<type> value which forms part of
829829
the method names described in L<"Package-specific Attribute Handling"> below.
830830
*/
831-
XS(XS_attributes_reftype)
831+
XS_EXTERNAL(XS_attributes_reftype)
832832
{
833833
dVAR;
834834
dXSARGS;

0 commit comments

Comments
 (0)