Skip to content

Commit

Permalink
Handle intrin files on win32 with gcc
Browse files Browse the repository at this point in the history
This fixes #20033.

When building on Windows with Strawberry 5.32.1 (gcc 8.3.0) as the toolchain,
the Errno.pm is created by a script Errno_pm.pl, which takes output from the
compiler to find headers.

A subset of these headers requires them to only be included by some specific
headers. Previously the header order was effectively random and this
occasionally caused build errors (that further were never detected).

The get_files() is now returning the header names in the order the compiler
saw them which insures they are in the right order.
  • Loading branch information
kenneth-olwing authored and tonycoz committed Aug 25, 2022
1 parent f58ed7c commit 697eaf8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ Keith Thompson <keith.s.thompson@gmail.com> Keith Thompson <kst@mib.org>
Ken Neighbors <unknown> Ken Neighbors <perlbug@perl.org>
Ken Williams <ken@mathforum.org> <kenahoo@gmail.com>
Ken Williams <ken@mathforum.org> Ken Williams <ken.williams@thomsonreuters.com>
Kenneth Ölwing <knth@cpan.org> Kenneth Olwing <knth@cpan.org>
Kent Fredric <kentfredric@gmail.com> Kent Fredric <kentnl@cpan.org>
Kevin Brintnall <kbrint@rufus.net> kevin brintnall <kbrint@rufus.net>
Kevin Ryde <user42@zip.com.au> Kevin Ryde <perlbug-followup@perl.org>
Expand Down
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ Ken Williams <ken@mathforum.org>
Kenichi Ishigaki <ishigaki@cpan.org>
Kenneth Albanowski <kjahds@kjahds.com>
Kenneth Duda <kjd@cisco.com>
Kenneth Ölwing <knth@cpan.org>
Kent Fredric <kentfredric@gmail.com>
Keong Lim <Keong.Lim@sr.com.au>
Kevin Brintnall <kbrint@rufus.net>
Expand Down
43 changes: 24 additions & 19 deletions ext/Errno/Errno_pm.PL
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ExtUtils::MakeMaker;
use Config;
use strict;

our $VERSION = "1.36";
our $VERSION = "1.37";

my %err = ();

Expand All @@ -18,18 +18,11 @@ if ($Config{gccversion} ne '' && $^O eq 'MSWin32') {
# MinGW complains "warning: #pragma system_header ignored outside include
# file" if the header files are processed individually, so include them
# all in .c file and process that instead.
my %seen;
open INCS, '>', 'includes.c' or
die "Cannot open includes.c";
foreach $file (@files) {
next if $file eq 'errno.c';
next unless -f $file;
if ( $file eq 'avx512vpopcntdqvlintrin.h' || $file eq 'avx512bwintrin.h' ) {
# "Never use <avx512bwintrin.h> directly; include <immintrin.h> instead."
# "Never use <avx512vpopcntdqvlintrin.h> directly; include <immintrin.h> instead."
$file = 'immintrin.h';
}
next if ++$seen{$file} > 1;
print INCS qq[#include "$file"\n];
}
close INCS;
Expand Down Expand Up @@ -114,7 +107,7 @@ sub default_cpp {
}

sub get_files {
my %file = ();
my @file;
# When cross-compiling we may store a path for gcc's "sysroot" option:
my $sysroot = $Config{sysroot} || '';
my $linux_errno_h;
Expand All @@ -128,34 +121,34 @@ sub get_files {

# VMS keeps its include files in system libraries
if ($^O eq 'VMS') {
$file{'Sys$Library:DECC$RTLDEF.TLB'} = 1;
push(@file, 'Sys$Library:DECC$RTLDEF.TLB');
} elsif ($^O eq 'os390') {
# OS/390 C compiler doesn't generate #file or #line directives
# and it does not tag the header as 1047 (EBCDIC), so make a local
# copy and tag it
my $cp = `cp /usr/include/errno.h ./errno.h`;
my $chtag = `chtag -t -cIBM-1047 ./errno.h`;
$file{'./errno.h'} = 1;
push(@file, './errno.h');
} elsif ($Config{archname} eq 'arm-riscos') {
# Watch out for cross compiling for RISC OS
my $dep = `echo "#include <errno.h>" | gcc -E -M -`;
if ($dep =~ /(\S+errno\.h)/) {
$file{$1} = 1;
push(@file, $1);
}
} elsif ($^O eq 'linux' &&
$Config{gccversion} ne '' &&
$Config{gccversion} !~ /intel/i &&
# might be using, say, Intel's icc
$linux_errno_h
) {
$file{$linux_errno_h} = 1;
push(@file, $linux_errno_h);
} elsif ($^O eq 'haiku') {
# hidden in a special place
$file{'/boot/system/develop/headers/posix/errno.h'} = 1;
push(@file, '/boot/system/develop/headers/posix/errno.h');

} elsif ($^O eq 'vos') {
# avoid problem where cpp returns non-POSIX pathnames
$file{'/system/include_library/errno.h'} = 1;
push(@file, '/system/include_library/errno.h');
} else {
open(CPPI, '>', 'errno.c') or
die "Cannot open errno.c";
Expand Down Expand Up @@ -183,16 +176,28 @@ sub get_files {
if (/$pat/o) {
my $f = $1;
$f =~ s,\\\\,/,g;
$file{$f} = 1;
push(@file, $f);
}
}
else {
$file{$1} = 1 if /$pat/o;
push(@file, $1) if /$pat/o;
}
}
close(CPPO);
}
return keys %file;
return uniq(@file);
}

#
#
sub uniq
{
# At this point List::Util::uniq appears not to be usable so
# roll our own.
#
# Returns a list with unique values, while keeping the order
#
return do { my %seen; grep { !$seen{$_}++ } @_ };
}

sub write_errno_pm {
Expand Down Expand Up @@ -364,7 +369,7 @@ ESQ

if ($IsMSWin32) {
print " WINSOCK => [qw(\n";
$k = join(" ", grep { /^WSAE/ } keys %err);
$k = join(" ", grep { /^WSAE/ } sort keys %err);
$k =~ s/(.{50,70})\s/$1\n\t/g;
print "\t",$k,"\n )],\n";
}
Expand Down

0 comments on commit 697eaf8

Please sign in to comment.