I reported a while ago problems with lyx-1.0.3 on alpha and
subsequently proposed spec file modifications to avoid triggering
the problem. Here is more detailed account what is really going on
(and a code modification).
This is indeed a compiler bug. To see it on a simple example look
at the following code:
#include <stdio.h>
#include <string.h>
unsigned char buffer[sizeof(char *) + 2];
int
main ()
{
unsigned char *p;
int i;
p = (unsigned char *)&p; /* trivial initialization */
printf("original = %p\n", p);
#if defined(BUG)
memcpy (&buffer[1], &p, sizeof(p));
#else
{
unsigned char *target, *source;
target = &buffer[1];
source = (unsigned char *)&p;
for (i = 0; i < sizeof(char *) ; i++) {
*target++ = *source++;
}
}
#endif
for (i = sizeof(char *) + 2; i > 0 ; ) {
printf("%02x ", buffer[--i]);
}
printf("\n");
return(0);
}
If BUG is not defined then, whatever an optimization level this prints
original = 0x11ffffb60
00 00 00 00 01 1f ff fb 60 00
If you add to your compilation flags -DBUG and **any** level of
optimization above -O0 then, with some versions of egcs on Alpha,
including egcs-1.1.2 release, you will see
original = 0x11ffffb60
00 00 00 00 00 00 00 00 60 00
Short scan through a generated assembler seems to indicate that this
is a faulty expansion of an inline function memcpy (this inlining does
not happen with -O0 and you are safe). I am not entirely sure about
diagnosis, but it seems to be plausible. I am told that in egcs (gcc)
2.95, which is not released yet and only available in snapshots this
bug vanished. I did not try that yet myself.
Here is a patch which makes math_iter.C "safe" in the face
of a broken compiler.
--- lyx-1.0.3/src/math_iter.C~ Mon Nov 30 10:26:29 1998
+++ lyx-1.0.3/src/math_iter.C Mon Jun 28 22:45:12 1999
@@ -265,10 +265,21 @@
if (!MathIsInset(type))
type = LM_TC_INSET;
split(shift);
- array->bf[pos] = type;
- memcpy(&array->bf[pos+1], &p, sizeof(p));
+// array->bf[pos] = type;
+// memcpy(&array->bf[pos+1], &p, sizeof(p));
+// pos += SizeInset;
+// array->bf[pos-1] = type;
+ {
+ unsigned char *pt = &array->bf[pos];
+ unsigned char *ps = (unsigned char *)&p;
+ size_t i;
+ *pt++ = type;
+ for(i = 0; i < sizeof(p); i++) {
+ *pt++ = *ps++;
+ }
+ *pt = type;
+ }
pos += SizeInset;
- array->bf[pos-1] = type;
array->bf[array->last] = '\0';
fcode = -1;
}
After this change and recompilation (even with a higher level
of an optimization than -O2) LyX seems to be doing just fine
although I definitely did not test all its aspects.
Regards,
Michal
[EMAIL PROTECTED]
[EMAIL PROTECTED]