Skip Menu |
Report information
Id: 131689
Status: new
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: mauke- <l.mai [at] web.de>
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: Wishlist
Type: core
Perl Version: 5.26.0
Fixed In: (no value)

Attachments
0001-Configure-check-for-__builtin_add_overflow-and-frien.patch
0002-provide-guard-macros-for-__builtin_add_overflow-and-.patch



Subject: Configure should probe for __builtin_add_overflow
To: perlbug [...] perl.org
Date: Sun, 02 Jul 2017 10:13:59 +0200
From: l.mai [...] web.de
Download (untitled) / with headers
text/plain 3.2k
This is a bug report for perl from l.mai@web.de, generated with the help of perlbug 1.40 running under perl 5.26.0. ----------------------------------------------------------------- [Please describe your issue here] I'd like to be able __builtin_add_overflow, __builtin_sub_overflow, __builtin_mul_overflow (safe +, -, * with overflow checks) in core code. It would be nice if Configure had checks for those (it already checks for __builtin_choose_expr and __builtin_expect). [Please do not change anything below this line] ----------------------------------------------------------------- --- Flags: category=core severity=wishlist --- Site configuration information for perl 5.26.0: Configured by mauke at Tue May 30 23:06:36 CEST 2017. Summary of my perl5 (revision 5 version 26 subversion 0) configuration: Platform: osname=linux osvers=4.10.11-1-arch archname=i686-linux uname='linux simplicio 4.10.11-1-arch #1 smp preempt tue apr 18 09:00:04 cest 2017 i686 gnulinux ' config_args='' hint=recommended useposix=true d_sigaction=define useithreads=undef usemultiplicity=undef use64bitint=undef use64bitall=undef uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='cc' ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64' optimize='-O2 -march=native' cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include' ccversion='' gccversion='7.1.1 20170516' gccosandvers='' intsize=4 longsize=4 ptrsize=4 doublesize=8 byteorder=1234 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=12 longdblkind=3 ivtype='long' ivsize=4 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=4 prototype=define Linker and Libraries: ld='cc' ldflags ='-fstack-protector-strong -L/usr/local/lib' libpth=/usr/local/lib /usr/lib/gcc/i686-pc-linux-gnu/7.1.1/include-fixed /usr/lib /lib libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc libc=libc-2.25.so so=so useshrplib=false libperl=libperl.a gnulibc_version='2.25' Dynamic Linking: dlsrc=dl_dlopen.xs dlext=so d_dlsymun=undef ccdlflags='-Wl,-E' cccdlflags='-fPIC' lddlflags='-shared -O2 -march=native -L/usr/local/lib -fstack-protector-strong' --- @INC for perl 5.26.0: /home/mauke/usr/lib/perl5/site_perl/5.26.0/i686-linux /home/mauke/usr/lib/perl5/site_perl/5.26.0 /home/mauke/usr/lib/perl5/5.26.0/i686-linux /home/mauke/usr/lib/perl5/5.26.0 --- Environment for perl 5.26.0: HOME=/home/mauke LANG=en_US.UTF-8 LANGUAGE=en_US LC_COLLATE=C LC_MONETARY=de_DE.UTF-8 LC_TIME=de_DE.UTF-8 LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/mauke/perl5/perlbrew/bin:/home/mauke/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl PERLBREW_BASHRC_VERSION=0.73 PERLBREW_HOME=/home/mauke/.perlbrew PERLBREW_ROOT=/home/mauke/perl5/perlbrew PERL_BADLANG (unset) PERL_UNICODE=SAL SHELL=/bin/bash
RT-Send-CC: perl5-porters [...] perl.org, h.m.brand [...] xs4all.nl
Download (untitled) / with headers
text/plain 705b
On Sun, 02 Jul 2017 01:14:12 -0700, mauke- wrote: Show quoted text
> > I'd like to be able __builtin_add_overflow, __builtin_sub_overflow, > __builtin_mul_overflow (safe +, -, * with overflow checks) in core > code. > > It would be nice if Configure had checks for those (it already checks > for > __builtin_choose_expr and __builtin_expect).
I've attached patches to do that, but I'm not sure if this is the right way to do it (see bug #131688). The first patch extends Configure. The second patch extends config_h.SH, which contains a comment saying "THIS IS A GENERATED FILE. DO NOT HAND-EDIT. See Porting/config_h.pl", but I saw Porting/config_h.pl and it contains no useful information, so I hand-edited anyway.
Subject: 0001-Configure-check-for-__builtin_add_overflow-and-frien.patch
From 27f6a544755754ae61bcf02dfbff843a94c6eeb0 Mon Sep 17 00:00:00 2001 From: Lukas Mai <l.mai@web.de> Date: Sun, 2 Jul 2017 09:35:59 +0200 Subject: [PATCH 1/2] Configure: check for __builtin_add_overflow and friends --- Configure | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git Configure Configure index 3259249500..4d151d97de 100755 --- Configure +++ Configure @@ -398,6 +398,9 @@ d_bcmp='' d_bcopy='' d_builtin_choose_expr='' d_builtin_expect='' +d_builtin_add_overflow='' +d_builtin_sub_overflow='' +d_builtin_mul_overflow='' d_bzero='' d_c99_variadic_macros='' d_casti32='' @@ -11562,6 +11565,117 @@ set d_builtin_expect eval $setvar $rm_try +: Look for GCC-style __builtin_add_overflow +case "$d_builtin_add_overflow" in +'') + echo " " + echo "Checking whether your compiler can handle __builtin_add_overflow ..." >&4 + $cat >try.c <<'EOCP' +int main(void) { + const unsigned int uint_max = ~0u; + int target_int = 0; + if (__builtin_add_overflow(1, 2, &target_int) || target_int != 3) { + return 1; + } + if (!__builtin_add_overflow((int)(uint_max >> 1), 1, &target_int)) { + return 1; + } + if (!__builtin_add_overflow(uint_max, -1, &target_int)) { + return 1; + } + return 0; +} +EOCP + set try + if eval $compile && $run ./try; then + echo "Your C compiler supports __builtin_add_overflow." + val="$define" + else + echo "Your C compiler doesn't seem to understand __builtin_add_overflow." + val="$undef" + fi + ;; +*) val="$d_builtin_add_overflow" ;; +esac + +set d_builtin_add_overflow +eval $setvar +$rm_try + +: Look for GCC-style __builtin_sub_overflow +case "$d_builtin_sub_overflow" in +'') + echo " " + echo "Checking whether your compiler can handle __builtin_sub_overflow ..." >&4 + $cat >try.c <<'EOCP' +int main(void) { + const unsigned int uint_max = ~0u; + int target_int = 0; + if (__builtin_sub_overflow(1, -2, &target_int) || target_int != 3) { + return 1; + } + if (!__builtin_sub_overflow(-(int)(uint_max >> 1), 2, &target_int)) { + return 1; + } + if (!__builtin_sub_overflow(uint_max, 1, &target_int)) { + return 1; + } + return 0; +} +EOCP + set try + if eval $compile && $run ./try; then + echo "Your C compiler supports __builtin_sub_overflow." + val="$define" + else + echo "Your C compiler doesn't seem to understand __builtin_sub_overflow." + val="$undef" + fi + ;; +*) val="$d_builtin_sub_overflow" ;; +esac + +set d_builtin_sub_overflow +eval $setvar +$rm_try + +: Look for GCC-style __builtin_mul_overflow +case "$d_builtin_mul_overflow" in +'') + echo " " + echo "Checking whether your compiler can handle __builtin_mul_overflow ..." >&4 + $cat >try.c <<'EOCP' +int main(void) { + const unsigned int uint_max = ~0u; + int target_int = 0; + if (__builtin_mul_overflow(2, 3, &target_int) || target_int != 6) { + return 1; + } + if (!__builtin_mul_overflow((int)(uint_max >> 1), 2, &target_int)) { + return 1; + } + if (!__builtin_mul_overflow(uint_max, 1, &target_int)) { + return 1; + } + return 0; +} +EOCP + set try + if eval $compile && $run ./try; then + echo "Your C compiler supports __builtin_mul_overflow." + val="$define" + else + echo "Your C compiler doesn't seem to understand __builtin_mul_overflow." + val="$undef" + fi + ;; +*) val="$d_builtin_mul_overflow" ;; +esac + +set d_builtin_mul_overflow +eval $setvar +$rm_try + : see if bzero exists set bzero d_bzero eval $inlibc @@ -24463,6 +24577,9 @@ d_bsdgetpgrp='$d_bsdgetpgrp' d_bsdsetpgrp='$d_bsdsetpgrp' d_builtin_choose_expr='$d_builtin_choose_expr' d_builtin_expect='$d_builtin_expect' +d_builtin_add_overflow='$d_builtin_add_overflow' +d_builtin_sub_overflow='$d_builtin_sub_overflow' +d_builtin_mul_overflow='$d_builtin_mul_overflow' d_bzero='$d_bzero' d_c99_variadic_macros='$d_c99_variadic_macros' d_casti32='$d_casti32' -- 2.13.2
Subject: 0002-provide-guard-macros-for-__builtin_add_overflow-and-.patch
From 0c07092cb3bd0b47e475f702566aaab2ffbd257b Mon Sep 17 00:00:00 2001 From: Lukas Mai <l.mai@web.de> Date: Sun, 2 Jul 2017 09:51:57 +0200 Subject: [PATCH 2/2] provide guard macros for __builtin_add_overflow and friends --- config_h.SH | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git config_h.SH config_h.SH index e9b144f02b..d35163f0e0 100755 --- config_h.SH +++ config_h.SH @@ -2586,6 +2586,24 @@ sed <<!GROK!THIS! >$CONFIG_H -e 's!^#undef\(.*/\)\*!/\*#define\1 \*!' -e 's!^#un #$d_builtin_expect HAS_BUILTIN_EXPECT /**/ #$d_builtin_choose_expr HAS_BUILTIN_CHOOSE_EXPR /**/ +/* HAS_BUILTIN_ADD_OVERFLOW: + * This symbol, if defined, indicates that the compiler supports + * __builtin_add_overflow for adding integers with overflow checks. + */ +#$d_builtin_add_overflow HAS_BUILTIN_ADD_OVERFLOW /**/ + +/* HAS_BUILTIN_SUB_OVERFLOW: + * This symbol, if defined, indicates that the compiler supports + * __builtin_sub_overflow for subtracting integers with overflow checks. + */ +#$d_builtin_sub_overflow HAS_BUILTIN_SUB_OVERFLOW /**/ + +/* HAS_BUILTIN_MUL_OVERFLOW: + * This symbol, if defined, indicates that the compiler supports + * __builtin_mul_overflow for multiplying integers with overflow checks. + */ +#$d_builtin_mul_overflow HAS_BUILTIN_MUL_OVERFLOW /**/ + /* HAS_C99_VARIADIC_MACROS: * If defined, the compiler supports C99 variadic macros. */ -- 2.13.2


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org