https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118621

            Bug ID: 118621
           Summary: On PowerPC, taking address-of stack-allocated struct
                    variable gets 0xffffffffffffffff
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ej_zg at hotmail dot com
  Target Milestone: ---

Created attachment 60245
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=60245&action=edit
LINALG-pp-LU_det.i zipped, as uncompressed is 1.267MB

This happens on (in Debian terms): alpha powerpc ppc64. See at the bottom other
misbehaviour with the same code, where it gives numerically wrong results
instead of SEGV.

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/powerpc64-linux-gnu/14/lto-wrapper
Target: powerpc64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 14.2.0-14'
--with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,rust --prefix=/usr
--with-gcc-major-version-only --program-suffix=-14
--program-prefix=powerpc64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext 
--enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace
--enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support
--enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release 
--with-target-system-zlib=auto --with-libphobos-druntime-only=yes
--enable-objc-gc=auto --enable-secureplt --disable-softfloat
--enable-targets=powerpc64-linux,powerpc-linux --enable-multiarch
--disable-werror --with-long-double-128 --enable-multilib
--enable-checking=release --build=powerpc64-linux-gnu
--host=powerpc64-linux-gnu --target=powerpc64-linux-gnu
--with-build-config=bootstrap-lto-lean 
--enable-link-serialization=4
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Debian 14.2.0-14) 

The build command-line:
powerpc64-linux-gnu-gcc -c  -I. -I/usr/include
"-I/usr/lib/powerpc64-linux-gnu/perl5/5.40/PDL/Core" -D_REENTRANT -D_GNU_SOURCE
-DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O0
-Werror=implicit-function-declaration
-ffile-prefix-map=/home/sebastic/tmp/debian/libpdl-gsl-perl-2.101=.
-fstack-protector-strong -Wformat -Werror=format-security -Wdate-time  
-DVERSION=\"2.101\" -DXS_VERSION=\"2.101\" -fPIC
"-I/usr/lib/powerpc64-linux-gnu/perl/5.40/CORE"  
lib/PDL/GSL/LINALG-pp-LU_det.c -o lib/PDL/GSL/LINALG-pp-LU_det.o

There was no compiler output (errors, warnings, etc). The code works across
many other architectures, including amd64, arm64, s390x, hppa. See footnote at
the end for failures (non-SEGV-ing) on mips64el, sparc64.

I attach the *.i file - it's zipped because this form says max 1000KB, and it's
1267KB. Sorry.

When run (by t/gsl_linalg.t), it SEGVs, giving this gdb log - note that &m
became 0xffffffffffffffff, which is clearly wrong:
dpkg-buildpackage: info: binary and diff upload (original source NOT included)
$ gdb perl -ex 'run -Mblib t/gsl_linalg.t'
GNU gdb (Debian 16.1-1) 16.1
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "powerpc64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from perl...
Reading symbols from
/usr/lib/debug/.build-id/55/28ab0590d43e911804f39a805c4984b21d0473.debug...
Starting program: /usr/bin/perl -Mblib t/gsl_linalg.t
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/powerpc64-linux-gnu/libthread_db.so.1".
ok 1 - ndarrays are equal
ok 2 - ndarrays are equal
ok 3 - tridiag
ok 4 - ndarrays are equal

Program received signal SIGSEGV, Segmentation fault.
0x00003ffff6c5be20 in gsl_linalg_complex_LU_det (LU=0xffffffffffffffff,
signum=0) at luc.c:514
warning: 514    luc.c: No such file or directory
(gdb) bt full
#0  0x00003ffff6c5be20 in gsl_linalg_complex_LU_det (LU=0xffffffffffffffff,
signum=0) at luc.c:514
        i = <optimized out>
        n = <optimized out>
        det = <optimized out>
#1  0x00003ffff6f6936c in pdl_LU_det_readdata (__privtrans=0x1004900a0) at
lib/PDL/GSL/LINALG-pp-LU_det.c:120
        m = {size1 = 4, size2 = 4, tda = 4, data = 0x1004dfc50, block = 0x0,
owner = 0}
        z = 3.4766779035665179e-310 + 2.1242460109729937e-314i
        __tdims = 0x1004dfb20
        __tdims0 = 1
        __tdims1 = 1
        __offsp = 0x100486d50
        LU_datap = 0x1004dfc50
        signum_datap = 0x10048f5a0
        det_datap = 0x1004df610
        PDL_err = {error = PDL_ENONE, message = 0x0, needs_free = 0 '\000'}
        __brcloopval = 0
        __tind0 = 0
        __tind1 = 0
        __tnpdls = 0
        __tinc0_LU = 0
        __tinc0_signum = 0
        __tinc0_det = 0
        __tinc1_LU = 0
        __tinc1_signum = 0
        __tinc1_det = 0
        __inc_LU_n = <optimized out>
        __inc_LU_m = <optimized out>
