YaK:: CMOC 0.1.78 bug report : lib/float-ctor.native_o for OS9 [Changes]   [Calendar]   [Search]   [Index]   [PhotoTags]   
[mega_changes]
[photos]

CMOC 0.1.78 bug report: lib/float-ctor.native_o for OS9

Execution in my emulator, showing ASM source and comments where it can, way on the right. (It helps to make your font very small, perhaps Control Minus a few times, so lines fit on one line.)

dcf6:39       {rts                    }  a=df b=a1 x=dfa1:3031 y=0000:00ff u=0024:0000 s=1ef9:a015,0001 cc=EfhiNzvc dp=00 #2586085 {{x.x.s:00353 | bss_end  RTS                     end of global variable initialization}}




a038:163c99   {lbra  $dcd4            }  a=df b=a1 x=dfa1:3031 y=0000:00ff u=0024:0000 s=1ef9:a015,0001 cc=EfhiNzvc dp=00 #2586086 {{crt.asm.os9asm:00096 |         LBRA    constructors}}




dcd4:308dcbff {leax  $a8d7,pcr        }  a=df b=a1 x=a8d7:c621 y=0000:00ff u=0024:0000 s=1ef9:a015,0001 cc=EfhiNzvc dp=00 #2586087 {{}}

dcd8:af8dc338 {stx   $a014,pcr        }  a=df b=a1 x=a8d7:c621 y=0000:00ff u=0024:0000 s=1ef9:a015,0001 cc=EfhiNzvc dp=00 #2586088 {{}}

dcdc:39       {rts                    }  a=df b=a1 x=a8d7:c621 y=0000:00ff u=0024:0000 s=1efb:0001,0020 cc=EfhiNzvc dp=00 #2586089 {{crt.asm.os9asm:00579 |         RTS}}




a015:d709     {stb   $09              }  a=df b=a1 x=a8d7:c621 y=0000:00ff u=0024:0000 s=1efb:0001,0020 cc=EfhiNzvc dp=00 #2586090 {{x.x.s:00016 |         LBSR    _main           call main()}}

That's at the end of the global variable initialization, and it calls constructors. There's only one constructor SECTION, length 8, from cmoc/lib/float-ctor.native_o

The source of that constructor seems to be in enableCMOCFloatSupport.asm:

_enableCMOCFloatSupport
        leax    unpackSingleAndConvertToASCII,PCR       ; PCR in caps b/c ref to code
        stx     unpackSingleAndConvertToASCII_hook,pcr

I've forgotten what the ",PCR" vs ",pcr" rule is, but I think the "stx" should not be Program Counter Relative on OS9.

Notice that the "stx $a014,pcr" is overwriting the first byte of the instruction that is executed after the "rts", at $a015 -- it should be a LBSR _main (as it is in the source at the right) but it has become a "stb $09" instruction (as the emulator decoded it at the left).

I also don't know how CMOC Float Support got enabled in my binary. I don't think it should be.

I'm pretty sure that my cmoc linkage hacks do not create this bug.

Also it doesn't look like any changes from 0.1.78 to 0.1.79 would fix it.


Here's Hello World, and it causes the float support constructor:

$
$ which cmoc
/opt/yak/cmoc/bin/cmoc
$ cmoc -v
cmoc (cmoc 0.1.78)
$ cat -n hello.c
     1        #include <cmoc.h>
     2
     3        int main() {
     4            printf("hello world\n");
     5            return 0;
     6        }
$ cmoc --os9 -i hello.c
$ grep constructor hello.map
Section: constructors_start (crt.os9_o) load at 0660, length 0000
Section: constructors (/opt/cmoc-0.1.78/share/cmoc/lib/float-ctor.native_o) load at 0660, length 0008
Section: constructors_end (crt.os9_o) load at 0668, length 0001
Symbol: \02constructors (/opt/cmoc-0.1.78/share/cmoc/lib/float-ctor.native_o) = 0660
Symbol: \02constructors_end (crt.os9_o) = 0668
Symbol: \02constructors_start (crt.os9_o) = 0660
Symbol: constructors (crt.os9_o) = 0660
Symbol: l_constructors (<synthetic>) = 0008
Symbol: l_constructors_end (<synthetic>) = 0001
Symbol: l_constructors_start (<synthetic>) = 0000
Symbol: s_constructors (<synthetic>) = 0660
Symbol: s_constructors_end (<synthetic>) = 0668
Symbol: s_constructors_start (<synthetic>) = 0660
$
$ lwasm --version
lwasm from lwtools 4.19
$ lwlink --version
lwlink from lwtools 4.19
$

A log of its execution shows the bug at the third-to-the-last instruction in this log file:

  • hello-emulator.log That's right before it branches to _main
  • (unless otherwise marked) Copyright 2002-2014 YakPeople. All rights reserved.
    (last modified 2022-09-13)       [Login]
    (No back references.)