[M3devel] bad code on PPC_LINUX?

Jay jayk123 at hotmail.com
Thu Jan 10 08:11:11 CET 2008


Something is screwy I think.
My gdb skills are um not good.

On PPC_LINUX.

/dev2/cm3/m3-sys/cm3/src/Utils.m3

PROCEDURE WriteFile (file: TEXT;  proc: Emitter;  append := FALSE) =
  VAR wr: Wr.T;
  BEGIN
    IF (append)
      THEN wr := AppendWriter (file, fatal := TRUE);
      ELSE wr := OpenWriter (file, fatal := TRUE);
    END;
    TRY           (* line 78 *)
      TRY
        proc (wr);
      EXCEPT
      | Wr.Failure (ec) =>
          Msg.FatalError (ec, "write failed on ", file);
      | Thread.Alerted =>
          Msg.FatalError (NIL, "interrupted while writing ", file);
      END;
    FINALLY
      CloseWriter (wr, file);
    END;
  END WriteFile;

I get a SEGV on line 78.

I'm willing to believe, sadly, that some of these huge offsets
are the price of TRY and saving the register context on anything
other than x86 (for registers that aren't even used by the function?),
however it crashes just after the call and notice there the huge 32k offset.

And really? A 720 byte frame for any function with a TRY on PowerPC?
Really?
I guess I should look at what PPC_DARWIN does.

If someone can give me a quick run down on PowerPC ABI, thanks.
I'll search the web. Or maybe check my Mac docs.
register 0 is 0 or general purpose?
Stack is register ?
I know that return address is in the link register.
bl is branch and link -- call -- jump and save pc in link register.

The code is:
(gdb) disassemble
Dump of assembler code for function Utils__WriteFile:
0x10024fbc :        stwu    r1,-720(r1)
0x10024fc0 :        mflr    r0
0x10024fc4 :        mfcr    r12
0x10024fc8 :       stfd    f14,576(r1)
0x10024fcc :       stfd    f15,584(r1)
0x10024fd0 :       stfd    f16,592(r1)
0x10024fd4 :       stfd    f17,600(r1)
0x10024fd8 :       stfd    f18,608(r1)
0x10024fdc :       stfd    f19,616(r1)
0x10024fe0 :       stfd    f20,624(r1)
0x10024fe4 :       stfd    f21,632(r1)
0x10024fe8 :       stfd    f22,640(r1)
0x10024fec :       stfd    f23,648(r1)
0x10024ff0 :       stfd    f24,656(r1)
0x10024ff4 :       stfd    f25,664(r1)
0x10024ff8 :       stfd    f26,672(r1)
0x10024ffc :       stfd    f27,680(r1)
0x10025000 :       stfd    f28,688(r1)
0x10025004 :       stfd    f29,696(r1)
0x10025008 :       stfd    f30,704(r1)
0x1002500c :       stfd    f31,712(r1)
0x10025010 :       stw     r14,504(r1)
0x10025014 :       stw     r15,508(r1)
0x10025018 :       stw     r16,512(r1)
0x1002501c :       stw     r17,516(r1)
0x10025020 :      stw     r18,520(r1)
0x10025024 :      stw     r19,524(r1)
0x10025028 :      stw     r20,528(r1)
0x1002502c :      stw     r21,532(r1)
---Type  to continue, or q  to quit---
0x10025030 :      stw     r22,536(r1)
0x10025034 :      stw     r23,540(r1)
0x10025038 :      stw     r24,544(r1)
0x1002503c :      stw     r25,548(r1)
0x10025040 :      stw     r26,552(r1)
0x10025044 :      stw     r27,556(r1)
0x10025048 :      stw     r28,560(r1)
0x1002504c :      stw     r29,564(r1)
0x10025050 :      stw     r30,568(r1)
0x10025054 :      stw     r31,572(r1)
0x10025058 :      stw     r0,724(r1)
0x1002505c :      stw     r12,500(r1)
0x10025060 :      mr      r31,r1
0x10025064 :      bl      0x10025068 
0x10025068 :      mflr    r30
0x1002506c :      lwz     r0,-176(r30)
0x10025070 :      add     r30,r0,r30
0x10025074 :      stw     r3,8(r31)
0x10025078 :      stw     r4,12(r31)
0x1002507c :      mr      r0,r5
0x10025080 :      stb     r0,16(r31)
0x10025084 :      li      r0,0
0x10025088 :      stw     r0,20(r31)
0x1002508c :      lbz     r0,16(r31)
0x10025090 :      clrlwi  r0,r0,24
0x10025094 :      cmpwi   r0,0
0x10025098 :      beq-    0x100250b8 
0x1002509c :      lwz     r3,8(r31)
0x100250a0 :      li      r4,1
0x100250a4 :      bl      0x100248a4 
---Type  to continue, or q  to quit---
0x100250a8 :      stw     r3,476(r31)
0x100250ac :      lwz     r9,476(r31)
0x100250b0 :      stw     r9,20(r31)
0x100250b4 :      b       0x100250d0 
0x100250b8 :      lwz     r3,8(r31)
0x100250bc :      li      r4,1
0x100250c0 :      bl      0x10024658 
0x100250c4 :      stw     r3,476(r31)
0x100250c8 :      lwz     r9,476(r31)
0x100250cc :      stw     r9,20(r31)

 ** here I believe ** 

0x100250d0 :      lwz     r0,-32760(r30)
0x100250d4 :      stw     r0,32(r31)
0x100250d8 :      addi    r0,r31,8
0x100250dc :      stw     r0,36(r31)
0x100250e0 :      li      r0,3
0x100250e4 :      stw     r0,28(r31)
0x100250e8 :      lwz     r9,-32764(r30)
0x100250ec :      lwz     r0,0(r9)
0x100250f0 :      stw     r0,24(r31)
0x100250f4 :      lwz     r9,-32764(r30)
0x100250f8 :      addi    r0,r31,24
0x100250fc :      stw     r0,0(r9)
0x10025100 :      lwz     r9,-32768(r30)
0x10025104 :      addi    r0,r9,76
0x10025108 :      stw     r0,64(r31)
0x1002510c :      li      r0,0
0x10025110 :      stw     r0,60(r31)
0x10025114 :      lwz     r9,-32764(r30)
0x10025118 :      lwz     r0,0(r9)
0x1002511c :      stw     r0,56(r31)
---Type  to continue, or q  to quit---
0x10025120 :      lwz     r9,-32764(r30)
0x10025124 :      addi    r0,r31,56
0x10025128 :      stw     r0,0(r9)
0x1002512c :      addi    r9,r31,56
0x10025130 :      addi    r0,r9,48
0x10025134 :      mr      r3,r0
0x10025138 :      bl      0x101bbf28 
0x1002513c :      mr      r0,r3
0x10025140 :      cmpwi   r0,0
0x10025144 :      bne-    0x100251ac 
0x10025148 :      lwz     r9,12(r31)
0x1002514c :      stw     r9,476(r31)
0x10025150 :      lwz     r9,476(r31)
0x10025154 :      cmpwi   r9,0
0x10025158 :      beq-    0x10025188 
0x1002515c :      lwz     r9,476(r31)
0x10025160 :      lwz     r0,0(r9)
0x10025164 :      li      r9,-1
0x10025168 :      cmpw    r0,r9
0x1002516c :      bne-    0x10025188 
0x10025170 :      lwz     r9,476(r31)
0x10025174 :      lwz     r9,8(r9)
0x10025178 :      stw     r9,480(r31)
0x1002517c :      lwz     r9,476(r31)
0x10025180 :      lwz     r9,4(r9)
0x10025184 :      stw     r9,476(r31)
0x10025188 :      lwz     r11,480(r31)
0x1002518c :      lwz     r3,20(r31)
0x10025190 :      lwz     r0,476(r31)
0x10025194 :      mtlr    r0
---Type  to continue, or q  to quit---
0x10025198 :      blrl
0x1002519c :      lwz     r9,-32764(r30)
0x100251a0 :      lwz     r0,56(r31)
0x100251a4 :      stw     r0,0(r9)
0x100251a8 :      b       0x10025210 
0x100251ac :      lwz     r9,68(r31)
0x100251b0 :      lwz     r9,0(r9)
0x100251b4 :      lis     r0,-15535
0x100251b8 :      ori     r0,r0,42454
0x100251bc :      cmpw    r9,r0
0x100251c0 :      bne-    0x100251f0 
0x100251c4 :      lwz     r0,72(r31)
0x100251c8 :      stw     r0,472(r31)
0x100251cc :      lwz     r9,-32768(r30)
0x100251d0 :      addi    r0,r9,180
0x100251d4 :      lwz     r3,472(r31)
0x100251d8 :      mr      r4,r0
0x100251dc :      lwz     r5,8(r31)
0x100251e0 :      li      r6,0
0x100251e4 :      li      r7,0
0x100251e8 :      bl      0x10023b4c 
0x100251ec :      b       0x10025210 
0x100251f0 :      lwz     r9,-32768(r30)
0x100251f4 :      addi    r0,r9,212
0x100251f8 :      li      r3,0
0x100251fc :      mr      r4,r0
0x10025200 :      lwz     r5,8(r31)
0x10025204 :      li      r6,0
0x10025208 :      li      r7,0
0x1002520c :      bl      0x10023b4c 
---Type  to continue, or q  to quit---
0x10025210 :      lwz     r9,-32764(r30)
0x10025214 :      lwz     r0,24(r31)
0x10025218 :      stw     r0,0(r9)
0x1002521c :      addi    r11,r31,8
0x10025220 :      bl      0x10024f74 
0x10025224 :      lwz     r11,0(r1)
0x10025228 :      lwz     r0,4(r11)
0x1002522c :      lwz     r12,-220(r11)
0x10025230 :      mtlr    r0
0x10025234 :      lwz     r14,-216(r11)
0x10025238 :      lwz     r15,-212(r11)
0x1002523c :      lwz     r16,-208(r11)
0x10025240 :      lwz     r17,-204(r11)
0x10025244 :      lwz     r18,-200(r11)
0x10025248 :      lwz     r19,-196(r11)
0x1002524c :      lwz     r20,-192(r11)
0x10025250 :      lwz     r21,-188(r11)
0x10025254 :      lwz     r22,-184(r11)
0x10025258 :      lwz     r23,-180(r11)
0x1002525c :      lwz     r24,-176(r11)
0x10025260 :      lwz     r25,-172(r11)
0x10025264 :      lwz     r26,-168(r11)
0x10025268 :      lwz     r27,-164(r11)
0x1002526c :      lwz     r28,-160(r11)
0x10025270 :      lwz     r29,-156(r11)
0x10025274 :      lwz     r30,-152(r11)
0x10025278 :      lwz     r31,-148(r11)
0x1002527c :      lfd     f14,-144(r11)
0x10025280 :      lfd     f15,-136(r11)
0x10025284 :      lfd     f16,-128(r11)
---Type  to continue, or q  to quit---
0x10025288 :      lfd     f17,-120(r11)
0x1002528c :      lfd     f18,-112(r11)
0x10025290 :      lfd     f19,-104(r11)
0x10025294 :      lfd     f20,-96(r11)
0x10025298 :      lfd     f21,-88(r11)
0x1002529c :      lfd     f22,-80(r11)
0x100252a0 :      lfd     f23,-72(r11)
0x100252a4 :      lfd     f24,-64(r11)
0x100252a8 :      lfd     f25,-56(r11)
0x100252ac :      lfd     f26,-48(r11)
0x100252b0 :      lfd     f27,-40(r11)
0x100252b4 :      lfd     f28,-32(r11)
0x100252b8 :      lfd     f29,-24(r11)
0x100252bc :      lfd     f30,-16(r11)
0x100252c0 :      lfd     f31,-8(r11)
0x100252c4 :      mtcrf   56,r12
0x100252c8 :      mr      r1,r11
0x100252cc :      blr
0x100252d0 :      .long 0x24ebb0
End of assembler dump.


(gdb) bt
#0  Utils__WriteFile (M3_Bd56fi_file=0x10277ba0, M3_DmuccK_proc=0x7fb22210,
    M3_AicXUJ_append=0 '\0') at Utils.m3:78