#2  0x00003ffff7a15fb4 in pdl__ensure_trans (trans=trans@entry=0x1004900a0,
what=what@entry=4, inputs_only=inputs_only@entry=0 '\000',
recurse_count=recurse_count@entry=0) at lib/PDL/Core/pdlapi.c:109
        PDL_err_local = {error = PDL_ENONE, message = 0x0, needs_free = 0
'\000'}
        vtable = 0x3ffff6f80388 <pdl_LU_det_vtable>
        i = <optimized out>
        istart = 2
        iend = 3
        PDL_err = <optimized out>
        vtable = 0x3ffff6f80388 <pdl_LU_det_vtable>
        j = <optimized out>
        flag = <optimized out>
        par_pvaf = <optimized out>
        j_end = <optimized out>
#3  0x00003ffff7a19474 in pdl_make_trans_mutual (trans=0x1004900a0) at
lib/PDL/Core/pdlapi.c:764
        PDL_err_local = {error = PDL_EUSERERROR, message = 0x101097f68 "",
needs_free = 0 '\000'}
        PDL_err = {error = PDL_ENONE, message = <optimized out>, needs_free =
<optimized out>}
        vtable = 0x3ffff6f80388 <pdl_LU_det_vtable>
        pdls = <optimized out>
        i = 3
        npdls = <optimized out>
        nparents = <optimized out>
        nchildren = <optimized out>
        disable_back = <optimized out>
        dataflow = 0 '\000'
        wasnull = <optimized out>
#4  0x00003ffff6f6988c in pdl_run_LU_det (LU=0x100515dd0, signum=0x10048f410,
det=0x1004df480) at lib/PDL/GSL/LINALG-pp-LU_det.c:166
        PDL_err = {error = PDL_ENONE, message = 0x0, needs_free = 0 '\000'}
        __privtrans = 0x1004900a0
        badflag_cache = 0 '\000'
#5  0x00003ffff6f646d4 in XS_PDL_LU_det (my_perl=0x10045a2a0, cv=0x101097f68)
at lib/PDL/GSL/LINALG.xs:111
        bless_stash = 0x100c3bd10
        parent = 0x101083b30
        det = 0x1004df480
        RETVAL = {error = PDL_EUSERERROR, message = 0x2802284400000000 <error:
Cannot access memory at address 0x2802284400000000>, needs_free = 0 '\000'}
        det_SV = 0x101096238
        objname = 0x100be5b90 "PDL"
        nreturn = 1
        LU = 0x100515dd0
        signum = 0x10048f410
        sp = 0x10045fe60
        ax = 1
        mark = 0x10045fe60
        items = 2
#6  0x0000000100151f1c in Perl_rpp_invoke_xs (my_perl=0x10045a2a0,
cv=<optimized out>) at inline.h:1193
No locals.
#7  Perl_pp_entersub (my_perl=0x10045a2a0) at pp_hot.c:6495
        markix = 0
        is_scalar = false
        gv = 0x1001462fc <Perl_pp_nextstate+140>
        cv = <optimized out>
        cx = <optimized out>
        old_savestack_ix = <optimized out>
        sv = 0x101083b18
        do_ref = <optimized out>
        p_ = <optimized out>
        p_ = <optimized out>
        p_ = <optimized out>
        p_ = <optimized out>
#8  0x00000001001eeb5c in Perl_runops_standard (my_perl=0x10045a2a0) at
run.c:41
        op = <optimized out>
#9  0x0000000100097f54 in S_run_body (my_perl=<optimized out>,
oldscope=<optimized out>) at perl.c:2860
No locals.
#10 perl_run (my_perl=0x10045a2a0) at perl.c:2780
        oldscope = 1
        ret = <optimized out>
        cur_env = {je_prev = 0x10045a5b0, je_buf = {{__jmpbuf =
{3835103292886016385, 4299521792, 3835160186928002545, 0, 0, 0, 0, 0, 0, 0, 0,
0, 70368609951744, 70368609942384, 4299433704, 70368744174408, 3,
70368744174576,
                70368744174376, 1, 4299530912, -3690978264, 0 <repeats 42
times>}, __mask_was_saved = 0, __saved_mask = {__val = {4299528576, 4521984,
4299530912, 70368744173040, 69059281371852151, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                  70368609951744, 70368609942384}}}}, je_ret = 3, je_mustcatch
= false, je_old_delaymagic = 0, je_old_stack_hwm = 3}
        p_ = <optimized out>
#11 0x0000000100060ac0 in main (argc=<optimized out>, argv=<optimized out>,
env=<optimized out>) at perlmain.c:127
        exitstatus = <optimized out>
        i = <optimized out>


Footnote: the test fails without SEGV on two other architectures, which might
shed light:

mips64el:
#   Failed test 'ndarrays are equal'
#   at t/gsl_linalg.t line 38.
#     1/1 values do not match
#          got: CDouble  D []         (P    ) -0.07329228-0.07329228i
#     expected: CDouble  D []         (P    ) -0.07329228-8.64040000000001e-11i

sparc64:
#   Failed test 'ndarrays are equal'
#   at t/gsl_linalg.t line 38.
#     1/1 values do not match
#          got: CDouble  D []         (P    ) 0
#     expected: CDouble  D []         (P    ) -0.07329228-8.64040000000001e-11i

Reply via email to