Subject: | CCFLAGS should not override $Config{ccflags} |
As seen in http://bugs.debian.org/628522 and possibly also
http://rt.cpan.org/Ticket/Display.html?id=67990 :
Compiling XS extensions without $Config{ccflags} can break the
binary interface on some platforms as preprocessor definitions like
-D_FILE_OFFSET_BITS=64 are not used for the build.
This has become a practical problem for us (Debian) with 5.14.0 where
such extensions actually stop working on the x86 (32-bit) architecture;
see also the recent similar EU::CBuilder issue at
http://rt.perl.org/rt3/Public/Bug/Display.html?id=89478
Unless a correct use case exists for compiling an XS module without
$Config{ccflags} (I can't think of any), it seems to me that any extra
CCFLAGS should be appended to those rather than overriding them.
The alternative to such a fix seems to be that the modules overriding
CCFLAGS should include $Config{ccflags} themselves. In that case this
requirement should probably be mentioned in the EU::MM documentation.
The attached naive patch implements the first option. Please note that I
had to change an existing test to accomodate the new behaviour. Based on
the comment the aim of the test is not to check that CCFLAGS was
completely overridden, just that the contents are not deleted.
This potentially affects modules that already explicitly set CCFLAGS to
a value that includes $Config{ccflags}. I'm only aware of DBD::Oracle
doing this if it's building with 'bcc32' (probably a win32 thing?).
FWIW, Dominic Hargreaves has tested a rebuild of about 400 XS modules on
Debian/5.14.0 with the patch without any regressions, as mentioned in
the Debian bug report.
Please let me know what you think. Many thanks for your work on
ExtUtils::MakeMaker!
--
Niko Tyni
ntyni@debian.org
Subject: | 0001-Append-CCFLAGS-to-Config-ccflags-instead-of-overridi.patch |
From bb5cff55e52477be757b73d915bda76b4c5e088f Mon Sep 17 00:00:00 2001
From: Niko Tyni <ntyni@debian.org>
Date: Mon, 30 May 2011 22:54:24 +0300
Subject: [PATCH] Append CCFLAGS to $Config{ccflags} instead of overriding it
As seen in
http://bugs.debian.org/628522
and possibly also
http://rt.cpan.org/Ticket/Display.html?id=67990
compiling XS extensions without $Config{ccflags} can break the
binary interface on some platforms. There does not seem to be any correct
use case for compiling a module without $Config{ccflags}, so any extra
CCFLAGS should be appended to those rather than overriding them.
---
lib/ExtUtils/MM_Unix.pm | 6 +++++-
t/MM_Unix.t | 8 ++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/lib/ExtUtils/MM_Unix.pm b/lib/ExtUtils/MM_Unix.pm
index a3b7e9d..5e0758a 100644
--- a/lib/ExtUtils/MM_Unix.pm
+++ b/lib/ExtUtils/MM_Unix.pm
@@ -250,7 +250,11 @@ sub cflags {
$cflags{$_} =~ s/^\s+//;
$cflags{$_} =~ s/\s+/ /g;
$cflags{$_} =~ s/\s+$//;
- $self->{uc $_} ||= $cflags{$_};
+ if (/ccflags/ && $self->{uc $_}) {
+ $self->{uc $_} = "$cflags{$_} " . $self->{uc $_};
+ } else {
+ $self->{uc $_} ||= $cflags{$_};
+ }
}
if ($self->{POLLUTE}) {
diff --git a/t/MM_Unix.t b/t/MM_Unix.t
index 55c29e3..5f76e08 100644
--- a/t/MM_Unix.t
+++ b/t/MM_Unix.t
@@ -12,7 +12,7 @@ BEGIN {
plan skip_all => 'Non-Unix platform';
}
else {
- plan tests => 110;
+ plan tests => 112;
}
}
@@ -20,6 +20,7 @@ BEGIN { use_ok( 'ExtUtils::MM_Unix' ); }
use strict;
use File::Spec;
+use Config;
my $class = 'ExtUtils::MM_Unix';
@@ -220,6 +221,9 @@ foreach (qw/ EXPORT_LIST PERL_ARCHIVE PERL_ARCHIVE_AFTER /)
$t->cflags();
# Brief bug where CCFLAGS was being blown away
- is( $t->{CCFLAGS}, '-DMY_THING', 'cflags retains CCFLAGS' );
+ like( $t->{CCFLAGS}, "/-DMY_THING/", 'cflags retains CCFLAGS' );
+
+ like( $t->{CCFLAGS}, "/\Q$Config{ccflags}\E/", 'cflags does not override $Config{ccflags} with CCFLAGS' );
+ like( $t->{CCFLAGS}, '/ -DMY_THING$/', 'cflags appends CCFLAGS to $Config{ccflags}' );
}
--
1.7.5.1