On Wednesday, September 22, 2021 at 2:10:00 AM UTC+10, Ralf Fassel wrote:
> We're building snack on Windows for both 32bit and 64bit,
> with msys/configure and MSVC 2019. We fiddle with the generated
> Makefiles a bit (replace -I/c/some/path by -Ic:/some/path, -ltclstub by
> tclstub.lib etc via sed), so it should be feasible with mingw, too.
Ah, thanks Ralf. That's good to know. I had a couple of problems building that I had to patch around
1. KSDATAFORMAT_SUBTYPE_PCM redeclared in win/jkAudIO_win.c.
2. roundf() defined locally in generic/jkFormatMP3.c
3. Link errors with Tcl_SeekOld and Tcl_TellOld. These seem to be #undefined in Tcl 8.6 so I used the same definition as for TCL_MINOR_VERSION < 4 in jSound.h.
So then it would build although with plenty of warnings. But then it seg faults in jkFormatMP3.c. But it does this for both the 32 and 64 bit builds.
Thread 1 received signal SIGSEGV, Segmentation fault.
layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
2873 for (ch=0;ch<ext->nch;ch++) requantize_mono(ext, gr,ch,&info,header);
1: x/3i $pc
=> 0x39a45a0 <ReadMP3Samples+7904>: movl $0x0,(%rax)
0x39a45a6 <ReadMP3Samples+7910>: add $0x4,%rax
0x39a45aa <ReadMP3Samples+7914>: jmp 0x39a45a0 <ReadMP3Samples+7904>
Value can't be converted to integer.
(gdb) backtrace full no-filter
#0 layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
Now, there was a warning from gcc when compiling this module:
gcc -g -O2 -O2 -fomit-frame-pointer -DHAVE_STDINT_H -IC:/Users/scottyw/Desktop/src/tcltk/tcltk-build/tcl8.6.9/generic -I/c/Users/scottyw/Desktop/src/tcltk/tcltk-build/tk8.6.9/generic -I/c/Users/scottyw/Desktop/src/tcltk/tcltk-build/tk8.6.9/xlib -I/mingw/dx6/include -I../win/../generic -DWIN -DUSE_TCL_STUBS -DUSE_TK_STUBS -DBUILD_snack -DTCL_81_API -c -o jkFormatMP3.o ../win/../generic/jkFormatMP3.c
../win/../generic/jkFormatMP3.c: In function 'requantize_mono':
../win/../generic/jkFormatMP3.c:774:26: warning: iteration 18 invokes undefined behavior [-Waggressive-loop-optimizations]
774 | ext->xr[ch][0][l]=FRAS2(ext->is[ch][l],a);
| ^
../win/../generic/jkFormatMP3.c:773:13: note: within this loop
773 | while (l<36) {
| ^
I decided to remove the -O2 optimisation from the Makefile, and I rebuilt the 32 bit version, and now it runs. The test I am using is a desktop stopwatch I use for metering our tasks in the workshop. It plays an MP3 at the alarm time and I use snack for this.
I'm still having a problem with a seg fault at the same place in the 64 bit version. I've turned off optimisaton with -O0 but I'm not sure this is working:
Thread 1 received signal SIGSEGV, Segmentation fault.
layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
warning: Source file is more recent than executable.
2873 if (header->mode!=1 || (header->mode==1 && header->mode_extension==0))
1: x/3i $pc
=> 0x3ab45a0 <ReadMP3Samples+7904>: movl $0x0,(%rax)
0x3ab45a6 <ReadMP3Samples+7910>: add $0x4,%rax
0x3ab45aa <ReadMP3Samples+7914>: jmp 0x3ab45a0 <ReadMP3Samples+7904>
(gdb) backtrace full no-filter
#0 layer3_frame (len=<optimized out>, header=0x22f7b0, ext=<optimized out>)
at ../win/../generic/jkFormatMP3.c:2873
rest = <optimized out>
gr = <optimized out>
tmp = <optimized out>
fs = <optimized out>
hsize = <optimized out>
ch = 0
sb = <optimized out>
i = <optimized out>
mean_frame_size = <optimized out>
bitrate = <optimized out>
ssize = <optimized out>
cnt = <optimized out>
info = {main_data_begin = 15, scfsi = {{0, 0, 0, 0}, {0, 0, 0, 0}},
part2_3_length = {{940, 0}, {0, 0}}, big_values = {{107, 0}, {0,
0}}, global_gain = {{177, 0}, {0, 0}}, scalefac_compress = {{
223, 0}, {0, 0}}, window_switching_flag = {{1, 0}, {0, 0}},
block_type = {{3, 0}, {0, 0}}, mixed_block_flag = {{0, 0}, {0, 0}},
table_select = {{{15, 6, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}}},
subblock_gain = {{{0, 0, 0}, {0, 0, 0}}, {{0, 0, 0}, {0, 0, 0}}},
region0_count = {{0, 0}, {0, 0}}, region1_count = {{0, 0}, {0, 0}},
preflag = {{0, 0}, {0, 0}}, scalefac_scale = {{1, 0}, {0, 0}},
count1table_select = {{0, 0}, {0, 0}}, error = {0, 0}}
gr = <optimized out>
ch = <optimized out>
sb = <optimized out>
i = <optimized out>
tmp = <optimized out>
mean_frame_size = <optimized out>
bitrate = <optimized out>
fs = <optimized out>
hsize = <optimized out>
ssize = <optimized out>
cnt = <optimized out>
rest = <optimized out>
win_type = <optimized out>
l = <optimized out>
l = <optimized out>