jart / cosmopolitan

build-once run-anywhere c library
ISC License
18.32k stars 628 forks source link

OCaml artifact segfault on `arm64v8` machine (ubuntu) but it's work with `--{f,s}trace` and on `x86_64` #990

Closed dinosaure closed 10 months ago

dinosaure commented 11 months ago

I currently try to upgrade esperanto with Cosmopolitan 3.1.3. Currently the artifact works fine on x86_64 but it segfaults on aarch64 (I took docker run -it --rm --platform linux/arm64 arm64v8/ubuntu to test). However, if I use the --strace option, the program works fine.

Currently, the way to produce such artifact from an OCaml code is a bit hard but available here: https://github.com/dinosaure/esperanto/pull/43 (see the ./README.md updated according to the usage of apelink). I uploaded what I produced from this little project in OCaml: hxd. This is the output of --strace with echo "Salut"|./xxd.com:

$ echo "Salut"|./xxd.com
root@48e408a212e4:~# echo "Salut"|./xxd.com --strace
SYS   9816   9816          2'062'000 getenv("HOME") → "/root"
SYS   9816   9816          2'664'000 getenv("TMPDIR") → NULL
SYS   9816   9816          3'021'008 getenv("TERM") → "xterm"
SYS   9816   9816          4'151'008 getenv("COSMOPOLITAN_DISABLE_ZIPOS") → NULL
SYS   9816   9816          4'193'008 getenv("COSMOPOLITAN_INIT_ZIPOS") → NULL
SYS   9816   9816          4'307'008 getcwd([u"/root"], 1'019) → 6
SYS   9816   9816          5'133'008 openat(AT_FDCWD, "/root/xxd.com", O_RDONLY) → 3
SYS   9816   9816          6'389'008 fstat(3, [{.st_size=3'538'423, .st_blocks=3'538'944/512, .st_mode=0100755, .st_uid=1000, .st_gid=1000, .st_dev=0x3f, .st_ino=0x257df}]) → 0
SYS   9816   9816          8'762'000 mmap(0, 3'538'423, PROT_READ, MAP_SHARED, 3, 0) → 0x100080200000 (3'604'480 bytes total)
SYS   9816   9816         10'134'000 munmap(0x100080200000, 3'276'800) → 0 (327'680 bytes total)
SYS   9816   9816         10'306'000 madvise(0x10008052d000, 204'800, 4) → 0
SYS   9816   9816         10'832'000 mmap(0, 144, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100080040000 (393'216 bytes total)
SYS   9816   9816         11'764'000 close(3) → 0
SYS   9816   9816         11'819'008 __zipos_get("/root/xxd.com") → 0
SYS   9816   9816         12'113'008 mmap(0, 458'752, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100080080000 (851'968 bytes total)
SYS   9816   9816         12'430'000 mmap(0, 65'536, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100080050000 (917'504 bytes total)
SYS   9816   9816         17'778'000 inflate([u"SYMT☺   ↨▬        •       •          ☺  "...], 458'752, u"\\█q\\σ√£8■╧L3╖f║t○┼á!4╠Ñ!¶]→B╤Ñ!¶]èP╗]è¼Ä"..., 97'180) → 0
SYS   9816   9816         18'187'008 GetSymbolTableFromZip() → 0x100080080000
SYS   9816   9816         18'556'000 issetugid() → 0
SYS   9816   9816         18'679'008 getenv("OCAMLRUNPARAM") → NULL
SYS   9816   9816         18'747'008 issetugid() → 0
SYS   9816   9816         18'752'000 getenv("CAMLRUNPARAM") → NULL
SYS   9816   9816         19'032'000 mmap(0, 196'608, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100080100000 (1'114'112 bytes total)
SYS   9816   9816         20'136'000 mmap(0, 2'162'688, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100080200000 (3'276'800 bytes total)
SYS   9816   9816         20'680'000 mmap(0, 1'048'576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) → 0x100080600000 (4'325'376 bytes total)
SYS   9816   9816         21'446'000 getenv("PATH") → "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
00000000: 5361 6c75 740a                           Salut.

And this is the output for --ftrace:

root@48e408a212e4:~# echo Salut|./xxd.com --ftrace
FUN   9828   9828         14'158'992     768 &main
FUN   9828   9828         14'924'000     784   &caml_main
FUN   9828   9828         15'034'000     800     &caml_startup_common
FUN   9828   9828         15'070'000     880       &caml_init_domain
FUN   9828   9828         15'192'992     912         &caml_stat_alloc_noexc
FUN   9828   9828         15'286'992     912         &malloc
FUN   9828   9828         15'348'992     928           &__dlmalloc
FUN   9828   9828         15'576'992     912         &caml_alloc_minor_tables
FUN   9828   9828         15'668'992     944           &caml_stat_alloc_noexc
FUN   9828   9828         15'710'992     944           &malloc
FUN   9828   9828         15'738'992     960             &__dlmalloc
FUN   9828   9828         15'842'000     944           &caml_stat_alloc_noexc
FUN   9828   9828         15'876'000     944           &malloc
FUN   9828   9828         15'918'000     960             &__dlmalloc
FUN   9828   9828         15'952'992     944           &caml_stat_alloc_noexc
FUN   9828   9828         15'982'992     944           &malloc
FUN   9828   9828         15'994'000     960             &__dlmalloc
FUN   9828   9828         16'096'992     880       &caml_parse_ocamlrunparam
FUN   9828   9828         16'204'000     928         &caml_secure_getenv
FUN   9828   9828         16'308'992     928         &secure_getenv
FUN   9828   9828         16'422'992     960           &issetugid
FUN   9828   9828         16'514'992     992             &__getauxval
FUN   9828   9828         16'702'000     960           &getenv
FUN   9828   9828         16'792'000     928         &caml_secure_getenv
FUN   9828   9828         16'816'992     928         &secure_getenv
FUN   9828   9828         16'824'992     960           &issetugid
FUN   9828   9828         16'828'992     992             &__getauxval
FUN   9828   9828         16'832'992     960           &getenv
FUN   9828   9828         16'868'000     880       &caml_startup_aux
FUN   9828   9828         16'936'992     880       &caml_init_frame_descriptors
FUN   9828   9828         16'968'992     928         &caml_stat_alloc
FUN   9828   9828         17'038'992     960           &malloc
FUN   9828   9828         17'046'992     976             &__dlmalloc
FUN   9828   9828         17'112'992     928         &caml_stat_alloc
FUN   9828   9828         17'118'992     960           &malloc
FUN   9828   9828         17'122'992     976             &__dlmalloc
FUN   9828   9828         17'126'000     928         &caml_stat_alloc
FUN   9828   9828         17'130'000     960           &malloc
FUN   9828   9828         17'158'992     976             &__dlmalloc
FUN   9828   9828         17'688'992     928         &caml_stat_alloc
FUN   9828   9828         17'694'992     960           &malloc
FUN   9828   9828         17'698'992     976             &__dlmalloc
FUN   9828   9828         17'702'000     928         &caml_stat_alloc
FUN   9828   9828         17'704'992     960           &malloc
FUN   9828   9828         17'708'992     976             &__dlmalloc
FUN   9828   9828         17'712'000     928         &caml_stat_alloc
FUN   9828   9828         17'716'000     960           &malloc
FUN   9828   9828         17'718'992     976             &__dlmalloc
FUN   9828   9828         17'722'000     928         &caml_stat_alloc
FUN   9828   9828         17'724'992     960           &malloc
FUN   9828   9828         17'728'992     976             &__dlmalloc
FUN   9828   9828         17'732'000     928         &caml_stat_alloc
FUN   9828   9828         17'734'992     960           &malloc
FUN   9828   9828         17'738'000     976             &__dlmalloc
FUN   9828   9828         17'742'000     928         &caml_stat_alloc
FUN   9828   9828         17'744'992     960           &malloc
FUN   9828   9828         17'748'000     976             &__dlmalloc
FUN   9828   9828         17'752'000     928         &caml_stat_alloc
FUN   9828   9828         17'754'992     960           &malloc
FUN   9828   9828         17'758'000     976             &__dlmalloc
FUN   9828   9828         17'762'000     928         &caml_stat_alloc
FUN   9828   9828         17'778'000     960           &malloc
FUN   9828   9828         17'782'992     976             &__dlmalloc
FUN   9828   9828         17'786'000     928         &caml_stat_alloc
FUN   9828   9828         17'790'000     960           &malloc
FUN   9828   9828         17'792'992     976             &__dlmalloc
FUN   9828   9828         17'796'000     928         &caml_stat_alloc
FUN   9828   9828         17'800'000     960           &malloc
FUN   9828   9828         17'802'992     976             &__dlmalloc
FUN   9828   9828         17'806'000     928         &caml_stat_alloc
FUN   9828   9828         17'810'000     960           &malloc
FUN   9828   9828         17'812'992     976             &__dlmalloc
FUN   9828   9828         17'816'000     928         &caml_stat_alloc
FUN   9828   9828         17'820'000     960           &malloc
FUN   9828   9828         17'822'992     976             &__dlmalloc
FUN   9828   9828         17'826'000     928         &caml_stat_alloc
FUN   9828   9828         17'830'000     960           &malloc
FUN   9828   9828         17'832'992     976             &__dlmalloc
FUN   9828   9828         17'836'000     928         &caml_stat_alloc
FUN   9828   9828         17'838'992     960           &malloc
FUN   9828   9828         17'842'000     976             &__dlmalloc
FUN   9828   9828         17'846'000     928         &caml_stat_alloc
FUN   9828   9828         17'848'992     960           &malloc
FUN   9828   9828         17'852'000     976             &__dlmalloc
FUN   9828   9828         17'854'992     928         &caml_stat_alloc
FUN   9828   9828         17'858'992     960           &malloc
FUN   9828   9828         17'862'000     976             &__dlmalloc
FUN   9828   9828         17'864'992     928         &caml_stat_alloc
FUN   9828   9828         17'868'000     960           &malloc
FUN   9828   9828         17'870'992     976             &__dlmalloc
FUN   9828   9828         17'884'992     928         &caml_stat_alloc
FUN   9828   9828         17'890'000     960           &malloc
FUN   9828   9828         17'908'992     976             &__dlmalloc
FUN   9828   9828         17'914'000     928         &caml_stat_alloc
FUN   9828   9828         17'918'000     960           &malloc
FUN   9828   9828         17'922'000     976             &__dlmalloc
FUN   9828   9828         17'926'000     928         &caml_stat_alloc
FUN   9828   9828         17'928'992     960           &malloc
FUN   9828   9828         17'932'000     976             &__dlmalloc
FUN   9828   9828         17'936'000     928         &caml_stat_alloc
FUN   9828   9828         17'938'992     960           &malloc
FUN   9828   9828         17'942'000     976             &__dlmalloc
FUN   9828   9828         17'944'992     928         &caml_stat_alloc
FUN   9828   9828         17'948'992     960           &malloc
FUN   9828   9828         17'952'000     976             &__dlmalloc
FUN   9828   9828         17'954'992     928         &caml_stat_alloc
FUN   9828   9828         17'958'992     960           &malloc
FUN   9828   9828         17'962'000     976             &__dlmalloc
FUN   9828   9828         17'964'992     928         &caml_stat_alloc
FUN   9828   9828         17'968'992     960           &malloc
FUN   9828   9828         17'972'000     976             &__dlmalloc
FUN   9828   9828         17'974'992     928         &caml_stat_alloc
FUN   9828   9828         17'978'992     960           &malloc
FUN   9828   9828         18'010'000     976             &__dlmalloc
FUN   9828   9828         18'016'992     928         &caml_stat_alloc
FUN   9828   9828         18'022'000     960           &malloc
FUN   9828   9828         18'026'000     976             &__dlmalloc
FUN   9828   9828         18'030'000     928         &caml_stat_alloc
FUN   9828   9828         18'032'992     960           &malloc
FUN   9828   9828         18'036'000     976             &__dlmalloc
FUN   9828   9828         18'040'000     928         &caml_stat_alloc
FUN   9828   9828         18'044'000     960           &malloc
FUN   9828   9828         18'046'992     976             &__dlmalloc
FUN   9828   9828         18'050'000     928         &caml_stat_alloc
FUN   9828   9828         18'052'992     960           &malloc
FUN   9828   9828         18'056'992     976             &__dlmalloc
FUN   9828   9828         18'060'000     928         &caml_stat_alloc
FUN   9828   9828         18'062'992     960           &malloc
FUN   9828   9828         18'066'000     976             &__dlmalloc
FUN   9828   9828         18'070'000     928         &caml_stat_alloc
FUN   9828   9828         18'072'992     960           &malloc
FUN   9828   9828         18'076'000     976             &__dlmalloc
FUN   9828   9828         18'078'992     928         &caml_stat_alloc
FUN   9828   9828         18'082'992     960           &malloc
FUN   9828   9828         18'086'000     976             &__dlmalloc
FUN   9828   9828         18'088'992     928         &caml_stat_alloc
FUN   9828   9828         18'092'992     960           &malloc
FUN   9828   9828         18'096'000     976             &__dlmalloc
FUN   9828   9828         18'098'992     928         &caml_stat_alloc
FUN   9828   9828         18'110'992     960           &malloc
FUN   9828   9828         18'116'000     976             &__dlmalloc
FUN   9828   9828         18'120'000     928         &caml_stat_alloc
FUN   9828   9828         18'124'000     960           &malloc
FUN   9828   9828         18'126'992     976             &__dlmalloc
FUN   9828   9828         18'130'000     928         &caml_stat_alloc
FUN   9828   9828         18'134'000     960           &malloc
FUN   9828   9828         18'136'992     976             &__dlmalloc
FUN   9828   9828         18'140'000     928         &caml_stat_alloc
FUN   9828   9828         18'144'000     960           &malloc
FUN   9828   9828         18'146'992     976             &__dlmalloc
FUN   9828   9828         18'150'000     928         &caml_stat_alloc
FUN   9828   9828         18'154'000     960           &malloc
FUN   9828   9828         18'156'992     976             &__dlmalloc
FUN   9828   9828         18'160'000     928         &caml_stat_alloc
FUN   9828   9828         18'162'992     960           &malloc
FUN   9828   9828         18'166'992     976             &__dlmalloc
FUN   9828   9828         18'170'000     928         &caml_stat_alloc
FUN   9828   9828         18'174'000     960           &malloc
FUN   9828   9828         18'176'992     976             &__dlmalloc
FUN   9828   9828         18'180'000     928         &caml_stat_alloc
FUN   9828   9828         18'182'992     960           &malloc
FUN   9828   9828         18'186'992     976             &__dlmalloc
FUN   9828   9828         18'190'000     928         &caml_stat_alloc
FUN   9828   9828         18'192'992     960           &malloc
FUN   9828   9828         18'196'000     976             &__dlmalloc
FUN   9828   9828         18'200'000     928         &caml_stat_alloc
FUN   9828   9828         18'202'992     960           &malloc
FUN   9828   9828         18'206'000     976             &__dlmalloc
FUN   9828   9828         18'218'992     928         &caml_stat_alloc
FUN   9828   9828         18'222'992     960           &malloc
FUN   9828   9828         18'226'992     976             &__dlmalloc
FUN   9828   9828         18'230'000     928         &caml_stat_alloc
FUN   9828   9828         18'234'000     960           &malloc
FUN   9828   9828         18'236'992     976             &__dlmalloc
FUN   9828   9828         18'240'000     928         &caml_stat_alloc
FUN   9828   9828         18'244'000     960           &malloc
FUN   9828   9828         18'246'992     976             &__dlmalloc
FUN   9828   9828         18'250'000     928         &caml_stat_alloc
FUN   9828   9828         18'252'992     960           &malloc
FUN   9828   9828         18'256'000     976             &__dlmalloc
FUN   9828   9828         18'260'992     928         &caml_stat_alloc
FUN   9828   9828         18'264'000     960           &malloc
FUN   9828   9828         18'268'000     976             &__dlmalloc
FUN   9828   9828         18'270'992     928         &caml_stat_alloc
FUN   9828   9828         18'274'000     960           &malloc
FUN   9828   9828         18'276'992     976             &__dlmalloc
FUN   9828   9828         18'280'992     928         &caml_stat_alloc
FUN   9828   9828         18'284'000     960           &malloc
FUN   9828   9828         18'286'992     976             &__dlmalloc
FUN   9828   9828         18'290'000     928         &caml_stat_alloc
FUN   9828   9828         18'404'992     960           &malloc
FUN   9828   9828         18'412'992     976             &__dlmalloc
FUN   9828   9828         18'418'000     928         &caml_stat_alloc
FUN   9828   9828         18'472'000     960           &malloc
FUN   9828   9828         18'478'000     976             &__dlmalloc
FUN   9828   9828         18'482'992     928         &caml_stat_alloc
FUN   9828   9828         18'486'000     960           &malloc
FUN   9828   9828         18'490'000     976             &__dlmalloc
FUN   9828   9828         18'492'992     928         &caml_stat_alloc
FUN   9828   9828         18'496'000     960           &malloc
FUN   9828   9828         18'500'000     976             &__dlmalloc
FUN   9828   9828         18'502'992     928         &caml_stat_alloc
FUN   9828   9828         18'506'000     960           &malloc
FUN   9828   9828         18'508'992     976             &__dlmalloc
FUN   9828   9828         18'534'000     928         &caml_stat_alloc
FUN   9828   9828         18'580'000     960           &malloc
FUN   9828   9828         18'586'992     976             &__dlmalloc
FUN   9828   9828         18'590'992     928         &caml_stat_alloc
FUN   9828   9828         18'594'992     960           &malloc
FUN   9828   9828         18'598'000     976             &__dlmalloc
FUN   9828   9828         18'600'992     928         &caml_stat_alloc
FUN   9828   9828         18'604'992     960           &malloc
FUN   9828   9828         18'608'000     976             &__dlmalloc
FUN   9828   9828         18'636'992     880       &init_frame_descriptors
FUN   9828   9828         18'832'992     928         &caml_stat_alloc
FUN   9828   9828         18'840'992     960           &malloc
FUN   9828   9828         18'844'000     976             &__dlmalloc
FUN   9828   9828         18'896'000   1'040               &sys_alloc.constprop.0
FUN   9828   9828         19'022'992   1'152                 &dlmalloc_requires_more_vespene_gas
FUN   9828   9828         19'070'992   1'168                   &_mapanon
FUN   9828   9828         19'136'992   1'200                     &mmap
FUN   9828   9828         19'170'992   1'296                       &__mmi_lock
FUN   9828   9828         19'192'000   1'312                         &pthread_mutex_lock
FUN   9828   9828         19'272'992   1'360                           &gettid
FUN   9828   9828         19'484'992   1'296                       &__mmap_unlocked
FUN   9828   9828         19'588'000   1'456                         &getauxval
FUN   9828   9828         19'628'992   1'488                           &__getauxval
FUN   9828   9828         19'754'000   1'456                         &__find_memory
FUN   9828   9828         19'968'992   1'456                         &__choose_memory.constprop.0
FUN   9828   9828         20'068'000   1'520                           &__find_memory
FUN   9828   9828         20'250'000   1'456                         &sys_mmap
FUN   9828   9828         20'280'992   1'472                           &__sys_mmap
FUN   9828   9828         20'304'000   1'472                           &systemfive
FUN   9828   9828         20'420'992   1'456                         &__finish_memory.constprop.0.isra.0
FUN   9828   9828         20'524'000   1'552                           &__track_memory
FUN   9828   9828         20'602'000   1'648                             &__find_memory
FUN   9828   9828         20'662'000   1'648                             &__mint_memory
FUN   9828   9828         20'756'000   1'696                               &__shove_memory.isra.0
FUN   9828   9828         21'014'992   1'296                       &__mmi_unlock
FUN   9828   9828         21'078'992   1'312                         &pthread_mutex_unlock
FUN   9828   9828         21'118'000   1'344                           &gettid
FUN   9828   9828         21'732'992     928         &fill_hashtable
FUN   9828   9828         21'804'992     976           &next_frame_descr
FUN   9828   9828         22'836'992     880       &caml_init_locale
FUN   9828   9828         22'902'000     912         &newlocale
FUN   9828   9828         22'936'992     880       &caml_init_custom_operations
FUN   9828   9828         22'954'992     912         &caml_stat_alloc
FUN   9828   9828         22'960'992     944           &malloc
FUN   9828   9828         22'966'000     960             &__dlmalloc
FUN   9828   9828         23'098'000     912         &caml_stat_alloc
FUN   9828   9828         23'118'992     944           &malloc
FUN   9828   9828         23'124'992     960             &__dlmalloc
FUN   9828   9828         23'160'992     912         &caml_stat_alloc
FUN   9828   9828         23'170'992     944           &malloc
FUN   9828   9828         23'178'992     960             &__dlmalloc
FUN   9828   9828         23'200'992     912         &caml_stat_alloc
FUN   9828   9828         23'208'000     944           &malloc
FUN   9828   9828         23'236'000     960             &__dlmalloc
FUN   9828   9828         23'296'000     880       &caml_init_gc
FUN   9828   9828         23'368'000   1'008         &caml_page_table_initialize
FUN   9828   9828         23'420'992   1'056           &caml_stat_alloc_noexc
FUN   9828   9828         23'482'992   1'056           &malloc
FUN   9828   9828         23'492'992   1'072             &__dlmalloc
FUN   9828   9828         23'522'000   1'056           &memset
FUN   9828   9828         23'714'000   1'008         &caml_set_minor_heap_size
FUN   9828   9828         23'756'000   1'072           &caml_stat_alloc_aligned_noexc
FUN   9828   9828         23'820'000   1'104             &caml_stat_alloc_noexc
FUN   9828   9828         23'848'000   1'104             &malloc
FUN   9828   9828         23'856'992   1'120               &__dlmalloc
FUN   9828   9828         23'862'000   1'184                 &sys_alloc.constprop.0
FUN   9828   9828         23'926'992   1'296                   &dlmalloc_requires_more_vespene_gas
FUN   9828   9828         23'938'000   1'312                     &_mapanon
FUN   9828   9828         23'944'000   1'344                       &mmap
FUN   9828   9828         23'968'000   1'440                         &__mmi_lock
FUN   9828   9828         23'992'000   1'456                           &pthread_mutex_lock
FUN   9828   9828         24'032'000   1'504                             &gettid
FUN   9828   9828         24'042'000   1'440                         &__mmap_unlocked
FUN   9828   9828         24'046'992   1'600                           &getauxval
FUN   9828   9828         24'066'992   1'632                             &__getauxval
FUN   9828   9828         24'092'000   1'600                           &__find_memory
FUN   9828   9828         24'130'000   1'600                           &__choose_memory.constprop.0
FUN   9828   9828         24'180'000   1'664                             &__find_memory
FUN   9828   9828         24'204'992   1'600                           &sys_mmap
FUN   9828   9828         24'258'992   1'616                             &__sys_mmap
FUN   9828   9828         24'266'992   1'616                             &systemfive
FUN   9828   9828         24'306'992   1'600                           &__finish_memory.constprop.0.isra.0
FUN   9828   9828         24'314'000   1'696                             &__track_memory
FUN   9828   9828         24'320'000   1'792                               &__find_memory
FUN   9828   9828         24'326'000   1'792                               &__mint_memory
FUN   9828   9828         24'330'992   1'840                                 &__shove_memory.isra.0
FUN   9828   9828         24'356'000   1'440                         &__mmi_unlock
FUN   9828   9828         24'404'992   1'456                           &pthread_mutex_unlock
FUN   9828   9828         24'438'000   1'488                             &gettid
FUN   9828   9828         24'590'992   1'072           &caml_page_table_add
FUN   9828   9828         24'646'992   1'120             &caml_page_table_modify
FUN   9828   9828         25'100'000   1'072           &caml_memprof_renew_minor_sample
FUN   9828   9828         25'204'000   1'072           &caml_update_young_limit
FUN   9828   9828         25'332'000   1'008         &caml_set_allocation_policy
FUN   9828   9828         25'438'000   1'008         &caml_init_major_heap
FUN   9828   9828         25'516'992   1'056           &caml_alloc_for_heap
FUN   9828   9828         25'574'000   1'088             &caml_stat_alloc_noexc
FUN   9828   9828         25'630'992   1'088             &malloc
FUN   9828   9828         25'640'992   1'104               &__dlmalloc
FUN   9828   9828         25'646'000   1'168                 &sys_alloc.constprop.0
FUN   9828   9828         25'652'000   1'280                   &dlmalloc_requires_more_vespene_gas
FUN   9828   9828         25'658'000   1'296                     &_mapanon
FUN   9828   9828         25'662'000   1'328                       &mmap
FUN   9828   9828         25'684'000   1'424                         &__mmi_lock
FUN   9828   9828         25'730'000   1'440                           &pthread_mutex_lock
FUN   9828   9828         25'756'992   1'488                             &gettid
FUN   9828   9828         25'764'992   1'424                         &__mmap_unlocked
FUN   9828   9828         25'770'000   1'584                           &getauxval
FUN   9828   9828         25'772'992   1'616                             &__getauxval
FUN   9828   9828         25'778'000   1'584                           &__find_memory
FUN   9828   9828         25'782'000   1'584                           &__choose_memory.constprop.0
FUN   9828   9828         25'786'000   1'648                             &__find_memory
FUN   9828   9828         25'790'992   1'584                           &sys_mmap
FUN   9828   9828         25'794'992   1'600                             &__sys_mmap
FUN   9828   9828         25'798'992   1'600                             &systemfive
FUN   9828   9828         25'818'000   1'584                           &__finish_memory.constprop.0.isra.0
FUN   9828   9828         25'846'000   1'680                             &__track_memory
FUN   9828   9828         25'870'992   1'776                               &__find_memory
FUN   9828   9828         25'880'000   1'776                               &__mint_memory
FUN   9828   9828         25'886'992   1'824                                 &__shove_memory.isra.0
FUN   9828   9828         25'894'000   1'424                         &__mmi_unlock
FUN   9828   9828         25'916'000   1'440                           &pthread_mutex_unlock
FUN   9828   9828         25'924'000   1'472                             &gettid
FUN   9828   9828         26'026'992   1'056           &caml_page_table_add
FUN   9828   9828         26'054'000   1'104             &caml_page_table_modify
FUN   9828   9828         26'156'992   1'056           &bf_init_merge
FUN   9828   9828         26'266'000   1'056           &bf_make_free_blocks
FUN   9828   9828         26'394'992   1'136             &bf_insert_block
FUN   9828   9828         26'498'000   1'056           &caml_stat_alloc_noexc
FUN   9828   9828         26'526'000   1'056           &malloc
FUN   9828   9828         26'534'992   1'072             &__dlmalloc
FUN   9828   9828         26'560'000   1'056           &caml_stat_alloc_noexc
FUN   9828   9828         26'566'000   1'056           &malloc
FUN   9828   9828         26'568'992   1'072             &__dlmalloc
FUN   9828   9828         26'600'992   1'008         &memset
FUN   9828   9828         26'678'992   1'008         &caml_gc_message
FUN   9828   9828         26'806'992     880       &caml_init_atom_table
FUN   9828   9828         26'824'992     912         &caml_stat_alloc_aligned_noexc
FUN   9828   9828         26'830'992     944           &caml_stat_alloc_noexc
FUN   9828   9828         26'836'000     944           &malloc
FUN   9828   9828         26'840'992     960             &__dlmalloc
FUN   9828   9828         26'880'000     912         &caml_page_table_add
FUN   9828   9828         26'904'992     960           &caml_page_table_modify
FUN   9828   9828         26'936'000     880       &caml_page_table_add
FUN   9828   9828         26'942'000     928         &caml_page_table_modify
FUN   9828   9828         26'992'000     880       &caml_page_table_add
FUN   9828   9828         27'004'000     928         &caml_page_table_modify
FUN   9828   9828         27'010'000     880       &caml_page_table_add
FUN   9828   9828         27'014'992     928         &caml_page_table_modify
FUN   9828   9828         27'020'992     880       &caml_page_table_add
FUN   9828   9828         27'026'000     928         &caml_page_table_modify
FUN   9828   9828         27'068'992     880       &caml_page_table_add
FUN   9828   9828         27'076'992     928         &caml_page_table_modify
FUN   9828   9828         27'082'000     880       &caml_page_table_add
FUN   9828   9828         27'086'000     928         &caml_page_table_modify
FUN   9828   9828         27'090'000     880       &caml_page_table_add
FUN   9828   9828         27'094'000     928         &caml_page_table_modify
FUN   9828   9828         27'098'992     880       &caml_page_table_add
FUN   9828   9828         27'104'000     928         &caml_page_table_modify
FUN   9828   9828         27'108'992     880       &caml_page_table_add
FUN   9828   9828         27'114'000     928         &caml_page_table_modify
FUN   9828   9828         27'118'992     880       &caml_page_table_add
FUN   9828   9828         27'122'992     928         &caml_page_table_modify
FUN   9828   9828         27'126'992     880       &caml_page_table_add
FUN   9828   9828         27'130'992     928         &caml_page_table_modify
FUN   9828   9828         27'134'000     880       &caml_page_table_add
FUN   9828   9828         27'138'992     928         &caml_page_table_modify
FUN   9828   9828         27'144'000     880       &caml_page_table_add
FUN   9828   9828         27'148'992     928         &caml_page_table_modify
FUN   9828   9828         27'154'000     880       &caml_page_table_add
FUN   9828   9828         27'158'992     928         &caml_page_table_modify
FUN   9828   9828         27'164'000     880       &caml_page_table_add
FUN   9828   9828         27'168'992     928         &caml_page_table_modify
FUN   9828   9828         27'174'992     880       &caml_page_table_add
FUN   9828   9828         27'178'992     928         &caml_page_table_modify
FUN   9828   9828         27'184'000     880       &caml_page_table_add
FUN   9828   9828         27'188'992     928         &caml_page_table_modify
FUN   9828   9828         27'194'000     880       &caml_page_table_add
FUN   9828   9828         27'200'000     928         &caml_page_table_modify
FUN   9828   9828         27'204'992     880       &caml_page_table_add
FUN   9828   9828         27'210'000     928         &caml_page_table_modify
FUN   9828   9828         27'214'992     880       &caml_page_table_add
FUN   9828   9828         27'232'000     928         &caml_page_table_modify
FUN   9828   9828         27'238'000     880       &caml_page_table_add
FUN   9828   9828         27'242'992     928         &caml_page_table_modify
FUN   9828   9828         27'248'000     880       &caml_page_table_add
FUN   9828   9828         27'252'992     928         &caml_page_table_modify
FUN   9828   9828         27'258'000     880       &caml_page_table_add
FUN   9828   9828         27'262'992     928         &caml_page_table_modify
FUN   9828   9828         27'268'000     880       &caml_page_table_add
FUN   9828   9828         27'272'992     928         &caml_page_table_modify
FUN   9828   9828         27'278'000     880       &caml_page_table_add
FUN   9828   9828         27'282'992     928         &caml_page_table_modify
FUN   9828   9828         27'288'000     880       &caml_page_table_add
FUN   9828   9828         27'292'992     928         &caml_page_table_modify
FUN   9828   9828         27'298'000     880       &caml_page_table_add
FUN   9828   9828         27'302'992     928         &caml_page_table_modify
FUN   9828   9828         27'308'992     880       &caml_page_table_add
FUN   9828   9828         27'312'992     928         &caml_page_table_modify
FUN   9828   9828         27'318'000     880       &caml_page_table_add
FUN   9828   9828         27'322'992     928         &caml_page_table_modify
FUN   9828   9828         27'340'000     880       &caml_page_table_add
FUN   9828   9828         27'344'992     928         &caml_page_table_modify
FUN   9828   9828         27'350'000     880       &caml_page_table_add
FUN   9828   9828         27'354'992     928         &caml_page_table_modify
FUN   9828   9828         27'360'000     880       &caml_page_table_add
FUN   9828   9828         27'366'000     928         &caml_page_table_modify
FUN   9828   9828         27'370'992     880       &caml_page_table_add
FUN   9828   9828         27'374'992     928         &caml_page_table_modify
FUN   9828   9828         27'380'992     880       &caml_page_table_add
FUN   9828   9828         27'384'992     928         &caml_page_table_modify
FUN   9828   9828         27'390'000     880       &caml_page_table_add
FUN   9828   9828         27'394'992     928         &caml_page_table_modify
FUN   9828   9828         27'400'992     880       &caml_page_table_add
FUN   9828   9828         27'406'000     928         &caml_page_table_modify
FUN   9828   9828         27'410'992     880       &caml_page_table_add
FUN   9828   9828         27'416'000     928         &caml_page_table_modify
FUN   9828   9828         27'420'992     880       &caml_page_table_add
FUN   9828   9828         27'424'992     928         &caml_page_table_modify
FUN   9828   9828         27'438'992     880       &caml_page_table_add
FUN   9828   9828         27'446'000     928         &caml_page_table_modify
FUN   9828   9828         27'452'000     880       &caml_page_table_add
FUN   9828   9828         27'456'000     928         &caml_page_table_modify
FUN   9828   9828         27'460'992     880       &caml_page_table_add
FUN   9828   9828         27'466'000     928         &caml_page_table_modify
FUN   9828   9828         27'470'992     880       &caml_page_table_add
FUN   9828   9828         27'476'000     928         &caml_page_table_modify
FUN   9828   9828         27'480'992     880       &caml_page_table_add
FUN   9828   9828         27'486'000     928         &caml_page_table_modify
FUN   9828   9828         27'492'000     880       &caml_page_table_add
FUN   9828   9828         27'496'992     928         &caml_page_table_modify
FUN   9828   9828         27'502'000     880       &caml_page_table_add
FUN   9828   9828         27'506'992     928         &caml_page_table_modify
FUN   9828   9828         27'512'000     880       &caml_page_table_add
FUN   9828   9828         27'516'992     928         &caml_page_table_modify
FUN   9828   9828         27'522'000     880       &caml_page_table_add
FUN   9828   9828         27'526'000     928         &caml_page_table_modify
FUN   9828   9828         27'530'000     880       &caml_page_table_add
FUN   9828   9828         27'532'992     928         &caml_page_table_modify
FUN   9828   9828         27'546'992     880       &caml_page_table_add
FUN   9828   9828         27'552'992     928         &caml_page_table_modify
FUN   9828   9828         27'558'992     880       &caml_page_table_add
FUN   9828   9828         27'564'000     928         &caml_page_table_modify
FUN   9828   9828         27'568'992     880       &caml_page_table_add
FUN   9828   9828         27'574'000     928         &caml_page_table_modify
FUN   9828   9828         27'578'000     880       &caml_page_table_add
FUN   9828   9828         27'582'992     928         &caml_page_table_modify
FUN   9828   9828         27'586'992     880       &caml_page_table_add
FUN   9828   9828         27'592'000     928         &caml_page_table_modify
FUN   9828   9828         27'596'000     880       &caml_page_table_add
FUN   9828   9828         27'600'992     928         &caml_page_table_modify
FUN   9828   9828         27'606'992     880       &caml_page_table_add
FUN   9828   9828         27'610'992     928         &caml_page_table_modify
FUN   9828   9828         27'616'992     880       &caml_page_table_add
FUN   9828   9828         27'620'000     928         &caml_page_table_modify
FUN   9828   9828         27'626'000     880       &caml_page_table_add
FUN   9828   9828         27'630'992     928         &caml_page_table_modify
FUN   9828   9828         27'636'000     880       &caml_page_table_add
FUN   9828   9828         27'640'992     928         &caml_page_table_modify
FUN   9828   9828         27'656'000     880       &caml_page_table_add
FUN   9828   9828         27'682'000     928         &caml_page_table_modify
FUN   9828   9828         27'690'992     880       &caml_page_table_add
FUN   9828   9828         27'694'992     928         &caml_page_table_modify
FUN   9828   9828         27'784'000     880       &caml_register_code_fragment
FUN   9828   9828         27'812'000     944         &caml_stat_alloc
FUN   9828   9828         27'818'000     976           &malloc
FUN   9828   9828         27'824'000     992             &__dlmalloc
FUN   9828   9828         27'882'000     944         &caml_skiplist_insert
FUN   9828   9828         27'950'000   1'136           &caml_stat_alloc
FUN   9828   9828         27'970'992   1'168             &malloc
FUN   9828   9828         27'994'000   1'184               &__dlmalloc
FUN   9828   9828         28'030'992     944         &caml_skiplist_insert
FUN   9828   9828         28'036'992   1'136           &caml_stat_alloc
FUN   9828   9828         28'042'992   1'168             &malloc
FUN   9828   9828         28'046'992   1'184               &__dlmalloc
FUN   9828   9828         28'068'000     880       &caml_register_code_fragment
FUN   9828   9828         28'074'000     944         &caml_stat_alloc
FUN   9828   9828         28'078'992     976           &malloc
FUN   9828   9828         28'096'992     992             &__dlmalloc
FUN   9828   9828         28'102'992     944         &caml_skiplist_insert
FUN   9828   9828         28'124'992   1'136           &caml_stat_alloc
FUN   9828   9828         28'130'000   1'168             &malloc
FUN   9828   9828         28'134'992   1'184               &__dlmalloc
FUN   9828   9828         28'140'000     944         &caml_skiplist_insert
FUN   9828   9828         28'144'992   1'136           &caml_stat_alloc
FUN   9828   9828         28'150'000   1'168             &malloc
FUN   9828   9828         28'154'000   1'184               &__dlmalloc
FUN   9828   9828         28'168'992     880       &caml_init_signals
FUN   9828   9828         28'206'992     880       &caml_init_backtrace
FUN   9828   9828         28'228'992     880       &caml_register_global_root
FUN   9828   9828         28'242'000     880       &caml_skiplist_insert
FUN   9828   9828         28'248'000   1'072         &caml_stat_alloc
FUN   9828   9828         28'252'992   1'104           &malloc
FUN   9828   9828         28'258'000   1'120             &__dlmalloc
FUN   9828   9828         28'274'992     880       &caml_debugger_init
FUN   9828   9828         28'344'992     880       &caml_executable_name
FUN   9828   9828         28'374'000     880       &caml_search_exe_in_path
FUN   9828   9828         28'412'992     928         &caml_ext_table_init
FUN   9828   9828         28'434'992     960           &caml_stat_alloc
FUN   9828   9828         28'440'992     992             &malloc
FUN   9828   9828         28'446'000   1'008               &__dlmalloc
FUN   9828   9828         28'462'000     928         &getenv
FUN   9828   9828         28'556'992     928         &caml_decompose_path
FUN   9828   9828         28'600'992     976           &caml_stat_strdup
FUN   9828   9828         28'656'000   1'024             &strlen
FUN   9828   9828         28'800'000   1'024             &caml_stat_alloc_noexc
FUN   9828   9828         28'828'000   1'024             &malloc
FUN   9828   9828         28'852'000   1'040               &__dlmalloc
FUN   9828   9828         28'908'992   1'024             &memmove
FUN   9828   9828         29'022'000     976           &caml_ext_table_add
FUN   9828   9828         29'146'992     928         &caml_search_in_path
FUN   9828   9828         29'188'000   1'136           &caml_stat_strdup
FUN   9828   9828         29'196'000   1'184             &strlen
FUN   9828   9828         29'208'992   1'184             &caml_stat_alloc_noexc
FUN   9828   9828         29'212'992   1'184             &malloc
FUN   9828   9828         29'216'992   1'200               &__dlmalloc
FUN   9828   9828         29'220'992   1'184             &memmove
FUN   9828   9828         29'274'992     928         &caml_stat_free
FUN   9828   9828         29'326'000     928         &free
FUN   9828   9828         29'352'000     944           &__dlfree
FUN   9828   9828         29'582'000     928         &caml_ext_table_free
FUN   9828   9828         29'612'000     928         &caml_stat_free
FUN   9828   9828         29'662'000     928         &free
FUN   9828   9828         29'670'992     944           &__dlfree
FUN   9828   9828         29'788'000     880       &caml_sys_init
FUN   9828   9828         29'818'992     912         &caml_alloc_array
FUN   9828   9828         29'884'000   1'056           &caml_alloc
FUN   9828   9828         29'980'992   1'056           &caml_copy_string
FUN   9828   9828         30'026'992   1'104             &strlen
FUN   9828   9828         30'066'000   1'104             &caml_alloc_string
FUN   9828   9828         30'154'000   1'104             &memmove
FUN   9828   9828         30'186'000   1'056           &caml_modify
FUN   9828   9828         30'276'000     880       &caml_register_generational_global_root
FUN   9828   9828         30'344'000     880       &caml_skiplist_insert
FUN   9828   9828         30'368'992   1'072         &caml_stat_alloc
FUN   9828   9828         30'374'992   1'104           &malloc
FUN   9828   9828         30'380'000   1'120             &__dlmalloc
FUN   9828   9828         30'406'992     880       &_setjmp
00000000: 5361 6c75 740a                           Salut.

The artifact was made with aarch64-unknown-cosmo-cc on one side and x86_64-unknown-cosmo-cc on the other side. These artifact was linked together with:

$ apelink -o xxd.com \
     -l $(opam var bin)/ape-x86_64.elf \
     -l $(opam var bin)/ape-aarch64.elf \
     -M $(opam var bin)/ape-m1.c \
     _build/bin/x86_64-esperanto/xxd.exe.dbg \
     _build/bin/aarch64-esperanto/xxd.exe.dbg

These artifacts was built with dune and the Esperanto toolchain.

xxd.zip

jart commented 11 months ago

Here's some examples of ways you could troubleshoot this.

  1. Try putting ShowCrashReports() at the top of your main() function. You'll need to #include <cosmo.h>. This should cause a crash report to be printed to stderr, provided signals aren't blocked.

  2. You should be able to gdb xxd.aarch64.elf and set a break setjmp and then stepi until it crashes, so you can poke around and see what specific thing is doing it. Saying layout asm and layout reg in gdb can be helpful if it's an assembly level error. Otherwise layout src and layout reg for source tui.

That should hopefully give us some additional clues. I'm also surprised your terminal didn't print Segmentation fault. since xxd appears to be successfully printing its output in your trace.

jart commented 11 months ago

Another thing worth noting for GDB debugging, is I'm ashamed to admit you might want to create a symlink named /home/jart/cosmo that points to your cosmopolitan mono repo directory. That way you'll be able to see the libc source code when you debug.

dinosaure commented 11 months ago

I made a simpler program:

let () = print_endline "Hello World!"

Again, with ./main.aarch64.exe.dbg --strace, the program works well on linux/arm64 arm64v8/ubuntu. But without the --strace option, it segfaults again. I tried to use gdb but if I do break setjmp, run, the program fails with:

(gdb) break setjmp
Breakpoint 1 at 0x10000041f24: file libc/nexgen32e/setjmp.S, line 31.
(gdb) run
Starting program: /root/main.aarch64.exe.dbg 
warning: Error disabling address space randomization: Operation not permitted
warning: Could not trace the inferior process.
warning: ptrace: Function not implemented
During startup program exited with code 127.
(gdb) 

Not sure how to debug this situation. I upload the artifiact made by the esperanto toolchain here: main.aarch64.exe.zip.

dinosaure commented 11 months ago

POST: I noticed that a core-dump was made by qemu (due to docker run + qemu). So I uploaded it here: dump.zip

And I can see that from gdb:

(gdb) where
#0  0x000001000004116c in ?? ()
#1  0x0000000000100000 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
jart commented 11 months ago

Your qemu-aarch64 docker environment looks broken. Even when qemu + gdb works, it's painful. You'll have a much better experience if you get something like a Raspberry Pi so you can do your debugging on the genuine article.

dinosaure commented 11 months ago

I finally got an aarch64 machine and, indeed, the gdb output is much better than a docker with qemu. With the same main.aarch64.elf artifact, I have this output:

(gdb) run
Starting program: /root/main.aarch64.elf 

Program received signal SIGSEGV, Segmentation fault.
pthread_mutex_lock (mutex=0x10000078560 <__mmi_lock_obj>) at ./libc/thread/tls.h:76
76  ./libc/thread/tls.h: No such file or directory.
(gdb) where
#0  pthread_mutex_lock (mutex=0x10000078560 <__mmi_lock_obj>) at ./libc/thread/tls.h:76
#1  0x0000010000040fd0 in __mmi_lock () at libc/intrin/mmi_lock.c:27
#2  0x0000010000034ad4 in mmap (addr=0x0, size=131072, prot=3, flags=34, fd=-1, off=0) at libc/runtime/mmap.c:478
#3  0x0000010000033dc0 in _mapanon (size=131072) at libc/runtime/mapanon.c:61
#4  0x0000010000033468 in dlmalloc_requires_more_vespene_gas (size=<optimized out>) at third_party/dlmalloc/vespene.c:31
#5  0x00000100000307f8 in sys_alloc (nb=nb@entry=65632, m=0x100000802b8 <_gm_>) at third_party/dlmalloc/dlmalloc.c:187
#6  0x00000100000312c4 in __dlmalloc (bytes=65616) at third_party/dlmalloc/dlmalloc.c:712
#7  0x000001000002ea60 in malloc (n=<optimized out>) at libc/mem/malloc.c:46
#8  0x0000010000009a7c in caml_stat_alloc_noexc (sz=65616) at memory.c:799
#9  caml_stat_alloc (sz=65616) at memory.c:821
#10 0x000001000000fbf8 in caml_open_descriptor_in (fd=0) at io.c:98
#11 0x0000010000010ba4 in caml_ml_open_descriptor_in (fd=<optimized out>) at io.c:517
#12 0x0000010000022ab4 in caml_c_call ()
#13 0x0000010000004864 in camlStdlib__entry () at stdlib.ml:314
#14 0x00000100000014d4 in caml_program ()
#15 0x0000010000022b24 in caml_start_program ()
#16 0x0000010000023384 in caml_startup_common (argv=0x10000075c28, pooling=<optimized out>, pooling@entry=0) at startup_nat.c:160
#17 0x000001000002345c in caml_startup_exn (argv=<optimized out>) at startup_nat.c:167
#18 caml_startup (argv=<optimized out>) at startup_nat.c:172
#19 caml_main (argv=<optimized out>) at startup_nat.c:179
#20 0x000001000000059c in main (argc=<optimized out>, argv=<optimized out>) at main.c:37
#21 0x0000010000000d30 in cosmo (sp=0xfffffffff3d0, m1=0x0) at libc/runtime/cosmo2.c:177
#22 0x0000010000000144 in _start () at libc/crt/crt.S:144
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) display i/$pc
1: x/i $pc
=> 0x1000004116c <pthread_mutex_lock>:  ldur    x1, [x28, #-128]
(gdb) info registers
x0             0x10000078560       1099512120672
x1             0x20000             131072
x2             0x3                 3
x3             0x22                34
x4             0xffffffff          4294967295
x5             0x0                 0
x6             0x100000741f0       1099512103408
x7             0x10000075cc0       1099512110272
x8             0x10000010b8c       1099511696268
x9             0x10000075cd8       1099512110296
x10            0x10000074068       1099512103016
x11            0x10000075cf0       1099512110320
x12            0x4fd               1277
x13            0x10000075d08       1099512110344
x14            0x7fffffffffffffff  9223372036854775807
x15            0x10000075d20       1099512110368
x16            0xfffffffff120      281474976706848
x17            0x10000001498       1099511633048
x18            0x0                 0
x19            0xffffffff          4294967295
x20            0x20000             131072
x21            0x0                 0
x22            0x20000             131072
x23            0x3                 3
x24            0x22                34
x25            0x0                 0
x26            0xfffffffff140      281474976706880
x27            0x100080400f40      17594337726272
x28            0x100080040010      17594333790224
x29            0xffffffffef60      281474976706400
x30            0x10000040fd0       1099511893968
sp             0xffffffffef60      0xffffffffef60
pc             0x1000004116c       0x1000004116c <pthread_mutex_lock>
cpsr           0x80001000          [ EL=0 BTYPE=0 SSBS N ]
fpsr           0x0                 [ ]
fpcr           0x0                 [ RMode=0 ]

It seems related to pthread_mutex_lock. EDIT: it's more about TLS than pthread_mutex_lock. I think, it's the __get_tls function. So it's probably related to how I link the program?

jart commented 11 months ago

Now that's very interesting. Thanks for getting the RasPi. That's going to make it much easier for me to support you.

On AARCH64, Cosmopolitan reserves the x28 register for itself. It's the Libc register. We need it in order to do thread-local storage in such a way that it'll work on platforms like Apple Silicon, be easy, and most importantly be fast. In order for it to work, cosmocc is designed to compile every single module in your application using the -ffixed-x28 flag.

There's two likely causes of this issue:

  1. There's some Ocaml assembly source code somewhere, that was handwritten, which is clobbering x28. In that case, you need to change the assembly code to leave x28 alone.
  2. You compiled one of your modules using something other than cosmocc.

Hope this helps!

dinosaure commented 11 months ago

There's some Ocaml assembly source code somewhere, that was handwritten, which is clobbering x28. In that case, you need to change the assembly code to leave x28 alone.

I think that's the case, OCaml seems to use x28 to store the state of the domain (something like a metadata needed by the OCaml runtime). It seems that you fix x18 also, should I try to inhibit OCaml to not use these registers?

jart commented 11 months ago

Yes x18 is the platform register. We can't use it because Apple reserves it. https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms

dinosaure commented 10 months ago

I'm finally able to produce an executable with OCaml which works. I restricted OCaml to use less registers and let x28 free for Cosmopolitan (I decided to took x25 instead). So now it works :tada: for small projects. I hope that it will works for bigger projects! The patch on the OCaml compiler is available here.