jsoftware / jsource

J engine source mirror
Other
645 stars 91 forks source link

Segfault in test suite g022.ijs for 903-release-b #134

Open leahneukirchen opened 2 years ago

leahneukirchen commented 2 years ago

On Void Linux x86_64 glibc (gcc (GCC) 10.2.1 20201203), updating J to 903 release b fails the test suite:

Starting program: /builddir/jsource-903-release-b/test/bin/j64/jconsole tsu.ijs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib64/libthread_db.so.1".
see: tsu_notes, tsu_usage, tsu_pacman, and tsu_jd

   RUN  ddall  NB. report scripts that fail
   RECHO ddall NB. echo script names as run and final count of failures

j903-b/j64/linux/release/GPL3/voidlinux.org/2022-04-10T12:35:50/gcc-10-2/SLEEF=1
   RECHO ddall
/builddir/jsource-903-release-b/test/g0.ijs
...
/builddir/jsource-903-release-b/test/g021s.ijs
/builddir/jsource-903-release-b/test/g022.ijs

Program received signal SIGSEGV, Segmentation fault.
(gdb) bt
#0  __emu_mm256_cmp_pd (param3=5, m256_param2=..., m256_param1=...)
    at ../../../../jsrc/avxintrin-emu.h:1108
#1  geDD (n=<optimized out>, m=6, x=0x5555555bbf48, y=0x5555557e8d08, 
    z=0x5555555c0448 "", jt=<optimized out>) at ../../../../jsrc/vcomp.c:194
#2  0x00007ffff74a8361 in jtva2 (jt=<optimized out>, a=a@entry=0x5555555bbf00, 
    w=w@entry=0x5555557e8cc0, self=self@entry=0x7ffff78e0a80 <primtab+5376>, 
    allranks=<optimized out>, allranks@entry=33685504)
    at ../../../../jsrc/va2.c:705
#3  0x00007ffff74a9756 in jtatomic2 (jt=0x555555570200, a=0x5555555bbf00, 
    w=0x5555557e8cc0, self=0x7ffff78e0a80 <primtab+5376>)
    at ../../../../jsrc/va2.c:1227
#4  0x00007ffff7450c3b in jtfitcteq (jt=0x555555570200, a=<optimized out>, 
    w=<optimized out>, self=<optimized out>) at ../../../../jsrc/cv.c:13
#5  0x00007ffff7421769 in fork200 (jt=jt@entry=0x555555570200, 
    a=a@entry=0x5555555bbf00, w=w@entry=0x5555557e8cc0, 
    self=self@entry=0x5555555ba600) at ../../../../jsrc/cf.c:23
#6  0x00007ffff7448089 in jtrank2ex0 (jt=<optimized out>, a=<optimized out>, 
    w=<optimized out>, fs=<optimized out>, f2=<optimized out>)
    at ../../../../jsrc/cr.c:516
#7  0x00007ffff7476a6d in jtparsea (jt=jt@entry=0x555555570200, 
    queue=<optimized out>, nwds=<optimized out>) at ../../../../jsrc/p.c:807
#8  0x00007ffff74540e7 in jtxdefn (jt=0x555555570200, a=<optimized out>, 
    w=<optimized out>, self=0x5555555c5800) at ../../../../jsrc/cx.c:430
#9  0x00007ffff7476a6d in jtparsea (jt=jt@entry=0x555555570200, 
    queue=<optimized out>, queue@entry=0x5555556aec00, nwds=nwds@entry=4)
    at ../../../../jsrc/p.c:807
#10 0x00007ffff747793c in jtparse (jt=jt@entry=0x555555570200, 
    w=<optimized out>) at ../../../../jsrc/p.c:293
#11 0x00007ffff7479f2d in jtimmex (jt=0x555555570200, jt@entry=0x555555570208, 
    w=<optimized out>) at ../../../../jsrc/px.c:52
#12 0x00007ffff7479fcd in jtimmea (jt=0x555555570200, jt@entry=0x555555570208, 
    w=<optimized out>) at ../../../../jsrc/px.c:61
#13 0x00007ffff785eca0 in jtline (jt=jt@entry=0x555555570200, 
    w=<optimized out>, w@entry=0x555555875900, si=<optimized out>, 
    si@entry=41, ce=ce@entry=3 '\003', tso=<optimized out>, tso@entry=0 '\000')
    at ../../../../jsrc/xs.c:82
#14 0x00007ffff785ee69 in jtline (tso=0 '\000', ce=3 '\003', si=41, 
    w=0x555555875900, jt=0x555555570200) at ../../../../jsrc/xs.c:124
#15 jtlinf (jt=0x555555570200, a=<optimized out>, w=<optimized out>, 
    ce=<optimized out>, tso=<optimized out>) at ../../../../jsrc/xs.c:124
#16 0x00007ffff740ea95 in on1cell (jt=0x555555570200, w=<optimized out>, 
    self=<optimized out>) at ../../../../jsrc/ca.c:80
#17 0x00007ffff740e9f4 in on1cell (jt=0x555555570200, jt@entry=0x555555570201, 
    w=0x7fffffffe281, w@entry=0x7fffffffe280, self=self@entry=0x5555557fdd40)
    at ../../../../jsrc/ca.c:80
#18 0x00007ffff7443229 in jtrank1ex0 (jt=<optimized out>, w=0x5555556a4440, 
    fs=<optimized out>, f1=<optimized out>) at ../../../../jsrc/cr.c:192
#19 0x00007ffff7484e0a in jtunquote (jt=0x555555570200, a=0x5555556a4440, 
    w=0x5555557ff040, self=<optimized out>) at ../../../../jsrc/sc.c:141
