Skip to content

Regression on powerpc: segfault on evaluating JS code #1122

Closed

Description

@barracuda156

@bnoordhuis @saghul @bellard I will try to dig into this myself too, but if you got any idea, it would be very helpful.

Original ticket about the issue is here: andrjohns/QuickJSR#88
But the bug is in quickjs-ng itself, as it appears, not in its R port or my R build environment.

Specifically, this example fails both with 0.10.x and 0.9.0:

wget https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js
./qjs --include ./stanc.js 
qjs > stanc("model_name","data{}")

0.10.x crashes already on the first command:

Starting program: /opt/local/bin/qjs --include ./stanc.js
Reading symbols for shared libraries +++. done

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x03000300
0x03000300 in ?? ()
(gdb) bt
#0  0x03000300 in ?? ()
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
#1  0x000228b8 in JS_RunGC ()
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
Cannot access memory at address 0x3000300
#2  0x00025200 in JS_NewObjectFromShape ()
Cannot access memory at address 0x3000300
#3  0x00026d5c in JS_NewArrayFrom ()
#4  0x00014b40 in JS_CallInternal ()
#5  0x0001494c in JS_CallInternal ()
#6  0x0001494c in JS_CallInternal ()
#7  0x0001494c in JS_CallInternal ()
#8  0x0001494c in JS_CallInternal ()
#9  0x0001494c in JS_CallInternal ()
#10 0x0001494c in JS_CallInternal ()
#11 0x00019660 in JS_CallFree ()
#12 0x0006d03c in __JS_EvalInternal ()
#13 0x00040224 in JS_EvalThis2 ()
#14 0x000402ac in JS_Eval ()
#15 0x00003468 in eval_buf ()
#16 0x00003500 in eval_file ()
#17 0x00079b18 in main ()

0.9.0 handles the first command, but segfaults on the second:

$ qjs --include ./stanc.js
QuickJS-ng - Type ".help" for help
qjs >  stanc("model_name","data{}")
Segmentation fault

For comparison, quickjs (non-ng one, 2025.04.05) works normally:

$ qjs --include ./stanc.js
QuickJS - Type "\h" for help
qjs > stanc("model_name","data{}")
{ result: "// Code generated by stanc v2.37.0-rc2-20-g216cb27\n#include <stan/model/m...", warnings: [  ] }
qjs > 

And a build from May:

--->  Activating quickjs-devel @20250520_0
Sergey-Fedorovs-Mac:~ svacchanda\$ qjs --include ./stanc.js
QuickJS - Type "\h" for help
qjs > stanc("model_name","data{}")
{ result: "// Code generated by stanc v2.37.0-rc2-20-g216cb27\n#include <stan/model/model_header.hpp>\nnamespace model_name_namespace {\nusing stan::model::model_base_crtp;\nusing namespace stan::math;\nstan::math::profile_map profiles__;\nstatic constexpr std::array<const char*, 1> locations_array__ =\n  {\" (found before start of program)\"};\nclass model_name final : public model_base_crtp<model_name> {\n private:\n  \n public:\n  ~model_name() {}\n  model_name(stan::io::var_context& context__, unsigned int\n             random_seed__ = 0, std::ostream* pstream__ = nullptr)\n      : model_base_crtp(0) {\n    int current_statement__ = 0;\n    // suppress unused var warning\n    (void) current_statement__;\n    using local_scalar_t__ = double;\n    auto base_rng__ = stan::services::util::create_rng(random_seed__, 0);\n    // suppress unused var warning\n    (void) base_rng__;\n    static constexpr const char* function__ =\n      \"model_name_namespace::model_name\";\n    // suppress unused var warning\n    (void) function__;"... 11809 more characters, warnings: [  ] }
qjs > 

