Subject: | Does not load on some architectures |
First, I want to thank you for doing this module with a good algorithm and with the C code! There are so many bad ways people have done this. I've found it very useful. This is a long message - the short summary is that I want you to do a s/CCFLAGS/OPTIMIZE/g inside Makefile.PL - only one line needs to change and your module will work on a lot more platforms, and possibly compile more like you expect it to.
Long details:
The CCFLAGS => '-O3' line in Makefile.PL is causing this to not compile on some architectures.
It works fine on ordinary Linux x64 architectures, but on other systems, overwriting the CCFLAGS is bad and breaks the module.
For example, on my Debian ARM-based system, if I comment out the line in Makefile.PL where you overwrite CCFLAGS, the tests succeed. But if I leave Makefile.PL the way it was in the distribution, it fails during tests with a handshake failure error. I've included an example of the failure at the end of this comment. It also fails on Solaris. You'll probably see some of these at http://matrix.cpantesters.org/?dist=Net-IP-LPM+1.09 within 24 hours or so (you'll see the red at the top under Solaris, and also at least some red on Perl 5.22.0 on Linux, after the cpantesters.org system gets a chance to process my test results).
Here's what one of the compiles looks like when I remove your CCFLAGS override (this builds a file that can be dynamically loaded - it works):
=======
cc -c -I. -D_REENTRANT -D_GNU_SOURCE -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -O2 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" -fPIC "-I/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/armv7l-linux-thread-multi/CORE" LPM.c
=======
Here's one that fails (as the module is delivered, with the override of CCFLAGS):
=======
cc -c -I. -O3 -O2 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" -fPIC "-I/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/armv7l-linux-thread-multi/CORE" LPM.c
=======
As you can see, several -D defines from the Perl build are missing when the CCFLAGS variable they are in is overwritten with "-O3", causing critical structures to be mismatched. Also, there still is an -O2 present following your -O3 - it may not do what you think it is doing.
I then changed the "CCFLAGS => '-O3'" line in Makefile.PL to "OPTIMIZE => '-O3'". This, I believe does what you want - the important defines like -D_FILE_OFFSET_BITS remain, and the old -O2 is gone:
======
cc -c -I. -D_REENTRANT -D_GNU_SOURCE -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -O3 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" -fPIC "-I/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/armv7l-linux-thread-multi/CORE" LPM.c
======
I've attached a patch (but it really is just s/CCFLAGS/OPTIMIZE/g in Makefile.PL. FWIW, -O3 vs. -O2 doesn't seem to be noticeably different on my systems for performance with this module.
Example failure:
root@armperl:~/Net-IP-LPM-1.09# make test [17/316]
cp lib/Net/IP/LPM.pm blib/lib/Net/IP/LPM.pm
Running Mkbootstrap for Net::IP::LPM ()
chmod 644 "LPM.bs"
"/usr/local/perlbrew/perls/5.22.0.thread/bin/perl" "/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/ExtUtils/xsubpp" -typemap "/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/ExtUtils/typemap" LPM.xs > LPM.xsc && mv LPM.xsc LPM.c
Please specify prototyping behavior for LPM.xs (see perlxs manual)
cc -c -I. -O3 -O2 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" -fPIC "-I/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/armv7l-linux-thread-multi/CORE" LPM.c
cc -c -I. -O3 -O2 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" -fPIC "-I/usr/local/perlbrew/perls/5.22.0.thread/lib/5.22.0/armv7l-linux-thread-multi/CORE" lpm_lib.c
rm -f blib/arch/auto/Net/IP/LPM/LPM.so
cc -shared -O2 -L/usr/local/lib -fstack-protector-strong LPM.o lpm_lib.o -o blib/arch/auto/Net/IP/LPM/LPM.so \
\
chmod 755 blib/arch/auto/Net/IP/LPM/LPM.so
"/usr/local/perlbrew/perls/5.22.0.thread/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- LPM.bs blib/arch/auto/Net/IP/LPM/LPM.bs 644
PERL_DL_NONLAZY=1 "/usr/local/perlbrew/perls/5.22.0.thread/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/01-Net-IP-LPM.t ... LPM.c: loadable library and perl binaries are mismatched (got handshake key 0x8d80080, needed 0x8f80080)
t/01-Net-IP-LPM.t ... Dubious, test returned 1 (wstat 256, 0x100)
Failed 13/13 subtests
t/02-performance.t .. LPM.c: loadable library and perl binaries are mismatched (got handshake key 0x8d80080, needed 0x8f80080)
t/02-performance.t .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 2/2 subtests
Test Summary Report
-------------------
t/01-Net-IP-LPM.t (Wstat: 256 Tests: 0 Failed: 0)
Non-zero exit status: 1
Parse errors: Bad plan. You planned 13 tests but ran 0.
t/02-performance.t (Wstat: 256 Tests: 0 Failed: 0)
Non-zero exit status: 1
Parse errors: Bad plan. You planned 2 tests but ran 0.
Files=2, Tests=0, 1 wallclock secs ( 0.14 usr 0.02 sys + 0.43 cusr 0.04 csys = 0.63 CPU)
Result: FAIL
Failed 2/2 test programs. 0/0 subtests failed.
Makefile:1013: recipe for target 'test_dynamic' failed
make: *** [test_dynamic] Error 1
root@armperl:~/Net-IP-LPM-1.09# vi Makefile.PL
root@armperl:~/Net-IP-LPM-1.09# perl Makefile.PL
Generating a Unix-style Makefile
Writing Makefile for Net::IP::LPM
Writing MYMETA.yml and MYMETA.json
Subject: | net-ip-lpm-jcm.patch |
diff --git a/Makefile.PL b/Makefile.PL
index 0bee1d3..21b60f0 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -20,8 +20,8 @@ WriteMakefile(
#OBJECT => 'lpm_lib.o', # link all the C files too
#MYEXTLIB => 'libnf/libnf$(LIB_EXT)',
NORECURS => 0,
- #CCFLAGS => '-std=c99 -Wall -pedantic -O3'
- CCFLAGS => '-O3'
+ #OPTIMIZE => '-std=c99 -Wall -pedantic -O3'
+ OPTIMIZE => '-O3'
);
if (eval {require ExtUtils::Constant; 1}) {
# If you edit these definitions to change the constants used by this module,