not really a bug but somewhat odd : checking compiler /usr/local/bin/gcc8 ... no, mpn_lshift_com

Dennis Clarke dclarke at blastwave.org
Sun Jul 28 11:09:38 UTC 2019


On 7/28/19 6:44 AM, Vincent Lefevre wrote:
> On 2019-07-28 06:12:06 -0400, Dennis Clarke wrote:
>> configure:6813: ./a.out || ./b.out || ./a.exe || ./a_out.exe || ./conftest
>> Abort trap (core dumped)
> 
> I don't know in your case, but I fear that this program is buggy.
> 
> [...]
>> void
>> lshift_com (rp, up, n, cnt)
>>   unsigned long *rp;
>>   unsigned long *up;
>>   long n;
>>   unsigned cnt;
> 
> It uses the old pre-ANSI K&R function definition, and AFAIK, in
> this case, there is no notion of prototype, i.e. it is expected
> that the caller passes compatible types as the compiler will not
> be able to do type conversion. Note that the 4th parameter, cnt,
> is of type unsigned int.
> 
>> {
>>   unsigned long high_limb, low_limb;
>>   unsigned tnc;
>>   long i;
>>   up += n;
>>   rp += n;
>>   tnc = 8 * sizeof (unsigned long) - cnt;
>>   low_limb = *--up;
>>   high_limb = low_limb << cnt;
>>   for (i = n - 1; i != 0; i--)
>>     {
>>       low_limb = *--up;
>>       *--rp = ~(high_limb | (low_limb >> tnc));
>>       high_limb = low_limb << cnt;
>>     }
>>   *--rp = ~high_limb;
>> }
>> int
>> main ()
>> {
>>   unsigned long *r, *r2;
>>   unsigned long a[88 + 1];
>>   long i;
>>   for (i = 0; i < 88 + 1; i++)
>>     a[i] = ~0L;
>>   r = malloc (10000 * sizeof (unsigned long));
>>   r2 = r;
>>   for (i = 0; i < 528; i += 23)
>>     {
>>       lshift_com (r2, a,
>>                   i / (8 * sizeof (unsigned long)) + 1,
>>                   i % (8 * sizeof (unsigned long)));
> 
> Here the 4th argument is of type >= long since i is of type long.
> With calling via registers, this may not be an issue (here, the
> value would be correct), but if the data are passed on the stack,
> this will probably not work.
> 
>>       r2 += 88 + 1;
>>     }
>>   if (r[2048] != 0 || r[2049] != 0 || r[2050] != 0 || r[2051] != 0 ||
>>       r[2052] != 0 || r[2053] != 0 || r[2054] != 0)
>>     abort ();
>>   free (r);
>>   return 0;
>> }
> [...]
> 
> If you want an example about K&R function definition issues,
> consider
> 
> foo (a)
> {
> }
> 
> main ()
> {
>   foo (1, 2);
>   return 0;
> }
> 
> With GCC, this builds without any error.
> 


I have to figure out how libgmp was built by the ports process on
FreeBSD for this system because :

hydra$
hydra$ echo $CC
/usr/bin/gcc
hydra$ echo $CPPFLAGS
-D_TS_ERRNO -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE
hydra$
hydra$ CFLAGS='-m64 -g -fno-builtin -O0 -mcpu=970 -mno-altivec
-mfull-toc -mregnames -fno-unsafe-math-optimizations' ; export CFLAGS
hydra$
hydra$ $CC $CFLAGS $CPPFLAGS -I/usr/local/include -c -o f.o f.c
hydra$ $CC $CFLAGS $CPPFLAGS -Wl,-rpath=/usr/local/lib -L/usr/local/lib
-o f f.o -lgmp -lm
hydra$
hydra$ file f
f: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, Unspecified
or Power ELF V1 ABI, version 1 (FreeBSD), dynamically linked,
interpreter /libexec/ld-elf.so.1, FreeBSD-style, for FreeBSD 13.0
(1300036), with debug_info, not stripped
hydra$
hydra$ ldd f
f:
        libgmp.so.10 => /usr/local/lib/libgmp.so.10 (0x810066000)
        libm.so.5 => /lib/libm.so.5 (0x810102000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x810148000)
        libc.so.7 => /lib/libc.so.7 (0x81016c000)