Activity

  1. barracuda156 commented on Jul 16, 2025

    @barracuda156
    ContributorAuthor

    The first crash is fixed in the PR. This is the second:

    Starting program: /opt/local/bin/qjs --include ./stanc.js
    Reading symbols for shared libraries +++. done
    QuickJS-ng - Type ".help" for help
    qjs > stanc("model_name","data{}")
    
    Program received signal EXC_BAD_ACCESS, Could not access memory.
    Reason: KERN_INVALID_ADDRESS at address: 0x062da041
    lre_exec_backtrack (s=0xbfffa4d8, capture=0x267ab0, stack=0xbfffa4c0, stack_len=0, pc=0x62da042 <Address 0x62da042 out of bounds>, cptr=0x1040674 "result", no_recurse=false) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/libregexp.c:2071
    2071            opcode = *pc++;
    (gdb) bt
    #0  lre_exec_backtrack (s=0xbfffa4d8, capture=0x267ab0, stack=0xbfffa4c0, stack_len=0, pc=0x62da042 <Address 0x62da042 out of bounds>, cptr=0x1040674 "result", no_recurse=false) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/libregexp.c:2071
    #1  0x00010764 in lre_exec (capture=0x267ab0, bc_buf=0x2da034 "", cbuf=0x1040674 "result", cindex=0, clen=6, cbuf_type=0, opaque=0x2022d0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/libregexp.c:2510
    #2  0x000a6058 in js_regexp_exec (ctx=0x2022d0, this_val=18446744069477889872, argc=1, argv=0xbfffb1a0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:45554
    #3  0x000491ac in js_call_c_function (ctx=0x2022d0, func_obj=18446744069417380416, this_obj=18446744069477889872, argc=1, argv=0xbfffb1a0, flags=2) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16270
    #4  0x00049b00 in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069417380416, this_obj=18446744069477889872, new_target=12884901888, argc=1, argv=0xbfffb1a0, flags=2) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16485
    #5  0x00054dec in JS_CallFree (ctx=0x2022d0, func_obj=18446744069417380416, this_obj=18446744069477889872, argc=1, argv=0xbfffb1a0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:18948
    #6  0x000a6e5c in JS_RegExpExec (ctx=0x2022d0, r=18446744069477889872, s=18446744043661821536) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:45817
    #7  0x000a71bc in js_regexp_Symbol_match (ctx=0x2022d0, this_val=18446744069477889872, argc=1, argv=0xbfffbe08) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:45875
    #8  0x000491ac in js_call_c_function (ctx=0x2022d0, func_obj=18446744069477890304, this_obj=18446744069477889872, argc=1, argv=0xbfffbe08, flags=2) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16270
    #9  0x00049b00 in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069477890304, this_obj=18446744069477889872, new_target=12884901888, argc=1, argv=0xbfffbe08, flags=2) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16485
    #10 0x00054dec in JS_CallFree (ctx=0x2022d0, func_obj=18446744069477890304, this_obj=18446744069477889872, argc=1, argv=0xbfffbe08) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:18948
    #11 0x0009f484 in js_string_match (ctx=0x2022d0, this_val=18446744043661821536, argc=1, argv=0xbfffc9f0, atom=214) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:43545
    #12 0x00049214 in js_call_c_function (ctx=0x2022d0, func_obj=18446744069477113520, this_obj=18446744043661821536, argc=1, argv=0xbfffc9f0, flags=0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16283
    #13 0x00049b00 in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069477113520, this_obj=18446744043661821536, new_target=12884901888, argc=1, argv=0xbfffc9f0, flags=0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16485
    #14 0x0004bbf0 in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069457735072, this_obj=12884901888, new_target=12884901888, argc=2, argv=0xbfffd4d8, flags=0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16903
    #15 0x0004b8ec in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069457620384, this_obj=18446744069457620320, new_target=12884901888, argc=2, argv=0xbfffdef0, flags=0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16866
    #16 0x0004bbf0 in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069473179584, this_obj=12884901888, new_target=12884901888, argc=1, argv=0xbfffe8f0, flags=0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16903
    #17 0x0004b8ec in JS_CallInternal (caller_ctx=0x2022d0, func_obj=18446744069473224496, this_obj=12884901888, new_target=12884901888, argc=1, argv=0xbffff350, flags=2) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:16866
    #18 0x00054d64 in JS_Call (ctx=0x2022d0, func_obj=18446744069473224496, this_obj=12884901888, argc=1, argv=0xbffff350) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:18941
    #19 0x000b63c4 in promise_reaction_job (ctx=0x2022d0, argc=5, argv=0x23d064) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:50198
    #20 0x000197b0 in JS_ExecutePendingJob (rt=0x200190, pctx=0xbffff434) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs.c:2008
    #21 0x000e1b94 in js_std_loop (ctx=0x2022d0) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/quickjs-libc.c:4351
    #22 0x00004330 in main (argc=3, argv=0xbffffb50) at /opt/local/var/macports/build/quicrPPK1p/work/quickjs-0.10.1/qjs.c:701
    

    Any idea what causes it?

  2. barracuda156 commented on Jul 16, 2025

    @barracuda156
    ContributorAuthor

    I give up on this for now, it is problematic to bisect, since the issue is old, at least 0.8.0 exhibits the same behavior, but 0.7.0 does not build at all.

    It is probably issue with structs sizes, several of which differ between quickjs vs quickjs-ng, but there is no easy way to adjust those, it seems.

    FWIW, rebuilding with -mone-byte-bool does not solve the second crash, but pc address differs in that case.

  3. past-due commented on Jul 16, 2025

    @past-due
    Contributor
  4. barracuda156 commented on Jul 16, 2025

    @barracuda156
    ContributorAuthor

    @past-due Thank you, I will try it once back to the hardware.

  5. bnoordhuis commented on Jul 16, 2025

    @bnoordhuis
    Contributor

    When I run it locally with tip of master on x86_64, I don't get a crash; I get this (coming from stanc.js itself, it catches and converts the stack overflow RangeError):

    qjs > stanc("model_name","data{}")
    {
      errors: [
        0,
        'Internal compiler error:\nStack overflow\n\n\nThis should never happen. Please fil...'
      ],
      warnings: []
    }
    

    We don't have ppc-specific code but maybe it's a stack limit thing? What happens when you pass --stack-size <n> to qjs and play around with different values of n? n is in kilobytes.

  6. barracuda156 commented on Jul 18, 2025

    @barracuda156
    ContributorAuthor

    @bnoordhuis Unfortunately, stack-size does not seem to have impact here.

    @past-due Changing those two bools either to int or to uint8_t breaks the binary (it crashes on launch itself, like originally).

  7. bnoordhuis commented on Jul 18, 2025

    @bnoordhuis
    Contributor

    What happens when you revert to commit 8bcc070? That's the commit preceding the stdbool change.

  8. barracuda156 commented on Jul 18, 2025

    @barracuda156
    ContributorAuthor

    @bnoordhuis I will try.

    Besides, looks like this second crash is unrelated to size of bool or bitness. I have just tried on ppc64 and got the same segfault (on ppc64 bool is standard).

  9. bnoordhuis commented on Mar 15, 2026

    @bnoordhuis
    Contributor

    @barracuda156 is this still an issue? I'm guessing 'no' since it's been almost a year but I thought I'd ask anyway.

  10. barracuda156 commented on Mar 16, 2026

    @barracuda156
    ContributorAuthor

    @bnoordhuis Sorry, I will test with the current version and update soon. It got postponed since with Rstan it seems not to cause troubles so far (R package builds are done regularly). Which in itself does not guarantee issue does not exist, of course.

  11. barracuda156 commented on Mar 19, 2026

    @barracuda156
    ContributorAuthor

    Unfortunately, 0.12.1 still exhibits the issue:

    $ wget https://github.com/stan-dev/stanc3/releases/download/nightly/stanc.js
    Saving to: ‘stanc.js’
    
    stanc.js            100%[===================>]   3.13M   995KB/s    in 3.2s    
    
    2026-03-19 13:03:09 (995 KB/s) - ‘stanc.js’ saved [3281272/3281272]
    
    $ qjs --include ./stanc.js
    QuickJS-ng - Type ".help" for help
    qjs > stanc("model_name","data{}")
    Segmentation fault
    
  12. barracuda156 commented on Mar 19, 2026

    @barracuda156
    ContributorAuthor

    Looks like on the same spot:

    (gdb) run
    Starting program: /opt/local/bin/qjs --include ./stanc.js
    Reading symbols for shared libraries +++. done
    QuickJS-ng - Type ".help" for help
    qjs > stanc("model_name","data{}")
    
    Program received signal EXC_BAD_ACCESS, Could not access memory.
    Reason: KERN_INVALID_ADDRESS at address: 0x061d2e31
    0x00005b64 in lre_exec_backtrack ()
    (gdb) bt
    #0  0x00005b64 in lre_exec_backtrack ()
    #1  0x00008fe8 in lre_exec ()
    #2  0x000594ac in js_regexp_exec ()
    #3  0x0004ad50 in js_call_c_function ()
    #4  0x00016550 in JS_CallInternal ()
    #5  0x0001c390 in JS_CallFree ()
    #6  0x0006799c in JS_RegExpExec ()
    #7  0x00067ee4 in js_regexp_Symbol_match ()
    #8  0x0004ad50 in js_call_c_function ()
    #9  0x00016550 in JS_CallInternal ()
    #10 0x0001c390 in JS_CallFree ()
    #11 0x0006fbd0 in js_string_match ()
    #12 0x0004ad8c in js_call_c_function ()
    #13 0x00016550 in JS_CallInternal ()
    #14 0x000176e0 in JS_CallInternal ()
    #15 0x00017578 in JS_CallInternal ()
    #16 0x000176e0 in JS_CallInternal ()
    #17 0x00017578 in JS_CallInternal ()
    #18 0x0001c2c0 in JS_Call ()
    #19 0x000212b4 in promise_reaction_job ()
    #20 0x00020d80 in JS_ExecutePendingJob ()
    #21 0x0007da3c in js_std_loop ()
    #22 0x0007fbf4 in main ()
    (gdb) disassemble
    Dump of assembler code for function lre_exec_backtrack:
    0x00005b20 <lre_exec_backtrack+0>:	mfcr    r12
    0x00005b24 <lre_exec_backtrack+4>:	mflr    r0
    0x00005b28 <lre_exec_backtrack+8>:	stmw    r15,-68(r1)
    0x00005b2c <lre_exec_backtrack+12>:	bcl-    20,4*cr7+so,0x5b30 <lre_exec_backtrack+16>
    0x00005b30 <lre_exec_backtrack+16>:	stw     r0,8(r1)
    0x00005b34 <lre_exec_backtrack+20>:	mflr    r31
    0x00005b38 <lre_exec_backtrack+24>:	stw     r12,4(r1)
    0x00005b3c <lre_exec_backtrack+28>:	mr      r27,r3
    0x00005b40 <lre_exec_backtrack+32>:	stwu    r1,-144(r1)
    0x00005b44 <lre_exec_backtrack+36>:	mr      r22,r4
    0x00005b48 <lre_exec_backtrack+40>:	lwz     r26,8(r3)
    0x00005b4c <lre_exec_backtrack+44>:	mr      r21,r5
    0x00005b50 <lre_exec_backtrack+48>:	lwz     r23,4(r3)
    0x00005b54 <lre_exec_backtrack+52>:	mr      r25,r6
    0x00005b58 <lre_exec_backtrack+56>:	mr      r29,r7
    0x00005b5c <lre_exec_backtrack+60>:	mr      r30,r8
    0x00005b60 <lre_exec_backtrack+64>:	mr      r20,r9
    0x00005b64 <lre_exec_backtrack+68>:	lbz     r2,0(r29)
    0x00005b68 <lre_exec_backtrack+72>:	addi    r28,r29,1
    0x00005b6c <lre_exec_backtrack+76>:	clrlwi  r24,r2,24
    0x00005b70 <lre_exec_backtrack+80>:	addi    r2,r2,-1
    0x00005b74 <lre_exec_backtrack+84>:	clrlwi  r2,r2,24
    0x00005b78 <lre_exec_backtrack+88>:	cmplwi  r2,28
    0x00005b7c <lre_exec_backtrack+92>:	bgt-    0x6784 <lre_exec_backtrack+3172>
    0x00005b80 <lre_exec_backtrack+96>:	addis   r9,r31,0
    0x00005b84 <lre_exec_backtrack+100>:	rlwinm  r2,r2,2,0,29
    0x00005b88 <lre_exec_backtrack+104>:	addi    r9,r9,108
    0x00005b8c <lre_exec_backtrack+108>:	lwzx    r2,r9,r2
    0x00005b90 <lre_exec_backtrack+112>:	add     r2,r2,r9
    0x00005b94 <lre_exec_backtrack+116>:	mtctr   r2
    0x00005b98 <lre_exec_backtrack+120>:	bctr
    0x00005b9c <lre_exec_backtrack+124>:	.long 0x294
    0x00005ba0 <lre_exec_backtrack+128>:	.long 0x288
    0x00005ba4 <lre_exec_backtrack+132>:	.long 0x244
    0x00005ba8 <lre_exec_backtrack+136>:	.long 0x444
    0x00005bac <lre_exec_backtrack+140>:	.long 0x4b8
    0x00005bb0 <lre_exec_backtrack+144>:	.long 0x36c
    0x00005bb4 <lre_exec_backtrack+148>:	.long 0x3e4
    0x00005bb8 <lre_exec_backtrack+152>:	.long 0x34c
    0x00005bbc <lre_exec_backtrack+156>:	.long 0x2e0
    0x00005bc0 <lre_exec_backtrack+160>:	.long 0x2e0
    0x00005bc4 <lre_exec_backtrack+164>:	.long 0x74
    0x00005bc8 <lre_exec_backtrack+168>:	.long 0x514
    0x00005bcc <lre_exec_backtrack+172>:	.long 0x514
    0x00005bd0 <lre_exec_backtrack+176>:	.long 0x538
    0x00005bd4 <lre_exec_backtrack+180>:	.long 0x5a4
    0x00005bd8 <lre_exec_backtrack+184>:	.long 0x584
    0x00005bdc <lre_exec_backtrack+188>:	.long 0x59c
    0x00005be0 <lre_exec_backtrack+192>:	.long 0x5f0
    0x00005be4 <lre_exec_backtrack+196>:	.long 0x5f0
    0x00005be8 <lre_exec_backtrack+200>:	.long 0x6cc
    0x00005bec <lre_exec_backtrack+204>:	.long 0x6cc
    0x00005bf0 <lre_exec_backtrack+208>:	.long 0x8e4
    0x00005bf4 <lre_exec_backtrack+212>:	.long 0x9e8
    0x00005bf8 <lre_exec_backtrack+216>:	.long 0x330
    0x00005bfc <lre_exec_backtrack+220>:	.long 0x330
    0x00005c00 <lre_exec_backtrack+224>:	.long 0x5d0
    0x00005c04 <lre_exec_backtrack+228>:	.long 0x5dc
    0x00005c08 <lre_exec_backtrack+232>:	.long 0xad0
    0x00005c0c <lre_exec_backtrack+236>:	.long 0xb28
    0x00005c10 <lre_exec_backtrack+240>:	cmpwi   r20,0
    0x00005c14 <lre_exec_backtrack+244>:	bne-    0x5c34 <lre_exec_backtrack+276>
    0x00005c18 <lre_exec_backtrack+248>:	li      r24,1
    0x00005c1c <lre_exec_backtrack+252>:	mr      r3,r27
    0x00005c20 <lre_exec_backtrack+256>:	bl      0x5938 <lre_poll_timeout>
    0x00005c24 <lre_exec_backtrack+260>:	cmpwi   r3,0
    0x00005c28 <lre_exec_backtrack+264>:	beq+    0x5c50 <lre_exec_backtrack+304>
    0x00005c2c <lre_exec_backtrack+268>:	li      r24,-2
    0x00005c30 <lre_exec_backtrack+272>:	b       0x5c38 <lre_exec_backtrack+280>
    0x00005c34 <lre_exec_backtrack+276>:	mr      r24,r30
    0x00005c38 <lre_exec_backtrack+280>:	addi    r1,r1,144
    0x00005c3c <lre_exec_backtrack+284>:	mr      r3,r24
    0x00005c40 <lre_exec_backtrack+288>:	lwz     r12,4(r1)
    0x00005c44 <lre_exec_backtrack+292>:	mr      r11,r1
    0x00005c48 <lre_exec_backtrack+296>:	mtcrf   24,r12
    0x00005c4c <lre_exec_backtrack+300>:	b       0x7efcc <restGPRx+8>
    0x00005c50 <lre_exec_backtrack+304>:	lwz     r2,52(r27)
    0x00005c54 <lre_exec_backtrack+308>:	cmpwi   r2,0
    0x00005c58 <lre_exec_backtrack+312>:	beq-    0x5c38 <lre_exec_backtrack+280>
    
  13. barracuda156 commented on Mar 19, 2026

    @barracuda156
    ContributorAuthor

    And quickjs (non-ng) works from the latest commit, as earlier:

    $ qjs --include ./stanc.js
    QuickJS - Type "\h" for help
    qjs > stanc("model_name","data{}")
    { result: "// Code generated by stanc v2.38.0-85-g582ade1\n#include <stan/model/model_header.hpp>\nnamespace model_name_namespace {\nusing stan::model::model_base_crtp;\nusing namespace stan::math;\nstan::math::profile_map profiles__;\nstatic constexpr std::array<const char*, 1> locations_array__ =\n  {\" (found before start of program)\"};\nclass model_name final : public model_base_crtp<model_name> {\n private:\n  \n public:\n  ~model_name() {}\n  model_name(stan::io::var_context& context__, unsigned int\n             random_seed__ = 0, std::ostream* pstream__ = nullptr)\n      : model_base_crtp(0) {\n    int current_statement__ = 0;\n    // suppress unused var warning\n    (void) current_statement__;\n    using local_scalar_t__ = double;\n    auto base_rng__ = stan::services::util::create_rng(random_seed__, 0);\n    // suppress unused var warning\n    (void) base_rng__;\n    static constexpr const char* function__ =\n      \"model_name_namespace::model_name\";\n    // suppress unused var warning\n    (void) function__;\n   "... 11807 more characters, warnings: [  ] }
    
  14. bnoordhuis commented on Mar 19, 2026

    @bnoordhuis
    Contributor

    Thanks for testing. Does a debug build (one with source line info) point to any particular line in lre_exec_backtrack?

    edit: and this is on ppc32, not ppc64, right?

  15. bnoordhuis commented on Mar 19, 2026

    @bnoordhuis
    Contributor

    I've been somewhat able to reproduce the crash (or at least: a crash) but I don't have a ppc32-capable gdb at hand so it's tricky to debug.

    I do observe that simply entering > stanc (no function call, just the name) is enough to trigger a segfault, but only inside the REPL. qjs --include stanc.js -e 'print(stanc)' works okay.

  16. saghul commented on Mar 19, 2026

    @saghul
    Contributor

    @bnoordhuis I had Claude take a look earlier today, but I haven't had the time to double check its output yet.

    It found the same with the REPL, and apparently there might be a bug in our byteswapping logic for BE systems.

    I can make a WIP PR if you like?

  17. bnoordhuis commented on Mar 19, 2026

    @bnoordhuis
    Contributor

    Hah, I managed to track it down to byteswapping right at the moment you posted that comment. :-)

  18. saghul commented on Mar 19, 2026

    @saghul
    Contributor

    :-) In case it helps, it found 2 bugs: #1410

  19. added a commit that references this issue on Mar 19, 2026
  20. bnoordhuis commented on Mar 19, 2026

    @bnoordhuis
    Contributor

    @barracuda156 Saúl and I decided to simply rip out the byte-swap logic (#1412) so that means big endian will effectively be unsupported going forward.

    I think it should still be possible to get a working build but you'll have to compile on the target machine itself (cross-compiling won't work) and you're going to need to regenerate all the pre-compiled bytecode with make codegen.

  21. added a commit that references this issue on Mar 19, 2026
  22. barracuda156 commented on Mar 20, 2026

    @barracuda156
    ContributorAuthor

    @bnoordhuis Can we not just break BE support? There are people using BE systems, which are not limited to old macOS, of course. Power CPU are bi-endian, s390x are strictly big-endian, Amiga systems and upcoming (hopefully) PowerPC Linux notebook use big-endian ppc CPUs.
    There is third-party software relying on quickjs, and in some cases specifically quickjs-ng (Rstan, elinks browser).

    Please, reconsider this. Byte-swapping is a fixable issue.

  23. saghul commented on Mar 20, 2026

    @saghul
    Contributor

    From a purely utilitarian prespective, if nobody thought this was important enough to fix since July last year, maybe it's simply not important enough to fix.

    Native Big Endian builds should still work, is that something you can test?

    Byte-swapping is a fixable issue.

    Fixing is one thing, maintaining it ad eternum is another...

  24. barracuda156 commented on Mar 20, 2026

    @barracuda156
    ContributorAuthor

    From a purely utilitarian prespective, if nobody thought this was important enough to fix since July last year, maybe it's simply not important enough to fix.

    @saghul Well, it was not a pressing issue because it did not seem to affect my use-cases (which is largely Rstan; elinks switched to quickjs-ng just recently, I have not updated the port yet). I did try to fix it a few times, but failed. Last time with Claude, which found one of the issues you fixed in your [closed, sadly] PR, but that did not fix this specific test case.

    Native Big Endian builds should still work, is that something you can test?

    I only do native builds, it is easier than cross-compiling. I do not care about cross-compilation support personally, but native builds are important. Rstan does not use external quickjs-ng (and some other ports which embed it), so broken big-endian will be a painful situation.

    You know I care about this at least from the fact that I found and fixed the first bug with bool.

  25. saghul commented on Mar 20, 2026

    @saghul
    Contributor

    If you do native builds then make codegen && make should produce a working binary.

  26. barracuda156 commented on Mar 20, 2026

    @barracuda156
    ContributorAuthor

    Ok, I will look into that. What to do about third-party apps that bundle quickjs-ng or otherwise incorporate its code?

    P. S. If I test your PR and it is confirmed to fix the bug here, can we consider restoring BE support plus merging your PR? It goes without saying that it does not imply any commitment to keep BE support no matter what; there may be a reason to drop it at some point, but if it is not that point yet (as a matter of fact, even with this bug unfixed, it was working just fine on BE in most cases), there is no real need to drop it right now at least. TBH I also feel bad to be a trigger for this undesirable change :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions