amiga-gcc icon indicating copy to clipboard operation
amiga-gcc copied to clipboard

Crashes on 68000 CPU when exceptions are enabled

Open rosneru opened this issue 4 years ago • 20 comments

I've just found out that some code does crash on a 68000 CPU when exceptions are used:

#include <dos/dos.h>
#include <stdio.h>

class A
{
public:

  A()
    : m_pText("Hey\n")
  {
  }

  void Run()
  {
    printf("%s", m_pText);
  }

private:
  const char* m_pText;
};


int main(void)
{
  try
  {
    A a;
    a.Run();

    return RETURN_OK;
  }
  catch(const char* pMsg)
  {
    printf("%s\n", pMsg);
    return RETURN_FAIL;
  }
}

$ m68k-amigaos-g++ exc_test.cpp -o exc_test -noixemul

The binary crashes on a WinUAE config with CPU set to 68000. With 68020 it works.

Maybe there's some CPU-dependent code generated when using exceptions?

rosneru avatar May 10 '20 17:05 rosneru

Guess this one is not fixable: the exception info may lead to a word read from an odd address, which raises an address error trap on the 68000

bebbo avatar May 10 '20 17:05 bebbo

but the above code is working here in WinUAE without problems.

Note that binaries created with -noixemul do not work on kickstart 1.3 You have to use -mcrt=nix13

bebbo avatar May 10 '20 17:05 bebbo

I've run the code in WinUAE on a A600 config but using 3.1 ROMs 40.63 (A500, A600, A2000) and a Workbench 3.1, 1MB ChipRAM, most compatible settings.

But I understand that the odd addresses can be a problem on the non-32-bit 68000.

Thanks for explaining.

rosneru avatar May 10 '20 18:05 rosneru

please test

bebbo avatar Dec 05 '21 12:12 bebbo

Thanks for reopening this.

But I did a quick test and recompiled the above example with m68k-amigaos-gcc (GCC) 6.5.0b 211205132514 and it still did crash.

But as I've no real hardware 68000 Amiga, I used a WinUAE config. Maybe I choose some problematic settings in WinUAE, I'll check it soon.

rosneru avatar Dec 07 '21 10:12 rosneru

here are some tests (including your file) exception.zip

addresserror crashes on A500 and both others do work now.

bebbo avatar Dec 07 '21 13:12 bebbo

All these binaries crash on my config, an emulated A600 with 3.1 ROM and plain Workbench 3.1 install on DH0, mapped to an Windows-Folder (no HDF).

Here some pictures of the config:

winuae-cpu winuae-chipset winuae-chipset-adv winuae-rom winuae-ram

And the crash:

winuae-exception-crash

Is something obviously wrong?

rosneru avatar Dec 07 '21 17:12 rosneru

duh - my more compatible is not checked here - now the guru is visiting me too...

bebbo avatar Dec 07 '21 18:12 bebbo

exceptionfixed.zip

these are working now - fix should be live soon

bebbo avatar Dec 08 '21 17:12 bebbo

They also work on my config. Great!

rosneru avatar Dec 08 '21 17:12 rosneru

the fix is live, you need

make update
make clean-libgcc
make libgcc

bebbo avatar Dec 08 '21 18:12 bebbo

Great, now the example above now works on my 68000 config, and so does also my own program ADiffView.

So I can release a new version with 68000 compatibility soon:-)

Thank you for fixing this:thumbsup:

rosneru avatar Dec 08 '21 18:12 rosneru

nice app. and thanks for reporting/testing!

bebbo avatar Dec 08 '21 19:12 bebbo

I have a strange problem here about exceptions. But it has nothing to do with 68000/68020+.

When I do a throw in the constructor of a certain class, the program crashes. However, it works for other classes/constructors. It also works without crashing if I compile with -O0 instead of -O2.

I pushed the example with the crash to a different branch

For example the linked file DiffDocument.h. There in line 98 the DiffEngine is instantiated. Although this is empty in this example and only throws an exception in the constructor, it crashes at this point.

But if I activate DiffEngineFake, which is implemented directly on top in DiffDocument.h, it works. The DiffEngineFake exception is thrown, no crash.

If I move the instantiation of DiffEngineFake below that of DiffEngine, it now also works: Now the exception of DiffEngine is thrown, no crash.

If I now comment out DiffEngineFake, it crashes again.

I don't want to waste your time with my issues, but could it be somehow related to the gcc 6.5 and the exception implementation?

I'm only asking this because I'm a little stumped on this behavior.

rosneru avatar Dec 13 '21 07:12 rosneru

please provide a more simple test case. cmake .. only builds it for Linux.

bebbo avatar Dec 13 '21 08:12 bebbo

Yeah that's right, I'm using WSL2 with Debian installed.

In the next few days I will try to find a simpler example that also crashes. But somehow I already fear that it is due to the context of my project and only reproducible there:D

rosneru avatar Dec 13 '21 09:12 rosneru

how do you build that for the Amiga?

bebbo avatar Dec 13 '21 09:12 bebbo

In Windows I have WinUAE installed, and in its config I add a harddrive DH1 as directory with the directory path set to

\\wsl$\Debian\home\username\amiga-share\

And in Linux the whole repository is cloned into that

/home/username/amiga-share 

directory. All the cmake/make/gcc tools work from there and the binaries are created directly in the repository directory.

In Windows I have some WinUAE configs, e.g. a basic A1200 one which also use the amiga-share as DH1 and from their startup-sequence directly start the given binary (e.g. ADiffView_gcc). So, for example on my Windows desktop I have an icon / link ADiffView which on double click starts its WinUAE config with the current binarie I compiled seconds ago from Linux.

For coding in Windows I use VSCode. When I there open the folder

\\wsl$\Debian\home\username\amiga-share\ADiffView\

it automatically switches to WSL/Linux mode with the Linux console integrated at the bottom. <Ctrl+Shift+b> builds directly from VSCode.

rosneru avatar Dec 13 '21 09:12 rosneru

I've attached a minimal example that crashes when loaded from the startup-sequence of a basic an A1200 config.

The crash is coming from the instantiation of DiffEngine in DiffDocument.h, line 87. When this line is commented out it doesn't crash after rebuild.

exception-crash.zip

rosneru avatar Dec 13 '21 18:12 rosneru

The latter example is not related to odd addresses, it's an unwinding issue.

bebbo avatar May 15 '22 06:05 bebbo

with amiga13.1 this prints Exception

bebbo avatar May 15 '23 19:05 bebbo