| Store | Cart

[perl #121686] A request to backport a commit to perl 5.16

From: Craig A. Berry (via RT) <perl...@perl.org>
Sat, 19 Apr 2014 09:15:10 -0700
# New Ticket Created by  Craig A. Berry 
# Please include the string:  [perl #121686]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=121686 >


I received this request privately from one of the macports folks and I'm opening a ticket to get it properly considered.

The short version is whether 7db66e12883f0, "A more C++-friendly dNOOP," can be backported to maint-5.16 to fix a problem with newer, stricter versions of clang++.

Begin forwarded message:

> From: Mojca Miklavec <moj...@macports.org>> Subject: A request to backport a commit to perl 5.16> Date: April 3, 2014 at 4:59:20 AM CDT> To: "Craig A. Berry" <crai...@mac.com>, Ricardo Signes <r...@cpan.org>> > Hi,> > I would like to kindly request adding the following commit also to> maint-5.16 if possible (for the next 5.16.4 release):> > http://perl5.git.perl.org/perl.git/commit/7db66e12883f0832ca80164b723768b848187bda?f=perl.h> > (I didn't test with 5.14 or 5.12, so maybe it's needed there as well.> If there's a need to test it, I can ask users to do it, but we are> experiencing other problems on 5.14 which currently don't allow us to> test *exactly* that scenario.)> > See:> https://trac.macports.org/ticket/43150> > I'm still waiting for confirmation from other users if that solves the> problem for them as well. This only became a problem with the latest> XCode release and a stricter clang compiler.> > Thank you,>    Mojca


The problem is readily illustrated by configuring a build of maint-5.16 as of v5.16.3-9-g7aa08a0 with -Dcc=clang++ when the clang++ version is:

$ clang++ --version
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix

This is what comes with XCode 5.1.1, but how one acquires the relevant version of clang++ probably doesn't matter.  The build falls down hard like so:

`sh  cflags "optimize='-O3'" mro.o`  mro.c
	  CCCMD =  clang++ -DPERL_CORE -c -fno-common -DPERL_DARWIN -no-cpp-precomp -I/usr/local/include -I/opt/local/include  -O3  -Wall -ansi -W -Wextra -Wdeclaration-after-statement -Wendif-labels -Wc++-compat -Wwrite-strings -Wno-unused-variable -Wno-unused-parameter
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated
mro.c:421:10: warning: implicit conversion of NULL constant to 'bool' [-Wnull-conversion]
              ? newSVhek(HvENAME_HEK(stash)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./embed.h:360:42: note: expanded from macro 'newSVhek'
#define newSVhek(a)             Perl_newSVhek(aTHX_ a)
                                ~~~~~~~~~~~~~       ^
mro.c:421:10: warning: implicit conversion of NULL constant to 'bool' [-Wnull-conversion]
              ? newSVhek(HvENAME_HEK(stash)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~
./embed.h:360:42: note: expanded from macro 'newSVhek'
#define newSVhek(a)             Perl_newSVhek(aTHX_ a)
                                ~~~~~~~~~~~~~       ^
mro.c:1396:5: error: declaration of 'Perl___notused' has a different language linkage
    dVAR;
    ^
./perl.h:174:17: note: expanded from macro 'dVAR'
#  define dVAR          dNOOP
                        ^
./perl.h:362:26: note: expanded from macro 'dNOOP'
#define dNOOP extern int Perl___notused(void)
                         ^
mro.c:493:5: note: previous declaration is here
    dVAR;
    ^
./perl.h:174:17: note: expanded from macro 'dVAR'
#  define dVAR          dNOOP
                        ^
./perl.h:362:26: note: expanded from macro 'dNOOP'
#define dNOOP extern int Perl___notused(void)
                         ^
2 warnings and 1 error generated.
make: *** [mro.o] Error 1

The problem doesn't exist in 5.18.x and later because I fixed a similar problem for the OpenVMS C++ compiler as follows:

commit 7db66e12883f0832ca80164b723768b848187bda
Author: Craig A. Berry <crai...@mac.com>
Date:   Wed May 30 18:57:51 2012 -0500

    A more C++-friendly dNOOP.

    The problem with Perl___notused under C++ is that in some cases
    it's merely extern, and in some cases (via the XS macro via the
    XSPROTO macro) it's extern "C".  Object code analysis shows that
    you do actually get one mangled and one unmangled version of the
    symbol, which wouldn't matter since the whole point is to have
    something we never use.

    Except that one very picky C++ compiler (HP C++ for OpenVMS) sees
    what we're up to and slaps us down hard.  Since declaration after
    statement has always been allowed in C++, just go ahead and do a
    real noop statement for C++ and avoid the use of an external
    symbol.

diff --git a/perl.h b/perl.h
index 3d89f8a..798e7b7 100644
--- a/perl.h
+++ b/perl.h
@@ -359,7 +359,11 @@
 /* Rats: if dTHR is just blank then the subsequent ";" throws an error */
 /* Declaring a *function*, instead of a variable, ensures that we don't rely
    on being able to suppress "unused" warnings.  */
+#ifdef __cplusplus
+#define dNOOP (void)0
+#else
 #define dNOOP extern int Perl___notused(void)
+#endif

 #ifndef pTHX
 /* Don't bother defining tTHX and sTHX; using them outside
[end]

The problem with backporting this as-is is that's it's not binary compatible.  If the core is built with C++ after this patch, the Perl___notused symbol goes missing from libperl.  A previously-built extension looking for that symbol at run-time would blow up.

However, if building the core is only supported for C, and C++ is only supported for extension building, it might be ok because the Perl___notused symbol will still be present in a libperl built with C.  So that's one potential answer.

Another is to provide the Perl___notused symbol somewhere such as mathoms.c when building with C++.

The perl -V info below reflects the platform where the issue was reproduced but not the compiler used since you don't even get as far as miniperl with clang++.

$ ./perl -Ilib -V
Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
  Commit id: 7aa08a0f356a87b817f92a7941678ccf0e162b90
  Platform:
    osname=darwin, osvers=13.1.0, archname=darwin-2level
    uname='darwin triamond.local 13.1.0 darwin kernel version 13.1.0: thu jan 16 19:40:37 pst 2014; root:xnu-2422.90.20~2release_x86_64 x86_64 '
    config_args='-des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include',
    optimize='-O3',
    cppflags='-fno-common -DPERL_DARWIN -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -I/opt/local/include'
    ccversion='', gccversion='4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -fstack-protector -L/usr/local/lib -L/opt/local/lib'
    libpth=/usr/local/lib /opt/local/lib /usr/lib
    libs=-ldbm -ldl -lm -lutil -lc
    perllibs=-ldl -lm -lutil -lc
    libc=, so=dylib, useshrplib=false, libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
    cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/usr/local/lib -L/opt/local/lib -fstack-protector'


Characteristics of this binary (from libperl):
  Compile-time options: HAS_TIMES PERLIO_LAYERS PERL_DONT_CREATE_GVSV
                        PERL_MALLOC_WRAP PERL_PRESERVE_IVUV USE_64_BIT_ALL
                        USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE
                        USE_LOCALE_COLLATE USE_LOCALE_CTYPE
                        USE_LOCALE_NUMERIC USE_PERLIO USE_PERL_ATOF
  Built under darwin
  Compiled at Apr 19 2014 10:38:05
  @INC:
    lib
    /usr/local/lib/perl5/site_perl/5.16.3/darwin-2level
    /usr/local/lib/perl5/site_perl/5.16.3
    /usr/local/lib/perl5/5.16.3/darwin-2level
    /usr/local/lib/perl5/5.16.3
    /usr/local/lib/perl5/site_perl/5.16.2/darwin-2level
    /usr/local/lib/perl5/site_perl/5.16.2
    /usr/local/lib/perl5/site_perl



________________________________________
Craig A. Berry
mailto:crai...@mac.com

"... getting out of a sonnet is much more
 difficult than getting in."
                 Brad Leithauser

Recent Messages in this Thread
Tony Cook via RT Apr 23, 2014 11:41 pm
Craig A. Berry (via RT) Apr 19, 2014 04:15 pm
David Golden Apr 20, 2014 10:04 am
Tony Cook via RT Apr 20, 2014 11:58 pm
Tony Cook via RT Apr 23, 2014 11:38 pm
Craig A. Berry Apr 21, 2014 12:59 am
Leon Timmermans Apr 21, 2014 02:03 pm
Karen Etheridge Apr 22, 2014 05:59 pm
Messages in this thread