Oops, I got that backwards.

It's __mp_alloc which gets the value from XLIMBLEN(x)

The __mp_size gets its value from XSGN(x).

Generally speaking __mp_alloc is always as least as large as the
absolute value of __mp_size.

__mp_alloc represents the total amount of memory allocated for digits
(the number of big digits, each of which occupies 8 bytes in 64 bit
systems).

__mp_size is the amount of memory actually used (and the sign of
__mp_size is the sign of the represented integer).

The digit sequence pointed to by __mp_d is unsigned.

Note also that __mp_size will be zero when representing the integer 0.
And, typically __mp_alloc would also be 0 for this case, though it
could be something larger.  If __mp_alloc is 0, that means that no
memory was allocated, libgmp tries to guarantee that __mp_d would have
a pointer that could be dereferenced without throwing a segmentation
fault even for this case. (And I believe that since we're always using
voidAV1 to supply the value for __mp_d that we're satisfying this
constraint.)

Anyways, sorry about the goof -- I should spelled out these details
also, in my previous message.

Thanks,


--
Raul

On Tue, Jan 31, 2023 at 12:15 PM Raul Miller <[email protected]> wrote:
>
> On Tue, Jan 31, 2023 at 12:02 PM bill lam <[email protected]> wrote:
> > I meant the string pointed by this voidAV1((x)
> > string in J literal arrays are not null-terminated.
>
> Oh...  I see what you're asking about.
>
> #define mpzXnojt(MPZ,x) mpz_t MPZ= {XLIMBLEN(x), XSGN((x)), voidAV1((x))}
>
> But we're not working with a literal array in that context. That macro
> only makes sense when x is an element of an array of type XNUM (or the
> numerator or denominator of an element of an array of type RAT).
>
> Here, we're initializing a value whose name is passed in the parameter
> MPZ and whose type will be mpz_t which is a one element array of a
> struct with three fields, and the three fields of this value are:
>    __mp_size
>    __mp_alloc
>    __mp_d
>
> Here, the __mp_size is initialized with XLIMBLEN(x), and the mp_d
> pointer is initialized with voidAV1(x) which is the starting memory
> address of sequence of "big digits" for the libgmp representation of
> the magnitude of the number.
>
> I hope this makes sense.
>
> I have tried to put descriptive comments into jgmp.h (and jgmpinit.h)
> describing this issue (and other issues) but I guess it's easy to
> overlook.
>
> Thanks,
>
> --
> Raul
>
> >
> >
> > On Wed, Feb 1, 2023 at 12:54 AM Raul Miller <[email protected]> wrote:
> >
>
> > > mpz_get_str in this context returns a null terminated string:
> > > https://gmplib.org/manual/Converting-Integers. And I'm passing in a
> > > null value for its first argument, so libgmp is figuring out how much
> > > memory we need to allocate.
> > >
> > > Anyways, s would always be null terminated.
> > >
> > > But the crash is happening inside of mpz_get_str, so that result can't
> > > be the problem -- we haven't gotten that far, yet.
> > >
> > > One thing I'm wondering, from the description, is if libgmp was
> > > compiled with avx support only or avx2 support, and whether that
> > > introduces any issues (such as the state of machine flags) in the
> > > handling of calling conventions. But I haven't figured out how to
> > > research this issue, yet.
> > >
> > > Thanks,
> > >
> > > --
> > > Raul
> > >
> > > On Tue, Jan 31, 2023 at 11:13 AM bill lam <[email protected]> wrote:
> > > >
> > > > Raul,
> > > >
> > > > From the backtrace below, I suspect something wrong in the parameter of
> > > > calling  __gmpz_get_str(..)
> > > > Have you checked voidAV1((x) is properly null terminated ?
> > > >
> > > > #define SgetX(Xy) ({\
> > > >  X Sy=Xy; mpX(Sy); C*s= jmpz_get_str(0,10,mpSy); \
> > > >  X tempx= UNvoidAV1(s); mpX(tempx); X safex= jtXmpzcommon(jt, mptempx,
> > > 0); \
> > > >  CAV1(safex);}) // ": y
> > > >
> > > > #define mpzXnojt(MPZ,x) mpz_t MPZ= {XLIMBLEN(x), XSGN((x)), 
> > > > voidAV1((x))}
> > > >
> > > >
> > > >
> > > >   x: 1000
> > > > JE has crashed, likely due to an internal bug.  Please report the code
> > > > which caused the crash, as well as the following printout, to the J
> > > > programming forum.
> > > > 00000000004030a2: ?:0:  sigsegv
> > > > 00007f84a7b2dd4f: ?:0:  ?
> > > > 00007f84a673ce2e: ?:0:  __gmpz_get_str
> > > > 00007f84a71b6c6a: ?:0:  jtthxqe
> > > > 00007f84a71b75be: ?:0:  jtthorn1main
> > > > 00007f84a71bb3bb: ?:0:  jtjprx
> > > > 00007f84a71bcf11: ?:0:  jtjpr1
> > > > 00007f84a71bcd9b: ?:0:  jtjpr
> > > > 00007f84a71db0d9: ?:0:  jtimmex
> > > > 00007f84a71c7a61: ?:0:  jdo
> > > > 00007f84a71c7813: ?:0:  JDo
> > > > 0000000000402f9f: ?:0:  main
> > > > 00007f84a7b1829c: ?:0:  __libc_start_main
> > > > 00000000004024ed: ?:0:  _start
> > > >
> > > > On Tue, Jan 31, 2023 at 10:30 PM Igor Zhuravlov <[email protected]>
> > > wrote:
> > > >
> > > > > Bill,
> > > > >
> > > > > you were right. libgmp.so from my desktop PC which passes all 3 tests,
> > > > > isn't stripped. Therefore, it cannot be from distro. May be, it's from
> > > > > previous version of j904_linux64.tar.gz . It's meta-data:
> > > > > - size: 614504 bytes
> > > > > - timestamp: 2022-12-15 09:17:56
> > > > > - GMP version: 6.2.1
> > > > >
> > > > > I've checked again all libgmp.so available on both PCs, and may
> > > conclude:
> > > > > 1) two libgmp 6.1.2 libs (from distro and built from gmplib.org
> > > tarball)
> > > > >    pass (x: 1000) test but crash with (+/ .*) and (-/ .*) tests;
> > > > > 2) two libgmp 6.2.1 libs bundled with J (from tarballs dated 
> > > > > 2022-12-15
> > > > >    and 2023-01-15) work fine with JE j904/j64avx2/linux and crash for
> > > > >    all 3 tests with JE j904/j64avx/linux;
> > > > > 3) libgmp 6.2.1 built from gmplib.org tarball works fine with JE
> > > > >    j904/j64avx/linux (on the same PC where it was built).
> > > > >
> > > > > Crash case (JE: j904/j64avx/linux, libgmp 6.2.1 bundled with J, 
> > > > > current
> > > > > tarball version):
> > > > >
> > > > > user@notebook:~/j904/bin> LANG=C ./jconsole
> > > > >    JVERSION
> > > > > Engine: j904/j64avx/linux
> > > > > Beta-j: commercial/2023-01-07T02:27:29
> > > > > Library: 9.04.11
> > > > > Platform: Linux 64
> > > > > Installer: J904 install
> > > > > InstallPath: /home/user/j904
> > > > > Contact: www.jsoftware.com
> > > > >    x: 1000
> > > > > JE has crashed, likely due to an internal bug.  Please report the code
> > > > > which caused the crash, as well as the following printout, to the J
> > > > > programming forum.
> > > > > 00000000004030a2: ?:0:  sigsegv
> > > > > 00007f84a7b2dd4f: ?:0:  ?
> > > > > 00007f84a673ce2e: ?:0:  __gmpz_get_str
> > > > > 00007f84a71b6c6a: ?:0:  jtthxqe
> > > > > 00007f84a71b75be: ?:0:  jtthorn1main
> > > > > 00007f84a71bb3bb: ?:0:  jtjprx
> > > > > 00007f84a71bcf11: ?:0:  jtjpr1
> > > > > 00007f84a71bcd9b: ?:0:  jtjpr
> > > > > 00007f84a71db0d9: ?:0:  jtimmex
> > > > > 00007f84a71c7a61: ?:0:  jdo
> > > > > 00007f84a71c7813: ?:0:  JDo
> > > > > 0000000000402f9f: ?:0:  main
> > > > > 00007f84a7b1829c: ?:0:  __libc_start_main
> > > > > 00000000004024ed: ?:0:  _start
> > > > > ffffffffffffffff: ?:0:  ?
> > > > >
> > > > >
> > > -----------------------------------------------------------------------------
> > > > > Aborted                 (core dumped)
> > > > >
> > > > > user@notebook:~/j904/bin> LANG=C ./jconsole.
> > > > >    (+/ .*)x: 4 4$_ __ 0 0 1 1 0 0 0 0 1 0 0 0 0 1
> > > > > JE has crashed, likely due to an internal bug.  Please report the code
> > > > > which caused the crash, as well as the following printout, to the J
> > > > > programming forum.
> > > > > 00000000004030a2: ?:0:  sigsegv
> > > > > 00007fc29f286d4f: ?:0:  ?
> > > > > 00007fc29e11cc3a: ?:0:  __gmpn_mul_1
> > > > >
> > > > >
> > > -----------------------------------------------------------------------------
> > > > > Aborted                 (core dumped)
> > > > >
> > > > > user@notebook:~/j904/bin> LANG=C ./jconsole.
> > > > >    (-/ .*)x: 4 4$_ __ 0 0 1 1 0 0 0 0 1 0 0 0 0 1
> > > > > JE has crashed, likely due to an internal bug.  Please report the code
> > > > > which caused the crash, as well as the following printout, to the J
> > > > > programming forum.
> > > > > 00000000004030a2: ?:0:  sigsegv
> > > > > 00007efd35339d4f: ?:0:  ?
> > > > > 00007efd341cfc3a: ?:0:  __gmpn_mul_1
> > > > >
> > > > >
> > > -----------------------------------------------------------------------------
> > > > > Aborted                 (core dumped)
> > > > >
> > > > > user@notebook:~/j904/bin> LANG=C ./jconsole.
> > > > >    load '~user/temp/gmp_ver.ijs'
> > > > >    gmp_version ''
> > > > > libgmp.so      569448 15-Jan-23 23:05:28
> > > > > 6.2.1
> > > > >    exit ''
> > > > >
> > > > > user@notebook:~/j904/bin> ./jconsole
> > > > >    fread < '~user/temp/gmp_ver.ijs'
> > > > > NB. nilad to get GMP version string
> > > > > NB. ver=. gmp_version ''
> > > > > gmp_version=: 3 : 0
> > > > >   dl=. '/usr/lib64/libdl.so'
> > > > >   g=. (jpath '~bin') , '/libgmp.so'
> > > > >   echo dir g
> > > > >   h=. 0 {:: (dl , ' dlopen * *c i') cd g ; 1  NB. lazy binding
> > > > >   assert 0 ~: h
> > > > >   p=. 0 {:: (dl , ' dlsym x x *c') cd h ; '__gmp_version'
> > > > >   assert 0 ~: p
> > > > >   c=. memr p , 0 1 4
> > > > >   assert 0 ~: c
> > > > >   ver=. memr c , 0 _1
> > > > > )
> > > > >
> > > > > --
> > > > > Regards,
> > > > > Igor
> > > > >
> > > > >
> > > > > On Tue, Jan 31, 2023 at 01:24 AM bill lam <[email protected]> wrote:
> > > > > > I found libgmp 6.1.2 crashed for those 2 lines, but libgmp 6.2.1 
> > > > > > that
> > > > > > bundled by J works fine.
> > > > > >
> > > > > > I think libgmp 6.1.2  is buggy but the bundled 6.2.1 can't be loaded
> > > on
> > > > > > your computers.
> > > > > >
> > > > > > If you linux distro can provide libgmp 6.2.1 ( or 6.2.0) you should
> > > > > update
> > > > > > to the newer version.
> > > > > >
> > > > > > Can you double check the version of libgmp after OS upgrade on your
> > > > > desktop
> > > > > > computer?
> > > > >
> > > > >
> > > > >
> > > > > ----------------------------------------------------------------------
> > > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > > > >
> > > > ----------------------------------------------------------------------
> > > > For information about J forums see http://www.jsoftware.com/forums.htm
> > > ----------------------------------------------------------------------
> > > For information about J forums see http://www.jsoftware.com/forums.htm
> > >
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to