oridb / mc

Myrddin Compiler
MIT License
389 stars 34 forks source link

segmentation violation when use C code that do IO #208

Open aerphanas opened 1 month ago

aerphanas commented 1 month ago

os: intel x86_64 GNU/Linux Debian 12 myrddin ver: master branch from github

i am trying to do raylib in myrddin, but when i try to run it it crash, i don't know why, i do simple test to check it here's the code

bld.proj

bin ctest =
    main.myr
    lib cmain
;;

lib cmain =
    cmain.myr
    cmain.glue.c
;;

main.myr

use std
use cmain

const main = { -> void
    cmain.print_hello()
}

cmain.myr

use std

pkg cmain =
    extern const print_hello : (-> void)
;;

cmain.glue.c

/* CFLAGS: -Wall -Wextra */
/* LIBS: c */

#include <stdio.h>

void
cmain$print_hello()
{
    printf("test");
}

when i compile & run it says this

    cc -c -o obj/cmain.glue.o cmain.glue.c -Wall -Wextra
    ar -rcs obj/libcmain.a obj/cmain.o obj/cmain.glue.o
    6m -O obj -I obj main.myr
    ld --gc-sections -o obj/ctest /usr/local/lib/myr/_myrrt.o obj/main.o -Lobj -lcmain -lc -lstd -L/usr/local/lib/myr -lsys -dynamic-linker /lib64/ld-linux-x86-64.so.2
ld: warning: syscall.o: missing .note.GNU-stack section implies executable stack
ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
ctest: exit 1
10887: signal: sys: segmentation violation

but when i change cmain$print_hello() and the rest to just return "int" it works

aerphanas commented 1 month ago

I tested it with Myrddin version r0.3.1; it works.

aerphanas commented 1 month ago

The last commit that I know worked is b17873e. After that, a couple of commits couldn't be built, and then in 4d6ba69, it started to segfault.