[tlbuild] m-tx test fails on powerpc-linux
Johannes Hielscher
jhielscher at posteo.de
Sun Apr 8 03:11:20 CEST 2018
> > 3) Failing that, I can only suggest running under the debugger and
> > try to discern where the bad value comes from.
>
> I'll have a try. Tomorrow.
>
OK, I found the error in the m-tx code, which explains the wrong value
of fracindent. Located by some lengthy gdb fiddling.
(tl;dr: patch below)
I am no Pascal expert, but the loop ranges in preamble.pas:501ff
for i:=1 to maxvoices do setVocal(i,false);
for i:=1 to maxstaves do stave_size[i]:=unspec;
for i:=0 to maxstaves do nspace[i]:=unspec;
begin nspace[i]:=unspec; stave_size[i]:=unspec; end;
are definitely inconsistent. Pascal won't switch from zero-based to
one-based arrays within a loop.
There is an array bound violation error in here. (NB nspace[] is
created with maxstaves entries!). In the C code, this is even more
obvious:
for (i = 0; i <= maxstaves; i++)
nspace[i] = unspec;
nspace[i] = unspec;
In the last iteration, of the third loop, the (semantically unrelated)
variable fracindent gets overwritten, since it happens to lie at exactly
the memory address of nspace[maxstaves], at least within the
memory of the PowerPC binary:
(gdb) print &nspace[16]
$20 = (short *) 0x20060b18 <fracindent>
Note that gdb even knows this!
Other architecture probably have other memory alignments, so that the
bound violation does at least not overwrite the (somewhat
visible) fracindent variable -- but what else?
I came up with this tiny fix that makes prepmx behave correctly:
Index: Build/source/utils/m-tx/mtx-src/preamble.c
===================================================================
--- Build/source/utils/m-tx/mtx-src/preamble.c (Revision 47364)
+++ Build/source/utils/m-tx/mtx-src/preamble.c (Arbeitskopie)
@@ -799,7 +799,7 @@
setVocal(i, false);
for (i = 0; i <= maxstaves - 1; i++)
stave_size[i] = unspec;
- for (i = 0; i <= maxstaves; i++)
+ for (i = 0; i < maxstaves; i++)
nspace[i] = unspec;
nspace[i] = unspec;
stave_size[i-1] = unspec;
Index: Build/source/utils/m-tx/mtx-src/preamble.pas
===================================================================
--- Build/source/utils/m-tx/mtx-src/preamble.pas (Revision 47364)
+++ Build/source/utils/m-tx/mtx-src/preamble.pas (Arbeitskopie)
@@ -500,7 +500,7 @@
style_supplied := false;
for i:=1 to maxvoices do setVocal(i,false);
for i:=1 to maxstaves do stave_size[i]:=unspec;
- for i:=0 to maxstaves do nspace[i]:=unspec;
+ for i:=0 to maxstaves-1 do nspace[i]:=unspec;
begin nspace[i]:=unspec; stave_size[i]:=unspec; end;
n_pages:=1; n_systems:=1;
readStyles; old_known_styles := known_styles;
(The Pascal part of the patch is just based on an extrapolation from
the surrounding code. It should be controlled by someone who is
familiar with the intentions behind array/loop ranges in Pascal.)
BTW The code line in question was indeed introduced by m-tx v0.63 and
came into TL with SVN -r46254. I just didn't find it in the first run
because I thought that it would be enough to search for "fracindent"
when fracindent behaves strange \-:
Thanks,
Johannes
More information about the tlbuild
mailing list