hydra$
hydra$
hydra$ ./f 4
-------------------------------------------------------------
        system name = FreeBSD
          node name = hydra
            release = 13.0-CURRENT
            version = FreeBSD 13.0-CURRENT r350103 GENERIC
            machine = powerpc
-------------------------------------------------------------
             n       approx time in nanosecs
       ---------+----------------------------
         10000                 29219391 nsec
         20000                114556192 nsec
         30000                265402902 nsec
         40000                484338149 nsec
       --------------------------------------
hydra$

hydra$
hydra$ $CC $CFLAGS $CPPFLAGS -I/usr/local/include -c -o
mpfr_gmp_version.o mpfr_gmp_version.c
hydra$ $CC $CFLAGS $CPPFLAGS -Wl,-rpath=/usr/local/lib -L/usr/local/lib
-o mpfr_gmp_version mpfr_gmp_version.o -lgmp -lmpfr
hydra$
hydra$ ldd mpfr_gmp_version
mpfr_gmp_version:
        libgmp.so.10 => /usr/local/lib/libgmp.so.10 (0x810066000)
        libmpfr.so.6 => /usr/local/lib/libmpfr.so.6 (0x810102000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x81019f000)
        libc.so.7 => /lib/libc.so.7 (0x8101c3000)
hydra$
hydra$ ./mpfr_gmp_version
Compiler: GCC 4.2.1 20070831 patched [FreeBSD]
C/C++: __STDC__ = 1, __STDC_VERSION__ = undef
GNU compatibility: __GNUC__ = 4, __GNUC_MINOR__ = 2

GMP .....  Library: 6.1.2         Header: 6.1.2
MPFR ....  Library: 4.0.2         Header: 4.0.2 (based on 4.0.2)
MPFR features: TLS = yes, float128 = no, decimal = no, GMP internals = no
MPFR tuning: src/powerpc32/mparam.h
MPFR patches: [none]

__GMP_CC = "cc -std=gnu99"
__GMP_CFLAGS = "-O2 -pipe  -fstack-protector-strong -fno-strict-aliasing "
GMP_LIMB_BITS     = 64
GMP_NAIL_BITS     = 0
GMP_NUMB_BITS     = 64
mp_bits_per_limb  = 64
sizeof(mp_limb_t) = 8
The GMP library expects 64 bits in a mp_limb_t.

sizeof(mpfr_prec_t) = 8 (signed type)
sizeof(mpfr_exp_t)  = 8 (signed type)
_MPFR_PREC_FORMAT = 3
MPFR_PREC_MIN = 1 (signed)
MPFR_PREC_MAX = 9223372036854775551 (signed)
_MPFR_EXP_FORMAT = 3
sizeof(mpfr_t) = 32
sizeof(mpfr_ptr) = 8
hydra$

So this machine built the ports release package of libgmp just fine and
it works with those CFLAGS and that compiler.


hydra$
hydra$ pwd
/opt/bw/build/gmp-6.1.2_FreeBSD_13.0-CURRENT_r350103_ppc64.001
hydra$ ./configure ABI=mode64 --enable-cxx --prefix=/opt/bw 2>&1 | tee
../gmp-6.1.2_FreeBSD_13.0-CURRENT_r350103_ppc64.001.config.log2
checking build system type... powerpc64-unknown-freebsd13.0
checking host system type... powerpc64-unknown-freebsd13.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=mode64
checking compiler /usr/bin/gcc -m64 -g -fno-builtin -O0 -mcpu=970
-mno-altivec -mfull-toc -mregnames -fno-unsafe-math-optimizations
-D_TS_ERRNO -D_POSIX_PTHREAD_SEMANTICS -D_LARGEFILE64_SOURCE... no,
mpn_lshift_com optimization 2, program does not run
configure: error: could not find a working compiler, see config.log for
details
hydra$
hydra$ /usr/bin/gcc --version
gcc (GCC) 4.2.1 20070831 patched [FreeBSD]
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

hydra$

So I will dig around and see what is going on as I like to have debug
versions of these libs around so I can single step if desired.


-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
GreyBeard and suspenders optional


More information about the gmp-bugs mailing list