Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account / $Config{cppsymbols} omits gcc-3.4+ cpp "predefined macros" #8305

p5pRT opened this issue Jan 31, 2006 · 3 comments


Copy link

p5pRT commented Jan 31, 2006

Migrated from (status was 'resolved')

Searchable as RT38385$

Copy link

p5pRT commented Jan 31, 2006


Created by

The gcc cpp "predefined macros" have no definitions in,
causing many includes of .ph files to fail, eg. :
$ perl -e 'require "sys/";'
Undefined subroutine &main​::__LONG_MAX__ called at (eval 259) line 1.
Compilation failed in require at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/sys/ line 11.
Compilation failed in require at -e line 1

__LONG_MAX__, and __INT_MAX__, and many other '#define's, have NO
definition in ANY header file with gcc-3.4+, but are built-in to
cpp, as described in the documention on the cpp option '-dM'​:
  `-dCHARS' ...
  Instead of the normal output, generate a list of `#define'
  directives for all the macros defined during the execution of
  the preprocessor, including predefined macros. This gives
  you a way of finding out what is predefined in your version
  of the preprocessor. Assuming you have no file `foo.h', the

  touch foo.h; cpp -dM foo.h

  will show all the predefined macros.

With gcc-4+ on i386 Fedora Core, many '#define's are "predefined" in cpp​:
$ >foo.h; cpp -dM foo.h | egrep '_MAX__|__VERSION|long '
#define __WCHAR_MAX__ 2147483647
#define __SHRT_MAX__ 32767
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __UINTMAX_TYPE__ long long unsigned int
#define __SCHAR_MAX__ 127
#define __DBL_MAX__ 1.7976931348623157e+308
#define __LONG_LONG_MAX__ 9223372036854775807LL
#define __VERSION__ "4.1.0 20060128 (Red Hat 4.1.0-0.17)"
#define __LONG_MAX__ 2147483647L
#define __WCHAR_TYPE__ long int
#define __INT_MAX__ 2147483647
#define __INTMAX_MAX__ 9223372036854775807LL
#define __FLT_MAX__ 3.40282347e+38F
#define __INTMAX_TYPE__ long long int

Also, many of these '#define's will cause the current version of
h2ph to emit bad definitions - ie
  __VERSION__="4.1.0\ 20060128\ (Red\ Hat\ 4.1.0-0.17)"
would have become​:
unless (defined &__VERSION__) { sub __VERSION__() { "\"4\.1\.0\\" } }
because h2ph split the $Config{cppsymbols} on /\s/ only.
Also floating point defintions were mangled into strings by h2ph​:
unless (defined &__LDBL_MAX__) { sub __LDBL_MAX__() { "1\.18973149535723176502e\+4932L" }
This problem was originally reported as Red Hat bugzilla #178343​:
and is present in all current perl versions - 5.8.7, 5.8.8-RC1, and 5.9.3+ (bleadperl).

So here's a patch against the 5.8.8-RC1 source to merge in the cpp internal
"predefined macro" definitions into Cppsym.true in Configure, so they appear in
$Config{cppsymbols}, and to fix h2ph's _extract_cc_defines() and
build_preamble_if_necessary() subs to deal with escaped whitespace symbol values,
floating point constants, signed numeric constants, and parethensized values properly​:

___ BEGIN PATCH​: ___

Inline Patch
--- perl-5.8.8-RC1/Configure.bz178343   2006-01-08 09:51:03.000000000 -0500
+++ perl-5.8.8-RC1/Configure    2006-01-31 11:50:02.000000000 -0500
@@ -20230,6 +20230,19 @@
 chmod +x Cppsym.try
 $eunicefix Cppsym.try
 ./Cppsym < Cppsym.know > Cppsym.true
+: Add in any linux cpp "predefined macros":
+if [[ "$osname" == *linux* ]] && [[ "$ccname" == *gcc* ]]; then
+tHdrH=`mktemp ./XXXXXX`
+rm -f $tHdrH'.h' $tHdrH
+touch $tHdrH'.h'
+if cpp -dM $tHdrH'.h' > $tHdrH'_cppsym.h' && [ -s $tHdrH'_cppsym.h' ] ; then
+   sed 's/#define[\ \  ]*//;s/[\ \     ].*$//' < $tHdrH'_cppsym.h' > $tHdrH'_cppsym.real';
+   if [ -s $tHdrH'_cppsym.real' ]; then
+      cat $tHdrH'_cppsym.real' Cppsym.know  | sort | uniq | ./Cppsym | sort | uniq > Cppsym.true;
+   fi;
+rm -f $tHdrH'.h' $tHdrH'_cppsym.h' $tHdrH'_cppsym.real';
 : now check the C compiler for additional symbols
 case "$osname" in
--- perl-5.8.8-RC1/utils/h2ph.PL.bz178343       2006-01-13 12:56:47.000000000 -0500
+++ perl-5.8.8-RC1/utils/h2ph.PL        2006-01-31 11:53:24.000000000 -0500
@@ -778,8 +778,16 @@
             if ($opt_D) {
                 print PREAMBLE "# $_=$define{$_}\n";
-            if ($define{$_} =~ /^(\d+)U?L{0,2}$/i) {
+           if ($define{$_} =~ /^\((.*)\)$/) {
+             # parenthesized value:  d=(v)
+               $define{$_} = $1;
+           };
+           if ($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/ ) {
+             # float:
+               print PREAMBLE
+                    "unless (defined &$_) { sub $_() { $1 } }\n\n";
+           } elsif ($define{$_} =~ /^([+-]?\d+)U?L{0,2}$/i) {
+             # integer:
                 print PREAMBLE
                     "unless (defined &$_) { sub $_() { $1 } }\n\n";
             } elsif ($define{$_} =~ /^\w+$/) {
@@ -805,9 +813,8 @@
         @Config{'ccsymbols', 'cppsymbols', 'cppccsymbols'};

     # Split compiler pre-definitions into `key=value' pairs:
