FlatAssembler / ArithmeticExpressionCompiler

A compiler for my own simple low-level programming language, built in JavaScript using the Duktape framework. Produces code compatible with FlatAssembler. Superseded by AECforWebAssembly.
https://flatassembler.github.io/compiler.html
3 stars 0 forks source link

"Analog Clock" crashes on HaikuOS #7

Open FlatAssembler opened 3 years ago

FlatAssembler commented 3 years ago

I just noticed that the analogClock.aec example from ArithmeticExpressionCompiler.zip, when compiled and assembled on HaikuOS, crashes before exiting. It works on Linux and FreeBSD. The assembly code produced by the compiler is in the attachment. analogClock.s.zip Here is what happens on Linux: analogClockForLinux And here is what happens of HaikuOS: HaikuError I do not know what causes it, as GDB on HaikuOS apparently refuses to disassemble the part of the program that crashes. Or maybe I am doing something wrong, as I don't know much GDB: HaikuDebugging

pulkomandy commented 3 years ago

Hi! gdb in Haiku doesn't work very well. If you select "debug" in the crash dialog you will get Haiku own debugger, where you should be able to get disassembly and backtrace information. Or you can select "save debug report" to put said information in a textfile that you can easily share (if you need other people to look into the problem)

FlatAssembler commented 3 years ago

Hi! gdb in Haiku doesn't work very well. If you select "debug" in the crash dialog you will get Haiku own debugger, where you should be able to get disassembly and backtrace information. Or you can select "save debug report" to put said information in a textfile that you can easily share (if you need other people to look into the problem)

To be honest, I know next-to-nothing about debugging. I have jumped into compiler development very unprepared. I have uploaded the assembly code that my compiler produced, it can be compiled by setarch x86 (to switch to a modern-ish version of GNU Assembler) and then gcc -o analogClock analogClock.s, so you can easily see what is happening if you are willing to help.

FlatAssembler commented 3 years ago

OK, here is a report from the Haiku debugger in case it helps (and I do not understand how it could help more than the assembly code easily assembled using GNU Assembler). It is not as easy to upload it since none of the browsers working on Haiku work with GitHub well enough to upload files, and VirtualBox guest additions also don't seem to work on Haiku. Thankfully, VirtualBox supports USBs, so I could transfer the files between the host Linux and Haiku in VirtualBox using a USB stick. analogClock-780-debug-07-01-2021-07-13-19.txt

kenmays commented 3 years ago

There are some conditions mentioned:

  1. operands invalid for 'fcomip' <-- GCC2

You can run 'Debugger analogClock' and run the your application from Debugger's GUI. You'll see its gdb similariities for walking through your program and backtracing.

FlatAssembler commented 3 years ago

As far as I understand it, that "operands invalid for 'fcomip'" is caused by the archaic version of GNU Assembler (one that comes with GCC2) not supporting the "fcomip" instruction (or, more likely, supporting it with some other syntax). The GNU Assembler that comes with GCC 7 (try "setarch x86") does not complain about that.

On Thu, Jan 7, 2021 at 4:02 PM kenmays notifications@github.com wrote:

There are some conditions mentioned:

  1. operands invalid for 'fcomip' <-- (this might be the culprit)
  2. Unknown pseudo-ops: '.cfi_def_cfa {_startproc/_escape/_restore/_endproc}'

You can run 'Debugger analagClock' and run the your application from Debugger's GUI. You'll see its gdb similariities for walking through your program and backtracing.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/FlatAssembler/ArithmeticExpressionCompiler/issues/7#issuecomment-756169848, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALA7APJDQ5DT2SE6NL43TA3SYXEJRANCNFSM4VR76YWQ .

-- Teo

pulkomandy commented 3 years ago

The crash seems to be in the code of Haiku that handles cleaning up after the main function terminates. It's probably because the generated asm does not include the expected structures to handle the cleanup, and our code in Haiku doesn't handle that properly?

FlatAssembler commented 3 years ago

The crash seems to be in the code of Haiku that handles cleaning up after the main function terminates. It's probably because the generated asm does not include the expected structures to handle the cleanup, and our code in Haiku doesn't handle that properly?

Well, that sounds believable. But what exactly should I do then? In what way does Haiku expect programs to terminate?

pulkomandy commented 3 years ago

I think we should fix our code on Haiku side to not crash when this happens.

FlatAssembler commented 3 years ago

I think we should fix our code on Haiku side to not crash when this happens.

Well, it is clearly possible to write an assembly-language program that will run on both 32-bit Linux and 32-bit HaikuOS without modification, for example, FlatAssembler does. So, you dare doing operating system development? Oh, you brave soul! Sounds like an incredibly frustrating job.