[tex-k] mf segfaults if compiled with -g3 (bug in mfmpi386.asm)

Edward Catmur ed at catmur.co.uk
Wed Mar 29 01:09:15 CEST 2006


If compiled with -g3 or -ggdb3 in CFLAGS, mf segfaults.

Disassembly shows that where optimised functions such as ztakefraction
should be called, bogus locations are instead called, causing segfault:

0x0806a835 <zfinoffsetprep+101>:        sub    %edi,%eax
0x0806a837 <zfinoffsetprep+103>:        cmp    %eax,%edx
0x0806a839 <zfinoffsetprep+105>:        jl     0x806aa60 <zfinoffsetprep
+656>
0x0806a83f <zfinoffsetprep+111>:        mov    %esi,0x4(%esp)
0x0806a843 <zfinoffsetprep+115>:        mov    %ebx,(%esp)
0x0806a846 <zfinoffsetprep+118>:        call   0x1787c
0x0806a84b <zfinoffsetprep+123>:        mov    0x14(%ebp),%esi
0x0806a84e <zfinoffsetprep+126>:        mov    %eax,%edi
0x0806a850 <zfinoffsetprep+128>:        mov    %eax,0x4(%esp)
0x0806a854 <zfinoffsetprep+132>:        mov    %esi,(%esp)
0x0806a857 <zfinoffsetprep+135>:        call   0x177f8

If compiled with -g, this becomes:

0x0806a835 <zfinoffsetprep+101>:        sub    %edi,%eax
0x0806a837 <zfinoffsetprep+103>:        cmp    %eax,%edx
0x0806a839 <zfinoffsetprep+105>:        jl     0x806aa60 <zfinoffsetprep
+656>
0x0806a83f <zfinoffsetprep+111>:        mov    %esi,0x4(%esp)
0x0806a843 <zfinoffsetprep+115>:        mov    %ebx,(%esp)
0x0806a846 <zfinoffsetprep+118>:        call   0x808ef08 <zmakefraction>
0x0806a84b <zfinoffsetprep+123>:        mov    0x14(%ebp),%esi
0x0806a84e <zfinoffsetprep+126>:        mov    %eax,%edi
0x0806a850 <zfinoffsetprep+128>:        mov    %eax,0x4(%esp)
0x0806a854 <zfinoffsetprep+132>:        mov    %esi,(%esp)
0x0806a857 <zfinoffsetprep+135>:        call   0x808ee84 <ztakefraction>

This happens because if compiled with -g3, the asm in mfmpi386.asm ends
up in the .data section and the symbols ztakefraction etc. do not end up
in the global symbol table (or something like that; I'm no assembly
expert).

Adding ".text\n" to the top of mfmpi386.asm fixes this:

--- texk/web2c/lib/mfmpi386.asm    2006/03/28 23:06:02     1.1
+++ texk/web2c/lib/mfmpi386.asm    2006/03/28 23:06:19
@@ -2,7 +2,8 @@
    and MetaPost. Public domain. Included in texmfmp.c.
    By Wayne Sullivan <wgs at maths.ucd.ie>. */

-asm("        .align 4\n"
+asm(".text\n"
+"        .align 4\n"
 #ifdef ASM_NEEDS_UNDERSCORE
 ".globl _ztakefraction\n"
 "_ztakefraction:\n"

Hope I'm sending this to the right address and that this makes sense.

Ed Catmur



More information about the tex-k mailing list