#1  0x10020a10 in Makefile__Build (M3_Bd56fi_src_dir=0x102720ec)
    at Makefile.m3:101
#2  0x100292d4 in Main__DoIt () at Main.m3:71
#3  0x10029834 in Main_M3 (M3_AcxOUs_mode=1) at Main.m3:193
#4  0x10188f9c in RTLinker__RunMainBody (M3_DUuepq_m=0x10279b28)
    at RTLinker.m3:387
#5  0x101880bc in RTLinker__AddUnitI (M3_DUuepq_m=0x10279b28) at RTLinker.m3:100
#6  0x10188198 in RTLinker__AddUnit (M3_DUuepw_b=0x100297f8) at RTLinker.m3:110
#7  0x100002ec in main (argc=1, argv=0x7fb22834, envp=0x7fb2283c) at _m3main.mc:4

I haven't yet figured out how to get gdb to show me the details of the SEGV, like what address was referenced.

I swear I think this was working better recently.

Oh, I did change something. I will try to change it back.
I added -fPIC.
Dynamic linking was not working and I thought that might fix it.
I'll definitely try without it now.

Also, relevant aside -- what, if any, distributions/versions of Linux are people using on PowerPC?
Specifically on PowerPC (to limit the religious explosion)
I'm currently using Yellow Dog, I think 4.1, but only for Modula-3 purposes, not for anything else.

ps: I'd like a SMALL forum of SMART programmers, to discuss GENERAL programming topics.
This is it perhaps?

 - Jay
_________________________________________________________________
Watch “Cause Effect,” a show about real people making a real difference.
http://im.live.com/Messenger/IM/MTV/?source=text_watchcause


More information about the M3devel mailing list