Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 94069
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: rurban [...] x-ray.at
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Invalid compile-time use constant encoding for perlcc
perlcc fails to run code which uses Net::DNS because Net::DNS::Domain captures a ptr to an external XS encoding object at compile-time. use constant ASCII => eval { require Encode; Encode::find_encoding('ASCII'); # return encoding object } || 0; The PVMG contains in the IV the ptr to the external symbol of &ascii_encoding. which is an external symbol from the shared library. The only workaround in the compiler which needs to thaw the state of the compile-time state is to do something like: #include <dlfcn.h> void *handle = dlopen(sv_list[5032].sv_u.svu_pv, RTLD_NOW|RTLD_NOLOAD); // <pathto/Encode.so> void *ascii_encoding = dlsym(handle, "ascii_encoding"); SvIV_set(&sv_list[1], PTR2IV(ascii_encoding)); which is not managable generally. Please store the encodings at run-time as in the attached patch. Btw: using lower-case encoding names is recommended. INIT { sub ASCII { eval { require Encode; Encode::find_encoding('ASCII'); # return encoding object } || 0; } ... See https://code.google.com/p/perl-compiler/issues/detail?id=305
Subject: Net-DNS-0.74-perlcc.patch
diff -bu Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm~ Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm --- Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm~ 2014-01-16 03:48:52.000000000 -0600 +++ Net-DNS-0.74-RJ8GaG/lib/Net/DNS/Domain.pm 2014-03-20 16:44:32.763915278 -0500 @@ -40,21 +40,28 @@ use integer; use Carp; - -use constant ASCII => eval { +INIT { + sub ASCII { + eval { require Encode; Encode::find_encoding('ASCII'); # return encoding object -} || 0; + } || 0; + } -use constant UTF8 => eval { + sub UTF8 { + eval { die if Encode::decode_utf8( chr(91) ) ne '['; # not UTF-EBCDIC [see UTR#16 3.6] Encode::find_encoding('UTF8'); # return encoding object -} || 0; + } || 0; + } -use constant LIBIDN => eval { + sub LIBIDN { + eval { require Net::LibIDN; # tested and working UTF8 && Net::LibIDN::idn_to_ascii( pack( 'U*', 20013, 22269 ), 'utf-8' ) eq 'xn--fiqs8s'; -} || 0; + } || 0; + } +} =head1 METHODS
From: rurban [...] x-ray.at
broken from 0.67 - 0.74 See also https://github.com/rurban/distroprefs/commit/b38336e84df3cb0183a0da189ef2636b7a0474c4 for a distroprefs recipe to patch it automatically.
From: rwfranks [...] acm.org
Reini, Thanks for the thorough investigation. The compile-time constants are used to allow the perl interpreter to optimise away unused code. Performance is horrible without it. I will work this and mail patch for you to test when I have one. Dick On Thu Mar 20 17:54:56 2014, rurban@x-ray.at wrote: Show quoted text
> broken from 0.67 - 0.74 > > See also > https://github.com/rurban/distroprefs/commit/b38336e84df3cb0183a0da189ef2636b7a0474c4 > for a distroprefs recipe to patch it automatically.
On Sat Mar 22 09:52:48 2014, rwfranks@acm.org wrote: Show quoted text
> Reini, > > Thanks for the thorough investigation. > > The compile-time constants are used to allow the perl interpreter to > optimise away unused code. Performance is horrible without it. > > I will work this and mail patch for you to test when I have one.
Dick, I am working with Reini. The provided patch is incomplete and will not fix the problem. This patch has been tested and fixes the problem.
Subject: 0001-Dont-capture-sub-refs-in-BEGIN.patch.txt
From 2810f2e68e4095005568cccd9ff781bb131781e8 Mon Sep 17 00:00:00 2001 From: Todd Rinaldo <toddr@cpanel.net> Date: Fri, 21 Mar 2014 00:28:41 -0500 Subject: [PATCH] Dont capture sub refs in BEGIN RT 94069 - perlcc fails to run code which uses Net::DNS because Net::DNS::Domain captures a ptr to an external XS encoding object at compile-time. See https://code.google.com/p/perl-compiler/issues/detail?id=305 --- modules/Net-DNS/Net-DNS/lib/Net/DNS/Domain.pm | 42 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/modules/Net-DNS/Net-DNS/lib/Net/DNS/Domain.pm b/modules/Net-DNS/Net-DNS/lib/Net/DNS/Domain.pm index ab5fc16..4fa2fc8 100644 --- a/modules/Net-DNS/Net-DNS/lib/Net/DNS/Domain.pm +++ b/modules/Net-DNS/Net-DNS/lib/Net/DNS/Domain.pm @@ -40,22 +40,38 @@ use strict; use integer; use Carp; +my $ascii_sub; + +sub ASCII { + return $ascii_sub if ($ascii_sub); + $ascii_sub = eval { + require Encode; + Encode::find_encoding('ASCII'); # return encoding object + } || 0; + return $ascii_sub; +} -use constant ASCII => eval { - require Encode; - Encode::find_encoding('ASCII'); # return encoding object -} || 0; +my $utf8_sub; -use constant UTF8 => eval { - die if Encode::decode_utf8( chr(91) ) ne '['; # not UTF-EBCDIC [see UTR#16 3.6] - Encode::find_encoding('UTF8'); # return encoding object -} || 0; +sub UTF8 { + return $utf8_sub if ($utf8_sub); + $utf8_sub = eval { + die if Encode::decode_utf8( chr(91) ) ne '['; # not UTF-EBCDIC [see UTR#16 3.6] + Encode::find_encoding('UTF8'); # return encoding object + } || 0; + return $utf8_sub; +} -use constant LIBIDN => eval { - require Net::LibIDN; # tested and working - UTF8 && Net::LibIDN::idn_to_ascii( pack( 'U*', 20013, 22269 ), 'utf-8' ) eq 'xn--fiqs8s'; -} || 0; +my $libidn_sub; +sub LIBIDN { + return $libidn_sub if ($libidn_sub); + $libidn_sub = eval { + require Net::LibIDN; # tested and working + UTF8 && Net::LibIDN::idn_to_ascii( pack( 'U*', 20013, 22269 ), 'utf-8' ) eq 'xn--fiqs8s'; + } || 0; + return $libidn_sub; +} =head1 METHODS @@ -348,6 +364,8 @@ sub _unescape { ## Remove escape sequences in string } +undef($ascii_sub); + 1; __END__ -- 1.9.0
From: rurban [...] x-ray.at
On Tue Mar 25 12:18:40 2014, TODDR wrote: Show quoted text
> On Sat Mar 22 09:52:48 2014, rwfranks@acm.org wrote:
> > Reini, > > > > Thanks for the thorough investigation. > > > > The compile-time constants are used to allow the perl interpreter to > > optimise away unused code. Performance is horrible without it. > > > > I will work this and mail patch for you to test when I have one.
> > Dick, I am working with Reini. The provided patch is incomplete and > will not fix the problem. This patch has been tested and fixes the > problem.
I've tested all those suggestions and some of mine. Todd and my first fix loose too much performance. This is a resolver. They want ASCII/UTF8 to be evaluated at compile-time, so on ASCII/UTF8 systems the relevant if checks will be constant folded. My first fix did the same. BEGIN { sub ... } would be the equivalent to use constant, because they need to be stored as CONSTSUB, not as CV. Storing a bool 1/0 pair in ASCII does not help either. I tried it previously also. I'm afraid that we cannot go that way. The ptr where I crash now (being a PVMG pointing the Encoding &ascii_encoding) went just from being a SVOP CONST (ASCII) to a PAD like Net::DNS::Domain::_decode_ascii :pad[1][8] (my $ascii). I see that you need compile-time constants for performance. In the meantime my init2-encode-issue305 perlcc branch gets pretty stable for for non dlopen systems, and I need it to patch older Net::DNS modules in the wild anyway, so I I thing you can close this ticket and I handle it in perlcc instead. Sorry for the trouble. Very interesting case. We'd really need an perl5-level API to announce extern symbols stored in PVMG->IV refs, together with the symbol name to find them at run-time. LISP's do it that way when they thaw frozen images with shared libraries which can be remapped.
From: rurban [...] x-ray.at
Dick came up with a very good patch, which fixes the perlcc issues. Attached.
Subject: netdns-bits.tar.gz
Download netdns-bits.tar.gz
application/gzip 2k

Message body not shown because it is not plain text.

If you want to optimize this, it's a a OS level, right? Why not code the module into a template and generate the right code at make install time? Losta "Optimized" modules do this already. It's not like ASCII/UTF8 change at a perl installation level over the life of the install.
From: rwfranks [...] acm.org
On Thu Mar 27 13:54:54 2014, TODDR wrote: Show quoted text
> If you want to optimize this, it's a a OS level, right? Why not code > the module into a template and generate the right code at make install > time? Losta "Optimized" modules do this already. It's not like > ASCII/UTF8 change at a perl installation level over the life of the > install.
Reini was never questioning the strategy, merely pointing out that the implement
From: rwfranks [...] acm.org
On Sat Mar 29 18:02:26 2014, rwfranks@acm.org wrote: Show quoted text
> On Thu Mar 27 13:54:54 2014, TODDR wrote:
> > If you want to optimize this, it's a a OS level, right? Why not code > > the module into a template and generate the right code at make > > install > > time? Losta "Optimized" modules do this already. It's not like > > ASCII/UTF8 change at a perl installation level over the life of the > > install.
>
Reini was never questioning the strategy, merely pointing out that the implementation did not work in a compiled environment. Conditional compilation is sufficient to provide the limited optimisation necessary in the interpreted implementation, and irrelevant for compiled perl because everything runs an order of magnitude faster. [sorry for hitting wrong key and posting this half done]
Will be fixed in 0.75