#20 0x00007ffff740e9f4 in on1cell (jt=0x555555570200, w=0x5555556a4441, 
    self=<optimized out>) at ../../../../jsrc/ca.c:80
#21 0x00007ffff7484e0a in jtunquote (jt=0x555555570200, a=0x5555556a4440, 
    w=0x5555557fd740, self=<optimized out>) at ../../../../jsrc/sc.c:141
#22 0x00007ffff7476a6d in jtparsea (jt=jt@entry=0x555555570200, 
    queue=<optimized out>, queue@entry=0x5555555b8dc0, nwds=nwds@entry=2)
    at ../../../../jsrc/p.c:807
#23 0x00007ffff747793c in jtparse (jt=jt@entry=0x555555570200, 
    w=<optimized out>) at ../../../../jsrc/p.c:293
#24 0x00007ffff7479f2d in jtimmex (jt=jt@entry=0x555555570200, 
    w=<optimized out>) at ../../../../jsrc/px.c:52
#25 0x00007ffff746b558 in jdo (jt=0x555555570000, lp=<optimized out>)
    at ../../../../jsrc/io.c:373
#26 0x00007ffff746b5c1 in JDo (jt=<optimized out>, lp=<optimized out>)
    at ../../../../jsrc/io.c:479
#27 0x000055555555677b in main (argc=<optimized out>, argv=<optimized out>)
    at ../../../../jsrc/jconsole.c:313

I'm not sure how to dump the offending line.

CPU is

processor       : 15
vendor_id       : AuthenticAMD
cpu family      : 23
model           : 113
model name      : AMD Ryzen 7 3700X 8-Core Processor
stepping        : 0
microcode       : 0x8701013
cpu MHz         : 2200.000
cache size      : 512 KB
physical id     : 0
siblings        : 16
core id         : 7
cpu cores       : 8
apicid          : 15
initial apicid  : 15
fpu             : yes
fpu_exception   : yes
cpuid level     : 16
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sme sev sev_es
bugs            : sysret_ss_attrs spectre_v1 spectre_v2 spec_store_bypass
bogomips        : 7199.25
TLB size        : 3072 4K pages
clflush size    : 64
cache_alignment : 64
address sizes   : 43 bits physical, 48 bits virtual
power management: ts ttp tm hwpstate cpb eff_freq_ro [13] [14]

There is also an error during build with -Werror:

../../../../jsrc/viavx.c: In function 'jtindexofsub':
cc1: warning: function may return address of local variable [-Wreturn-local-addr]
In file included from ../../../../jsrc/j.h:1814,
                 from ../../../../jsrc/viavx.c:8:
../../../../jsrc/viavx.c:1785:78: note: declared here
 1785 | A jtindexofsub(J jt,I mode,A a,A w){F2PREFIP;PROLOG(0079);A h=0;fauxblockINT(zfaux,1,0);
      |                                                                              ^~~~~

Which I had overriden to be ignored.

leahneukirchen commented 2 years ago

List of tests segfaulting:

g022.ijs
g110.ijs
g122.ijs
g221.ijs
g320ip.ijs
g3x.ijs
g422.ijs
g422os.ijs
g422sort.ijs
g432.ijs
gicap2.ijs
gqco.ijs
gspi.ijs

Reproducer:

      t1 =. 1&<.&.(0.05&+)&.> <@((?@$)&0)"1 (3+i.3) ,"0/ 1+i.50
      t2 =. 1&<.&.(0.05&+)&.> <@((?@$)&0)"1 $@> t1
      f =. 1 : 0
:
({."1&.> x) ((u f.)!.0"+"+ -: (u f.)!.0)&> y
)
      t1 >: f t2
leahneukirchen commented 2 years ago

Crashing functions for the first next few:

g110: ltDD
g122: i0eqDD0 __emu_mm256_cmp_pd
g221: jtsortdq sortdq1
leahneukirchen commented 2 years ago

Tests pass for the AVX1 version. The AVX2 version doesn't seem to start, even though my CPU should have AVX2? (but not AVX-512).

bilam commented 2 years ago

I suspect it ran into bus error in the function/macro __emu_mm256_cmp_pd probably misaligned access to sse registers. From your cpuinfo, there seems no avx2 flag so that avx2 version can't run.

You can try compile with -O0 or using clang. Only clang is officially supported for J source.

bilam commented 2 years ago

I tried on centos with gcc 8, it gave warnings. It is on your own to use gcc.

../../../../jsrc/avxintrin-emu.h: In function 'emu_mm256_maskload_pd': ../../../../jsrc/avxintrin-emu.h:1348:22: note: The ABI for passing parameters with 32-byte alignment has changed in GCC 4.6 emu_maskload_impl( emu_mm256_maskload_pd, emum256d, emum256i, double, emu_int64_t );

leahneukirchen commented 2 years ago

My cpu has avx and avx2 in /proc/cpuinfo flags, isn't that enough?

I'll check clang.

leahneukirchen commented 2 years ago

With clang 12.0.1, non-AVX test succeeds, but both AVX and AVX2 don't start now. :(

bilam commented 2 years ago

I believe the problem is your computer, try run on another computer or build again with debug.

leahneukirchen commented 2 years ago

For the record, j901f works fine. I don't think it's my computer, I use it to build all kinds of things and never had a problem...

The AVX versions also don't work on a Intel(R) Core(TM) i7-8550U CPU, which has AVX, AVX2 but no AVX-512.

bilam commented 2 years ago

I'm pretty sure avx and avx2 binaries are good. You can download binaries from our website. They are built on github.

moon-chilled commented 2 years ago

what happens if you add -falign-functions=4 to the cflags?

bilam commented 2 years ago

I don't think your suggestion would work. The issue is about abi.