-    foreach (split /\s+/, $allsymbols) {
-        /(.+?)=(.+)/ and $define{$1} = $2;
+    while( $allsymbols=~/([^\s]+)=((\\\s|[^\s])+)/g ) {
+        $define{$1} = $2;
         if ($opt_D) {
             print STDERR "$_:  $1 -> $2\n";
___ END PATCH ___ \

Please consider fixing this issue in the upcoming 5.8.8 / 5.9.3 releases,
as many header files are made unusable by this problem .

Thanks & Regards,
Jason Vas Dias<jvdias@​>
perl package maintainer
Red Hat, Inc.

Perl Info


This perlbug was built using Perl v5.8.8 in the Red Hat build system.
It is being executed now by  Perl v5.8.8 - Fri Jan 20 16:43:53 EST 2006.

Site configuration information for perl v5.8.8:

Configured by Red Hat, Inc. at Fri Jan 20 16:43:53 EST 2006.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
    osname=linux, osvers=2.6.15-1.1863_fc5, archname=i386-linux-thread-multi
    uname='linux jvdias 2.6.15-1.1863_fc5 #1 thu jan 19 19:17:58 est 2006 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=pentium4 -fasynchronous-unwind-tables -Dversion=5.8.8 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_setservent_r_proto -Dinc_version_list=5.8.7 5.8.6 5.8.5 5.8.4 5.8.3 -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=pentium4 -fasynchronous-unwind-tables',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='4.1.0 20060117 (Red Hat 4.1.0-0.15)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.8.8:

Environment for perl v5.8.8:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)

Copy link

p5pRT commented Mar 3, 2006

From @Tux

The intent of this patch is correct, but the implementation leaves some
loose end. Except for the inconsistency in whitespace use and the
amount of unneeded semi-colon's, the syntax used is unportable.
Further, even though this patch is only for linux, mktemp is not
needed, as temp files are used all over the place in Configure, so I
ended up with the following change​:

: Add in any linux cpp "predefined macros"​:
case "$osname​::$gccversion" in
  rm -f $tHdrH'.h' $tHdrH
  touch $tHdrH'.h'
  if cpp -dM $tHdrH'.h' > $tHdrH'_cppsym.h' && [ -s $tHdrH'_cppsym.h
' ]; then
  sed 's/#define[\ \ ]*//;s/[\ \ ].*$//' <$tHdrH'_cppsym.h' >
  if [ -s $tHdrH'_cppsym.real' ]; then
  cat $tHdrH'_cppsym.real' Cppsym.know | sort | uniq | ./Cppsym |
sort | uniq > Cppsym.true
  rm -f $tHdrH'.h' $tHdrH'_cppsym.h' $tHdrH'_cppsym.real'

(changes 27363 and 27367)

Copy link

p5pRT commented Mar 3, 2006

@Tux - Status changed from 'new' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant